From 0add10ef126bfb861192df3e7c6574910c31a7ae Mon Sep 17 00:00:00 2001 From: ludc Date: 星期四, 01 八月 2024 17:19:03 +0800 Subject: [PATCH] 版本规则管理所有接口上传(已测试待联调) --- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsRevisionRuleServiceImpl.java | 316 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 308 insertions(+), 8 deletions(-) diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsRevisionRuleServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsRevisionRuleServiceImpl.java index 08b20db..904da86 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsRevisionRuleServiceImpl.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsRevisionRuleServiceImpl.java @@ -2,24 +2,43 @@ import com.vci.client.mw.ClientSessionUtility; import com.vci.corba.common.PLException; +import com.vci.corba.omd.stm.StatePool; import com.vci.corba.omd.vrm.VersionRule; +import com.vci.dto.OsAttributeDTO; import com.vci.dto.OsRevisionRuleDTO; +import com.vci.dto.OsStatusDTO; +import com.vci.pagemodel.OsAttributeVO; +import com.vci.pagemodel.OsEnumVO; +import com.vci.pagemodel.OsStatusVO; +import com.vci.po.OsAttributePO; +import com.vci.po.OsEnumPO; +import com.vci.po.OsRevisionRulePO; +import com.vci.starter.poi.bo.ReadExcelOption; +import com.vci.starter.poi.bo.WriteExcelData; +import com.vci.starter.poi.bo.WriteExcelOption; +import com.vci.starter.poi.constant.ExcelLangCodeConstant; +import com.vci.starter.poi.util.ExcelUtil; import com.vci.starter.web.annotation.log.VciUnLog; -import com.vci.starter.web.util.VciBaseUtil; -import com.vci.starter.web.util.VciDateUtil; +import com.vci.starter.web.exception.VciBaseException; +import com.vci.starter.web.pagemodel.BaseResult; +import com.vci.starter.web.util.*; import com.vci.pagemodel.OsRevisionRuleVO; -import com.vci.starter.web.util.WebThreadLocalUtil; import com.vci.web.service.OsRevisionRuleServiceI; import com.vci.web.util.Func; import com.vci.web.util.PlatformClientUtil; import com.vci.web.util.WebUtil; import org.apache.commons.lang3.StringUtils; +import org.apache.poi.hssf.util.HSSFColor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import javax.swing.*; import java.awt.*; +import java.io.File; import java.util.*; import java.util.List; import java.util.stream.Collectors; @@ -44,6 +63,16 @@ @Autowired(required = false) @Lazy private OsRevisionRuleServiceI self; + + /** + * 鏃ュ織 + */ + private Logger logger = LoggerFactory.getLogger(getClass()); + + /** + * 蹇呭~鍒� + */ + private List<Integer> ColumnNameisRed = new ArrayList<Integer>(); /** * 鏌ヨ鎵�鏈夌殑鐗堟湰瑙勫垯 @@ -82,7 +111,7 @@ //鐗堟湰瑙勫垯鍚堣妫�楠� this.checkVersionRule(osRevisionRuleDTO); //鏌ラ噸 - VersionRule vr = platformClientUtil.getVersionService().getVersionRule(osRevisionRuleDTO.getName()); + VersionRule vr = platformClientUtil.getVersionService().getVersionRule(osRevisionRuleDTO.getId()); //name涓嶄负绌� if(Func.isNotEmpty(vr) && !"".equals(vr.name)){ throw new PLException("500",new String[]{"鍚嶇О閲嶅璇锋洿鎹㈠悕绉�!"}); @@ -108,6 +137,50 @@ throw new PLException("500",new String[]{"淇敼鐨勭増鏈鍒欏湪绯荤粺涓笉瀛樺湪!"}); } return platformClientUtil.getVersionService().modifyVersionRule(this.dto2VersionRule(osRevisionRuleDTO)); + } + + /** + * 鍒犻櫎鐗堟湰瑙勫垯 + * @param osRevisionRuleDTOS + * @return + */ + @Override + public boolean deleteVersionRule(List<OsRevisionRuleDTO> osRevisionRuleDTOS) throws PLException { + VciBaseUtil.alertNotNull(osRevisionRuleDTOS,"寰呭垹闄ょ殑灞炴�у垪琛�"); + //鍒ゆ柇瑕佸垹闄ょ殑鐗堟湰瑙勫垯鏄惁鏈夎寮曠敤 + osRevisionRuleDTOS.stream().forEach(item->{ + String vrName = item.getId(); + try { + String[] btNamesByVerName = platformClientUtil.getBtmService().getBTNamesByVerName(vrName); + if(btNamesByVerName != null && btNamesByVerName.length > 0){ + throw new VciBaseException("璇ョ増鏈凡琚娇鐢ㄤ笉鍏佽鍒犻櫎"); + } + } catch (PLException e) { + logger.error(e.getMessage()); + e.printStackTrace(); + throw new VciBaseException(e.getMessage()); + } + }); + + //骞冲彴鐨刣eleteStatus鏂规硶蹇呬紶涓変釜鍙傛暟锛宱id銆乶ame鍜宼s + List<VersionRule> vrList = new ArrayList<>(); + for(OsRevisionRuleDTO vrDTO : osRevisionRuleDTOS){ + //oid鍜宼s鍒ょ┖ + String oid = vrDTO.getOid(); + //id涓昏鐢ㄦ潵瀵圭紦瀛樻暟鎹垹闄� + String id = vrDTO.getId(); + //鍚庡彴浼氱敤ts杩涜鏁版嵁涓�鑷存�ф牎楠� + Date ts = vrDTO.getTs(); + if(Func.isBlank(oid) || Func.isBlank(id) || Func.isEmpty(ts)){ + throw new PLException("500",new String[]{"寰呭垹闄ょ殑鐘舵�佸垪琛ㄤ腑涓婚敭銆恛id銆戙�佽皟鏁存椂闂淬�恡s銆戙�佺姸鎬佸悕绉般�恘ame銆戜笉鑳戒负绌猴紒"}); + } + VersionRule vr = new VersionRule(); + vr.oid = oid; + vr.name = id; + vr.ts = Func.format(ts,VciDateUtil.DateTimeMillFormat); + vrList.add(vr); + } + return platformClientUtil.getVersionService().deleteVersionRules(vrList.toArray(new VersionRule[vrList.size()])); } /** @@ -142,7 +215,7 @@ if(Func.isNotBlank(dto.getPrefixion()) && (dto.getPrefixion().matches(regex3))){ throw new PLException("500",new String[]{"鍓嶇紑涓嶈兘浠ョ┖鏍煎紑澶�"}); } - if (dto.getPrefixion().length() + dto.getPrefixion().length() > 32) { + if (Func.isNotBlank(dto.getPrefixion()) && dto.getPrefixion().length() > 32) { throw new PLException("500",new String[]{"鍓嶇紑涓嶈兘瓒呰繃32涓瓧绗�"}); } //鍚庣紑鐩稿叧鍒ゆ柇 @@ -150,7 +223,7 @@ if(Func.isNotBlank(dto.getSuffix()) && (dto.getSuffix().matches(regex4))){ throw new PLException("500",new String[]{"鍚庣紑涓嶈兘浠ョ┖鏍肩粨灏�"}); } - if (dto.getSuffix().length() + dto.getSuffix().length() > 32) { + if (Func.isNotBlank(dto.getSuffix()) && dto.getSuffix().length() > 32) { throw new PLException("500",new String[]{"鍚庣紑涓嶈兘瓒呰繃32涓瓧绗�"}); } if (dto.getId().length() > 255) { @@ -164,6 +237,7 @@ */ private VersionRule dto2VersionRule(OsRevisionRuleDTO osRevisionRuleDTO){ VersionRule newVR = new VersionRule(); + newVR.oid = osRevisionRuleDTO.getOid(); newVR.name = osRevisionRuleDTO.getId(); newVR.tag = osRevisionRuleDTO.getName(); newVR.description = osRevisionRuleDTO.getDescription(); @@ -172,8 +246,9 @@ newVR.stepLength = osRevisionRuleDTO.getStepLength(); newVR.prefixion = osRevisionRuleDTO.getPrefixion(); newVR.suffix = osRevisionRuleDTO.getSuffix(); - String userName = "developer";//WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); + String userName = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); long timeMillis = System.currentTimeMillis(); + newVR.ts = Func.format((Func.isNotEmpty(osRevisionRuleDTO.getTs()) ? osRevisionRuleDTO.getTs():new Date()),VciDateUtil.DateTimeMillFormat); newVR.creator = Func.isBlank(osRevisionRuleDTO.getCreator()) ? userName:osRevisionRuleDTO.getCreator(); newVR.createTime = Func.isEmpty(osRevisionRuleDTO.getCreateTime()) ? timeMillis:osRevisionRuleDTO.getCreateTime().getTime(); newVR.modifier = userName; @@ -213,7 +288,7 @@ try { ruleVO.setCreateTime(VciDateUtil.long2Date(versionRule.createTime)); ruleVO.setLastModifyTime(VciDateUtil.long2Date(versionRule.modifyTime)); - ruleVO.setTs(VciDateUtil.str2Date(versionRule.ts,VciDateUtil.DateTimeFormat)); + ruleVO.setTs(VciDateUtil.str2Date(versionRule.ts,VciDateUtil.DateTimeMillFormat)); } catch (Exception e) { e.printStackTrace(); } @@ -245,6 +320,27 @@ } /** + * 浣跨敤澶氫釜缂栧彿鑾峰彇瑙勫垯鐨勫�� + * @param vrIdList 缂栧彿 + * @return 鏄剧ず瀵硅薄 + */ + @Override + public List<OsRevisionRuleVO> getRevisionRuleByIds(Collection<String> vrIdList) { + if(Func.isEmpty(vrIdList)){ + return null; + } + Map<String, OsRevisionRuleVO> revisionRuleVOMap = self.selectAllRevisionMap(); + List<OsRevisionRuleVO> versionRuleList = new ArrayList<>(); + vrIdList.stream().forEach(vrId->{ + OsRevisionRuleVO versionRuleVO = revisionRuleVOMap.getOrDefault(vrId.toLowerCase(Locale.ROOT),null); + if(versionRuleVO!=null){ + versionRuleList.add(versionRuleVO); + } + }); + return versionRuleList; + } + + /** * 鏌ヨ搴旂敤鑼冨洿 * @param vrName 鐗堟湰瑙勫垯鑻辨枃鍚嶇О * @return @@ -269,6 +365,210 @@ } /** + * 瀵煎嚭閫変腑鐨勭増鏈鍒� + * @param exportFileName 瀵煎嚭鐨勬枃浠跺悕 + * @param vrNames 闇�瑕佸鍑虹殑鐗堟湰瑙勫垯鍚嶇О + * @param flag 鎺у埗瀵煎嚭鐨勫垪鍚嶆槸鍚﹀拰瀵煎叆妯℃澘涓�鑷� + * @return + */ + @Override + public String exportVersionRule(String exportFileName, String vrNames, boolean flag) throws PLException { + if(Func.isBlank(vrNames)){ + throw new PLException("500",new String[]{"璇峰嬀閫夎瀵煎嚭鐨勭増鏈鍒�!"}); + } + //鐣岄潰娌′紶鍚嶇О锛屼娇鐢ㄩ粯璁ゅ鍑哄悕绉� + exportFileName = Func.isBlank(exportFileName) ? "鐗堟湰瑙勫垯瀵煎嚭_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName; + //璁剧疆鍒楀悕 + List<String> columns = this.getCloumns(flag); + + //鍐檈xcel + String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName + ".xls"; + try { + new File(excelPath).createNewFile(); + } catch (Throwable e) { + throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e); + } + //璁剧疆鍒� + List<WriteExcelData> excelDataList = new ArrayList<>(); + //璁剧疆鍒楀ご + for (int index = 0; index < columns.size(); index++) { + excelDataList.add(new WriteExcelData(0,index, columns.get(index))); + } + //鎸夌収鐗堟湰瑙勫垯鍚嶆煡璇紝鐒跺悗澶勭悊鐗堟湰瑙勫垯瀵煎嚭 + List<String> vrIdList = Func.toStrList(vrNames); + List<OsRevisionRuleVO> revisionRuleVOList = this.getRevisionRuleByIds(vrIdList); + if(Func.isEmpty(revisionRuleVOList)){ + excelDataList.add(new WriteExcelData(1,1, "鏍规嵁鍚嶇О鏈煡璇㈠埌鐗堟湰瑙勫垯淇℃伅锛岃鍒锋柊鍚庡皾璇曢噸鏂板鍑猴紒")); + }else{ + for (int i = 0; i < revisionRuleVOList.size(); i++) { + OsRevisionRuleVO revisionRuleVO = revisionRuleVOList.get(i); + excelDataList.add(new WriteExcelData(i+1,0, revisionRuleVO.getId())); + excelDataList.add(new WriteExcelData(i+1,1, revisionRuleVO.getName())); + excelDataList.add(new WriteExcelData(i+1,2, revisionRuleVO.getJumpCharacter())); + excelDataList.add(new WriteExcelData(i+1,3, revisionRuleVO.getInitialValue())); + excelDataList.add(new WriteExcelData(i+1,4, revisionRuleVO.getStepLength())); + excelDataList.add(new WriteExcelData(i+1,5, revisionRuleVO.getPrefixion())); + excelDataList.add(new WriteExcelData(i+1,6, revisionRuleVO.getSuffix())); + excelDataList.add(new WriteExcelData(i+1,7, revisionRuleVO.getDescription())); + if(!flag){ + excelDataList.add(new WriteExcelData(i+1,8, Func.format(revisionRuleVO.getCreateTime(),"yyyy骞碝M鏈坉d鏃� hh:mm:ss"))); + } + } + } + WriteExcelOption excelOption = new WriteExcelOption(excelDataList); + ExcelUtil.writeDataToFile(excelPath, excelOption); + return excelPath; + } + + /** + * 涓嬭浇鐗堟湰瑙勫垯瀵煎叆妯℃澘 + * @param exportFileName + * @return + * @throws PLException + */ + @Override + public String downloadVersionRuleTemplate(String exportFileName) throws Exception { + //鐣岄潰娌′紶鍚嶇О锛屼娇鐢ㄩ粯璁ゅ鍑哄悕绉� + exportFileName = Func.isBlank(exportFileName) ? "鐗堟湰瑙勫垯瀵煎叆妯℃澘_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName; + //璁剧疆鍒楀悕 + List<String> columns = this.getCloumns(true); + //璁剧疆蹇呭~鍒� + ColumnNameisRed.clear(); + ColumnNameisRed.add(0); + ColumnNameisRed.add(3); + ColumnNameisRed.add(4); + + //鍐檈xcel + String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName + ".xls"; + try { + new File(excelPath).createNewFile(); + } catch (Throwable e) { + throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e); + } + //璁剧疆鍒� + List<WriteExcelData> excelDataList = new ArrayList<>(); + //璁剧疆鍒楀ご + for (int index = 0; index < columns.size(); index++) { + //鍒ゆ柇鏄惁涓哄繀濉垪锛岀粰蹇呭~鍒楄缃鑹� + if(ColumnNameisRed.contains(index)){ + WriteExcelData excelData = new WriteExcelData(0, index, columns.get(index)); + excelData.setFontColor(String.valueOf(HSSFColor.HSSFColorPredefined.RED.getIndex())); + excelDataList.add(excelData); + }else{ + excelDataList.add(new WriteExcelData(0,index, columns.get(index))); + } + } + WriteExcelOption excelOption = new WriteExcelOption(excelDataList); + ExcelUtil.writeDataToFile(excelPath, excelOption); + return excelPath; + } + + /** + * 瀵煎叆鐗堟湰瑙勫垯 + * @param file + * @return + */ + @Override + public BaseResult importVersionRules(File file) throws Exception { + VciBaseUtil.alertNotNull(file,"excel鏂囦欢"); + if(!file.exists()){ + throw new VciBaseException("瀵煎叆鐨別xcel鏂囦欢涓嶅瓨鍦�,{0}",new String[]{file.getPath()}); + } + try{ + //1銆佽鍙杄xcel涓殑鏁版嵁锛岀粍鎴愬璞� + ReadExcelOption excelOption = new ReadExcelOption(); + List<OsRevisionRulePO> poList = ExcelUtil.readDataObjectFromExcel(file, OsRevisionRulePO.class,excelOption,(value, po, fieldName)->{}); + //鍘婚櫎閮芥槸绌虹殑鎯呭喌 + if(CollectionUtils.isEmpty(poList)){ + return BaseResult.fail(ExcelLangCodeConstant.IMPORT_CONTENT_NULL,new String[]{}); + } + //excel鍒ら噸锛屾暟鎹牎楠岋紝dto瀵硅薄杞崲锛屽瓨鍌ㄥ璞¤浆鎹紝鎵ц淇濆瓨 + List<OsRevisionRuleDTO> dtoList = new ArrayList<>(); + //褰撳墠excel涓槸鍚﹂噸澶嶇敤鐨勫垽閲峂ap:锛坘ey锛氬垽閲嶇増鏈鍒欏悕锛寁alue锛氳鍙凤級 + Map<String, String> excelReapeat = new HashMap<>(); + //鏁版嵁搴撴煡璇㈡槸鍚︽湁宸插瓨鍦ㄧ殑鏋氫妇鍚嶏紝鏂逛究鍚庣画鍋氬垽閲嶅鐞� + List<OsRevisionRuleVO> versionRuleVOList = this.getRevisionRuleByIds(poList.stream().map(OsRevisionRulePO::getId).collect(Collectors.toSet())); + List<String> repeatVrId = new ArrayList<>(); + if(Func.isNotEmpty(versionRuleVOList)){ + repeatVrId = versionRuleVOList.stream().map(OsRevisionRuleVO::getId).collect(Collectors.toList()); + } + //鍒ゆ柇蹇呭~灞炴�ф槸鍚︿负绌哄拰鍏朵粬鏍¢獙 + List<String> finalRepeatVrId = repeatVrId; + poList.stream().forEach(vrPO -> { + if(Func.isBlank(vrPO.getId())){//鐗堟湰瑙勫垯鍚嶅垽绌� + throw new VciBaseException("绗��"+vrPO.getRowIndex()+"銆戣锛寁ersionrulenameerror"); + }else if(excelReapeat.containsKey(vrPO.getId())){//鐗堟湰瑙勫垯鍚嶈〃鏍间腑鍒ら噸 + throw new VciBaseException("绗��"+excelReapeat.get(vrPO.getId())+"銆戣鍜岀銆�"+vrPO.getRowIndex()+"銆戣鏁版嵁锛屽悕绉伴噸澶�"); + }else if (Func.isNotEmpty(finalRepeatVrId) && finalRepeatVrId.contains(vrPO.getId())){//鍒ゆ柇鍚嶇О鏄惁涓庣郴缁熶腑閲嶅 + throw new VciBaseException("绗��"+vrPO.getRowIndex()+"銆戣锛屽悕绉板湪绯荤粺涓凡缁忓瓨鍦�,璇蜂慨鏀�!"); + } + + //鐗堟湰瑙勫垯鍚峞xcel涓垽閲嶅鐞� + excelReapeat.put(vrPO.getId(),vrPO.getRowIndex()); + OsRevisionRuleDTO revisionRuleDTO = new OsRevisionRuleDTO(); + //revisionRuleDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT)); + revisionRuleDTO.setId(vrPO.getId()); + revisionRuleDTO.setName(vrPO.getName()); + revisionRuleDTO.setJumpCharacter(vrPO.getJumpCharacter()); + revisionRuleDTO.setInitialValue(vrPO.getInitialValue()); + revisionRuleDTO.setStepLength(vrPO.getStepLength()); + revisionRuleDTO.setPrefixion(vrPO.getPrefixion()); + revisionRuleDTO.setSuffix(vrPO.getSuffix()); + revisionRuleDTO.setDescription(vrPO.getDescription()); + try { + //妫�鏌ョ増鏈鍒欐槸鍚﹀悎瑙� + checkVersionRule(revisionRuleDTO); + } catch (PLException e) { + e.printStackTrace(); + throw new VciBaseException(VciBaseUtil.getExceptionMessage(e)); + } + dtoList.add(revisionRuleDTO); + }); + //鎵ц淇濆瓨鎿嶄綔 + dtoList.stream().forEach(dto->{ + try { + boolean b = platformClientUtil.getVersionService().addVersionRule(dto2VersionRule(dto)); + if(!b){ + throw new VciBaseException("save and return false"); + } + } catch (PLException e) { + e.printStackTrace(); + throw new VciBaseException("鎵ц淇濆瓨鏃跺嚭鐜伴敊璇紝閿欒鐗堟湰瑙勫垯瀵硅薄鍚嶄负锛氥��" + dto.getId() + "銆戯紝鍘熷洜锛�"+VciBaseUtil.getExceptionMessage(e)); + } + }); + }catch (Exception e){ + if(logger.isErrorEnabled()){ + logger.error("璇诲彇excel鍐呭鏃舵垨淇濆瓨鐢ㄦ埛淇℃伅鏃跺嚭鐜颁簡閿欒锛屽叿浣撳師鍥狅細",VciBaseUtil.getExceptionMessage(e)); + } + e.printStackTrace(); + return BaseResult.fail(VciBaseUtil.getExceptionMessage(e),new String[]{},e); + } + return BaseResult.success("鏋氫妇瀵煎叆鎴愬姛锛�"); + } + + /** + * 鑾峰彇瀵煎嚭鎴栧鍏ユā鏉跨殑鍒楀悕 + * @param flag 鏄惁鑾峰彇瀵煎叆妯℃澘鍒楀悕 + * @return + */ + private List<String> getCloumns(boolean flag){ + if(flag){ + return new ArrayList<>( + Arrays.asList( + "鍚嶇О", "鏍囩", "璺宠穬瀛楃锛堜互閫楀彿鍒嗛殧锛�", + "鍒濆鍊�", "姝ラ暱", "鍓嶇紑", "鍚庣紑", "鎻忚堪" + ) + ); + } + return new ArrayList<>( + Arrays.asList( + "鍚嶇О", "鏍囩", "璺宠穬瀛楃", "鍒濆鍊�", "姝ラ暱", + "鍓嶇紑", "鍚庣紑", "鎻忚堪", "鍒涘缓鏃堕棿" + ) + ); + } + + /** * 娓呴櫎缂撳瓨 */ @Override -- Gitblit v1.9.3