From 43603c1cb538ae4d8c2f6ce4710121c8c95677bd Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期四, 14 十二月 2023 16:43:30 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java | 474 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 448 insertions(+), 26 deletions(-)
diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java
index fcdd558..7768fed 100644
--- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java
@@ -1,6 +1,8 @@
package com.vci.ubcs.code.service.impl;
import com.vci.ubcs.code.algorithm.CustomSerialEnum;
+import com.vci.ubcs.code.annotation.MdmSerialAlgorithm;
+import com.vci.ubcs.code.annotation.MdmSerialAlgorithmMethod;
import com.vci.ubcs.code.dto.CodeCustomSerialDTO;
import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -29,12 +31,15 @@
import com.vci.ubcs.starter.web.constant.QueryOptionConstant;
import com.vci.ubcs.starter.web.constant.RegExpConstant;
import com.vci.ubcs.starter.web.enumpck.OsCodeFillTypeEnum;
+import com.vci.ubcs.starter.web.util.ApplicationContextProvider;
import com.vci.ubcs.starter.web.util.VciBaseUtil;
import com.vci.ubcs.starter.web.util.VciDateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@@ -42,16 +47,17 @@
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
-import java.lang.reflect.InvocationTargetException;
+import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import static com.vci.ubcs.code.constant.MdmEngineConstant.*;
+import static com.vci.ubcs.code.enumpack.CodeSecTypeEnum.CODE_SERIAL_SEC;
+
@Service
@Slf4j
public class MdmProductCodeServiceImpl implements MdmProductCodeService {
@@ -93,7 +99,7 @@
@Override
@Transactional(rollbackFor = Exception.class)
- public List<String> productCodeAndSaveData(CodeClassifyFullInfoBO classifyFullInfoBO, CodeClassifyTemplateVO templateVO, CodeRuleVO ruleVO, List<CodeOrderSecDTO> secDTOList, List<BaseModel> dataCBOList) throws Exception {
+ public List<String> productCodeAndSaveData(CodeClassifyFullInfoBO classifyFullInfoBO, CodeClassifyTemplateVO templateVO, CodeRuleVO ruleVO, List<CodeOrderSecDTO> secDTOList, List<BaseModel> dataCBOList,BladeUser user) throws Exception {
dataCBOList = dataCBOList.stream().sorted(((o1, o2) -> o1.getCreateTime().compareTo(o2.getCreateTime()))).collect(Collectors.toList());
List<String> codeList = new ArrayList<>();
final CodeRuleVO finalRuleVO = ruleVO;
@@ -104,11 +110,10 @@
// && StringUtils.isNotBlank(cbo.getAttributeValue(CODE_SEC_LENGTH_FIELD))
){
//鏄巻鍙叉暟鎹鍏�
- //鍘嗗彶鏁版嵁鎵ц鐨勬椂鍊欙紝杩欎釜绯荤粺浼氬緢鍗�
//涓昏鏄负浜嗗綍鍏ユ渶澶ф祦姘村彿鍜宎llcode
//SessionInfo sessionInfo = VciBaseUtil.getCurrentUserSessionInfo();
List<CodeAllCode> allCodeDOList = new CopyOnWriteArrayList<>();
- Map<String/**娴佹按渚濇嵁**/, ConcurrentHashMap<String/**鐮佹鐨勪富閿�**/,String/**鏈�澶ф祦姘村彿**/>> maxSerialMap = new ConcurrentHashMap<>();
+ Map<String/**娴佹按渚濇嵁**/, HashMap<String/**鐮佹鐨勪富閿�**/,String/**鏈�澶ф祦姘村彿**/>> maxSerialMap = new HashMap<>();
// TODO 澶氱嚎绋嬫祦寮曞彂鐨勯棶棰樺凡淇敼
dataCBOList.parallelStream().forEach(cbo->{
log.info("code:----->"+cbo.getId());
@@ -124,6 +129,7 @@
Map<String/**鐮佹鐨勪富閿�**/,String/**鐮佹鐨勫��**/> serialValueMap = new HashMap<>();
Map<String, CodeBasicSecVO> secVOMap = secVOList.stream().collect(Collectors.toMap(s -> s.getOid(), t -> t));
Map<String,Integer> serialSecOidIndexMap=new HashMap<>();
+ LinkedList<String> codeValueList=new LinkedList<>();
for (int i = 0; i < secLengths.length; i++) {
CodeBasicSecVO secVO = secVOList.get(i);
String thisSecValue = "";
@@ -143,9 +149,10 @@
serialUnitList.add(thisSecValue);
serialSecOidIndexMap.put(secVO.getOid(),i);
}
- if(CodeSecTypeEnum.CODE_SERIAL_SEC.getValue().equalsIgnoreCase(secVO.getSecType())){
+ if(CODE_SERIAL_SEC.getValue().equalsIgnoreCase(secVO.getSecType())){
serialValueMap.put(secVO.getOid(),thisSecValue);
}
+ codeValueList.add(thisSecValue);
}
List<String> serialUnFileStringList = new ArrayList<>();
AtomicReference<String> newSerialUnitString = new AtomicReference<>("");
@@ -179,8 +186,8 @@
serialDb = killFillChar(subSecValue,secVO.getCodeFillSeparator(),
OsCodeFillTypeEnum.LEFT.getValue().equalsIgnoreCase(secVO.getCodeFillType()));
}
- Double newSerialDb= CustomSerialEnum.getDoubleCustomSerialValue(secValue,secVO.getCustomCodeSerialType());
- ConcurrentHashMap<String, String> thisUnitMaxMap = maxSerialMap.getOrDefault(serialUnitString, new ConcurrentHashMap<>());
+ Double newSerialDb= CustomSerialEnum.getDoubleCustomSerialValue(serialDb,secVO.getCustomCodeSerialType());
+ HashMap<String, String> thisUnitMaxMap = maxSerialMap.getOrDefault(serialUnitString, new HashMap<>());
Double maxValue=newSerialDb;
if(thisUnitMaxMap.containsKey(secOid)){
String newMaxValue= thisUnitMaxMap.getOrDefault(secOid,"");
@@ -197,7 +204,7 @@
});
}
CodeAllCode allCodeDO = new CodeAllCode();
- DefaultAttrAssimtUtil.addDefaultAttrAssimt(allCodeDO, MdmBtmTypeConstant.CODE_ALL_CODE);
+ DefaultAttrAssimtUtil.addDefaultAttrAssimt(allCodeDO, MdmBtmTypeConstant.CODE_ALL_CODE,user);
allCodeDO.setCodeClassifyOid(classifyFullInfoBO.getCurrentClassifyVO().getOid());
allCodeDO.setCodeRuleOid(finalRuleVO.getOid());
allCodeDO.setId(cbo.getId());
@@ -208,6 +215,8 @@
String unFillSerial =serialUnFileStringList.size()==1?serialUnFileStringList.get(0)+ SERIAL_VALUE_SPACE:serialUnFileStringList.stream().collect(Collectors.joining(SERIAL_VALUE_SPACE));
allCodeDO.setUnFillSerial(unFillSerial);
allCodeDO.setLcStatus(cbo.getLcStatus());
+ allCodeDO.setLctid("codeAllCodeLC");
+ allCodeDO.setCodeDelimit(codeValueList.stream().collect(Collectors.joining(SERIAL_VALUE_SPACE)));//娣诲姞閾炬帴绗�
allCodeDOList.add(allCodeDO);
});
//澶勭悊鏈�澶х殑娴佹按鍙�
@@ -229,13 +238,13 @@
log.info("oldmaxSerial--->"+serialValueDO.getMaxSerial()+"---- newmaxSerial---->"+maxSerial);
if(VciBaseUtil.getDouble(serialValueDO.getMaxSerial())<VciBaseUtil.getDouble(maxSerial)){
serialValueDO.setMaxSerial(String.valueOf(maxSerial));
- DefaultAttrAssimtUtil.updateDefaultAttrAssimt(serialValueDO);
+ DefaultAttrAssimtUtil.updateDefaultAttrAssimt(serialValueDO,user);
editSerialValueList.add(serialValueDO);
}
}else{
//娌℃湁
CodeSerialValue serialValueDO = new CodeSerialValue();
- DefaultAttrAssimtUtil.addDefaultAttrAssimt(serialValueDO, MdmBtmTypeConstant.CODE_SERIAL_VALUE);
+ DefaultAttrAssimtUtil.addDefaultAttrAssimt(serialValueDO, MdmBtmTypeConstant.CODE_SERIAL_VALUE,user);
serialValueDO.setCodeRuleOid(finalRuleVO.getOid());
serialValueDO.setSerialUnit(serialUnit);
serialValueDO.setCodeSecOid(secOid);
@@ -256,7 +265,6 @@
}
//澶勭悊allCode
if(!CollectionUtils.isEmpty(allCodeDOList)){
- // TODO 鍘嗗彶鏁版嵁瀵煎叆鐨勬椂鍊欒繖鍎垮伓灏斾細瑙﹀彂绌烘寚閽堝紓甯�
Map<String,List<CodeAllCode>> ruleGroup = allCodeDOList.stream().collect(Collectors.groupingBy(s -> s.getCodeRuleOid()));
Map<String, CodeAllCode> codeDOMap = allCodeDOList.stream().collect(Collectors.toMap(s -> s.getCodeRuleOid() + "${SEP}" + s.getId(), t -> t));
List<CodeAllCode> addCodeDOs = new CopyOnWriteArrayList<>();
@@ -404,22 +412,21 @@
sb.append(serialValue).append(SERIAL_VALUE_SPACE);
}
}
+ String codeDelimiter=thisSecValueList.stream().collect(Collectors.joining(SERIAL_VALUE_SPACE));
//瑕佸瓨鍌ㄦ渶鍚庣殑鍏ㄩ儴allcode
- wrapperAllCode(classifyFullInfoBO, finalRuleVO, cbo, templateVO, allCodeDOList, serialUnitString, sb.toString());
+ wrapperAllCode(classifyFullInfoBO, finalRuleVO, cbo, templateVO, allCodeDOList, serialUnitString, sb.toString(),codeDelimiter);
}
//澶勭悊鏈�澶ф祦姘�
saveSerialValue( finalRuleVO, lastMaxSerialValueMap, maxSerialValueMap);
allCodeDOList.stream().forEach(
- allCode -> {DefaultAttrAssimtUtil.addDefaultAttrAssimt(allCode,"codeallcode");allCode.setLctid("codeAllCodeLC");}
+ allCode -> {DefaultAttrAssimtUtil.addDefaultAttrAssimt(allCode,"codeallcode",user);allCode.setLctid("codeAllCodeLC");}
);
-
Map<String, String> statusMap = allCodeDOList.stream().collect(Collectors.toMap(s -> s.getOid(), s -> s.getLcStatus()));
allCodeDOList.stream().filter(s -> StringUtils.equalsIgnoreCase("codeallcode",s.getBtmname())).forEach(s -> {
s.setLcStatus(statusMap.get(s.getOid()));
});
-
//閫氳繃ID鏉ヨ繘琛屽幓閲�
List<CodeAllCode> distinctCodeAllCOdes = allCodeDOList.stream().collect(Collectors
@@ -517,6 +524,122 @@
}
}
+
+
+ /**
+ * 杞崲娴佹按鐮佹鐨勫��
+ * @param serialSecVOList 娴佹按鐮佹
+ * @param secDTOS;娴佹按鍊�
+ * @param attrSevIsSerialDepend 鏄惁鏈夊睘鎬х爜娈靛弬涓庢祦姘�
+ * @param ruleVO 瑙勫垯鐨勫唴瀹�
+ * @param serialUnitMap 娴佹按渚濇嵁
+ * @param maxSerialValueMap 鏈�澶х殑娴佹按鍙�
+ * @param thisSecValueList 鏈鐨勭爜鍊�
+ * @param lastMaxSerialValueMap 灏佽鍚�
+ * @param firstData 鏄惁涓虹涓�鏉℃暟鎹�
+ */
+ private void switchSerialSecValueBZ(BaseModel cbo,List<CodeOrderSecDTO> secDTOS, List<CodeBasicSecVO> serialSecVOList,boolean attrSevIsSerialDepend,
+ CodeRuleVO ruleVO,Map<String,String> serialUnitMap,
+ Map<String/**鐮佹鐨勪富閿�**/,Map<String/**娴佹按渚濇嵁**/,CodeSerialValue>> maxSerialValueMap,List<String> thisSecValueList,
+ Map<String/**鐮佹鐨勪富閿�**/,Map<String/**娴佹按渚濇嵁**/, String>> lastMaxSerialValueMap,boolean firstData){
+ if (!CollectionUtils.isEmpty(serialSecVOList)) {
+ Map<String/**鐮佹oid**/, String/**鐮佹鐮佸��**/> attrNameIdMap = secDTOS.stream().collect(Collectors.toMap(s -> s.getSecOid(), t -> t.getSecValue().toLowerCase(Locale.ROOT),(o1, o2)->o2));
+ Map<String,String> secIdserialValueMap=new LinkedHashMap<>();
+ for (int j = 0; j < serialSecVOList.size(); j++) {
+ AtomicReference<String> serialUnitString= new AtomicReference<>("");
+ CodeBasicSecVO secVO = serialSecVOList.get(j);
+ String secVOValue="";
+ if(attrNameIdMap.containsKey(secVO.getOid())){
+ secVOValue=attrNameIdMap.get(secVO.getOid());
+ if(StringUtils.isNotBlank(secVOValue)){
+ continue;
+ }
+ }
+ if(serialUnitMap.containsKey(secVO.getOid())){
+ serialUnitString.set(serialUnitMap.get(secVO.getOid()));
+ secIdserialValueMap.forEach((key,vaule)->{
+ serialUnitString.set(serialUnitString.get().replace("${"+key+"}", vaule));
+ });
+ if (attrSevIsSerialDepend || firstData) {
+ QueryWrapper<CodeSerialValue> codeSerialWrapper = new QueryWrapper<>();
+ codeSerialWrapper.eq("codeRuleOid", ruleVO.getOid());
+ codeSerialWrapper.eq("serialUnit", serialUnitString.get());
+ codeSerialWrapper.eq("codeSecOid", secVO.getOid());
+ List<CodeSerialValue> serialValueDOS = serialValueMapper.selectList(codeSerialWrapper);
+ if (!CollectionUtils.isEmpty(serialValueDOS)) {
+ Map<String, CodeSerialValue> unitSerialMap = maxSerialValueMap.getOrDefault(secVO.getOid(), new HashMap<>());
+ CodeSerialValue serialValueDO = serialValueDOS.get(0);
+ unitSerialMap.put(serialValueDO.getSerialUnit(),serialValueDO);
+ maxSerialValueMap.put(secVO.getOid(), unitSerialMap);
+ }
+ }
+ String serialString="";
+ String thisSerialValue = "";
+ String startValue = null;
+ if (maxSerialValueMap.containsKey(secVO.getOid()) && maxSerialValueMap.get(secVO.getOid()).containsKey(serialUnitString.get())) {
+ startValue = maxSerialValueMap.get(secVO.getOid()).get(serialUnitString.get()).getMaxSerial();
+ }
+ if (lastMaxSerialValueMap.containsKey(secVO.getOid()) && lastMaxSerialValueMap.get(secVO.getOid()).containsKey(serialUnitString.get())) {
+ //璇存槑澶氫釜鐢宠锛屼箣鍓嶅凡缁忓姞浜嗘祦姘村彿浜�
+ startValue = lastMaxSerialValueMap.get(secVO.getOid()).get(serialUnitString.get());
+ }
+ if(StringUtils.isNotBlank(secVO.getCustomCodeSerialClass())){//鑷畾涔夋祦姘村鐞�
+ String currentFlowValue=startValue;
+ CodeCustomSerialDTO codeCustomSerialDTO=new CodeCustomSerialDTO();
+ codeCustomSerialDTO.setSerialUnitString(serialUnitString.get());
+ codeCustomSerialDTO.setSerialCodeCodeBasicSec(secVO);
+ codeCustomSerialDTO.setCurrentFlowValue(startValue);
+ codeCustomSerialDTO.setCodeBasicSecVOList(ruleVO.getSecVOList());
+ codeCustomSerialDTO.setCodeRuleOid(ruleVO.getOid());
+ codeCustomSerialDTO.setBaseModel(cbo);
+ codeCustomSerialDTO.setSerialUnitString(serialUnitString.get());
+ codeCustomSerialDTO.setSecValueList(thisSecValueList);
+ thisSerialValue=customCodeSerial(secVO.getCustomCodeSerialClass(),codeCustomSerialDTO);
+ serialUnitString.set(codeCustomSerialDTO.getSerialUnitString());
+ log.info(secVO.getCustomCodeSerialClassText()+"---->"+thisSerialValue);
+ }else {
+ Double newThisSerialValue = 0d;
+ if (startValue == null) {
+ //绗竴涓紪鐮�
+ newThisSerialValue = VciBaseUtil.getDouble(secVO.getSerialStart());
+ } else {
+ //娴佹按鍙疯偗瀹氭槸鏁板瓧
+ newThisSerialValue = Double.parseDouble(startValue) + (j + 1) * secVO.getSerialStep();
+ }
+ //瑕佺湅鏄惁瓒呰繃鏈�澶х殑娴佹按鍊�
+ if (newThisSerialValue >= secVO.getCodeFillLimit()) {
+ throw new VciBaseException("娴佹按鍙峰凡缁忚秴杩囧厑璁哥殑鏈�澶ф祦姘村�納0}", new String[]{secVO.getCodeFillLimit().toString()});
+ }
+ thisSerialValue=String.valueOf(newThisSerialValue.intValue());
+ }
+ //瑕佺湅琛ヤ綅鐨勫唴瀹�
+ Integer fillLength = VciBaseUtil.getInt(secVO.getCodeFillLength());
+ if (fillLength == 0 || fillLength > VciBaseUtil.getInt(secVO.getCodeSecLength())) {
+ //闃叉鍦ㄦ坊鍔犵殑鍦版柟娌℃湁鎺у埗姝g‘
+ fillLength = VciBaseUtil.getInt(secVO.getCodeSecLength());
+ }
+ serialString = thisSerialValue;
+ serialString = fillString(fillLength, OsCodeFillTypeEnum.forValue(secVO.getCodeFillType()), serialString, secVO.getCodeFillSeparator());
+ for (int z = 0; z < thisSecValueList.size(); z++) {
+ String secValue = thisSecValueList.get(z);
+ if (secValue.equalsIgnoreCase("${" + secVO.getOid() + "}")) {
+ // TODO: 娴佹按鐢熸垚鐮佸�煎悗鎷兼帴鍓嶅悗缂�
+ thisSecValueList.set(z, joinPreffixAndSuffix(secVO, serialString));
+ }
+ }
+ secIdserialValueMap.put(secVO.getOid(),thisSerialValue);//璁板綍娴佹按鐮佹褰撳墠鐨勫��
+ if(StringUtils.isNotBlank(thisSerialValue)) {
+ Map<String, String> unitSerialMap = lastMaxSerialValueMap.getOrDefault(secVO.getOid(), new HashMap<>());
+ unitSerialMap.put(serialUnitString.get(), String.valueOf(thisSerialValue));
+ lastMaxSerialValueMap.put(secVO.getOid(), unitSerialMap);
+ }
+ }
+ }
+ }
+ }
+
+
+
/**
* 杞崲娴佹按鐮佹鐨勫��
* @param serialSecVOList 娴佹按鐮佹
@@ -587,7 +710,10 @@
codeCustomSerialDTO.setCodeBasicSecVOList(ruleVO.getSecVOList());
codeCustomSerialDTO.setCodeRuleOid(ruleVO.getOid());
codeCustomSerialDTO.setBaseModel(cbo);
+ codeCustomSerialDTO.setSerialUnitString(newSerialUnitString.get());
+ codeCustomSerialDTO.setSecValueList(thisSecValueList);
thisSerialValue=customCodeSerial(secVO.getCustomCodeSerialClass(),codeCustomSerialDTO);
+ newSerialUnitString.set(codeCustomSerialDTO.getSerialUnitString());
log.info(secVO.getCustomCodeSerialClassText()+"---->"+thisSerialValue);
}else {
Double newThisSerialValue = 0d;
@@ -628,7 +754,33 @@
}
}
- private String customCodeSerial(String className, CodeCustomSerialDTO codeCustomSerialDTO){
+ private String customCodeSerial(String beanName, CodeCustomSerialDTO codeCustomSerialDTO){
+ AtomicReference<String> result = new AtomicReference<>("");
+ //BusAnnotationUtil.callForAnnotation(FlowNotifyWeb.class, FlowNotifyBefore.class,noticeInfo);
+ //鍦ㄧ櫥褰曚箣鍓嶏紝鐪嬬湅鏄惁鏈夋彃浠�
+ Map<String, Object> beanMap = ApplicationContextProvider.getApplicationContext().getBeansWithAnnotation(MdmSerialAlgorithm.class);
+ if (!CollectionUtils.isEmpty(beanMap)) {
+ if(beanMap.containsKey(beanName)){
+ Object v=beanMap.get(beanName);
+ Method[] methods = v.getClass().getDeclaredMethods();
+ if (methods != null && methods.length > 0) {
+ for (Method method : methods) {
+ if (method.isAnnotationPresent(MdmSerialAlgorithmMethod.class)) {
+ try {
+ Object o= method.invoke(v, codeCustomSerialDTO);
+ result.set(Func.isEmpty(o) ?"":o.toString());
+ } catch (Throwable e) {
+ if (log.isErrorEnabled()) {
+ log.error("璋冪敤鎻掍欢鍑洪敊", e);
+ }
+ throw new VciBaseException("璋冪敤鎻掍欢鍑洪敊,{0},{1}", new String[]{v.getClass().getName(), method.getName()}, e);
+ }
+ }
+ }
+ }
+ }
+ }
+ /*
String result = "";
try {
Class classInstance=Class.forName(className);
@@ -648,8 +800,8 @@
throw new VciBaseException("鎵ц鑷畾涔夋祦姘寸畻娉曞鐞嗘柟娉曞嚭鐜板紓甯�");
} catch (InstantiationException e) {
e.printStackTrace();
- }
- return result;
+ }*/
+ return result.get();
}
/**
@@ -772,20 +924,20 @@
/**
* 鎷兼帴鍓嶅悗缂�
- * @param secVO
- * @param secValue
+ * @param secVO 鐮佹
+ * @param secValue 鐮佸��
* @return
*/
- private String joinPreffixAndSuffix(CodeBasicSecVO secVO, String secValue){
+ public String joinPreffixAndSuffix(CodeBasicSecVO secVO, String secValue){
StringBuilder joinSecValue = new StringBuilder();
// 鎷兼帴鍓嶇紑
- if (Func.isNotEmpty(secVO.getPrefixCode())) {
+ if (Func.isNotEmpty(secVO.getPrefixCode()) && Func.isNotEmpty(secValue)) {
joinSecValue = joinSecValue.append(secVO.getPrefixCode());
}
// 鍦ㄤ腑闂存嫾鎺ュ��
joinSecValue.append(secValue);
// 鎷兼帴鍚庣紑
- if(Func.isNotEmpty(secVO.getSuffixCode())){
+ if(Func.isNotEmpty(secVO.getSuffixCode()) && Func.isNotEmpty(secValue)){
joinSecValue = joinSecValue.append(secVO.getSuffixCode());
}
return joinSecValue.toString();
@@ -824,10 +976,11 @@
* @param cbo 涓氬姟鏁版嵁
* @param templateVO 妯℃澘鐨勪俊鎭�
* @param allCodeDOList 鎵�鏈夌殑鐮佸�肩殑瀵硅薄鍒楄〃
+ * @param codeDelimiter 鐮佸�煎垎鍓茬
*/
private void wrapperAllCode(CodeClassifyFullInfoBO classifyFullInfoBO, CodeRuleVO ruleVO,
BaseModel cbo, CodeClassifyTemplateVO templateVO,
- List<CodeAllCode> allCodeDOList, String serialUnitString, String serialValueString){
+ List<CodeAllCode> allCodeDOList, String serialUnitString, String serialValueString,String codeDelimiter){
CodeAllCode allCodeDO = new CodeAllCode();
DefaultAttrAssimtUtil.addDefaultAttrAssimt(allCodeDO, MdmBtmTypeConstant.CODE_ALL_CODE);
allCodeDO.setCodeClassifyOid(classifyFullInfoBO.getCurrentClassifyVO().getOid());
@@ -839,6 +992,7 @@
allCodeDO.setSerialUnit(serialUnitString);
allCodeDO.setUnFillSerial(serialValueString);
allCodeDO.setLcStatus(cbo.getLcStatus());
+ allCodeDO.setCodeDelimit(codeDelimiter);
allCodeDOList.add(allCodeDO);
}
@@ -1002,6 +1156,274 @@
return updateFlag.get();
}
+ /***
+ *
+ * @param classifyFullInfoBO 鍒嗙被鐨勫叏閮ㄤ俊鎭�
+ * @param templateVO 妯℃澘鐨勬樉绀哄璞�
+ * @param ruleVO 缂栫爜瑙勫垯鐨勬樉绀哄璞�
+ * @param secDTOList 鍚勪釜鐮佹鐨勫��
+ * @param dataCBOList 涓氬姟鏁版嵁
+ * @return
+ * @throws Exception
+ */
+ @Override
+ public List<String> productCodeAndSaveDataBZ(CodeClassifyFullInfoBO classifyFullInfoBO, CodeClassifyTemplateVO templateVO, CodeRuleVO ruleVO, List<CodeOrderSecDTO> secDTOList, List<BaseModel> dataCBOList) throws Exception {
+ dataCBOList = dataCBOList.stream().sorted(((o1, o2) -> o1.getCreateTime().compareTo(o2.getCreateTime()))).collect(Collectors.toList());
+ List<String> codeList = new ArrayList<>();
+ final CodeRuleVO finalRuleVO = ruleVO;
+
+ List<CodeBasicSecVO> secVOList = finalRuleVO.getSecVOList().stream().sorted(((o1, o2) -> o1.getOrderNum().compareTo(o2.getOrderNum()))).collect(Collectors.toList());
+ List<String> serialUnitList = new LinkedList<>();
+ List<String> secValueList = new ArrayList<>();
+ Map<String, String> secValueMap = secDTOList.stream().collect(Collectors.toMap(s -> s.getSecOid(), s -> s.getSecValue()==null?"":s.getSecValue()));
+ List<CodeBasicSecVO> serialSecVOList = new ArrayList<>();
+ List<CodeBasicSecVO> attrSecVOList = new ArrayList<>();
+ Map<String,String> secOdserialUnitMap=new HashMap<>();
+ LinkedHashMap<String,String> newSecValueMap=new LinkedHashMap<>();
+ for (int i = 0; i < secVOList.size(); i++) {
+ CodeBasicSecVO secVO = secVOList.get(i);
+ String secValue="";
+ String secOid=secVO.getOid();
+ if(secValueMap.containsKey(secOid)){
+ secValue=secValueMap.get(secOid);
+ }
+ newSecValueMap.put(secOid,secValue);
+ switchSecValueBZ(secVO, secValueMap, classifyFullInfoBO, serialSecVOList, attrSecVOList, serialUnitList, secValueList);
+ //鍒嗘瀛樺偍娴佹按渚濊禆
+ if(secVO.getSecType().equals(CodeSecTypeEnum.CODE_SERIAL_SEC.getValue())){
+ int finalI = i;
+ final int[] index = {0};
+ List<String> newSerialUnitList= serialUnitList.stream().filter(secValueStr -> {
+ return index[0]++< finalI;//闄ゅ幓娴佹按鐨�
+ }).collect(Collectors.toList());
+ String serialUnitString = newSerialUnitList.size() == 0 ? EMPTY_SERIAL_UNIT : newSerialUnitList.stream().collect(Collectors.joining(SERIAL_UNIT_SPACE));
+ secOdserialUnitMap.put(secVO.getOid(),serialUnitString);
+ }
+ }
+ //澶勭悊灞炴�х爜娈靛拰娴佹按鐮佹
+ Map<String/**娴佹按鐮佹鐨勪富閿�**/, Map<String/**娴佹按渚濇嵁**/, String>> lastMaxSerialValueMap = new HashMap<>();
+ List<CodeAllCode> allCodeDOList = new ArrayList<>();
+ //宸茬粡瀛樺偍鐨勬渶澶ф祦姘村彿鐨勫唴瀹�
+ Map<String/**鐮佹鐨勪富閿�**/, Map<String, CodeSerialValue>> maxSerialValueMap = new HashMap<>();
+ for (int i = 0; i < dataCBOList.size(); i++) {
+ BaseModel cbo = dataCBOList.get(i);
+ cbo.getData().remove(CODE_SEC_LENGTH_FIELD);//灏嗘key闄ゅ幓
+ cbo.getData().remove(IMPORT_ROW_INDEX);//灏嗘key闄ゅ幓
+ cbo.getData().remove("codeclassifyid");//灏嗘key闄ゅ幓
+ List<String> thisSecValueList = new LinkedList<>();
+ for (int j = 0; j < secValueList.size(); j++) {
+ thisSecValueList.add(secValueList.get(j));
+ }
+ List<String> thisSerialUnitList = new LinkedList<>();
+ //鍥犱负娴佹按渚濇嵁姣忔鍙兘涓嶄竴鏍凤紝鎵�浠ユ瘡娆¢兘鎷疯礉涓�浠�
+ for (int j = 0; j < serialUnitList.size(); j++) {
+ thisSerialUnitList.add(serialUnitList.get(j));
+ }
+ //鍏堢湅鐪嬫湁娌℃湁灞炴�х殑鐮佹
+ boolean attrSevIsSerialDepend = CollectionUtils.isEmpty(attrSecVOList) ? false : (attrSecVOList.stream().anyMatch(s -> VciBaseUtil.getBoolean(s.getSerialDependFlag())));
+ switchAttrSecValue(attrSecVOList, cbo, thisSecValueList, attrSevIsSerialDepend, thisSerialUnitList);
+
+ switchSerialSecValueBZ(cbo,secDTOList,serialSecVOList, attrSevIsSerialDepend, finalRuleVO, secOdserialUnitMap, maxSerialValueMap, thisSecValueList, lastMaxSerialValueMap, i == 0);
+
+ //缁勮缂栫爜鐨勫��
+ cbo.setId(thisSecValueList.stream().collect(Collectors.joining()));
+ codeList.add(cbo.getId());
+ StringBuilder sb = new StringBuilder();
+ //鎶婄爜娈甸噷闈㈤兘鎵句竴涓嬫祦姘村彿
+ AtomicReference<String> serialUnitString= new AtomicReference<>("");
+ for (int j = 0; j < serialSecVOList.size(); j++) {
+ CodeBasicSecVO secVO = serialSecVOList.get(j);
+ if(lastMaxSerialValueMap.containsKey(secVO.getOid())){//姝や负鏈�鍚庨渶瑕佸瓨鍏ユ祦姘翠緷璧栫殑鏈�澶ф祦姘�
+ Map<String/**娴佹按渚濇嵁**/, String> serialValueMap= lastMaxSerialValueMap.get(secVO.getOid());
+ serialValueMap.forEach((maxSerialUnitString,serialValue)->{
+ if(StringUtils.isNotBlank(serialValue)){
+ serialUnitString.set(maxSerialUnitString);
+ sb.append(serialValue).append(SERIAL_VALUE_SPACE);
+ }
+ });
+ }else{
+ if(secValueMap.containsKey(secVO.getOid())) {//浼佷笟鏍囧噯澶勭悊淇椤哄簭鍙峰凡缁忓瓨鍦ㄧ殑鏁版嵁鍒欎笉闇�瑕佸姩娴佹按渚濊禆琛ㄧ殑鏁版嵁
+ serialUnitString.set(secOdserialUnitMap.get(secVO.getOid()));
+ sb.append(secValueMap.get(secVO.getOid())).append(SERIAL_VALUE_SPACE);
+ }
+ }
+ }
+ String codeDelimiter=thisSecValueList.stream().collect(Collectors.joining(SERIAL_VALUE_SPACE));
+ //瑕佸瓨鍌ㄦ渶鍚庣殑鍏ㄩ儴allcode
+ wrapperAllCode(classifyFullInfoBO, finalRuleVO, cbo, templateVO, allCodeDOList, serialUnitString.get(), sb.toString(),codeDelimiter);
+ }
+ //澶勭悊鏈�澶ф祦姘�
+ saveSerialValue( finalRuleVO, lastMaxSerialValueMap, maxSerialValueMap);
+
+ allCodeDOList.stream().forEach(
+ allCode -> {DefaultAttrAssimtUtil.addDefaultAttrAssimt(allCode,"codeallcode");allCode.setLctid("codeAllCodeLC");}
+ );
+
+ Map<String, String> statusMap = allCodeDOList.stream().collect(Collectors.toMap(s -> s.getOid(), s -> s.getLcStatus()));
+ allCodeDOList.stream().filter(s -> StringUtils.equalsIgnoreCase("codeallcode",s.getBtmname())).forEach(s -> {
+ s.setLcStatus(statusMap.get(s.getOid()));
+ });
+ //閫氳繃ID鏉ヨ繘琛屽幓閲�
+ List<CodeAllCode> distinctCodeAllCOdes = allCodeDOList.stream().collect(Collectors
+ .collectingAndThen(
+ Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CodeAllCode::getId))),
+ ArrayList::new));
+ if( distinctCodeAllCOdes.size() != allCodeDOList.size() ){
+ throw new ServiceException("缂栫爜鏁版嵁閲嶅锛屾棤娉曚繚瀛橈紝璇锋敞鎰忥紒");
+ }
+ QueryWrapper<CodeAllCode> wrapper = new QueryWrapper<>();
+ wrapper.eq("CREATECODEBTM",allCodeDOList.get(0).getCreateCodeBtm());
+ wrapper.in("ID",allCodeDOList.stream().map(CodeAllCode::getId).collect(Collectors.toList()));
+ List<CodeAllCode> codeAllCodes = codeAllCodeService.selectByWrapper(wrapper);
+ List<CodeAllCode> takeBack = codeAllCodes.stream().filter(e -> e.getLcStatus().equals("TakeBack")).collect(Collectors.toList());
+ if(codeAllCodes.size()>takeBack.size()){
+ throw new ServiceException("鐢熸垚缂栫爜鏁版嵁ID宸叉湁鍘嗗彶璁板綍,璇风‘璁ゅ涓嬬敓鎴愮殑ID鏁版嵁锛�"+ allCodeDOList.stream().map(CodeAllCode::getId).collect(Collectors.toList()));
+ }
+ for (CodeAllCode codeAllCode : takeBack) {
+ codeAllCode.setTs(new Date());
+ codeAllCode.setLastModifyTime(new Date());
+ codeAllCode.setLastModifier(AuthUtil.getUserId().toString());
+ Iterator<CodeAllCode> iterator = allCodeDOList.iterator();
+ while (iterator.hasNext()){
+ CodeAllCode next = iterator.next();
+ if(codeAllCode.getId().equals(next.getId())){
+ codeAllCode.setCreateCodeOid(next.getCreateCodeOid());
+ codeAllCode.setLcStatus(next.getLcStatus());
+ //iterator.remove();
+ }
+ }
+ }
+ if(takeBack.size()>0){
+ codeAllCodeService.updateBatchById(takeBack);
+ }
+ codeAllCodeService.saveBatch(allCodeDOList);
+ mdmEngineService.insertBatchByType(dataCBOList.get(0).getBtmname(),dataCBOList);
+ return codeList;
+ }
+
+
+ /**
+ * 杞崲鐮佸�肩殑鍐呭
+ * @param secVO 鐮佹鐨勫唴瀹�
+ * @param secValueMap 鐮佸�肩殑鍐呭锛宬ey鏄爜娈电殑涓婚敭锛寁alue鏄爜鍊�
+ * @param classifyFullInfoBO 鍒嗙被鐨勫叏閮ㄤ俊鎭�
+ * @param serialSecVOList 娴佹按鐮佹
+ * @param attrSecVOList 灞炴�х爜娈�
+ * @param serialUnitList 娴佹按渚濇嵁
+ * @param secValueList 鐮佸�煎垪琛�
+ */
+ private void switchSecValueBZ(CodeBasicSecVO secVO,Map<String,String> secValueMap,
+ CodeClassifyFullInfoBO classifyFullInfoBO,List<CodeBasicSecVO> serialSecVOList,
+ List<CodeBasicSecVO> attrSecVOList, List<String> serialUnitList,
+ List<String> secValueList ){
+ CodeSecTypeEnum secType = CodeSecTypeEnum.forValue(secVO.getSecType());
+ String secValue = secValueMap.getOrDefault(secVO.getOid(), "");
+ switch (secType) {
+ case CODE_FIXED_SEC:
+ secValue = joinPreffixAndSuffix(secVO, secValue);
+ //鍥哄畾鐮佹鐨勶紝鐩存帴鐢ㄧ爜鍊�,涓嶈鐮佸�肩殑闀垮害鏄灏戯紝鍥犱负鍙彉闀垮害鍜屽浐瀹氶暱搴︽槸鎺у埗鍦ㄧ爜娈电鐞嗛噷闈㈢殑鐮佸�煎畾涔夌殑
+ break;
+ case CODE_DATE_SEC:
+ //鏃堕棿鐮佹锛岄渶瑕佸皢褰撳墠鏃堕棿渚濇嵁鏃堕棿鏍煎紡杩涜杞崲.
+ //鏃堕棿鐮佹涓嶆秹鍙婂埌鏄惁琛ヤ綅
+ secValue =joinPreffixAndSuffix(secVO, VciDateUtil.date2Str(new Date(), secVO.getCodeDateFormatStr()));
+ break;
+ case CODE_CLASSIFY_SEC:
+ //鍒嗙被鐮佹鐨勶紝涔熸槸浠庡墠绔�夋嫨浜嗙爜鍊煎嵆鍙紝涓嶈鐮佸�肩殑闀垮害鏄灏�
+ CodeClassifyValue codeClassifyValueDO= codeClassifyValueMapper.selectById(secValue);
+ if(codeClassifyValueDO!=null) {
+ secValue = joinPreffixAndSuffix(secVO, codeClassifyValueDO.getId());
+ }
+ break;
+ case CODE_LEVEL_SEC:
+ //灞傜骇鐮佹锛岄渶瑕佷粠鍒嗙被涓婅幏鍙栫浉搴旂殑淇℃伅
+ if (CodeLevelTypeEnum.MIN.getValue().equalsIgnoreCase(secVO.getCodeLevelType())) {
+ //鏈�灏忓眰锛屽洜涓烘垜浠彧鑳藉湪鍙跺瓙鑺傜偣涓婄敵璇风紪鐮侊紝鎵�浠ヨ繖涓氨鏄綋鍓嶅垎绫荤殑
+ if (CodeGetValueTypeEnum.CURRENT.getValue().equalsIgnoreCase(secVO.getCodeGetValueType()) || CollectionUtils.isEmpty(classifyFullInfoBO.getParentClassifyVOs())) {
+ //灏辨槸褰撳墠鍒嗙被鐨�
+ secValue = classifyFullInfoBO.getCurrentClassifyVO().getId();
+ } else {
+ //鎴戜滑闇�瑕佷粠椤跺眰寮�濮嬫壘鍒板綋鍓嶅垎绫讳负姝�
+ secValue = classifyFullInfoBO.getParentClassifyVOs().stream().sorted(((o1, o2) -> -o1.getDataLevel().compareTo(o2.getDataLevel()))).map(CodeClassifyVO::getId).collect(Collectors.joining()) + classifyFullInfoBO.getCurrentClassifyVO().getId();
+ }
+ } else {
+ //鎸囧畾灞傦紝鎴戜滑闇�瑕侀�氳繃涓婄骇鐨勬潵鑾峰彇
+ if (CollectionUtils.isEmpty(classifyFullInfoBO.getParentClassifyVOs())) {
+ //璇存槑褰撳墠宸茬粡鏄渶楂樼殑浜�
+ secValue = classifyFullInfoBO.getCurrentClassifyVO().getId();
+ } else {
+ //杩欎釜鎴戜滑闇�瑕佺湅鐪�,灞傜骇鏄笉鏄ぇ浜庝簡鏈�澶у眰绾х殑鏁�
+ List<CodeClassifyVO> parentClassifyVOList = classifyFullInfoBO.getParentClassifyVOs().stream().sorted(((o1, o2) -> -o1.getDataLevel().compareTo(o2.getDataLevel()))).collect(Collectors.toList());
+ if (secVO.getCodeLevelValue() > (parentClassifyVOList.size() + 1)) {
+ //鎸囧畾鐨勫眰绾ф瘮褰撳墠鐨勫眰绾ц繕澶т簡锛屾墍浠ュ彧鑳借幏鍙栧綋鍓嶅眰绾т簡
+ if (CodeGetValueTypeEnum.CURRENT.getValue().equalsIgnoreCase(secVO.getCodeGetValueType())) {
+ secValue = classifyFullInfoBO.getCurrentClassifyVO().getId();
+ } else {
+ secValue = parentClassifyVOList.stream().map(CodeClassifyVO::getId).collect(Collectors.joining()) + classifyFullInfoBO.getCurrentClassifyVO().getId();
+ }
+ } else {
+ //鎴戜滑鑾峰彇鍏朵腑鎸囧畾灞傜殑鍐呭
+ if (CodeGetValueTypeEnum.CURRENT.getValue().equalsIgnoreCase(secVO.getCodeGetValueType())) {
+ CodeClassifyVO classifyVO = parentClassifyVOList.stream().filter(s -> s.getDataLevel().intValue() == secVO.getCodeLevelValue().intValue()).findFirst().orElseGet(() -> null);
+ if (classifyVO != null) {
+ secValue = classifyVO.getId();
+ }
+ } else {
+ //灏忎簬绛変簬鐨勫叏閮ㄦ嬁鍑烘潵
+ secValue = parentClassifyVOList.stream().filter(s -> s.getDataLevel().intValue() <= secVO.getCodeLevelValue().intValue()).sorted(((o1, o2) -> -o1.getDataLevel().compareTo(o2.getDataLevel()))).map(CodeClassifyVO::getId).collect(Collectors.joining());
+ }
+ }
+ }
+ }
+ //鐪嬬湅闀垮害鏄惁闇�瑕佹埅鏂�
+ if (!CodeCutTypeEnum.NONE.getValue().equalsIgnoreCase(secVO.getValueCutType()) &&
+ secVO.getValueCutLength() != null && secVO.getValueCutLength() > 0 && secValue.length() > secVO.getValueCutLength()) {
+ if (CodeCutTypeEnum.RIGHT.getValue().equalsIgnoreCase(secVO.getValueCutType())) {
+ //宸︽埅鍙栨槸浠庡乏杈瑰壀鎺夛紝鍙虫埅鍙栨槸浠庡彸杈瑰壀鎺�--淇濈暀宸﹁竟
+ secValue = secValue.substring(0, secVO.getValueCutLength());
+ } else {
+ secValue = secValue.substring(secValue.length() - secVO.getValueCutLength());
+ }
+ }
+ secValue = joinPreffixAndSuffix(secVO,secValue);
+ break;
+ case CODE_REFER_SEC:
+ //寮曠敤鐨勫湪椤甸潰涓婂凡缁忛�夋嫨浜嗭紝鎵�浠ョ洿鎺ヤ娇鐢ㄥ墠绔笂浼犻�掔殑鍊�
+ //寮曠敤灏辨槸鍙傜収锛屽彲鑳芥槸鍏朵粬鐨勫垎绫伙紙涓氬姟绫诲瀷锛変笅鐨勬暟鎹紝鎵�浠ュ彧鍦ㄩ〉闈笂閫夋嫨
+ secValue = joinPreffixAndSuffix(secVO,secValue);
+ break;
+ case CODE_ATTR_SEC:
+ //灞炴�т笌寮曠敤鐨勫尯鍒槸锛屽睘鎬ф槸褰撳墠鏁版嵁閲岀殑灞炴�э紝鑰屽紩鐢ㄥ彲鑳芥槸寮曠敤鍏朵粬鐨勫垎绫荤殑锛堜笟鍔$被鍨嬶級
+ //鍥犱负鍙兘鏄壒閲忕殑鏁版嵁鐨勬搷浣滐紝鎵�浠ユ垜浠繖閲屼笉鑳界洿鎺ュ鐞嗗睘鎬э紝闇�瑕佸悗杈逛竴杈瑰鐞�
+ secValue = "${attr_" + secVO.getOid() + "}";
+ attrSecVOList.add(secVO);
+ break;
+ case CODE_VARIABLE_SEC:
+ //鍙彉鐮佹锛屾槸鍦ㄩ〉闈笂杈撳叆鍐呭
+ if (secValue.length() > VciBaseUtil.getInt(secVO.getCodeSecLength())) {
+ throw new VciBaseException("銆恵0}銆戣繖涓爜娈垫槸鍙彉鐮佹锛屼絾鏄幇鍦ㄨ緭鍏ョ殑鐮佸�肩殑闀垮害({1})瓒呰繃浜嗚瀹氱殑闀垮害{2}", new String[]{secVO.getName(), String.valueOf(secValue.length()), secVO.getCodeSecLength()});
+ }
+ OsCodeFillTypeEnum fillTypeEnum = OsCodeFillTypeEnum.forValue(secVO.getCodeFillType());
+ secValue = fillString(VciBaseUtil.getInt(secVO.getCodeSecLength()), fillTypeEnum, secValue, secVO.getCodeFillSeparator());
+ secValue = joinPreffixAndSuffix(secVO,secValue);
+ break;
+ case CODE_SERIAL_SEC:
+ //娴佹按鐮佹
+ serialSecVOList.add(secVO);
+ if(secValueMap.containsKey(secVO.getOid())){
+ secValue=secValueMap.get(secVO.getOid());
+ }else{
+ secValue = "${" + secVO.getOid() + "}";
+ }
+ default:
+ break;
+ }
+ if (VciBaseUtil.getBoolean(secVO.getSerialDependFlag())) {
+ serialUnitList.add(secValue);
+ }
+ secValueList.add(secValue);
+ }
+
/**
* 浣跨敤CBO澶勭悊缁勫悎瑙勫垯鐨勫唴瀹�
* @param cbo 鏁版嵁鐨勫唴瀹�
@@ -1017,7 +1439,7 @@
}
Map<String, String> map = new HashMap<String, String>();
for (String i : dataMap.keySet()) {
- map.put(i, String.valueOf(dataMap.get(i)));
+ map.put(i, String.valueOf(dataMap.get(i)).trim());
}
// WebUtil.copyValueToMapFromCbos(cbo,dataMap);
return formulaService.getValueByFormula(map,rule);
--
Gitblit v1.9.3