Prechádzať zdrojové kódy

设备类型统计报表

hfxc226 2 rokov pred
rodič
commit
e1a736bee7

+ 8 - 2
platform-dao/src/main/java/com/platform/dao/dto/sb/SbInfoDTO.java

@@ -530,16 +530,22 @@ public class SbInfoDTO extends BaseDTO implements Serializable {
      * 是否过滤数据,查询主子数据
      */
     private Boolean parentSearch;
-
     /**
      * 有效期搜索开始时间
      */
     private LocalDate nextCheckDateStart;
-
     /**
      * 有效期搜索结束时间
      */
     private LocalDate nextCheckDateEnd;
+    /**
+     * 有效期搜索开始时间
+     */
+    private LocalDate checkDateStart;
+    /**
+     * 有效期搜索结束时间
+     */
+    private LocalDate checkDateEnd;
 
     /**
      * 申请时间

+ 9 - 0
platform-dao/src/main/java/com/platform/dao/mapper/sb/SbInfoMapper.java

@@ -28,6 +28,7 @@ public interface SbInfoMapper extends MyMapper<SbInfo> {
      * @return
      */
     List<SbInfoVO> selectVOList(SbInfoDTO dto);
+
     /**
      * 分页查询
      *
@@ -146,4 +147,12 @@ public interface SbInfoMapper extends MyMapper<SbInfo> {
 
     // 根据位置code,查询该位置设备数量,包括下属位置
     List<Map<String, String>> selectCountByUseTypeGroup(String positionCode);
+
+    /**
+     * 分页查询类型汇总
+     *
+     * @param useType 自定义类型
+     * @return
+     */
+    List<Map<String, String>> selectCountMap(SbInfoDTO dto);
 }

+ 40 - 0
platform-dao/src/main/java/com/platform/dao/vo/report/SbInfoTypeReportVO.java

@@ -0,0 +1,40 @@
+package com.platform.dao.vo.report;
+
+import com.platform.dao.vo.query.check.CheckJobVO;
+import com.platform.dao.vo.sb.SbInfoVO;
+import com.platform.office.annotation.Excel;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * @author cyz
+ */
+@Data
+@Accessors(chain = true)
+public class SbInfoTypeReportVO implements Serializable {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 每月总数
+     */
+    @Excel(name = "类型名称", orderNum = "1")
+    private String typeName;
+    /**
+     * 总数
+     */
+    @Excel(name = "总数", orderNum = "2")
+    private Integer totalNum;
+    /**
+     * 占比
+     */
+    @Excel(name = "占比", orderNum = "3")
+    private double rate;
+
+    /**
+     * 明细列表
+     */
+    List<SbInfoVO> detailList;
+}

+ 15 - 0
platform-dao/src/main/resources/mapper/sb/SbInfoMapper.xml

@@ -304,6 +304,12 @@ user.real_name as saveUserName,sb.repair_dept_id
         <if test="saveUser != null">
             and sb.save_user = #{saveUser}
         </if>
+        <if test="checkDateStart != null">
+            and sb.check_date <![CDATA[ >= ]]> #{checkDateStart}
+        </if>
+        <if test="checkDateEnd != null">
+            and sb.check_date <![CDATA[ <= ]]> #{checkDateEnd}
+        </if>
         <if test="nextCheckDateStart != null">
             and sb.next_check_date <![CDATA[ >= ]]> #{nextCheckDateStart}
         </if>
@@ -816,4 +822,13 @@ user.real_name as saveUserName,sb.repair_dept_id
         group By info.use_type
     </select>
 
+    <select id="selectCountMap" parameterType="com.platform.dao.dto.sb.SbInfoDTO"
+            resultType="java.util.Map">
+        select count(*) as num, type_id as typeId from t_sb_info
+        <if test="useType != null">
+            where use_type = #{useType}
+        </if>
+        GROUP BY type_id
+    </select>
+
 </mapper>

+ 67 - 0
platform-rest/src/main/java/com/platform/rest/controller/report/SbInfoReportController.java

@@ -0,0 +1,67 @@
+package com.platform.rest.controller.report;
+
+import com.platform.common.util.DateUtils;
+import com.platform.common.util.R;
+import com.platform.dao.dto.sb.SbInfoDTO;
+import com.platform.dao.dto.sb.SbMeasureLogDTO;
+import com.platform.dao.util.ExcelUtil;
+import com.platform.dao.vo.report.MeasureLogReportVO;
+import com.platform.dao.vo.report.SbInfoTypeReportVO;
+import com.platform.rest.log.annotation.SysLog;
+import com.platform.service.sb.SbInfoService;
+import com.platform.service.sb.SbMeasureLogService;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletResponse;
+import java.time.LocalDate;
+import java.util.List;
+
+/**
+ * @Description 设备报表 控制器
+ * 1: 设备类型报表,可以根据自定义类型筛选、厂区筛选(车间筛选)
+ * 2:待定
+ * @Author liuyu
+ * @Date 2020-05-29 10:39:40
+ * @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping("/report/sb/infos")
+public class SbInfoReportController {
+
+    private final SbInfoService sbInfoService;
+
+    /**
+     * 类型数量统计
+     *
+     * @param dto  查询条件
+     * @param year 查询年份
+     * @return R
+     */
+    @SysLog("类型数量统计报表")
+    @GetMapping("")
+    public R getMonthReportByYear(SbInfoDTO dto, @RequestParam(required = false) Integer year, @RequestParam(required = false) LocalDate startMonth, @RequestParam(required = false) LocalDate endMonth) {
+        return new R(sbInfoService.getTypeReport(dto, year, startMonth, endMonth));
+    }
+
+    /**
+     * 类型数量统计
+     *
+     * @param dto  查询条件
+     * @param year 查询年份
+     * @return R
+     */
+    @GetMapping("/export")
+    @SysLog("类型数量统计报表导出")
+    public void export(HttpServletResponse response, SbInfoDTO dto, @RequestParam(required = false) Integer year, @RequestParam(required = false) LocalDate startMonth, @RequestParam(required = false) LocalDate endMonth) {
+        List<SbInfoTypeReportVO> list = sbInfoService.getTypeReport(dto, year, startMonth, endMonth);
+        String fileName = "类型占比";
+        ExcelUtil.exportResponseDict(response, SbInfoTypeReportVO.class, list, fileName);
+    }
+
+    
+}

+ 4 - 0
platform-service/src/main/java/com/platform/service/sb/SbInfoService.java

@@ -3,11 +3,13 @@ package com.platform.service.sb;
 import com.platform.dao.bean.MyVOPage;
 import com.platform.dao.dto.sb.SbInfoDTO;
 import com.platform.dao.entity.sb.SbInfo;
+import com.platform.dao.vo.report.SbInfoTypeReportVO;
 import com.platform.dao.vo.sb.*;
 import com.platform.service.base.IBaseService;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.time.LocalDate;
 import java.util.List;
 import java.util.Map;
 
@@ -327,4 +329,6 @@ public interface SbInfoService extends IBaseService<SbInfo, SbInfoDTO> {
      * @return
      */
     List<SbInfoVO> getChildSbByIds(List<String> ids);
+
+    List<SbInfoTypeReportVO> getTypeReport(SbInfoDTO dto, Integer year, LocalDate startMonth, LocalDate endMonth);
 }

+ 121 - 79
platform-service/src/main/java/com/platform/service/sb/impl/SbInfoServiceImpl.java

@@ -19,6 +19,7 @@ import com.platform.dao.bean.MyVOPage;
 import com.platform.dao.dto.check.CheckStandardDTO;
 import com.platform.dao.dto.part.PartInfoDTO;
 import com.platform.dao.dto.sb.SbInfoDTO;
+import com.platform.dao.dto.sb.SbMeasureLogDTO;
 import com.platform.dao.dto.sb.SbModelSpareBomDTO;
 import com.platform.dao.dto.upms.SysDeptDTO;
 import com.platform.dao.dto.upms.SysUserDeptDTO;
@@ -52,7 +53,10 @@ import com.platform.dao.util.compare.FieldComparedUtils;
 import com.platform.dao.vo.SysUserDeptVO;
 import com.platform.dao.vo.SysUserVO;
 import com.platform.dao.vo.export.sb.ExportSbInfoVO;
+import com.platform.dao.vo.query.sb.SbMeasureLogVO;
 import com.platform.dao.vo.query.upms.SysDeptVO;
+import com.platform.dao.vo.report.MeasureLogReportVO;
+import com.platform.dao.vo.report.SbInfoTypeReportVO;
 import com.platform.dao.vo.sb.*;
 import com.platform.service.base.impl.BaseServiceImpl;
 import com.platform.service.business.ActivitiBusinessService;
@@ -464,7 +468,7 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
     @Override
     public void modModelByDTO(SbInfoDTO model) {
 
-        if(model.getCheckDate() != null && model.getCheckPeriod() != null && model.getNextCheckDate() == null){
+        if (model.getCheckDate() != null && model.getCheckPeriod() != null && model.getNextCheckDate() == null) {
             model.setNextCheckDate(model.getCheckDate().minusMonths(-model.getCheckPeriod()));
         }
         if (model.getIsFinancing() == null) {
@@ -483,9 +487,9 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
         setSbStatusLogAndStopLog(model);
         // 保存修改记录
         SbInfo sbInfo = mapper.selectByPrimaryKey(model.getId());
-        SbInfoDTO oldDTO = BeanConverterUtil.copyObjectProperties(sbInfo,SbInfoDTO.class);
-        String updateInfo = FieldComparedUtils.compareBean(oldDTO,model);
-        packageLogInfo(updateInfo,model.getId());
+        SbInfoDTO oldDTO = BeanConverterUtil.copyObjectProperties(sbInfo, SbInfoDTO.class);
+        String updateInfo = FieldComparedUtils.compareBean(oldDTO, model);
+        packageLogInfo(updateInfo, model.getId());
         super.modModelByDTO(model);
         // 保存文件
         this.saveImageFile(model);
@@ -494,7 +498,7 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
         this.saveRecheckFile(model);
     }
 
-    private void packageLogInfo(String updateInfo,String sbId){
+    private void packageLogInfo(String updateInfo, String sbId) {
         SbChangeLog log = new SbChangeLog();
         log.setCreatedTime(LocalDateTime.now());
         log.setCreatedUserId(SecurityUtils.getUserInfo().getUserId());
@@ -593,36 +597,36 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
         List<SbModelSpareBomVO> spareList = new ArrayList<>();
         List<SbModelSpareBomVO> spareList2 = new ArrayList<>();
         for (PartInfo info : partInfoList) {
-        for (SbModelSpareBomVO vo : sbModelSpareBomVOList) {
-            if (StringUtils.isBlank(vo.getSbPartId())) {
-                spareList.add(vo);
-            } else {
-                if (info.getId().equals(vo.getSbPartId())) {
-                    spareList2.add(vo);
+            for (SbModelSpareBomVO vo : sbModelSpareBomVOList) {
+                if (StringUtils.isBlank(vo.getSbPartId())) {
+                    spareList.add(vo);
+                } else {
+                    if (info.getId().equals(vo.getSbPartId())) {
+                        spareList2.add(vo);
+                    }
                 }
             }
+            info.setSparePartInfoVOList(spareList2);
         }
-        info.setSparePartInfoVOList(spareList2);
-    }
         sbTreeVO.setId(sbInfoDTO.getId());
         sbTreeVO.setPartInfoList(partInfoList);
         sbTreeVO.setSbModelSpareBomVOList(spareList);
         return sbTreeVO;
     }
 
-@Override
+    @Override
     public SbTreeVO getSbVOById(SbInfoDTO sbInfoDTO) {
-        SbInfoVO sbInfoVO=sbInfoMapper.getById(sbInfoDTO.getId());
-        List<SbInfoVO> ids=sbInfoMapper.getSubSb(sbInfoDTO);
+        SbInfoVO sbInfoVO = sbInfoMapper.getById(sbInfoDTO.getId());
+        List<SbInfoVO> ids = sbInfoMapper.getSubSb(sbInfoDTO);
         SbTreeVO sbTreeVO = new SbTreeVO();
         sbTreeVO.setModel(sbInfoVO.getModel());
         sbTreeVO.setName(sbInfoVO.getName());
         sbTreeVO.setStatus(sbInfoVO.getStatus());
-        List<SbTreeVO> subSbTreeList=new ArrayList<>();
-        if(ids!=null&&ids.size()>0){
-            for(SbInfoVO id: ids){
-                SbInfoDTO infoDTO=new SbInfoDTO();
-                SbTreeVO subSbTreeVO= getSbVOById(infoDTO.setId(id.getId()));
+        List<SbTreeVO> subSbTreeList = new ArrayList<>();
+        if (ids != null && ids.size() > 0) {
+            for (SbInfoVO id : ids) {
+                SbInfoDTO infoDTO = new SbInfoDTO();
+                SbTreeVO subSbTreeVO = getSbVOById(infoDTO.setId(id.getId()));
 //                subSbTreeVO.setName(id.getName());
 
                 subSbTreeList.add(subSbTreeVO);
@@ -669,10 +673,10 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
         List<SysUser> users = sysUserMapper.selectAll(); // 用户集合
         try {
             List<ExportSbInfoVO> list = ExcelUtil.importExcel(file.getInputStream(), ExportSbInfoVO.class, 1);
-            if(CollectionUtil.isNotEmpty(list)){
-                for(ExportSbInfoVO vo : list){
-                    SbInfo tempInfo = BeanConverterUtil.copyObjectProperties(vo,SbInfo.class);
-                    if(StringUtils.isNotBlank(vo.getTypeName())){ // 设备类型匹配
+            if (CollectionUtil.isNotEmpty(list)) {
+                for (ExportSbInfoVO vo : list) {
+                    SbInfo tempInfo = BeanConverterUtil.copyObjectProperties(vo, SbInfo.class);
+                    if (StringUtils.isNotBlank(vo.getTypeName())) { // 设备类型匹配
                         boolean findSbType = false;
                         for (SbType sbType : typeList) {
                             if (sbType.getName().equalsIgnoreCase(vo.getTypeName().trim())) {
@@ -685,7 +689,7 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
                             throw new BusinessException("系统找不到该设备类型名称,请先添加设备类型, 设备类型名称" + vo.getTypeName());
                         }
                     }
-                    if(StringUtils.isNotBlank(vo.getPositionName())){ // 设备位置匹配
+                    if (StringUtils.isNotBlank(vo.getPositionName())) { // 设备位置匹配
                         boolean findPosition = false;
                         for (SbPosition position : positionList) {
                             if (position.getName().equalsIgnoreCase(vo.getPositionName().trim())) {
@@ -698,7 +702,7 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
                             throw new BusinessException("系统找不到车间名称,请先添加车间, 车间名称" + vo.getPositionName());
                         }
                     }
-                    if(StringUtils.isNotBlank(vo.getProducerName())){ // 生产商匹配
+                    if (StringUtils.isNotBlank(vo.getProducerName())) { // 生产商匹配
                         boolean findProducer = false;
                         for (FirmProducer producer : producerList) {
                             if (producer.getName().equalsIgnoreCase(vo.getProducerName().trim())) {
@@ -711,7 +715,7 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
                             throw new BusinessException("找不到生产商,请先添加:" + vo.getProducerName());
                         }
                     }
-                    if(StringUtils.isNotBlank(vo.getSaveUserName())){ // 使用人员
+                    if (StringUtils.isNotBlank(vo.getSaveUserName())) { // 使用人员
                         boolean findSaveUser = false;
                         for (SysUser user : users) {
                             if (user.getRealName().equalsIgnoreCase(vo.getSaveUserName().trim())) {
@@ -738,11 +742,11 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
                         }
                     }*/
                     // 如果计量设备
-                    if(vo.getUseType() == SbUseType.BGCL.getValue() && vo.getIsMeasure() == YesNoEnum.YES.getValue()){
-                        if(vo.getCheckDate() == null && vo.getNextCheckDate() == null){
+                    if (vo.getUseType() == SbUseType.BGCL.getValue() && vo.getIsMeasure() == YesNoEnum.YES.getValue()) {
+                        if (vo.getCheckDate() == null && vo.getNextCheckDate() == null) {
                             throw new BusinessException("上次和下次检定日期,不能全部为空");
                         }
-                        if(vo.getCheckPeriod() == null){
+                        if (vo.getCheckPeriod() == null) {
                             throw new BusinessException("检定周期不能为空");
                         }
                     }
@@ -761,9 +765,8 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
      * 定时任务,对需要检定的进行检定状态设置,
      * 1:根据设备的检定预警周期
      * 2:筛选
-     *      a) 检定状态为正常的
-     *      b) 当前日期+预警天数>有效期的
-     *
+     * a) 检定状态为正常的
+     * b) 当前日期+预警天数>有效期的
      */
     @Override
     public void generateSbMeasureLog() {
@@ -773,40 +776,40 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
         record.setIsMeasure(YesNoEnum.YES.getValue());
         List<SbInfoVO> list = mapper.selectPageInfoForWarn(record);
         List<SbInfoVO> updateList = new ArrayList<>();
-        if(CollectionUtil.isNotEmpty(list)){
-            for(SbInfoVO vo:list){
+        if (CollectionUtil.isNotEmpty(list)) {
+            for (SbInfoVO vo : list) {
                 SbInfoVO update = new SbInfoVO();
                 update.setId(vo.getId());
                 update.setMeasureStatus(YesNoEnum.YES.getValue());
                 updateList.add(update);
             }
         }
-        if(CollectionUtil.isNotEmpty(updateList)){
+        if (CollectionUtil.isNotEmpty(updateList)) {
             updateBatch(updateList);
         }
     }
 
     @Override
     public List<SbInfoVO> getChildSbByIds(List<String> ids) {
-        Map<String,String> maps = new HashMap<>();
-        ids.forEach(item -> maps.put(item,item));
+        Map<String, String> maps = new HashMap<>();
+        ids.forEach(item -> maps.put(item, item));
         SbInfoDTO queryDTO = new SbInfoDTO();
         queryDTO.setIds(ids);
         List<SbInfoVO> list = mapper.selectVOList(queryDTO);
         List<SbInfoVO> resultList = ListUtils.newArrayList();
-        if(list != null && list.size() > 0){
+        if (list != null && list.size() > 0) {
             list.forEach(item -> {
                 // 子设备且父设备在maps中不添加
-                if(StringUtils.isNotBlank(item.getParentId())){
+                if (StringUtils.isNotBlank(item.getParentId())) {
                     // 子设备
-                    if(StringUtils.isBlank(maps.get(item.getParentId()))){
+                    if (StringUtils.isBlank(maps.get(item.getParentId()))) {
                         // 获取子设备
                         SbInfoDTO query = new SbInfoDTO();
                         query.setParentId(item.getId());
                         item.setChildren(mapper.selectVOList(query));
                         resultList.add(item);
                     }
-                }else{
+                } else {
                     // 获取子设备
                     SbInfoDTO query = new SbInfoDTO();
                     query.setParentId(item.getId());
@@ -820,18 +823,19 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
 
     /**
      * 更新和记录修改
+     *
      * @param sbInfos
      */
-    private void updateListAndSaveChange(List<SbInfo> sbInfos){
-        if(sbInfos.size() > 0){
-            for(SbInfo sbInfo : sbInfos){
-                SbInfoDTO afterDTO = BeanConverterUtil.copyObjectProperties(sbInfo,SbInfoDTO.class);
+    private void updateListAndSaveChange(List<SbInfo> sbInfos) {
+        if (sbInfos.size() > 0) {
+            for (SbInfo sbInfo : sbInfos) {
+                SbInfoDTO afterDTO = BeanConverterUtil.copyObjectProperties(sbInfo, SbInfoDTO.class);
                 SbInfo old = mapper.selectByPrimaryKey(sbInfo.getId());
-                SbInfoDTO beforeDTO = BeanConverterUtil.copyObjectProperties(old,SbInfoDTO.class);
+                SbInfoDTO beforeDTO = BeanConverterUtil.copyObjectProperties(old, SbInfoDTO.class);
                 mapper.updateByPrimaryKeySelective(sbInfo);
-                String info = FieldComparedUtils.compareBean(beforeDTO,afterDTO);
-                if(StringUtils.isNotBlank(info)){
-                    packageLogInfo(info,sbInfo.getId()); // 保存修改记录
+                String info = FieldComparedUtils.compareBean(beforeDTO, afterDTO);
+                if (StringUtils.isNotBlank(info)) {
+                    packageLogInfo(info, sbInfo.getId()); // 保存修改记录
                 }
             }
         }
@@ -1175,15 +1179,15 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
     @Override
     public List<Map<String, String>> selectCountByPositionGroup() {
         List<Map<String, String>> sbInfoCountMapList = mapper.selectCountByPositionGroup();
-        if(sbInfoCountMapList != null) {
-            for (Map<String, String>  map: sbInfoCountMapList) {
+        if (sbInfoCountMapList != null) {
+            for (Map<String, String> map : sbInfoCountMapList) {
                 // 汇总厂区的,将厂区下面的车间数量累加到上面
                 if (String.valueOf(map.get("type")).equals("1")) {
                     int childNum = 0;
-                    for (Map<String, String>  child: sbInfoCountMapList) {
+                    for (Map<String, String> child : sbInfoCountMapList) {
                         if (map.get("id").equals(child.get("parentId"))) {
                             String childNumStr = String.valueOf(child.get("num"));
-                            if(!StringUtils.isEmpty(childNumStr)){
+                            if (!StringUtils.isEmpty(childNumStr)) {
                                 childNum = childNum + Integer.valueOf(childNumStr);
                             }
                         }
@@ -1197,6 +1201,7 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
 
     /**
      * 按照类型分组统计数量
+     *
      * @param positionCode : 位置code
      * @return
      */
@@ -1208,7 +1213,7 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
         List<String> positionIds = sbPositions.stream().map(SbPosition::getId).collect(Collectors.toList());
         List<SbInfoVO> sbInfoVOS = mapper.selectVOList(new SbInfoDTO().setPositionIds(positionIds));
         List<Map<String, String>> result = new ArrayList<>();
-        if(CollectionUtil.isNotEmpty(sbInfoVOS)) {
+        if (CollectionUtil.isNotEmpty(sbInfoVOS)) {
             Map<String, Long> stringStringMap = sbInfoVOS.stream().collect(Collectors.groupingBy(SbInfoVO::getTypeId, Collectors.counting()));
             List<SbType> typeList = sbTypeMapper.selectAll();
             for (SbType type : typeList) {
@@ -1227,6 +1232,7 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
 
     /**
      * 查询某个车间下面的数据,状态分组统计数量
+     *
      * @param positionCode : 位置code
      * @return
      */
@@ -1238,6 +1244,7 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
 
     /**
      * 按照自定义类型分组统计数量
+     *
      * @param positionCode : 位置code
      * @return
      */
@@ -1962,6 +1969,7 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
         LocalDateTime now = LocalDateTime.now();
         System.out.println(DateUtils.dateToString(now.minusMonths(-12)));
     }
+
     @Override
     public void generateSbCodeAll() {
         List<SbInfo> list = mapper.selectAll();
@@ -2096,48 +2104,55 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
         List<String> addTypeList = new ArrayList<>();
         try {
             List<ExportSbInfoVO> list = ExcelUtil.importExcel(file.getInputStream(), ExportSbInfoVO.class, 1);
-            if(CollectionUtil.isNotEmpty(list)){
+            if (CollectionUtil.isNotEmpty(list)) {
                 int i = 2;
-                for(ExportSbInfoVO vo : list){
+                for (ExportSbInfoVO vo : list) {
                     i++;
                     // 如果有检定周期,就是需要检定
-                    SbInfo tempInfo = BeanConverterUtil.copyObjectProperties(vo,SbInfo.class);
+                    SbInfo tempInfo = BeanConverterUtil.copyObjectProperties(vo, SbInfo.class);
                     tempInfo.setSeatNumber(30);// 默认30天提醒
+
                     // 对必填字段进行判断
-                    if(StringUtils.isBlank(vo.getPositionNo())){
-                      throw new BusinessException("第" + i + "行,位号为空,位号为必填项目,请填写;");// 编号为空,复制位号
+                    if (StringUtils.isBlank(vo.getPositionNo())) {
+                        throw new BusinessException("第" + i + "行,位号为空,位号为必填项目,请填写;");// 编号为空,复制位号
                     }
-                    if(vo.getIsFinancing() == 1 && StringUtils.isBlank(vo.getFinancingNo())){
+                    if (vo.getIsFinancing() == 1 && StringUtils.isBlank(vo.getFinancingNo())) {
                         throw new BusinessException("第" + i + "行,是固定资产,但是资产编号为空,请填写;");// 编号为空,复制位号
                     }
-                    if(StringUtils.isBlank(vo.getName())){
+                    if (StringUtils.isBlank(vo.getName())) {
                         throw new BusinessException("第" + i + "行,名称为空,请填写;");// 编号为空,复制位号
                     }
-                    if(StringUtils.isBlank(vo.getModel())){
+                    if (StringUtils.isBlank(vo.getModel())) {
                         throw new BusinessException("第" + i + "行,型号为空,请填写;");// 编号为空,复制位号
                     }
-                    if(vo.getLevel() == null || vo.getLevel()<1 || vo.getLevel()>3){
+                    if (vo.getLevel() == null || vo.getLevel() < 1 || vo.getLevel() > 3) {
                         throw new BusinessException("第" + i + "行,等级为空,A级请填1,B级填2,C级填3;");// 编号为空,复制位号
                     }
-                    if(vo.getUseType() == null || vo.getUseType()<3 || vo.getUseType()>5){
+                    if (vo.getUseType() == null || vo.getUseType() < 3 || vo.getUseType() > 5) {
                         throw new BusinessException("第" + i + "行,自定义类型为空,生产设备请填3,计量设备填4,特种设备填5;");// 编号为空,复制位号
                     }
-                    if(vo.getStatus() == null || vo.getStatus()<1 || vo.getStatus()>2){
+                    if (vo.getUseType() == 4) {
+                        tempInfo.setIsChild(1);
+                    }
+                    if (vo.getUseType() != 4) {
+                        tempInfo.setIsChild(0);
+                    }
+                    if (vo.getStatus() == null || vo.getStatus() < 1 || vo.getStatus() > 2) {
                         throw new BusinessException("第" + i + "行,状态为空,在库请填1,使用中填2;");// 编号为空,复制位号
                     }
-                    if(StringUtils.isBlank(vo.getNo())){
+                    if (StringUtils.isBlank(vo.getNo())) {
                         tempInfo.setNo(vo.getPositionNo());// 编号为空,复制位号
                     }
-                    if(StringUtils.isNotEmpty(vo.getPpNo())){
+                    if (StringUtils.isNotEmpty(vo.getPpNo())) {
                         tempInfo.setIsChild(1);
                     }
-                    if(StringUtils.isNotEmpty(vo.getFinancingNo())){
+                    if (StringUtils.isNotEmpty(vo.getFinancingNo())) {
                         tempInfo.setIsFinancing(1);
                     }
-                    if(vo.getCheckPeriod() != null){
+                    if (vo.getCheckPeriod() != null) {
                         tempInfo.setIsMeasure(1);
                     }
-                    if(StringUtils.isNotBlank(vo.getTypeName())){ // 设备类型匹配
+                    if (StringUtils.isNotBlank(vo.getTypeName())) { // 设备类型匹配
                         boolean findSbType = false;
                         for (SbType sbType : typeList) {
                             if (sbType.getName().equalsIgnoreCase(vo.getTypeName().trim())) {
@@ -2151,7 +2166,7 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
                             // throw new BusinessException("系统找不到该设备类型名称,请先添加设备类型, 设备类型名称" + vo.getTypeName());
                         }
                     }
-                    if(StringUtils.isNotBlank(vo.getPositionName())){ // 设备位置匹配
+                    if (StringUtils.isNotBlank(vo.getPositionName())) { // 设备位置匹配
                         boolean findPosition = false;
                         for (SbPosition position : positionList) {
                             if (position.getName().equalsIgnoreCase(vo.getPositionName().trim())) {
@@ -2178,7 +2193,7 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
                             throw new BusinessException("找不到生产商,请先添加:" + vo.getProducerName());
                         }
                     }*/
-                    if(StringUtils.isNotBlank(vo.getSaveUserName())){ // 使用人员
+                    if (StringUtils.isNotBlank(vo.getSaveUserName())) { // 使用人员
                         boolean findSaveUser = false;
                         for (SysUser user : users) {
                             if (user.getRealName().equalsIgnoreCase(vo.getSaveUserName().trim())) {
@@ -2192,14 +2207,17 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
                         }
                     }
                     // 如果计量设备 且是需要检定
-                    if(vo.getUseType() == SbUseType.BGCL.getValue() && vo.getIsMeasure() == YesNoEnum.YES.getValue()){
-                        if(vo.getCheckDate() == null && vo.getNextCheckDate() == null){
+                    if (vo.getUseType() == SbUseType.BGCL.getValue() && vo.getIsMeasure() == YesNoEnum.YES.getValue()) {
+                        if (vo.getCheckDate() == null && vo.getNextCheckDate() == null) {
                             throw new BusinessException("上次和下次检定日期,不能全部为空");
                         }
-                        if(vo.getCheckPeriod() == null){
+                        if (vo.getCheckPeriod() == null) {
                             throw new BusinessException("检定周期不能为空");
                         }
                     }
+                    // 初始化的默认数据
+                    tempInfo.setMeasureStatus(0);
+                    tempInfo.setIsShow(0);
                     tempInfo.setId(IdGeneratorUtils.getObjectId());
                     tempInfo.setCreatedUserName(SecurityUtils.getUserInfo().getUsername());
                     tempInfo.setCreatedUserId(SecurityUtils.getUserInfo().getUserId());
@@ -2208,8 +2226,8 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
                 }
             }
 
-            if(CollectionUtil.isNotEmpty(addTypeList)){
-                throw new BusinessException(addTypeList.size() + "个设备类型名称找不到,请先添加:" + addTypeList.toString());
+            if (CollectionUtil.isNotEmpty(addTypeList)) {
+                throw new BusinessException(addTypeList.size() + "个设备类型名称找不到,请先添加:" + addTypeList);
             }
             // 导入数据
             mapper.insertListforComplex(addList);
@@ -2500,4 +2518,28 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
         backlogUserDTO.setDetailType(WorkplaceBacklogDetailTypeEnum.SB_SCRAP_RESULT.getValue());
         backlogUserMapper.updateByUser(backlogUserDTO);
     }
+
+    @Override
+    public List<SbInfoTypeReportVO> getTypeReport(SbInfoDTO sbInfoDTO, Integer searchYear, LocalDate startMonth, LocalDate endMonth) {
+        List<Map<String, String>> countMap = mapper.selectCountMap(sbInfoDTO);
+        List<SbType> typeList = sbTypeMapper.selectAll();
+        List<SbInfoTypeReportVO> result = new ArrayList<>();
+        Integer totalNum = 0;
+        for (Map<String, String> map : countMap) {
+            SbInfoTypeReportVO vo = new SbInfoTypeReportVO();
+            vo.setTotalNum(Integer.valueOf(String.valueOf(map.get("num"))));
+            totalNum = totalNum + vo.getTotalNum();
+            for (SbType sbType : typeList) {
+                if (map.get("typeId").equals(sbType.getId())) {
+                    vo.setTypeName(sbType.getName());
+                    break;
+                }
+            }
+            result.add(vo);
+        }
+        for (SbInfoTypeReportVO sbInfoTypeReportVO : result) {
+            sbInfoTypeReportVO.setRate(BigDecimalUtil.div(sbInfoTypeReportVO.getTotalNum() * 100, totalNum, 2));
+        }
+        return result;
+    }
 }