| | |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.StringPool; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.cache.Cache; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.PlatformTransactionManager; |
| | | 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.time.ZoneId; |
| | | import java.time.ZonedDateTime; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.DATA_OID_NOT_EXIST; |
| | |
| | | @Service |
| | | public class MdmEngineServiceImpl implements MdmEngineService { |
| | | |
| | | /** |
| | | * 单次sql的最多导入数量 |
| | | */ |
| | | @Value("${batchadd.single_maxnum:500}") |
| | | private Integer MAX_IMPORT_NUM; |
| | | |
| | | /** |
| | | * 模板的服务 |
| | | */ |
| | | @Resource |
| | | private CodeClstemplateServiceImpl templateService; |
| | | private ICodeClstemplateService templateService; |
| | | |
| | | /** |
| | | * 生成编码的服务 |
| | |
| | | */ |
| | | @Resource |
| | | IEnumClient enumClient; |
| | | /** |
| | | * 版本规则服务 |
| | | */ |
| | | @Resource |
| | | private IRevisionRuleClient revisionRuleClient; |
| | | |
| | | /** |
| | | * 公式的服务 |
| | |
| | | @Autowired |
| | | private FormulaServiceImpl formulaService; |
| | | |
| | | |
| | | /** |
| | | * 对omd中提供的feign接口进行调用,以及处理相关逻辑 |
| | | */ |
| | | @Autowired |
| | | ICodeReferBtmTypeService codeReferBtmTypeService; |
| | | |
| | | |
| | | /** |
| | | * 相似项查询规则 |
| | |
| | | */ |
| | | @Autowired |
| | | private IBtmTypeClient btmTypeClient; |
| | | /** |
| | | * 版本规则的服务 |
| | | */ |
| | | @Resource |
| | | private IRevisionRuleClient revisionRuleClient; |
| | | // |
| | | |
| | | /** |
| | | * 通用查询 |
| | | */ |
| | | @Resource |
| | | CommonsMapper commonsMapper; |
| | | private CommonsMapper commonsMapper; |
| | | |
| | | /** |
| | | * 编码规则的服务 |
| | |
| | | } |
| | | codeAllCodeService.updateBatchById(codeCbos); |
| | | } |
| | | |
| | | /** |
| | | * 申请单一编码 |
| | | * |
| | |
| | | */ |
| | | @Override |
| | | public String addSaveCode(CodeOrderDTO orderDTO) throws Exception { |
| | | return addSaveCode(orderDTO,true); |
| | | return addSaveCode(orderDTO,true); |
| | | } |
| | | |
| | | /*** |
| | |
| | | public String addSaveCodeNotauthUser(CodeOrderDTO orderDTO, boolean authUser) throws Exception { |
| | | return addSaveCode(orderDTO,authUser); |
| | | } |
| | | |
| | | /** |
| | | * 申请单一编码 |
| | | * |
| | |
| | | checkEnumOnOrder(templateVO, orderDTO); |
| | | //8.处理时间格式,在数据库里面不论是字符串还是日期格式,都使用相同的格式存储 |
| | | switchDateAttrOnOrder(templateVO, orderDTO); |
| | | //9.生成编码的信息 |
| | | // ClientBusinessObject cbo = boService.createCBOByBtmName(classifyFullInfo.getTopClassifyVO().getBtmtypeid()); |
| | | BaseModel cbo = createCBOByBtmName(classifyFullInfo.getTopClassifyVO().getBtmTypeId()); |
| | | // //默认的属性都不用从前端拷贝 |
| | | // //设置编码需要的默认属性的内容 |
| | | //9.生成编码的信息 ,初始化业务类型:缓存先取消,因为版本规则会出现变动的情况所以无法使用缓存 |
| | | // BaseModel cbo = createCBOByBtmName(classifyFullInfo.getTopClassifyVO().getBtmTypeId()); |
| | | BaseModel cbo = createBaseModel(classifyFullInfo.getTopClassifyVO().getBtmTypeId().trim().toLowerCase()); |
| | | //默认的属性都不用从前端拷贝 |
| | | //设置编码需要的默认属性的内容 |
| | | copyValueToCBO(classifyFullInfo, cbo, orderDTO, templateVO, false); |
| | | cbo.setOid(VciBaseUtil.getPk()); |
| | | cbo.setRevisionOid(VciBaseUtil.getPk()); |
| | |
| | | if(StringUtils.isNotBlank(orderDTO.getLcStatus())||StringUtils.isNotBlank(orderDTO.getData().get("lcStatus"))){ |
| | | cbo.setLcStatus(StringUtils.isNotBlank(orderDTO.getLcStatus())?orderDTO.getLcStatus():orderDTO.getData().get("lcStatus")); |
| | | } |
| | | // //TODO:因为默认的属性都不拷贝,目前集团码叫name,并没有从DTO拷贝到cbo里。增加一个单独处理,以后再看要不要调整 |
| | | //TODO:因为默认的属性都不拷贝,目前集团码叫name,并没有从DTO拷贝到cbo里。增加一个单独处理,以后再看要不要调整 |
| | | cbo.setName(orderDTO.getName() == null ? "" : orderDTO.getName()); |
| | | // //end -- modify by lihang @20220407 |
| | | //end -- modify by lihang @20220407 |
| | | List<BaseModel> cboList = new ArrayList<>(); |
| | | |
| | | //备注 |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 判断编码的码段是否输入或者选择了码值 |
| | |
| | | List<CodeClassifyTemplateAttrVO> selectAttrVOs = templateVO.getAttributes().stream().filter(s -> StringUtils.isNotBlank(s.getLibraryIdentification())).collect(Collectors.toList()); |
| | | |
| | | if (!CollectionUtils.isEmpty(selectAttrVOs)) { |
| | | // SessionInfo sessionInfo = VciBaseUtil.getCurrentUserSessionInfo(); |
| | | //SessionInfo sessionInfo = VciBaseUtil.getCurrentUserSessionInfo(); |
| | | selectAttrVOs.parallelStream().forEach(attrVO -> { |
| | | List<String> valuesList = new ArrayList<>(); |
| | | cboList.parallelStream().forEach(cbo -> { |
| | | // String value = cbo.get.getAttributeValue(attrVO.getId()); |
| | | //String value = cbo.get.getAttributeValue(attrVO.getId()); |
| | | |
| | | //将bean转为map,mybatis统一处理 |
| | | Map<String, String> map = null; |
| | | |
| | | // baseModels.stream().forEach(model-> { |
| | | //baseModels.stream().forEach(model-> { |
| | | try { |
| | | map = VciBaseUtil.convertBean2Map(cbo,null); |
| | | } catch (Exception e) { |
| | | throw new VciBaseException("类型转换错误:" + e.getMessage()); |
| | | } |
| | | // }); |
| | | //}); |
| | | |
| | | String value = map.get(attrVO.getId()); |
| | | if (StringUtils.isNotBlank(value)) { |
| | |
| | | conditionMap.put(queryKey, QueryOptionConstant.OR + queryValue); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询编码数据的列表 |
| | |
| | | wrapperData(dataList, templateVO, sqlBO.getSelectFieldList(), true); |
| | | R<List<Map<String, String>>> result = R.data(Collections.singletonList(cbo)); |
| | | //我们要看是否不是升版的,升版的话,需要对比不相等的属性 |
| | | String copy = cbo.get("copyfromversion"); |
| | | /* String copy = cbo.get("copyfromversion"); |
| | | // if (StringUtils.isBlank(copy)) { |
| | | // copy = cbo.getAttributeValue("copyfromversion"); |
| | | // } |
| | |
| | | Map<String, String> difFieldMap = new HashMap<>(); |
| | | Map<String, String> finalOldData = oldData; |
| | | cbo.forEach((key, value) -> { |
| | | String oldValue = finalOldData.getOrDefault(key, ""); |
| | | if (value == null) { |
| | | // 这儿oldmap中的全是大写,而cbo中的全是小写所以会拿不到只,这儿直接处理成小写拿不到就用大写拿 |
| | | String oldValue = String.valueOf(finalOldData.getOrDefault(key.toUpperCase(Locale.ROOT), finalOldData.getOrDefault(key, ""))); |
| | | if (value == null || value == "null") { |
| | | value = ""; |
| | | } |
| | | if (oldValue == null) { |
| | | if (oldValue == null || oldValue == "null") { |
| | | oldValue = ""; |
| | | } |
| | | if (!value.equalsIgnoreCase(oldValue)) { |
| | |
| | | difFieldList.add(difFieldMap); |
| | | result.setData(difFieldList); |
| | | } |
| | | } |
| | | }*/ |
| | | return result; |
| | | } |
| | | |
| | |
| | | return getTableDefineByTemplateVO(templateService.getObjectHasAttrByOid(templateOid)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 使用模板显示对象转换为表格的信息(包含扩展的按钮) |
| | | * |
| | |
| | | } |
| | | return uiInfoVO; |
| | | } |
| | | |
| | | @Override |
| | | public MdmUIInfoVO getFlowUIInfoByClassifyOid(String codeClassifyOid, String functionId,String templateId,String taskId,String modelKey){ |
| | | // MdmUIInfoVO uiInfoVO = getTableDefineByClassifyOid_v2(codeClassifyOid,templateId,taskId,modelKey); |
| | |
| | | * @return 处理成功数据条数 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Integer insertBatchByType(String btmType, List<BaseModel> baseModels) { |
| | | //使用传入的业务类型查询表 |
| | | R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(btmType)); |
| | |
| | | }).collect(Collectors.toSet()); |
| | | //将bean转为map,mybatis统一处理 |
| | | List<Map<String, String>> maps = new ArrayList<>(); |
| | | |
| | | baseModels.stream().forEach(model -> { |
| | | try { |
| | | maps.add(VciBaseUtil.convertBean2Map(model,existFild)); |
| | |
| | | throw new VciBaseException("类型转换错误:" + e.toString()); |
| | | } |
| | | }); |
| | | return commonsMapper.insertByBaseModel(listR.getData().get(0).getTableName(), maps.get(0), maps); |
| | | try { |
| | | bactchExecuteInsert(listR.getData().get(0).getTableName(),maps); |
| | | }catch (Exception e){ |
| | | throw new ServiceException("分批执行insert语句报错:"+e.getMessage()); |
| | | } |
| | | return maps.size(); |
| | | } |
| | | |
| | | /** |
| | | * 分批执行insert语句 |
| | | * @param tableName |
| | | * @param maps |
| | | * @throws ServiceException |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | void bactchExecuteInsert(String tableName, List<Map<String, String>> maps) throws ServiceException{ |
| | | ExecutorService executor = Executors.newFixedThreadPool(10); // 创建一个固定大小的线程池 |
| | | List<Map<String, String>> threadSafeMaps = new CopyOnWriteArrayList<>(maps); |
| | | |
| | | for (int i = 0; i < threadSafeMaps.size(); i += MAX_IMPORT_NUM) { |
| | | final int startIndex = i; |
| | | final int endIndex = Math.min(i + MAX_IMPORT_NUM, maps.size()); |
| | | |
| | | executor.execute(() -> { |
| | | List<Map<String, String>> subList = threadSafeMaps.subList(startIndex, endIndex); |
| | | // 调用插入数据库的方法 |
| | | commonsMapper.insertByBaseModel(tableName, threadSafeMaps.get(0), subList); |
| | | }); |
| | | } |
| | | |
| | | // 关闭线程池 |
| | | executor.shutdown(); |
| | | try { |
| | | // 等待所有任务执行完成 |
| | | executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); |
| | | } catch (InterruptedException e) { |
| | | // 处理异常 |
| | | throw new ServiceException("多线程方式执行批量插入时产生错误:"+e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 传入业务类型以及ID查询业务表数据是否重复 |
| | | * |
| | |
| | | toBo.setNameOid(fromBo.getNameOid()); |
| | | toBo.setBtmname(fromBo.getBtmname()); |
| | | toBo.setLastR(String.valueOf(1)); |
| | | // 升版将FirstR修改为0 |
| | | toBo.setFirstR(String.valueOf(0)); |
| | | toBo.setFirstV(String.valueOf(1)); |
| | | toBo.setLastV(String.valueOf(1)); |
| | |
| | | toBo.setLastModifier(String.valueOf(AuthUtil.getUser().getAccount())); |
| | | toBo.setLastModifyTime(new Date()); |
| | | toBo.setRevisionRule(fromBo.getRevisionRule()); |
| | | toBo.setVersionRule(fromBo.getVersionRule());R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(fromBo.getBtmname())); |
| | | toBo.setVersionRule(fromBo.getVersionRule()); |
| | | //查询业务类型信息,可以获取到版本规则信息(revisionRuleId) |
| | | R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(fromBo.getBtmname())); |
| | | if (!listR.isSuccess() || listR.getData().size() == 0) { |
| | | throw new VciBaseException("传入业务类型未查询到相应表单,请检查!"); |
| | | } |
| | | Map<String, Object> nextRevision = commonsMapper.getNextRevision(listR.getData().get(0).getTableName(), fromBo.getNameOid()); |
| | | toBo.setRevisionSeq(Integer.parseInt(nextRevision.get("REVISIONSEQ").toString())); |
| | | toBo.setRevisionValue(nextRevision.get("REVISIONVAL").toString()); |
| | | //Map<String, Object> nextRevision = commonsMapper.getNextRevision(listR.getData().get(0).getTableName(), fromBo.getNameOid()); |
| | | /* |
| | | TODO:这是一个待后期完善的功能,目前实现方式是,先查询出当前数据的大版本规则, |
| | | 然后再查询业务表使用的规则的步长是多少然后计算出该升版为多少 |
| | | */ |
| | | Map<String, Object> nextRevision = commonsMapper.getCurrentRevision(listR.getData().get(0).getTableName(), fromBo.getNameOid()); |
| | | R<RevisionRuleVO> revisionRuleVOR = revisionRuleClient.selectById(listR.getData().get(0).getRevisionRuleId()); |
| | | String revisionval = nextRevision.get("REVISIONVAL").toString(); |
| | | // 未查询到版本规则,默认直接给大版本加一 |
| | | if(!revisionRuleVOR.isSuccess() || Func.isEmpty(revisionRuleVOR.getData())){ |
| | | revisionval = String.valueOf((Integer.parseInt(revisionval)+1)); |
| | | }else { |
| | | revisionval = String.valueOf(Integer.parseInt(revisionval)+revisionRuleVOR.getData().getSerialStep()); |
| | | } |
| | | toBo.setRevisionValue(revisionval); |
| | | toBo.setRevisionSeq(Integer.parseInt(nextRevision.get("REVISIONSEQ").toString())); |
| | | toBo.setVersionSeq(Integer.valueOf(nextRevision.get("VERSIONSEQ").toString())); |
| | | toBo.setVersionValue(nextRevision.get("VERSIONVAL").toString()); |
| | | toBo.setLctid(fromBo.getLctid()); |