From 0ed2995fbd51293095e78b6c55055d6f7794f992 Mon Sep 17 00:00:00 2001 From: lyh <925863403@qq.com> Date: 星期三, 09 四月 2025 16:30:15 +0800 Subject: [PATCH] 修改指派程序至设备,点检工单流程与异常报修,修改flow已办查询 --- lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/AssignFileStreamServiceImpl.java | 181 ++++++++++++++++++++++++++------------------- 1 files changed, 104 insertions(+), 77 deletions(-) diff --git a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/AssignFileStreamServiceImpl.java b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/AssignFileStreamServiceImpl.java index df6ebb3..49e51e3 100644 --- a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/AssignFileStreamServiceImpl.java +++ b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/AssignFileStreamServiceImpl.java @@ -1,6 +1,7 @@ package org.jeecg.modules.dncFlow.service.impl; 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; @@ -8,7 +9,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.google.common.collect.Lists; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.flowable.engine.TaskService; @@ -36,6 +36,7 @@ import org.jeecg.modules.dncFlow.service.IToEquipmentTaskService; import org.jeecg.modules.dncFlow.vo.AssignFlowTaskVo; 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; import org.jeecg.modules.flowable.apithird.service.FlowCommonService; import org.jeecg.modules.flowable.domain.vo.FlowTaskVo; @@ -48,7 +49,6 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -91,15 +91,11 @@ @Autowired private ISynchronizedFlagService synchronizedFlagService; @Autowired - private IDeviceGroupService deviceGroupService; - @Autowired private IDeviceCharactersService iDeviceCharactersService; @Autowired private IMdcEquipmentService iMdcEquipmentService; @Autowired private IMdcProductionService iMdcProductionService; - @Autowired - private StringRedisTemplate redisTemplate; @Autowired private TaskService taskService; @Resource @@ -108,6 +104,10 @@ private IFlowDefinitionService flowDefinitionService; @Autowired private IFlowTaskService flowTaskService; + @Autowired + private IDeviceTypeService deviceTypeService; + @Autowired + private IFlowMyBusinessService flowMyBusinessService; @Value("${securedoc.whether}") private String whether; @@ -192,15 +192,18 @@ DocInfo docInfo = getDocInfo(stream); MdcEquipment mdcEquipment = getMdcEquipment(stream); DocFile docFile = docFileService.getById(stream.getFileId()); - DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 4, stream.getDeviceId()); + DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 7, stream.getDeviceId()); if (deviceDoc != null) { handleExistingDeviceDoc(docFile, mdcEquipment, stream.getDeviceId()); } - deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 4, stream.getDeviceId()); + deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 7, stream.getDeviceId()); if (deviceDoc != null) { handleExistingDeviceDoc(docFile, mdcEquipment, stream.getDeviceId()); } PermissionStreamNew permissionStreams = getPermissionStreams(stream); + if (permissionStreams==null){ + return Result.error("鐢ㄦ埛娌℃湁鏉冮檺"); + } LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); String userId = user.getId(); saveBusinessObject(stream, userId); @@ -209,8 +212,19 @@ stream.getStreamId(), "IAssignFileStreamService", "assign_nc_to_device", null); Map<String, Object> variables = new HashMap<>(); variables.put("dataId", stream.getStreamId()); - variables.put("organization", stream.getApplyReason()); - return flowDefinitionService.startProcessInstanceByKey("assign_nc_to_device", variables); + if (stream.getApplyReason() != null) { + variables.put("organization", stream.getApplyReason()); + }else { + variables.put("organization", ""); + } + Result result= flowDefinitionService.startProcessInstanceByKey("assign_nc_to_device", variables); + if (result.isSuccess()){ + return Result.OK("鎿嶄綔鎴愬姛"); + }else { + super.removeById(stream.getStreamId()); + + return Result.error("鎿嶄綔澶辫触"); + } } @Override @@ -221,7 +235,7 @@ DocInfo docInfo = getDocInfo(stream); MdcEquipment mdcEquipment = getMdcEquipment(stream); DocFile docFile = getDocFile(stream); - DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 4, stream.getDeviceId()); + DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 7, stream.getDeviceId()); if(deviceDoc != null) { // 鍒犻櫎 澶囦唤 瑕嗙洊 鍘熸湁鐨� List<String> strings=iMdcProductionService.findListParentTreeAll(mdcEquipment.getId()); @@ -231,16 +245,6 @@ docFile.getFileName(), docFile.getFileSuffix()); } } - /*deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 4, stream.getDeviceId()); - if(deviceDoc != null) { - // 鍒犻櫎 澶囦唤 瑕嗙洊 鍘熸湁鐨� - List<String> strings = deviceGroupService.findListParentTreeAll(deviceInfo.getGroupId()); - if (strings != null && !strings.isEmpty()) { - String path = StringUtils.join(strings.toArray(), "/"); - boolean copyFileNc = FileUtilS.copyFileNcToBak(path + "/"+ deviceInfo.getDeviceNo(), - docFile.getFileName(), docFile.getFileSuffix()); - } - }*/ getPermissionStreams(stream); //鎻掑叆鏂囨。鍒拌澶囧彂閫佹枃妗� if(deviceDoc == null) { @@ -250,7 +254,7 @@ DocRelative docRelative = new DocRelative(); docRelative.setDocId(docInfo.getDocId()); docRelative.setClassificationId(classification.getClassificationId()); - docRelative.setAttributionType(4); + docRelative.setAttributionType(7); docRelative.setAttributionId(stream.getDeviceId()); boolean b = docRelativeService.save(docRelative); if(!b) { @@ -288,6 +292,34 @@ //flowable澶勭悊 FlowTaskVo flowTaskVo = new FlowTaskVo(); BeanUtils.copyProperties(assignFlowTaskVo, flowTaskVo); + + List<FlowMyBusiness> businessList = flowMyBusinessService.list( + new QueryWrapper<FlowMyBusiness>() + .eq("process_instance_id", assignFlowTaskVo.getInstanceId()) + ); + if (businessList.isEmpty()) { + return false; + } + FlowMyBusiness flowMyBusiness = businessList.get(0); + List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class); + if (todoUsers == null || !todoUsers.contains(user.getUsername())) { + return false; + } + + // 4. 璁ら浠诲姟锛堝鐞嗗凡琚棰嗙殑鎯呭喌锛� + String taskId = flowMyBusiness.getTaskId(); + Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); + if (task == null) { + return false; + } + if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) { + return false; + } + taskService.claim(taskId, user.getUsername()); + Map<String, Object> values=new HashMap<>(); + values.put("dataId", assignFlowTaskVo.getDataId()); + flowTaskVo.setTaskId(assignFlowTaskVo.getTaskId()); + flowTaskVo.setValues(values); flowTaskService.complete(flowTaskVo); //鏇存柊瀵硅薄灏佽 AssignFileStream up = new AssignFileStream(); @@ -303,20 +335,20 @@ DocInfo docInfo; //鍚屾剰鎿嶄綔 if (StrUtil.isNotEmpty(en.getStepId())){ - //宸ユ鎸囨淳 - docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), 6, en.getStepId()); + //宸ユ涓嬭澶囩被鎸囨淳 + docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), 6, en.getDeviceTypeId()); }else { - docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), 5, en.getProcessId()); + docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), 5, en.getDeviceTypeId()); } if(docInfo == null || docInfo.getDocStatus() == 3) - ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR); + ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR); MdcEquipment mdcEquipment = iMdcEquipmentService.getById(en.getDeviceId()); if(mdcEquipment == null) ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE); DocFile docFile = docFileService.getById(en.getFileId()); if(docFile == null) ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); - DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(en.getDocId(),4, en.getDeviceId()); + DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(en.getDocId(),7, en.getDeviceId()); if(deviceDoc != null) { // 鍒犻櫎 澶囦唤 瑕嗙洊 鍘熸湁鐨� List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId()); @@ -325,7 +357,7 @@ boolean copyFileNc = FileUtilS.copyFileNcToBak(path + "/"+ mdcEquipment.getEquipmentId(), docFile.getFileName(), docFile.getFileSuffix()); /* //docInfoService.getBaseMapper().deleteById(deviceDoc.getDocId()); - boolean doc = docRelativeService.deleteCopyDocByAttrNext(deviceDoc.getDocId(),4,stream.getDeviceId()); + boolean doc = docRelativeService.deleteCopyDocByAttrNext(deviceDoc.getDocId(),7,stream.getDeviceId()); if (!doc) { ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR_DELEVE); }*/ @@ -339,7 +371,7 @@ DocRelative docRelative = new DocRelative(); docRelative.setDocId(docInfo.getDocId()); docRelative.setClassificationId(classification.getClassificationId()); - docRelative.setAttributionType(4); + docRelative.setAttributionType(7); docRelative.setAttributionId(en.getDeviceId()); b = docRelativeService.save(docRelative); } @@ -402,14 +434,6 @@ List<TaskRequest> list = approveBatchRequest.getTaskArr(); if(list == null || list.isEmpty()) ExceptionCast.cast(CommonCode.INVALID_PARAM); -// list.forEach(item -> { -// AssignFileStream stream = new AssignFileStream(); -// stream.setApproveContent(approveBatchRequest.getApproveContent()); -// stream.setStatus(approveBatchRequest.getStatus()); -// boolean b = approveAssignFile(item.getId(), item.getBusinessKey(), stream); -// if(!b) -// ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR); -// }); return synchronizedFlagService.updateFlag(1); } @@ -471,7 +495,7 @@ if(deviceInfo == null) ExceptionCast.cast(DeviceCode.DEVICE_NOT_EXIST); //鍒犻櫎鍘熸潵璁惧涓嬬殑鎵�鏈夋枃妗� - docRelativeService.deleteByDocAttr(4, deviceInfo.getDeviceId()); + docRelativeService.deleteByDocAttr(7, deviceInfo.getDeviceId()); List<DocInfo> docInfoList = docInfoService.getByProcessIds(streams); if(docInfoList == null || docInfoList.isEmpty()) ExceptionCast.cast(DocumentCode.DOC_NOT_EXIST); @@ -490,7 +514,7 @@ DocRelative docRelative = new DocRelative(); docRelative.setDocId(docInfo.getDocId()); docRelative.setClassificationId(classification.getClassificationId()); - docRelative.setAttributionType(4); + docRelative.setAttributionType(7); docRelative.setAttributionId(deviceInfo.getDeviceId()); boolean b = docRelativeService.save(docRelative); if(!b) @@ -559,8 +583,8 @@ if (!copyFileNc) { ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); } else { - DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(deviceId, 4, deviceId); - boolean doc = docRelativeService.deleteDocByAttr(deviceDoc.getDocId(), 4, deviceId); + DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(deviceId, 7, deviceId); + boolean doc = docRelativeService.deleteDocByAttr(deviceDoc.getDocId(), 7, deviceId); if (!doc) { ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR_DELEVE); } @@ -568,38 +592,54 @@ } } - //鏉冮檺鏍¢獙 private PermissionStreamNew getPermissionStreams(AssignFileStream stream) { - PermissionStreamNew permissionStreams; LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + DeviceType deviceType = deviceTypeService.getById(stream.getAttributionId()); + String attributionId = deviceType != null ? deviceType.getAttributionId() : stream.getAttributionId(); + + PermissionStreamNew permissionStreams; if (stream.getAttributionType().equals("5")) { // 宸ュ簭 - ProcessStream processStream = processStreamService.getById(stream.getAttributionId()); - if (processStream == null) { - ExceptionCast.cast(CommonCode.INVALID_PARAM); - } - stream.setProductId(processStream.getProductId()); - stream.setComponentId(processStream.getComponentId()); - stream.setPartsId(processStream.getPartsId()); - stream.setProcessId(processStream.getProcessId()); - permissionStreams = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(processStream.getProcessId(),user.getId(),"5"); + permissionStreams = handleProcess(stream, attributionId, user); } else { // 宸ユ - WorkStep workStep = workStepService.getById(stream.getAttributionId()); - if (workStep == null) { - ExceptionCast.cast(CommonCode.INVALID_PARAM); - } - stream.setProductId(workStep.getProductId()); - stream.setComponentId(workStep.getComponentId()); - stream.setPartsId(workStep.getPartsId()); - stream.setProcessId(workStep.getProcessId()); - stream.setStepId(workStep.getId()); - permissionStreams = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(workStep.getId(),user.getId(),"6"); + permissionStreams = handleWorkStep(stream, attributionId, user); } - if (permissionStreams == null ) { + if (permissionStreams == null) { ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE); } return permissionStreams; + } + + private PermissionStreamNew handleProcess(AssignFileStream stream, String attributionId, LoginUser user) { + ProcessStream processStream = processStreamService.getById(attributionId); + if (processStream == null) { + ExceptionCast.cast(CommonCode.INVALID_PARAM); + } + stream.setProductId(processStream.getProductId()); + stream.setComponentId(processStream.getComponentId()); + stream.setPartsId(processStream.getPartsId()); + stream.setProcessId(processStream.getProcessId()); + if (deviceTypeService.getById(stream.getAttributionId()) != null) { + stream.setDeviceTypeId(deviceTypeService.getById(stream.getAttributionId()).getId()); + } + return permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(processStream.getProcessId(), user.getId(), "5"); + } + + private PermissionStreamNew handleWorkStep(AssignFileStream stream, String attributionId, LoginUser user) { + WorkStep workStep = workStepService.getById(attributionId); + if (workStep == null) { + ExceptionCast.cast(CommonCode.INVALID_PARAM); + } + stream.setProductId(workStep.getProductId()); + stream.setComponentId(workStep.getComponentId()); + stream.setPartsId(workStep.getPartsId()); + stream.setProcessId(workStep.getProcessId()); + stream.setStepId(workStep.getId()); + if (deviceTypeService.getById(stream.getAttributionId()) != null) { + stream.setDeviceTypeId(deviceTypeService.getById(stream.getAttributionId()).getId()); + } + return permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(workStep.getId(), user.getId(), "6"); } //鑾峰彇閮ㄩ棬淇℃伅 @@ -629,19 +669,6 @@ ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_SAVE_ERROR); } } - - //寮�濮嬪伐浣滄祦 -// private ProcessInstance startProcessInstance(AssignFileStream stream, List<String> userIdList) { -// String approveUsers = String.join(",", userIdList); -// Map<String, Object> avariableMap = new HashMap<>(); -// avariableMap.put(APPLY_VARIABLE, stream.getApplyUserId()); -// avariableMap.put(APPROVE_VARIABLE, approveUsers); -// ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(PROCESS_KEY, stream.getStreamId(), avariableMap); -// if (processInstance == null) { -// ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE); -// } -// return processInstance; -// } //鎷惧彇浠诲姟 private void completeTask(ProcessInstance processInstance, String userId) { @@ -750,6 +777,6 @@ @Override public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) { - return Lists.newArrayList("jeecg"); + return null; } } -- Gitblit v1.9.3