Lius
2025-04-21 63998f305e26b10676dad4f836b0987c55160489
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamWeekMaintenanceOrderServiceImpl.java
@@ -3,6 +3,7 @@
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.extension.plugins.pagination.Page;
@@ -20,19 +21,15 @@
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.eam.constant.BusinessCodeConst;
import org.jeecg.modules.eam.constant.OrderCreationMethodEnum;
import org.jeecg.modules.eam.constant.WeekMaintenanceStatusEnum;
import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
import org.jeecg.modules.eam.constant.*;
import org.jeecg.modules.eam.entity.EamEquipment;
import org.jeecg.modules.eam.entity.EamWeekMaintenanceOrder;
import org.jeecg.modules.eam.entity.EamWeekMaintenanceOrderDetail;
import org.jeecg.modules.eam.mapper.EamWeekMaintenanceOrderMapper;
import org.jeecg.modules.eam.request.EamWeekMaintenanceQuery;
import org.jeecg.modules.eam.request.EamWeekMaintenanceRequest;
import org.jeecg.modules.eam.service.IEamEquipmentService;
import org.jeecg.modules.eam.service.IEamReportRepairService;
import org.jeecg.modules.eam.service.IEamWeekMaintenanceOrderDetailService;
import org.jeecg.modules.eam.service.IEamWeekMaintenanceOrderService;
import org.jeecg.modules.eam.service.*;
import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness;
import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService;
import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI;
@@ -81,10 +78,16 @@
    private IEamEquipmentService eamEquipmentService;
    @Autowired
    private IEamReportRepairService eamReportRepairService;
    @Autowired
    private IEamEquipmentExtendService eamEquipmentExtendService;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addWeekMaintenance(EamWeekMaintenanceRequest request) {
        EamEquipment equipment = eamEquipmentService.getById(request.getEquipmentId());
        if (equipment == null) {
            throw new JeecgBootException("设备不存在,添加失败!");
        }
        EamWeekMaintenanceOrder order = new EamWeekMaintenanceOrder();
        order.setOrderNum(request.getOrderNum());
        order.setEquipmentId(request.getEquipmentId());
@@ -94,7 +97,7 @@
        order.setRemark(request.getRemark());
        //状态初始化
        order.setMaintenanceStatus(WeekMaintenanceStatusEnum.WAIT_MAINTENANCE.name());
        order.setCreationMethod(OrderCreationMethodEnum.MANUAL.name());
        order.setCreationMethod(request.getCreationMethod());
        //删除标记
        order.setDelFlag(CommonConstant.DEL_FLAG_0);
        eamWeekMaintenanceOrderMapper.insert(order);
@@ -109,7 +112,7 @@
        //判断是否存在保养人 如果存在则启动流程
        if (StringUtils.isNotBlank(order.getOperator())) {
            //启动流程
            flowCommonService.initActBusiness("工单号:" + order.getOrderNum() + ";开始进行设备周保",
            flowCommonService.initActBusiness("工单号:" + order.getOrderNum() + ";设备编号: " + equipment.getEquipmentCode() + ";进行设备周保",
                    order.getId(), "IEamWeekMaintenanceOrderService", "week_maintenance_process", null);
            Map<String, Object> variables = new HashMap<>();
            variables.put("dataId", order.getId());
@@ -132,6 +135,8 @@
                eamWeekMaintenanceOrderMapper.updateById(order);
                return result.isSuccess();
            }
            //更新设备保养状态
            eamEquipmentExtendService.updateEquipmentMaintenanceStatus(order.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name());
        }
        return true;
@@ -191,6 +196,10 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean editWeekMaintenance(EamWeekMaintenanceRequest request) {
        EamEquipment equipment = eamEquipmentService.getById(request.getEquipmentId());
        if (equipment == null) {
            throw new JeecgBootException("设备不存在,添加失败!");
        }
        EamWeekMaintenanceOrder entity = eamWeekMaintenanceOrderMapper.selectById(request.getId());
        if (entity == null) {
            throw new JeecgBootException("编辑的数据已删除,请刷新重试!");
@@ -229,7 +238,7 @@
        //判断是否存在保养人 如果存在则启动流程
        if (StringUtils.isNotBlank(entity.getOperator())) {
            //启动流程
            flowCommonService.initActBusiness("工单号:" + entity.getOrderNum() + ";开始进行设备周保",
            flowCommonService.initActBusiness("工单号:" + entity.getOrderNum() + ";设备编号: " + equipment.getEquipmentCode() + ";进行设备周保",
                    entity.getId(), "IEamWeekMaintenanceOrderService", "week_maintenance_process", null);
            Map<String, Object> variables = new HashMap<>();
            variables.put("dataId", entity.getId());
@@ -252,6 +261,8 @@
                eamWeekMaintenanceOrderMapper.updateById(entity);
                return result.isSuccess();
            }
            //更新设备保养状态
            eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name());
        }
        return true;
    }
@@ -266,6 +277,10 @@
        if (!WeekMaintenanceStatusEnum.WAIT_MAINTENANCE.name().equals(entity.getMaintenanceStatus())) {
            throw new JeecgBootException("该工单已进行过领取!");
        }
        EamEquipment equipment = eamEquipmentService.getById(entity.getEquipmentId());
        if (equipment == null) {
            throw new JeecgBootException("设备不存在,添加失败!");
        }
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        entity.setOperator(sysUser.getUsername());
        entity.setMaintenanceStatus(WeekMaintenanceStatusEnum.UNDER_MAINTENANCE.name());
@@ -273,7 +288,7 @@
        eamWeekMaintenanceOrderMapper.updateById(entity);
        //启动流程
        flowCommonService.initActBusiness("工单号:" + entity.getOrderNum() + ";开始进行设备周保",
        flowCommonService.initActBusiness("工单号:" + entity.getOrderNum() + ";设备编号: " + equipment.getEquipmentCode() + ";进行设备周保",
                entity.getId(), "IEamWeekMaintenanceOrderService", "week_maintenance_process", null);
        Map<String, Object> variables = new HashMap<>();
        variables.put("dataId", entity.getId());
@@ -290,6 +305,8 @@
        variables.put("NextAssignee", usernames);
        Result result = flowDefinitionService.startProcessInstanceByKey("week_maintenance_process", variables);
        if (result != null) {
            //更新设备保养状态
            eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name());
            return result.isSuccess();
        }
        return true;
@@ -297,7 +314,8 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean approval(EamWeekMaintenanceRequest request) {
    @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.WEEK_MAINTENANCE, businessTable = "eam_week_maintenance_order")
    public EamWeekMaintenanceOrder approval(EamWeekMaintenanceRequest request) {
        EamWeekMaintenanceOrder entity = eamWeekMaintenanceOrderMapper.selectById(request.getId());
        if (entity == null) {
            throw new JeecgBootException("审批的数据已删除,请刷新重试!");
@@ -330,7 +348,7 @@
        WeekMaintenanceStatusEnum status = WeekMaintenanceStatusEnum.getInstance(entity.getMaintenanceStatus());
        if (status == null) {
            return false;
            return null;
        }
        //流程变量
        Map<String, Object> values = new HashMap<>();
@@ -365,9 +383,11 @@
                if (CollectionUtil.isNotEmpty(request.getTableDetailList())) {
                    eamWeekMaintenanceOrderDetailService.updateBatchById(request.getTableDetailList());
                }
                //更新设备保养状态
                eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.WAIT_CONFIRM.name());
                break;
            case WAIT_CONFIRM:
                if(StringUtils.isBlank(equipment.getEquipmentManager())) {
                if (StringUtils.isBlank(equipment.getEquipmentManager())) {
                    throw new JeecgBootException("设备未分配设备管理员,无法进入下级审批!");
                }
                //班组长确认
@@ -384,6 +404,7 @@
                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<>();
@@ -446,6 +467,8 @@
                        log.error("JSON转换失败:" + e.getMessage(), e);
                    }
                }
                //更新设备保养状态
                eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.NORMAL.name());
                break;
        }
        request.setValues(values);
@@ -457,7 +480,19 @@
        }
        //保存工单
        eamWeekMaintenanceOrderMapper.updateById(entity);
        return true;
        return entity;
    }
    @Override
    public List<EamWeekMaintenanceOrder> selectUnCompleteOrder(String expiredDate) {
        LambdaQueryWrapper<EamWeekMaintenanceOrder> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.lt(EamWeekMaintenanceOrder::getMaintenanceDate, expiredDate);
        List<String> unCompleteStatus = new ArrayList<>();
        unCompleteStatus.add(WeekMaintenanceStatusEnum.WAIT_MAINTENANCE.name());
        unCompleteStatus.add(WeekMaintenanceStatusEnum.UNDER_MAINTENANCE.name());
        queryWrapper.in(EamWeekMaintenanceOrder::getMaintenanceStatus, unCompleteStatus);
        queryWrapper.orderByAsc(EamWeekMaintenanceOrder::getMaintenanceDate);
        return eamWeekMaintenanceOrderMapper.selectList(queryWrapper);
    }
    private boolean isUserAuthorized(FlowMyBusiness flowMyBusiness, LoginUser user) {