26-03-14-14:30 规则CRUD
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.solution.rule.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@ApiModel("红蓝对抗规则")
|
||||
public class Rule {
|
||||
@ApiModelProperty("规则ID")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty("规则名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("场景类型:0-防御,1-空降,null表示通用")
|
||||
private Integer sceneType;
|
||||
|
||||
@ApiModelProperty("触发条件(JSON格式)")
|
||||
private String conditions;
|
||||
|
||||
@ApiModelProperty("响应动作(JSON格式)")
|
||||
private String actions;
|
||||
|
||||
@ApiModelProperty("优先级(数值越小优先级越高)")
|
||||
private Integer priority;
|
||||
|
||||
@ApiModelProperty("是否启用(0禁用,1启用)")
|
||||
private Boolean enabled;
|
||||
|
||||
@ApiModelProperty("创建时间")
|
||||
private Date createdTime;
|
||||
|
||||
@ApiModelProperty("更新时间")
|
||||
private Date updatedTime;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.solution.rule.mapper;
|
||||
|
||||
import com.solution.rule.domain.vo.ComponentCountVO;
|
||||
import com.solution.rule.domain.vo.PlatformComponentNamesVO;
|
||||
import com.solution.rule.domain.vo.WeaponModelVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface FireRuleMapper {
|
||||
|
||||
/**
|
||||
* 获取所有武器平台和组件
|
||||
* @return
|
||||
*/
|
||||
List<WeaponModelVO> getWeapon();
|
||||
|
||||
List<WeaponModelVO> getPlatformComponentNames();
|
||||
|
||||
/**
|
||||
* 获取所有组件以及数量
|
||||
* @return
|
||||
*/
|
||||
List<ComponentCountVO> getModuleAndCount();
|
||||
|
||||
/**
|
||||
* 获取通信组件的所有平台和组件
|
||||
* @param scenarioId
|
||||
* @return
|
||||
*/
|
||||
List<PlatformComponentNamesVO> getCommPlatformComponentNames(Integer scenarioId);
|
||||
|
||||
|
||||
}
|
||||
@@ -1,34 +1,38 @@
|
||||
package com.solution.rule.mapper;
|
||||
|
||||
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||
import com.solution.rule.domain.vo.ComponentCountVO;
|
||||
import com.solution.rule.domain.vo.PlatformComponentNamesVO;
|
||||
import com.solution.rule.domain.vo.WeaponModelVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.solution.rule.domain.Rule;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface RuleMapper {
|
||||
/**
|
||||
* 根据ID查询规则
|
||||
*/
|
||||
Rule selectRuleById(Integer id);
|
||||
|
||||
/**
|
||||
* 获取所有武器平台和组件
|
||||
* @return
|
||||
* 查询规则列表(支持分页)
|
||||
*/
|
||||
List<WeaponModelVO> getWeapon();
|
||||
|
||||
List<WeaponModelVO> getPlatformComponentNames();
|
||||
List<Rule> selectRuleList(Rule rule);
|
||||
|
||||
/**
|
||||
* 获取所有组件以及数量
|
||||
* @return
|
||||
* 新增规则
|
||||
*/
|
||||
List<ComponentCountVO> getModuleAndCount();
|
||||
int insertRule(Rule rule);
|
||||
|
||||
/**
|
||||
* 获取通信组件的所有平台和组件
|
||||
* @param scenarioId
|
||||
* @return
|
||||
* 修改规则
|
||||
*/
|
||||
List<PlatformComponentNamesVO> getCommPlatformComponentNames(Integer scenarioId);
|
||||
}
|
||||
int updateRule(Rule rule);
|
||||
|
||||
/**
|
||||
* 删除规则
|
||||
*/
|
||||
int deleteRuleById(Integer id);
|
||||
|
||||
/**
|
||||
* 批量删除规则
|
||||
*/
|
||||
int deleteRuleByIds(@Param("ids")Integer[] ids);
|
||||
}
|
||||
@@ -1,16 +1,12 @@
|
||||
package com.solution.rule.service;
|
||||
|
||||
import com.solution.rule.domain.FireRuleExecuteDTO;
|
||||
import com.solution.rule.domain.dto.RequestDTO;
|
||||
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||
import com.solution.rule.domain.vo.PlatformComponentNamesVO;
|
||||
import com.solution.rule.domain.vo.PlatformWeaponAggregateVO;
|
||||
import com.solution.rule.domain.vo.WeaponModelVO;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public interface RuleService {
|
||||
public interface FireRuleService {
|
||||
|
||||
/**
|
||||
* 开始执行规则匹配
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.solution.rule.service;
|
||||
|
||||
import com.solution.rule.domain.Rule;
|
||||
import java.util.List;
|
||||
|
||||
public interface IRuleService {
|
||||
/**
|
||||
* 根据ID查询规则
|
||||
*/
|
||||
Rule selectRuleById(Integer id);
|
||||
|
||||
/**
|
||||
* 查询规则列表
|
||||
*/
|
||||
List<Rule> selectRuleList(Rule rule);
|
||||
|
||||
/**
|
||||
* 新增规则
|
||||
*/
|
||||
int insertRule(Rule rule);
|
||||
|
||||
/**
|
||||
* 修改规则
|
||||
*/
|
||||
int updateRule(Rule rule);
|
||||
|
||||
/**
|
||||
* 删除规则
|
||||
*/
|
||||
int deleteRuleById(Integer id);
|
||||
|
||||
/**
|
||||
* 批量删除规则
|
||||
*/
|
||||
int deleteRuleByIds(Integer[] ids);
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package com.solution.rule.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.solution.common.constant.ExceptionConstants;
|
||||
import com.solution.rule.domain.FireRuleExecuteDTO;
|
||||
import com.solution.rule.domain.RuleParam;
|
||||
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||
import com.solution.rule.domain.vo.ComponentCountVO;
|
||||
import com.solution.rule.domain.vo.PlatformComponentNamesVO;
|
||||
import com.solution.rule.domain.vo.PlatformWeaponAggregateVO;
|
||||
import com.solution.rule.domain.vo.WeaponModelVO;
|
||||
import com.solution.rule.mapper.FireRuleMapper;
|
||||
import com.solution.rule.service.FireRuleService;
|
||||
import com.solution.rule.strategy.SceneStrategy;
|
||||
import com.solution.rule.strategy.SceneStrategyFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class FireRuleServiceImpl implements FireRuleService {
|
||||
|
||||
private static final long COMPONENT_QUANTITY_THRESHOLD = 1;
|
||||
|
||||
@Autowired
|
||||
private SceneStrategyFactory strategyFactory;
|
||||
|
||||
@Autowired
|
||||
private FireRuleMapper ruleMapper;
|
||||
|
||||
/* @Override
|
||||
public WeaponModelVO execute(Integer sceneType, WeaponModelDTO weaponModelDTO) {
|
||||
if(ObjectUtil.isNull(sceneType) || ObjectUtil.isEmpty(weaponModelDTO)){
|
||||
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
|
||||
}
|
||||
//TODO 查数据库获取我方装备
|
||||
List<PlatformWeaponAggregateVO> weapon = this.getWeapon();
|
||||
|
||||
SceneStrategy strategy = strategyFactory.getStrategy(sceneType);
|
||||
WeaponModelVO result = strategy.execute(weaponModelDTO);
|
||||
if(ObjectUtil.isEmpty(result)){
|
||||
throw new RuntimeException(ExceptionConstants.RESULT_EXCEPTION);
|
||||
}
|
||||
return result;
|
||||
}*/
|
||||
|
||||
|
||||
@Override
|
||||
public List<PlatformWeaponAggregateVO> execute(FireRuleExecuteDTO fireRuleExecuteDTO) {
|
||||
if(ObjectUtil.isEmpty(fireRuleExecuteDTO)){
|
||||
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
|
||||
}
|
||||
List<WeaponModelDTO> weaponModelDTOs = fireRuleExecuteDTO.getWeaponModelDTOs();
|
||||
Integer sceneType = fireRuleExecuteDTO.getSceneType();
|
||||
// 查数据库获取我方装备
|
||||
List<ComponentCountVO> weapon = this.getModuleAndCount();
|
||||
|
||||
// 创建RuleParam并设置数据
|
||||
RuleParam ruleParam = new RuleParam();
|
||||
ruleParam.setWeaponModelDTOList(weaponModelDTOs);
|
||||
ruleParam.setDatabaseWeapons(weapon);
|
||||
|
||||
// 执行策略
|
||||
SceneStrategy strategy = strategyFactory.getStrategy(sceneType);
|
||||
List<PlatformWeaponAggregateVO> result = strategy.execute(ruleParam);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlatformWeaponAggregateVO> getWeapon() {
|
||||
List<WeaponModelVO> flatList = ruleMapper.getWeapon();
|
||||
if (CollUtil.isEmpty(flatList)) {
|
||||
throw new RuntimeException(ExceptionConstants.RESULT_EXCEPTION);
|
||||
}
|
||||
|
||||
Map<String, List<WeaponModelVO>> groupByPlatform = flatList.stream()
|
||||
.collect(Collectors.groupingBy(WeaponModelVO::getPlatformName));
|
||||
|
||||
List<PlatformWeaponAggregateVO> result = new ArrayList<>();
|
||||
for (Map.Entry<String, List<WeaponModelVO>> entry : groupByPlatform.entrySet()) {
|
||||
PlatformWeaponAggregateVO platformVO = new PlatformWeaponAggregateVO();
|
||||
platformVO.setPlatformName(entry.getKey());
|
||||
|
||||
List<ComponentCountVO> components = entry.getValue().stream()
|
||||
.map(item -> {
|
||||
ComponentCountVO comp = new ComponentCountVO();
|
||||
comp.setComponentName(item.getComponentName());
|
||||
comp.setCount(item.getCount());
|
||||
return comp;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
platformVO.setComponentCountVOS(components);
|
||||
|
||||
result.add(platformVO);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有武器平台和组件
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<PlatformComponentNamesVO> getPlatformComponentNames() {
|
||||
List<WeaponModelVO> flatList = ruleMapper.getPlatformComponentNames();
|
||||
if (CollUtil.isEmpty(flatList)) {
|
||||
throw new RuntimeException(ExceptionConstants.RESULT_EXCEPTION);
|
||||
}
|
||||
|
||||
|
||||
Map<String, List<String>> groupByPlatform = flatList.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
WeaponModelVO::getPlatformName,
|
||||
Collectors.mapping(WeaponModelVO::getComponentName, Collectors.toList())
|
||||
));
|
||||
|
||||
return groupByPlatform.entrySet().stream()
|
||||
.map(entry -> {
|
||||
PlatformComponentNamesVO vo = new PlatformComponentNamesVO();
|
||||
vo.setPlatformName(entry.getKey());
|
||||
vo.setComponentNames(entry.getValue());
|
||||
return vo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取通信组件的所有平台和组件
|
||||
* @param scenarioId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<PlatformComponentNamesVO> getCommPlatformComponentNames(Integer scenarioId) {
|
||||
return ruleMapper.getCommPlatformComponentNames(scenarioId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有组件以及数量
|
||||
* @return
|
||||
*/
|
||||
private List<ComponentCountVO> getModuleAndCount(){
|
||||
List<ComponentCountVO> componentCountVOS = ruleMapper.getModuleAndCount();
|
||||
if(CollUtil.isEmpty(componentCountVOS)){
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return componentCountVOS;
|
||||
}
|
||||
}
|
||||
@@ -1,156 +1,46 @@
|
||||
package com.solution.rule.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.solution.common.constant.ExceptionConstants;
|
||||
import com.solution.rule.domain.FireRuleExecuteDTO;
|
||||
import com.solution.rule.domain.RuleParam;
|
||||
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||
import com.solution.rule.domain.vo.ComponentCountVO;
|
||||
import com.solution.rule.domain.vo.PlatformComponentNamesVO;
|
||||
import com.solution.rule.domain.vo.PlatformWeaponAggregateVO;
|
||||
import com.solution.rule.domain.vo.WeaponModelVO;
|
||||
import com.solution.rule.domain.Rule;
|
||||
import com.solution.rule.mapper.RuleMapper;
|
||||
import com.solution.rule.service.RuleService;
|
||||
import com.solution.rule.strategy.SceneStrategy;
|
||||
import com.solution.rule.strategy.SceneStrategyFactory;
|
||||
import com.solution.rule.service.IRuleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class RuleServiceImpl implements RuleService {
|
||||
|
||||
private static final long COMPONENT_QUANTITY_THRESHOLD = 1;
|
||||
|
||||
@Autowired
|
||||
private SceneStrategyFactory strategyFactory;
|
||||
public class RuleServiceImpl implements IRuleService {
|
||||
|
||||
@Autowired
|
||||
private RuleMapper ruleMapper;
|
||||
|
||||
/* @Override
|
||||
public WeaponModelVO execute(Integer sceneType, WeaponModelDTO weaponModelDTO) {
|
||||
if(ObjectUtil.isNull(sceneType) || ObjectUtil.isEmpty(weaponModelDTO)){
|
||||
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
|
||||
}
|
||||
//TODO 查数据库获取我方装备
|
||||
List<PlatformWeaponAggregateVO> weapon = this.getWeapon();
|
||||
|
||||
SceneStrategy strategy = strategyFactory.getStrategy(sceneType);
|
||||
WeaponModelVO result = strategy.execute(weaponModelDTO);
|
||||
if(ObjectUtil.isEmpty(result)){
|
||||
throw new RuntimeException(ExceptionConstants.RESULT_EXCEPTION);
|
||||
}
|
||||
return result;
|
||||
}*/
|
||||
|
||||
|
||||
@Override
|
||||
public List<PlatformWeaponAggregateVO> execute(FireRuleExecuteDTO fireRuleExecuteDTO) {
|
||||
if(ObjectUtil.isEmpty(fireRuleExecuteDTO)){
|
||||
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
|
||||
}
|
||||
List<WeaponModelDTO> weaponModelDTOs = fireRuleExecuteDTO.getWeaponModelDTOs();
|
||||
Integer sceneType = fireRuleExecuteDTO.getSceneType();
|
||||
// 查数据库获取我方装备
|
||||
List<ComponentCountVO> weapon = this.getModuleAndCount();
|
||||
|
||||
// 创建RuleParam并设置数据
|
||||
RuleParam ruleParam = new RuleParam();
|
||||
ruleParam.setWeaponModelDTOList(weaponModelDTOs);
|
||||
ruleParam.setDatabaseWeapons(weapon);
|
||||
|
||||
// 执行策略
|
||||
SceneStrategy strategy = strategyFactory.getStrategy(sceneType);
|
||||
List<PlatformWeaponAggregateVO> result = strategy.execute(ruleParam);
|
||||
|
||||
return result;
|
||||
public Rule selectRuleById(Integer id) {
|
||||
return ruleMapper.selectRuleById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlatformWeaponAggregateVO> getWeapon() {
|
||||
List<WeaponModelVO> flatList = ruleMapper.getWeapon();
|
||||
if (CollUtil.isEmpty(flatList)) {
|
||||
throw new RuntimeException(ExceptionConstants.RESULT_EXCEPTION);
|
||||
}
|
||||
|
||||
Map<String, List<WeaponModelVO>> groupByPlatform = flatList.stream()
|
||||
.collect(Collectors.groupingBy(WeaponModelVO::getPlatformName));
|
||||
|
||||
List<PlatformWeaponAggregateVO> result = new ArrayList<>();
|
||||
for (Map.Entry<String, List<WeaponModelVO>> entry : groupByPlatform.entrySet()) {
|
||||
PlatformWeaponAggregateVO platformVO = new PlatformWeaponAggregateVO();
|
||||
platformVO.setPlatformName(entry.getKey());
|
||||
|
||||
List<ComponentCountVO> components = entry.getValue().stream()
|
||||
.map(item -> {
|
||||
ComponentCountVO comp = new ComponentCountVO();
|
||||
comp.setComponentName(item.getComponentName());
|
||||
comp.setCount(item.getCount());
|
||||
return comp;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
platformVO.setComponentCountVOS(components);
|
||||
|
||||
result.add(platformVO);
|
||||
}
|
||||
|
||||
return result;
|
||||
public List<Rule> selectRuleList(Rule rule) {
|
||||
return ruleMapper.selectRuleList(rule);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有武器平台和组件
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<PlatformComponentNamesVO> getPlatformComponentNames() {
|
||||
List<WeaponModelVO> flatList = ruleMapper.getPlatformComponentNames();
|
||||
if (CollUtil.isEmpty(flatList)) {
|
||||
throw new RuntimeException(ExceptionConstants.RESULT_EXCEPTION);
|
||||
}
|
||||
|
||||
|
||||
Map<String, List<String>> groupByPlatform = flatList.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
WeaponModelVO::getPlatformName,
|
||||
Collectors.mapping(WeaponModelVO::getComponentName, Collectors.toList())
|
||||
));
|
||||
|
||||
return groupByPlatform.entrySet().stream()
|
||||
.map(entry -> {
|
||||
PlatformComponentNamesVO vo = new PlatformComponentNamesVO();
|
||||
vo.setPlatformName(entry.getKey());
|
||||
vo.setComponentNames(entry.getValue());
|
||||
return vo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
public int insertRule(Rule rule) {
|
||||
return ruleMapper.insertRule(rule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取通信组件的所有平台和组件
|
||||
* @param scenarioId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<PlatformComponentNamesVO> getCommPlatformComponentNames(Integer scenarioId) {
|
||||
return ruleMapper.getCommPlatformComponentNames(scenarioId);
|
||||
public int updateRule(Rule rule) {
|
||||
return ruleMapper.updateRule(rule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有组件以及数量
|
||||
* @return
|
||||
*/
|
||||
private List<ComponentCountVO> getModuleAndCount(){
|
||||
List<ComponentCountVO> componentCountVOS = ruleMapper.getModuleAndCount();
|
||||
if(CollUtil.isEmpty(componentCountVOS)){
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return componentCountVOS;
|
||||
@Override
|
||||
public int deleteRuleById(Integer id) {
|
||||
return ruleMapper.deleteRuleById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteRuleByIds(Integer[] ids) {
|
||||
return ruleMapper.deleteRuleByIds(ids);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user