lyh
2025-07-12 097313810e7f44078a5244f794e945269a665d72
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamSecondMaintenanceOrderServiceImpl.java
@@ -39,6 +39,7 @@
import org.jeecg.modules.system.service.IBaseFactoryUserService;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.system.vo.UserSelector;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -82,6 +83,10 @@
    private IEamReportRepairService eamReportRepairService;
    @Autowired
    private IEamEquipmentExtendService eamEquipmentExtendService;
    @Autowired
    private IEamBaseHFCodeService hfCodeService;
    @Autowired
    private IEamMaintenanceStandardDetailService eamMaintenanceStandardDetailService;
    @Override
    public IPage<EamSecondMaintenanceOrder> queryPageList(Page<EamSecondMaintenanceOrder> page, EamSecondMaintenanceQuery query) {
@@ -155,6 +160,12 @@
        order.setStandardId(request.getStandardId());
        order.setMaintenanceDate(request.getMaintenanceDate());
        order.setOperator(request.getOperator());
        //技术状态鉴定表
        EamBaseHFCode eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.SECOND_MAINTENANCE.name());
        if(eamBaseHFCode == null) {
            throw new JeecgBootException("未配置技术状态鉴定表的HF编码,添加失败!");
        }
        order.setHfCode(eamBaseHFCode.getHfCode());
        order.setRemark(request.getRemark());
        //状态初始化
        order.setMaintenanceStatus(SecondMaintenanceStatusEnum.WAIT_MAINTENANCE.name());
@@ -163,43 +174,17 @@
        order.setDelFlag(CommonConstant.DEL_FLAG_0);
        eamSecondMaintenanceOrderMapper.insert(order);
        //处理明细数据
        if (CollectionUtil.isNotEmpty(request.getTableDetailList())) {
            request.getTableDetailList().forEach(tableDetail -> {
                tableDetail.setId(null);
                tableDetail.setOrderId(order.getId());
        List<EamMaintenanceStandardDetail> eamMaintenanceStandardDetailList= eamMaintenanceStandardDetailService.selectByStandardId(order.getStandardId());
        List<EamSecondMaintenanceOrderDetail> requestTableDetailList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(eamMaintenanceStandardDetailList)) {
            eamMaintenanceStandardDetailList.forEach(item -> {
                EamSecondMaintenanceOrderDetail detail = new EamSecondMaintenanceOrderDetail();
                BeanUtils.copyProperties(item, detail);
                detail.setOrderId(order.getId());
                requestTableDetailList.add(detail);
            });
            secondMaintenanceOrderDetailService.saveBatch(request.getTableDetailList());
            secondMaintenanceOrderDetailService.saveBatch(requestTableDetailList);
        }
        //判断是否存在保养人 如果存在则启动流程
        if (StringUtils.isNotBlank(order.getOperator())) {
            //启动流程
            flowCommonService.initActBusiness("工单号: " + order.getOrderNum() + ";设备编号: " + equipment.getEquipmentCode() + ";安装位置" + equipment.getInstallationPosition(),
                    order.getId(), "IEamSecondMaintenanceOrderService", "second_maintenance_process", null);
            Map<String, Object> variables = new HashMap<>();
            variables.put("dataId", order.getId());
            if (StrUtil.isEmpty(order.getRemark())) {
                variables.put("organization", "新增二保工单默认启动流程");
                variables.put("comment", "新增二保工单默认启动流程");
            } else {
                variables.put("organization", order.getRemark());
                variables.put("comment", order.getRemark());
            }
            variables.put("proofreading", true);
            List<String> usernames = new ArrayList<>();
            usernames.add(order.getOperator());
            variables.put("NextAssignee", usernames);
            Result result = flowDefinitionService.startProcessInstanceByKey("second_maintenance_process", variables);
            if (result != null) {
                //更新周保状态
                order.setMaintenanceStatus(SecondMaintenanceStatusEnum.UNDER_MAINTENANCE.name());
                order.setActualStartTime(new Date());
                eamSecondMaintenanceOrderMapper.updateById(order);
                //更新设备保养状态
                eamEquipmentExtendService.updateEquipmentMaintenanceStatus(order.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_SECOND_MAINTENANCE.name());
                return result.isSuccess();
            }
        }
        return true;
    }
@@ -218,33 +203,9 @@
            throw new JeecgBootException("只有待保养状态的数据才可编辑!");
        }
        entity.setMaintenanceDate(request.getMaintenanceDate());
        entity.setOperator(request.getOperator());
        entity.setRemark(request.getRemark());
        eamSecondMaintenanceOrderMapper.updateById(entity);
        //处理详情
        if (CollectionUtil.isNotEmpty(request.getTableDetailList())) {
            List<EamSecondMaintenanceOrderDetail> addList = new ArrayList<>();
            List<EamSecondMaintenanceOrderDetail> updateList = new ArrayList<>();
            request.getTableDetailList().forEach(tableDetail -> {
                tableDetail.setOrderId(entity.getId());
                if (tableDetail.getId() == null) {
                    addList.add(tableDetail);
                } else {
                    updateList.add(tableDetail);
                }
            });
            if (CollectionUtil.isNotEmpty(addList)) {
                secondMaintenanceOrderDetailService.saveBatch(addList);
            }
            if (CollectionUtil.isNotEmpty(updateList)) {
                secondMaintenanceOrderDetailService.updateBatchById(updateList);
            }
        }
        if (CollectionUtil.isNotEmpty(request.getRemoveDetailList())) {
            List<String> ids = request.getRemoveDetailList().stream().map(EamSecondMaintenanceOrderDetail::getId).collect(Collectors.toList());
            secondMaintenanceOrderDetailService.removeBatchByIds(ids);
        }
        //判断是否存在保养人 如果存在则启动流程
        if (StringUtils.isNotBlank(entity.getOperator())) {
            //启动流程
@@ -385,10 +346,6 @@
                //设置entity
                entity.setMaintenanceStatus(SecondMaintenanceStatusEnum.WAIT_CONFIRM.name());
                entity.setActualEndTime(new Date());
                //处理详情
                if (CollectionUtil.isNotEmpty(request.getTableDetailList())) {
                    secondMaintenanceOrderDetailService.updateBatchById(request.getTableDetailList());
                }
                //更新设备保养状态
                eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.SECOND_MAINTENANCE_WAIT_CONFIRM.name());
                break;
@@ -399,33 +356,12 @@
                }
                //班组长确认
                userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                values.put("dataId", entity.getId());
                values.put("organization", request.getConfirmComment());
                values.put("comment", request.getConfirmComment());
                values.put("NextAssignee", userApprovalList);
                values.put("confirmation", request.getConfirmDealType());
                request.setComment(request.getConfirmComment());
                //设置entity
                entity.setMaintenanceStatus(SecondMaintenanceStatusEnum.WAIT_LEADER_CONFIRM.name());
                entity.setConfirmTime(new Date());
                if (CommonConstant.HAS_CANCLE.equals(request.getConfirmDealType())) {
                    //驳回
                    userApprovalList = new ArrayList<>();
                    userApprovalList.add(entity.getOperator());
                    values.put("NextAssignee", userApprovalList);
                    entity.setMaintenanceStatus(WeekMaintenanceStatusEnum.UNDER_MAINTENANCE.name());
                }
                //处理报修
                List<EamSecondMaintenanceOrderDetail> collect = request.getTableDetailList().stream().filter((detail) -> CommonConstant.DEFAULT_1.equals(detail.getReportFlag())).collect(Collectors.toList());
                if (CollectionUtil.isNotEmpty(collect)) {
                    eamReportRepairService.reportRepairFromSecondMaintenance(equipment.getId(), entity.getOperator(), collect);
                }
                break;
            case WAIT_LEADER_CONFIRM:
                values.put("dataId", entity.getId());
                values.put("organization", request.getLeaderConfirmComment());
                values.put("comment", request.getLeaderConfirmComment());
                request.setComment(request.getLeaderConfirmComment());
                //设置entity
                entity.setMaintenanceStatus(SecondMaintenanceStatusEnum.COMPLETE.name());
                //更新设备保养状态