From c606a7210097ca126fcf9fdb123cebf2a964f51d Mon Sep 17 00:00:00 2001 From: xiejun <xiejun@vci-tech.com> Date: 星期四, 26 十二月 2024 16:51:44 +0800 Subject: [PATCH] 集成获取mdm分发通用数据格式接口集成 日志输出到日志文件中 --- Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleCharacterServiceImpl.java | 112 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 90 insertions(+), 22 deletions(-) diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleCharacterServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleCharacterServiceImpl.java index aaabd6f..bdd4be6 100644 --- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleCharacterServiceImpl.java +++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleCharacterServiceImpl.java @@ -1,6 +1,5 @@ package com.vci.ubcs.code.service.impl; -import com.alibaba.nacos.common.utils.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -12,11 +11,13 @@ import com.vci.ubcs.starter.exception.VciBaseException; import com.vci.ubcs.starter.util.DefaultAttrAssimtUtil; import com.vci.ubcs.starter.web.util.VciBaseUtil; +import lombok.AllArgsConstructor; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.rmi.ServerException; import java.util.*; import java.util.stream.Collectors; @@ -26,10 +27,11 @@ * @date 2023-11-30 */ @Service +@AllArgsConstructor public class CodeRuleCharacterServiceImpl extends ServiceImpl<CodeRuleCharacterMapper, CodeRuleCharacter> implements ICodeRuleCharacterService { - @Autowired - private CodeRuleCharacterMapper codeRuleCharacterMapper; + private final CodeRuleCharacterMapper codeRuleCharacterMapper; + /*** * 浣跨敤缂栫爜瑙勫垯oid鑾峰彇鏁版嵁 * @param codeRuleId @@ -41,21 +43,59 @@ public List<Map<String, String>> getDataByRuleId(String codeRuleId,String chartType) throws VciBaseException { List<Map<String,String>> charValueList=new ArrayList<>(); CodeRuleCharacter codeRuleCharacter=codeRuleCharacterMapper.selectOne(Wrappers.<CodeRuleCharacter>query().lambda().eq(CodeRuleCharacter::getCodeRuleId,codeRuleId).eq(CodeRuleCharacter::getChartType,chartType)); - List<Character> characterList=codeRuleCharacter.getChartValue().chars().mapToObj(c -> (char) c).collect(Collectors.toList()); - for (int i = 0; i < characterList.size(); i += 15) { - final int startIndex = i; - final int endIndex = Math.min(i + 15, characterList.size()); - List<Character> subList = characterList.subList(startIndex, endIndex); - Map<String, String> chartMap=new HashMap<>(); - // 璋冪敤鎻掑叆鏁版嵁搴撶殑鏂规硶 - for (int j=1;j<subList.size()+1;j++){ - String characterValue=subList.get(j-1)==null?"":subList.get(j-1).toString(); - chartMap.put(String.valueOf(j),String.valueOf(characterValue)); + if(codeRuleCharacter!=null&&StringUtils.isNotBlank(codeRuleCharacter.getOid())){ + List<Character> characterList=codeRuleCharacter.getChartValue().chars().mapToObj(c -> (char) c).collect(Collectors.toList()); + for (int i = 0; i < characterList.size(); i += 15) { + final int startIndex = i; + final int endIndex = Math.min(i + 15, characterList.size()); + List<Character> subList = characterList.subList(startIndex, endIndex); + Map<String, String> chartMap=new HashMap<>(); + // 璋冪敤鎻掑叆鏁版嵁搴撶殑鏂规硶 + for (int j=1;j<subList.size()+1;j++){ + String characterValue=subList.get(j-1)==null?"":subList.get(j-1).toString(); + chartMap.put(String.valueOf(j),String.valueOf(characterValue)); + } + charValueList.add(chartMap); } - charValueList.add(chartMap); } return charValueList; } + + /*** + * 浣跨敤缂栫爜瑙勫垯oid鑾峰彇鏁版嵁 + * @param codeRuleId + * @param chartType + * @return + * @throws VciBaseException + */ + @Override + public List<Map<String, String>> getSelectListByRuleId(String codeRuleId,String chartType) throws ServerException { + List<Map<String, String>> charValueMap = new ArrayList<>(); + CodeRuleCharacter codeRuleCharacter=codeRuleCharacterMapper.selectOne(Wrappers.<CodeRuleCharacter>query().lambda().eq(CodeRuleCharacter::getCodeRuleId,codeRuleId).eq(CodeRuleCharacter::getChartType,chartType)); + if(codeRuleCharacter!=null&&StringUtils.isNotBlank(codeRuleCharacter.getOid())){ + List<Character> characterList=codeRuleCharacter.getChartValue().chars().mapToObj(c -> (char) c).collect(Collectors.toList()); + characterList.stream().forEach(item->{ + Map<String, String> map = new HashMap<>(); + map.put("lable",item.toString()); + map.put("value",item.toString()); + charValueMap.add(map); + }); + } + return charValueMap; + } + + @Override + public String getRegexStrByCodeRuleId(String codeRuleId, String chartType) throws ServerException { + StringBuilder regexStr = new StringBuilder(); + CodeRuleCharacter codeRuleCharacter=codeRuleCharacterMapper.selectOne(Wrappers.<CodeRuleCharacter>query().lambda().eq(CodeRuleCharacter::getCodeRuleId,codeRuleId).eq(CodeRuleCharacter::getChartType,chartType)); + if(codeRuleCharacter!=null&&StringUtils.isNotBlank(codeRuleCharacter.getOid())){ + regexStr.append("^["); + regexStr.append(codeRuleCharacter.getChartValue()); + regexStr.append("]+$"); + } + return regexStr.toString(); + } + /*** * 瀛楃闆嗘暟鎹繚瀛� * @param codeRuleCharacterVO @@ -63,20 +103,48 @@ * @throws VciBaseException */ @Override - public R saveOrUpdate(CodeRuleCharacterVO codeRuleCharacterVO) throws VciBaseException { + public R saveOrUpdate(CodeRuleCharacterVO codeRuleCharacterVO,int operation) throws VciBaseException { VciBaseUtil.alertNotNull(codeRuleCharacterVO.getCodeRuleId(),"缂栫爜瑙勫垯id",codeRuleCharacterVO.getChartType(),"瀛楃闆嗙被鍨�"); CodeRuleCharacter codeRuleCharacter=codeRuleCharacterMapper.selectOne(Wrappers.<CodeRuleCharacter>query().lambda().eq(CodeRuleCharacter::getCodeRuleId,codeRuleCharacterVO.getCodeRuleId()).eq(CodeRuleCharacter::getChartType,codeRuleCharacterVO.getChartType())); if(codeRuleCharacter!=null&& StringUtils.isNotBlank(codeRuleCharacter.getOid())) { List<Character> oldCharacterList = StringUtils.isBlank(codeRuleCharacter.getChartValue())?new ArrayList<>():codeRuleCharacter.getChartValue().chars().mapToObj(c -> (char) c).collect(Collectors.toList()); List<Character> newCharacterList = StringUtils.isBlank(codeRuleCharacterVO.getChartValue())?new ArrayList<>():codeRuleCharacterVO.getChartValue().chars().mapToObj(c -> (char) c).collect(Collectors.toList()); - List<Character> intersectList = intersect(oldCharacterList, newCharacterList); - if (intersectList.size() > 0) { - String ss = Joiner.on(",").join(intersectList); - throw new VciBaseException("绯荤粺涓瓨鍦ㄧ浉搴旂殑瀛楃:銆�" + ss + "銆�"); + if(operation==1) {//鏂板鏃跺�� + List<Character> intersectList = intersect(oldCharacterList, newCharacterList); + if (intersectList.size() > 0) { + String ss = Joiner.on(",").join(intersectList); + throw new VciBaseException("绯荤粺涓瓨鍦ㄧ浉搴旂殑瀛楃:銆�" + ss + "銆�"); + } + List<Character> allCharacterList = union(oldCharacterList, newCharacterList); + String str = allCharacterList.stream().map(integer -> Func.isNotEmpty(integer) ? integer.toString() : "").collect(Collectors.joining()); + codeRuleCharacter.setChartValue(str); + }else if(operation==2){//淇敼 + String oldChartValue= codeRuleCharacterVO.getOldChartValue(); + String chartValue= codeRuleCharacterVO.getChartValue(); + Map<String,String> oldChartNewChartMap=new HashMap<>(); + List<Character> chartValueList = StringUtils.isBlank(chartValue)?new ArrayList<>():chartValue.chars().mapToObj(c -> (char) c).collect(Collectors.toList()); + List<Character> oldChartValueList = StringUtils.isBlank(oldChartValue)?new ArrayList<>():oldChartValue.chars().mapToObj(c -> (char) c).collect(Collectors.toList()); + + if(chartValueList.size()!=oldChartValueList.size()){ + throw new VciBaseException("鏇挎崲鐨勫�间釜鏁颁笌閫変腑鍊肩殑涓暟涓嶇浉绛�"); + } + /*** + * id + */ + for (int i=0;i<oldChartValueList.size();i++){ + Character oldValue=oldChartValueList.get(i); + if(oldCharacterList.contains(oldValue)){ + int index =oldCharacterList.indexOf(oldValue); + oldCharacterList.set(index,chartValueList.get(i)); + } + } + String str = oldCharacterList.stream().map(integer -> Func.isNotEmpty(integer) ? integer.toString() : "").collect(Collectors.joining()); + codeRuleCharacter.setChartValue(str); + }else{//鍒犻櫎 + oldCharacterList.removeAll(newCharacterList); + String str = oldCharacterList.stream().map(integer -> Func.isNotEmpty(integer) ? integer.toString() : "").collect(Collectors.joining()); + codeRuleCharacter.setChartValue(str); } - List<Character> allCharacterList = union(oldCharacterList, newCharacterList); - String str = allCharacterList.stream().map(integer -> Func.isNotEmpty(integer)?integer.toString():"").collect(Collectors.joining()); - codeRuleCharacter.setChartValue(str); codeRuleCharacterMapper.updateById(codeRuleCharacter); }else{ codeRuleCharacter=new CodeRuleCharacter(); -- Gitblit v1.9.3