| | |
| | | package org.springblade.mdm.program.service; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import io.netty.util.internal.StringUtil; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.flow.service.CureFlowService; |
| | | import org.springblade.mdm.flow.service.FlowCommonService; |
| | | import org.springblade.mdm.flow.service.FlowProgramFileService; |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | | import org.springblade.mdm.program.entity.NcProgramExchange; |
| | | import org.springblade.mdm.program.mapper.NcProgramExchangeMapper; |
| | | import org.springblade.mdm.program.vo.DncSendBackData; |
| | | import org.springblade.mdm.utils.EntityUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | private final NcNodeService ncNodeService; |
| | | private final OssTemplate ossTemplate; |
| | | private final BladeRedis bladeRedis; |
| | | private final FlowCommonService flowCommonService; |
| | | |
| | | private String getFileKey(){ |
| | | return "dncexpfile-"+ AuthUtil.getUserId(); |
| | |
| | | */ |
| | | public List<DncSendBackData> dncSendBackUpload(MultipartFile file) { |
| | | List<DncSendBackData> list; |
| | | if(file == null || file.isEmpty()){ |
| | | throw new ServiceException("文件为空"); |
| | | } |
| | | |
| | | if(!StringUtils.endsWith(file.getOriginalFilename(),".zip")){ |
| | | throw new ServiceException("文件必须为zip包"); |
| | | } |
| | | try { |
| | | BladeFile bfile = ossTemplate.putFile(file);//上传,供后续入库使用 |
| | | //设置一个缓存,2小时过期 |
| | |
| | | InputStream zipFileInputStream = file.getInputStream();//test |
| | | |
| | | //byte[] bytes = FileUtil.copyToByteArray(zipFileInputStream); |
| | | list = parseDncZipFromByteArray(zipFileInputStream); |
| | | list = parseProgramListFromZip(zipFileInputStream); |
| | | |
| | | } catch (IOException e) { |
| | | log.error("上传dnc回传文件失败",e); |
| | |
| | | * @return 回传程序列表 |
| | | * @throws IOException 文件操作异常 |
| | | */ |
| | | List<DncSendBackData> parseDncZipFromByteArray(InputStream inputStream) throws IOException { |
| | | List<DncSendBackData> parseProgramListFromZip(InputStream inputStream) throws IOException { |
| | | List<DncSendBackData> list = new ArrayList<>(); |
| | | Path tempZipFile = createTempFile(inputStream); |
| | | |
| | |
| | | //目录,才是程序包, |
| | | //查询数据库,对应上才能确认时有效的程序包 |
| | | String packageName = StringUtils.removeEnd(entryName,"/"); |
| | | List<NcNode> pkgList = ncNodeService.lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE).eq(NcNode::getName, packageName).eq(NcNode::getIsLastEdition,1).list(); |
| | | if(!pkgList.isEmpty()) { |
| | | NcNode programPackageNode = pkgList.get(0); |
| | | NcNode programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName); |
| | | NcNode curedProgramPkg = ncNodeService.getLastEditionCuredProgramPackage(packageName); |
| | | |
| | | if(programPackageNode!=null && curedProgramPkg == null) {//无固化程序,才放入列表 |
| | | //NcNode programPackageNode = pkgList.get(0); |
| | | progData.setId(programPackageNode.getId()); |
| | | progData.setProgramName(packageName); |
| | | |
| | |
| | | progData.setProgramNo(programPackageNode.getProgramNo()); |
| | | list.add(progData); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | entry = entris.nextElement(); |
| | | entryNameList.add(entry.getName()); |
| | | } |
| | | |
| | | log.info("allentrynames:{}",entryNameList); |
| | | //根据内部文件,读取和分析程序包和程序文件数据 |
| | | List<String> dirList = entryNameList.stream().filter(s -> s.endsWith("/")).toList(); |
| | | for(String dir : dirList){ |
| | | String programPackageName = StringUtils.removeEnd(dir,"/"); |
| | | |
| | | NcNode oriProgramPkg = this.ncNodeService.getLastEditionProgramPackage(programPackageName); |
| | | if(oriProgramPkg == null){ |
| | | log.warn("未发现匹配的程序包名{}",programPackageName); |
| | | NcNode tryProgramPkg = this.ncNodeService.getLastEditionTryingProgramPackage(programPackageName); |
| | | NcNode curedProgramPkg = ncNodeService.getLastEditionCuredProgramPackage(programPackageName); |
| | | if(curedProgramPkg != null){ |
| | | throw new ServiceException(programPackageName+"已经固化,请勿重复入库。"); |
| | | } |
| | | if(tryProgramPkg == null){ |
| | | log.warn("文件夹未发现匹配的程序包名{}",dir); |
| | | continue; |
| | | } |
| | | //检查是否在审批过程中 |
| | | //根据节点信息查询流程 |
| | | boolean active = flowCommonService.isProcessInstanceActive(tryProgramPkg.getProcessInstanceId()); |
| | | if(active){ |
| | | throw new ServiceException(programPackageName+"正在审批中,请勿重复入库。"); |
| | | } |
| | | /* |
| | | if(oriProgramPkg.hasCured()){ |
| | | throw new ServiceException(programPackageName+"已经固化,请勿重复入库。"); |
| | | }*/ |
| | | |
| | | if(!programPackageIdList.contains(oriProgramPkg.getId())){ |
| | | if(!programPackageIdList.contains(tryProgramPkg.getId())){ |
| | | //不在勾选的范围内 |
| | | log.info("{}不在勾选范围内",programPackageName); |
| | | continue; |
| | | } |
| | | NcNode newProgramPkg = new NcNode(); |
| | | BeanUtils.copyProperties(oriProgramPkg, newProgramPkg); |
| | | clearBaseProperties(newProgramPkg); |
| | | BeanUtils.copyProperties(tryProgramPkg, newProgramPkg); |
| | | EntityUtil.clearBaseProperties(newProgramPkg); |
| | | newProgramPkg.setIsLastEdition(1); |
| | | ncNodeService.save(newProgramPkg); |
| | | newProgramPackageNodeList.add(newProgramPkg); |
| | | |
| | | //旧数据更新为老版本 |
| | | oriProgramPkg.setIsLocked(1);//旧版自动锁定 |
| | | oriProgramPkg.setIsLastEdition(0);; |
| | | ncNodeService.updateById(oriProgramPkg); |
| | | tryProgramPkg.setIsLocked(1);//旧版自动锁定 |
| | | tryProgramPkg.setIsLastEdition(0);; |
| | | ncNodeService.updateById(tryProgramPkg); |
| | | |
| | | //List<FlowProgramFile> newFlowFiles = new ArrayList<>(); |
| | | List<NcNode> newProgramNodes = new ArrayList<>(); |
| | |
| | | if(!entryName.endsWith("/")){ |
| | | //实际的文件 |
| | | String fileName = StringUtils.removeStart(entryName,dir);//去除文件名路径部分 |
| | | NcNode oldProgramNode = this.ncNodeService.getLastEditionProgramFile(fileName,oriProgramPkg.getId()); |
| | | NcNode oldProgramNode = this.ncNodeService.getLastEditionProgramFile(fileName,tryProgramPkg.getId()); |
| | | if(oldProgramNode == null){ |
| | | log.info("{}找不到程序文件",entryName); |
| | | return; |
| | |
| | | |
| | | NcNode newProgramNode = new NcNode(); |
| | | BeanUtils.copyProperties(oldProgramNode, newProgramNode); |
| | | clearBaseProperties(newProgramNode); |
| | | EntityUtil.clearBaseProperties(newProgramNode); |
| | | newProgramNode.setIsLastEdition(1); |
| | | newProgramNode.setParentId(newProgramPkg.getId()); |
| | | newProgramNode.setParentIds(newProgramPkg.getParentIds()+","+newProgramPkg.getId()); |
| | |
| | | |
| | | FlowProgramFile oldFlowFile = flowProgramFileService.getById(newProgramNode.getFlowProgramFileId()); |
| | | |
| | | FlowProgramFile newFlowFile = new FlowProgramFile();//TODO |
| | | FlowProgramFile newFlowFile = new FlowProgramFile(); |
| | | BeanUtils.copyProperties(oldFlowFile, newFlowFile); |
| | | newFlowFile.setProcessInstanceId(null); |
| | | clearBaseProperties(newFlowFile); |
| | | EntityUtil.clearBaseProperties(newFlowFile); |
| | | |
| | | try { |
| | | InputStream ins = zipFile.getInputStream(zipFile.getEntry(entryName)); |
| | |
| | | newProgramNode.setFlowProgramFile(newFlowFile); |
| | | newProgramNode.setVersionNumber(oldProgramNode.genNewVersionNumber()); |
| | | newProgramNodes.add(newProgramNode); |
| | | oldProgramNode.setIsLastEdition(0); |
| | | oldProgramNode.setIsLocked(1); |
| | | ncNodeService.updateById(oldProgramNode); |
| | | //旧节点处理,咋办?如果导出工控网 重复导出呢?,isLastEdition不用设置了,因为 程序包节点 是新的 |
| | | //TODO 待验证 |
| | | //oldProgramNode.setIsLastEdition(原来是0); |
| | | //oldProgramNode.setIsLocked(1); |
| | | //ncNodeService.updateById(oldProgramNode); |
| | | } |
| | | }); |
| | | |
| | |
| | | entity.setCreateUser(jsonObject.getLong("createUser")); |
| | | entity.setUpdateUser(jsonObject.getLong("updateUser")); |
| | | } |
| | | |
| | | /* |
| | | void clearBaseProperties(BizEntity entity){ |
| | | entity.setId(null); |
| | | entity.setCreateTime(null); |
| | |
| | | entity.setStatus(null); |
| | | entity.setCreateUser(null); |
| | | entity.setUpdateUser(null); |
| | | } |
| | | }*/ |
| | | } |