| | |
| | | package com.vci.ubcs.code.service.impl; |
| | | |
| | | import com.vci.ubcs.code.algorithm.CustomSerialEnum; |
| | | import com.vci.ubcs.code.dto.CodeCustomSerialDTO; |
| | | 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; |
| | |
| | | log.info("code:----->"+cbo.getId()); |
| | | //VciBaseUtil.setCurrentUserSessionInfo(sessionInfo); |
| | | String code = cbo.getId(); |
| | | List<String> serialUnitList = new ArrayList<>(); |
| | | List<String> serialUnitList = new CopyOnWriteArrayList<>(); |
| | | 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除去 |
| | |
| | | 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 = killFillChar(subSecValue,secVO.getCodeFillSeparator(), |
| | | OsCodeFillTypeEnum.LEFT.getValue().equalsIgnoreCase(secVO.getCodeFillType())); |
| | | } |
| | |
| | | // 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 ArrayList<>(); |
| | | List<CodeAllCode> editCodeDOs = new ArrayList<>(); |
| | | List<CodeAllCode> addCodeDOs = new CopyOnWriteArrayList<>(); |
| | | List<CodeAllCode> editCodeDOs = new CopyOnWriteArrayList<>(); |
| | | ruleGroup.forEach((ruleOid,allCodeDOS)->{ |
| | | VciBaseUtil.switchCollectionForOracleIn(allCodeDOS).stream().forEach(codeDOs->{ |
| | | QueryWrapper<CodeAllCode> allCodeWrapper = new QueryWrapper<>(); |
| | |
| | | .collectingAndThen( |
| | | Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CodeAllCode::getId))), |
| | | ArrayList::new)); |
| | | if( distinctCodeAllCOdes.size() != addCodeDOs.size() ){ |
| | | if(distinctCodeAllCOdes.size() != addCodeDOs.size() ){ |
| | | throw new VciBaseException("编码数据重复,无法保存,请注意!"); |
| | | } |
| | | QueryWrapper<CodeAllCode> wrapper = new QueryWrapper<>(); |
| | |
| | | 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())); |
| | | throw new ServiceException("生成编码数据ID已有历史记录,请确认如下生成的ID数据:"+ addCodeDOs.stream().map(CodeAllCode::getId).collect(Collectors.toList())); |
| | | } |
| | | for (CodeAllCode codeAllCode : takeBack) { |
| | | codeAllCode.setTs(new Date()); |
| | |
| | | if(codeAllCode.getId().equals(next.getId())){ |
| | | codeAllCode.setCreateCodeOid(next.getCreateCodeOid()); |
| | | codeAllCode.setLcStatus(next.getLcStatus()); |
| | | iterator.remove(); |
| | | // TODO: 这儿先暂时注释掉,没看懂这儿为什么要这样做,导致报错 |
| | | //iterator.remove(); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | // try { |
| | | mdmEngineService.insertBatchByType(dataCBOList.get(0).getBtmname(),dataCBOList); |
| | | // 提交事务 |
| | | //transactionTemplate.getTransactionManager().commit(status); |
| | | // }catch (Exception e){ |
| | | // // 出现异常时回滚事务 |
| | | // transactionTemplate.getTransactionManager().rollback(status); |
| | | // } |
| | | |
| | | } |
| | | return codeList; |
| | | }else { |
| | |
| | | //处理最大流水 |
| | | 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数据:"+ codeAllCodes.stream().map(CodeAllCode::getId).collect(Collectors.toList())); |
| | | } |
| | | allCodeDOList.stream().forEach( |
| | | allCode -> {DefaultAttrAssimtUtil.addDefaultAttrAssimt(allCode,"codeallcode");allCode.setLctid("codeAllCodeLC");} |
| | | ); |
| | | |
| | | 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(); |
| | | } |
| | | |
| | | 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(); |
| | | } |
| | | } |
| | | 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; |
| | | //} |
| | | } |
| | | 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 { |
| | |
| | | CodeRuleVO ruleVO,String serialUnitString, |
| | | Map<String/**码段的主键**/,Map<String/**流水依据**/,CodeSerialValue>> maxSerialValueMap,List<String> thisSecValueList, |
| | | 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++) { |
| | |
| | | } |
| | | } |
| | | } |
| | | private String customCodeSerial(String className, CodeCustomSerialDTO codeCustomSerialDTO){ |
| | | |
| | | private String customCodeSerial(String className, CodeCustomSerialDTO codeCustomSerialDTO){ |
| | | String result = ""; |
| | | try { |
| | | Class classInstance=Class.forName(className); |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 转换码值的内容 |
| | | * @param secVO 码段的内容 |