| | |
| | | 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 { |
| | | //没有选择设备,根据中心过滤设备 |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 生产设备自主维护点检表打印 |
| | | * @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()); |