Merge branch 'refs/heads/develop'
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package com.solution.web.controller.rule;
|
||||
|
||||
import com.solution.common.core.controller.BaseController;
|
||||
import com.solution.common.core.domain.AjaxResult;
|
||||
import com.solution.rule.domain.FireRuleExecuteDTO;
|
||||
import com.solution.rule.service.FireRuleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
|
||||
@Api("火力规则")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/firerule")
|
||||
public class FireRuleController extends BaseController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private FireRuleService ruleService;
|
||||
|
||||
|
||||
/**
|
||||
* 开始执行规则匹配
|
||||
* @param fireRuleExecuteDTO 敌方参数
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/start")
|
||||
@ApiOperation("开始执行规则匹配")
|
||||
public AjaxResult execute(@RequestBody FireRuleExecuteDTO fireRuleExecuteDTO){
|
||||
return success(ruleService.execute(fireRuleExecuteDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有武器平台和组件
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/weapon")
|
||||
@ApiOperation("获取所有武器平台和组件")
|
||||
public AjaxResult getPlatformComponentNames(){
|
||||
return success(ruleService.getPlatformComponentNames());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取通信组件的所有平台和组件
|
||||
* @param scenarioId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/comm")
|
||||
@ApiOperation("获取通信组件的所有平台和组件")
|
||||
public AjaxResult getCommPlatformComponentNames(Integer scenarioId){
|
||||
return success(ruleService.getCommPlatformComponentNames(scenarioId));
|
||||
}
|
||||
}
|
||||
@@ -1,55 +1,65 @@
|
||||
package com.solution.web.controller.rule;
|
||||
|
||||
import com.solution.common.annotation.Log;
|
||||
import com.solution.common.core.controller.BaseController;
|
||||
import com.solution.common.core.domain.AjaxResult;
|
||||
import com.solution.rule.domain.FireRuleExecuteDTO;
|
||||
import com.solution.rule.service.RuleService;
|
||||
import com.solution.common.core.page.TableDataInfo;
|
||||
import com.solution.common.enums.BusinessType;
|
||||
import com.solution.rule.domain.Rule;
|
||||
import com.solution.rule.service.IRuleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Api("火力规则")
|
||||
@Api("红蓝对抗规则管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/firerule")
|
||||
@RequestMapping("/api/system/rule")
|
||||
public class RuleController extends BaseController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private RuleService ruleService;
|
||||
private IRuleService ruleService;
|
||||
|
||||
|
||||
/**
|
||||
* 开始执行规则匹配
|
||||
* @param fireRuleExecuteDTO 敌方参数
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/start")
|
||||
@ApiOperation("开始执行规则匹配")
|
||||
public AjaxResult execute(@RequestBody FireRuleExecuteDTO fireRuleExecuteDTO){
|
||||
return success(ruleService.execute(fireRuleExecuteDTO));
|
||||
@PreAuthorize("@ss.hasPermi('system:rule:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询规则列表")
|
||||
public TableDataInfo list(Rule rule) {
|
||||
startPage();
|
||||
List<Rule> list = ruleService.selectRuleList(rule);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有武器平台和组件
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/weapon")
|
||||
@ApiOperation("获取所有武器平台和组件")
|
||||
public AjaxResult getPlatformComponentNames(){
|
||||
return success(ruleService.getPlatformComponentNames());
|
||||
@PreAuthorize("@ss.hasPermi('system:rule:query')")
|
||||
@GetMapping("/{id}")
|
||||
@ApiOperation("获取规则详情")
|
||||
public AjaxResult getInfo(@PathVariable Integer id) {
|
||||
return success(ruleService.selectRuleById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取通信组件的所有平台和组件
|
||||
* @param scenarioId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/comm")
|
||||
@ApiOperation("获取通信组件的所有平台和组件")
|
||||
public AjaxResult getCommPlatformComponentNames(Integer scenarioId){
|
||||
return success(ruleService.getCommPlatformComponentNames(scenarioId));
|
||||
@PreAuthorize("@ss.hasPermi('system:rule:add')")
|
||||
@Log(title = "规则管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("新增规则")
|
||||
public AjaxResult add(@RequestBody Rule rule) {
|
||||
return toAjax(ruleService.insertRule(rule));
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:rule:edit')")
|
||||
@Log(title = "规则管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
@ApiOperation("修改规则")
|
||||
public AjaxResult edit(@RequestBody Rule rule) {
|
||||
return toAjax(ruleService.updateRule(rule));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:rule:remove')")
|
||||
@Log(title = "规则管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除规则")
|
||||
public AjaxResult remove(@PathVariable Integer[] ids) {
|
||||
return toAjax(ruleService.deleteRuleByIds(ids));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.solution.rule.mapper.FireRuleMapper">
|
||||
|
||||
|
||||
<resultMap id="platformComponentCountMap" type="com.solution.rule.domain.vo.WeaponModelVO">
|
||||
<result property="platformName" column="platform_name"/>
|
||||
<result property="componentName" column="component_name"/>
|
||||
<result property="count" column="count"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="PlatformComponentNamesVOResultMap" type="com.solution.rule.domain.vo.PlatformComponentNamesVO">
|
||||
<result property="platformName" column="platformName"/>
|
||||
<collection property="componentNames" ofType="java.lang.String">
|
||||
<result column="componentName"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="getWeapon" resultMap="platformComponentCountMap">
|
||||
SELECT
|
||||
p.name AS platform_name,
|
||||
pc.name AS component_name,
|
||||
COUNT(pc.name) AS count
|
||||
FROM platform p
|
||||
LEFT JOIN platform_component pc ON p.id = pc.platform_id
|
||||
GROUP BY p.id, p.name, pc.name
|
||||
ORDER BY p.id, pc.name
|
||||
|
||||
</select>
|
||||
|
||||
<select id="getPlatformComponentNames" resultType="com.solution.rule.domain.vo.WeaponModelVO">
|
||||
SELECT DISTINCT
|
||||
p.name AS platformName,
|
||||
pc.name AS componentName
|
||||
FROM platform p
|
||||
INNER JOIN platform_component pc ON p.id = pc.platform_id
|
||||
WHERE pc.name IS NOT NULL
|
||||
ORDER BY p.name, pc.name
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getModuleAndCount" resultType="com.solution.rule.domain.vo.ComponentCountVO">
|
||||
SELECT
|
||||
name AS componentName,
|
||||
COUNT(*) AS count
|
||||
FROM platform_component
|
||||
WHERE name IS NOT NULL
|
||||
GROUP BY name
|
||||
ORDER BY count DESC;
|
||||
</select>
|
||||
|
||||
<select id="getCommPlatformComponentNames" resultMap="PlatformComponentNamesVOResultMap"
|
||||
parameterType="java.lang.Integer">
|
||||
SELECT
|
||||
p.name AS platformName,
|
||||
pc.name AS componentName
|
||||
FROM platform p
|
||||
INNER JOIN platform_component pc ON p.id = pc.platform_id
|
||||
WHERE pc.type = "comm"
|
||||
AND p.scenario_id = #{scenarioId}
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -1,66 +1,97 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.solution.rule.mapper.RuleMapper">
|
||||
|
||||
|
||||
<resultMap id="platformComponentCountMap" type="com.solution.rule.domain.vo.WeaponModelVO">
|
||||
<result property="platformName" column="platform_name"/>
|
||||
<result property="componentName" column="component_name"/>
|
||||
<result property="count" column="count"/>
|
||||
<resultMap id="RuleResult" type="com.solution.rule.domain.Rule">
|
||||
<id property="id" column="id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="sceneType" column="scene_type"/>
|
||||
<result property="conditions" column="conditions"/>
|
||||
<result property="actions" column="actions"/>
|
||||
<result property="priority" column="priority"/>
|
||||
<result property="enabled" column="enabled"/>
|
||||
<result property="createdTime" column="created_time"/>
|
||||
<result property="updatedTime" column="updated_time"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="PlatformComponentNamesVOResultMap" type="com.solution.rule.domain.vo.PlatformComponentNamesVO">
|
||||
<result property="platformName" column="platformName"/>
|
||||
<collection property="componentNames" ofType="java.lang.String">
|
||||
<result column="componentName"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="getWeapon" resultMap="platformComponentCountMap">
|
||||
SELECT
|
||||
p.name AS platform_name,
|
||||
pc.name AS component_name,
|
||||
COUNT(pc.name) AS count
|
||||
FROM platform p
|
||||
LEFT JOIN platform_component pc ON p.id = pc.platform_id
|
||||
GROUP BY p.id, p.name, pc.name
|
||||
ORDER BY p.id, pc.name
|
||||
<sql id="selectRuleVo">
|
||||
select id, name, scene_type, conditions, actions, priority, enabled, created_time, updated_time
|
||||
from rule
|
||||
</sql>
|
||||
|
||||
<select id="selectRuleById" parameterType="Integer" resultMap="RuleResult">
|
||||
<include refid="selectRuleVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getPlatformComponentNames" resultType="com.solution.rule.domain.vo.WeaponModelVO">
|
||||
SELECT DISTINCT
|
||||
p.name AS platformName,
|
||||
pc.name AS componentName
|
||||
FROM platform p
|
||||
INNER JOIN platform_component pc ON p.id = pc.platform_id
|
||||
WHERE pc.name IS NOT NULL
|
||||
ORDER BY p.name, pc.name
|
||||
<select id="selectRuleList" parameterType="com.solution.rule.domain.Rule" resultMap="RuleResult">
|
||||
<include refid="selectRuleVo"/>
|
||||
<where>
|
||||
<if test="name != null and name != ''">
|
||||
AND name like concat('%', #{name}, '%')
|
||||
</if>
|
||||
<if test="sceneType != null">
|
||||
AND scene_type = #{sceneType}
|
||||
</if>
|
||||
<if test="enabled != null">
|
||||
AND enabled = #{enabled}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="insertRule" parameterType="com.solution.rule.domain.Rule" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into rule
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="name != null and name != ''">name,</if>
|
||||
<if test="sceneType != null">scene_type,</if>
|
||||
<if test="conditions != null">conditions,</if>
|
||||
<if test="actions != null">actions,</if>
|
||||
<if test="priority != null">priority,</if>
|
||||
<if test="enabled != null">enabled,</if>
|
||||
created_time,
|
||||
updated_time
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="name != null and name != ''">#{name},</if>
|
||||
<if test="sceneType != null">#{sceneType},</if>
|
||||
<if test="conditions != null">#{conditions},</if>
|
||||
<if test="actions != null">#{actions},</if>
|
||||
<if test="priority != null">#{priority},</if>
|
||||
<if test="enabled != null">#{enabled},</if>
|
||||
now(),
|
||||
now()
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<select id="getModuleAndCount" resultType="com.solution.rule.domain.vo.ComponentCountVO">
|
||||
SELECT
|
||||
name AS componentName,
|
||||
COUNT(*) AS count
|
||||
FROM platform_component
|
||||
WHERE name IS NOT NULL
|
||||
GROUP BY name
|
||||
ORDER BY count DESC;
|
||||
</select>
|
||||
<update id="updateRule" parameterType="com.solution.rule.domain.Rule">
|
||||
update rule
|
||||
<set>
|
||||
<if test="name != null and name != ''">name = #{name},</if>
|
||||
<if test="sceneType != null">scene_type = #{sceneType},</if>
|
||||
<if test="conditions != null">conditions = #{conditions},</if>
|
||||
<if test="actions != null">actions = #{actions},</if>
|
||||
<if test="priority != null">priority = #{priority},</if>
|
||||
<if test="enabled != null">enabled = #{enabled},</if>
|
||||
updated_time = now()
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="getCommPlatformComponentNames" resultMap="PlatformComponentNamesVOResultMap"
|
||||
parameterType="java.lang.Integer">
|
||||
SELECT
|
||||
p.name AS platformName,
|
||||
pc.name AS componentName
|
||||
FROM platform p
|
||||
INNER JOIN platform_component pc ON p.id = pc.platform_id
|
||||
WHERE pc.type = "comm"
|
||||
AND p.scenario_id = #{scenarioId}
|
||||
</select>
|
||||
<delete id="deleteRuleById" parameterType="Integer">
|
||||
delete from rule where id = #{id}
|
||||
</delete>
|
||||
|
||||
<!--<delete id="deleteRuleByIds" parameterType="String">
|
||||
delete from rule where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>-->
|
||||
<delete id="deleteRuleByIds">
|
||||
delete from rule where id in
|
||||
<foreach item="id" collection="ids" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user