From 7f0570d20aac189f1b170942bd7100b281a1c824 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期三, 26 四月 2023 00:07:37 +0800 Subject: [PATCH] 代码整合,新增codefixedcontroller --- Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeClassifyValueServiceImpl.java | 329 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 329 insertions(+), 0 deletions(-) diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeClassifyValueServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeClassifyValueServiceImpl.java index ba1e151..e9749c9 100644 --- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeClassifyValueServiceImpl.java +++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeClassifyValueServiceImpl.java @@ -1,14 +1,343 @@ package com.vci.ubcs.code.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.vci.ubcs.code.dto.CodeClassifyValueDTO; import com.vci.ubcs.code.entity.CodeClassifyValue; +import com.vci.ubcs.code.enumpack.FrameworkDataLCStatus; import com.vci.ubcs.code.mapper.CodeClassifyValueMapper; +import com.vci.ubcs.code.service.ICodeBasicSecService; import com.vci.ubcs.code.service.ICodeClassifyValueService; +import com.vci.ubcs.code.vo.pagemodel.CodeClassifyValueVO; +import com.vci.ubcs.code.wrapper.CodeClassifyValueWrapper; +import com.vci.ubcs.starter.exception.VciBaseException; +import com.vci.ubcs.starter.revision.model.TreeQueryObject; +import com.vci.ubcs.starter.revision.model.TreeWrapperOptions; +import com.vci.ubcs.starter.revision.service.RevisionModelUtil; +import com.vci.ubcs.starter.web.pagemodel.Tree; +import com.vci.ubcs.starter.web.util.BeanUtilForVCI; +import com.vci.ubcs.starter.web.util.VciBaseUtil; +import org.springblade.core.tool.api.R; +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.*; +import java.util.stream.Collectors; + +import static com.vci.ubcs.code.constant.FrameWorkDefaultValueConstant.LC_STATUS; +import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.DATA_CASCADE_LINKED_NOT_DELETE; +import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.DATA_OID_NOT_EXIST; @Service public class CodeClassifyValueServiceImpl extends ServiceImpl<CodeClassifyValueMapper, CodeClassifyValue> implements ICodeClassifyValueService { + @Resource + private RevisionModelUtil revisionModelUtil; + + @Resource + private CodeClassifyValueMapper codeClassifyValueMapper; + + @Resource + @Lazy + private ICodeBasicSecService codeBasicSecService; + + /** + * 涓婄骇鑺傜偣鐨勫睘鎬у悕绉� + */ + private static final String PARENT_FIELD_NAME = "parentClassifyValueOid"; + + /** + * 鏌ヨ鍒嗙被鐮佹鐨勭爜鍊� 鏍� + * @param treeQueryObject 鏍戞煡璇㈠璞� + * @return 鍒嗙被鐮佹鐨勭爜鍊� 鏄剧ず鏍� + * @throws VciBaseException 鏌ヨ鏉′欢涓嶇鍚堣姹傜殑鏃跺�欎細鎶涘嚭寮傚父 + */ + @Override + public List<Tree> treeCodeClassifyValue(TreeQueryObject treeQueryObject) throws VciBaseException { + // List<CodeClassifyValueDO> doList =selectCodeClassifyValueDOByTree(treeQueryObject); + List<CodeClassifyValue> doList =selectCodeClassifyValueDO4Tree(treeQueryObject); + List<CodeClassifyValueVO> voList = CodeClassifyValueWrapper.build().listVO(doList); + TreeWrapperOptions treeWrapperOptions = new TreeWrapperOptions(PARENT_FIELD_NAME); + treeWrapperOptions.copyFromTreeQuery(treeQueryObject); + return revisionModelUtil.doList2Trees(voList,treeWrapperOptions,(CodeClassifyValueVO s) ->{ + //鍙互鍦ㄨ繖閲屽鐞嗘爲鑺傜偣鐨勬樉绀� + return s.getId() + " " + s.getName() + (FrameworkDataLCStatus.DISABLED.getValue().equalsIgnoreCase(s + .getLcStatus()) ? (" 銆愬仠鐢ㄣ�� ") : ""); + }); + } + + /** + * 澧炲姞鍒嗙被鐮佹鐨勭爜鍊� + * @param codeClassifyValueDTO 鍒嗙被鐮佹鐨勭爜鍊兼暟鎹紶杈撳璞� + * @return 鎵ц缁撴灉 + * @throws VciBaseException 鍙傛暟涓虹┖锛屽敮涓�椤癸紝蹇呰緭椤逛笉閫氳繃鏃朵細鎶涘嚭寮傚父 + */ + @Override + public boolean addSave(CodeClassifyValueDTO codeClassifyValueDTO) throws VciBaseException{ + VciBaseUtil.alertNotNull(codeClassifyValueDTO,"闇�瑕佹坊鍔犵殑鏁版嵁瀵硅薄"); + //娣诲姞瀵圭爜鍊煎瓙鐖剁骇鐨勫垽鏂� + if(StringUtils.isNotBlank(codeClassifyValueDTO.getParentclassifyvalueoid())){ + String parentclassifyvalueoid = codeClassifyValueDTO.getParentclassifyvalueoid(); + String codeclassifysecoid = codeClassifyValueDTO.getCodeclassifysecoid(); + CodeClassifyValue parentDO = codeClassifyValueMapper.selectById(parentclassifyvalueoid); + if (parentDO.getCodeClassifySecOid().equalsIgnoreCase(codeclassifysecoid)){ + throw new VciBaseException("涓嶅厑璁稿湪鐖剁爜鍊间腑鐩存帴娣诲姞瀛愮爜鍊�"); + } + } + //灏咲TO杞崲涓篋O + CodeClassifyValue codeClassifyValueDO = new CodeClassifyValue(); + BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyValueDTO,codeClassifyValueDO); + //鏌ヨ + List<CodeClassifyValue> existList = codeClassifyValueMapper.selectList(Wrappers.<CodeClassifyValue>query() + .lambda().eq(CodeClassifyValue::getCodeClassifySecOid, codeClassifyValueDO.getCodeClassifySecOid()) + .eq(CodeClassifyValue::getParentClassifyValueOid, codeClassifyValueDO.getParentClassifyValueOid()) + ); + codeClassifyValueDO.setOrderNum(existList.size() + 1); + boolean resBoolean = codeClassifyValueMapper.insert(codeClassifyValueDO) > 0; + return resBoolean; + } + + /** + * 淇敼鍒嗙被鐮佹鐨勭爜鍊� + * @param codeClassifyValueDTO 鍒嗙被鐮佹鐨勭爜鍊兼暟鎹紶杈撳璞� + * @return 鎵ц缁撴灉 + * @throws VciBaseException 鍙傛暟涓虹┖锛屽敮涓�椤癸紝蹇呰緭椤逛笉閫氳繃鏃朵細鎶涘嚭寮傚父 + */ + @Override + public boolean editSave(CodeClassifyValueDTO codeClassifyValueDTO) throws VciBaseException{ + VciBaseUtil.alertNotNull(codeClassifyValueDTO,"鏁版嵁瀵硅薄",codeClassifyValueDTO.getOid(),"鍒嗙被鐮佹鐨勭爜鍊间富閿�"); + //灏咲TO杞崲涓篋O + CodeClassifyValue codeClassifyValueDO = selectByOid(codeClassifyValueDTO.getOid()); + revisionModelUtil.copyFromDTOIgnore(codeClassifyValueDTO,codeClassifyValueDO); + boolean resBoolean = codeClassifyValueMapper.updateById(codeClassifyValueDO) > 0; + return resBoolean; + } + + /** + * 妫�鏌� 鍒嗙被鐮佹鐨勭爜鍊兼槸鍚﹀垹闄� + * @param codeClassifyValueDTO 鍒嗙被鐮佹鐨勭爜鍊兼暟鎹紶杈撳璞★紝蹇呴』瑕佹湁oid鍜宼s灞炴�� + * @return 鎵ц缁撴灉 success涓簍rue涓哄彲浠ュ垹闄わ紝false琛ㄧず鏈夋暟鎹紩鐢紝obj涓簍rue琛ㄧず鏈変笅绾� + * @throws VciBaseException 鍙傛暟涓虹┖锛岃寮曠敤鏃舵姏鍑哄紓甯� + */ + @Override + public R checkIsCanDelete(CodeClassifyValueDTO codeClassifyValueDTO) throws VciBaseException{ + VciBaseUtil.alertNotNull(codeClassifyValueDTO,"鏁版嵁浼犺緭瀵硅薄",codeClassifyValueDTO.getOid(),"涓婚敭"); + CodeClassifyValue codeClassifyValueDO = selectByOid(codeClassifyValueDTO.getOid()); + return checkIsCanDeleteForDO(codeClassifyValueDTO,codeClassifyValueDO); + } + + /** + * 鏍¢獙鏄惁鍙互鍒犻櫎锛屽鏋滃瓨鍦ㄤ笅绾э紝骞朵笖涓嬬骇鏈夋暟鎹紩鐢ㄥ垯涓嶈兘鍒犻櫎 + * @param codeClassifyValueDTO 鏁版嵁浼犺緭瀵硅薄 + * @param codeClassifyValueDO 鏁版嵁搴撲腑鐨勬暟鎹璞� + * @return success涓簍rue涓哄彲浠ュ垹闄わ紝false琛ㄧず鏈夋暟鎹紩鐢紝obj涓簍rue琛ㄧず鏈変笅绾� + */ + private R checkIsCanDeleteForDO(CodeClassifyValueDTO codeClassifyValueDTO, CodeClassifyValue codeClassifyValueDO) { + //boService.checkTs(codeClassifyValueDTO); + //鏍¢獙涓嬬骇鏄惁鏈夊紩鐢� + if(checkChildIsLinked(codeClassifyValueDO.getOid())){ + return R.fail(DATA_CASCADE_LINKED_NOT_DELETE); + } + return R.status(checkHasChild(codeClassifyValueDO.getOid())); + } + + /** + * 妫�鏌ユ槸鍚︽湁涓嬬骇鏄惁鍏宠仈浜嗘暟鎹� + * + * @param oid 涓婚敭 + * @return true 琛ㄧず鏈夊紩鐢紝false琛ㄧず娌℃湁寮曠敤 + * @throws VciBaseException 鍙傛暟涓虹┖鍜屾湁寮曠敤鐨勬椂鍊欎細鎶涘嚭寮傚父 + */ + @Override + public boolean checkChildIsLinked(String oid) throws VciBaseException { + VciBaseUtil.alertNotNull(oid,"涓婚敭"); + List<String> childOids = codeClassifyValueMapper.selectAllLevelChildOid(oid.trim()); + if(!CollectionUtils.isEmpty(childOids)){ + for(String childOid: childOids){ + if(!checkIsLinked(childOid)){ + return false; + } + } + return true; + } + return false; + } + + /** + * 鏍¢獙鏄惁鏈変笅绾ц妭鐐癸紝涓嶆牎楠屾槸鍚﹀叧鑱斾簡鏁版嵁 + * + * @param oid 涓婚敭 + * @return true琛ㄧず鏈変笅绾э紝false琛ㄧず娌℃湁涓嬬骇 + * @throws VciBaseException 鍙傛暟閿欒锛屾垨鑰呮暟鎹笉瀛樺湪鐨勬椂鍊欎細鎶涘嚭寮傚父 + */ + @Override + public boolean checkHasChild(String oid) throws VciBaseException { + VciBaseUtil.alertNotNull(oid,"涓婚敭"); + return codeClassifyValueMapper.countAllLevelChildOid(oid.trim()) > 0; + } + + /** + * 鏍¢獙鏄惁琚紩鐢� + * @param oid 涓婚敭 + * @throws VciBaseException 琚紩鐢ㄧ殑鏃跺�欎細鎶涘嚭寮傚父 + */ + private boolean checkIsLinked(String oid) throws VciBaseException{ + //TODO 娣诲姞闇�瑕佹牎楠屽紩鐢ㄧ殑鍦版柟 + return false; + } + + /** + * 鍒犻櫎鍒嗙被鐮佹鐨勭爜鍊� + * @param codeClassifyValueDTO 鍒嗙被鐮佹鐨勭爜鍊兼暟鎹紶杈撳璞★紝oid鍜宼s闇�瑕佷紶杈� + * @return 鍒犻櫎缁撴灉鍙嶉锛氾細success锛氭垚鍔燂紝fail锛氬け璐� + * @throws VciBaseException 鍙傛暟涓虹┖锛岃寮曠敤鏃舵姏鍑哄紓甯� + */ + @Override + @Transactional(rollbackFor = Exception.class) + public R deleteCodeClassifyValue(CodeClassifyValueDTO codeClassifyValueDTO) throws VciBaseException{ + VciBaseUtil.alertNotNull(codeClassifyValueDTO,"鍒嗙被鐮佹鐨勭爜鍊兼暟鎹璞�",codeClassifyValueDTO.getOid(),"鍒嗙被鐮佹鐨勭爜鍊肩殑涓婚敭"); + CodeClassifyValue codeClassifyValueDO = selectByOid(codeClassifyValueDTO.getOid()); + R baseResult = checkIsCanDeleteForDO(codeClassifyValueDTO,codeClassifyValueDO); + if(baseResult.isSuccess()) { + //鎵句笅绾х殑锛岃繖涓槸鍙互鍒犻櫎鐨勬椂鍊橰 + List<String> childrenOids = codeClassifyValueMapper.selectAllLevelChildOid(codeClassifyValueDO.getOid().trim()); + if (!CollectionUtils.isEmpty(childrenOids)) { + Collection<Collection<String>> childrenCollections = VciBaseUtil.switchCollectionForOracleIn(childrenOids); + for(Collection<String> s : childrenCollections){ + codeClassifyValueMapper.delete(Wrappers.<CodeClassifyValue>query().lambda().eq(CodeClassifyValue::getOid,s)); + } + } + }else{ + return baseResult; + } + //鎵ц鍒犻櫎鎿嶄綔 + boolean resBoolean = codeClassifyValueMapper.deleteById(codeClassifyValueDO.getOid()) > 0; + return R.status(resBoolean); + } + + /** + * 涓婚敭鑾峰彇鍒嗙被鐮佹鐨勭爜鍊� + * @param oid 涓婚敭 + * @return 鍒嗙被鐮佹鐨勭爜鍊兼樉绀哄璞� + * @throws VciBaseException 鍙傛暟涓虹┖锛屾暟鎹笉瀛樺湪鏃朵細鎶涘嚭寮傚父 + */ + @Override + public CodeClassifyValueVO getObjectByOid(String oid) throws VciBaseException{ + return CodeClassifyValueWrapper.build().entityVO(selectByOid(oid)); + } + + /** + * 涓婚敭鎵归噺鑾峰彇鍒嗙被鐮佹鐨勭爜鍊� + * @param oidCollections 涓婚敭闆嗗悎锛屼絾鏄彈鎬ц兘褰卞搷锛屽缓璁竴娆℃煡璇笉瓒呰繃10000涓� + * @return 鍒嗙被鐮佹鐨勭爜鍊兼樉绀哄璞� + * @throws VciBaseException 鏌ヨ鍑虹幇寮傚父鏃朵細鎶涘嚭 + */ + @Override + public Collection<CodeClassifyValueVO> listCodeClassifyValueByOids(Collection<String> oidCollections) throws VciBaseException{ + VciBaseUtil.alertNotNull(oidCollections,"鏁版嵁瀵硅薄涓婚敭闆嗗悎"); + List<CodeClassifyValue> codeClassifyValueDOList = listCodeClassifyValueDOByOidCollections(oidCollections); + return CodeClassifyValueWrapper.build().listVO(codeClassifyValueDOList); + } + + /** + * 鍙傜収鏍� 鍒嗙被鐮佹鐨勭爜鍊� + * @param treeQueryObject 鏍戝舰鏌ヨ瀵硅薄 + * @return 鍒嗙被鐮佹鐨勭爜鍊兼樉绀烘爲 + * @throws VciBaseException 鏌ヨ鏉′欢鍜屽垎椤靛嚭閿欑殑鏃跺�欎細鎶涘嚭寮傚父 + */ + @Override + public List<Tree> referTree(TreeQueryObject treeQueryObject) throws VciBaseException { + if(treeQueryObject == null){ + treeQueryObject = new TreeQueryObject(); + } + if(treeQueryObject.getConditionMap() == null){ + treeQueryObject.setConditionMap(new HashMap<>()); + } + if(treeQueryObject.getConditionMap().containsKey(LC_STATUS)) { + treeQueryObject.getConditionMap().remove(LC_STATUS); + } + return treeCodeClassifyValue(treeQueryObject); + } + + /** + * 鎵归噺娣诲姞鍒嗙被鐮佹鐨勭爜鍊笺�備富瑕佹槸淇濆瓨鐮佸�肩殑搴忓彿 + * @param dtoList 鍒嗙被鐮佹鐨勭爜鍊煎垪琛� + * @param codeclassifysecoid 鍒嗙被鐮佹鐨勪富閿� + * @return 鎵ц缁撴灉 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public R batchSave4Order(List<CodeClassifyValueDTO> dtoList, String codeclassifysecoid) { + VciBaseUtil.alertNotNull(codeclassifysecoid,"鍒嗙被鐮佹涓婚敭"); + List<CodeClassifyValue> valueDOList = codeClassifyValueMapper.selectList(Wrappers.<CodeClassifyValue>query() + .lambda().eq(CodeClassifyValue::getCodeClassifySecOid,codeclassifysecoid) + ); + + List<CodeClassifyValue> updateList = new ArrayList<>(); + dtoList.forEach(dto -> { + if( StringUtils.isNotBlank( dto.getOid() )){ + List<CodeClassifyValue> collect = valueDOList.stream().filter(value -> { + return dto.getOid().equals(value.getOid()); + }).collect(Collectors.toList()); + collect.forEach(ccv -> { + ccv.setOrderNum(dto.getOrdernum()); + ccv.setId(dto.getId()); + ccv.setName(dto.getName()); + updateList.add(ccv); + }); + } + }); + boolean resBoolean = this.updateBatchById(updateList); + return R.status(resBoolean); + } + + /** + * 浣跨敤涓婚敭闆嗗悎鏌ヨ鏁版嵁瀵硅薄 + * @param oidCollections 涓婚敭鐨勯泦鍚� + * @return 鏁版嵁瀵硅薄鍒楄〃 + */ + private List<CodeClassifyValue> listCodeClassifyValueDOByOidCollections(Collection<String> oidCollections){ + List<CodeClassifyValue> codeClassifyValueDOList = new ArrayList<CodeClassifyValue>(); + if(!CollectionUtils.isEmpty(oidCollections)){ + Collection<Collection<String>> oidCollectionsList = VciBaseUtil.switchCollectionForOracleIn(oidCollections); + for(Collection<String> oids: oidCollectionsList){ + List<CodeClassifyValue> tempDOList = codeClassifyValueMapper.selectBatchIds(oids); + if(!CollectionUtils.isEmpty(tempDOList)){ + codeClassifyValueDOList.addAll(tempDOList); + } + } + } + return codeClassifyValueDOList; + } + + /** + * 涓婚敭鏌ヨ鏁版嵁瀵硅薄 + * @param oid 涓婚敭 + * @return 鏁版嵁瀵硅薄 + * @throws VciBaseException 鍙傛暟涓虹┖锛屽苟涓旀暟鎹笉瀛樺湪鐨勬椂鍊欎細鎶涘嚭寮傚父 + */ + private CodeClassifyValue selectByOid(String oid) throws VciBaseException{ + VciBaseUtil.alertNotNull(oid,"涓婚敭"); + CodeClassifyValue codeClassifyValueDO = codeClassifyValueMapper.selectById(oid.trim()); + if(codeClassifyValueDO == null || StringUtils.isBlank(codeClassifyValueDO.getOid())){ + throw new VciBaseException(DATA_OID_NOT_EXIST); + } + return codeClassifyValueDO; + } + + private List<CodeClassifyValue> selectCodeClassifyValueDO4Tree(TreeQueryObject treeQueryObject){ + Map<String, String> conditionMap = treeQueryObject.getConditionMap(); + List<String> oids = codeBasicSecService.getOidByCodeclassifysecOid(conditionMap.get("codeclassifysecoid")); + LambdaQueryWrapper<CodeClassifyValue> wrapper = Wrappers.<CodeClassifyValue>query() + .lambda().in(CodeClassifyValue::getCodeClassifySecOid,oids) + .orderByDesc(CodeClassifyValue::getOrderNum); + return codeClassifyValueMapper.selectList(wrapper); + } } -- Gitblit v1.9.3