| | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog; |
| | | import org.jeecg.modules.eam.constant.*; |
| | | import org.jeecg.modules.eam.request.*; |
| | | import org.jeecg.modules.system.entity.BaseFactory; |
| | | import org.jeecg.modules.system.entity.BaseFactoryUser; |
| | | import org.jeecg.modules.system.service.IBaseFactoryService; |
| | | import org.jeecg.modules.system.service.IBaseFactoryUserService; |
| | | import org.jeecg.modules.eam.constant.BusinessCodeConst; |
| | | import org.jeecg.modules.eam.constant.EquipmentOperationTagEnum; |
| | | import org.jeecg.modules.eam.constant.InspectionItemCategroyEnum; |
| | | import org.jeecg.modules.eam.constant.InspectionStatus; |
| | | import org.jeecg.modules.eam.entity.*; |
| | | import org.jeecg.modules.eam.mapper.EamInspectionOrderMapper; |
| | | import org.jeecg.modules.eam.request.EamInspectionOrderQuery; |
| | | import org.jeecg.modules.eam.request.EamInspectionOrderRequest; |
| | | import org.jeecg.modules.eam.service.*; |
| | | import org.jeecg.modules.eam.util.DateUtils; |
| | | import org.jeecg.modules.eam.vo.InspectionVo; |
| | |
| | | import org.jeecg.modules.flowable.apithird.service.FlowCommonService; |
| | | import org.jeecg.modules.flowable.service.IFlowDefinitionService; |
| | | import org.jeecg.modules.flowable.service.IFlowTaskService; |
| | | import org.jeecg.modules.system.service.ISysDictService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.IntStream; |
| | | |
| | | /** |
| | | * @Description: 点检工单 |
| | |
| | | private IEamReportRepairService eamReportRepairService; |
| | | @Resource |
| | | private IEamMaintenanceStandardDetailService eamMaintenanceStandardDetailService; |
| | | @Resource |
| | | private ISysDictService sysDictService; |
| | | |
| | | @Override |
| | | public IPage<EamInspectionOrder> queryPageList(Page<EamInspectionOrder> page, EamInspectionOrderQuery query) { |
| | |
| | | return eamInspectionOrderMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | /** |
| | | * 导出获取基本信息 |
| | | * @param equipmentCode 设备编码 |
| | | * @param inspectionDate 点检日期 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public JSONObject exportInspectionOrderBaseInfo(String equipmentCode, String inspectionDate) { |
| | | // 创建结果对象 |
| | | JSONObject result = new JSONObject(); |
| | | EamInspectionOrderBaseResponse eamInspectionOrderBaseResponse = eamInspectionOrderMapper.findInsOrderBaseInfo(equipmentCode, inspectionDate); |
| | | // 处理单位 |
| | | String factoryOrgCode = eamInspectionOrderBaseResponse.getFactoryName(); |
| | | BaseFactory baseFactory = baseFactoryService.getOne(new LambdaQueryWrapper<BaseFactory>().eq(BaseFactory::getOrgCode, factoryOrgCode.substring(0, 6))); |
| | | eamInspectionOrderBaseResponse.setFactoryName(baseFactory.getFactoryName()); |
| | | result.put("data",Collections.singletonList(eamInspectionOrderBaseResponse)); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 日点检项列表 |
| | | * @param equipmentCode 设备编码 |
| | | * @param inspectionDate 点检日期 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public JSONObject exportInspectionOrderDetailList(String equipmentCode, String inspectionDate) { |
| | | // 创建结果对象 |
| | | JSONObject result = new JSONObject(); |
| | | List<EamInsOrderDetailResultResponse> eamInsOrderDetailResultResponseList = eamInspectionOrderMapper.findInsOrderDetailList(equipmentCode, inspectionDate); |
| | | if (eamInsOrderDetailResultResponseList == null || eamInsOrderDetailResultResponseList.isEmpty()) { |
| | | return result; |
| | | } |
| | | Map<EamInsOrderDetailResultResponse, List<EamInsOrderDetailResultResponse>> groupMap = eamInsOrderDetailResultResponseList |
| | | .stream().collect(Collectors.groupingBy( |
| | | // 分组键:包含 itemCode、itemName、itemDemand 的对象 |
| | | item -> new EamInsOrderDetailResultResponse( |
| | | item.getItemCode(), |
| | | item.getItemName(), |
| | | item.getItemDemand() |
| | | ), |
| | | // 用 TreeMap 作为容器,并指定按 itemCode 排序的比较器 |
| | | () -> new TreeMap<>(Comparator.comparingInt(EamInsOrderDetailResultResponse::getItemCode)), |
| | | // 收集每组的元素为 List |
| | | Collectors.toList() |
| | | )); |
| | | List<Map<String, Object>> resultList = new ArrayList<>(); |
| | | groupMap.forEach((insOrderDetailResultResponse, insOrderDetailResultResponseList) -> { |
| | | Map<String, Object> resultMap = new LinkedHashMap<>(); |
| | | resultMap.put("itemCode", insOrderDetailResultResponse.getItemCode()); |
| | | resultMap.put("itemName", insOrderDetailResultResponse.getItemName()); |
| | | resultMap.put("itemDemand", insOrderDetailResultResponse.getItemDemand()); |
| | | Map<Integer, EamInsOrderDetailResultResponse> collect = insOrderDetailResultResponseList |
| | | .stream().collect(Collectors.toMap( |
| | | // 分组键:提取日期中的“天” |
| | | item -> { |
| | | Date date = item.getInspectionDate(); |
| | | LocalDate localDate = date.toInstant() |
| | | .atZone(ZoneId.systemDefault()) |
| | | .toLocalDate(); |
| | | return localDate.getDayOfMonth(); // 键为“天”(1-31) |
| | | }, |
| | | // 值:直接使用当前对象(作为初始值) |
| | | item -> item, |
| | | // 合并函数:当同一“天”有多个对象时,如何处理(这里示例取第一个) |
| | | (existing, replacement) -> existing // 若有重复键,保留已存在的对象 |
| | | )); |
| | | for (int i = 1; i <= 31; i++) { |
| | | if (collect.containsKey(i)) { |
| | | String inspectionResult = ""; |
| | | switch (collect.get(i).getInspectionResult()) { |
| | | case "NORMAL": |
| | | inspectionResult = "√"; |
| | | break; |
| | | case "ANOMALY": |
| | | inspectionResult = "×"; |
| | | break; |
| | | case "FAULT": |
| | | inspectionResult = "△"; |
| | | break; |
| | | case "CLOSE": |
| | | inspectionResult = "T"; |
| | | break; |
| | | } |
| | | resultMap.put("inspectionResult" + i, inspectionResult); |
| | | } else { |
| | | resultMap.put("inspectionResult" + i, ""); |
| | | } |
| | | } |
| | | resultList.add(resultMap); |
| | | }); |
| | | result.put("data", resultList); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 日点检责任人列表 |
| | | * @param equipmentCode 设备编码 |
| | | * @param inspectionDate 点检日期 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public JSONObject exportInspectionOrderDetailUserList(String equipmentCode, String inspectionDate) { |
| | | // 创建结果对象 |
| | | JSONObject result = new JSONObject(); |
| | | List<EamInsOrderDetailUserResponse> eamInsOrderDetailUserResponseList = eamInspectionOrderMapper.findInspectionOrderDetailUserList(equipmentCode, inspectionDate); |
| | | if (eamInsOrderDetailUserResponseList == null || eamInsOrderDetailUserResponseList.isEmpty()) { |
| | | return result; |
| | | } |
| | | Map<Integer, EamInsOrderDetailUserResponse> groupMap = eamInsOrderDetailUserResponseList.stream().collect(Collectors.toMap( |
| | | // 分组键:提取日期中的“天” |
| | | item -> { |
| | | Date date = item.getInspectionDate(); |
| | | LocalDate localDate = date.toInstant() |
| | | .atZone(ZoneId.systemDefault()) |
| | | .toLocalDate(); |
| | | return localDate.getDayOfMonth(); // 键为“天”(1-31) |
| | | }, |
| | | // 值:直接使用当前对象(作为初始值) |
| | | item -> item, |
| | | // 合并函数:当同一“天”有多个对象时,如何处理(这里示例取第一个) |
| | | (existing, replacement) -> existing // 若有重复键,保留已存在的对象 |
| | | )); |
| | | Map<String, Object> resultMap = new LinkedHashMap<>(); |
| | | for (int i = 1; i <= 31; i++) { |
| | | if (groupMap.containsKey(i)) { |
| | | EamInsOrderDetailUserResponse eamInsOrderDetailUserResponse = groupMap.get(i); |
| | | resultMap.put("operator" + i, sysDictService.queryTableDictTextByKey("sys_user", "realname", "username", eamInsOrderDetailUserResponse.getOperator())); |
| | | resultMap.put("confirmUser" + i, sysDictService.queryTableDictTextByKey("sys_user", "realname", "username", eamInsOrderDetailUserResponse.getConfirmUser())); |
| | | } else { |
| | | resultMap.put("operator" + i, ""); |
| | | resultMap.put("confirmUser" + i, ""); |
| | | } |
| | | } |
| | | result.put("data", Collections.singletonList(resultMap)); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 周点检项列表 |
| | | * @param equipmentCode 设备编码 |
| | | * @param inspectionDate 点检日期 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public JSONObject exportWeekInsDetailList(String equipmentCode, String inspectionDate) { |
| | | // 创建结果对象 |
| | | JSONObject result = new JSONObject(); |
| | | List<EamWeekInsDetailResultResponse> eamWeekInsDetailResultResponseList = eamInspectionOrderMapper.findWeekInsDetailList(equipmentCode, inspectionDate); |
| | | if (eamWeekInsDetailResultResponseList == null || eamWeekInsDetailResultResponseList.isEmpty()) { |
| | | return result; |
| | | } |
| | | Map<EamWeekInsDetailResultResponse, List<EamWeekInsDetailResultResponse>> groupMap = eamWeekInsDetailResultResponseList |
| | | .stream().collect(Collectors.groupingBy( |
| | | // 分组键:包含 itemCode、itemName、itemDemand 的对象 |
| | | item -> new EamWeekInsDetailResultResponse( |
| | | item.getItemCode(), |
| | | item.getItemName(), |
| | | item.getItemDemand() |
| | | ), |
| | | // 用 TreeMap 作为容器,并指定按 itemCode 排序的比较器 |
| | | () -> new TreeMap<>(Comparator.comparingInt(EamWeekInsDetailResultResponse::getItemCode)), |
| | | // 收集每组的元素为 List |
| | | Collectors.toList() |
| | | )); |
| | | List<Map<String, Object>> resultList = new ArrayList<>(); |
| | | groupMap.forEach((weekInsDetailResultResponse, weekInsDetailResultResponseList) -> { |
| | | Map<String, Object> resultMap = new LinkedHashMap<>(); |
| | | resultMap.put("itemCode", weekInsDetailResultResponse.getItemCode()); |
| | | resultMap.put("itemName", weekInsDetailResultResponse.getItemName()); |
| | | resultMap.put("itemDemand", weekInsDetailResultResponse.getItemDemand()); |
| | | // 使用AtomicInteger作为计数器,从1开始 |
| | | AtomicInteger counter = new AtomicInteger(1); |
| | | Map<Integer, EamWeekInsDetailResultResponse> collect = weekInsDetailResultResponseList |
| | | .stream() |
| | | .collect(Collectors.toMap( |
| | | // 分组键:使用自增序号(从1开始) |
| | | item -> counter.getAndIncrement(), |
| | | // 值:直接使用当前对象 |
| | | item -> item, |
| | | // 合并函数:当同一序号有多个对象时(理论上不会发生),如何处理 |
| | | (existing, replacement) -> existing, // 若有重复键,保留已存在的对象 |
| | | // 指定Map的具体实现(可选) |
| | | LinkedHashMap::new // 保持插入顺序 |
| | | )); |
| | | for (int i = 1; i <= 5; i++) { |
| | | if (collect.containsKey(i)) { |
| | | String inspectionResult = ""; |
| | | switch (collect.get(i).getInspectionResult()) { |
| | | case "NORMAL": |
| | | inspectionResult = "√"; |
| | | break; |
| | | case "ANOMALY": |
| | | inspectionResult = "×"; |
| | | break; |
| | | case "FAULT": |
| | | inspectionResult = "△"; |
| | | break; |
| | | case "CLOSE": |
| | | inspectionResult = "T"; |
| | | break; |
| | | } |
| | | resultMap.put("inspectionResult" + i, inspectionResult); |
| | | } else { |
| | | resultMap.put("inspectionResult" + i, ""); |
| | | } |
| | | } |
| | | resultList.add(resultMap); |
| | | }); |
| | | result.put("data", resultList); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 周点检责任人列表 |
| | | * @param equipmentCode 设备编码 |
| | | * @param inspectionDate 点检日期 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public JSONObject exportWeekInsOrderDetailUserList(String equipmentCode, String inspectionDate) { |
| | | // 创建结果对象 |
| | | JSONObject result = new JSONObject(); |
| | | List<EamWeekInsDetailUserResponse> eamWeekInsDetailUserResponseList = eamInspectionOrderMapper.findWeekInsOrderDetailUserList(equipmentCode, inspectionDate); |
| | | if (eamWeekInsDetailUserResponseList == null || eamWeekInsDetailUserResponseList.isEmpty()) { |
| | | return result; |
| | | } |
| | | // 使用AtomicInteger作为计数器,从1开始 |
| | | AtomicInteger counter = new AtomicInteger(1); |
| | | Map<Integer, EamWeekInsDetailUserResponse> groupMap = eamWeekInsDetailUserResponseList |
| | | .stream() |
| | | .collect(Collectors.toMap( |
| | | // 分组键:使用自增序号(从1开始) |
| | | item -> counter.getAndIncrement(), |
| | | // 值:直接使用当前对象(作为初始值) |
| | | item -> item, |
| | | // 合并函数:当同一“天”有多个对象时,如何处理(这里示例取第一个) |
| | | (existing, replacement) -> existing // 若有重复键,保留已存在的对象 |
| | | )); |
| | | Map<String, Object> resultMap = new LinkedHashMap<>(); |
| | | for (int i = 1; i <= 5; i++) { |
| | | if (groupMap.containsKey(i)) { |
| | | EamWeekInsDetailUserResponse eamWeekInsDetailUserResponse = groupMap.get(i); |
| | | resultMap.put("operator" + i, sysDictService.queryTableDictTextByKey("sys_user", "realname", "username", eamWeekInsDetailUserResponse.getInspector())); |
| | | resultMap.put("confirmUser" + i, sysDictService.queryTableDictTextByKey("sys_user", "realname", "username", eamWeekInsDetailUserResponse.getConfirmUser())); |
| | | } else { |
| | | resultMap.put("operator" + i, ""); |
| | | resultMap.put("confirmUser" + i, ""); |
| | | } |
| | | } |
| | | result.put("data", Collections.singletonList(resultMap)); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<String> addInspectionOrder(EamInspectionOrderRequest eamInspectionOrderRequest) { |
| | |
| | | if (CollectionUtils.isNotEmpty(maintenanceStandardDetailList)) { |
| | | List<EamWeekInspectionDetail> weekInspectionDetailList = maintenanceStandardDetailList.stream().map(EamWeekInspectionDetail::new).collect(Collectors.toList()); |
| | | weekInspectionDetailList.forEach(weekInspectionDetail -> { |
| | | weekInspectionDetail.setEquipmentId(eamInspectionOrderRequest.getEquipmentId()); |
| | | weekInspectionDetail.setStandardId(eamInspectionOrderRequest.getStandardId()); |
| | | // TODO 周点检日期 |
| | | weekInspectionDetail.setPlanInspectionDate(eamInspectionOrderRequest.getInspectionDate()); |
| | |
| | | return (List<String>) object; |
| | | } |
| | | |
| | | @Override |
| | | public List<InspectionVo> findInspectionResult(String equipmentId, String itemDemand, String yearMonth) { |
| | | return this.baseMapper.findInspectionResult(equipmentId, itemDemand, yearMonth); |
| | | } |
| | | |
| | | @Override |
| | | public List<InspectionVo> findInspectionUser(String equipmentId, String yearMonth) { |
| | | return this.baseMapper.findInspectionUser(equipmentId, yearMonth); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> findInspectionStandard(String equipmentId) { |
| | | return this.baseMapper.findInspectionStandard(equipmentId); |
| | | } |
| | | } |