| | |
| | | package org.jeecg.modules.eam.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.task.api.Task; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.eam.constant.InspectionStatus; |
| | | import org.jeecg.modules.eam.entity.EamEquipment; |
| | | import org.jeecg.modules.eam.entity.EamInspectionOrder; |
| | | import org.jeecg.modules.eam.entity.EamInspectionOrderDetail; |
| | | import org.jeecg.modules.eam.mapper.EamInspectionOrderMapper; |
| | | import org.jeecg.modules.eam.request.EamInspectionOrderRequest; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentService; |
| | | import org.jeecg.modules.eam.service.IEamInspectionOrderDetailService; |
| | | import org.jeecg.modules.eam.service.IEamInspectionOrderService; |
| | | import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness; |
| | | import org.jeecg.modules.flowable.apithird.business.service.impl.FlowMyBusinessServiceImpl; |
| | | import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI; |
| | | 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.SysUser; |
| | | import org.jeecg.modules.system.service.IMdcUserProductionService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Description: 点检工单 |
| | |
| | | * @Date: 2025-04-02 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Service |
| | | public class EamInspectionOrderServiceImpl extends ServiceImpl<EamInspectionOrderMapper, EamInspectionOrder> implements IEamInspectionOrderService { |
| | | @Service("IEamInspectionOrderService") |
| | | public class EamInspectionOrderServiceImpl extends ServiceImpl<EamInspectionOrderMapper, EamInspectionOrder> implements IEamInspectionOrderService, FlowCallBackServiceI { |
| | | @Autowired |
| | | private IEamInspectionOrderDetailService eamInspectionOrderDetailService; |
| | | @Resource |
| | | private FlowCommonService flowCommonService; |
| | | @Resource |
| | | private IFlowDefinitionService flowDefinitionService; |
| | | @Autowired |
| | | private IFlowTaskService flowTaskService; |
| | | @Autowired |
| | | private IEamEquipmentService eamEquipmentService; |
| | | @Autowired |
| | | private FlowMyBusinessServiceImpl flowMyBusinessService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | @Autowired |
| | | private IEamEquipmentService iEamEquipmentService; |
| | | @Autowired |
| | | private IMdcUserProductionService mdcUserProductionService; |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean addInspectionOrder(EamInspectionOrderRequest eamInspectionOrderRequest) { |
| | | EamInspectionOrder eamInspectionOrder = new EamInspectionOrder(); |
| | | BeanUtils.copyProperties(eamInspectionOrderRequest,eamInspectionOrder); |
| | | //修改状态 |
| | | if (StrUtil.isNotBlank(eamInspectionOrderRequest.getOperator())){ |
| | | eamInspectionOrder.setInspectionStatus(InspectionStatus.IN_PROGRESS.getCode()); |
| | | }else { |
| | | eamInspectionOrder.setInspectionStatus(InspectionStatus.INIT.getCode()); |
| | | } |
| | | save(eamInspectionOrder); |
| | | //处理明细数据 |
| | | if(CollectionUtil.isNotEmpty(eamInspectionOrderRequest.getTableDetailList())) { |
| | | eamInspectionOrderRequest.getTableDetailList().forEach(tableDetail -> { |
| | | tableDetail.setOrderId(eamInspectionOrder.getId()); |
| | | tableDetail.setId(null); |
| | | }); |
| | | eamInspectionOrderDetailService.saveBatch(eamInspectionOrderRequest.getTableDetailList()); |
| | | } |
| | | if (StrUtil.isNotBlank(eamInspectionOrderRequest.getOperator())){ |
| | | triggerProcess(eamInspectionOrder); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 触发流程 |
| | | * @param eamInspectionOrder |
| | | * @return |
| | | */ |
| | | public boolean triggerProcess(EamInspectionOrder eamInspectionOrder) { |
| | | EamEquipment equipment = eamEquipmentService.getById(eamInspectionOrder.getEquipmentId()); |
| | | if (equipment == null) { |
| | | return false; |
| | | }else { |
| | | eamInspectionOrder.setEquipmentCode(equipment.getEquipmentCode()); |
| | | } |
| | | System.out.println("设备点检:" + eamInspectionOrder.getId()); |
| | | flowCommonService.initActBusiness("工单号:"+eamInspectionOrder.getOrderNum()+"设备编号"+eamInspectionOrder.getEquipmentCode()+"进行设备点检", |
| | | eamInspectionOrder.getId(), "IEamInspectionOrderService", "eam_inspection", null); |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | variables.put("dataId", eamInspectionOrder.getId()); |
| | | if (StrUtil.isEmpty(eamInspectionOrder.getRemark())){ |
| | | variables.put("organization", "新增点检工单默认启动流程"); |
| | | variables.put("comment", "新增点检工单默认启动流程"); |
| | | }else { |
| | | variables.put("organization", eamInspectionOrder.getRemark()); |
| | | variables.put("comment", eamInspectionOrder.getRemark()); |
| | | } |
| | | variables.put("proofreading",true); |
| | | List<String> usernames=new ArrayList<>(); |
| | | usernames.add(eamInspectionOrder.getOperator()); |
| | | variables.put("NextAssignee", usernames); |
| | | Result result= flowDefinitionService.startProcessInstanceByKey("eam_inspection", variables); |
| | | return result.isSuccess(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public boolean editInspectionOrder(EamInspectionOrderRequest eamInspectionOrderRequest) { |
| | | EamInspectionOrder eamInspectionOrder = new EamInspectionOrder(); |
| | | BeanUtils.copyProperties(eamInspectionOrderRequest, eamInspectionOrder); |
| | | updateById(eamInspectionOrder); |
| | | //处理明细数据 |
| | | if (CollectionUtil.isNotEmpty(eamInspectionOrderRequest.getTableDetailList())) { |
| | | eamInspectionOrderRequest.getTableDetailList().forEach(tableDetail -> { |
| | | tableDetail.setOrderId(eamInspectionOrder.getId()); |
| | | }); |
| | | //删除明细 |
| | | eamInspectionOrderDetailService.remove(new QueryWrapper<EamInspectionOrderDetail>().eq("order_id", eamInspectionOrder.getId())); |
| | | eamInspectionOrderDetailService.saveBatch(eamInspectionOrderRequest.getTableDetailList()); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 领取点检工单 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean takeInspectionOrder(String id){ |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | EamInspectionOrder eamInspectionOrder=this.getById(id); |
| | | if (eamInspectionOrder==null) { |
| | | return false; |
| | | }else { |
| | | eamInspectionOrder.setOperator(user.getUsername()); |
| | | //修改状态 |
| | | eamInspectionOrder.setInspectionStatus(InspectionStatus.IN_PROGRESS.getCode()); |
| | | this.triggerProcess(eamInspectionOrder); |
| | | this.updateById(eamInspectionOrder); |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 作废点检工单 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean cancelInspectionOrder(String id){ |
| | | EamInspectionOrder eamInspectionOrder = this.getById(id); |
| | | if (eamInspectionOrder == null) { |
| | | return false; |
| | | }else { |
| | | eamInspectionOrder.setInspectionStatus("5"); |
| | | return updateById(eamInspectionOrder); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 点检流程 |
| | | * @param eamInspectionOrderRequest |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public Result<?> inspectionProcess(EamInspectionOrderRequest eamInspectionOrderRequest){ |
| | | try { |
| | | // 参数校验 |
| | | if (!StrUtil.isNotBlank(eamInspectionOrderRequest.getTaskId()) || !StrUtil.isNotBlank(eamInspectionOrderRequest.getDataId())) { |
| | | return Result.error("非法参数"); |
| | | } |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String userId = user.getId(); |
| | | eamInspectionOrderRequest.setAssignee(user.getUsername()); |
| | | if (!StrUtil.isNotBlank(userId)) { |
| | | return Result.error("账号不存在"); |
| | | } |
| | | |
| | | // 数据查询 |
| | | EamInspectionOrder eamInspectionOrder = this.getById(eamInspectionOrderRequest.getDataId()); |
| | | if (eamInspectionOrder == null) { |
| | | return Result.error("未找到对应数据"); |
| | | } |
| | | |
| | | // 2. 查询流程业务记录(处理空结果) |
| | | List<FlowMyBusiness> businessList = flowMyBusinessService.list( |
| | | new QueryWrapper<FlowMyBusiness>() |
| | | .eq("process_instance_id", eamInspectionOrderRequest.getInstanceId()) |
| | | ); |
| | | if (businessList.isEmpty()) { |
| | | return Result.error("流程记录不存在"); |
| | | } |
| | | FlowMyBusiness flowMyBusiness = businessList.get(0); |
| | | |
| | | // 3. 校验用户是否为候选处理人 |
| | | List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class); |
| | | if (todoUsers == null || !todoUsers.contains(user.getUsername())) { |
| | | return Result.error("用户无权操作此任务"); |
| | | } |
| | | |
| | | // 4. 认领任务(处理已被认领的情况) |
| | | String taskId = flowMyBusiness.getTaskId(); |
| | | Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); |
| | | if (task == null) { |
| | | return Result.error("任务不存在或已完成"); |
| | | } |
| | | if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) { |
| | | return Result.error("任务已被他人认领"); |
| | | } |
| | | taskService.claim(taskId, user.getUsername()); |
| | | Map<String, Object> values = new HashMap<>(); |
| | | if ((InspectionStatus.IN_PROGRESS.getCode()).equals(eamInspectionOrder.getInspectionStatus())) { |
| | | //点检人点检结束 |
| | | //查询对应班组长,作为下一节点处理人,存在多个处理人 |
| | | String orgId=iEamEquipmentService.getById(eamInspectionOrder.getEquipmentId()).getOrgId(); |
| | | //筛选出班组长岗位,post为PCR0003 |
| | | List<SysUser> sysUserList= mdcUserProductionService.queryByPostAndProId("PCR0003",orgId); |
| | | List<String> usernameList; |
| | | if (sysUserList.isEmpty()){ |
| | | return Result.error("未找到该设备对应车间的班组长,请联系管理员处理"); |
| | | }else { |
| | | usernameList = sysUserList.stream().map(SysUser::getUsername).collect(Collectors.toList()); |
| | | } |
| | | // 设置流程变量 |
| | | |
| | | values.put("dataId", eamInspectionOrder.getId()); |
| | | values.put("organization", "点检人点检结束"); |
| | | values.put("comment","点检人点检结束" ); |
| | | values.put("NextAssignee", usernameList); |
| | | eamInspectionOrderRequest.setComment("点检人点检结束"); |
| | | }else { |
| | | //班组长确认 |
| | | values.put("dataId", eamInspectionOrder.getId()); |
| | | values.put("organization", "班组长确认"); |
| | | values.put("comment","班组长确认" ); |
| | | eamInspectionOrderRequest.setComment("班组长确认"); |
| | | } |
| | | eamInspectionOrderRequest.setValues(values); |
| | | // 完成流程任务 |
| | | Result result = flowTaskService.complete(eamInspectionOrderRequest); |
| | | if (result.isSuccess()) { |
| | | // 更新状态 |
| | | if ((InspectionStatus.IN_PROGRESS.getCode()).equals(eamInspectionOrder.getInspectionStatus())) { |
| | | //点检完成 |
| | | eamInspectionOrder.setInspectionStatus("3"); |
| | | eamInspectionOrder.setInspectionDate(new Date()); |
| | | eamInspectionOrderDetailService.remove(new QueryWrapper<EamInspectionOrderDetail>().eq("order_id", eamInspectionOrder.getId())); |
| | | eamInspectionOrderDetailService.saveBatch(eamInspectionOrderRequest.getTableDetailList()); |
| | | this.updateById(eamInspectionOrder); |
| | | } |
| | | } else if ((InspectionStatus.COMPLETED.getCode()).equals(eamInspectionOrder.getInspectionStatus())){ |
| | | // 班组长确认任务 |
| | | eamInspectionOrder.setInspectionStatus("4"); |
| | | eamInspectionOrder.setConfirmUser(user.getUsername()); |
| | | eamInspectionOrder.setConfirmTime(new Date()); |
| | | this.updateById(eamInspectionOrder); |
| | | //处理异常数据进入维修单 |
| | | return result; |
| | | } |
| | | |
| | | return Result.OK("操作成功"); |
| | | } catch (Exception e) { |
| | | return Result.error("操作失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 批量作废与领取 |
| | | * @param ids |
| | | * @param type |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> batchCancelOrTakeInspectionOrder(String ids, String type){ |
| | | if (type == null) { |
| | | return Result.error("请选择操作类型"); |
| | | } |
| | | LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | List<String> list = Arrays.asList(ids.split(",")); |
| | | QueryWrapper<EamInspectionOrder> queryWrapper =new QueryWrapper<>(); |
| | | queryWrapper.in("id", list); |
| | | queryWrapper.eq("inspection_status", "1"); |
| | | List<EamInspectionOrder> eamInspectionOrderList =this.list(queryWrapper); |
| | | if (!eamInspectionOrderList.isEmpty()){ |
| | | eamInspectionOrderList.forEach(eamInspectionOrder -> { |
| | | eamInspectionOrder.setInspectionStatus(type); |
| | | if (type.equals("2")){ |
| | | eamInspectionOrder.setOperator(loginUser.getUsername()); |
| | | }else { |
| | | eamInspectionOrder.setOperator(null); |
| | | } |
| | | }); |
| | | this.updateBatchById(eamInspectionOrderList); |
| | | } |
| | | return Result.OK("操作成功"); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Result<?> selectVoById(String id){ |
| | | List<EamInspectionOrder> eamInspectionOrders=this.list(new QueryWrapper<EamInspectionOrder>().eq("id", id)); |
| | | List<EamInspectionOrderRequest> eamInspectionOrderRequestList=new ArrayList<>(); |
| | | eamInspectionOrders.forEach(eamInspectionOrder -> { |
| | | EamInspectionOrderRequest eamInspectionOrderRequest=new EamInspectionOrderRequest(); |
| | | BeanUtils.copyProperties(eamInspectionOrder,eamInspectionOrderRequest); |
| | | List<EamInspectionOrderDetail> eamInspectionOrderDetails=eamInspectionOrderDetailService |
| | | .list(new QueryWrapper<EamInspectionOrderDetail>().eq("order_id", eamInspectionOrder.getId())); |
| | | eamInspectionOrderRequest.setTableDetailList(eamInspectionOrderDetails); |
| | | eamInspectionOrderRequestList.add(eamInspectionOrderRequest); |
| | | }); |
| | | return Result.ok(eamInspectionOrderRequestList); |
| | | } |
| | | |
| | | @Override |
| | | public void afterFlowHandle(FlowMyBusiness business) { |
| | | business.getTaskNameId();//接下来审批的节点 |
| | | business.getValues();//前端传进来的参数 |
| | | business.getActStatus(); |
| | | } |
| | | |
| | | @Override |
| | | public Object getBusinessDataById(String dataId) { |
| | | return this.getById(dataId); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> flowValuesOfTask(String taskNameId, Map<String, Object> values) { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) { |
| | | //业务是否干预流程,业务干预,流程干预,指定人员进行处理 |
| | | //获取下一步处理人 |
| | | Object object=values.get("NextAssignee"); |
| | | return (List<String>) object; |
| | | } |
| | | } |