| | |
| | | package com.vci.ubcs.code.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.vci.ubcs.code.algorithm.CustomSerialEnum; |
| | | import com.vci.ubcs.code.annotation.MdmSerialAlgorithm; |
| | | import com.vci.ubcs.code.annotation.MdmSerialAlgorithmMethod; |
| | |
| | | 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; |
| | |
| | | @Autowired |
| | | private FormulaServiceImpl formulaService; |
| | | |
| | | // 注入事务管理器 |
| | | // @Autowired |
| | | // private TransactionTemplate transactionTemplate; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public List<String> productCodeAndSaveData(CodeClassifyFullInfoBO classifyFullInfoBO, CodeClassifyTemplateVO templateVO, CodeRuleVO ruleVO, List<CodeOrderSecDTO> secDTOList, List<BaseModel> dataCBOList,BladeUser user) throws Exception { |
| | |
| | | //VciBaseUtil.setCurrentUserSessionInfo(sessionInfo); |
| | | String code = cbo.getId(); |
| | | List<String> serialUnitList = new CopyOnWriteArrayList<>(); |
| | | String seclenghStr=cbo.getData().get(CODE_SEC_LENGTH_FIELD); |
| | | //String seclenghStr=cbo.getData().get(CODE_SEC_LENGTH_FIELD); |
| | | String[] secLengths = cbo.getData().get(CODE_SEC_LENGTH_FIELD).split("#"); |
| | | cbo.getData().remove(CODE_SEC_LENGTH_FIELD);//将此key除去 |
| | | cbo.getData().remove(IMPORT_ROW_INDEX);//将此key除去 |
| | |
| | | //最后 |
| | | thisSecValue = seclenghStr.contains("#")?code.substring(VciBaseUtil.getInt(secLengths[i-1]),code.length()):code; |
| | | }else {*/ |
| | | int start = 0; |
| | | for (int j = 0; j < i; j++) { |
| | | start += VciBaseUtil.getInt(secLengths[j]); |
| | | } |
| | | thisSecValue = code.substring(start,start+VciBaseUtil.getInt(secLengths[i])); |
| | | int start = 0; |
| | | for (int j = 0; j < i; j++) { |
| | | start += VciBaseUtil.getInt(secLengths[j]); |
| | | } |
| | | thisSecValue = code.substring(start,start+VciBaseUtil.getInt(secLengths[i])); |
| | | // } |
| | | if(VciBaseUtil.getBoolean(secVO.getSerialDependFlag())){ |
| | | serialUnitList.add(thisSecValue); |
| | |
| | | List<String> serialUnFileStringList = new ArrayList<>(); |
| | | AtomicReference<String> newSerialUnitString = new AtomicReference<>(""); |
| | | if(!CollectionUtils.isEmpty(serialValueMap)){ |
| | | AtomicInteger index= new AtomicInteger(); |
| | | AtomicInteger index = new AtomicInteger(); |
| | | serialValueMap.forEach((secOid,secValue)->{ |
| | | //要看是不是补位的 |
| | | CodeBasicSecVO secVO = secVOMap.get(secOid); |
| | |
| | | if(OsCodeFillTypeEnum.NONE.getValue().equalsIgnoreCase(secVO.getCodeFillType())){ |
| | | //不补码 |
| | | //把所有不是数字的去掉,因为可能会是老数据,新规则 |
| | | // serialDb = VciBaseUtil.getDouble(killUnNumberChar(subSecValue)); |
| | | //serialDb = VciBaseUtil.getDouble(killUnNumberChar(subSecValue)); |
| | | //serialDb = killUnNumberChar(subSecValue); |
| | | serialDb=subSecValue; |
| | | }else { |
| | |
| | | serialDb = killFillChar(subSecValue,secVO.getCodeFillSeparator(), |
| | | OsCodeFillTypeEnum.LEFT.getValue().equalsIgnoreCase(secVO.getCodeFillType())); |
| | | } |
| | | 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,""); |
| | | maxValue=StringUtils.isBlank(newMaxValue)?-1:VciBaseUtil.getDouble(newMaxValue); |
| | | if(maxValue<newSerialDb){ |
| | | maxValue=newSerialDb; |
| | | Double newSerialDb = CustomSerialEnum.getDoubleCustomSerialValue(serialDb,secVO.getCustomCodeSerialType()); |
| | | //TODO: 20240822需要这块代码是同步性的,maxSerialMap这儿会因为线程受影响,修改后测试多次总数为5000条一次导入耗费时间为3分30秒左右 |
| | | synchronized(this) { |
| | | HashMap<String, String> thisUnitMaxMap = maxSerialMap.getOrDefault(serialUnitString, new HashMap<>()); |
| | | Double maxValue=newSerialDb; |
| | | if(thisUnitMaxMap.containsKey(secOid)){ |
| | | String newMaxValue = thisUnitMaxMap.getOrDefault(secOid,""); |
| | | maxValue = StringUtils.isBlank(newMaxValue)?-1:VciBaseUtil.getDouble(newMaxValue); |
| | | if(maxValue < newSerialDb){ |
| | | maxValue = newSerialDb; |
| | | } |
| | | } |
| | | 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)); |
| | | } |
| | | 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)); |
| | | }); |
| | | } |
| | | CodeAllCode allCodeDO = new CodeAllCode(); |
| | |
| | | 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); |
| | | }); |
| | |
| | | VciBaseUtil.toInSql(codeDOs.stream().map(s->s.getId()).collect(Collectors.toList()).toArray(new String[0])) + ")"); |
| | | List<CodeAllCode> existCodes = codeAllCodeService.selectByWrapper(allCodeWrapper); |
| | | |
| | | |
| | | if(!CollectionUtils.isEmpty(existCodes)){ |
| | | existCodes.stream().forEach(existCode->{ |
| | | String rule_id = existCode.getCodeRuleOid() + "${SEP}" + existCode.getId(); |
| | |
| | | if(!CollectionUtils.isEmpty(editCodeDOs)){ |
| | | codeAllCodeService.updateBatchById(editCodeDOs); |
| | | } |
| | | // 获取事务定义 |
| | | //DefaultTransactionDefinition def = new DefaultTransactionDefinition(); |
| | | // 开始事务 |
| | | //TransactionStatus status = transactionTemplate.getTransactionManager().getTransaction(def); |
| | | if(!CollectionUtils.isEmpty(addCodeDOs)){ |
| | | Map<String, String> statusMap = addCodeDOs.stream().collect(Collectors.toMap(s -> s.getOid(), s -> s.getLcStatus())); |
| | | addCodeDOs.stream().filter(s -> StringUtils.equalsIgnoreCase("codeallcode",s.getBtmname())).forEach(s -> { |
| | |
| | | for (CodeAllCode codeAllCode : takeBack) { |
| | | codeAllCode.setTs(new Date()); |
| | | codeAllCode.setLastModifyTime(new Date()); |
| | | codeAllCode.setLastModifier(AuthUtil.getUserId().toString()); |
| | | Iterator<CodeAllCode> iterator = addCodeDOs.iterator(); |
| | | codeAllCode.setLastModifier(Func.isNotEmpty(user) ? user.getAccount():AuthUtil.getUserAccount()); |
| | | for (int i = 0; i < addCodeDOs.size(); i++) { |
| | | if(codeAllCode.getId().equals(addCodeDOs.get(i).getId())){ |
| | | codeAllCode.setCreateCodeOid(addCodeDOs.get(i).getCreateCodeOid()); |
| | | codeAllCode.setLcStatus(addCodeDOs.get(i).getLcStatus()); |
| | | addCodeDOs.remove(i); |
| | | } |
| | | } |
| | | /*Iterator<CodeAllCode> iterator = addCodeDOs.iterator(); |
| | | while (iterator.hasNext()){ |
| | | CodeAllCode next = iterator.next(); |
| | | if(codeAllCode.getId().equals(next.getId())){ |
| | | codeAllCode.setCreateCodeOid(next.getCreateCodeOid()); |
| | | codeAllCode.setLcStatus(next.getLcStatus()); |
| | | // TODO: 这儿先暂时注释掉,没看懂这儿为什么要这样做,导致报错 |
| | | //iterator.remove(); |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | }*/ |
| | | } |
| | | if(takeBack.size()>0){ |
| | | codeAllCodeService.updateBatchById(takeBack); |
| | |
| | | |
| | | codeAllCodeService.saveBatch(addCodeDOs); |
| | | } |
| | | |
| | | // try { |
| | | mdmEngineService.insertBatchByType(dataCBOList.get(0).getBtmname(),dataCBOList); |
| | | // 提交事务 |
| | | //transactionTemplate.getTransactionManager().commit(status); |
| | | // }catch (Exception e){ |
| | | // // 出现异常时回滚事务 |
| | | // transactionTemplate.getTransactionManager().rollback(status); |
| | | // } |
| | | |
| | | } |
| | | return codeList; |
| | | }else { |
| | |
| | | List<CodeBasicSecVO> attrSecVOList = new ArrayList<>(); |
| | | for (int i = 0; i < secVOList.size(); i++) { |
| | | CodeBasicSecVO secVO = secVOList.get(i); |
| | | switchSecValue(secVO, secValueMap, classifyFullInfoBO, serialSecVOList, attrSecVOList, serialUnitList, secValueList); |
| | | try{ |
| | | switchSecValue(secVO, secValueMap, classifyFullInfoBO, serialSecVOList, attrSecVOList, serialUnitList, secValueList); |
| | | }catch (Exception e){ |
| | | throw new ServiceException("码值转换时出现错误,原因:"+e.getMessage()); |
| | | } |
| | | } |
| | | //处理属性码段和流水码段 |
| | | Map<String/**流水码段的主键**/, Map<String/**流水依据**/, String>> lastMaxSerialValueMap = new HashMap<>(); |
| | |
| | | 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())); |
| | |
| | | .collectingAndThen( |
| | | Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CodeAllCode::getId))), |
| | | ArrayList::new)); |
| | | if( distinctCodeAllCOdes.size() != allCodeDOList.size() ){ |
| | | if(distinctCodeAllCOdes.size() != allCodeDOList.size() ){ |
| | | throw new ServiceException("编码数据重复,无法保存,请注意!"); |
| | | } |
| | | QueryWrapper<CodeAllCode> wrapper = new QueryWrapper<>(); |
| | |
| | | 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.setLastModifier(Func.isNotEmpty(user) ? user.getAccount():AuthUtil.getUserAccount()); |
| | | for (int i = 0; i < allCodeDOList.size(); i++) { |
| | | if(codeAllCode.getId().equals(allCodeDOList.get(i).getId())){ |
| | | codeAllCode.setCreateCodeOid(allCodeDOList.get(i).getCreateCodeOid()); |
| | | codeAllCode.setLcStatus(allCodeDOList.get(i).getLcStatus()); |
| | | allCodeDOList.remove(i); |
| | | } |
| | | } |
| | | /*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); |
| | | // batchCBO.getCreateCbos().stream().filter(s -> StringUtils.equalsIgnoreCase("codeallcode",s.getBtmName())).forEach(s -> { |
| | | // s.setLcStatus(statusMap.get(s.getOid())); |
| | | // try { |
| | | // s.setAttributeValue("lcstatus",statusMap.get(s.getOid())); |
| | | // } catch (VCIError e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // }); |
| | | } |
| | | // WebUtil.setPersistence(true); |
| | | // boService.persistenceBatch(batchCBO); |
| | | return codeList; |
| | | } |
| | | |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 转换流水码段的值 |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 转换流水码段的值 |
| | |
| | | case CODE_CLASSIFY_SEC: |
| | | //分类码段的,也是从前端选择了码值即可,不论码值的长度是多少 |
| | | CodeClassifyValue codeClassifyValueDO= codeClassifyValueMapper.selectById(secValue); |
| | | //当码值为空或#NaN?时即表示作为空字符串进行拼接 |
| | | if(Func.isBlank(codeClassifyValueDO.getId()) || codeClassifyValueDO.getId().equals("#NaN?")){ |
| | | codeClassifyValueDO.setId(""); |
| | | } |
| | | if(codeClassifyValueDO!=null) { |
| | | secValue = joinPreffixAndSuffix(secVO, codeClassifyValueDO.getId()); |
| | | } |
| | |
| | | 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()}); |
| | | throw new ServiceException(String.format("【{%s}】这个码段是可变码段,但是现在输入的码值的长度({%s})超过了规定的长度{%s}", secVO.getName(), secValue.length(), secVO.getCodeSecLength())); |
| | | } |
| | | OsCodeFillTypeEnum fillTypeEnum = OsCodeFillTypeEnum.forValue(secVO.getCodeFillType()); |
| | | secValue = fillString(VciBaseUtil.getInt(secVO.getCodeSecLength()), fillTypeEnum, secValue, secVO.getCodeFillSeparator()); |
| | |
| | | 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 !secValueStr.equals("${"+secVO.getOid()+"}"); |
| | | return index[0]++< finalI;//除去流水的 |
| | | }).collect(Collectors.toList()); |
| | | String serialUnitString = serialUnitList.size() == 0 ? EMPTY_SERIAL_UNIT : newSerialUnitList.stream().collect(Collectors.joining(SERIAL_UNIT_SPACE)); |
| | | String serialUnitString = newSerialUnitList.size() == 0 ? EMPTY_SERIAL_UNIT : newSerialUnitList.stream().collect(Collectors.joining(SERIAL_UNIT_SPACE)); |
| | | secOdserialUnitMap.put(secVO.getOid(),serialUnitString); |
| | | } |
| | | } |
| | |
| | | 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()); |
| | | 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)); |
| | |
| | | codeAllCode.setLastModifyTime(new Date()); |
| | | codeAllCode.setLastModifier(AuthUtil.getUserId().toString()); |
| | | Iterator<CodeAllCode> iterator = allCodeDOList.iterator(); |
| | | while (iterator.hasNext()){ |
| | | for (int i = 0; i < allCodeDOList.size(); i++) { |
| | | if(codeAllCode.getId().equals(allCodeDOList.get(i).getId())){ |
| | | codeAllCode.setCreateCodeOid(allCodeDOList.get(i).getCreateCodeOid()); |
| | | codeAllCode.setLcStatus(allCodeDOList.get(i).getLcStatus()); |
| | | allCodeDOList.remove(i); |
| | | } |
| | | } |
| | | /*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); |
| | |
| | | mdmEngineService.insertBatchByType(dataCBOList.get(0).getBtmname(),dataCBOList); |
| | | return codeList; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 转换码值的内容 |
| | |
| | | case CODE_CLASSIFY_SEC: |
| | | //分类码段的,也是从前端选择了码值即可,不论码值的长度是多少 |
| | | CodeClassifyValue codeClassifyValueDO= codeClassifyValueMapper.selectById(secValue); |
| | | if(Func.isBlank(codeClassifyValueDO.getId()) || codeClassifyValueDO.getId().equals("#NaN?")){ |
| | | codeClassifyValueDO.setId(""); |
| | | } |
| | | if(codeClassifyValueDO!=null) { |
| | | secValue = joinPreffixAndSuffix(secVO, codeClassifyValueDO.getId()); |
| | | } |