From 79120a1740872fbb20a79d0cde0a3fa9f55ec285 Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期三, 31 七月 2024 17:29:12 +0800
Subject: [PATCH] 版本规则新增、修改接口上传。

---
 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsRevisionRuleServiceImpl.java |  163 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 151 insertions(+), 12 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 cafde0d..08b20db 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
@@ -1,24 +1,28 @@
 package com.vci.web.service.impl;
 
+import com.vci.client.mw.ClientSessionUtility;
 import com.vci.corba.common.PLException;
 import com.vci.corba.omd.vrm.VersionRule;
+import com.vci.dto.OsRevisionRuleDTO;
 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.web.constant.CacheKeyConstant;
-import com.vci.web.pageModel.OsRevisionRuleVO;
+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.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cache.annotation.CachePut;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
+import javax.swing.*;
+import java.awt.*;
 import java.util.*;
+import java.util.List;
 import java.util.stream.Collectors;
-
-import static com.vci.web.constant.CacheNameConstant.VCI_OBJECT_SERVICE;
 
 /**
  * 鐗堟湰瑙勫垯鐨勬湇鍔�
@@ -40,6 +44,7 @@
     @Autowired(required = false)
     @Lazy
     private OsRevisionRuleServiceI self;
+
     /**
      * 鏌ヨ鎵�鏈夌殑鐗堟湰瑙勫垯
      *
@@ -60,10 +65,120 @@
      * @return key 鏄増鏈殑鑻辨枃鍚嶇О
      */
     @Override
-    @CachePut(value = VCI_OBJECT_SERVICE,key = CacheKeyConstant.ALL_REVISION,unless = "#result ==null ")
     @VciUnLog
     public Map<String, OsRevisionRuleVO> selectAllRevisionMap() {
         return Optional.ofNullable(self.selectAllRevision()).orElseGet(()->new ArrayList<>()).stream().collect(Collectors.toMap(s->s.getId().toLowerCase(),t->t,(o1,o2)->o1));
+    }
+
+    /**
+     * 鍒涘缓鐗堟湰瑙勫垯
+     * @param osRevisionRuleDTO
+     * @return
+     */
+    @Override
+    public boolean addVersionRule(OsRevisionRuleDTO osRevisionRuleDTO) throws PLException {
+        //鍒ょ┖
+        VciBaseUtil.alertNotNull(osRevisionRuleDTO,"鐗堟湰瑙勫垯瀵硅薄",osRevisionRuleDTO.getId(),"鐗堟湰瑙勫垯鍚嶇О");
+        //鐗堟湰瑙勫垯鍚堣妫�楠�
+        this.checkVersionRule(osRevisionRuleDTO);
+        //鏌ラ噸
+        VersionRule vr = platformClientUtil.getVersionService().getVersionRule(osRevisionRuleDTO.getName());
+        //name涓嶄负绌�
+        if(Func.isNotEmpty(vr) && !"".equals(vr.name)){
+            throw new PLException("500",new String[]{"鍚嶇О閲嶅璇锋洿鎹㈠悕绉�!"});
+        }
+        return platformClientUtil.getVersionService().addVersionRule(this.dto2VersionRule(osRevisionRuleDTO));
+    }
+
+    /**
+     * 淇敼鐗堟湰瑙勫垯
+     * @param osRevisionRuleDTO
+     * @return
+     */
+    @Override
+    public boolean updateVersionRule(OsRevisionRuleDTO osRevisionRuleDTO) throws PLException {
+        //鍒ょ┖
+        VciBaseUtil.alertNotNull(osRevisionRuleDTO,"鐗堟湰瑙勫垯瀵硅薄",osRevisionRuleDTO.getId(),"鐗堟湰瑙勫垯鍚嶇О");
+        //鍒ゆ柇鏄惁鍦ㄧ郴缁熶腑瀛樺湪
+        VersionRule vr = platformClientUtil.getVersionService().getVersionRule(osRevisionRuleDTO.getName());
+        //鐗堟湰瑙勫垯鍚堣妫�楠�
+        this.checkVersionRule(osRevisionRuleDTO);
+        //name涓嶄负绌�
+        if(Func.isEmpty(vr) && !"".equals(vr.name)){
+            throw new PLException("500",new String[]{"淇敼鐨勭増鏈鍒欏湪绯荤粺涓笉瀛樺湪!"});
+        }
+        return platformClientUtil.getVersionService().modifyVersionRule(this.dto2VersionRule(osRevisionRuleDTO));
+    }
+
+    /**
+     * 妫�鏌ョ増鏈鍒欒缃殑鏄惁鍚堢悊
+     * @param dto
+     */
+    private void checkVersionRule(OsRevisionRuleDTO dto) throws PLException {
+        //鐗堟湰瑙勫垯鍚嶇О鍙兘涓鸿嫳鏂囧瓧姣�
+        String regex = "[a-z A-Z]*";
+        if (!dto.getId().matches(regex)) {
+            throw new PLException("500",new String[]{"鍚嶇О鍙兘涓鸿嫳鏂囷紒"});
+        }
+        //璺宠穬瀛楃鍙兘涓烘暟瀛楁垨鑰呭瓧姣�
+        if(Func.isNotBlank(dto.getJumpCharacter()) && (!(dto.getJumpCharacter().matches(regex)))){
+            throw new PLException("500",new String[]{"璺宠穬瀛楃鍙兘涓烘暟瀛楁垨鑰呭瓧姣嶏紒"});
+        }
+        //鍒濆鍊间笉鑳戒负绌轰笖鍙兘涓烘暟瀛楁垨鑰呭瓧姣嶆垨鑻辨枃鐘舵�佷笅鐨勭鍙�
+        String regex1 = "[A-Za-z0-9!@#$%^&*()-_=+{}':|;,.?/]+$";
+        if(Func.isBlank(dto.getInitialValue()) || !dto.getInitialValue().matches(regex1)){
+            throw new PLException("500",new String[]{"鍒濆鍊间笉鑳戒负绌轰笖鍙兘涓烘暟瀛楁垨鑰呭瓧姣嶆垨鑻辨枃鐘舵�佷笅鐨勭鍙凤紒"});
+        }
+        if(dto.getInitialValue().length() + dto.getInitialValue().length() > 32) {
+            throw new PLException("500",new String[]{"鍒濆鍊间笉鑳借秴杩�32涓瓧绗︼紒"});
+        }
+        //姝ラ暱涓嶈兘涓虹┖涓斿繀椤讳负1-9鐨勬鏁存暟
+        String regex2 = "[1-9]";
+        if(Func.isBlank(dto.getStepLength()) || (!dto.getStepLength().matches(regex2))){
+            throw new PLException("500",new String[]{"姝ラ暱涓嶈兘涓虹┖涓斿繀椤讳负1-9鐨勬鏁存暟"});
+        }
+        //鍓嶇紑鐩稿叧鍒ゆ柇
+        String regex3 = "^\\s+.*";
+        if(Func.isNotBlank(dto.getPrefixion()) && (dto.getPrefixion().matches(regex3))){
+            throw new PLException("500",new String[]{"鍓嶇紑涓嶈兘浠ョ┖鏍煎紑澶�"});
+        }
+        if (dto.getPrefixion().length() + dto.getPrefixion().length() > 32) {
+            throw new PLException("500",new String[]{"鍓嶇紑涓嶈兘瓒呰繃32涓瓧绗�"});
+        }
+        //鍚庣紑鐩稿叧鍒ゆ柇
+        String regex4 = "^*.\\s+$";
+        if(Func.isNotBlank(dto.getSuffix()) && (dto.getSuffix().matches(regex4))){
+            throw new PLException("500",new String[]{"鍚庣紑涓嶈兘浠ョ┖鏍肩粨灏�"});
+        }
+        if (dto.getSuffix().length() + dto.getSuffix().length() > 32) {
+            throw new PLException("500",new String[]{"鍚庣紑涓嶈兘瓒呰繃32涓瓧绗�"});
+        }
+        if (dto.getId().length() > 255) {
+            throw new PLException("500",new String[]{"鍚嶇О涓嶈兘瓒呰繃255涓瓧绗�"});
+        }
+    }
+
+    /**
+     * dto瀵硅薄杞崲涓篤ersionRule瀵硅薄
+     * @return
+     */
+    private VersionRule dto2VersionRule(OsRevisionRuleDTO osRevisionRuleDTO){
+        VersionRule newVR = new VersionRule();
+        newVR.name = osRevisionRuleDTO.getId();
+        newVR.tag = osRevisionRuleDTO.getName();
+        newVR.description = osRevisionRuleDTO.getDescription();
+        newVR.jumpCharacter = osRevisionRuleDTO.getJumpCharacter();
+        newVR.initialValue = osRevisionRuleDTO.getInitialValue();
+        newVR.stepLength = osRevisionRuleDTO.getStepLength();
+        newVR.prefixion = osRevisionRuleDTO.getPrefixion();
+        newVR.suffix = osRevisionRuleDTO.getSuffix();
+        String userName = "developer";//WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId();
+        long timeMillis = System.currentTimeMillis();
+        newVR.creator = Func.isBlank(osRevisionRuleDTO.getCreator()) ? userName:osRevisionRuleDTO.getCreator();
+        newVR.createTime = Func.isEmpty(osRevisionRuleDTO.getCreateTime()) ? timeMillis:osRevisionRuleDTO.getCreateTime().getTime();
+        newVR.modifier = userName;
+        newVR.modifyTime = timeMillis;
+        return newVR;
     }
 
     /**
@@ -105,11 +220,11 @@
             ruleVO.setDescription(versionRule.description);
             ruleVO.setId(versionRule.name);
             ruleVO.setName(versionRule.tag);
-            ruleVO.setSerialStep(WebUtil.getInt(versionRule.stepLength));
-            ruleVO.setSkipCode(versionRule.jumpCharacter);
-            ruleVO.setPrefixCode(versionRule.prefixion);
-            ruleVO.setSuffixCode(versionRule.suffix);
-            ruleVO.setStartCode(versionRule.initialValue);
+            ruleVO.setStepLength(WebUtil.getInt(versionRule.stepLength));
+            ruleVO.setJumpCharacter(versionRule.jumpCharacter);
+            ruleVO.setPrefixion(versionRule.prefixion);
+            ruleVO.setSuffix(versionRule.suffix);
+            ruleVO.setInitialValue(versionRule.initialValue);
             //associated鏆傛椂娌℃湁浣跨敤
         }
         return ruleVO;
@@ -130,11 +245,35 @@
     }
 
     /**
+     * 鏌ヨ搴旂敤鑼冨洿
+     * @param vrName 鐗堟湰瑙勫垯鑻辨枃鍚嶇О
+     * @return
+     */
+    @Override
+    public List<Map<String, String>> getUsedVersionRuleList(String vrName) throws PLException {
+        if(Func.isBlank(vrName)){
+            throw new PLException("500",new String[]{"璇烽�夋嫨瑕佹煡璇㈠簲鐢ㄨ寖鍥寸殑灞炴��!"});
+        }
+        String[] btNames = platformClientUtil.getBtmService().getBTNamesByVerName(vrName);
+        if(Func.isEmpty(btNames)){
+            return new ArrayList<>();
+        }
+        List<Map<String,String>> btmNameMapList = new ArrayList<>();
+        Arrays.stream(btNames).forEach(btName->{
+            Map<String, String> itemMap = new HashMap<>();
+            itemMap.put("versionRuleName",vrName);
+            itemMap.put("source",btName);
+            btmNameMapList.add(itemMap);
+        });
+        return btmNameMapList;
+    }
+
+    /**
      * 娓呴櫎缂撳瓨
      */
     @Override
-    @CachePut(value = VCI_OBJECT_SERVICE,key = CacheKeyConstant.ALL_REVISION)
     public void clearCache() {
 
     }
+
 }

--
Gitblit v1.9.3