zhangherong
2 天以前 b63d81722fa0fc56f3f6da7ccf8a294f15b8253a
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java
@@ -19,6 +19,7 @@
import org.jeecg.common.constant.DataBaseConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.StrUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
import org.jeecg.modules.eam.constant.*;
@@ -47,6 +48,7 @@
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@@ -90,6 +92,8 @@
    private ISysDictService sysDictService;
    @Resource
    private ISysUserService sysUserService;
    @Resource
    private IEamBaseHFCodeService eamBaseHFCodeService;
    @Override
    public IPage<EamInspectionOrder> queryPageList(Page<EamInspectionOrder> page, EamInspectionOrderQuery query) {
@@ -170,6 +174,14 @@
     */
    @Override
    public JSONObject exportInspectionOrderBaseInfo(String equipmentCode, String inspectionDate) {
        if (StrUtils.isEmpty(inspectionDate)) {
            // 获取当前日期
            LocalDate currentDate = LocalDate.now();
            // 定义日期格式
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
            // 格式化当前月份
            inspectionDate = currentDate.format(formatter);
        }
        // 创建结果对象
        JSONObject result = new JSONObject();
        EamInspectionOrderBaseResponse eamInspectionOrderBaseResponse = eamInspectionOrderMapper.findInsOrderBaseInfo(equipmentCode, inspectionDate);
@@ -189,6 +201,14 @@
     */
    @Override
    public JSONObject exportInspectionOrderDetailList(String equipmentCode, String inspectionDate) {
        if (StrUtils.isEmpty(inspectionDate)) {
            // 获取当前日期
            LocalDate currentDate = LocalDate.now();
            // 定义日期格式
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
            // 格式化当前月份
            inspectionDate = currentDate.format(formatter);
        }
        // 创建结果对象
        JSONObject result = new JSONObject();
        List<EamInsOrderDetailResultResponse> eamInsOrderDetailResultResponseList = eamInspectionOrderMapper.findInsOrderDetailList(equipmentCode, inspectionDate);
@@ -232,19 +252,21 @@
            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;
                    if (!StrUtils.isEmpty(collect.get(i).getInspectionResult())) {
                        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 {
@@ -265,6 +287,14 @@
     */
    @Override
    public JSONObject exportInspectionOrderDetailUserList(String equipmentCode, String inspectionDate) {
        if (StrUtils.isEmpty(inspectionDate)) {
            // 获取当前日期
            LocalDate currentDate = LocalDate.now();
            // 定义日期格式
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
            // 格式化当前月份
            inspectionDate = currentDate.format(formatter);
        }
        // 创建结果对象
        JSONObject result = new JSONObject();
        List<EamInsOrderDetailUserResponse> eamInsOrderDetailUserResponseList = eamInspectionOrderMapper.findInspectionOrderDetailUserList(equipmentCode, inspectionDate);
@@ -308,6 +338,14 @@
     */
    @Override
    public JSONObject exportWeekInsDetailList(String equipmentCode, String inspectionDate) {
        if (StrUtils.isEmpty(inspectionDate)) {
            // 获取当前日期
            LocalDate currentDate = LocalDate.now();
            // 定义日期格式
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
            // 格式化当前月份
            inspectionDate = currentDate.format(formatter);
        }
        // 创建结果对象
        JSONObject result = new JSONObject();
        List<EamWeekInsDetailResultResponse> eamWeekInsDetailResultResponseList = eamInspectionOrderMapper.findWeekInsDetailList(equipmentCode, inspectionDate);
@@ -333,36 +371,40 @@
            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 // 保持插入顺序
                    ));
            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;
                    if (!StrUtils.isEmpty(collect.get(i).getInspectionResult())) {
                        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 {
@@ -383,6 +425,14 @@
     */
    @Override
    public JSONObject exportWeekInsOrderDetailUserList(String equipmentCode, String inspectionDate) {
        if (StrUtils.isEmpty(inspectionDate)) {
            // 获取当前日期
            LocalDate currentDate = LocalDate.now();
            // 定义日期格式
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
            // 格式化当前月份
            inspectionDate = currentDate.format(formatter);
        }
        // 创建结果对象
        JSONObject result = new JSONObject();
        List<EamWeekInsDetailUserResponse> eamWeekInsDetailUserResponseList = eamInspectionOrderMapper.findWeekInsOrderDetailUserList(equipmentCode, inspectionDate);
@@ -394,12 +444,18 @@
        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++) {
@@ -429,6 +485,12 @@
        //修改状态
        eamInspectionOrder.setInspectionStatus(InspectionStatus.WAIT_INSPECTION.name());
        eamInspectionOrder.setDelFlag(CommonConstant.DEL_FLAG_0);
        //HF码处理
        EamBaseHFCode eamBaseHFCode = eamBaseHFCodeService.selectByCategory(HfTemplateCategoryEnum.INSPECTION.name());
        if (eamBaseHFCode == null) {
            return Result.error("添加失败,未配置点检HF编码!");
        }
        eamInspectionOrder.setHfCode(eamBaseHFCode.getHfCode());
        save(eamInspectionOrder);
        //处理日点检明细数据
        if (StrUtil.isNotBlank(eamInspectionOrderRequest.getStandardId())) {
@@ -479,7 +541,7 @@
        } else {
            eamInspectionOrder.setEquipmentId(equipment.getId());
        }
        flowCommonService.initActBusiness("工单号: " + eamInspectionOrder.getOrderNum() + ";设备编号: " + equipment.getEquipmentCode() + (equipment.getInstallationPosition() == null ? "" : ";安装位置: " + equipment.getInstallationPosition()),
        flowCommonService.initActBusiness("工单号: " + eamInspectionOrder.getOrderNum() + ";设备编号: " + equipment.getEquipmentCode(),
                eamInspectionOrder.getId(), "IEamInspectionOrderService", "eam_inspection", null);
        Map<String, Object> variables = new HashMap<>();
        variables.put("dataId", eamInspectionOrder.getId());
@@ -603,6 +665,19 @@
                throw new JeecgBootException("设备不存在,请检查!");
            }
            // 检查周保过期时间
            if (eamInspectionOrderRequest.getTableWeekDetailList() == null || eamInspectionOrderRequest.getTableWeekDetailList().isEmpty()) {
                List<EamWeekInspectionDetail> weekInspectionDetailList = eamWeekInspectionDetailService.list(new LambdaQueryWrapper<EamWeekInspectionDetail>().eq(EamWeekInspectionDetail::getStandardId, eamInspectionOrderRequest.getStandardId()).between(EamWeekInspectionDetail::getPlanInspectionDate, DateUtils.getFirstDayOfWeek(eamInspectionOrderRequest.getInspectionDate()), DateUtils.getLastDayOfWeek(eamInspectionOrderRequest.getInspectionDate())));
                if (weekInspectionDetailList != null && !weekInspectionDetailList.isEmpty()) {
                    if (StrUtil.isEmpty(eamInspectionOrderRequest.getOperator())) {
                        Date lastDate = DateUtils.getLastDayOfWeek(eamInspectionOrderRequest.getInspectionDate());
                        if (DateUtils.isSameDay(lastDate, new Date())) {
                            throw new JeecgBootException("本周点检未完成,请进行填报!");
                        }
                    }
                }
            }
            // 设置流程变量
            setupProcessVariables(eamInspectionOrderRequest, eamInspectionOrder, user, equipment);
@@ -616,9 +691,9 @@
            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) {
@@ -674,7 +749,10 @@
            values.put("organization", "点检人点检结束");
            values.put("comment", "点检人点检结束");
            // 获取下一步执行人
            List<UserSelector> userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), null, BusinessCodeConst.PCR0002);
            List<UserSelector> userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0002);
            if (CollectionUtil.isEmpty(userSelectors)) {
                throw new JeecgBootException("设备未分配给维修工,无法进入下级审批!");
            }
            List<String> userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
            values.put("NextAssignee", userApprovalList);
            request.setComment("点检人点检结束");
@@ -684,13 +762,14 @@
            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);