¶Ô±ÈÐÂÎļþ |
| | |
| | | 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; |
| | | import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.engine.runtime.ProcessInstance; |
| | | import org.flowable.task.api.Task; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.dnc.constant.DncPassLogPassType; |
| | | import org.jeecg.modules.dnc.constant.DocAttributionTypeEnum; |
| | | import org.jeecg.modules.dnc.dto.TransferPackage; |
| | | import org.jeecg.modules.dnc.entity.*; |
| | | import org.jeecg.modules.dnc.exception.ExceptionCast; |
| | | import org.jeecg.modules.dnc.response.*; |
| | | import org.jeecg.modules.dnc.service.*; |
| | | import org.jeecg.modules.dnc.service.impl.FileFerryService; |
| | | import org.jeecg.modules.dnc.utils.ValidateUtil; |
| | | import org.jeecg.modules.dnc.utils.date.DateUtil; |
| | | import org.jeecg.modules.dnc.utils.file.FileUtilS; |
| | | import org.jeecg.modules.dncFlow.entity.AssignFileStream; |
| | | import org.jeecg.modules.dncFlow.ext.AssignFileStreamExt; |
| | | import org.jeecg.modules.dncFlow.mapper.AssignFileStreamMapper; |
| | | import org.jeecg.modules.dncFlow.request.ApproveBatchRequest; |
| | | import org.jeecg.modules.dncFlow.request.AssignFileRequest; |
| | | import org.jeecg.modules.dncFlow.request.AssignFileStreamQueryRequest; |
| | | import org.jeecg.modules.dncFlow.request.TaskRequest; |
| | | import org.jeecg.modules.dncFlow.service.IAssignFileStreamService; |
| | | 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; |
| | | import org.jeecg.modules.flowable.service.IFlowDefinitionService; |
| | | import org.jeecg.modules.flowable.service.IFlowTaskService; |
| | | import org.jeecg.modules.mdc.entity.MdcEquipment; |
| | | import org.jeecg.modules.mdc.service.IMdcEquipmentService; |
| | | import org.jeecg.modules.system.service.IMdcProductionService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service("IAssignFileStreamService") |
| | | public class AssignFileStreamServiceImpl extends ServiceImpl<AssignFileStreamMapper, AssignFileStream> implements IAssignFileStreamService , FlowCallBackServiceI { |
| | | private static final String PROCESS_KEY = "assign_nc_to_device"; |
| | | private static final String SEND_CODE = "SEND"; |
| | | @Value("${flowable.enable}") |
| | | private Boolean flowableEnable; |
| | | @Value("${fileHomePath}") |
| | | private String fileHomePath; |
| | | @Autowired |
| | | private IDocInfoService docInfoService; |
| | | @Autowired |
| | | private IDocClassificationService classificationService; |
| | | @Autowired |
| | | private IDocFileService docFileService; |
| | | @Autowired |
| | | private IDocRelativeService docRelativeService; |
| | | @Autowired |
| | | private ISynchronizedFlagService synchronizedFlagService; |
| | | @Autowired |
| | | private IDeviceCharactersService iDeviceCharactersService; |
| | | @Autowired |
| | | private IMdcEquipmentService iMdcEquipmentService; |
| | | @Autowired |
| | | private IMdcProductionService iMdcProductionService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | @Resource |
| | | private FlowCommonService flowCommonService; |
| | | @Resource |
| | | private IFlowDefinitionService flowDefinitionService; |
| | | @Autowired |
| | | private IFlowTaskService flowTaskService; |
| | | @Autowired |
| | | private IFlowMyBusinessService flowMyBusinessService; |
| | | @Autowired |
| | | private PermissionService permissionService; |
| | | @Autowired |
| | | private IDncPassLogService dncPassLogService; |
| | | @Value("${deploy.secretFolder}") |
| | | private String secretFolder; //æ¶å¯ç½ä¼ è¾ncæä»¶å¤¹ |
| | | @Autowired |
| | | private FileFerryService ferryService; |
| | | @Autowired |
| | | private IDocClassificationService iDocClassificationService; |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public Result<?> applyAssignFile(AssignFileStream stream) { |
| | | synchronized (this){ |
| | | //å¤æè®¾å¤ç¹æ®å符 |
| | | String specialChar = getDeviceSpecialChar(stream.getDeviceId(),stream.getFileId()); |
| | | if (StrUtil.isNotEmpty(specialChar)){ |
| | | //æåºç¹æ®å符å¼å¸¸ |
| | | return Result.error("æä»¶åç§°åå¨è®¾å¤ç¹æ®å符"); |
| | | } |
| | | //æ¥è¯¢ææ¡£çç¶æï¼æ¹åç¶ææå¯ä»¥ææ´¾ |
| | | DocInfo docInfo=getDocInfo(stream); |
| | | DocClassification docClassification=iDocClassificationService.getById(docInfo.getClassificationId()); |
| | | if (docInfo.getDocDispatchStatus()!=null&&docInfo.getDocDispatchStatus()!=3&&docClassification.getClassificationCode().equals("nc")){ |
| | | return Result.error("该æä»¶ç¶æä¸å
è®¸ææ´¾,请å
å®æå®¡ç¾æµç¨"); |
| | | } |
| | | if(flowableEnable) { |
| | | return applyAssignFileActive(stream); |
| | | }else { |
| | | return applyAssignFileNonActive(stream); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¤æè®¾å¤ç¹æ®å符 |
| | | * @param deviceId,fileId |
| | | * 设å¤IDï¼æä»¶ID |
| | | */ |
| | | public String getDeviceSpecialChar(String deviceId, String fileId){ |
| | | //æ¿æ¢ä¸ºmdc设å¤è¡¨ |
| | | MdcEquipment mdcEquipment = iMdcEquipmentService.getById(deviceId); |
| | | if(mdcEquipment == null) |
| | | ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE); |
| | | // DocFile docFile = docFileService.getById(fileId); |
| | | DocInfo docInfo = docInfoService.getOne(new QueryWrapper<DocInfo>().eq("publish_file_id",fileId)); |
| | | if(docInfo == null) |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | List<DeviceCharacters> deviceCharactersList=iDeviceCharactersService.list( |
| | | new LambdaQueryWrapper<DeviceCharacters>().eq(DeviceCharacters::getDeviceNo,mdcEquipment.getEquipmentId())); |
| | | if (deviceCharactersList.isEmpty()){ |
| | | return ""; |
| | | }else { |
| | | List<String> specialCharList=deviceCharactersList.stream().map(DeviceCharacters::getCharacters).collect(Collectors.toList()); |
| | | if(!specialCharList.isEmpty()){ |
| | | //å¯¹æ¯æä»¶åæ¯å¦å
å«ç¹æ®å符 |
| | | String fileName=docInfo.getDocName(); |
| | | for(String specialChar:specialCharList){ |
| | | if (fileName.contains(specialChar)){ |
| | | return specialChar; |
| | | } |
| | | } |
| | | }else { |
| | | return ""; |
| | | } |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | private ResponseResult createSpecialCharErrorResponse(String specialChar) { |
| | | return new ResponseResult(new ResultCode() { |
| | | @Override |
| | | public boolean success() { |
| | | return false; |
| | | } |
| | | @Override |
| | | public int code() { |
| | | return 88881; |
| | | } |
| | | @Override |
| | | public String message() { |
| | | return "æä»¶åç§°åå¨è®¾å¤ç¹æ®å符" + specialChar; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public Result<?> applyAssignFileActive(AssignFileStream stream) { |
| | | validateParams(stream); |
| | | DocInfo docInfo = getDocInfo(stream); |
| | | MdcEquipment mdcEquipment = getMdcEquipment(stream); |
| | | DocFile docFile = docFileService.getById(stream.getFileId()); |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 7, stream.getDeviceId()); |
| | | if (deviceDoc != null) { |
| | | handleExistingDeviceDoc(docFile, mdcEquipment, 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); |
| | | System.out.println("ææ´¾NCææ¡£å°è®¾å¤æµç¨ï¼" + stream.getDocId()); |
| | | flowCommonService.initActBusiness("ææ´¾NCææ¡£å°è®¾å¤æµç¨ï¼" +docInfo.getDocName()+"."+docInfo.getDocSuffix()+"å°è®¾å¤->"+mdcEquipment.getEquipmentName() , |
| | | stream.getStreamId(), "IAssignFileStreamService", "assign_nc_to_device", null); |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | variables.put("dataId", stream.getStreamId()); |
| | | 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 |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public Result<?> applyAssignFileNonActive(AssignFileStream stream) { |
| | | //æéæ ¡éª |
| | | validateParams(stream); |
| | | DocInfo docInfo = getDocInfo(stream); |
| | | //ä¿®æ¹åæç¶æ |
| | | docInfo.setDocDispatchStatus(4); |
| | | docInfoService.updateById(docInfo); |
| | | MdcEquipment mdcEquipment = getMdcEquipment(stream); |
| | | DocFile docFile = getDocFile(stream); |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 7, stream.getDeviceId()); |
| | | if(deviceDoc != null) { |
| | | // å é¤ å¤ä»½ è¦ç åæç |
| | | List<String> strings=iMdcProductionService.findListParentTreeAll(mdcEquipment.getId()); |
| | | if (strings != null && !strings.isEmpty()) { |
| | | String path = StringUtils.join(strings.toArray(), "/"); |
| | | boolean copyFileNc = FileUtilS.copyFileNcToBak(path + "/"+ mdcEquipment.getEquipmentId(), |
| | | docFile.getFileName(), docFile.getFileSuffix()); |
| | | } |
| | | } |
| | | getPermissionStreams(stream); |
| | | //æå
¥ææ¡£å°è®¾å¤åéææ¡£ |
| | | if(deviceDoc == null) { |
| | | DocClassification classification = classificationService.getByCode(SEND_CODE); |
| | | if(classification == null) |
| | | ExceptionCast.cast(DocumentCode.DOC_CLASS_ERROR); |
| | | DocRelative docRelative = new DocRelative(); |
| | | docRelative.setDocId(docInfo.getDocId()); |
| | | docRelative.setClassificationId(classification.getClassificationId()); |
| | | docRelative.setAttributionType(7); |
| | | docRelative.setAttributionId(stream.getDeviceId()); |
| | | boolean b = docRelativeService.save(docRelative); |
| | | if(!b) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR); |
| | | } |
| | | |
| | | } |
| | | List<DocRelative> docRelativeList=docRelativeService. |
| | | list(new QueryWrapper<DocRelative>() |
| | | .eq("attribution_type",stream.getAttributionType()) |
| | | .eq("attribution_id",stream.getAttributionId()) |
| | | .eq("doc_id",stream.getDocId())); |
| | | if (docRelativeList.isEmpty()){ |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR); |
| | | } |
| | | handleFileTransfer(mdcEquipment, docFile); |
| | | //NCæä»¶çæ·è´ |
| | | handleFileProcessing(docFile, mdcEquipment, secretFolder); |
| | | //对åºäº§åç»ææ æ·è´ |
| | | handleProductTree(docInfo,docRelativeList.get(0),mdcEquipment.getEquipmentId()); |
| | | synchronizedFlagService.updateFlag(2); |
| | | return Result.OK("æä½æå"); |
| | | } |
| | | |
| | | @Override |
| | | public AssignFileStreamExt getAssignFileStreamDetail(String streamId) { |
| | | if(!ValidateUtil.validateString(streamId)) |
| | | return null; |
| | | return super.getBaseMapper().getAssignFileStreamDetail(streamId); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean approveAssignFile(AssignFlowTaskVo assignFlowTaskVo) { |
| | | if(!ValidateUtil.validateString(assignFlowTaskVo.getTaskId()) || !ValidateUtil.validateString(assignFlowTaskVo.getDataId()) || assignFlowTaskVo == null) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String userId = user.getId(); |
| | | if(!ValidateUtil.validateString(userId)) |
| | | ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST); |
| | | if(!ValidateUtil.validateInteger(assignFlowTaskVo.getStatus())) |
| | | ExceptionCast.cast(ActivitiCode.ACT_STATUS_ERROR); |
| | | AssignFileStream en = super.getById(assignFlowTaskVo.getDataId()); |
| | | if(en == null) |
| | | ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_DETAIL_ERROR); |
| | | //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(); |
| | | up.setApproveContent(assignFlowTaskVo.getApproveContent()); |
| | | up.setStatus(assignFlowTaskVo.getStatus()); |
| | | up.setApproveUserId(userId); |
| | | up.setApproveTime(DateUtil.getNow()); |
| | | up.setStreamId(assignFlowTaskVo.getDataId()); |
| | | boolean b = super.updateById(up); |
| | | if(!b) |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR); |
| | | if(up.getStatus() == 2) { |
| | | //åææä½ |
| | | DocInfo docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), Integer.valueOf(en.getAttributionType()), en.getAttributionId()); |
| | | if(docInfo == null ) |
| | | 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.setDocDispatchStatus(4); |
| | | docInfoService.updateById(docInfo); |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(en.getDocId(),7, en.getDeviceId()); |
| | | if(deviceDoc != null) { |
| | | // å é¤ å¤ä»½ è¦ç åæç |
| | | List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId()); |
| | | if (strings != null && !strings.isEmpty()) { |
| | | String path = StringUtils.join(strings.toArray(), "/"); |
| | | boolean copyFileNc = FileUtilS.copyFileNcToBak(path + "/"+ mdcEquipment.getEquipmentId(), |
| | | docFile.getFileName(), docFile.getFileSuffix()); |
| | | /* //docInfoService.getBaseMapper().deleteById(deviceDoc.getDocId()); |
| | | boolean doc = docRelativeService.deleteCopyDocByAttrNext(deviceDoc.getDocId(),7,stream.getDeviceId()); |
| | | if (!doc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR_DELEVE); |
| | | }*/ |
| | | } |
| | | } else { |
| | | //æå
¥ææ¡£å°è®¾å¤åéææ¡£ |
| | | DocClassification classification = classificationService.getByCode(SEND_CODE); |
| | | if(classification == null) |
| | | ExceptionCast.cast(DocumentCode.DOC_CLASS_ERROR); |
| | | |
| | | DocRelative docRelative = new DocRelative(); |
| | | docRelative.setDocId(docInfo.getDocId()); |
| | | docRelative.setClassificationId(classification.getClassificationId()); |
| | | docRelative.setAttributionType(7); |
| | | docRelative.setAttributionId(en.getDeviceId()); |
| | | b = docRelativeService.save(docRelative); |
| | | } |
| | | if(!b) |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR); |
| | | if (mdcEquipment != null) { |
| | | List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId()); |
| | | if (strings != null && !strings.isEmpty()) { |
| | | String path = StringUtils.join(strings.toArray(), "/"); |
| | | boolean copyFileNc = FileUtilS.copyFileNc(docFile.getFilePath(),path + "/"+ mdcEquipment.getEquipmentId(), |
| | | docFile.getFileEncodeName(), |
| | | docFile.getFileName(),docFile.getFileSuffix()); |
| | | if (!copyFileNc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | } else { |
| | | FileUtilS.deleteZipFromToSend(path + "/"+ mdcEquipment.getEquipmentId(), |
| | | docFile.getFileName(),docFile.getFileSuffix()); |
| | | } |
| | | } |
| | | } |
| | | List<DocRelative> docRelativeList=docRelativeService. |
| | | list(new QueryWrapper<DocRelative>() |
| | | .eq("attribution_type",en.getAttributionType()) |
| | | .eq("attribution_id",en.getAttributionId()) |
| | | .eq("doc_id",en.getDocId())); |
| | | if (docRelativeList.isEmpty()){ |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR); |
| | | } |
| | | //æ¶å¯ç½è¿è¡NCæä»¶çæ·è´ |
| | | handleFileTransfer(mdcEquipment, docFile); |
| | | //NCæä»¶çæ·è´ |
| | | handleFileProcessing(docFile, mdcEquipment, secretFolder); |
| | | //对åºäº§åç»ææ æ·è´ |
| | | handleProductTree(docInfo,docRelativeList.get(0),mdcEquipment.getEquipmentId()); |
| | | return synchronizedFlagService.updateFlag(1); |
| | | }else if(up.getStatus() == 3) { |
| | | //æç»æä½ ä»ä¹ä¹ä¸å |
| | | return true; |
| | | }else { |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean applyBatchAssignFile(AssignFileRequest assignFileRequest) { |
| | | if(assignFileRequest == null) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | String[] deviceIds = assignFileRequest.getDeviceIds(); |
| | | if(deviceIds == null || deviceIds.length < 1) |
| | | ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE); |
| | | AssignFileStream stream; |
| | | for(String id : deviceIds) { |
| | | stream = new AssignFileStream(); |
| | | stream.setProcessId(assignFileRequest.getProcessId()); |
| | | stream.setStepId(assignFileRequest.getStepId()); |
| | | stream.setDocId(assignFileRequest.getDocId()); |
| | | stream.setFileId(assignFileRequest.getFileId()); |
| | | stream.setApplyReason(assignFileRequest.getApplyReason()); |
| | | stream.setDeviceId(id); |
| | | Result b = applyAssignFile(stream); |
| | | if(!b.isSuccess()) |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPLY_ERROR); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean approveBatchAssignFile(ApproveBatchRequest approveBatchRequest) { |
| | | if(approveBatchRequest == null) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | List<TaskRequest> list = approveBatchRequest.getTaskArr(); |
| | | if(list == null || list.isEmpty()) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | return synchronizedFlagService.updateFlag(1); |
| | | } |
| | | |
| | | @Override |
| | | public Result<?> findPageList(int page, int size, AssignFileStreamQueryRequest request) { |
| | | if(page < 1 || size < 1) { |
| | | ExceptionCast.cast(CommonCode.INVALID_PAGE); |
| | | } |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String userId = user.getId(); |
| | | if(!ValidateUtil.validateString(userId)) |
| | | ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST); |
| | | LambdaQueryWrapper<AssignFileStreamExt> lambdaQueryWrapper = Wrappers.lambdaQuery(); |
| | | lambdaQueryWrapper.eq(AssignFileStreamExt::getApproveUserId, userId); |
| | | lambdaQueryWrapper.orderByDesc(AssignFileStreamExt::getApproveTime); |
| | | IPage<AssignFileStreamExt> pageData = new Page<>(page, size); |
| | | if(request != null) { |
| | | if(ValidateUtil.validateString(request.getAscStr())) { |
| | | String[] ascArr = request.getAscStr().split(","); |
| | | // ((Page<AssignFileStreamExt>) pageData).setAsc(ascArr); |
| | | } |
| | | if(ValidateUtil.validateString(request.getDescStr())) { |
| | | String[] descStr = request.getDescStr().split(","); |
| | | // ((Page<AssignFileStreamExt>) pageData).setDesc(descStr); |
| | | } |
| | | } |
| | | IPage<AssignFileStreamExt> streamExtIPage = super.getBaseMapper().findByPage(pageData, lambdaQueryWrapper); |
| | | return Result.ok(streamExtIPage); |
| | | } |
| | | |
| | | @Override |
| | | public QueryPageResponseResult<AssignFileStreamExt> findPageListByDocId(int page, int size, String docId) { |
| | | if(page < 1 || size < 1) { |
| | | ExceptionCast.cast(CommonCode.INVALID_PAGE); |
| | | } |
| | | if(!ValidateUtil.validateString(docId)) |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ID_NONE); |
| | | QueryWrapper<AssignFileStreamExt> queryWrapper = Wrappers.query(); |
| | | queryWrapper.eq("a.doc_id", docId); |
| | | queryWrapper.orderByDesc("approve_time"); |
| | | IPage<AssignFileStreamExt> pageData = new Page<>(page, size); |
| | | IPage<AssignFileStreamExt> streamExtIPage = super.getBaseMapper().findByPage(pageData, queryWrapper); |
| | | return new QueryPageResponseResult<>(CommonCode.SUCCESS, streamExtIPage); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean getFlowableEnable(){ |
| | | if(flowableEnable != null) { |
| | | return flowableEnable; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | //ä¼ åéªè¯ |
| | | private void validateParams(AssignFileStream stream) { |
| | | if (stream == null) { |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | } |
| | | if (!ValidateUtil.validateString(stream.getAttributionId()) || !ValidateUtil.validateString(stream.getDocId()) |
| | | || !ValidateUtil.validateString(stream.getFileId()) || !ValidateUtil.validateString(stream.getAttributionType())) { |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | } |
| | | if (!ValidateUtil.validateString(stream.getDeviceId())) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE); |
| | | } |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String userId = user.getId(); |
| | | if (!ValidateUtil.validateString(userId)) { |
| | | ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST); |
| | | } |
| | | } |
| | | |
| | | //è·åæä»¶ä¿¡æ¯ |
| | | private DocInfo getDocInfo(AssignFileStream stream) { |
| | | DocInfo docInfo = docInfoService.getByDocAttrAndDocId(stream.getDocId(), Integer.parseInt(stream.getAttributionType()), stream.getAttributionId()); |
| | | if (docInfo == null || docInfo.getDocStatus() == 3) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR); |
| | | } |
| | | return docInfo; |
| | | } |
| | | |
| | | //è·åæä»¶ |
| | | private void handleExistingDeviceDoc(DocFile docFile, MdcEquipment mdcEquipment, String deviceId) { |
| | | List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId()); |
| | | if (strings != null && !strings.isEmpty()) { |
| | | String path = StringUtils.join(strings.toArray(), "/"); |
| | | boolean copyFileNc = FileUtilS.copyFileNcToBak(path + "/" + mdcEquipment.getEquipmentId(), |
| | | docFile.getFileName(), docFile.getFileSuffix()); |
| | | if (!copyFileNc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | } else { |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(deviceId, 7, deviceId); |
| | | boolean doc = docRelativeService.deleteDocByAttr(deviceDoc.getDocId(), 7, deviceId); |
| | | if (!doc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR_DELEVE); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private PermissionStreamNew getPermissionStreams(AssignFileStream stream) { |
| | | PermissionStreamNew permissionStreamNew = permissionService.getPermissionStreams(stream); |
| | | if (permissionStreamNew == null) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE); |
| | | } |
| | | return permissionStreamNew ; |
| | | } |
| | | |
| | | //å°è£
æ°æ® |
| | | private void saveBusinessObject(AssignFileStream stream, String userId) { |
| | | String streamId = IdWorker.getIdStr(); |
| | | stream.setStreamId(streamId); |
| | | stream.setApplyUserId(userId); |
| | | stream.setApplyTime(DateUtil.getNow()); |
| | | stream.setStatus(1); |
| | | boolean b = super.save(stream); |
| | | if (!b) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_SAVE_ERROR); |
| | | } |
| | | } |
| | | |
| | | //æ¾åä»»å¡ |
| | | private void completeTask(ProcessInstance processInstance, String userId) { |
| | | Task task = taskService.createTaskQuery().processDefinitionKey(PROCESS_KEY).taskAssignee(userId) |
| | | .processInstanceId(processInstance.getId()).singleResult(); |
| | | if (task == null) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE); |
| | | } |
| | | taskService.complete(task.getId()); |
| | | } |
| | | |
| | | //è·åè®¾å¤ |
| | | private MdcEquipment getMdcEquipment(AssignFileStream stream) { |
| | | MdcEquipment mdcEquipment = iMdcEquipmentService.getById(stream.getDeviceId()); |
| | | if (mdcEquipment == null) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE); |
| | | } |
| | | return mdcEquipment; |
| | | } |
| | | |
| | | //è·åæä»¶ |
| | | private DocFile getDocFile(AssignFileStream stream) { |
| | | DocFile docFile = docFileService.getById(stream.getFileId()); |
| | | if (docFile == null) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | } |
| | | return docFile; |
| | | } |
| | | |
| | | //æå
¥æä»¶ä¼ è¾ä»»å¡è¡¨ |
| | | @Override |
| | | public void handleFileTransfer(MdcEquipment mdcEquipment, DocFile docFile) { |
| | | List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId()); |
| | | if (strings != null && !strings.isEmpty()) { |
| | | String path = StringUtils.join(strings.toArray(), "/"); |
| | | boolean copyFileNc = FileUtilS.copyFileNc(docFile.getFilePath(), path + "/" + mdcEquipment.getEquipmentId(), |
| | | docFile.getFileEncodeName(), |
| | | docFile.getFileName(), docFile.getFileSuffix()); |
| | | if (!copyFileNc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | } else { |
| | | FileUtilS.deleteZipFromToSend(path + "/" + mdcEquipment.getEquipmentId(), |
| | | docFile.getFileName(), docFile.getFileSuffix()); |
| | | } |
| | | } else { |
| | | throw new RuntimeException("æä»¶ä¼ è¾è·¯å¾è·å失败"); |
| | | } |
| | | } |
| | | |
| | | //å°è£
å¤çæä»¶ |
| | | private void handleFileProcessing(DocFile docFile, MdcEquipment mdcEquipment, String secretFolder) { |
| | | if (!docFile.getFileSuffix().equals("zip") && !docFile.getFileSuffix().equals("rar")) { |
| | | List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId()); |
| | | if (strings != null && !strings.isEmpty()) { |
| | | DncPassLog passInfoTxt = new DncPassLog(); |
| | | |
| | | String path = StringUtils.join(strings.toArray(), "/"); |
| | | Date dateFirst = DateUtil.getNow(); |
| | | passInfoTxt.setDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)); |
| | | /*æ¥è¯¢æå䏿¡è®°å½*/ |
| | | //ä¼ç 500æ¯«ç§ |
| | | DncPassLog dncPassLog = dncPassLogService.findDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)); |
| | | int fileNc =0; |
| | | if (dncPassLog !=null) { |
| | | fileNc = dncPassLog.getSequenceNumber() + 1; |
| | | } else { |
| | | fileNc = 1; |
| | | } |
| | | //å¤çæä»¶åç§° æä»¶è·¯å¾ |
| | | String sequenceNc = String.format("%06d",fileNc); |
| | | DncPassLog passInfoNc = new DncPassLog(); |
| | | passInfoNc.setSequenceNumber(fileNc); |
| | | passInfoNc.setSequenceOrder(sequenceNc); |
| | | passInfoNc.setDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)); |
| | | passInfoNc.setPassType("02"); |
| | | passInfoNc.setPassName(docFile.getFileName()); |
| | | try { |
| | | Thread.sleep(1000); |
| | | Date date = new Date(); |
| | | passInfoNc.setCreateTime(date); |
| | | System.out.println(DateUtil.format(date,DateUtil.STR_DATE_TIME)); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | dncPassLogService.save(passInfoNc); |
| | | FileUtilS.copyFileUpName(path + "/" + mdcEquipment.getEquipmentId() + "/send/" + |
| | | docFile.getFileName(), |
| | | secretFolder +"/"+"10A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)+sequenceNc+"_"+mdcEquipment.getEquipmentId(), |
| | | docFile.getFileSuffix(), "NC"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¤ç对åºäº§åç»ææ ãncæä»¶ãåå
·å表ãç¨åºå 工确认表å°è£
|
| | | * @param docInfo |
| | | */ |
| | | private void handleProductTree(DocInfo docInfo,DocRelative docRelative,String equipmentId) { |
| | | /*æ¥è¯¢æå䏿¡è®°å½*/ |
| | | //ä¼ç 500æ¯«ç§ |
| | | DncPassLog passInfoTxt = new DncPassLog(); |
| | | Date dateFirst = DateUtil.getNow(); |
| | | passInfoTxt.setDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)); |
| | | DncPassLog dncPassLog = dncPassLogService.findDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)); |
| | | int fileTxt = 0, fileNc =0; |
| | | if (dncPassLog !=null) { |
| | | fileTxt = dncPassLog.getSequenceNumber() + 1; |
| | | } else { |
| | | fileTxt = 1; |
| | | } |
| | | String sequence = String.format("%06d",fileTxt); |
| | | passInfoTxt.setSequenceNumber(fileTxt); |
| | | passInfoTxt.setCreateTime(dateFirst); |
| | | passInfoTxt.setSequenceOrder(sequence); |
| | | System.out.println(DateUtil.format(dateFirst,DateUtil.STR_DATE_TIME)); |
| | | passInfoTxt.setPassType(DncPassLogPassType.PRODUCTSTRUCTURE.getCode()); |
| | | dncPassLogService.save(passInfoTxt); |
| | | String fileName="10A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY); |
| | | if (Objects.equals(docInfo.getAttributionType(), DocAttributionTypeEnum.PROCESS.getCode())){ |
| | | //å·¥åºå¯¹åºè®¾å¤ç±» |
| | | String filePath = ferryService.exportData(TransferPackage.DataType.PROCESS, docRelative.getId(),fileName+sequence+"_"+equipmentId+".ferry"); |
| | | System.out.println("å·¥åºæ°æ®å·²å¯¼åº: " + filePath); |
| | | }else { |
| | | //å·¥æ¥å¯¹åºè®¾å¤ç±» |
| | | String filePath = ferryService.exportData(TransferPackage.DataType.WORKSTEP, docRelative.getId(),fileName+sequence+"_"+equipmentId+".ferry"); |
| | | System.out.println("å·¥æ¥æ°æ®å·²å¯¼åº: " + filePath); |
| | | } |
| | | } |
| | | @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) { |
| | | return null; |
| | | } |
| | | } |