| | |
| | | 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; |
| | | |
| | | /** |
| | | * 版本规则的服务 |
| | |
| | | @Autowired(required = false) |
| | | @Lazy |
| | | private OsRevisionRuleServiceI self; |
| | | |
| | | /** |
| | | * 查询所有的版本规则 |
| | | * |
| | |
| | | * @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对象转换为VersionRule对象 |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 查询应用范围 |
| | | * @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() { |
| | | |
| | | } |
| | | |
| | | } |