From af73b1917e58e37daaa3e63f5303da1056cedfa3 Mon Sep 17 00:00:00 2001 From: wang1 <844966816@qq.com> Date: 星期四, 13 七月 2023 18:18:26 +0800 Subject: [PATCH] 修复生命周期调试异常,整理流程代码 --- Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/LifeCycleServiceImpl.java | 610 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 595 insertions(+), 15 deletions(-) diff --git a/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/LifeCycleServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/LifeCycleServiceImpl.java index 29ad035..ace2a89 100644 --- a/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/LifeCycleServiceImpl.java +++ b/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/LifeCycleServiceImpl.java @@ -1,18 +1,42 @@ package com.vci.ubcs.omd.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.vci.ubcs.omd.constant.BtmTypeConstant; import com.vci.ubcs.omd.dto.LifeCycleDTO; -import com.vci.ubcs.omd.entity.LifeCycleRule; -import com.vci.ubcs.omd.mapper.LifeCycleMapper; +import com.vci.ubcs.omd.dto.LifeCycleEdgeDTO; +import com.vci.ubcs.omd.dto.LifeCycleLineEventDTO; +import com.vci.ubcs.omd.dto.LifeCycleNodeDTO; +import com.vci.ubcs.omd.entity.*; +import com.vci.ubcs.omd.mapper.*; +import com.vci.ubcs.omd.repeater.DomainRepeater; +import com.vci.ubcs.omd.service.IBtmTypeService; import com.vci.ubcs.omd.service.ILifeCycleService; -import com.vci.ubcs.omd.vo.BtmTypeVO; -import com.vci.ubcs.omd.vo.LifeCycleVO; -import com.vci.ubcs.starter.web.pagemodel.PageHelper; +import com.vci.ubcs.omd.service.IStatusService; +import com.vci.ubcs.omd.vo.*; +import com.vci.ubcs.omd.wrapper.LifeCycleEventWrapper; +import com.vci.ubcs.omd.wrapper.LifeCycleRuleWrapper; +import com.vci.ubcs.starter.enumpack.NewAppConstantEnum; +import com.vci.ubcs.starter.exception.VciBaseException; +import com.vci.ubcs.starter.web.constant.RegExpConstant; +import com.vci.ubcs.starter.web.util.BeanUtil; +import com.vci.ubcs.starter.web.util.VciBaseUtil; +import org.springblade.core.mp.support.Condition; +import org.springblade.core.mp.support.Query; +import org.springblade.core.secure.utils.AuthUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; -import java.util.List; -import java.util.Map; +import javax.annotation.Resource; +import java.util.*; +import java.util.stream.Collectors; + /** * 鐢熷懡鍛ㄦ湡鐨勬湇鍔� @@ -22,17 +46,76 @@ @Service public class LifeCycleServiceImpl extends ServiceImpl<LifeCycleMapper, LifeCycleRule> implements ILifeCycleService{ + /** + * 鑺傜偣鐨勬暟鎹眰 + */ + @Resource + private LifeCycleNodeMapper nodeMapper; + + /** + * 杩炴帴绾挎暟鎹眰 + */ + @Resource + private LifeCycleEdgeMapper edgeMapper; + + /** + * 鐘舵�� + */ + @Autowired(required = false) + @Lazy + private IStatusService statusService; + + /** + * 杩炴帴绾跨殑浜嬩欢 + */ + @Resource + private LifeCycleLineEventMapper lineEventMapper; + + /** + * 涓氬姟绫诲瀷鐨勬湇鍔� + */ + @Autowired(required = false) + @Lazy + private IBtmTypeService btmTypeService; + + @Resource + private LifeCycleEventMapper eventMapper; + /** * 鑾峰彇鐢熷懡鍛ㄦ湡鍒楄〃 * * @param conditionMap 鏌ヨ鏉′欢 - * @param pageHelper 鍒嗛〉 + * @param query 鍒嗛〉 * @return 鐢熷懡鍛ㄦ湡鐨勬樉绀哄璞� */ @Override - public IPage<LifeCycleVO> listLife(Map<String, String> conditionMap, PageHelper pageHelper) { - return null; + public IPage<LifeCycleVO> listLife(Map<String, Object> conditionMap, Query query) { + return LifeCycleRuleWrapper.build().pageVO(baseMapper.selectPage(Condition.getPage(query),Condition.getQueryWrapper(conditionMap,LifeCycleRule.class).lambda().orderByAsc(LifeCycleRule::getId))); + } + + /** + * 鑾峰彇鍏ㄩ儴鐨勪簨浠� + * + * @param conditionMap 鏌ヨ鏉′欢 + * @param query 鍒嗛〉 + * @return 浜嬩欢鐨勬樉绀哄璞� + */ + @Override + public IPage<LifeCycleEventVO> listEvent(Map<String, Object> conditionMap, Query query) { + return LifeCycleEventWrapper.build().pageVO(eventMapper.selectPage(Condition.getPage(query),Condition.getQueryWrapper(conditionMap, LifeCycleEvent.class).lambda().orderByAsc(LifeCycleEvent::getEventFullName))); + } + + public List<LifeCycleEventVO> listEventNoPage(){ + QueryWrapper<LifeCycleEvent> queryWrapper = new QueryWrapper(); + List<LifeCycleEvent> lifeCycleEvents = eventMapper.selectList(queryWrapper); + List<LifeCycleEventVO> vos = new ArrayList<>(); + lifeCycleEvents.stream().forEach(lifeCycleEvent -> { + LifeCycleEventVO vo = new LifeCycleEventVO(); + BeanUtil.convert(lifeCycleEvent,vo); + vos.add(vo); + }); + return vos; } /** @@ -42,9 +125,152 @@ * @return 娣诲姞鍚庣殑鏄剧ず瀵硅薄 */ @Override + @Transactional public LifeCycleVO addSave(LifeCycleDTO lifeCycleDTO) { - return null; + VciBaseUtil.alertNotNull(lifeCycleDTO,"鐢熷懡鍛ㄦ湡淇℃伅",lifeCycleDTO.getId(),"鐢熷懡鍛ㄦ湡鐨勭紪鍙�",lifeCycleDTO.getName(),"鐢熷懡鍛ㄦ湡鍚嶇О",lifeCycleDTO.getNodes(),"鐢熷懡鍛ㄦ湡鐨勮妭鐐�",lifeCycleDTO.getStartStatus(),"璧峰鐘舵��"); + //鍏堟煡璇㈡槸鍚﹀瓨鍦� + QueryWrapper<LifeCycleRule> wrapper = new QueryWrapper<>(); + wrapper.eq("id",lifeCycleDTO.getId().toLowerCase(Locale.ROOT)); + if(baseMapper.selectCount(wrapper)>0){ + throw new VciBaseException("鐢熷懡鍛ㄦ湡鐨勭紪鍙蜂笉鑳介噸澶�"); + } + String lifeOid = addLifeCycle(lifeCycleDTO); + return LifeCycleRuleWrapper.build().entityVO(baseMapper.selectById(lifeOid)); } + + /** + * 娣诲姞鐢熷懡鍛ㄦ湡 + * @param lifeCycleDTO + * @return 涓婚敭 + */ + private String addLifeCycle(LifeCycleDTO lifeCycleDTO){ + //缂栧彿涓嶈兘鏈夌壒娈婄殑鍐呭 + if(!lifeCycleDTO.getId().matches(RegExpConstant.LETTER)){ + throw new VciBaseException("鐢熷懡鍛ㄦ湡鐨勭紪鍙峰彧鑳芥槸瀛楁瘝"); + } + LifeCycleRule life = LifeCycleRuleWrapper.build().copyDTO2DO(lifeCycleDTO); + life.setOid(VciBaseUtil.getPk()); + String creator = AuthUtil.getUserAccount(); + Date now = new Date(); + life.setCreator(creator); + life.setCreateTime(now); + life.setLastModifier(creator); + life.setLastModifyTime(now); + life.setTs(now); + + List<String> statusList = new ArrayList<>(); + //澶勭悊鑺傜偣 + if(!CollectionUtils.isEmpty(lifeCycleDTO.getNodes())){ + lifeCycleDTO.getNodes().stream().forEach(nodeDTO->{ + addLifeCycleNode(nodeDTO,life.getOid(),creator,now); + statusList.add(nodeDTO.getId()); + }); + } + if(!statusList.contains(life.getStartStatus())){ + throw new VciBaseException("璧峰鐘舵�佷笉鍦ㄧ敓鍛藉懆鏈熺殑鐢诲竷涓�"); + } + //鍒ゆ柇鎵�鏈夌殑鑺傜偣鍦ㄧ郴缁熼噷閮藉瓨鍦� + List<String> existStatusIdList = statusService.listStatusByIdCollection(statusList).stream().map(StatusVO::getId).collect(Collectors.toList()); + String unExistStatus = statusList.stream().filter(s -> !existStatusIdList.contains(s)).collect(Collectors.joining(",")); + if(StringUtils.hasLength(unExistStatus)){ + throw new VciBaseException(unExistStatus + "杩欎簺鐘舵�佸湪鐘舵�佹睜閲屼笉瀛樺湪锛屼笉鑳芥坊鍔犲埌鐢熷懡鍛ㄦ湡涓�"); + } + //澶勭悊杈圭晫鍜岃繛鎺ョ嚎 + if(!CollectionUtils.isEmpty(lifeCycleDTO.getEdges())){ + lifeCycleDTO.getEdges().stream().forEach(edgeDTO->{ + String edgeOid = addLifeCycleEdge(edgeDTO,statusList,life.getOid(),creator,now); + if(!CollectionUtils.isEmpty(edgeDTO.getEvents())){ + //鏈変簨浠� + edgeDTO.getEvents().stream().forEach(eventDTO->{ + addLifeCycleLineEvent(eventDTO,edgeOid,creator,now); + }); + } + }); + } + baseMapper.insert(life); + return life.getOid(); + } + + /** + * 娣诲姞鐢熷懡鍛ㄦ湡鐨勮繛鎺ョ嚎涓婄殑浜嬩欢 + * @param eventDTO + * @param edgeOid + * @param creator + * @param now + */ + private void addLifeCycleLineEvent(LifeCycleLineEventDTO eventDTO,String edgeOid,String creator,Date now){ + VciBaseUtil.alertNotNull(eventDTO.getBizDomain(),"鎵�灞為鍩�",eventDTO.getEventFullName(),"浜嬩欢鐨勫叏璺緞"); + NewAppConstantEnum[] values = NewAppConstantEnum.values(); + Boolean fined = false; + for (int i = 0; i < values.length; i++) { + NewAppConstantEnum value = values[i]; + if(value.getName().equalsIgnoreCase(eventDTO.getBizDomain())){ + fined = true; + break; + } + } + if(!fined){ + throw new VciBaseException(eventDTO.getBizDomain() + "杩欎釜棰嗗煙杩樻病鏈夊紑鏀�,璇疯寮�鍙戜汉鍛樺湪NewAppConstantEnum绫讳腑娣诲姞"); + } + LifeCycleLineEvent event = org.springblade.core.tool.utils.BeanUtil.copy(eventDTO, LifeCycleLineEvent.class); + event.setOid(VciBaseUtil.getPk()); + event.setPkLifeCycleEdge(edgeOid); + event.setCreator(creator); + event.setCreateTime(now); + event.setLastModifier(creator); + event.setLastModifyTime(now); + event.setTs(now); + lineEventMapper.insert(event); + } + + /** + * 娣诲姞鐢熷懡鍛ㄦ湡鐨勮妭鐐� + * @param nodeDTO + * @param lifeOid + * @param creator + * @param now + */ + private void addLifeCycleNode(LifeCycleNodeDTO nodeDTO,String lifeOid,String creator,Date now){ + VciBaseUtil.alertNotNull(nodeDTO.getId(),"鐘舵�佹爣璇�",nodeDTO.getName(),"鐘舵�佸悕绉�"); + LifeCycleNode node = org.springblade.core.tool.utils.BeanUtil.copy(nodeDTO, LifeCycleNode.class); + node.setOid(VciBaseUtil.getPk()); + node.setLifeCycleOid(lifeOid); + node.setCreator(creator); + node.setCreateTime(now); + node.setLastModifier(creator); + node.setLastModifyTime(now); + node.setTs(now); + nodeMapper.insert(node); + } + + /** + * 娣诲姞鐢熷懡鍛ㄦ湡鐨勮繛鎺ョ嚎 + * @param edgeDTO + * @param statusList + * @param lifeOid + * @param creator + * @param now + * @return 杩炴帴绾跨殑涓婚敭 + */ + private String addLifeCycleEdge(LifeCycleEdgeDTO edgeDTO,List<String> statusList,String lifeOid,String creator,Date now){ + VciBaseUtil.alertNotNull(edgeDTO.getSource(),"鏉ユ簮鐘舵��",edgeDTO.getTarget(),"鐩爣鐘舵��"); + if(!statusList.contains(edgeDTO.getSource()) + ||!statusList.contains(edgeDTO.getTarget())){ + throw new VciBaseException("鏁版嵁閿欒锛孾" + edgeDTO.getName() + "]杩炴帴绾夸笂涓娇鐢ㄧ殑鐘舵�佹病鏈夋壘鍒�"); + } + LifeCycleEdge edge = org.springblade.core.tool.utils.BeanUtil.copy(edgeDTO, LifeCycleEdge.class); + edge.setOid(VciBaseUtil.getPk()); + edge.setLifeCycleOid(lifeOid); + edge.setCreator(creator); + edge.setCreateTime(now); + edge.setLastModifier(creator); + edge.setLastModifyTime(now); + edge.setTs(now); + edgeMapper.insert(edge); + return edge.getOid(); + } + + /** * 鎵归噺娣诲姞鍐呭 @@ -53,8 +279,218 @@ * @return 娣诲姞鍚庣殑鏄剧ず瀵硅薄 */ @Override - public List<LifeCycleVO> batchAddSave(List<LifeCycleDTO> lifeCycleDTOs) { - return null; + @Transactional + public List<LifeCycleVO> batchAddSave(Collection<LifeCycleDTO> lifeCycleDTOs) { + VciBaseUtil.alertNotNull(lifeCycleDTOs,"鐢熷懡鍛ㄦ湡鐨勪俊鎭�"); + //鍏堥泦浣撴牎楠屼竴涓� + if(lifeCycleDTOs.stream().anyMatch(s->!StringUtils.hasLength(s.getId()) || !StringUtils.hasLength(s.getName()) + || CollectionUtils.isEmpty(s.getNodes()) || !StringUtils.hasLength(s.getStartStatus()))){ + throw new VciBaseException("鐢熷懡鍛ㄦ湡鐨勭紪鍙凤紝鍚嶇О锛岃捣濮嬬姸鎬侊紝鍖呭惈鐨勮妭鐐逛笉鑳戒负绌�"); + } + //缁熶竴鏍¢獙閲嶅 + Map<String, List<LifeCycleDTO>> dtoMap = lifeCycleDTOs.stream().collect(Collectors.groupingBy(s->s.getId().toLowerCase(Locale.ROOT))); + dtoMap.forEach((id,dtos)->{ + if(dtos.size()>1){ + throw new VciBaseException("缂栧彿涓恒��" + id + "銆戠殑鐢熷懡鍛ㄦ湡閲嶅"); + } + }); + VciBaseUtil.switchCollectionForOracleIn(dtoMap.keySet()).stream().forEach( + ids->{ + QueryWrapper wrapper = new QueryWrapper(LifeCycleRule.class); + ids.stream().forEach(id->{ + wrapper.eq("lower(id)",id); + wrapper.or(); + }); + wrapper.eq("1","2"); + if(baseMapper.selectCount(wrapper)>0){ + throw new VciBaseException("鐢熷懡鍛ㄦ湡鐨勭紪鍙蜂笉鑳介噸澶�"); + } + } + ); + //鍏堝惊鐜鐞嗕笅锛屽洜涓虹幇鍦ㄥ綋鍓嶇敤鎴锋病鏈夊鐞嗕负绾跨▼鍏变韩鐨勶紝鍚庨潰淇敼鍚庯紝鍙互鐢ㄥ苟鍙戞祦鍘诲鐞� + List<String> oidList = new ArrayList<>(); + lifeCycleDTOs.stream().forEach(dto->{ + oidList.add(addLifeCycle(dto)); + }); + return LifeCycleRuleWrapper.build().listEntityVO(listByIds(oidList)); + } + + /** + * 淇敼淇濆瓨 + * + * @param lifeCycleDTO 鏁版嵁浼犺緭瀵硅薄 + * @return + */ + @Override + public LifeCycleVO editSave(LifeCycleDTO lifeCycleDTO) { + VciBaseUtil.alertNotNull(lifeCycleDTO,"鐢熷懡鍛ㄦ湡淇℃伅",lifeCycleDTO.getId(),"鐢熷懡鍛ㄦ湡鐨勭紪鍙�",lifeCycleDTO.getName(),"鐢熷懡鍛ㄦ湡鍚嶇О" + ,lifeCycleDTO.getNodes(),"鐢熷懡鍛ㄦ湡鐨勮妭鐐�",lifeCycleDTO.getStartStatus(),"璧峰鐘舵��", + lifeCycleDTO.getOid(),"涓婚敭"); + LifeCycleRule rule = selectByOid(lifeCycleDTO.getOid()); + //鏌ヨ閲嶅 + QueryWrapper wrapper = new QueryWrapper(LifeCycleRule.class); + + wrapper.eq("lower(id)",lifeCycleDTO.getId().toLowerCase(Locale.ROOT)); + wrapper.ne("oid",lifeCycleDTO.getOid()); + if(baseMapper.selectCount(wrapper)>0){ + throw new VciBaseException("鐢熷懡鍛ㄦ湡鐨勭紪鍙蜂笉鑳介噸澶�"); + } + editLifeCycle(lifeCycleDTO,rule); + return LifeCycleRuleWrapper.build().entityVO(getById(rule.getOid())); + } + + public LifeCycleVO detail(LifeCycleDTO lifeCycleDTO){ + QueryWrapper wrapper = Condition.getQueryWrapper(org.springblade.core.tool.utils.BeanUtil.copy(lifeCycleDTO, LifeCycleRule.class)); + LifeCycleRule lifeCycleRule = baseMapper.selectOne(wrapper); + LifeCycleVO vo = LifeCycleRuleWrapper.build().entityVO(lifeCycleRule); + String lifeOid = lifeCycleRule.getOid(); + + QueryWrapper<LifeCycleNode> nodeWrapper = new QueryWrapper<>(); + nodeWrapper.eq("life_cycle_oid",lifeOid.toLowerCase(Locale.ROOT)); + List<LifeCycleNode> nodes = nodeMapper.selectList(nodeWrapper); + List<LifeCycleNodeVO> nodeVos = new ArrayList<>(); + nodes.stream().forEach(doo->{ + LifeCycleNodeVO vo1 = new LifeCycleNodeVO(); + BeanUtil.convert(doo,vo1); + nodeVos.add(vo1); + }); + vo.setNodes(nodeVos); + + QueryWrapper<LifeCycleEdge> edgeWrapper = new QueryWrapper<>(); + edgeWrapper.eq("life_cycle_oid",lifeOid.toLowerCase(Locale.ROOT)); + List<LifeCycleEdge> edges = edgeMapper.selectList(edgeWrapper); + List<LifeCycleEdgeVO> edgeVos = new ArrayList<>(); + edges.stream().forEach(doo->{ + LifeCycleEdgeVO vo2 = new LifeCycleEdgeVO(); + BeanUtil.convert(doo,vo2); + edgeVos.add(vo2); + }); + vo.setEdges(edgeVos); + + return vo; + } + /** + * 淇敼鐢熷懡鍛ㄦ湡 + * @param lifeCycleDTO + * @param life + */ + private void editLifeCycle(LifeCycleDTO lifeCycleDTO,LifeCycleRule life){ + if(!lifeCycleDTO.getId().matches(RegExpConstant.LETTER)){ + throw new VciBaseException("鐢熷懡鍛ㄦ湡鐨勭紪鍙峰彧鑳芥槸瀛楁瘝"); + } + BeanUtil.convert(lifeCycleDTO,life); + String creator = AuthUtil.getUserAccount(); + Date now = new Date(); + life.setLastModifier(creator); + life.setLastModifyTime(now); + life.setTs(now); + + //鍒犻櫎鐜板湪鍏ㄩ儴鐨勬暟鎹紝鐒跺悗閲嶆柊娣诲姞= + List<LifeCycleNode> nodeList = selectNodeByLifeOid(life.getOid()); + List<LifeCycleEdge> edges = selectEdgeByLifeOid(life.getOid()); + List<LifeCycleLineEvent> eventList = selectEventByEdgeOids(Optional.ofNullable(edges).orElseGet(ArrayList::new).stream().map(LifeCycleEdge::getOid).collect(Collectors.toList())); + if(!CollectionUtils.isEmpty(nodeList)){ + nodeMapper.deleteBatchIds(nodeList.stream().map(LifeCycleNode::getOid).collect(Collectors.toList())); + } + if(!CollectionUtils.isEmpty(edges)){ + edgeMapper.deleteBatchIds(edges.stream().map(LifeCycleEdge::getOid).collect(Collectors.toList())); + } + if(!CollectionUtils.isEmpty(eventList)){ + lineEventMapper.deleteBatchIds(eventList.stream().map(LifeCycleLineEvent::getOid).collect(Collectors.toList())); + } + + List<String> statusList = new ArrayList<>(); + //澶勭悊鑺傜偣 + if(!CollectionUtils.isEmpty(lifeCycleDTO.getNodes())){ + lifeCycleDTO.getNodes().stream().forEach(nodeDTO->{ + addLifeCycleNode(nodeDTO,life.getOid(),creator,now); + statusList.add(nodeDTO.getId()); + }); + } + if(!statusList.contains(life.getStartStatus())){ + throw new VciBaseException("璧峰鐘舵�佷笉鍦ㄧ敓鍛藉懆鏈熺殑鐢诲竷涓�"); + } + //鍒ゆ柇鎵�鏈夌殑鑺傜偣鍦ㄧ郴缁熼噷閮藉瓨鍦� + List<String> existStatusIdList = statusService.listStatusByIdCollection(statusList).stream().map(StatusVO::getId).collect(Collectors.toList()); + String unExistStatus = statusList.stream().filter(s -> !existStatusIdList.contains(s)).collect(Collectors.joining(",")); + if(StringUtils.hasLength(unExistStatus)){ + throw new VciBaseException(unExistStatus + "杩欎簺鐘舵�佸湪鐘舵�佹睜閲屼笉瀛樺湪锛屼笉鑳芥坊鍔犲埌鐢熷懡鍛ㄦ湡涓�"); + } + //澶勭悊杈圭晫鍜岃繛鎺ョ嚎 + if(!CollectionUtils.isEmpty(lifeCycleDTO.getEdges())){ + lifeCycleDTO.getEdges().stream().forEach(edgeDTO->{ + String edgeOid = addLifeCycleEdge(edgeDTO,statusList,life.getOid(),creator,now); + if(!CollectionUtils.isEmpty(edgeDTO.getEvents())){ + //鏈変簨浠� + edgeDTO.getEvents().stream().forEach(eventDTO->{ + addLifeCycleLineEvent(eventDTO,edgeOid,creator,now); + }); + } + }); + } + baseMapper.updateById(life); + + } + + /** + * 浣跨敤涓婚敭鏌ヨ + * @param oid + * @return + */ + private LifeCycleRule selectByOid(String oid){ + LifeCycleRule rule = null; + try { + rule = getById(oid); + }catch (Throwable e){ + throw new VciBaseException("浣跨敤涓婚敭鑾峰彇瀵硅薄鍑洪敊锛岃繖涓暟鎹彲鑳戒笉瀛樺湪锛屾垨鑰呮暟鎹噸澶嶄簡"); + } + return rule; + } + + /** + * 鎵归噺淇敼淇濆瓨 + * + * @param lifeCycleDTOs + * @return + */ + @Override + public List<LifeCycleVO> batchEditSave(Collection<LifeCycleDTO> lifeCycleDTOs) { + if(CollectionUtils.isEmpty(lifeCycleDTOs)){ + return new ArrayList<>(); + } + if(lifeCycleDTOs.stream().anyMatch(s->!StringUtils.hasLength(s.getId()) || !StringUtils.hasLength(s.getName()) + || CollectionUtils.isEmpty(s.getNodes()) || !StringUtils.hasLength(s.getStartStatus()))){ + throw new VciBaseException("鐢熷懡鍛ㄦ湡鐨勭紪鍙凤紝鍚嶇О锛岃捣濮嬬姸鎬侊紝鍖呭惈鐨勮妭鐐逛笉鑳戒负绌�"); + } + //缁熶竴鏍¢獙閲嶅 + Map<String, List<LifeCycleDTO>> dtoMap = lifeCycleDTOs.stream().collect(Collectors.groupingBy(s->s.getId().toLowerCase(Locale.ROOT))); + dtoMap.forEach((id,dtos)->{ + if(dtos.size()>1){ + throw new VciBaseException("缂栧彿涓恒��" + id + "銆戠殑鐢熷懡鍛ㄦ湡閲嶅"); + } + }); + VciBaseUtil.switchCollectionForOracleIn(dtoMap.keySet()).stream().forEach( + ids->{ + QueryWrapper wrapper = new QueryWrapper(LifeCycleRule.class); + ids.stream().forEach(id->{ + wrapper.eq("lower(id)",id); + wrapper.ne("oid",dtoMap.get(id).get(0).getOid()); + wrapper.or(); + }); + wrapper.eq("1","2"); + if(baseMapper.selectCount(wrapper)>0){ + throw new VciBaseException("鐢熷懡鍛ㄦ湡鐨勭紪鍙蜂笉鑳介噸澶�"); + } + } + ); + List<String> oidList = lifeCycleDTOs.stream().map(LifeCycleDTO::getOid).collect(Collectors.toList()); + List<LifeCycleRule> rules = listByIds(oidList); + if(!CollectionUtils.isEmpty(rules)){ + rules.stream().forEach(life->{ + editLifeCycle(dtoMap.get(life.getId().toLowerCase(Locale.ROOT)).get(0),life); + }); + } + return LifeCycleRuleWrapper.build().listEntityVO(listByIds(oidList)); } /** @@ -63,8 +499,125 @@ * @param lifeCycleDTO 鏁版嵁浼犺緭瀵硅薄 */ @Override + @Transactional public void delete(LifeCycleDTO lifeCycleDTO) { + VciBaseUtil.alertNotNull(lifeCycleDTO,"鏁版嵁浼犺緭瀵硅薄",lifeCycleDTO.getOid(),"涓婚敭"); + LifeCycleRule rule = selectByOid(lifeCycleDTO.getOid()); + //妫�鏌ヨ寮曠敤涓嶈兘鍒犻櫎 + Integer count = btmTypeService.countByLifeId(lifeCycleDTO.getId()); + if(count !=null && count>0){ + throw new VciBaseException("鐢熷懡鍛ㄦ湡琚娇鐢紝涓嶈兘琚垹闄�"); + } + //鎴戜滑鏌ヨ鍏ㄩ儴node鍜宔dge锛岀劧鍚庝竴璧峰垹闄� + List<LifeCycleNode> nodeList = selectNodeByLifeOid(rule.getOid()); + List<LifeCycleEdge> edges = selectEdgeByLifeOid(rule.getOid()); + List<LifeCycleLineEvent> eventList = selectEventByEdgeOids(Optional.ofNullable(edges).orElseGet(ArrayList::new).stream().map(LifeCycleEdge::getOid).collect(Collectors.toList())); + if(!CollectionUtils.isEmpty(nodeList)){ + nodeMapper.deleteBatchIds(nodeList.stream().map(LifeCycleNode::getOid).collect(Collectors.toList())); + } + if(!CollectionUtils.isEmpty(edges)){ + edgeMapper.deleteBatchIds(edges.stream().map(LifeCycleEdge::getOid).collect(Collectors.toList())); + } + if(!CollectionUtils.isEmpty(eventList)){ + lineEventMapper.deleteBatchIds(eventList.stream().map(LifeCycleLineEvent::getOid).collect(Collectors.toList())); + } + baseMapper.deleteById(rule); + } + /** + * 鏌ヨ閾炬帴绾� + * @param lifeOid + * @return + */ + private List<LifeCycleEdge> selectEdgeByLifeOid(String lifeOid){ + if(!StringUtils.hasLength(lifeOid)){ + return new ArrayList<>(); + } + LambdaQueryWrapper<LifeCycleEdge> query = new LambdaQueryWrapper<LifeCycleEdge>(); + query.eq(LifeCycleEdge::getLifeCycleOid,lifeOid); + return edgeMapper.selectList(query); + } + + + /** + * 鑾峰彇鑺傜偣鐨勪俊鎭� + * @param lifeOids 鐢熷懡鍛ㄦ湡鐨勪富閿泦鍚� + * @return + */ + private List<LifeCycleEdge> selectEdgeByLifeOids(Collection<String> lifeOids){ + if(!CollectionUtils.isEmpty(lifeOids)){ + return new ArrayList<>(); + } + List<LifeCycleEdge> edgeList = new ArrayList<>(); + VciBaseUtil.switchCollectionForOracleIn(lifeOids).stream().forEach(lOids->{ + LambdaQueryWrapper<LifeCycleEdge> query = new LambdaQueryWrapper<LifeCycleEdge>(); + lOids.stream().forEach(lOid->{ + query.eq(LifeCycleEdge::getLifeCycleOid,lOid); + query.or(); + }); + query.eq(LifeCycleEdge::getLifeCycleOid,"-1"); + edgeList.addAll(edgeMapper.selectList(query)); + }); + return edgeList; + } + + /** + * 鏌ヨ閾炬帴绾夸笂鐨勪簨浠� + * @param edgeOids + * @return + */ + private List<LifeCycleLineEvent> selectEventByEdgeOids(Collection<String> edgeOids){ + if(CollectionUtils.isEmpty(edgeOids)){ + return new ArrayList<>(); + } + List<LifeCycleLineEvent> eventList = new ArrayList<>(); + VciBaseUtil.switchCollectionForOracleIn(edgeOids).stream().forEach(edgeOidList->{ + LambdaQueryWrapper<LifeCycleLineEvent> query = new LambdaQueryWrapper<LifeCycleLineEvent>(); + edgeOidList.stream().forEach(edgeOid->{ + query.eq(LifeCycleLineEvent::getPkLifeCycleEdge,edgeOid); + query.or(); + }); + query.eq(LifeCycleLineEvent::getPkLifeCycleEdge,"-1"); + eventList.addAll(lineEventMapper.selectList(query)); + }); + return eventList; + } + + + /** + * 鑾峰彇鑺傜偣鐨勪俊鎭� + * @param lifeOid + * @return + */ + private List<LifeCycleNode> selectNodeByLifeOid(String lifeOid){ + if(!StringUtils.hasLength(lifeOid)){ + return new ArrayList<>(); + } + LambdaQueryWrapper<LifeCycleNode> query = new LambdaQueryWrapper<LifeCycleNode>(); + query.eq(LifeCycleNode::getLifeCycleOid,lifeOid); + return nodeMapper.selectList(query); + } + + /** + * 鑾峰彇鑺傜偣鐨勪俊鎭� + * @param lifeOids 鐢熷懡鍛ㄦ湡鐨勪富閿泦鍚� + * @return + */ + private List<LifeCycleNode> selectNodeByLifeOids(Collection<String> lifeOids){ + if(!CollectionUtils.isEmpty(lifeOids)){ + return new ArrayList<>(); + } + List<LifeCycleNode> nodeList = new ArrayList<>(); + VciBaseUtil.switchCollectionForOracleIn(lifeOids).stream().forEach(lOids->{ + LambdaQueryWrapper<LifeCycleNode> query = new LambdaQueryWrapper<LifeCycleNode>(); + lOids.stream().forEach(lOid->{ + query.eq(LifeCycleNode::getLifeCycleOid,lOid); + query.or(); + }); + query.eq(LifeCycleNode::getLifeCycleOid,"-1"); + nodeList.addAll(nodeMapper.selectList(query)); + }); + return nodeList; } /** @@ -73,8 +626,33 @@ * @param lifeCycleDTOs 鏁版嵁浼犺緭瀵硅薄鍒楄〃 */ @Override + @Transactional public void batchDelete(List<LifeCycleDTO> lifeCycleDTOs) { - + VciBaseUtil.alertNotNull(lifeCycleDTOs,"鐢熷懡鍛ㄦ湡鐨勪俊鎭�"); + if(lifeCycleDTOs.stream().anyMatch(s->!StringUtils.hasLength(s.getOid()))){ + throw new VciBaseException("鐢熷懡鍛ㄦ湡鐨勪富閿笉鑳戒负绌�"); + } + List<String> oidList = lifeCycleDTOs.stream().map(LifeCycleDTO::getOid).collect(Collectors.toList()); + List<LifeCycleRule> lifeList = baseMapper.selectBatchIds(oidList); + //鎵归噺鏌ヨ + String usedBtmTypeId = Optional.ofNullable(btmTypeService.selectByLifeIds(lifeList.stream().map(LifeCycleRule::getId).collect(Collectors.toList()))).orElseGet(ArrayList::new).stream().map(BtmTypeVO::getId).collect(Collectors.joining(",")); + if(StringUtils.hasLength(usedBtmTypeId)){ + throw new VciBaseException(usedBtmTypeId + "杩欎簺涓氬姟绫诲瀷寮曠敤浜嗙敓鍛藉懆鏈燂紝涓嶈兘鍒犻櫎"); + } + List<LifeCycleNode> nodeList = selectNodeByLifeOids(oidList); + List<LifeCycleEdge> edgeList = selectEdgeByLifeOids(oidList); + if(!CollectionUtils.isEmpty(nodeList)){ + nodeMapper.deleteBatchIds(nodeList.stream().map(LifeCycleNode::getOid).collect(Collectors.toList())); + } + if(!CollectionUtils.isEmpty(edgeList)){ + List<String> edgeOids = edgeList.stream().map(LifeCycleEdge::getOid).collect(Collectors.toList()); + edgeMapper.deleteBatchIds(edgeOids); + List<LifeCycleLineEvent> eventList = selectEventByEdgeOids(edgeOids); + if(!CollectionUtils.isEmpty(eventList)){ + lineEventMapper.deleteBatchIds(eventList.stream().map(LifeCycleLineEvent::getOid).collect(Collectors.toList())); + } + } + baseMapper.deleteBatchIds(oidList); } /** @@ -85,6 +663,8 @@ */ @Override public List<BtmTypeVO> listUses(LifeCycleDTO lifeCycleDTO) { - return null; + VciBaseUtil.alertNotNull(lifeCycleDTO,"鏁版嵁浼犺緭瀵硅薄",lifeCycleDTO.getOid(),"涓婚敭"); + LifeCycleRule rule = selectByOid(lifeCycleDTO.getOid()); + return btmTypeService.selectByLifeId(rule.getId()); } } -- Gitblit v1.9.3