From 8e832c69b20bd34f6da9ef25324ec690d1cccbe3 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期二, 30 一月 2024 11:30:32 +0800 Subject: [PATCH] 业务类型对象,分类授权,字符集相关代码修改 --- Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java | 408 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 335 insertions(+), 73 deletions(-) diff --git a/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java index 70559e2..bb016e6 100644 --- a/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java +++ b/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java @@ -4,29 +4,24 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.api.exception.NacosException; +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.IAttributeService; -import com.vci.ubcs.omd.service.IBtmTypeAttributeService; -import com.vci.ubcs.omd.service.IModifyAttributeService; -import com.vci.ubcs.omd.vo.BtmTypeTreeVO; +import com.vci.ubcs.omd.service.*; +import com.vci.ubcs.omd.vo.*; import com.vci.ubcs.omd.wrapper.BtmTypeWrapper; import com.vci.ubcs.omd.wrapper.ModifyAttributeWrapper; 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.omd.service.IBtmTypeService; -import com.vci.ubcs.omd.vo.BtmTypeVO; -import com.vci.ubcs.omd.vo.BtmTypeAttributeVO; -import com.vci.ubcs.omd.vo.LinkTypeVO; import com.vci.ubcs.starter.exception.VciBaseException; import com.vci.ubcs.starter.web.enumpck.BooleanEnum; import com.vci.ubcs.starter.web.enumpck.VciFieldTypeEnum; @@ -79,15 +74,27 @@ private IModifyAttributeService modifyAttributeService; /** + * 鐗堟湰瑙勫垯鐨勬湇鍔� + */ + @Autowired + private IRevisionRuleService revisionRuleService; + + /** * 灞炴�х殑鏈嶅姟 */ @Autowired private IAttributeService attributeService; /** + * 鐢熷懡鍛ㄦ湡鐨勬湇鍔� + */ + @Autowired + private ILifeCycleService lifeCycleService; + + /** * 琛ㄥ悕鍓嶇紑 */ - public static final String PL = "PL"; + public static final String PL = "PLBT"; /** * 璁剧疆骞冲彴鏈韩鐨勪笟鍔$被鍨� @@ -109,7 +116,11 @@ @Override public BtmTypeVO getBtmTypeByOid(String pkBtmType) throws ServiceException { Func.requireNotNull(pkBtmType,"涓氬姟绫诲瀷涓婚敭涓嶈兘涓虹┖"); - BtmTypeVO btmTypeVO = BtmTypeWrapper.build().entityVO(baseMapper.selectOne(Wrappers.<BtmType>query().lambda().eq(BtmType::getOid, pkBtmType))); + BtmType queryBtmType = baseMapper.selectOne(Wrappers.<BtmType>query().lambda().eq(BtmType::getOid, pkBtmType)); + if (queryBtmType == null){ + return null; + } + BtmTypeVO btmTypeVO = BtmTypeWrapper.build().entityVO(queryBtmType); btmTypeVO.setAttributes(btmTypeAttributeService.getAttributeByBtmTypeOid(pkBtmType)); return btmTypeVO; } @@ -198,7 +209,7 @@ */ @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); } /** @@ -359,6 +370,7 @@ if (!existFieldMap.containsKey(k)){ BtmTypeLinkAttributesDTO attr = new BtmTypeLinkAttributesDTO(); attr.setId(k); + attr.setName(v); attr.setAttrDataType(VciFieldTypeEnum.VTString.name()); attr.setAttributeLength(50); attr.setNullableFlag(false); @@ -381,7 +393,7 @@ ddlDTO.setBtmTypeList(btmTypeVOList); try { // 灏嗕互鍓嶇殑checkDifferent鍜宺eflexDifferent缁撳悎浜� - R result = DomainRepeater.checkDifferent(ddlDTO,btmTypeVO.getDomain()); + R result = DomainRepeater.checkDifferent(ddlDTO,btmTypeVO.getBizDomain()); if (result.isSuccess()){ List<ModifyAttributeInfo> infoList = new ArrayList<>(); Object data = result.getData(); @@ -459,7 +471,7 @@ * @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]; @@ -476,8 +488,9 @@ * @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(); @@ -485,17 +498,19 @@ // 浜嬬墿闅旂绾у埆锛屽紑鍚柊浜嬪姟锛岃繖鏍蜂細姣旇緝瀹夊叏浜涖�� transaction = dataSourceTransactionManager.getTransaction(def); // 鑾峰緱浜嬪姟鐘舵�� - } - checkBtmTypeBeforeSave(btmTypeDTO); + }*/ + //checkBtmTypeBeforeSave(btmTypeDTO); BtmType btmTypeDO = Optional.ofNullable(BeanUtil.copy(btmTypeDTO, BtmType.class)).orElseGet(BtmType::new); + btmTypeDO.setBizDomain(btmTypeDTO.getBizDomain()); List<BtmTypeLinkAttributesDTO> attributes = btmTypeDTO.getAttributes(); List<BtmTypeAttributeVO> afterAttributes; if (StringUtils.isBlank(btmTypeDO.getOid())){ btmTypeDO = BtmTypeWrapper.build().entityBeforeInsert(btmTypeDO); if (StringUtils.isBlank(btmTypeDO.getTableName())) { - btmTypeDO.setTableName(getTableName(btmTypeDO.getId(),btmTypeDO.getDomain())); + btmTypeDO.setTableName(getTableName(btmTypeDO.getId(),btmTypeDO.getBizDomain())); } // 娣诲姞灞炴�� + btmTypeDTO.setOid(btmTypeDO.getOid()); afterAttributes = addAttributeForBtm(btmTypeDTO); baseMapper.insert(btmTypeDO); }else { @@ -503,13 +518,17 @@ List<BtmTypeAttributeVO> beforeAttributes = btmTypeByOid.getAttributes(); // 澶勭悊灞炴�э紝澶氫綑鐨勫垹闄わ紝涓嶅瓨鍦ㄧ殑娣诲姞 afterAttributes = updateAttributeForBtm(btmTypeByOid.getOid(),beforeAttributes, attributes); + baseMapper.updateByPrimaryKey(btmTypeDO); } BtmTypeVO btmTypeVO = BtmTypeWrapper.build().entityVO(btmTypeDO); + //鍦ㄥ垱寤鸿〃鐨勬椂鍊欒繕闇�瑕佹妸榛樿鐨勫瓧娈靛甫涓娿�� + List<BtmTypeAttributeVO> defaultAttribute = btmTypeAttributeService.getDefaultAttribute(btmTypeVO); + afterAttributes.addAll(defaultAttribute); 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(); @@ -523,14 +542,18 @@ }); modifyAttributeService.saveBatch(ModifyAttributeWrapper.build().listEntityBeforeSave(infoList)); } - dataSourceTransactionManager.commit(transaction); + // dataSourceTransactionManager.commit(transaction); }else { - dataSourceTransactionManager.rollback(transaction); + // 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()); } } return R.data(btmTypeVO); @@ -557,8 +580,12 @@ 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; } @@ -581,47 +608,45 @@ 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 (StringUtils.isNotBlank(btmTypeDTO.getRevisionRuleId())) { -// if (revisionRuleServiceI.checkRevisionRuleExist(btmTypeDTO.getRevisionRuleId())) { -// throw new VciBaseException("鐗堟湰瑙勫垯{0}[{1}]鍦ㄧ郴缁熶腑涓嶅瓨鍦紝璇峰厛鏌ヨ瘉", -// new Object[]{btmTypeDTO.getRevisionRuleId(), btmTypeDTO.getRevisionRuleName()}); -// } -// } - btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.REVISION_MANAGE_FIELD_MAP)); + if (StringUtils.isNotBlank(btmTypeDTO.getRevisionRuleId())) { + if (!revisionRuleService.checkRevisionRuleExist(btmTypeDTO.getRevisionRuleId())) { + throw new VciBaseException("鐗堟湰瑙勫垯{0}[{1}]鍦ㄧ郴缁熶腑涓嶅瓨鍦紝璇峰厛鏌ヨ瘉", + new Object[]{btmTypeDTO.getRevisionRuleId(), btmTypeDTO.getRevisionRuleName()}); + } + } } 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}]涓叾涓湁鏌愪簺鍦ㄧ郴缁熶腑涓嶅瓨鍦紝璇峰厛鏌ヨ瘉", // new Object[]{btmTypeDTO.getSubLifeCycleId(), btmTypeDTO.getSubLifeCycleName()}); // } // } - btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.LIFECYCLE_MANAGE_FIELD_MAP)); } if (btmTypeDTO.isSecretFlag()){ // 闇�瑕佹帶鍒跺瘑绾� - btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.SECRET_MANAGE_FIELD_MAP)); - } - if (StringUtils.isBlank(btmTypeDTO.getOid())) { - btmTypeDTO.setOid(VciBaseUtil.getPk()); } } @Override @@ -640,20 +665,30 @@ * @return 鏌ヨ缁撴灉 */ @Override - public List<BtmTypeTreeVO> treeDomain() { + public List<BtmTreeVO> treeDomain() { try { - List<String> domain = DomainRepeater.getDomain(); + 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().collect(Collectors.groupingBy(BtmTypeVO::getDomain)); - List<BtmTypeTreeVO> treeList = new ArrayList<>(); + 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.contains(k)){ - BtmTypeTreeVO parent = new BtmTypeTreeVO(); - parent.setName(k); + if (domain.containsKey(k)){ + String label = domain.get(k); + BtmTreeVO parent = new BtmTreeVO(); + parent.setName(label); + parent.setLabel(label); + parent.setId(k); + parent.setLevel(1); parent.setChildList(v.stream().map(s -> { - BtmTypeTreeVO child = new BtmTypeTreeVO(); + BtmTreeVO child = new BtmTreeVO(); child.setOid(s.getOid()); - child.setName(s.getId() + " " + (s.getName() == null ? "" : s.getName())); + 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())); treeList.add(parent); @@ -675,7 +710,7 @@ public List<BtmTypeVO> getFromTable(String domain) { VciBaseUtil.alertNotNull(domain,"棰嗗煙鍊�"); try { - if (!DomainRepeater.getDomain().contains(domain)){ + if (!DomainRepeater.getDomain().stream().collect(Collectors.toMap(DomainVO::getValue, DomainVO::getLabel)).containsKey(domain)){ return null; } R result = DomainRepeater.getFromTable(domain); @@ -720,9 +755,9 @@ btmType.setOid(VciBaseUtil.getPk()); btmType.setTs(now); btmType.setCreator(user); - btmType.setBtmName("btmType"); + btmType.setBtmName(BtmTypeConstant.BTMTYPE); btmType.setCreateTime(now); - btmType.setDomain(domain); + btmType.setBizDomain(domain); btmType.setLastModifyTime(now); btmType.setLastModifier(user); btmType.setName(dto.getDescription()); @@ -735,9 +770,11 @@ }).map(attr -> { // 娣诲姞灞炴�э紝1鏄牎楠岋紝2鏄坊鍔� Attribute attribute = new Attribute(); - attribute.setKey(attr.getId()); - attribute.setLabel(attr.getName()); - attribute.setDictKey(attr.getAttrDataType()); + attribute.setId(attr.getId()); + attribute.setName(attr.getName()); + attribute.setTypeCode("attributeType"); + attribute.setTypeKey(attr.getAttrDataType()); +// attribute.setDictKey(attr.getAttrDataType()); attribute.setMaxLength(attr.getAttributeLength()); attribute.setPrecision(attr.getPrecisionLength()); attribute.setDescription(attr.getDescription()); @@ -747,10 +784,14 @@ attribute.setReferToId(attr.getReferBtmTypeId()); attribute.setReferToName(attr.getReferBtmTypeName()); attribute.setTs(now); + attribute.setOwner(user); attribute.setCreateTime(now); - attribute.setIsDeleted(0); - attribute.setCreateUser(AuthUtil.getUserId()); - idAttrMap.put(attribute.getKey(),attribute); + attribute.setLastModifier(user); + attribute.setLastModifyTime(now); + attribute.setBtmName(BtmTypeConstant.ATTRIBUTE); + attribute.setCreator(user); + attribute.setOid(VciBaseUtil.getPk()); + idAttrMap.put(attribute.getId(),attribute); // 鍦ㄨ繖閲岀粰涓氬姟绫诲瀷璁剧疆鐗堟湰鎺у埗銆佺敓鍛藉懆鏈熸帶鍒躲�佸瘑绾ф帶鍒剁浉鍏崇殑淇℃伅 // 娣诲姞涓氬姟绫诲瀷鍜屽睘鎬х殑鍏崇郴 @@ -760,7 +801,6 @@ btmTypeAttribute.setCreateTime(now); btmTypeAttribute.setLastModifier(user); btmTypeAttribute.setLastModifyTime(now); -// btmTypeAttribute.setBtmName("btmTypeAttribute"); btmTypeAttribute.setOid(VciBaseUtil.getPk()); btmTypeAttribute.setBtmName(btmType.getId()); btmTypeAttribute.setOwner(user); @@ -774,7 +814,7 @@ btmType.setConsistence(BooleanEnum.TRUE.getValue()); btmList.add(btmType); }); - List<Attribute> existAttr = attributeService.list(Wrappers.<Attribute>query().lambda().in(Attribute::getKey, attributeIds)); + List<Attribute> existAttr = attributeService.list(Wrappers.<Attribute>query().lambda().in(Attribute::getId, attributeIds)); if (!CollectionUtils.isEmpty(btmList)){ baseMapper.batchInsert(btmList); } @@ -796,11 +836,233 @@ if (CollectionUtils.isEmpty(existAttr)){ attributeService.saveBatch(idAttrMap.values()); }else { - List<Attribute> addList = idAttrMap.values().stream().filter(a -> existAttr.stream().noneMatch(b -> StringUtils.equals(a.getKey(), b.getKey()))).collect(Collectors.toList()); - if (CollectionUtils.isEmpty(addList)) { + List<Attribute> addList = idAttrMap.values().stream().filter(a -> existAttr.stream().noneMatch(b -> StringUtils.equals(a.getId(), b.getId()))).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(addList)) { attributeService.saveBatch(addList); } } return BtmTypeWrapper.build().listEntityVO(btmList); } + + /** + * 鎸夌収涓氬姟绫诲瀷id鑾峰彇榛樿灞炴�� + * + * @param btmTypeId 涓氬姟绫诲瀷id + * @return 涓氬姟绫诲瀷 + */ + @Override + public BtmTypeVO getDefaultAttrByBtmId(String btmTypeId) { + BtmTypeVO btmType = getBtmTypeById(btmTypeId); + if (btmType == null){ + return null; + } + btmType.setAttributes(btmTypeAttributeService.getDefaultAttribute(btmType)); + return btmType; + } + + /** + * 鎸夌収涓氬姟绫诲瀷id鑾峰彇鎵�鏈夌殑灞炴�� + * + * @param btmTypeId 涓氬姟绫诲瀷id + * @return 涓氬姟绫诲瀷 + */ + @Override + public BtmTypeVO getAllAttributeByBtmId(String btmTypeId) { + BtmTypeVO btmType = getBtmTypeById(btmTypeId); + if (btmType == null){ + return null; + } + btmType.setAttributes(btmTypeAttributeService.getAllAttribute(btmType)); + return btmType; + } + + /** + * 鎸夌収涓氬姟绫诲瀷涓婚敭鑾峰彇鎵�鏈夌殑灞炴�� + * + * @param btmTypeOid 涓氬姟绫诲瀷涓婚敭 + * @return 涓氬姟绫诲瀷 + */ + @Override + public BtmTypeVO getAllAttributeByBtmOid(String btmTypeOid) { + BtmTypeVO btmType = getBtmTypeByOid(btmTypeOid); + if (btmType == null){ + return null; + } + btmType.setAttributes(btmTypeAttributeService.getAllAttribute(btmType)); + return btmType; + } + + /** + * 鑾峰彇寮曠敤鏌愪釜鐢熷懡鍛ㄦ湡鐨勪笟鍔$被鍨� + * + * @param lifeId 鐢熷懡鍛ㄦ湡鐨勭紪鍙� + * @return 涓氬姟绫诲瀷鏄剧ず瀵硅薄 + */ + @Override + public List<BtmTypeVO> selectByLifeId(String lifeId) { + if(StringUtils.isBlank(lifeId)){ + return new ArrayList<>(); + } + LambdaQueryWrapper<BtmType> query = new LambdaQueryWrapper<BtmType>(); + query.eq(BtmType::getLifeCycleId,lifeId); + return BtmTypeWrapper.build().listEntityVO(getBaseMapper().selectList(query)); + } + + /** + * 鑾峰彇寮曠敤鏌愪簺鐢熷懡鍛ㄦ湡鐨勪笟鍔$被鍨� + * + * @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 鐢熷懡鍛ㄦ湡鐨勭紪鍙� + * @return 涓暟 + */ + @Override + public Integer countByLifeId(String lifeId) { + if(StringUtils.isBlank(lifeId)){ + return 0; + } + LambdaQueryWrapper<BtmType> query = new LambdaQueryWrapper<BtmType>(); + 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; + } + } -- Gitblit v1.9.3