| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.task.api.Task; |
| | |
| | | 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.dto.DailyResponsibleInfo; |
| | | import org.jeecg.modules.eam.dto.EamInspectionOrderDetailExport; |
| | | import org.jeecg.modules.eam.dto.EamInspectionOrderExport; |
| | | import org.jeecg.modules.eam.dto.WeeklyResponsibleInfo; |
| | | import org.jeecg.modules.eam.request.*; |
| | | import org.jeecg.modules.system.entity.BaseFactory; |
| | | import org.jeecg.modules.system.entity.BaseFactoryUser; |
| | |
| | | import java.time.LocalDate; |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.format.DateTimeParseException; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | |
| | | if (sysUser == null) { |
| | | return page; |
| | | } |
| | | if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) { |
| | | if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) { |
| | | //选择了设备,根据设备id过滤设备 |
| | | List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(",")); |
| | | List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(",")); |
| | | queryWrapper.in("e.equipment_code", equipArr); |
| | | } else { |
| | | //没有选择设备,根据中心过滤设备 |
| | |
| | | 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(), |
| | | // 分组键:使用planInspectionDate字段落在本月的周数 |
| | | item -> { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(item.getPlanInspectionDate()); |
| | | return calendar.get(Calendar.WEEK_OF_MONTH); |
| | | }, |
| | | // 值:直接使用当前对象 |
| | | item -> item, |
| | | // 合并函数:当同一序号有多个对象时(理论上不会发生),如何处理 |
| | | (existing, replacement) -> existing, // 若有重复键,保留已存在的对象 |
| | | // 合并函数:当同一周有多个对象时(根据需求不会发生,但仍需提供) |
| | | (existing, replacement) -> existing, |
| | | // 指定Map的具体实现(可选) |
| | | LinkedHashMap::new // 保持插入顺序 |
| | | )); |
| | |
| | | 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(), |
| | | // 值:直接使用当前对象(作为初始值) |
| | | // 分组键:使用 planInspectionDate 字段落在本月的周数 |
| | | item -> { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(item.getPlanInspectionDate()); |
| | | return calendar.get(Calendar.WEEK_OF_MONTH); |
| | | }, |
| | | // 值:直接使用当前对象 |
| | | item -> item, |
| | | // 合并函数:当同一“天”有多个对象时,如何处理(这里示例取第一个) |
| | | (existing, replacement) -> existing // 若有重复键,保留已存在的对象 |
| | | // 合并函数:当同一周有多个对象时(根据需求不会发生) |
| | | (existing, replacement) -> existing, |
| | | // 使用 LinkedHashMap 保持插入顺序 |
| | | LinkedHashMap::new |
| | | )); |
| | | Map<String, Object> resultMap = new LinkedHashMap<>(); |
| | | for (int i = 1; i <= 5; i++) { |
| | |
| | | weekInspectionDetailList.forEach(weekInspectionDetail -> { |
| | | weekInspectionDetail.setEquipmentId(eamInspectionOrderRequest.getEquipmentId()); |
| | | weekInspectionDetail.setStandardId(eamInspectionOrderRequest.getStandardId()); |
| | | // TODO 周点检日期 |
| | | weekInspectionDetail.setPlanInspectionDate(eamInspectionOrderRequest.getInspectionDate()); |
| | | }); |
| | | eamWeekInspectionDetailService.saveBatch(weekInspectionDetailList); |
| | |
| | | updateEamInspectionOrder(eamInspectionOrder); |
| | | |
| | | //查询数据,进行设备维修处理 |
| | | if (eamInspectionOrder.getInspectionStatus().equals(InspectionStatus.WAIT_CONFIRM.name())) { |
| | | updateEamInspectionOrderDetail(eamInspectionOrder); |
| | | } |
| | | // if (eamInspectionOrder.getInspectionStatus().equals(InspectionStatus.WAIT_CONFIRM.name())) { |
| | | // updateEamInspectionOrderDetail(eamInspectionOrder); |
| | | // } |
| | | |
| | | return eamInspectionOrder; |
| | | } catch (Exception e) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 生产设备自主维护点检表打印 |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<EamInspectionOrderExport> printInspectionOrder(String ids) { |
| | | |
| | | List<EamInspectionOrderExport> eamInspectionOrderExports = |
| | | this.eamInspectionOrderMapper.queryList(Arrays.asList(ids.split(","))); |
| | | |
| | | if (eamInspectionOrderExports == null || eamInspectionOrderExports.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | eamInspectionOrderExports.forEach(eamInspectionOrderExport -> { |
| | | |
| | | // 日期处理 |
| | | if (StrUtil.isNotEmpty(eamInspectionOrderExport.getInspectionMonth())){ |
| | | if (eamInspectionOrderExport.getInspectionMonth().length() == 1) { |
| | | eamInspectionOrderExport.setInspectionMonth("0" + eamInspectionOrderExport.getInspectionMonth()); |
| | | } |
| | | } |
| | | String finalInspectionDate = eamInspectionOrderExport.getInspectionYear()+"-" + eamInspectionOrderExport.getInspectionMonth(); |
| | | // 获取该设备的日点检明细数据 |
| | | List<EamInsOrderDetailResultResponse> detailResponseList = |
| | | eamInspectionOrderMapper.findInsOrderDetailList( |
| | | eamInspectionOrderExport.getEquipmentCode(), |
| | | finalInspectionDate |
| | | ); |
| | | |
| | | if (!detailResponseList.isEmpty()) { |
| | | // 按项目分组存储(项目编码为key) |
| | | Map<Integer, EamInspectionOrderDetailExport> detailExportMap = new HashMap<>(); |
| | | |
| | | // 初始化项目信息(每个项目对应一个31天状态的对象) |
| | | detailResponseList.forEach(detail -> { |
| | | Integer itemCode = detail.getItemCode(); |
| | | EamInspectionOrderDetailExport export = detailExportMap.get(itemCode); |
| | | |
| | | if (export == null) { |
| | | // 创建新的点检项目对象 |
| | | export = new EamInspectionOrderDetailExport() |
| | | .setItemCode(itemCode) |
| | | .setItemName(detail.getItemName()) |
| | | .setItemDemand(detail.getItemDemand()) |
| | | .setDateFlag(new String[31]); // 初始化31天状态数组 |
| | | |
| | | detailExportMap.put(itemCode, export); |
| | | } |
| | | }); |
| | | |
| | | // 填充各项目每日的点检状态 |
| | | detailResponseList.forEach(detail -> { |
| | | Integer itemCode = detail.getItemCode(); |
| | | EamInspectionOrderDetailExport export = detailExportMap.get(itemCode); |
| | | |
| | | try { |
| | | Date newinspectionDate = detail.getInspectionDate(); |
| | | |
| | | // 处理空日期情况 |
| | | if (newinspectionDate == null) { |
| | | log.warn("检测到空日期值, itemCode: {}"); |
| | | return; |
| | | } |
| | | // 转换为LocalDate |
| | | LocalDate date = newinspectionDate.toInstant() |
| | | .atZone(ZoneId.systemDefault()) |
| | | .toLocalDate(); |
| | | int day = date.getDayOfMonth(); |
| | | // 安全设置日期状态 |
| | | if (day >= 1 && day <= 31) { |
| | | String[] dateFlags = export.getDateFlag(); |
| | | if (dateFlags == null) { |
| | | dateFlags = new String[31]; |
| | | export.setDateFlag(dateFlags); |
| | | } |
| | | if (StrUtil.isNotEmpty(detail.getInspectionResult())){ |
| | | switch (detail.getInspectionResult()) { |
| | | case "NORMAL": |
| | | dateFlags[day - 1] = "√"; |
| | | break; |
| | | case "ANOMALY": |
| | | dateFlags[day - 1] = "×"; |
| | | break; |
| | | case "FAULT": |
| | | dateFlags[day - 1] = "△"; |
| | | break; |
| | | case "CLOSE": |
| | | dateFlags[day - 1] = "T"; |
| | | break; |
| | | } |
| | | } |
| | | } else { |
| | | log.warn("非法日期值: {}, itemCode: {}"); |
| | | } |
| | | } |
| | | catch (DateTimeParseException | NullPointerException e) { |
| | | log.error("日期处理错误 - 原始值: {}, 项目: {}, 错误: {}"); |
| | | } |
| | | }); |
| | | // 将点检项目集合转换为列表 |
| | | List<EamInspectionOrderDetailExport> detailExports = |
| | | new ArrayList<>(detailExportMap.values()); |
| | | // 设置到主导出对象中 |
| | | eamInspectionOrderExport.setEamDailyInspectionList(detailExports); |
| | | }else { |
| | | eamInspectionOrderExport.setEamDailyInspectionList(null); |
| | | } |
| | | // 获取该设备的周点检明细数据 |
| | | List<EamWeekInsDetailResultResponse> eamWeekInsDetailResultResponseList = |
| | | eamInspectionOrderMapper.findWeekInsDetailList( |
| | | eamInspectionOrderExport.getEquipmentCode(), |
| | | finalInspectionDate |
| | | ); |
| | | if (!eamWeekInsDetailResultResponseList.isEmpty()) { |
| | | // 按项目分组存储(项目编码为key) |
| | | Map<Integer, EamInspectionOrderDetailExport> detailExportMap = new HashMap<>(); |
| | | // 初始化项目信息 |
| | | eamWeekInsDetailResultResponseList.forEach(detail -> { |
| | | Integer itemCode = detail.getItemCode(); |
| | | EamInspectionOrderDetailExport export = detailExportMap.get(itemCode); |
| | | if (export == null) { |
| | | // 创建新的点检项目对象并初始化weekFlag数组 |
| | | export = new EamInspectionOrderDetailExport() |
| | | .setItemCode(itemCode) |
| | | .setItemName(detail.getItemName()) |
| | | .setItemDemand(detail.getItemDemand()) |
| | | .setWeekFlag(new String[5]); // 明确初始化长度为5 |
| | | detailExportMap.put(itemCode, export); |
| | | } |
| | | }); |
| | | // 填充各项目每周的点检状态 |
| | | eamWeekInsDetailResultResponseList.forEach(detail -> { |
| | | Integer itemCode = detail.getItemCode(); |
| | | EamInspectionOrderDetailExport export = detailExportMap.get(itemCode); |
| | | |
| | | Date newinspectionDate = detail.getPlanInspectionDate(); |
| | | if (newinspectionDate == null) { |
| | | log.warn("检测到空日期值, itemCode: {}"); |
| | | return; |
| | | } |
| | | |
| | | // 计算该日期是当月第几周 (1-5) |
| | | int week = calculateWeekOfMonth(newinspectionDate); |
| | | |
| | | if (week >= 1 && week <= 5) { |
| | | String[] weekFlags = export.getWeekFlag(); |
| | | if (weekFlags == null) { |
| | | weekFlags = new String[31]; |
| | | export.setWeekFlag(weekFlags); |
| | | } |
| | | if (StrUtil.isNotEmpty(detail.getInspectionResult())){ |
| | | switch (detail.getInspectionResult()) { |
| | | case "NORMAL": |
| | | weekFlags[week - 1] = "√"; |
| | | break; |
| | | case "ANOMALY": |
| | | weekFlags[week - 1] = "×"; |
| | | break; |
| | | case "FAULT": |
| | | weekFlags[week - 1] = "△"; |
| | | break; |
| | | case "CLOSE": |
| | | weekFlags[week - 1] = "T"; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | // 将点检项目集合转换为列表 |
| | | List<EamInspectionOrderDetailExport> weekDetailExports = |
| | | new ArrayList<>(detailExportMap.values()); |
| | | // 设置到主导出对象中 |
| | | eamInspectionOrderExport.setEamWeeklyInspectionList(weekDetailExports); |
| | | }else { |
| | | eamInspectionOrderExport.setEamWeeklyInspectionList(null); |
| | | } |
| | | |
| | | |
| | | // ================== 添加日点检责任人信息 ================== |
| | | DailyResponsibleInfo dailyResponsible = new DailyResponsibleInfo(); |
| | | List<EamInsOrderDetailUserResponse> dailyUserResponses = |
| | | eamInspectionOrderMapper.findInspectionOrderDetailUserList( |
| | | eamInspectionOrderExport.getEquipmentCode(), |
| | | finalInspectionDate |
| | | ); |
| | | |
| | | if (dailyUserResponses != null && !dailyUserResponses.isEmpty()) { |
| | | dailyUserResponses.forEach(response -> { |
| | | try { |
| | | Date date = response.getInspectionDate(); |
| | | if (date == null) return; |
| | | |
| | | LocalDate localDate = date.toInstant() |
| | | .atZone(ZoneId.systemDefault()) |
| | | .toLocalDate(); |
| | | |
| | | int day = localDate.getDayOfMonth(); |
| | | if (day < 1 || day > 31) return; |
| | | |
| | | // 获取操作员和确认人姓名 |
| | | String operator = sysDictService.queryTableDictTextByKey( |
| | | "sys_user", "realname", "username", response.getOperator()); |
| | | String confirmUser = sysDictService.queryTableDictTextByKey( |
| | | "sys_user", "realname", "username", response.getConfirmUser()); |
| | | |
| | | // 设置责任人信息 |
| | | dailyResponsible.setResponsibleForDay(day, operator, confirmUser); |
| | | } catch (Exception e) { |
| | | log.error("处理日点检责任人信息出错: {}"); |
| | | } |
| | | }); |
| | | } |
| | | eamInspectionOrderExport.setDailyResponsibleInfo(dailyResponsible); |
| | | |
| | | // ================== 添加周点检责任人信息 ================== |
| | | WeeklyResponsibleInfo weeklyResponsible = new WeeklyResponsibleInfo(); |
| | | List<EamWeekInsDetailUserResponse> weeklyUserResponses = |
| | | eamInspectionOrderMapper.findWeekInsOrderDetailUserList( |
| | | eamInspectionOrderExport.getEquipmentCode(), |
| | | finalInspectionDate |
| | | ); |
| | | |
| | | if (weeklyUserResponses != null && !weeklyUserResponses.isEmpty()) { |
| | | weeklyUserResponses.forEach(response -> { |
| | | try { |
| | | Date date = response.getPlanInspectionDate(); |
| | | if (date == null) return; |
| | | |
| | | // 计算周数 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(date); |
| | | int week = calendar.get(Calendar.WEEK_OF_MONTH); |
| | | if (week < 1 || week > 5) return; |
| | | |
| | | // 获取操作员和确认人姓名 |
| | | String operator = sysDictService.queryTableDictTextByKey( |
| | | "sys_user", "realname", "username", response.getInspector()); |
| | | String confirmUser = sysDictService.queryTableDictTextByKey( |
| | | "sys_user", "realname", "username", response.getConfirmUser()); |
| | | |
| | | // 设置责任人信息 |
| | | weeklyResponsible.setResponsibleForWeek(week, operator, confirmUser); |
| | | } catch (Exception e) { |
| | | log.error("处理周点检责任人信息出错: {}"); |
| | | } |
| | | }); |
| | | } |
| | | eamInspectionOrderExport.setWeeklyResponsibleInfo(weeklyResponsible); |
| | | }); |
| | | |
| | | return eamInspectionOrderExports; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 计算日期在当月是第几周(1-5) |
| | | */ |
| | | private int calculateWeekOfMonth(Date date) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(date); |
| | | return calendar.get(Calendar.WEEK_OF_MONTH); |
| | | } |
| | | |
| | | private boolean isValidRequest(EamInspectionOrderRequest request) { |
| | | return StrUtil.isNotBlank(request.getTaskId()) && StrUtil.isNotBlank(request.getDataId()); |
| | |
| | | values.put("organization", request.getConfirmComment()); |
| | | values.put("comment", request.getConfirmComment()); |
| | | values.put("confirmation", request.getConfirmDealType()); |
| | | request.setComment(request.getConfirmComment()); |
| | | request.setComment("维修工确认结束"); |
| | | if ("2".equals(request.getConfirmDealType())) { |
| | | // 维修工驳回 |
| | | List<String> usernames = new ArrayList<>(); |
| | | usernames.add(order.getOperator()); |
| | | order.setInspectionStatus(InspectionStatus.UNDER_INSPECTION.name()); |
| | | values.put("NextAssignee", usernames); |
| | | request.setComment("维修工驳回结束"); |
| | | } |
| | | } |
| | | request.setValues(values); |