From c8cb1f134df2fafc45f1128893a865143ce2bc9e Mon Sep 17 00:00:00 2001 From: wang1 <844966816@qq.com> Date: 星期三, 05 七月 2023 17:06:16 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/LifeCycleServiceImpl.java | 273 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 265 insertions(+), 8 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..f731a5d 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,49 @@ 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.dto.LifeCycleEdgeDTO; +import com.vci.ubcs.omd.dto.LifeCycleLineEventDTO; +import com.vci.ubcs.omd.dto.LifeCycleNodeDTO; +import com.vci.ubcs.omd.entity.LifeCycleEdge; +import com.vci.ubcs.omd.entity.LifeCycleLineEvent; +import com.vci.ubcs.omd.entity.LifeCycleNode; import com.vci.ubcs.omd.entity.LifeCycleRule; +import com.vci.ubcs.omd.mapper.LifeCycleEdgeMapper; +import com.vci.ubcs.omd.mapper.LifeCycleLineEventMapper; import com.vci.ubcs.omd.mapper.LifeCycleMapper; +import com.vci.ubcs.omd.mapper.LifeCycleNodeMapper; +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.service.IStatusService; 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.vo.StatusVO; +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 +53,49 @@ @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; + /** * 鑾峰彇鐢熷懡鍛ㄦ湡鍒楄〃 * * @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))); } /** @@ -42,9 +105,160 @@ * @return 娣诲姞鍚庣殑鏄剧ず瀵硅薄 */ @Override + @Transactional public LifeCycleVO addSave(LifeCycleDTO lifeCycleDTO) { - return null; + VciBaseUtil.alertNotNull(lifeCycleDTO,"鐢熷懡鍛ㄦ湡淇℃伅",lifeCycleDTO.getId(),"鐢熷懡鍛ㄦ湡鐨勭紪鍙�",lifeCycleDTO.getName(),"鐢熷懡鍛ㄦ湡鍚嶇О",lifeCycleDTO.getNodes(),"鐢熷懡鍛ㄦ湡鐨勮妭鐐�",lifeCycleDTO.getStartStatus(),"璧峰鐘舵��"); + //鍏堟煡璇㈡槸鍚﹀瓨鍦� + QueryWrapper wrapper = new QueryWrapper(LifeCycleRule.class); + wrapper.eq("lower(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.setBtmname(BtmTypeConstant.LIFE_CYCLE); + life.setOwner(creator); + 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.setBtmname(BtmTypeConstant.LIFE_CYCLE_LINE_EVENT); + event.setOwner(creator); + 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.setBtmname(BtmTypeConstant.LIFE_CYCLE_NODE); + node.setOwner(creator); + 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(),"鐩爣鐘舵��",edgeDTO.getName(),"杩炴帴绾垮悕绉�"); + 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.setBtmname(BtmTypeConstant.LIFE_CYCLE_EDGE); + edge.setOwner(creator); + edge.setCreator(creator); + edge.setCreateTime(now); + edge.setLastModifier(creator); + edge.setLastModifyTime(now); + edge.setTs(now); + edgeMapper.insert(edge); + return edge.getOid(); + } + + /** * 鎵归噺娣诲姞鍐呭 @@ -53,8 +267,40 @@ * @return 娣诲姞鍚庣殑鏄剧ず瀵硅薄 */ @Override + @Transactional public List<LifeCycleVO> batchAddSave(List<LifeCycleDTO> lifeCycleDTOs) { - return null; + 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(LifeCycleDTO::getId)); + 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.toLowerCase(Locale.ROOT)); + 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)); } /** @@ -64,7 +310,18 @@ */ @Override public void delete(LifeCycleDTO lifeCycleDTO) { + VciBaseUtil.alertNotNull(lifeCycleDTO,"鏁版嵁浼犺緭瀵硅薄",lifeCycleDTO.getOid(),"涓婚敭"); + LifeCycleRule rule = null; + try { + rule = getById(lifeCycleDTO.getOid()); + }catch (Throwable e){ + throw new VciBaseException("浣跨敤涓婚敭鑾峰彇瀵硅薄鍑洪敊锛岃繖涓暟鎹彲鑳戒笉瀛樺湪锛屾垨鑰呮暟鎹噸澶嶄簡"); + } + //妫�鏌ヨ寮曠敤涓嶈兘鍒犻櫎 + Integer count = btmTypeService.countByLifeId(lifeCycleDTO.getOid()); + if(count !=null && count>0){ + } } /** -- Gitblit v1.9.3