From 566c542d3f1eb0ad9e918bd1fa9586ab1ed7ec86 Mon Sep 17 00:00:00 2001 From: xiejun <xj@2023> Date: 星期五, 17 十一月 2023 01:28:50 +0800 Subject: [PATCH] 自定义流水相关开发 --- Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java | 270 ++++++++++++++++++++++++++++++++++------------------- 1 files changed, 173 insertions(+), 97 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 0924dbb..f48fd40 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 @@ -2,7 +2,9 @@ import com.alibaba.nacos.common.utils.StringUtils; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.vci.ubcs.code.algorithm.CustomSerialEnum; import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO; +import com.vci.ubcs.code.dto.CodeCustomSerialDTO; import com.vci.ubcs.code.dto.CodeOrderSecDTO; import com.vci.ubcs.code.entity.CodeAllCode; import com.vci.ubcs.code.entity.CodeClassifyValue; @@ -36,15 +38,16 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; -import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.support.DefaultTransactionDefinition; -import org.springframework.transaction.support.TransactionTemplate; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; +import java.lang.reflect.InvocationTargetException; +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; @@ -105,7 +108,7 @@ //涓昏鏄负浜嗗綍鍏ユ渶澶ф祦姘村彿鍜宎llcode //SessionInfo sessionInfo = VciBaseUtil.getCurrentUserSessionInfo(); List<CodeAllCode> allCodeDOList = new CopyOnWriteArrayList<>(); - Map<String/**娴佹按渚濇嵁**/, Map<String/**鐮佹鐨勪富閿�**/,Double/**鏈�澶ф祦姘村彿**/>> maxSerialMap = new HashMap<>(); + Map<String/**娴佹按渚濇嵁**/, ConcurrentHashMap<String/**鐮佹鐨勪富閿�**/,String/**鏈�澶ф祦姘村彿**/>> maxSerialMap = new ConcurrentHashMap<>(); // TODO 澶氱嚎绋嬫祦寮曞彂鐨勯棶棰樺凡淇敼 dataCBOList.parallelStream().forEach(cbo->{ log.info("code:----->"+cbo.getId()); @@ -120,6 +123,7 @@ List<CodeBasicSecVO> secVOList = finalRuleVO.getSecVOList().stream().sorted(((o1, o2) -> o1.getOrderNum().compareTo(o2.getOrderNum()))).collect(Collectors.toList()); 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<>(); for (int i = 0; i < secLengths.length; i++) { CodeBasicSecVO secVO = secVOList.get(i); String thisSecValue = ""; @@ -137,38 +141,59 @@ // } if(VciBaseUtil.getBoolean(secVO.getSerialDependFlag())){ serialUnitList.add(thisSecValue); + serialSecOidIndexMap.put(secVO.getOid(),i); } if(CodeSecTypeEnum.CODE_SERIAL_SEC.getValue().equalsIgnoreCase(secVO.getSecType())){ serialValueMap.put(secVO.getOid(),thisSecValue); } } - String serialUnitString = serialUnitList.size() == 0 ? EMPTY_SERIAL_UNIT : serialUnitList.stream().collect(Collectors.joining(SERIAL_UNIT_SPACE)); List<String> serialUnFileStringList = new ArrayList<>(); + AtomicReference<String> newSerialUnitString = new AtomicReference<>(""); if(!CollectionUtils.isEmpty(serialValueMap)){ + AtomicInteger index= new AtomicInteger(); serialValueMap.forEach((secOid,secValue)->{ //瑕佺湅鏄笉鏄ˉ浣嶇殑 CodeBasicSecVO secVO = secVOMap.get(secOid); - Double serialDb = null; + List<String >newSerialUnitList=new ArrayList<>(); + newSerialUnitList.addAll(serialUnitList); + if(index.get() ==0){ + if(serialSecOidIndexMap.containsKey(secOid)) { + int num = serialSecOidIndexMap.get(secOid); + newSerialUnitList.set(num, ""); + } + } + String serialUnitString = newSerialUnitList.size() == 0 ? EMPTY_SERIAL_UNIT : newSerialUnitList.stream().collect(Collectors.joining(SERIAL_UNIT_SPACE)); + newSerialUnitString.set(serialUnitString); + index.getAndIncrement(); + String serialDb = ""; // 鎴彇鎺夊墠鍚庣紑涔嬪悗鐨勭爜娈� String subSecValue = killPriffixSuffix(secValue, secVO.getPrefixCode(), secVO.getSuffixCode()); if(OsCodeFillTypeEnum.NONE.getValue().equalsIgnoreCase(secVO.getCodeFillType())){ //涓嶈ˉ鐮� //鎶婃墍鏈変笉鏄暟瀛楃殑鍘绘帀锛屽洜涓哄彲鑳戒細鏄�佹暟鎹紝鏂拌鍒� - serialDb = VciBaseUtil.getDouble(killUnNumberChar(subSecValue)); + // serialDb = VciBaseUtil.getDouble(killUnNumberChar(subSecValue)); + //serialDb = killUnNumberChar(subSecValue); + serialDb=subSecValue; }else { //宸﹀彸濉厖鐨勶紝鎴戜滑闇�瑕� - serialDb = VciBaseUtil.getDouble(killUnNumberChar(killFillChar(subSecValue,secVO.getCodeFillSeparator(), - OsCodeFillTypeEnum.LEFT.getValue().equalsIgnoreCase(secVO.getCodeFillType())))); + /*serialDb = VciBaseUtil.getDouble(killUnNumberChar(killFillChar(subSecValue,secVO.getCodeFillSeparator(), + OsCodeFillTypeEnum.LEFT.getValue().equalsIgnoreCase(secVO.getCodeFillType()))));*/ + serialDb = killFillChar(subSecValue,secVO.getCodeFillSeparator(), + OsCodeFillTypeEnum.LEFT.getValue().equalsIgnoreCase(secVO.getCodeFillType())); } - Map<String, Double> thisUnitMaxMap = maxSerialMap.getOrDefault(serialUnitString, new HashMap<>()); - Double maxValue=serialDb; + Double newSerialDb= CustomSerialEnum.getDoubleCustomSerialValue(secValue,secVO.getCustomCodeSerialType()); + ConcurrentHashMap<String, String> thisUnitMaxMap = maxSerialMap.getOrDefault(serialUnitString, new ConcurrentHashMap<>()); + Double maxValue=newSerialDb; if(thisUnitMaxMap.containsKey(secOid)){ - maxValue= thisUnitMaxMap.getOrDefault(secOid,new Double(-1)); - if(maxValue<serialDb){ - maxValue=serialDb; + String newMaxValue= thisUnitMaxMap.getOrDefault(secOid,""); + maxValue=StringUtils.isBlank(newMaxValue)?-1:VciBaseUtil.getDouble(newMaxValue); + if(maxValue<newSerialDb){ + maxValue=newSerialDb; } } - thisUnitMaxMap.put(secOid,maxValue); + String newMaxValue=CustomSerialEnum.getStringCustomSerialValue(maxValue,secVO.getCustomCodeSerialType()); + serialDb=CustomSerialEnum.getStringCustomSerialValue(newSerialDb,secVO.getCustomCodeSerialType()); + thisUnitMaxMap.put(secOid,newMaxValue); maxSerialMap.put(serialUnitString,thisUnitMaxMap); serialUnFileStringList.add(String.valueOf(serialDb)); }); @@ -181,7 +206,7 @@ allCodeDO.setCodeClassifyTemplateOid(templateVO.getOid()); allCodeDO.setCreateCodeBtm(cbo.getBtmname()); allCodeDO.setCreateCodeOid(cbo.getOid()); - allCodeDO.setSerialUnit(serialUnitString); + allCodeDO.setSerialUnit(newSerialUnitString.get()); 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()); @@ -204,7 +229,7 @@ if (!CollectionUtils.isEmpty(serialValueDOS)) { CodeSerialValue serialValueDO = serialValueDOS.get(0); log.info("oldmaxSerial--->"+serialValueDO.getMaxSerial()+"---- newmaxSerial---->"+maxSerial); - if(VciBaseUtil.getDouble(serialValueDO.getMaxSerial())<maxSerial){ + if(VciBaseUtil.getDouble(serialValueDO.getMaxSerial())<VciBaseUtil.getDouble(maxSerial)){ serialValueDO.setMaxSerial(String.valueOf(maxSerial)); DefaultAttrAssimtUtil.updateDefaultAttrAssimt(serialValueDO); editSerialValueList.add(serialValueDO); @@ -295,7 +320,7 @@ 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鏁版嵁锛�"+ addCodeDOs.stream().map(CodeAllCode::getId).collect(Collectors.toList())); + throw new ServiceException("鐢熸垚缂栫爜鏁版嵁ID宸叉湁鍘嗗彶璁板綍,璇风‘璁ゅ涓嬬敓鎴愮殑ID鏁版嵁锛�"+ codeAllCodes.stream().map(CodeAllCode::getId).collect(Collectors.toList())); } for (CodeAllCode codeAllCode : takeBack) { codeAllCode.setTs(new Date()); @@ -320,13 +345,6 @@ // try { mdmEngineService.insertBatchByType(dataCBOList.get(0).getBtmname(),dataCBOList); - // 鎻愪氦浜嬪姟 - //transactionTemplate.getTransactionManager().commit(status); -// }catch (Exception e){ -// // 鍑虹幇寮傚父鏃跺洖婊氫簨鍔� -// transactionTemplate.getTransactionManager().rollback(status); -// } - } return codeList; }else { @@ -341,7 +359,7 @@ switchSecValue(secVO, secValueMap, classifyFullInfoBO, serialSecVOList, attrSecVOList, serialUnitList, secValueList); } //澶勭悊灞炴�х爜娈靛拰娴佹按鐮佹 - Map<String/**娴佹按鐮佹鐨勪富閿�**/, Map<String/**娴佹按渚濇嵁**/, Double>> lastMaxSerialValueMap = new HashMap<>(); + Map<String/**娴佹按鐮佹鐨勪富閿�**/, Map<String/**娴佹按渚濇嵁**/, String>> lastMaxSerialValueMap = new HashMap<>(); List<CodeAllCode> allCodeDOList = new ArrayList<>(); //宸茬粡瀛樺偍鐨勬渶澶ф祦姘村彿鐨勫唴瀹� @@ -366,7 +384,7 @@ switchAttrSecValue(attrSecVOList, cbo, thisSecValueList, attrSevIsSerialDepend, thisSerialUnitList); String serialUnitString = thisSerialUnitList.size() == 0 ? EMPTY_SERIAL_UNIT : thisSerialUnitList.stream().collect(Collectors.joining(SERIAL_UNIT_SPACE)); - switchSerialSecValue(serialSecVOList, attrSevIsSerialDepend, finalRuleVO, serialUnitString, maxSerialValueMap, thisSecValueList, lastMaxSerialValueMap, i == 0); + switchSerialSecValue(cbo,serialSecVOList, attrSevIsSerialDepend, finalRuleVO, serialUnitString, maxSerialValueMap, thisSecValueList, lastMaxSerialValueMap, i == 0); //缁勮缂栫爜鐨勫�� cbo.setId(thisSecValueList.stream().collect(Collectors.joining())); @@ -375,9 +393,9 @@ //鎶婄爜娈甸噷闈㈤兘鎵句竴涓嬫祦姘村彿 for (int j = 0; j < serialSecVOList.size(); j++) { CodeBasicSecVO secVO = serialSecVOList.get(j); - Double serialValue = lastMaxSerialValueMap.getOrDefault(secVO.getOid(), new HashMap<>()).getOrDefault(serialUnitString, 0d); + String serialValue = lastMaxSerialValueMap.getOrDefault(secVO.getOid(), new HashMap<>()).getOrDefault(serialUnitString, ""); if (serialValue != null) { - sb.append(String.valueOf(serialValue.longValue())).append(SERIAL_VALUE_SPACE); + sb.append(serialValue).append(SERIAL_VALUE_SPACE); } } //瑕佸瓨鍌ㄦ渶鍚庣殑鍏ㄩ儴allcode @@ -386,54 +404,57 @@ //澶勭悊鏈�澶ф祦姘� 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 -> { + 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鏁版嵁锛�"+ codeAllCodes.stream().map(CodeAllCode::getId).collect(Collectors.toList())); + } - - //閫氳繃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(); + 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); -// iCodeWupinService.saveBatch(dataCBOList); - mdmEngineService.insertBatchByType(dataCBOList.get(0).getBtmname(),dataCBOList); + mdmEngineService.insertBatchByType(dataCBOList.get(0).getBtmname(), dataCBOList); + if(takeBack.size()>0){ + codeAllCodeService.updateBatchById(takeBack); + } + codeAllCodeService.saveBatch(allCodeDOList); +// iCodeWupinService.saveBatch(dataCBOList); + // 鎻愪氦浜嬪姟 + // transactionTemplate.getTransactionManager().commit(status); + //}catch (Exception e){ + // 鍑虹幇寮傚父鏃跺洖婊氫簨鍔� + // transactionTemplate.getTransactionManager().rollback(status); + // throw e; + //} // batchCBO.getCreateCbos().stream().filter(s -> StringUtils.equalsIgnoreCase("codeallcode",s.getBtmName())).forEach(s -> { // s.setLcStatus(statusMap.get(s.getOid())); // try { @@ -504,13 +525,27 @@ * @param lastMaxSerialValueMap 灏佽鍚� * @param firstData 鏄惁涓虹涓�鏉℃暟鎹� */ - private void switchSerialSecValue(List<CodeBasicSecVO> serialSecVOList,boolean attrSevIsSerialDepend, + private void switchSerialSecValue(BaseModel cbo, List<CodeBasicSecVO> serialSecVOList,boolean attrSevIsSerialDepend, CodeRuleVO ruleVO,String serialUnitString, Map<String/**鐮佹鐨勪富閿�**/,Map<String/**娴佹按渚濇嵁**/,CodeSerialValue>> maxSerialValueMap,List<String> thisSecValueList, - Map<String/**鐮佹鐨勪富閿�**/,Map<String/**娴佹按渚濇嵁**/, Double>> lastMaxSerialValueMap,boolean firstData){ + Map<String/**鐮佹鐨勪富閿�**/,Map<String/**娴佹按渚濇嵁**/, String>> lastMaxSerialValueMap,boolean firstData){ + if (!CollectionUtils.isEmpty(serialSecVOList)) { + Map<String,String> secIdserialValueMap=new LinkedHashMap<>(); for (int j = 0; j < serialSecVOList.size(); j++) { CodeBasicSecVO secVO = serialSecVOList.get(j); + String secVOValue=""; + AtomicReference<String> newSerialUnitString= new AtomicReference<>(serialUnitString); + if(j==0){ + secVOValue=""; + newSerialUnitString.set(serialUnitString.replace("${" + secVO.getOid() + "}", secVOValue)); + }else{ + CodeBasicSecVO upSecVO =serialSecVOList.get(j-1); + secIdserialValueMap.forEach((key,vaule)->{ + newSerialUnitString.set(serialUnitString.replace("${"+key+"}", vaule)); + }); + } + if (attrSevIsSerialDepend || firstData) { //濡傛灉灞炴�х爜娈典篃鏄緷璧栵紝鍒欐瘡娆¢兘瑕佹煡璇紝濡傛灉灞炴�х爜娈典笉鏄緷璧栵紝鍒欏彧鏌ヨ涓�娆� // Map<String, String> conditionMap = new HashMap<>(); @@ -519,8 +554,9 @@ // //杩欎釜瀛楁鏄负浜嗚В鍐冲涓祦姘寸殑闂 // conditionMap.put("codeSecOid", secVO.getOid()); QueryWrapper<CodeSerialValue> codeSerialWrapper = new QueryWrapper<>(); + codeSerialWrapper.eq("codeRuleOid", ruleVO.getOid()); - codeSerialWrapper.eq("serialUnit", serialUnitString); + codeSerialWrapper.eq("serialUnit", newSerialUnitString.get()); codeSerialWrapper.eq("codeSecOid", secVO.getOid()); List<CodeSerialValue> serialValueDOS = serialValueMapper.selectList(codeSerialWrapper); if (!CollectionUtils.isEmpty(serialValueDOS)) { @@ -530,25 +566,41 @@ maxSerialValueMap.put(secVO.getOid(), unitSerialMap); } } - Double startValue = null; - if(maxSerialValueMap.containsKey(secVO.getOid()) && maxSerialValueMap.get(secVO.getOid()).containsKey(serialUnitString)){ - startValue = VciBaseUtil.getDouble(maxSerialValueMap.get(secVO.getOid()).get(serialUnitString).getMaxSerial()); + String serialString=""; + String thisSerialValue = ""; + String startValue = null; + if (maxSerialValueMap.containsKey(secVO.getOid()) && maxSerialValueMap.get(secVO.getOid()).containsKey(newSerialUnitString.get())) { + startValue = maxSerialValueMap.get(secVO.getOid()).get(newSerialUnitString.get()).getMaxSerial(); } - if(lastMaxSerialValueMap.containsKey(secVO.getOid()) && lastMaxSerialValueMap.get(secVO.getOid()).containsKey(serialUnitString)){ + if (lastMaxSerialValueMap.containsKey(secVO.getOid()) && lastMaxSerialValueMap.get(secVO.getOid()).containsKey(newSerialUnitString.get())) { //璇存槑澶氫釜鐢宠锛屼箣鍓嶅凡缁忓姞浜嗘祦姘村彿浜� - startValue = lastMaxSerialValueMap.get(secVO.getOid()).get(serialUnitString); + startValue = lastMaxSerialValueMap.get(secVO.getOid()).get(newSerialUnitString.get()); } - Double thisSerialValue = 0d; - if (startValue == null) { - //绗竴涓紪鐮� - thisSerialValue = VciBaseUtil.getDouble(secVO.getSerialStart()); - } else { - //娴佹按鍙疯偗瀹氭槸鏁板瓧 - thisSerialValue = startValue + (j + 1) * secVO.getSerialStep(); - } - //瑕佺湅鏄惁瓒呰繃鏈�澶х殑娴佹按鍊� - if (thisSerialValue >= secVO.getCodeFillLimit()) { - throw new VciBaseException("娴佹按鍙峰凡缁忚秴杩囧厑璁哥殑鏈�澶ф祦姘村�納0}",new String[]{secVO.getCodeFillLimit().toString()}); + if(StringUtils.isNotBlank(secVO.getCustomCodeSerialClass())){//鑷畾涔夋祦姘村鐞� + String currentFlowValue=startValue; + CodeCustomSerialDTO codeCustomSerialDTO=new CodeCustomSerialDTO(); + codeCustomSerialDTO.setSerialUnitString(newSerialUnitString.get()); + codeCustomSerialDTO.setSerialCodeCodeBasicSec(secVO); + codeCustomSerialDTO.setCurrentFlowValue(startValue); + codeCustomSerialDTO.setCodeBasicSecVOList(ruleVO.getSecVOList()); + codeCustomSerialDTO.setCodeRuleOid(ruleVO.getOid()); + codeCustomSerialDTO.setBaseModel(cbo); + thisSerialValue=customCodeSerial(secVO.getCustomCodeSerialClass(),codeCustomSerialDTO); + 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()); @@ -556,8 +608,9 @@ //闃叉鍦ㄦ坊鍔犵殑鍦版柟娌℃湁鎺у埗姝g‘ fillLength = VciBaseUtil.getInt(secVO.getCodeSecLength()); } - String serialString = String.valueOf(thisSerialValue.longValue()); + 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() + "}")) { @@ -565,13 +618,36 @@ thisSecValueList.set(z, joinPreffixAndSuffix(secVO, serialString)); } } - Map<String, Double> unitSerialMap = lastMaxSerialValueMap.getOrDefault(secVO.getOid(), new HashMap<>()); - unitSerialMap.put(serialUnitString, thisSerialValue); + secIdserialValueMap.put(secVO.getOid(),thisSerialValue);//璁板綍娴佹按鐮佹褰撳墠鐨勫�� + Map<String, String> unitSerialMap = lastMaxSerialValueMap.getOrDefault(secVO.getOid(), new HashMap<>()); + unitSerialMap.put(newSerialUnitString.get(), String.valueOf(thisSerialValue)); lastMaxSerialValueMap.put(secVO.getOid(),unitSerialMap); } } } - + private String customCodeSerial(String className, CodeCustomSerialDTO codeCustomSerialDTO){ + String result = ""; + try { + Class classInstance=Class.forName(className); + Object obj =classInstance.newInstance(); + Method method= classInstance.getMethod("serialGenerate",CodeCustomSerialDTO.class); + method.setAccessible(Boolean.TRUE); + //method.invoke(obj); + Object o= method.invoke(obj,codeCustomSerialDTO); + result= Func.isEmpty(o) ?"":o.toString(); + } catch (ClassNotFoundException e) { + throw new VciBaseException("鏈壘鍒拌嚜瀹氫箟娴佹按绠楁硶绫绘枃浠�"); + } catch (InvocationTargetException e) { + throw new VciBaseException("鎵ц鑷畾涔夋祦姘寸畻娉曞鐞嗘柟娉曞嚭鐜板紓甯�"); + } catch (NoSuchMethodException e) { + throw new VciBaseException("鏈壘鍒拌嚜瀹氫箟娴佹按绠楁硶澶勭悊鏂规硶"); + } catch (IllegalAccessException e) { + throw new VciBaseException("鎵ц鑷畾涔夋祦姘寸畻娉曞鐞嗘柟娉曞嚭鐜板紓甯�"); + } catch (InstantiationException e) { + e.printStackTrace(); + } + return result; + } /** * 杞崲鐮佸�肩殑鍐呭 * @param secVO 鐮佹鐨勫唴瀹� @@ -769,7 +845,7 @@ * @param maxSerialValueMap 渚濇嵁瀛樺偍鐨勬渶澶ф祦姘寸殑鍐呭 */ private void saveSerialValue(CodeRuleVO ruleVO, - Map<String/**鐮佹鐨勪富閿�**/,Map<String, Double>> lastMaxSerialValueMap, + Map<String/**鐮佹鐨勪富閿�**/,Map<String, String>> lastMaxSerialValueMap, Map<String/**鐮佹鐨勪富閿�**/,Map<String, CodeSerialValue>> maxSerialValueMap){ List<CodeSerialValue> editSerialValueDOList = new ArrayList<>(); List<CodeSerialValue> addSerialValueDOList = new ArrayList<>(); -- Gitblit v1.9.3