From d4e94f635dbe265f10ad614eac7386968ae30c23 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期三, 19 七月 2023 11:25:30 +0800 Subject: [PATCH] 提交代码 --- Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java | 525 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 473 insertions(+), 52 deletions(-) diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java index 0366b45..fce6239 100644 --- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java +++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java @@ -17,38 +17,56 @@ package com.vci.ubcs.code.service.impl; import com.alibaba.cloud.commons.lang.StringUtils; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.vci.ubcs.code.constant.FrameWorkDefaultValueConstant; +import com.vci.ubcs.code.constant.MdmBtmTypeConstant; +import com.vci.ubcs.code.dto.CodeBasicSecDTO; import com.vci.ubcs.code.dto.CodeRuleDTO; -import com.vci.ubcs.code.entity.CodeAllCode; -import com.vci.ubcs.code.entity.CodeClassify; -import com.vci.ubcs.code.entity.CodeRule; +import com.vci.ubcs.code.entity.*; +import com.vci.ubcs.code.enumpack.CodeSecTypeEnum; import com.vci.ubcs.code.lifecycle.CodeRuleLC; import com.vci.ubcs.code.mapper.CodeRuleMapper; -import com.vci.ubcs.code.service.ICodeAllcodeService; -import com.vci.ubcs.code.service.ICodeBasicSecService; -import com.vci.ubcs.code.service.ICodeClassifyService; -import com.vci.ubcs.code.service.ICodeRuleService; +import com.vci.ubcs.code.mapper.CodeSerialValueMapper; +import com.vci.ubcs.code.mapper.CommonsMapper; +import com.vci.ubcs.code.service.*; +import com.vci.ubcs.code.vo.pagemodel.CodeBasicSecVO; import com.vci.ubcs.code.vo.pagemodel.CodeClassifyVO; +import com.vci.ubcs.code.vo.pagemodel.CodeFixedValueVO; import com.vci.ubcs.code.vo.pagemodel.CodeRuleVO; import com.vci.ubcs.code.wrapper.CodeClassifyWrapper; import com.vci.ubcs.code.wrapper.CodeRuleWrapper; -import com.vci.ubcs.com.vci.starter.exception.VciBaseException; -import com.vci.ubcs.com.vci.starter.revision.service.RevisionModelUtil; -import com.vci.ubcs.com.vci.starter.web.util.VciBaseUtil; +import com.vci.ubcs.omd.cache.EnumCache; +import com.vci.ubcs.omd.enums.EnumEnum; +import com.vci.ubcs.starter.exception.VciBaseException; +import com.vci.ubcs.starter.revision.model.TreeQueryObject; +import com.vci.ubcs.starter.revision.service.RevisionModelUtil; +import com.vci.ubcs.starter.util.DefaultAttrAssimtUtil; +import com.vci.ubcs.starter.util.UBCSCondition; +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.WebUtil; +import org.springblade.core.mp.support.Condition; +import org.springblade.core.mp.support.Query; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.constant.BladeConstant; import org.springblade.core.tool.utils.BeanUtil; +import org.springblade.core.tool.utils.Func; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static com.vci.ubcs.code.constant.FrameWorkDefaultValueConstant.FRAMEWORK_RELEASE_EDITING; import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.DATA_OID_NOT_EXIST; @@ -68,15 +86,23 @@ */ @Resource private CodeRuleMapper codeRuleMapper; - @Resource + private CommonsMapper commonsMapper; + @Resource + private CodeSerialValueMapper codeSerialValueMapper; + + /** + * 鍏朵粬鏈嶅姟灞� + */ + @Resource + @Lazy private ICodeClassifyService codeClassifyServcie; - @Resource - private ICodeAllcodeService codeAllcodeService; - + private ICodeAllCodeService codeAllcodeService; @Resource private ICodeBasicSecService codeBasicSecService; + @Resource + private ICodeClassifyValueService iCodeClassifyValueService; /** * 瀵硅薄鐨勬搷浣� @@ -84,15 +110,27 @@ @Resource private RevisionModelUtil revisionModelUtil; + @Value("${user-info.tenant-id}") + private String tenantId; + @Value("${user-info.id}") + private String userId; + + /** + * 鍒嗛〉鏌ヨ + * @param query + * @param conidtionMap + * @return + */ @Override - public IPage<CodeRuleVO> selectPlCodeRulePage(IPage<CodeRuleVO> page, CodeRuleVO codeRule) { - //瀵圭敓鍛藉懆鏈熺殑鏋氫妇杩涜杞崲 - if(!StringUtils.isEmpty(codeRule.getLcStatusText())){ - codeRule.setLcStatus(CodeRuleLC.getValueByText(codeRule.getLcStatusText())); + public IPage<CodeRuleVO> gridCodeRule(Query query, Map<String,Object> conidtionMap) { + //濡傛灉绛変簬鑷繁閰嶇疆鐨勭鐞嗙粍绉熸埛id鍜岀鐞嗙粍瓒呯璐﹀彿锛屽氨涓嶉渶瑕佹寜鐓ц鍒欐墍鏈夎�呮潵杩涜鏌ヨ + if(!(AuthUtil.getTenantId().equals(this.tenantId) && AuthUtil.getUserId().toString().equals(this.userId))){ + // 鎸夌収瑙勫垯鎵�鏈夎�呮潵鏌ヨ + conidtionMap.put("owner",AuthUtil.getUserId()); } - List<CodeRule> codeRulePage = codeRuleMapper.selectCodeRulePage(page, codeRule); + IPage<CodeRule> codeRuleIPage = this.codeRuleMapper.selectPage(Condition.getPage(query), UBCSCondition.getQueryWrapper(conidtionMap, CodeRule.class)); //do杞瑅o鍚屾椂setLcStatusText鐢熷懡鍛ㄦ湡鍊硷紝骞跺寘瑁呮垚鍒嗛〉瀵硅薄杩斿洖 - return page.setRecords(CodeRuleWrapper.build().listVO(codeRulePage)); + return CodeRuleWrapper.build().pageVO(codeRuleIPage); } /** @@ -103,31 +141,39 @@ * @throws VciBaseException 鍙傛暟涓虹┖锛屽敮涓�椤癸紝蹇呰緭椤逛笉閫氳繃鏃朵細鎶涘嚭寮傚父 */ @Override - public Boolean addSave(CodeRuleDTO codeRuleDTO) throws VciBaseException{ + public R addSave(CodeRuleDTO codeRuleDTO) throws VciBaseException { VciBaseUtil.alertNotNull(codeRuleDTO, "闇�瑕佹坊鍔犵殑鏁版嵁瀵硅薄"); - //灏咲TO杞崲涓篋O + if(checkCodeRuleRepeat(codeRuleDTO)){ + return R.fail("瑙勫垯缂栧彿宸插瓨鍦紒"); + } + // 灏咲TO杞崲涓篋O CodeRule codeRule = Objects.requireNonNull(BeanUtil.copy(codeRuleDTO, CodeRule.class)); - String userId = AuthUtil.getUserId().toString(); - codeRule.setOid(VciBaseUtil.getPk()); - codeRule.setRevisionOid(VciBaseUtil.getPk()); - codeRule.setNameOid(VciBaseUtil.getPk()); - codeRule.setBtmname("coderule"); - codeRule.setLastR("1"); - codeRule.setLastV("1"); - codeRule.setFirstR("1"); - codeRule.setFirstV("1"); - codeRule.setCreator(userId); - codeRule.setCreateTime(new Date()); - codeRule.setLastModifier("1"); - codeRule.setLastModifyTime(new Date()); - codeRule.setVersionRule("0"); - codeRule.setVersionSeq(1); + // 濉厖榛樿鍊� + DefaultAttrAssimtUtil.addDefaultAttrAssimt(codeRule, MdmBtmTypeConstant.CODE_RULE); codeRule.setLctid(CODE_RULE_LC); codeRule.setLcStatus(FRAMEWORK_RELEASE_EDITING); - codeRule.setOwner("1"); - codeRule.setCreator(userId); - codeRule.setLastModifier(userId); - return codeRuleMapper.insert(codeRule)>0; + return R.status(codeRuleMapper.insert(codeRule)>0); + } + + /** + * 妫�鏌d缂栧彿鏄惁閲嶅 + * @param codeRuleDTO 褰撳墠鍒ゆ柇鏄惁閲嶅鐨勫璞� + * @return 杩斿洖false琛ㄧず鏈噸澶� + */ + @Override + public boolean checkCodeRuleRepeat(CodeRuleDTO codeRuleDTO){ + List<CodeRule> codeRulesList = this.codeRuleMapper.selectList(Wrappers.<CodeRule>query().lambda().eq(CodeRule::getId, codeRuleDTO.getId())); + if(!codeRulesList.isEmpty()){ + return codeRulesList.parallelStream().anyMatch(codeRule -> { + if(StringUtils.isNotBlank(codeRuleDTO.getOid())){ + // 浠h〃鏄慨鏀� + return !codeRule.getOid().equals(codeRuleDTO.getOid()); + }else { + return true; + } + }); + } + return false; } /** @@ -137,7 +183,7 @@ * @return true琛ㄧず鍙互缂栬緫鎴栧垹闄わ紝false琛ㄧず涓嶅彲浠� */ @Override - public boolean checkEditDelStatus(String lcStatus) { + public boolean checkEditDelStatus(String lcStatus) throws VciBaseException { if (CodeRuleLC.RELEASED.getValue().equals(lcStatus) || CodeRuleLC.DISABLED.getValue().equals(lcStatus)) { return false; } @@ -152,15 +198,22 @@ * @throws VciBaseException 鍙傛暟涓虹┖锛屽敮涓�椤癸紝蹇呰緭椤逛笉閫氳繃鏃朵細鎶涘嚭寮傚父 */ @Override - public Boolean editSave(CodeRuleDTO codeRuleDTO) throws VciBaseException{ + public R editSave(CodeRuleDTO codeRuleDTO) throws VciBaseException{ VciBaseUtil.alertNotNull(codeRuleDTO, "鏁版嵁瀵硅薄", codeRuleDTO.getOid(), "涓绘暟鎹紪鐮佽鍒欎富閿�"); + if(checkCodeRuleRepeat(codeRuleDTO)){ + return R.fail("瑙勫垯缂栧彿宸插瓨鍦紒"); + } if (!checkEditDelStatus(codeRuleDTO.getLcStatus())) { throw new VciBaseException("缂栫爜瑙勫垯宸插彂甯冿紝涓嶅厑璁哥紪杈戞垨鍒犻櫎"); } //灏咲TO杞崲涓篋O CodeRule codeRule = selectByOid(codeRuleDTO.getOid()); revisionModelUtil.copyFromDTOIgnore(codeRuleDTO, codeRule); - return codeRuleMapper.updateById(codeRule)>0; + if(!codeRule.getOwner().equals(codeRuleDTO.getOwner())){ + codeRule.setOwner(codeRuleDTO.getOwner()); + } + DefaultAttrAssimtUtil.updateDefaultAttrAssimt(codeRule); + return R.status(codeRuleMapper.updateById(codeRule)>0); } /** @@ -183,16 +236,62 @@ } } - List<CodeAllCode> codeDOList = codeAllcodeService.selectByWrapper(Wrappers.<CodeAllCode>query().eq("codeRuleOid", codeRuleDTO.getOid())); + List<CodeAllCode> codeDOList = codeAllcodeService.selectByWrapper(Wrappers.<CodeAllCode>query().lambda().eq(CodeAllCode::getCodeRuleOid, codeRuleDTO.getOid())); if (!CollectionUtils.isEmpty(codeDOList)) { return R.fail("缂栫爜瑙勫垯宸茬敓鎴愮紪鐮侊紝涓嶅厑璁稿垹闄�"); } //鎵ц鍒犻櫎鎿嶄綔 //WebUtil.setPersistence(false); boolean resBoolean = codeBasicSecService.batchDeleteSecByCodeRuleOid(codeRule.getOid()); - resBoolean = codeRuleMapper.deleteById(codeRule.getOid())>0; + boolean resBoolean1 = codeRuleMapper.deleteById(codeRule.getOid()) > 0; //WebUtil.setPersistence(true); - return R.status(resBoolean); + return R.status(resBoolean&&resBoolean1); + } + + /** + * 缂栫爜瑙勫垯娓呯┖鎵�鏈夊凡鐢熸垚鐨勭紪鐮� + * + * @param oid 缂栫爜瑙勫垯涓婚敭 + * @return 鎵ц缁撴灉 + */ + @Override + public R clearAllCode(String oid) { + WebUtil.alertNotNull(oid, "缂栫爜瑙勫垯涓婚敭"); + List<CodeAllCode> codeDOList = codeAllcodeService.selectByWrapper(Wrappers.<CodeAllCode>query().lambda().eq(CodeAllCode::getCodeRuleOid, oid)); + if (CollectionUtils.isEmpty(codeDOList)) { + return R.fail("褰撳墠缂栫爜瑙勫垯娌℃湁鐢熸垚缂栫爜,鏃犻渶娓呯┖"); + } + //鏄惁闇�瑕佽繘琛宐tm涓嶇粺涓�鐨勫垽鏂�? + String btmType = codeDOList.get(0).getCreateCodeBtm(); + //澶氱绫诲瀷涓嬬殑鏌ヨ + Set<String> btmTypeSet = codeDOList.stream().filter(s -> { + return !btmType.equalsIgnoreCase(s.getCreateCodeBtm()); + }).map(s -> s.getCreateCodeBtm()).collect(Collectors.toSet()); + List<Map<String,String>> businessDataList = new ArrayList<>(); + if (btmTypeSet.size() > 1) { + for (String btm : btmTypeSet) { + Map<String,String> businessData = commonsMapper.selectByCount("PL_CODE_"+btm,oid,btm); + businessDataList.add(businessData); + } + }else { + Map<String,String> businessData = commonsMapper.selectByCount("PL_CODE_"+btmType,oid,btmType); + businessDataList.add(businessData); + } + if (CollectionUtils.isEmpty(businessDataList) || StringUtils.isBlank(businessDataList.get(0).get("count"))) { + //鏃犳晥鏌ヨ + return R.fail("鏌ヨ澶辫触"); + } else if (!"0".equalsIgnoreCase(businessDataList.get(0).get("count"))) { + return R.fail("缂栫爜瑙勫垯鐢熸垚鐨勭紪鐮佸凡鍦ㄤ笟鍔℃暟鎹腑搴旂敤锛屼笉鍏佽娓呯┖"); + } + //娌℃湁鏁版嵁锛屽彲浠ュ畨鍏ㄥ垹闄� + WebUtil.setPersistence(false); + //鍒犻櫎鐮佸�艰〃涓殑鏁版嵁锛屼絾涓嶅锛屽鏋滄湁娴佹按鐨勭爜娈碉紝闇�瑕侀噸鏂拌绠楁祦姘� + List<CodeSerialValue> serialValueList = codeSerialValueMapper.selectByCodeRoleId(oid); + /*BatchCBO batchCBO = boService.batchDelete(codeDOList); + batchCBO.getDeleteCbos().addAll(serialValueList); + WebUtil.setPersistence(true); + boService.persistenceBatch(batchCBO);*/ + return R.success("娓呯┖鐮佸�兼垚鍔燂紒"); } /** @@ -235,8 +334,330 @@ */ @Override public Collection<CodeClassifyVO> listUseRangeInCodeClassify(String oid) { - List<CodeClassify> codeClassifies = codeClassifyServcie.selectByWrapper(Wrappers.<CodeClassify>query().eq("codeRuleOid", oid)); + List<CodeClassify> codeClassifies = codeClassifyServcie.selectByWrapper(Wrappers.<CodeClassify>query().lambda().eq(CodeClassify::getCodeRuleOid, oid)); return CodeClassifyWrapper.build().listVO(codeClassifies); } + /** + * 涓婚敭鑾峰彇涓绘暟鎹紪鐮佽鍒� + * + * @param oid 涓婚敭 + * @return 涓绘暟鎹紪鐮佽鍒欐樉绀哄璞� + * @throws VciBaseException 鍙傛暟涓虹┖锛屾暟鎹笉瀛樺湪鏃朵細鎶涘嚭寮傚父 + */ + @Override + public CodeRuleVO getObjectByOid(String oid) throws VciBaseException { + CodeRule codeRule = selectByOid(oid); + return CodeRuleWrapper.build().entityVO(codeRule); + } + + /** + * 涓婚敭鎵归噺鑾峰彇涓绘暟鎹紪鐮佽鍒� + * + * @param oidCollections 涓婚敭闆嗗悎锛屼絾鏄彈鎬ц兘褰卞搷锛屽缓璁竴娆℃煡璇笉瓒呰繃10000涓� + * @return 涓绘暟鎹紪鐮佽鍒欐樉绀哄璞� + * @throws VciBaseException 鏌ヨ鍑虹幇寮傚父鏃朵細鎶涘嚭 + */ + @Override + public Collection<CodeRuleVO> listCodeRuleByOids(Collection<String> oidCollections) throws VciBaseException { + VciBaseUtil.alertNotNull(oidCollections, "鏁版嵁瀵硅薄涓婚敭闆嗗悎"); + List<CodeRule> codeRuleDOList = listCodeRuleDOByOidCollections(oidCollections); + return CodeRuleWrapper.build().listVO(codeRuleDOList); + } + + /** + * 涓婚敭鎵归噺鑾峰彇涓绘暟鎹紪鐮佽鍒� + * + * @param oidCollections 涓婚敭闆嗗悎锛屼絾鏄彈鎬ц兘褰卞搷锛屽缓璁竴娆℃煡璇笉瓒呰繃10000涓� + * @param hasSec 鏄惁鍖呭惈鐮佹 + * @return 涓绘暟鎹紪鐮佽鍒欐樉绀哄璞� + * @throws VciBaseException 鏌ヨ鍑虹幇寮傚父鏃朵細鎶涘嚭 + */ + @Override + public Collection<CodeRuleVO> listCodeRuleByIds(Collection<String> oidCollections, boolean hasSec) throws VciBaseException { + VciBaseUtil.alertNotNull(oidCollections, "鏁版嵁瀵硅薄涓婚敭闆嗗悎"); + List<CodeRule> codeRuleDOList = listCodeRuleDOByOidCollections(oidCollections); + return codeRuleDO2VOs(codeRuleDOList, true); + } + + /** + * 浣跨敤涓婚敭闆嗗悎鏌ヨ鏁版嵁瀵硅薄 + * + * @param oidCollections 涓婚敭鐨勯泦鍚� + * @return 鏁版嵁瀵硅薄鍒楄〃 + */ + private List<CodeRule> listCodeRuleDOByOidCollections(Collection<String> oidCollections) { + List<CodeRule> codeRuleDOList = new ArrayList<CodeRule>(); + if (!CollectionUtils.isEmpty(oidCollections)) { + Collection<Collection<String>> oidCollectionsList = VciBaseUtil.switchCollectionForOracleIn(oidCollections); + for (Collection<String> oids : oidCollectionsList) { + List<CodeRule> tempDOList = codeRuleMapper.selectBatchIds(oids); + if (!CollectionUtils.isEmpty(tempDOList)) { + codeRuleDOList.addAll(tempDOList); + } + } + } + return codeRuleDOList; + } + + /** + * 鍙傜収涓绘暟鎹紪鐮佽鍒欏垪琛� + * + * @param bladeQueryObject 鏌ヨ鏉′欢 + * @return 涓绘暟鎹紪鐮佽鍒欐樉绀哄璞″垪琛紝鐢熸晥鐨勫唴瀹� + * @throws VciBaseException 鏌ヨ鏉′欢鍜屽垎椤靛嚭閿欑殑鏃跺�欎細鎶涘嚭寮傚父 + */ + @Override + public IPage<CodeRuleVO> refDataGridCodeRule(BladeQueryObject bladeQueryObject) throws VciBaseException { + return gridCodeRule(bladeQueryObject.getQuery(), bladeQueryObject.getConditionMap()); + } + + /** + * 鍋滅敤涓庡惎鐢ㄧ紪鐮佽鍒� + * + * @param oid 缂栫爜瑙勫垯涓婚敭 + * @param update enable:鍚敤 disable:鍋滅敤 release:鍙戝竷 + * @return 鎵ц缁撴灉 + */ + @Override + public R updateStatus(String oid, String update) { + int count = 0; + //鍏堟煡璇㈠璞� + CodeRule codeRuleDO = selectByOid(oid); + //鍒涘缓淇敼瀵硅薄鐨勭殑wrapper鏉′欢 + LambdaUpdateWrapper<CodeRule> wrapper = Wrappers.<CodeRule>update() + .lambda() + .eq(CodeRule::getOid, oid); + if ("enable".equalsIgnoreCase(update)) { + if (!CodeRuleLC.DISABLED.getValue().equals(codeRuleDO.getLcStatus())) { + return R.fail("闈炲仠鐢ㄧ姸鎬佺殑缂栫爜瑙勫垯鏃犻渶鐐瑰嚮鍚敤"); + } + count = codeRuleMapper.update(null,wrapper.set(CodeRule::getLcStatus, CodeRuleLC.RELEASED.getValue())); + } else if ("disable".equalsIgnoreCase(update)) { + if (!CodeRuleLC.RELEASED.getValue().equals(codeRuleDO.getLcStatus())) { + return R.fail("闈炲彂甯冪姸鎬佺殑缂栫爜瑙勫垯鏃犳硶鍋滅敤"); + } + count = codeRuleMapper.update(null,wrapper.set(CodeRule::getLcStatus, CodeRuleLC.DISABLED.getValue())); + } else if ("release".equalsIgnoreCase(update)) { + if (!CodeRuleLC.EDITING.getValue().equals(codeRuleDO.getLcStatus())) { + return R.fail("闈炵紪杈戠姸鎬佺殑缂栫爜瑙勫垯鏃犳硶鍙戝竷"); + } + // 鍙戝竷鏃跺皢鐮佹绫诲瀷鎸夌収瀛楃涓插垎闅旂殑褰㈠紡鎷兼帴骞跺瓨鍌� + String secTypeStr = codeBasicSecService.listCodeBasicSecByRuleOid(codeRuleDO.getOid()).stream().map(CodeBasicSecVO::getSecType).collect(Collectors.joining(",")); + count = codeRuleMapper.update(null,wrapper.set(CodeRule::getLcStatus, CodeRuleLC.RELEASED.getValue()).set(CodeRule::getBasicSecTypes,secTypeStr)); + } else { + return R.fail("鏆備笉鏀寔鐨勬搷浣滅被鍨�"); + } + if (count > 0) { + return R.success("鏇存柊鐘舵�佹垚鍔�"); + } else { + return R.fail("鏇存柊鐘舵�佸け璐�"); + } + } + + /** + * 鍏嬮殕缂栫爜瑙勫垯 + * + * @param codeRuleDTO 涓绘暟鎹紪鐮佽鍒欐暟鎹紶杈撳璞★紝oid鍜宼s闇�瑕佷紶杈� + * @return 涓绘暟鎹紪鐮佽鍒欐樉绀哄璞� + */ + @Override + @Transactional(rollbackFor = Exception.class) + public R cloneCodeRule(CodeRuleDTO codeRuleDTO) { + VciBaseUtil.alertNotNull(codeRuleDTO, "闇�瑕佹坊鍔犵殑鏁版嵁瀵硅薄"); + CodeRule codeRuleDO = new CodeRule(); + BeanUtilForVCI.copyPropertiesIgnoreCase(codeRuleDTO, codeRuleDO); + boolean exFlag = codeRuleMapper.insert(codeRuleDO)>0; + List<CodeBasicSecDTO> secList = codeRuleDTO.getElements(); + List<CodeBasicSec> codeBasicSecs = new ArrayList<>(); + secList.forEach(codeBasicSecDTO -> { + codeBasicSecDTO.setPkCodeRule(codeRuleDO.getOid()); + KeyValue attrKv = codeBasicSecService.checkAttrNullableBySecType(codeBasicSecDTO); + if (!"success".equals(attrKv.getKey())) { + throw new VciBaseException(attrKv.getValue() + "涓嶈兘涓虹┖"); + } + CodeBasicSec codeBasicSecDO = new CodeBasicSec(); + BeanUtilForVCI.copyPropertiesIgnoreCase(codeBasicSecDTO, codeBasicSecDO); + codeBasicSecDO.setOid(""); + codeBasicSecDO.setRevisionOid(""); + codeBasicSecDO.setNameOid(""); + codeBasicSecs.add(codeBasicSecDO); + }); + boolean exFlag1 = this.codeBasicSecService.saveBatch(codeBasicSecs); + return R.data(exFlag&&exFlag1); + } + + /** + * 浣跨敤涓婚敭鑾峰彇缂栫爜瑙勫垯鐨勫唴瀹� + * + * @param oid 涓婚敭 + * @return 瑙勫垯鐨勬樉绀哄璞� + */ + @Override + public CodeRuleVO getObjectHasSecByOid(String oid) { + CodeRule ruleDO = selectByOid(oid); + return codeRuleDO2VO(ruleDO, true); + } + + /** + * 妫�鏌ョ浉浼肩紪鐮佽鍒欙紝骞惰繑鍥炲搴旂殑缁撴灉 + * @param oid 涓婚敭 + * @return 鎵ц缁撴灉 + */ + @Override + public R checkLikeCodeRule(String oid) throws VciBaseException { + // 1銆佹煡璇㈠嚭褰撳墠瑕佸彂甯冪殑瑙勫垯 + CodeRuleVO releaseCodeRule = getObjectHasSecByOid(oid); + // 褰撳墠鍙戝竷鐨勮鍒欎笉瀛樺湪鐮佹淇℃伅锛岀洿鎺ョ┖淇℃伅杩斿洖 + if(Func.isEmpty(releaseCodeRule.getSecVOList())){ + return R.success(""); + } + // 2銆佹壘鍑轰笌褰撳墠鍙戝竷鐨勮鍒欑爜娈甸『搴忎竴鑷寸殑瑙勫垯 + String secTypes = releaseCodeRule.getSecVOList().stream().map(CodeBasicSecVO::getSecType).collect(Collectors.joining(",")); + // 鏌ヨ鍑烘墍鏈夊凡鍙戝竷鐨勭紪鐮佽鍒欎腑鐮佹绫诲瀷椤哄簭涓庡綋鍓嶈鍙戝竷鐨勮鍒欓『搴忎竴鑷寸殑缂栫爜瑙勫垯锛屾鏃跺凡杩戣繃婊ゆ帀澶ч儴鍒嗚鍒欙紝杩愮畻閲忓噺灏� + List<CodeRule> codeRuleList = codeRuleMapper.selectList(Wrappers.<CodeRule>query().lambda() + .eq(CodeRule::getLcStatus, CodeRuleLC.RELEASED.getValue()) + .eq(CodeRule::getBasicSecTypes,secTypes) + ); + // 涓虹┖锛岃瘉鏄庝笉瀛樺湪绫诲悓鐨勭紪鐮佽鍒欑洿鎺ヨ繑鍥� + if(Func.isEmpty(codeRuleList)){ + return R.success(""); + } + // 鏌ヨ鍑哄熀纭�鐮佹鍒楄〃锛堟寜鐓rderNum鍗囧簭鎺掑簭锛� + List<CodeRuleVO> codeRuleVOS = codeRuleDO2VOs(codeRuleList, true); + // 3銆佸悇绫荤爜娈靛垎鍒繘琛屾瘮瀵� + List<CodeRuleVO> lastCodeRule = new ArrayList<>(); + codeRuleVOS.stream().forEach(item->{ + List<CodeBasicSecVO> secVOList = item.getSecVOList(); + boolean flag = true; + for (int index = 0; index < secVOList.size(); index++) { + // 褰撳墠瑕佸彂甯冪殑瑙勫垯鍖呭惈鐨勭爜娈典俊鎭� + CodeBasicSecVO releaseBasicSec = releaseCodeRule.getSecVOList().get(index); + // 宸插彂甯冪殑瑙勫垯鍖呭惈鐨勭爜娈典俊鎭� + CodeBasicSecVO releasedBasicSec = secVOList.get(index); + // 鍥犱负鐮佹椤哄簭閮芥槸鎸夌収OrderNum鎺掑簭鐨勶紝鎵�浠ョ洿鎺ユ寜鐓т笅鏍囦袱涓ゆ瘮杈冨氨鍙互浜� + switch (releasedBasicSec.getSecType()){ + // 灞炴�х爜娈碉紝姣斿灞炴�у拰灞炴�ф墍鍦ㄥ垎绫�(referCodeClassifyOid) + case "codeattrsec": + if(!releasedBasicSec.getReferCodeClassifyOid().equals(releaseBasicSec.getReferCodeClassifyOid())){ + flag = false; + } + break; + // 鍙彉鐮佹锛屾瘮瀵圭爜娈甸暱搴︼紝缂栫爜琛ヤ綅鏂瑰紡鍜岃ˉ浣嶆椂鐨勫瓧绗� + case "codevariablesec": + if(!(releasedBasicSec.getCodeSecLength().equals(releaseBasicSec.getCodeSecLength()) + && releasedBasicSec.getCodeFillType().equals(releaseBasicSec.getCodeFillType()) + && releasedBasicSec.getCodeFillSeparator().equals(releaseBasicSec.getCodeFillSeparator()))){ + flag = false; + } + break; + // 鍥哄畾鐮佹姣斿鎸夊崌搴忔帓搴忕殑鐮佸�硷紝 + case "codefixedsec": + if(Func.isNotEmpty(releasedBasicSec.getFixedValueVOList()) && Func.isNotEmpty(releaseBasicSec.getFixedValueVOList())){ + // 灏唂ixedValue鎸夌収閫楀彿鍒嗛殧鎷兼帴璧锋潵锛屼互渚挎瘮杈冿紝鐢变簬鏌ヨ鏃跺凡鎸夌収orderNum鎺掕繃搴忎簡锛屾墍浠ヤ笉闇�瑕佸啀娆℃帓搴� + String reledFixedValues = releasedBasicSec.getFixedValueVOList().stream().map(CodeFixedValueVO::getId).collect(Collectors.joining(",")); + String releFixedValues = releaseBasicSec.getFixedValueVOList().stream().map(CodeFixedValueVO::getId).collect(Collectors.joining(",")); + if(reledFixedValues.equals(releFixedValues)){ + flag = false; + } + } + break; + // 鍒嗙被鐮佹姣斿鎸夊崌搴忔帓搴忕爜鍊� + case "codeclassifysec": + if(!releasedBasicSec.getReferCodeClassifyOid().equals(releaseBasicSec.getReferCodeClassifyOid())){ + flag = false; + } + break; + // 鏃ユ湡鐮佹姣斿鏃ユ湡鏍煎紡 + case "codedatesec": + if(!releasedBasicSec.getCodeDateFormatStr().equals(releaseBasicSec.getCodeDateFormatStr())){ + flag = false; + } + break; + // 寮曠敤鐮佹锛屾瘮瀵瑰弬鐓у紩鐢ㄧ殑涓氬姟绫诲瀷 + case "coderefersec": + if(!releasedBasicSec.getReferBtmId().equals(releaseBasicSec.getReferBtmId())){ + flag = false; + } + break; + // 灞傜骇鐮佹锛屾瘮瀵瑰眰绾х被鍨嬨�佸眰绾х殑鍊笺�佸瓧绗︽埅鍙栫被鍨嬨�佸彇鍊肩被鍨� + case "codelevelsec": + if(!(releasedBasicSec.getCodeLevelType().equals(releaseBasicSec.getCodeLevelType()) + && releasedBasicSec.getCodeLevelValue().equals(releaseBasicSec.getCodeLevelValue()) + && releasedBasicSec.getValueCutType().equals(releaseBasicSec.getValueCutType()) + && releasedBasicSec.getCodeGetValueType().equals(releaseBasicSec.getCodeGetValueType()))){ + flag = false; + } + break; + // 娴佹按鐮佹姣斿鐮佹鐨勯暱搴� + case "codeserialsec": + if(!releasedBasicSec.getCodeFillLength().equals(releaseBasicSec.getCodeFillLength())){ + flag = false; + } + break; + } + if (flag) { + break; + } + } + // 婊¤冻鎵�鏈夌爜娈电被鍨嬫瘮瀵规潯浠剁殑瑙勫垯 + if (flag) { + lastCodeRule.add(item); + } + }); + StringBuffer resMsg = new StringBuffer(); + resMsg.append("瀛樺湪濡備笅鐩镐技瑙勫垯锛屾槸鍚︾户缁彂甯冿紵\n"); + // 鏈�鍚庡皢缁撴灉杩涜澶勭悊骞惰繑鍥� + lastCodeRule.stream().forEach(item->{ + resMsg.append(item.getName()); + resMsg.append(item.getId()); + resMsg.append("缂栫爜瑙勫垯;\n"); + }); + return R.fail(resMsg.toString()); + } + + /** + * 鎵归噺鏁版嵁瀵硅薄杞崲涓烘樉绀哄璞� + * + * @param codeRules 鏁版嵁瀵硅薄鍒楄〃 + * @param hasSec 鏄惁鍖呭惈鐮佹 + * @return 鏄剧ず瀵硅薄 + * @throws VciBaseException 鍙傛暟涓虹┖鎴栬�呬笉瀛樺湪鐨勬椂鍊欎細鎶涘嚭寮傚父 + */ + public List<CodeRuleVO> codeRuleDO2VOs(Collection<CodeRule> codeRules, boolean hasSec) throws VciBaseException { + List<CodeRuleVO> voList = new ArrayList<CodeRuleVO>(); + if (!CollectionUtils.isEmpty(codeRules)) { + for (CodeRule s : codeRules) { + CodeRuleVO vo = codeRuleDO2VO(s,true); + if (vo != null) { + voList.add(vo); + } + } + } + return voList; + } + + /** + * 鏁版嵁瀵硅薄杞崲涓烘樉绀哄璞� + * + * @param codeRuleDO 瑙勫垯鐨勬暟鎹璞� + * @param hasSec 鏄惁鏌ヨ鐮佹 + * @return 鏄剧ず瀵硅薄 + * @throws VciBaseException 鎷疯礉灞炴�у嚭閿欑殑鏃跺�欎細鎶涘嚭寮傚父 + */ + public CodeRuleVO codeRuleDO2VO(CodeRule codeRuleDO, boolean hasSec) throws VciBaseException { + CodeRuleVO vo = new CodeRuleVO(); + if (codeRuleDO != null) { + BeanUtilForVCI.copyPropertiesIgnoreCase(codeRuleDO, vo); + //濡傛灉鏈塴cstatus鐨勭被鐨勮瘽 + vo.setLcStatusText(CodeRuleLC.getTextByValue(vo.getLcStatus())); + if (hasSec) { + List<CodeBasicSecVO> codeBasicSecVOS = codeBasicSecService.listCodeBasicSecByRuleOid(vo.getOid()); + //鏌ヨ鐮佹 + vo.setSecVOList(codeBasicSecVOS); + } + } + return vo; + } + } -- Gitblit v1.9.3