| | |
| | | import com.alibaba.cloud.commons.lang.StringUtils; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import com.vci.ubcs.code.constant.MdmBtmTypeConstant; |
| | | |
| | | import com.vci.ubcs.code.dto.CodeBasicSecDTO; |
| | | import com.vci.ubcs.code.dto.CodeOrderDTO; |
| | | import com.vci.ubcs.code.dto.CodeOrderSecDTO; |
| | | import com.vci.ubcs.code.entity.*; |
| | | import com.vci.ubcs.code.enumpack.*; |
| | | import com.vci.ubcs.code.lifecycle.CodeRuleLC; |
| | | import com.vci.ubcs.code.mapper.CodeBasicSecMapper; |
| | | import com.vci.ubcs.code.mapper.CodeClassifyValueMapper; |
| | | import com.vci.ubcs.code.mapper.CodeFixedValueMapper; |
| | | import com.vci.ubcs.code.mapper.CodeSerialValueMapper; |
| | | import com.vci.ubcs.code.service.*; |
| | | import com.vci.ubcs.code.vo.CodeReferConfigVO; |
| | | import com.vci.ubcs.code.vo.pagemodel.*; |
| | |
| | | import com.vci.ubcs.omd.enums.EnumEnum; |
| | | import com.vci.ubcs.starter.enumpack.CodeTableNameEnum; |
| | | import com.vci.ubcs.starter.exception.VciBaseException; |
| | | import com.vci.ubcs.starter.revision.model.BaseModel; |
| | | import com.vci.ubcs.starter.revision.service.RevisionModelUtil; |
| | | import com.vci.ubcs.starter.util.DefaultAttrAssimtUtil; |
| | | import com.vci.ubcs.starter.util.MdmBtmTypeConstant; |
| | | import com.vci.ubcs.starter.util.UBCSCondition; |
| | | import com.vci.ubcs.starter.util.UBCSSqlKeyword; |
| | | import com.vci.ubcs.starter.web.enumpck.OsCodeFillTypeEnum; |
| | | import com.vci.ubcs.starter.web.pagemodel.*; |
| | | import com.vci.ubcs.starter.web.util.BeanUtilForVCI; |
| | | import com.vci.ubcs.starter.web.util.VciBaseUtil; |
| | | import com.vci.ubcs.starter.web.util.VciDateUtil; |
| | | import com.vci.ubcs.starter.web.util.WebUtil; |
| | | import com.vci.ubcs.system.entity.DictBiz; |
| | | import com.vci.ubcs.system.feign.IDictBizClient; |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.rmi.ServerException; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.*; |
| | | import static com.vci.ubcs.code.constant.MdmEngineConstant.EMPTY_SERIAL_UNIT; |
| | | import static com.vci.ubcs.code.constant.MdmEngineConstant.SERIAL_UNIT_SPACE; |
| | | |
| | | /** |
| | | * 码段基础信息服务接口 |
| | |
| | | private ICodeFixedValueService fixedValueService; |
| | | |
| | | /** |
| | | * 流水号的相关的信息 |
| | | */ |
| | | @Resource |
| | | private CodeSerialValueMapper serialValueMapper; |
| | | |
| | | /** |
| | | * 上层分类码段的属性名称 |
| | | */ |
| | | private static final String PARENT_FIELD_NAME = "parentclassifysecoid"; |
| | | private static final String PARENT_FIELD_NAME = "parentClassifySecOid"; |
| | | |
| | | /** |
| | | * 上级分类码值的属性名称 |
| | |
| | | // 将要作为删除条件的值放在一个集合里面 |
| | | Set<String> fixedSecOidSet = fixedSecList.stream().map(CodeBasicSec::getOid).collect(Collectors.toSet()); |
| | | // 通过外键进行查询 |
| | | List<CodeFixedValue> fixedValueS = fixedValueMapper.selectList(Wrappers.<CodeFixedValue>query().lambda().in(CodeFixedValue::getCodeFixedSecOid,fixedSecOidSet)); |
| | | if(!fixedValueS.isEmpty()){ |
| | | List<CodeFixedValue> fixedValues = fixedValueMapper.selectList(Wrappers.<CodeFixedValue>query().lambda().in(CodeFixedValue::getCodeFixedSecOid,fixedSecOidSet)); |
| | | if(!fixedValues.isEmpty()){ |
| | | // 根据查询出来的id执行固定码段执行删除 |
| | | deletFlag = fixedValueMapper.deleteBatchIds(fixedValueS.stream().map(CodeFixedValue::getOid).collect(Collectors.toSet()))>0; |
| | | deletFlag = fixedValueMapper.deleteBatchIds(fixedValues.stream().map(CodeFixedValue::getOid).collect(Collectors.toSet()))>0; |
| | | } |
| | | } |
| | | // 4、再删除分类码段 |
| | |
| | | // 将要作为删除条件的值放在一个集合里面 |
| | | Set<String> classifySecOidSet = classifySecList.stream().map(CodeBasicSec::getOid).collect(Collectors.toSet()); |
| | | // 通过外键进行查询 |
| | | List<CodeClassifyValue> fixedValueS = codeClassifyValueMapper.selectList(Wrappers.<CodeClassifyValue>query().lambda().in(CodeClassifyValue::getCodeClassifySecOid,classifySecOidSet)); |
| | | if(!fixedValueS.isEmpty()){ |
| | | List<CodeClassifyValue> codeClassifyValues = codeClassifyValueMapper.selectList(Wrappers.<CodeClassifyValue>query().lambda().in(CodeClassifyValue::getCodeClassifySecOid,classifySecOidSet)); |
| | | if(!codeClassifyValues.isEmpty()){ |
| | | // 根据查询出来的主键id执行固定码段执行删除 |
| | | deletFlag = fixedValueMapper.deleteBatchIds(fixedValueS.stream().map(CodeClassifyValue::getOid).collect(Collectors.toSet()))>0; |
| | | deletFlag = codeClassifyValueMapper.deleteBatchIds(codeClassifyValues.stream().map(CodeClassifyValue::getOid).collect(Collectors.toSet()))>0; |
| | | } |
| | | } |
| | | return deletFlag; |
| | |
| | | * @return 执行结果 |
| | | * @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常 |
| | | */ |
| | | @Override |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean addSave(CodeBasicSecDTO codeBasicSecDTO) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull(codeBasicSecDTO, "需要添加的数据对象",codeBasicSecDTO.getPkCodeRule(),"编码规则的主键"); |
| | |
| | | codeBasicSecDO.setValueCutTypeText(EnumCache.getValue(EnumEnum.CODE_CUT_TYPE,codeBasicSecDTO.getValueCutType())); |
| | | codeBasicSecDO.setCodeGetValueTypeText(EnumCache.getValue(EnumEnum.CODE_GET_VALUE_TYPE,codeBasicSecDTO.getCodeGetValueType())); |
| | | //填充一些默认值 |
| | | DefaultAttrAssimtUtil.addDefaultAttrAssimt(codeBasicSecDO,MdmBtmTypeConstant.CODE_BASIC_SEC); |
| | | DefaultAttrAssimtUtil.addDefaultAttrAssimt(codeBasicSecDO, MdmBtmTypeConstant.CODE_BASIC_SEC); |
| | | //排序号,默认等于当前已有的数量加1 |
| | | Long total = codeBasicSecMapper.selectCount(Wrappers.<CodeBasicSec>query() |
| | | .lambda() |
| | |
| | | //引用码段的时候,需要判断参照的信息是否正确 |
| | | if(CodeSecTypeEnum.CODE_REFER_SEC.getValue().equalsIgnoreCase(codeBasicSecDO.getSecType())){ |
| | | if(StringUtils.isBlank(codeBasicSecDO.getReferConfig())){ |
| | | throw new VciBaseException("引用码段的时候,需要填写 参照配置的内容"); |
| | | throw new VciBaseException("引用码段的时候,需要填写参照配置的内容"); |
| | | } |
| | | try{ |
| | | //JSONObject.parseObject(codeBasicSecDO.getReferConfig(), UIFormReferVO.class); |
| | |
| | | } |
| | | // 判断是否为引用码段,如果是应用码段的话,为了适配前端组件,这里要对表进行处理一下,按照以前的参照格式进行转换 |
| | | codeBasicSecDO.setReferValueInfo(referConfigToUIUiTable(codeReferConfigVO)); |
| | | if(codeReferConfigVO.getIsPersistence()=="true"){ |
| | | if(Func.toBoolean(codeReferConfigVO.getIsPersistence())){ |
| | | codeReferConfigService.insert(codeReferConfigVO); |
| | | } |
| | | } |
| | |
| | | BeanUtil.copy(showField,tableColVO); |
| | | tableColVO.setSortField(showField.getAttrSortField()); |
| | | uiTableFieldVOs.add(tableColVO); |
| | | if(showField.getIsQuery().equals("true")){ |
| | | queryColumns.add(tableColVO); |
| | | if(Func.toBoolean(showField.getIsQuery())){ |
| | | TableColVO tableQueryColumns = new TableColVO(); |
| | | BeanUtil.copy(showField,tableQueryColumns); |
| | | tableColVO.setSortField(showField.getAttrSortField()); |
| | | queryColumns.add(tableQueryColumns); |
| | | } |
| | | }); |
| | | } |
| | |
| | | uiTableConfigVO.setQueryColumns(queryColumns); |
| | | //set给表格配置属性 |
| | | uiFormReferVO.setTableConfig(uiTableConfigVO); |
| | | //字段名不一致,需要手动set |
| | | uiFormReferVO.setMuti(Func.toBoolean(codeReferConfig.getIsMuti())); |
| | | uiFormReferVO.setInitSort(new UIFieldSortVO(codeReferConfig.getSortField(),codeReferConfig.getSortType())); |
| | | // 筛选条件 |
| | | HashMap<String, String> whereMap = new HashMap<>(); |
| | | if(!codeReferConfig.getCodeSrchCondConfigVOS().isEmpty()){ |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean editSave(CodeBasicSecDTO codeBasicSecDTO) throws VciBaseException { |
| | | public boolean editSave(CodeBasicSecDTO codeBasicSecDTO) throws ServerException { |
| | | VciBaseUtil.alertNotNull(codeBasicSecDTO, "需要添加的数据对象"); |
| | | KeyValue attrKv = checkAttrNullableBySecType(codeBasicSecDTO); |
| | | if (! "success".equals(attrKv.getKey())){ |
| | | if (!"success".equals(attrKv.getKey())){ |
| | | throw new VciBaseException(attrKv.getValue() + "不能为空"); |
| | | } |
| | | //将DTO转换为DO |
| | |
| | | DefaultAttrAssimtUtil.updateDefaultAttrAssimt(codeBasicSecDO); |
| | | boolean status = codeRuleService.checkEditDelStatus(codeRuleService.getObjectByOid(codeBasicSecDO.getPkCodeRule()).getLcStatus()); |
| | | boolean resBoolean; |
| | | CodeReferConfigVO codeReferConfigVO = null; |
| | | if (!status){ |
| | | //返回错误信息 |
| | | throw new VciBaseException("编码规则不允许编辑或删除!"); |
| | |
| | | && StringUtils.isBlank(codeBasicSecDO.getCodeFillSeparator())){ |
| | | throw new VciBaseException("当补位方式为左补位或者右补位的时候,补位字符不能为空"); |
| | | } |
| | | CodeReferConfigVO codeReferConfigVO = null; |
| | | //引用码段的时候,需要判断参照的信息是否正确 |
| | | if(CodeSecTypeEnum.CODE_REFER_SEC.getValue().equalsIgnoreCase(codeBasicSecDO.getSecType())){ |
| | | if(StringUtils.isBlank(codeBasicSecDO.getReferConfig())){ |
| | | if(StringUtils.isBlank(codeBasicSecDTO.getReferConfig())){ |
| | | throw new VciBaseException("引用码段的时候,需要填写参照配置的内容"); |
| | | } |
| | | try{ |
| | | // JSONObject.parseObject(codeBasicSecDO.getReferConfig(), UIFormReferVO.class); |
| | | codeReferConfigVO = JSONObject.parseObject(codeBasicSecDO.getReferConfig(), CodeReferConfigVO.class); |
| | | codeReferConfigVO = JSONObject.parseObject(codeBasicSecDTO.getReferConfig(), CodeReferConfigVO.class); |
| | | }catch (Throwable e){ |
| | | throw new VciBaseException("引用码段的时候,参照配置的内容的格式不正确,",new String[0],e); |
| | | } |
| | | // 判断是否为引用码段,如果是应用码段的话,为了适配前端组件,这里要对表进行处理一下,按照以前的参照格式进行转换 |
| | | // 判断是否为引用码段,如果是引用码段的话,为了适配前端组件,这里要对表进行处理一下,按照以前的参照格式进行转换 |
| | | codeBasicSecDO.setReferValueInfo(referConfigToUIUiTable(codeReferConfigVO)); |
| | | if(codeReferConfigVO.getIsPersistence()=="true"){ |
| | | codeReferConfigService.insert(codeReferConfigVO); |
| | | } |
| | | } |
| | | revisionModelUtil.copyFromDTOIgnore(codeBasicSecDTO, codeBasicSecDO); |
| | | // revisionModelUtil.copyFromDTOIgnore(codeBasicSecDTO, codeBasicSecDO);//此处的拷贝会把referValueInfo的值给覆盖掉,需要重新赋值 |
| | | BaseModel tempModel = new BaseModel(); |
| | | BeanUtilForVCI.copyPropertiesIgnoreCase(codeBasicSecDO, tempModel); |
| | | BeanUtil.copyProperties(codeBasicSecDTO, codeBasicSecDO,"referValueInfo"); |
| | | BeanUtilForVCI.copyPropertiesIgnoreCase(tempModel, codeBasicSecDO); |
| | | codeBasicSecDO.setId(VciBaseUtil.getStringValueFromObject(VciBaseUtil.getValueFromField("id", codeBasicSecDTO))); |
| | | codeBasicSecDO.setName(VciBaseUtil.getStringValueFromObject(VciBaseUtil.getValueFromField("name", codeBasicSecDTO))); |
| | | codeBasicSecDO.setDescription(VciBaseUtil.getStringValueFromObject(VciBaseUtil.getValueFromField("description", codeBasicSecDTO))); |
| | | |
| | | resBoolean = codeBasicSecMapper.updateById(codeBasicSecDO)>0; |
| | | // 从分类码段或固定码段改为其他码段时,判断用户是否选择了清空码值 |
| | | if(codeBasicSecDTO.getIsClearValue()){ |
| | | // 分类码值清空 |
| | | if(codeBasicSecDTO.getSecType().equals(CodeSecTypeEnum.CODE_CLASSIFY_SEC.getValue())){ |
| | | codeClassifyValueService.deleteClassifyValueBySecOid(codeBasicSecDTO.getOid()); |
| | | }else { |
| | | //固定码值清空 |
| | | fixedValueService.deleteFixedValueBySecOid(codeBasicSecDTO.getOid()); |
| | | } |
| | | } |
| | | //SessionInfo sessionInfo = VciBaseUtil.getCurrentUserSessionInfo(); |
| | | if(StringUtils.isNotBlank(codeBasicSecDO.getCodeFillSeparator())){ |
| | | DictBiz dictBiz = new DictBiz(); |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R cloneCodeBasicSec(List<String> oidList, String pkCodeRule) throws ServiceException { |
| | | public R cloneCodeBasicSec(List<String> oidList, String pkCodeRule) throws ServiceException, ServerException { |
| | | boolean isLinked = checkIsLinked(pkCodeRule,null); |
| | | if (isLinked) { |
| | | return R.fail("编码规则已被引用,不允许编辑或删除"); |
| | | } |
| | | List<CodeBasicSec> createList = new ArrayList<>(); |
| | | List<CodeBasicSec> basicSecDOS = codeBasicSecMapper.selectBatchIds(oidList); |
| | | /* 需要注意的是克隆过来的码段需要对orderNum进行排序,否则会出现排序乱跳的情况 |
| | | 实现方式是查询出该规则下根据orderNum排序后的最后一个码段 */ |
| | | LambdaQueryWrapper<CodeBasicSec> lastBasicWrapper = Wrappers.<CodeBasicSec>query() |
| | | .lambda().orderByDesc(CodeBasicSec::getOrderNum) |
| | | .eq(CodeBasicSec::getPkCodeRule,pkCodeRule) |
| | | .last("limit 1"); |
| | | CodeBasicSec lastCodeBasicSec = codeBasicSecMapper.selectOne(lastBasicWrapper); |
| | | // 排序号从这儿开始排 |
| | | int orderNum = Func.isEmpty(lastCodeBasicSec) || Func.isEmpty(lastCodeBasicSec.getOrderNum()) ? -1 : lastCodeBasicSec.getOrderNum(); |
| | | if(basicSecDOS.isEmpty()){ |
| | | return R.fail("克隆的码段信息不存在!"); |
| | | } |
| | | basicSecDOS.forEach(sec -> { |
| | | List<CodeBasicSec> codeClassifySec = new ArrayList<>(); |
| | | Map<String,List<CodeFixedValue>> codeFixedValueMaps = new HashMap<>(); |
| | | for (CodeBasicSec sec : basicSecDOS) { |
| | | CodeBasicSec newSecDO = new CodeBasicSec(); |
| | | BeanUtilForVCI.copyPropertiesIgnoreCase(sec,newSecDO); |
| | | newSecDO.setOid(VciBaseUtil.getPk()); |
| | | newSecDO.setNameOid(VciBaseUtil.getPk()); |
| | | newSecDO.setRevisionOid(VciBaseUtil.getPk()); |
| | | newSecDO.setId(newSecDO.getId() + "_copy"); |
| | | newSecDO.setName(newSecDO.getName() + "_copy"); |
| | | String oldBasicOid = newSecDO.getOid(); |
| | | newSecDO.setId(newSecDO.getId()); |
| | | newSecDO.setName(newSecDO.getName()); |
| | | orderNum++; |
| | | newSecDO.setOrderNum(orderNum); |
| | | newSecDO.setPkCodeRule(pkCodeRule); |
| | | // 判断是否是分类码段,业务逻辑稍微复杂一点所以需要先提出来单独处理 |
| | | if(newSecDO.getSecType().equals(CodeSecTypeEnum.CODE_CLASSIFY_SEC.getValue())){ |
| | | // 存储旧的码段oid和新的码段的oid的关联关系 |
| | | codeClassifySec.add(newSecDO); |
| | | continue; |
| | | } |
| | | // 更改创建时间,修改时间等默认值 |
| | | DefaultAttrAssimtUtil.addDefaultAttrAssimt(newSecDO,MdmBtmTypeConstant.CODE_BASIC_SEC); |
| | | //固定码段 |
| | | if(newSecDO.getSecType().equals(CodeSecTypeEnum.CODE_FIXED_SEC.getValue())){ |
| | | // 固定码段存储好oid和码值的关联关系 |
| | | codeFixedValueMaps.put(newSecDO.getOid(),fixedValueService.list(Wrappers.<CodeFixedValue>query() |
| | | .lambda().eq(CodeFixedValue::getCodeFixedSecOid, oldBasicOid) |
| | | )); |
| | | } |
| | | createList.add(newSecDO); |
| | | } |
| | | // 处理分类码段的oid,因为oid关联parentClassifyOid,与码值codeClassifyOid,码值又需要通过旧的码段oid来查询,所以不能直接改变oid |
| | | changeParentOidAssnOid(codeClassifySec); |
| | | // 将处理过的分类码段也添加进要做新增处理的码段集合中 |
| | | createList.addAll(codeClassifySec); |
| | | boolean resBoolean = true; |
| | | if(!createList.isEmpty()){ |
| | | resBoolean = saveBatch(createList); |
| | | } |
| | | // 最终要存入码值表中的,码值对象 |
| | | List<CodeFixedValue> codeFixedDOValues = new ArrayList<>(); |
| | | // 构造码值对象,与码段主键关联关系,以及改变固定码值的oid |
| | | codeFixedValueMaps.forEach((key, value) -> { |
| | | value.stream().forEach(item -> { |
| | | item.setOid(""); |
| | | item.setCodeFixedSecOid(key); |
| | | DefaultAttrAssimtUtil.updateDefaultAttrAssimt(item); |
| | | codeFixedDOValues.add(item); |
| | | }); |
| | | }); |
| | | boolean resBoolean = saveBatch(createList); |
| | | //codeBasicSecMapper.insertBatch(createList); |
| | | return resBoolean ? R.data(resBoolean,"克隆码段信息成功"):R.fail("克隆码段信息失败!"); |
| | | boolean resFixed = true; |
| | | if(!codeFixedValueMaps.isEmpty()){ |
| | | // 克隆固定码值 |
| | | resFixed = fixedValueService.saveBatch(codeFixedDOValues); |
| | | } |
| | | return (resBoolean&&resFixed) ? R.data(resBoolean,"克隆码段信息成功"):R.fail("克隆码段信息失败!"); |
| | | } |
| | | |
| | | /** |
| | | * 改变码段中父分类码段和子分类码段之间的关联oid为新的oid,并且不破坏分类码值的关联关系 |
| | | * @param basicSecs |
| | | * @return |
| | | * @throws ServerException |
| | | */ |
| | | @Override |
| | | public boolean changeParentOidAssnOid(List<CodeBasicSec> basicSecs) throws ServerException { |
| | | Map<String, List<CodeClassifyValue>> codeClassValues = new HashMap<>(); |
| | | List<CodeClassifyValue> codeClassifyDOValues = new ArrayList<>(); |
| | | HashMap<String, String> oidMap = new HashMap<>(); |
| | | boolean resClone = false; |
| | | try { |
| | | // 遍历对象数组,为每个对象生成新的oid,并将原始oid和新oid的映射关系存储到Map中 |
| | | for (CodeBasicSec obj : basicSecs) { |
| | | String originalOid = obj.getOid(); |
| | | String newOid = VciBaseUtil.getPk(); |
| | | oidMap.put(originalOid, newOid); |
| | | } |
| | | // 遍历对象数组,更新每个对象的oid和codeClassifySecOid属性值 |
| | | for (CodeBasicSec obj : basicSecs) { |
| | | String originalOid = obj.getOid(); |
| | | String newOid = oidMap.get(originalOid); |
| | | // 新的oid关联要克隆码值 |
| | | codeClassValues.put(newOid,codeClassifyValueService.list(Wrappers.<CodeClassifyValue>query() |
| | | .lambda().eq(CodeClassifyValue::getCodeClassifySecOid, originalOid))); |
| | | obj.setOid(newOid); |
| | | String originalParentClassifyValueOid = obj.getParentClassifySecOid(); |
| | | String newParentClassifyValueOid = oidMap.get(originalParentClassifyValueOid); |
| | | obj.setParentClassifySecOid(newParentClassifyValueOid); |
| | | } |
| | | codeClassValues.forEach((key, value) -> { |
| | | value.stream().forEach(item -> { |
| | | DefaultAttrAssimtUtil.updateDefaultAttrAssimt(item); |
| | | item.setCodeClassifySecOid(key); |
| | | codeClassifyDOValues.add(item); |
| | | }); |
| | | }); |
| | | resClone = codeClassifyValueService.cloneCodeClassifyVaue(codeClassifyDOValues); |
| | | }catch (Exception e){ |
| | | throw new ServerException("父分类码段和子分类码段clone转换oid时出错:"+e.getCause()); |
| | | } |
| | | return resClone; |
| | | } |
| | | |
| | | /** |
| | |
| | | return codeBasicSecVO; |
| | | } |
| | | |
| | | /** |
| | | * 根据编码规则主键获取编码下的流水依赖码段 |
| | | * |
| | | * @param oid 编码规则主键 |
| | | * @return |
| | | * @throws VciBaseException |
| | | */ |
| | | @Override |
| | | public CodeRuleVO getSerialNumberDepend(String oid) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull(oid,"编码规则主键"); |
| | | CodeRuleVO codeRuleVO = codeRuleService.getObjectByOid(oid); |
| | | if (codeRuleVO != null) { |
| | | //如果有lcstatus的类的话 |
| | | codeRuleVO.setLcStatusText(CodeRuleLC.getTextByValue(codeRuleVO.getLcStatus())); |
| | | |
| | | LambdaQueryWrapper<CodeBasicSec> wrapper = Wrappers.<CodeBasicSec>query().lambda() |
| | | .eq(CodeBasicSec::getPkCodeRule, codeRuleVO.getOid()) |
| | | .eq(CodeBasicSec::getSecType,CodeSecTypeEnum.CODE_SERIAL_SEC.getValue()); |
| | | CodeBasicSec codeBasicSec = this.getOne(wrapper); |
| | | if(codeBasicSec != null && VciBaseUtil.isNotNull(codeBasicSec.getOid())){ |
| | | wrapper = Wrappers.<CodeBasicSec>query().lambda() |
| | | .eq(CodeBasicSec::getPkCodeRule,codeRuleVO.getOid()) |
| | | .eq(CodeBasicSec::getSerialDependFlag,"true") |
| | | .orderByAsc(CodeBasicSec::getOrderNum); |
| | | //.orderByAsc(CodeBasicSec::getSerialDependOrder); |
| | | List<CodeBasicSec> codeBasicSecList = this.list(wrapper); |
| | | if(!CollectionUtils.isEmpty(codeBasicSecList)){ |
| | | List<CodeBasicSecVO> codeBasicSecVOS = codeBasicSecDO2VOs(codeBasicSecList); |
| | | //查询固定码的码值 |
| | | Map<String, List<CodeFixedValueVO>> secValueMap = fixedValueService.listCodeFixedValueBySecOids(codeBasicSecList.stream().map(CodeBasicSec::getOid).collect(Collectors.toList())); |
| | | codeBasicSecVOS.stream().forEach(vo->{ |
| | | vo.setFixedValueVOList(secValueMap.getOrDefault(vo.getOid(),null)); |
| | | }); |
| | | codeRuleVO.setSecVOList(codeBasicSecVOS); |
| | | } |
| | | }else{ |
| | | throw new VciBaseException(codeRuleVO.getName()+"编码规则下无流水码段,无法设置最大流水号!"); |
| | | } |
| | | } |
| | | return codeRuleVO; |
| | | } |
| | | |
| | | /** |
| | | * 设置最大流水号 |
| | | * |
| | | * @param codeOrderDTO 编码申请传输对象 |
| | | * @return |
| | | * @throws VciBaseException |
| | | */ |
| | | @Override |
| | | public String setMaxSerialNumberForCodeRule(CodeOrderDTO codeOrderDTO) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull(codeOrderDTO.getCodeRuleOid(),"编码规则主键",codeOrderDTO.getMaxSecNum(),"最大流水号"); |
| | | List<CodeOrderSecDTO> codeOrderSecDTOList = codeOrderDTO.getSecDTOList(); |
| | | if(CollectionUtils.isEmpty(codeOrderSecDTOList)){ |
| | | throw new VciBaseException("最大流水号的流水依赖不能为空!"); |
| | | } |
| | | |
| | | String codeRuleOid = codeOrderDTO.getCodeRuleOid(); |
| | | int maxSecNum = codeOrderDTO.getMaxSecNum(); |
| | | |
| | | Map<String/**码段主键*/,CodeOrderSecDTO/**码段相关信息*/> codeOrderSecDTOMap = codeOrderSecDTOList.stream().collect(Collectors.toMap(s -> s.getSecOid(), t -> t)); |
| | | List<String> codeBasicSecOidList = codeOrderSecDTOList.stream().map(s->s.getSecOid()).collect(Collectors.toList());//流水依赖码段的主键集合 |
| | | |
| | | //获取流水依赖码段 |
| | | LambdaQueryWrapper<CodeBasicSec> wrapper = Wrappers.<CodeBasicSec>query().lambda() |
| | | .eq(CodeBasicSec::getPkCodeRule,codeRuleOid) |
| | | .in(CodeBasicSec::getOid,codeBasicSecOidList) |
| | | .eq(CodeBasicSec::getSerialDependFlag,"true") |
| | | .orderByAsc(CodeBasicSec::getSerialDependOrder); |
| | | List<CodeBasicSec> codeBasicSecList = this.list(wrapper); |
| | | |
| | | //按流水依赖顺序,处理流水依赖码段的值 |
| | | List<String> serialDependValueList = new ArrayList<>(); |
| | | codeBasicSecList.stream().forEach(s->{ |
| | | CodeOrderSecDTO codeOrderSecDTO = codeOrderSecDTOMap.get(s.getOid()); |
| | | String serialDependValue = codeOrderSecDTO.getSecValue(); |
| | | if(s.getSecType().equals(CodeSecTypeEnum.CODE_DATE_SEC.getValue())){ |
| | | try { |
| | | Date date = VciDateUtil.str2Date(codeOrderSecDTO.getSecValue(),s.getCodeDateFormatStr()); |
| | | serialDependValue = VciDateUtil.date2Str(date,s.getCodeDateFormatStr()); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | serialDependValueList.add(serialDependValue); |
| | | }); |
| | | |
| | | //获取流水码段 |
| | | wrapper = Wrappers.<CodeBasicSec>query().lambda() |
| | | .eq(CodeBasicSec::getPkCodeRule,codeRuleOid) |
| | | .eq(CodeBasicSec::getSecType,CodeSecTypeEnum.CODE_SERIAL_SEC.getValue()) |
| | | .orderByAsc(CodeBasicSec::getSerialDependOrder); |
| | | CodeBasicSec codeBasicSec = this.getOne(wrapper); |
| | | |
| | | //根据编码规则和流水依赖,获取最大流水号 |
| | | String serialUnitString = serialDependValueList.size() == 0 ? EMPTY_SERIAL_UNIT : serialDependValueList.stream().collect(Collectors.joining(SERIAL_UNIT_SPACE)); |
| | | LambdaQueryWrapper<CodeSerialValue> codeSerialWrapper = new LambdaQueryWrapper<>(); |
| | | codeSerialWrapper.eq(CodeSerialValue::getCodeRuleOid, codeRuleOid); |
| | | codeSerialWrapper.eq(CodeSerialValue::getSerialUnit, serialUnitString); |
| | | codeSerialWrapper.eq(CodeSerialValue::getCodeSecOid,codeBasicSec.getOid()); |
| | | codeSerialWrapper.orderByDesc(CodeSerialValue::getCreateTime); |
| | | List<CodeSerialValue> codeSerialValueList = serialValueMapper.selectList(codeSerialWrapper); |
| | | |
| | | //如果最大流水号不为空,说明已有最好流水号,更新最大流水号 |
| | | if(!CollectionUtils.isEmpty(codeSerialValueList)){ |
| | | CodeSerialValue codeSerialValue = codeSerialValueList.get(0); |
| | | int maxSerial = Double.valueOf(codeSerialValue.getMaxSerial()).intValue(); |
| | | //已有的最大流水号,小于设置的最大流水号,更新最大流水号 |
| | | if(maxSerial < maxSecNum){ |
| | | codeSerialValue.setMaxSerial(String.valueOf(maxSecNum)); |
| | | serialValueMapper.updateById(codeSerialValue); |
| | | }else{ |
| | | maxSecNum = maxSerial; |
| | | } |
| | | }else{ |
| | | //如果最大流水号不为空,说明无最好流水号,新增最大流水号 |
| | | CodeSerialValue codeSerialValue = new CodeSerialValue(); |
| | | DefaultAttrAssimtUtil.addDefaultAttrAssimt(codeSerialValue, MdmBtmTypeConstant.CODE_SERIAL_VALUE); |
| | | codeSerialValue.setCodeRuleOid(codeRuleOid); |
| | | codeSerialValue.setSerialUnit(serialUnitString); |
| | | codeSerialValue.setCodeSecOid(codeBasicSec.getOid()); |
| | | codeSerialValue.setMaxSerial(String.valueOf(maxSecNum)); |
| | | serialValueMapper.insert(codeSerialValue); |
| | | } |
| | | return String.valueOf(maxSecNum); |
| | | } |
| | | |
| | | /*** |
| | | * 根据流水依赖获取最大流水号 |
| | | * @param codeOrderDTO 编码申请传输对象 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Double getMaxSerialNumberForCodeRule(CodeOrderDTO codeOrderDTO) { |
| | | Double maxSerialNumber=0.0; |
| | | VciBaseUtil.alertNotNull(codeOrderDTO.getCodeRuleOid(),"编码规则主键"); |
| | | List<CodeOrderSecDTO> codeOrderSecDTOList=codeOrderDTO.getSecDTOList(); |
| | | if(CollectionUtils.isEmpty(codeOrderSecDTOList)){ |
| | | throw new VciBaseException("最大流水号的流水依赖不能为空!"); |
| | | } |
| | | String codeRuleOid = codeOrderDTO.getCodeRuleOid(); |
| | | Map<String/**码段主键*/,CodeOrderSecDTO/**码段相关信息*/> codeOrderSecDTOMap = codeOrderSecDTOList.stream().collect(Collectors.toMap(s -> s.getSecOid(), t -> t)); |
| | | List<String> codeBasicSecOidList = codeOrderSecDTOList.stream().map(s->s.getSecOid()).collect(Collectors.toList());//流水依赖码段的主键集合 |
| | | //获取流水依赖码段 |
| | | LambdaQueryWrapper<CodeBasicSec> wrapper = Wrappers.<CodeBasicSec>query().lambda() |
| | | .eq(CodeBasicSec::getPkCodeRule,codeRuleOid) |
| | | .in(CodeBasicSec::getOid,codeBasicSecOidList) |
| | | .eq(CodeBasicSec::getSerialDependFlag,"true") |
| | | .orderByAsc(CodeBasicSec::getSerialDependOrder); |
| | | List<CodeBasicSec> codeBasicSecList = this.list(wrapper); |
| | | //按流水依赖顺序,处理流水依赖码段的值 |
| | | List<String> serialDependValueList = new ArrayList<>(); |
| | | codeBasicSecList.stream().forEach(s->{ |
| | | CodeOrderSecDTO codeOrderSecDTO = codeOrderSecDTOMap.get(s.getOid()); |
| | | String serialDependValue = codeOrderSecDTO.getSecValue(); |
| | | if(s.getSecType().equals(CodeSecTypeEnum.CODE_DATE_SEC.getValue())){ |
| | | try { |
| | | Date date = VciDateUtil.str2Date(codeOrderSecDTO.getSecValue(),s.getCodeDateFormatStr()); |
| | | serialDependValue = VciDateUtil.date2Str(date,s.getCodeDateFormatStr()); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | serialDependValueList.add(serialDependValue); |
| | | }); |
| | | |
| | | //获取流水码段 |
| | | wrapper = Wrappers.<CodeBasicSec>query().lambda() |
| | | .eq(CodeBasicSec::getPkCodeRule,codeRuleOid) |
| | | .eq(CodeBasicSec::getSecType,CodeSecTypeEnum.CODE_SERIAL_SEC.getValue()) |
| | | .orderByAsc(CodeBasicSec::getSerialDependOrder); |
| | | CodeBasicSec codeBasicSec = this.getOne(wrapper); |
| | | //根据编码规则和流水依赖,获取最大流水号 |
| | | String serialUnitString = serialDependValueList.size() == 0 ? EMPTY_SERIAL_UNIT : serialDependValueList.stream().collect(Collectors.joining(SERIAL_UNIT_SPACE)); |
| | | LambdaQueryWrapper<CodeSerialValue> codeSerialWrapper = new LambdaQueryWrapper<>(); |
| | | codeSerialWrapper.eq(CodeSerialValue::getCodeRuleOid, codeRuleOid); |
| | | codeSerialWrapper.eq(CodeSerialValue::getSerialUnit, serialUnitString); |
| | | codeSerialWrapper.eq(CodeSerialValue::getCodeSecOid,codeBasicSec.getOid()); |
| | | codeSerialWrapper.orderByDesc(CodeSerialValue::getCreateTime); |
| | | List<CodeSerialValue> codeSerialValueList = serialValueMapper.selectList(codeSerialWrapper); |
| | | if(!CollectionUtils.isEmpty(codeSerialValueList)){ |
| | | maxSerialNumber=StringUtils.isBlank(codeSerialValueList.get(0).getMaxSerial())?0:Double.parseDouble(codeSerialValueList.get(0).getMaxSerial()); |
| | | } |
| | | return maxSerialNumber; |
| | | } |
| | | } |