| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.vci.ubcs.omd.cache.EnumCache; |
| | | import com.vci.ubcs.omd.constant.BtmTypeConstant; |
| | | import com.vci.ubcs.omd.constant.BtmTypeFieldConstant; |
| | | import com.vci.ubcs.omd.dto.BtmAndLinkTypeDdlDTO; |
| | | import com.vci.ubcs.omd.entity.Attribute; |
| | | import com.vci.ubcs.omd.entity.*; |
| | | import com.vci.ubcs.omd.enums.EnumEnum; |
| | | import com.vci.ubcs.omd.repeater.DomainRepeater; |
| | | import com.vci.ubcs.omd.service.*; |
| | | import com.vci.ubcs.omd.vo.*; |
| | |
| | | import com.vci.ubcs.starter.web.constant.OmdRegExpConstant; |
| | | import com.vci.ubcs.omd.dto.BtmTypeDTO; |
| | | import com.vci.ubcs.omd.dto.BtmTypeLinkAttributesDTO; |
| | | import com.vci.ubcs.omd.entity.BtmType; |
| | | import com.vci.ubcs.omd.entity.BtmTypeAttribute; |
| | | import com.vci.ubcs.omd.entity.ModifyAttributeInfo; |
| | | import com.vci.ubcs.omd.mapper.BtmTypeMapper; |
| | | import com.vci.ubcs.starter.exception.VciBaseException; |
| | | import com.vci.ubcs.starter.web.enumpck.BooleanEnum; |
| | |
| | | */ |
| | | @Autowired |
| | | private IAttributeService attributeService; |
| | | |
| | | /** |
| | | * 生命周期的服务 |
| | | */ |
| | | @Autowired |
| | | private ILifeCycleService lifeCycleService; |
| | | |
| | | /** |
| | | * 表名前缀 |
| | |
| | | */ |
| | | @Override |
| | | public List<BtmType> listBtmTypeDOByIdCollection(Collection<String> idCollection) throws ServiceException { |
| | | return CollectionUtils.isEmpty(idCollection) ? null : baseMapper.selectList(Wrappers.<BtmType>query().lambda().in(BtmType::getId, idCollection)); |
| | | return CollectionUtils.isEmpty(idCollection) ? null : baseMapper.selectByIdCollection(idCollection); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws ServiceException 参数为空的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public String getTableName(String id,String domain) throws ServiceException { |
| | | public String getTableName(String id,String domain) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull(id,"业务类型英文名称",domain,"领域名称"); |
| | | if (domain.contains("ubcs-")){ |
| | | domain = domain.split("ubcs-")[1]; |
| | |
| | | * @return 执行结果 |
| | | */ |
| | | @Override |
| | | public R submit(BtmTypeDTO btmTypeDTO, boolean autoCreateTable) { |
| | | TransactionStatus transaction = null; |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R submit(BtmTypeDTO btmTypeDTO, boolean autoCreateTable) throws ServiceException { |
| | | /*TransactionStatus transaction = null; |
| | | DefaultTransactionDefinition def = null; |
| | | if (autoCreateTable) { |
| | | def = new DefaultTransactionDefinition(); |
| | |
| | | // 事物隔离级别,开启新事务,这样会比较安全些。 |
| | | transaction = dataSourceTransactionManager.getTransaction(def); |
| | | // 获得事务状态 |
| | | } |
| | | checkBtmTypeBeforeSave(btmTypeDTO); |
| | | }*/ |
| | | //checkBtmTypeBeforeSave(btmTypeDTO); |
| | | BtmType btmTypeDO = Optional.ofNullable(BeanUtil.copy(btmTypeDTO, BtmType.class)).orElseGet(BtmType::new); |
| | | btmTypeDO.setBizDomain(btmTypeDTO.getDomain()); |
| | | btmTypeDO.setBizDomain(btmTypeDTO.getBizDomain()); |
| | | List<BtmTypeLinkAttributesDTO> attributes = btmTypeDTO.getAttributes(); |
| | | List<BtmTypeAttributeVO> afterAttributes; |
| | | if (StringUtils.isBlank(btmTypeDO.getOid())){ |
| | |
| | | List<BtmTypeAttributeVO> beforeAttributes = btmTypeByOid.getAttributes(); |
| | | // 处理属性,多余的删除,不存在的添加 |
| | | afterAttributes = updateAttributeForBtm(btmTypeByOid.getOid(),beforeAttributes, attributes); |
| | | baseMapper.updateByPrimaryKey(btmTypeDO); |
| | | } |
| | | BtmTypeVO btmTypeVO = BtmTypeWrapper.build().entityVO(btmTypeDO); |
| | | //在创建表的时候还需要把默认的字段带上。 |
| | |
| | | btmTypeVO.setAttributes(afterAttributes); |
| | | try { |
| | | if (autoCreateTable) { |
| | | // checkTableSame(btmTypeVO); |
| | | R result = DomainRepeater.submitBtmType(btmTypeDTO.getDomain(), btmTypeVO); |
| | | // checkTableSame(btmTypeVO); |
| | | R result = DomainRepeater.submitBtmType(btmTypeDTO.getBizDomain(), btmTypeVO); |
| | | if (result.isSuccess()){ |
| | | List<ModifyAttributeInfo> infoList = new ArrayList<>(); |
| | | Object data = result.getData(); |
| | |
| | | }); |
| | | modifyAttributeService.saveBatch(ModifyAttributeWrapper.build().listEntityBeforeSave(infoList)); |
| | | } |
| | | dataSourceTransactionManager.commit(transaction); |
| | | // dataSourceTransactionManager.commit(transaction); |
| | | }else { |
| | | dataSourceTransactionManager.rollback(transaction); |
| | | return R.fail(result.getMsg()); |
| | | // dataSourceTransactionManager.rollback(transaction); |
| | | // 创建表报错,抛出异常让该方法回滚 |
| | | throw new VciBaseException(result.getMsg()); |
| | | // return R.fail(result.getMsg()); |
| | | } |
| | | } |
| | | } catch (Throwable e) { |
| | | if (autoCreateTable) { |
| | | dataSourceTransactionManager.rollback(transaction); |
| | | // dataSourceTransactionManager.rollback(transaction); |
| | | throw new VciBaseException(e.getMessage()); |
| | | } |
| | | } |
| | |
| | | List<BtmTypeAttributeVO> voListAdd = btmTypeAttributeService.checkAndInsert(oid, addList, AuthUtil.getUserAccount(), new Date()); |
| | | List<BtmTypeAttributeVO> voListUpdate = btmTypeAttributeService.checkAndUpdate(oid, modifyList, AuthUtil.getUserAccount(), new Date()); |
| | | List<BtmTypeAttributeVO> returnList = new ArrayList<>(); |
| | | returnList.addAll(Objects.requireNonNull(voListAdd)); |
| | | returnList.addAll(Objects.requireNonNull(voListUpdate)); |
| | | if(!CollectionUtils.isEmpty(voListAdd)) { |
| | | returnList.addAll(Objects.requireNonNull(voListAdd)); |
| | | } |
| | | if(!CollectionUtils.isEmpty(voListUpdate)) { |
| | | returnList.addAll(Objects.requireNonNull(voListUpdate)); |
| | | } |
| | | return returnList; |
| | | } |
| | | |
| | |
| | | if (btmTypeDTO.getId().length() > 24) { |
| | | throw new VciBaseException("业务类型英文名称不能超过18,目前长度为{0}", new Object[]{btmTypeDTO.getId().length()}); |
| | | } |
| | | List<BtmType> btmTypeDOList = listBtmTypeDOByIdCollection(VciBaseUtil.str2List(btmTypeDTO.getId())); |
| | | List<BtmType> btmTypeDOList = listBtmTypeDOByIdCollection(VciBaseUtil.str2List(btmTypeDTO.getId().toLowerCase(Locale.ROOT))); |
| | | if (!CollectionUtils.isEmpty(btmTypeDOList) && btmTypeDOList.size() > 0) { |
| | | boolean exist = btmTypeDOList.stream().filter(btm -> StringUtils.isNotBlank(btm.getOid())).anyMatch(btm -> !StringUtils.equals(btmTypeDTO.getOid(), btm.getOid())); |
| | | BtmType existBtmType = btmTypeDOList.get(0); |
| | | throw new VciBaseException("业务类型英文名称已经存在(不区分大小写),这个英文名称对应的中文名称为{0},创建人{1},创建时间{2}" |
| | | , new Object[]{existBtmType.getName(), existBtmType.getCreator(), VciDateUtil.date2Str(existBtmType.getCreateTime(), VciDateUtil.DateFormat)}); |
| | | if (exist) { |
| | | throw new VciBaseException("业务类型英文名称已经存在(不区分大小写),这个英文名称对应的中文名称为{0},创建人{1},创建时间{2}" |
| | | , new Object[]{existBtmType.getName(), existBtmType.getCreator(), VciDateUtil.date2Str(existBtmType.getCreateTime(), VciDateUtil.DateFormat)}); |
| | | } |
| | | } |
| | | if (btmTypeDTO.isRevisionFlag()){ |
| | | // 需要控制版本 |
| | |
| | | if (btmTypeDTO.isLifeCycleFlag()){ |
| | | // 需要控制生命周期 |
| | | //检查使用的生命周期是否存在 |
| | | // if (StringUtils.isNotBlank(btmTypeDTO.getLifeCycleId()) |
| | | // && !FrameWorkLcStatusConstant.EMTYPE_LIFE_CYCLE.equalsIgnoreCase(btmTypeDTO.getLifeCycleId())) { |
| | | // if (lifeCycleServiceI.checkLifeCycleExist(btmTypeDTO.getLifeCycleId())) { |
| | | // throw new VciBaseException("生命周期{0}[{1}]在系统中不存在,请先查证", |
| | | // new Object[]{btmTypeDTO.getLifeCycleId(), btmTypeDTO.getLifeCycleName()}); |
| | | // } |
| | | // } |
| | | if (StringUtils.isNotBlank(btmTypeDTO.getLifeCycleId()) |
| | | // && !FrameWorkLcStatusConstant.EMTYPE_LIFE_CYCLE.equalsIgnoreCase(btmTypeDTO.getLifeCycleId()) |
| | | ) { |
| | | if (lifeCycleService.getOne(Wrappers.<LifeCycleRule>query().lambda().eq(LifeCycleRule::getId,btmTypeDTO.getLifeCycleId())) == null) { |
| | | throw new VciBaseException("生命周期{0}[{1}]在系统中不存在,请先查证", |
| | | new Object[]{btmTypeDTO.getLifeCycleId(), btmTypeDTO.getLifeCycleName()}); |
| | | } |
| | | } |
| | | // if (StringUtils.isNotBlank(btmTypeDTO.getSubLifeCycleId())) { |
| | | // if (lifeCycleServiceI.checkLifeCycleExist(btmTypeDTO.getSubLifeCycleId())) { |
| | | // throw new VciBaseException("备用生命周期{0}[{1}]中其中有某些在系统中不存在,请先查证", |
| | |
| | | try { |
| | | Map<String, String> domain = Optional.ofNullable(DomainRepeater.getDomain()).orElseGet(ArrayList::new).stream().collect(Collectors.toMap(DomainVO::getValue, DomainVO::getLabel)); |
| | | List<BtmTypeVO> vos = BtmTypeWrapper.build().listEntityVO(baseMapper.selectAll()); |
| | | Map<String, List<BtmTypeVO>> domainMap = vos.stream().sorted(Comparator.comparing(BtmTypeVO::getId)).collect(Collectors.groupingBy(BtmTypeVO::getBizDomain)); |
| | | if (CollectionUtils.isEmpty(vos)){ |
| | | return new ArrayList<>(); |
| | | } |
| | | Map<String, List<BtmTypeVO>> domainMap = Optional.ofNullable(vos).orElseGet(ArrayList::new).stream().sorted(Comparator.comparing(BtmTypeVO::getId)).collect(Collectors.groupingBy(BtmTypeVO::getBizDomain)); |
| | | List<BtmTreeVO> treeList = new ArrayList<>(); |
| | | domainMap.forEach((k,v)-> { |
| | | if (domain.containsKey(k)){ |
| | |
| | | parent.setName(label); |
| | | parent.setLabel(label); |
| | | parent.setId(k); |
| | | parent.setLevel(1); |
| | | parent.setChildList(v.stream().map(s -> { |
| | | BtmTreeVO child = new BtmTreeVO(); |
| | | child.setOid(s.getOid()); |
| | | child.setName(s.getName()); |
| | | child.setId(s.getId()); |
| | | child.setLevel(2); |
| | | child.setLabel(s.getId() + (s.getName() == null ? "" : "(" + s.getName() + ")")); |
| | | return child; |
| | | }).collect(Collectors.toList())); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取引用某些生命周期的业务类型 |
| | | * |
| | | * @param lifeIds 生命周期的编号集合 |
| | | * @return 业务类型显示对象 |
| | | */ |
| | | @Override |
| | | public List<BtmTypeVO> selectByLifeIds(Collection<String> lifeIds) { |
| | | if(CollectionUtils.isEmpty(lifeIds)){ |
| | | return new ArrayList<>(); |
| | | } |
| | | List<BtmType> btmTypeList = new ArrayList<>(); |
| | | VciBaseUtil.switchCollectionForOracleIn(lifeIds).stream().forEach(ids->{ |
| | | LambdaQueryWrapper<BtmType> query = new LambdaQueryWrapper<BtmType>(); |
| | | ids.stream().forEach(id->{ |
| | | query.eq(BtmType::getLifeCycleId,id); |
| | | query.or(); |
| | | }); |
| | | query.eq(BtmType::getLifeCycleId,"-1"); |
| | | btmTypeList.addAll(baseMapper.selectList(query)); |
| | | }); |
| | | return BtmTypeWrapper.build().listEntityVO(btmTypeList); |
| | | } |
| | | |
| | | /** |
| | | * 统计引用某个生命周期的业务类型 |
| | | * |
| | | * @param lifeId 生命周期的编号 |
| | |
| | | query.eq(BtmType::getLifeCycleId,lifeId); |
| | | return baseMapper.selectCount(query).intValue(); |
| | | } |
| | | |
| | | /** |
| | | * 统计引用某些生命周期的业务类型 |
| | | * |
| | | * @param lifeIds 生命周期的编号集合 |
| | | * @return 个数 |
| | | */ |
| | | @Override |
| | | public Integer countByLifeIds(Collection<String> lifeIds) { |
| | | if(CollectionUtils.isEmpty(lifeIds)){ |
| | | return 0; |
| | | } |
| | | final Integer[] total = {0}; |
| | | VciBaseUtil.switchCollectionForOracleIn(lifeIds).stream().forEach(ids->{ |
| | | LambdaQueryWrapper<BtmType> query = new LambdaQueryWrapper<BtmType>(); |
| | | ids.stream().forEach(id->{ |
| | | query.eq(BtmType::getLifeCycleId,id); |
| | | query.or(); |
| | | }); |
| | | query.eq(BtmType::getLifeCycleId,"-1"); |
| | | total[0] += baseMapper.selectCount(query).intValue(); |
| | | }); |
| | | return total[0]; |
| | | } |
| | | |
| | | /** |
| | | * 获取默认属性 |
| | | * @param defaultAttrType |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<BtmTypeAttributeVO> getDefaultAttr(String defaultAttrType) { |
| | | List<BtmTypeAttributeVO> list = new ArrayList<>(); |
| | | // 业务类型的默认基本字段 |
| | | if(defaultAttrType.equals("defaultAttr")){ |
| | | BtmTypeFieldConstant.BASIC_FIELD_MAP.forEach((id,name) -> { |
| | | id = id.toLowerCase(Locale.ROOT); |
| | | BtmTypeAttributeVO vo = new BtmTypeAttributeVO(); |
| | | vo.setId(id); |
| | | vo.setName(name); |
| | | vo.setIsDefaultAttr(true); |
| | | if ("oid".equals(id)){ |
| | | vo.setNullableFlag(false); |
| | | } |
| | | if (Arrays.asList("createtime","lastmodifytime","ts").contains(id)){ |
| | | vo.setAttrDataType(VciFieldTypeEnum.VTDateTime.name()); |
| | | vo.setAttributeLength(6); |
| | | }else { |
| | | vo.setAttrDataType(VciFieldTypeEnum.VTString.name()); |
| | | vo.setAttributeLength(150); |
| | | } |
| | | list.add(vo); |
| | | }); |
| | | |
| | | BtmTypeFieldConstant.MASTERDATA_FIELD_MAP.forEach((id,name) -> { |
| | | id = id.toLowerCase(Locale.ROOT); |
| | | BtmTypeAttributeVO vo = new BtmTypeAttributeVO(); |
| | | vo.setId(id); |
| | | vo.setName(name); |
| | | vo.setIsDefaultAttr(false); |
| | | if (Arrays.asList("codeclsfpath").contains(id)){ |
| | | vo.setAttrDataType(VciFieldTypeEnum.VTString.name()); |
| | | vo.setAttributeLength(500); |
| | | }else { |
| | | vo.setAttrDataType(VciFieldTypeEnum.VTString.name()); |
| | | vo.setAttributeLength(255); |
| | | } |
| | | list.add(vo); |
| | | }); |
| | | } |
| | | |
| | | // 版本规则字段 |
| | | if (defaultAttrType.equals("reVersionRule")){ |
| | | BtmTypeFieldConstant.REVISION_MANAGE_FIELD_MAP.forEach((id,name) -> { |
| | | BtmTypeAttributeVO vo = new BtmTypeAttributeVO(); |
| | | vo.setId(id); |
| | | vo.setName(name); |
| | | vo.setAttrDataType(VciFieldTypeEnum.VTString.name()); |
| | | // 版本规则字段不能为空 |
| | | // vo.setNullableFlag(false); |
| | | vo.setAttributeLength(150); |
| | | vo.setIsDefaultAttr(true); |
| | | if (Arrays.asList("revisionseq","versionseq").contains(id)){ |
| | | vo.setAttributeLength(5); |
| | | vo.setAttrDataType(VciFieldTypeEnum.VTInteger.name()); |
| | | } |
| | | if (Arrays.asList("checkintime","checkouttime").contains(id)){ |
| | | vo.setAttrDataType(VciFieldTypeEnum.VTDateTime.name()); |
| | | vo.setAttributeLength(6); |
| | | } |
| | | list.add(vo); |
| | | }); |
| | | } |
| | | |
| | | // 生命周期字段 |
| | | if (defaultAttrType.equals("lifeCycle")){ |
| | | BtmTypeFieldConstant.LIFECYCLE_MANAGE_FIELD_MAP.forEach((id,name) -> { |
| | | BtmTypeAttributeVO vo = new BtmTypeAttributeVO(); |
| | | vo.setId(id); |
| | | vo.setName(name); |
| | | // vo.setNullableFlag(false); |
| | | vo.setIsDefaultAttr(true); |
| | | vo.setAttributeLength(50); |
| | | vo.setAttrDataType(VciFieldTypeEnum.VTString.name()); |
| | | list.add(vo); |
| | | }); |
| | | } |
| | | |
| | | // 设置字段类型中文显示值,和排序 |
| | | List<BtmTypeAttributeVO> sortedList = list.stream() |
| | | .sorted(Comparator.comparing(BtmTypeAttributeVO::getIsDefaultAttr)) |
| | | .map(item-> { |
| | | item.setAttrDataTypeText(EnumCache.getValue(EnumEnum.VCI_FIELD_TYPE, item.getAttrDataType())); |
| | | return item; |
| | | }).collect(Collectors.toList()); |
| | | return sortedList; |
| | | } |
| | | |
| | | } |