| | |
| | | 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; |
| | | |
| | | |
| | | /** |
| | | * çå½å¨æçæå¡ |
| | |
| | | @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))); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * æ¹éæ·»å å
容 |
| | |
| | | * @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)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @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){ |
| | | |
| | | } |
| | | } |
| | | |
| | | /** |