Lius
7 天以前 0a19d4923b0a048aee0cda91c37f25bc6e140d54
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamSecondMaintenanceOrderServiceImpl.java
@@ -3,12 +3,12 @@
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.flowable.engine.TaskService;
@@ -33,8 +33,13 @@
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.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.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;
@@ -66,7 +71,10 @@
    private TaskService taskService;
    @Autowired
    private IFlowTaskService flowTaskService;
    @Autowired
    private IBaseFactoryUserService baseFactoryUserService;
    @Autowired
    private IBaseFactoryService baseFactoryService;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
@@ -75,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) {
@@ -84,16 +96,27 @@
        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 {
            //没有选择设备,根据车间过滤设备
            queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=e.org_id ", sysUser.getId());
            //没有选择设备,根据中心过滤设备
            List<BaseFactoryUser> baseFactoryUserList=baseFactoryUserService.
                    list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId,sysUser.getId()));
            if(!CollectionUtils.isEmpty(baseFactoryUserList)){
                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
                Set<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
                queryWrapper.in("e.factory_org_code", factoryCode);
            } else {
                return page;
            }
        }
        //查询条件过滤
        if (query != null) {
            if (StringUtils.isNotBlank(query.getId())){
                queryWrapper.eq("wmo.id", query.getId());
            }
            if (StringUtils.isNotBlank(query.getEquipmentId())) {
                queryWrapper.eq("wmo.equipment_id", query.getEquipmentId());
            }
@@ -140,6 +163,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());
@@ -148,43 +177,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;
    }
@@ -203,33 +206,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())) {
            //启动流程
@@ -278,17 +257,28 @@
            throw new JeecgBootException("设备不存在,添加失败!");
        }
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if(sysUser == null || !BusinessCodeConst.PCR0001.equals(sysUser.getPost())) {
            throw new JeecgBootException("不是操作工,无法领取此工单!");
        if(sysUser != null) {
            if (!BusinessCodeConst.PCR0001.equals(sysUser.getPost()) && !BusinessCodeConst.PCR0002.equals(sysUser.getPost())){
                throw new JeecgBootException("不是操作工,无法领取此工单!");
            }
        }
        entity.setOperator(sysUser.getUsername());
        List<String> usernames = new ArrayList<>();
        if (sysUser != null) {
            if (BusinessCodeConst.PCR0001.equals(sysUser.getPost())) {
                entity.setOperator(sysUser.getUsername());
                usernames.add(entity.getOperator());
            }
            if (BusinessCodeConst.PCR0002.equals(sysUser.getPost())) {
                entity.setRepairman(sysUser.getUsername());
                usernames.add(entity.getRepairman());
            }
        }
        entity.setMaintenanceStatus(SecondMaintenanceStatusEnum.UNDER_MAINTENANCE.name());
        entity.setActualStartTime(new Date());
        eamSecondMaintenanceOrderMapper.updateById(entity);
        //启动流程
        flowCommonService.initActBusiness("工单号: " + entity.getOrderNum() + ";设备编号: " + equipment.getEquipmentCode() + ";安装位置" + equipment.getInstallationPosition(),
                entity.getId(), "IEamSecondMaintenanceOrderService", "second_maintenance_process", null);
        flowCommonService.initActBusiness("工单号: " + entity.getOrderNum() + ";设备编号: " + equipment.getEquipmentCode() + "进行设备二级保养",
                entity.getId(), "IEamSecondMaintenanceOrderService", "SecondMaintenance_Process", null);
        Map<String, Object> variables = new HashMap<>();
        variables.put("dataId", entity.getId());
        if (StrUtil.isEmpty(entity.getRemark())) {
@@ -299,10 +289,24 @@
            variables.put("comment", entity.getRemark());
        }
        variables.put("proofreading", true);
        List<String> usernames = new ArrayList<>();
        usernames.add(entity.getOperator());
        variables.put("NextAssignee", usernames);
        Result result = flowDefinitionService.startProcessInstanceByKey("second_maintenance_process", variables);
        if (sysUser != null) {
            if (BusinessCodeConst.PCR0001.equals(sysUser.getPost())) {
                variables.put("operator_task", usernames);
                List<UserSelector> userSelectorList = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0002);
                if (!CollectionUtils.isEmpty(userSelectorList)) {
                    List<String> usernameList = userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                    variables.put("maintenance_task",usernameList);
                }
            }else if (BusinessCodeConst.PCR0002.equals(sysUser.getPost())) {
                variables.put("maintenance_task", usernames);
                List<UserSelector> userSelectorList = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0001);
                if (!CollectionUtils.isEmpty(userSelectorList)) {
                    List<String> usernameList = userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                    variables.put("operator_task",usernameList);
                }
            }
        }
        Result result = flowDefinitionService.startProcessInstanceByKey("SecondMaintenance_Process", variables);
        if (result != null) {
            //更新设备保养状态
            eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_SECOND_MAINTENANCE.name());
@@ -326,7 +330,7 @@
        }
        request.setAssignee(user.getUsername());
        // 获取流程业务记录
        FlowMyBusiness flowMyBusiness = flowMyBusinessService.getFlowMyBusiness(request.getInstanceId());
        FlowMyBusiness flowMyBusiness = flowMyBusinessService.getFlowMyBusiness(request.getInstanceId(), request.getTaskId());
        if (flowMyBusiness == null) {
            throw new JeecgBootException("流程实例不存在,请刷新后重试!");
        }
@@ -355,87 +359,105 @@
        List<UserSelector> userSelectors;
        switch (status) {
            case UNDER_MAINTENANCE:
                //保养中
                boolean parallelCompletion = flowTaskService.checkParallelCompletion(flowMyBusiness.getTaskId());
                //执行完成
                //设备管理员确认
//                String equipmentManager = equipment.getEquipmentManager();
//                if(StringUtils.isBlank(equipmentManager)) {
//                    throw new JeecgBootException("设备未分配设备管理员,无法进入下级审批!");
//                }
//                userApprovalList = Collections.singletonList(equipmentManager);
                values.put("dataId", entity.getId());
                values.put("organization", "二保执行结束");
                values.put("comment", "二保执行结束");
//                values.put("NextAssignee", userApprovalList);
                request.setComment("二保执行结束");
                //设置entity
                entity.setMaintenanceStatus(SecondMaintenanceStatusEnum.WAIT_CONFIRM.name());
                entity.setActualEndTime(new Date());
                //处理附件
                if (CollectionUtil.isNotEmpty(request.getImageFilesResult())) {
                    List<FileUploadResult> fileUploadResultList = request.getImageFilesResult();
                    ObjectMapper mapper = new ObjectMapper();
                    try {
                        String referenceFile = mapper.writeValueAsString(fileUploadResultList);
                        entity.setImageFiles(referenceFile);
                    } catch (JsonProcessingException e) {
                        log.error("JSON转换失败:" + e.getMessage(), e);
                 userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0004);
                if (CollectionUtil.isEmpty(userSelectors)) {
                    throw new JeecgBootException("设备未存在管理员,无法进入下级审批!");
                }else{
                    userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                    if (parallelCompletion) {
                        values.put("NextAssignee", userApprovalList);
                        entity.setMaintenanceStatus(SecondMaintenanceStatusEnum.WAIT_ADMIN_CONFIRM.name());
                        entity.setActualEndTime(new Date());
                    }
                }
                //处理详情
                if (CollectionUtil.isNotEmpty(request.getTableDetailList())) {
                    secondMaintenanceOrderDetailService.updateBatchById(request.getTableDetailList());
                if (BusinessCodeConst.PCR0001.equals(user.getPost())) {
                    entity.setOperator(user.getUsername());
                    values.put("organization", "二保操作工执行结束");
                    values.put("comment", "二保操作工执行结束");
                    request.setComment("二保操作工执行结束");
                    //处理对应详情
                    if (CollectionUtils.isNotEmpty(request.getTableDetailList())){
                        //删除原有数据
                        List<EamSecondMaintenanceOrderDetail> addList = new ArrayList<>();
                        //先删除原有
                        LambdaQueryWrapper<EamSecondMaintenanceOrderDetail> queryWrapper = new LambdaQueryWrapper<>();
                        queryWrapper.eq(EamSecondMaintenanceOrderDetail::getOrderId, entity.getId());
                        queryWrapper.eq(EamSecondMaintenanceOrderDetail::getItemCategory,EamMaintenanceStandardDetailCategory.OPERATOR_MAINTENANCE.name());
                        secondMaintenanceOrderDetailService.remove(queryWrapper);
                        request.getTableDetailList().forEach(tableDetail -> {
                            EamSecondMaintenanceOrderDetail eamMaintenanceStandardDetail=new EamSecondMaintenanceOrderDetail();
                            BeanUtils.copyProperties(tableDetail, eamMaintenanceStandardDetail);
                            eamMaintenanceStandardDetail.setOrderId(entity.getId());
                            addList.add(eamMaintenanceStandardDetail);
                        });
                        secondMaintenanceOrderDetailService.saveBatch(addList);
                    }
                }else if (BusinessCodeConst.PCR0002.equals(user.getPost())) {
                    entity.setRepairman(user.getUsername());
                    values.put("organization", "二保维修工执行结束");
                    values.put("comment", "二保维修工执行结束");
                    request.setComment("二保维修工执行结束");
                    //处理对应详情
                    if (CollectionUtils.isNotEmpty(request.getTableDetailList())){
                        //删除原有数据
                        List<EamSecondMaintenanceOrderDetail> addList = new ArrayList<>();
                        //先删除原有
                        LambdaQueryWrapper<EamSecondMaintenanceOrderDetail> queryWrapper = new LambdaQueryWrapper<>();
                        queryWrapper.eq(EamSecondMaintenanceOrderDetail::getOrderId, entity.getId());
                        queryWrapper.eq(EamSecondMaintenanceOrderDetail::getItemCategory,EamMaintenanceStandardDetailCategory.REPAIRER_MAINTENANCE.name());
                        secondMaintenanceOrderDetailService.remove(queryWrapper);
                        request.getTableDetailList().forEach(tableDetail -> {
                            EamSecondMaintenanceOrderDetail eamMaintenanceStandardDetail=new EamSecondMaintenanceOrderDetail();
                            BeanUtils.copyProperties(tableDetail, eamMaintenanceStandardDetail);
                            eamMaintenanceStandardDetail.setOrderId(entity.getId());
                            addList.add(eamMaintenanceStandardDetail);
                        });
                        secondMaintenanceOrderDetailService.saveBatch(addList);
                    }
                }
                //更新设备保养状态
                eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.SECOND_MAINTENANCE_WAIT_CONFIRM.name());
                values.put("dataId", entity.getId());
                break;
            case WAIT_CONFIRM:
                userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(),null, BusinessCodeConst.PCR0003);
            case WAIT_ADMIN_CONFIRM:
                //管理员确认
                userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0006);
                if (CollectionUtil.isEmpty(userSelectors)) {
                    throw new JeecgBootException("设备未分配给车间班组长,无法进入下级审批!");
                }
                //班组长确认
                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.setConfirmUser(user.getUsername());
                entity.setConfirmComment(request.getConfirmComment());
                entity.setConfirmTime(new Date());
                entity.setConfirmDealType(request.getConfirmDealType());
                if (CommonConstant.HAS_CANCLE.equals(request.getConfirmDealType())) {
                    //驳回
                    userApprovalList = new ArrayList<>();
                    userApprovalList.add(entity.getOperator());
                    throw new JeecgBootException("设备未存在检查人,无法进入下级审批!");
                }else{
                    userApprovalList= userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                    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);
                    values.put("dataId", entity.getId());
                    values.put("organization",request.getDealDescription());
                    values.put("comment", request.getDealDescription());
                    values.put("manageUserResult",request.getManageUserResult());
                    entity.setMaintenanceStatus(SecondMaintenanceStatusEnum.WAIT_INSPECTOR_CONFIRM.name());
                    entity.setManageUser(user.getUsername());
                    entity.setProblemDescription(request.getProblemDescription());
                    entity.setManageUserResult(request.getManageUserResult());
                    entity.setDealDescription(request.getDealDescription());
                    entity.setConfirmTime(new Date());
                    request.setComment(request.getDealDescription());
                }
                break;
            case WAIT_LEADER_CONFIRM:
            case WAIT_INSPECTOR_CONFIRM:
                //检查人确认
                values.put("dataId", entity.getId());
                values.put("organization", request.getLeaderConfirmComment());
                values.put("comment", request.getLeaderConfirmComment());
                request.setComment(request.getLeaderConfirmComment());
                //设置entity
                values.put("organization",request.getInspectConfirmComment());
                values.put("comment", request.getInspectConfirmComment());
                values.put("inspectorResult",request.getInspectorResult());
                entity.setMaintenanceStatus(SecondMaintenanceStatusEnum.COMPLETE.name());
                entity.setConfirmLeader(user.getUsername());
                entity.setLeaderConfirmComment(request.getLeaderConfirmComment());
                entity.setLeaderConfirmTime(new Date());
                //更新设备保养状态
                eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.NORMAL.name());
                entity.setInspector(user.getUsername());
                entity.setInspectorResult(request.getInspectorResult());
                entity.setInspectConfirmComment(request.getInspectConfirmComment());
                entity.setInspectConfirmTime(new Date());
                request.setComment(request.getDealDescription());
                break;
            default:
                throw  new JeecgBootException("审批失败");
        }
        request.setValues(values);
        // 完成流程任务
        Result result = flowTaskService.complete(request);
        if (!result.isSuccess()) {