| | |
| | | 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; |
| | |
| | | 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); |
| | | NcNode oriProgramPkg = this.ncNodeService.getLastEditionTryingProgramPackage(programPackageName); |
| | | NcNode curedProgramPkg = ncNodeService.getLastEditionCuredProgramPackage(programPackageName); |
| | | if(curedProgramPkg != null){ |
| | | throw new ServiceException(programPackageName+"已经固化,请勿重复入库。"); |
| | | } |
| | | if(oriProgramPkg == null){ |
| | | log.warn("未发现匹配的程序包名{}",programPackageName); |
| | | log.warn("文件夹未发现匹配的程序包名{}",dir); |
| | | continue; |
| | | } |
| | | //检查是否在审批过程中 |
| | | //根据节点信息查询流程 |
| | | boolean active = flowCommonService.isProcessInstanceActive(oriProgramPkg.getProcessInstanceId()); |
| | | if(active){ |
| | | throw new ServiceException(programPackageName+"正在审批中,请勿重复入库。"); |
| | | } |
| | | /* |
| | | if(oriProgramPkg.hasCured()){ |
| | | throw new ServiceException(programPackageName+"已经固化,请勿重复入库。"); |
| | | }*/ |
| | | |
| | | if(!programPackageIdList.contains(oriProgramPkg.getId())){ |
| | | //不在勾选的范围内 |