26-03-14-14:30 规则CRUD
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;
|
package com.solution.web.controller.rule;
|
||||||
|
|
||||||
|
import com.solution.common.annotation.Log;
|
||||||
import com.solution.common.core.controller.BaseController;
|
import com.solution.common.core.controller.BaseController;
|
||||||
import com.solution.common.core.domain.AjaxResult;
|
import com.solution.common.core.domain.AjaxResult;
|
||||||
import com.solution.rule.domain.FireRuleExecuteDTO;
|
import com.solution.common.core.page.TableDataInfo;
|
||||||
import com.solution.rule.service.RuleService;
|
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.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Api("红蓝对抗规则管理")
|
||||||
@Api("火力规则")
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/system/firerule")
|
@RequestMapping("/api/system/rule")
|
||||||
public class RuleController extends BaseController {
|
public class RuleController extends BaseController {
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RuleService ruleService;
|
private IRuleService ruleService;
|
||||||
|
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:rule:list')")
|
||||||
/**
|
@GetMapping("/list")
|
||||||
* 开始执行规则匹配
|
@ApiOperation("查询规则列表")
|
||||||
* @param fireRuleExecuteDTO 敌方参数
|
public TableDataInfo list(Rule rule) {
|
||||||
* @return
|
startPage();
|
||||||
*/
|
List<Rule> list = ruleService.selectRuleList(rule);
|
||||||
@PostMapping("/start")
|
return getDataTable(list);
|
||||||
@ApiOperation("开始执行规则匹配")
|
|
||||||
public AjaxResult execute(@RequestBody FireRuleExecuteDTO fireRuleExecuteDTO){
|
|
||||||
return success(ruleService.execute(fireRuleExecuteDTO));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@PreAuthorize("@ss.hasPermi('system:rule:query')")
|
||||||
* 获取所有武器平台和组件
|
@GetMapping("/{id}")
|
||||||
* @return
|
@ApiOperation("获取规则详情")
|
||||||
*/
|
public AjaxResult getInfo(@PathVariable Integer id) {
|
||||||
@GetMapping("/weapon")
|
return success(ruleService.selectRuleById(id));
|
||||||
@ApiOperation("获取所有武器平台和组件")
|
|
||||||
public AjaxResult getPlatformComponentNames(){
|
|
||||||
return success(ruleService.getPlatformComponentNames());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@PreAuthorize("@ss.hasPermi('system:rule:add')")
|
||||||
* 获取通信组件的所有平台和组件
|
@Log(title = "规则管理", businessType = BusinessType.INSERT)
|
||||||
* @param scenarioId
|
@PostMapping
|
||||||
* @return
|
@ApiOperation("新增规则")
|
||||||
*/
|
public AjaxResult add(@RequestBody Rule rule) {
|
||||||
@GetMapping("/comm")
|
return toAjax(ruleService.insertRule(rule));
|
||||||
@ApiOperation("获取通信组件的所有平台和组件")
|
}
|
||||||
public AjaxResult getCommPlatformComponentNames(Integer scenarioId){
|
|
||||||
return success(ruleService.getCommPlatformComponentNames(scenarioId));
|
@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;
|
package com.solution.rule.mapper;
|
||||||
|
|
||||||
import com.solution.rule.domain.dto.WeaponModelDTO;
|
import com.solution.rule.domain.Rule;
|
||||||
import com.solution.rule.domain.vo.ComponentCountVO;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import com.solution.rule.domain.vo.PlatformComponentNamesVO;
|
|
||||||
import com.solution.rule.domain.vo.WeaponModelVO;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface RuleMapper {
|
public interface RuleMapper {
|
||||||
|
/**
|
||||||
|
* 根据ID查询规则
|
||||||
|
*/
|
||||||
|
Rule selectRuleById(Integer id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有武器平台和组件
|
* 查询规则列表(支持分页)
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
List<WeaponModelVO> getWeapon();
|
List<Rule> selectRuleList(Rule rule);
|
||||||
|
|
||||||
List<WeaponModelVO> getPlatformComponentNames();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有组件以及数量
|
* 新增规则
|
||||||
* @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;
|
package com.solution.rule.service;
|
||||||
|
|
||||||
import com.solution.rule.domain.FireRuleExecuteDTO;
|
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.PlatformComponentNamesVO;
|
||||||
import com.solution.rule.domain.vo.PlatformWeaponAggregateVO;
|
import com.solution.rule.domain.vo.PlatformWeaponAggregateVO;
|
||||||
import com.solution.rule.domain.vo.WeaponModelVO;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
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;
|
package com.solution.rule.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import com.solution.rule.domain.Rule;
|
||||||
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.RuleMapper;
|
import com.solution.rule.mapper.RuleMapper;
|
||||||
import com.solution.rule.service.RuleService;
|
import com.solution.rule.service.IRuleService;
|
||||||
import com.solution.rule.strategy.SceneStrategy;
|
|
||||||
import com.solution.rule.strategy.SceneStrategyFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class RuleServiceImpl implements RuleService {
|
public class RuleServiceImpl implements IRuleService {
|
||||||
|
|
||||||
private static final long COMPONENT_QUANTITY_THRESHOLD = 1;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SceneStrategyFactory strategyFactory;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RuleMapper ruleMapper;
|
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
|
@Override
|
||||||
public List<PlatformWeaponAggregateVO> execute(FireRuleExecuteDTO fireRuleExecuteDTO) {
|
public Rule selectRuleById(Integer id) {
|
||||||
if(ObjectUtil.isEmpty(fireRuleExecuteDTO)){
|
return ruleMapper.selectRuleById(id);
|
||||||
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
|
@Override
|
||||||
public List<PlatformWeaponAggregateVO> getWeapon() {
|
public List<Rule> selectRuleList(Rule rule) {
|
||||||
List<WeaponModelVO> flatList = ruleMapper.getWeapon();
|
return ruleMapper.selectRuleList(rule);
|
||||||
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
|
@Override
|
||||||
public List<PlatformComponentNamesVO> getPlatformComponentNames() {
|
public int insertRule(Rule rule) {
|
||||||
List<WeaponModelVO> flatList = ruleMapper.getPlatformComponentNames();
|
return ruleMapper.insertRule(rule);
|
||||||
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
|
@Override
|
||||||
public List<PlatformComponentNamesVO> getCommPlatformComponentNames(Integer scenarioId) {
|
public int updateRule(Rule rule) {
|
||||||
return ruleMapper.getCommPlatformComponentNames(scenarioId);
|
return ruleMapper.updateRule(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 获取所有组件以及数量
|
public int deleteRuleById(Integer id) {
|
||||||
* @return
|
return ruleMapper.deleteRuleById(id);
|
||||||
*/
|
|
||||||
private List<ComponentCountVO> getModuleAndCount(){
|
|
||||||
List<ComponentCountVO> componentCountVOS = ruleMapper.getModuleAndCount();
|
|
||||||
if(CollUtil.isEmpty(componentCountVOS)){
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
}
|
||||||
return componentCountVOS;
|
|
||||||
|
@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" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!DOCTYPE mapper
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.solution.rule.mapper.RuleMapper">
|
<mapper namespace="com.solution.rule.mapper.RuleMapper">
|
||||||
|
|
||||||
|
<resultMap id="RuleResult" type="com.solution.rule.domain.Rule">
|
||||||
<resultMap id="platformComponentCountMap" type="com.solution.rule.domain.vo.WeaponModelVO">
|
<id property="id" column="id"/>
|
||||||
<result property="platformName" column="platform_name"/>
|
<result property="name" column="name"/>
|
||||||
<result property="componentName" column="component_name"/>
|
<result property="sceneType" column="scene_type"/>
|
||||||
<result property="count" column="count"/>
|
<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>
|
||||||
|
|
||||||
<resultMap id="PlatformComponentNamesVOResultMap" type="com.solution.rule.domain.vo.PlatformComponentNamesVO">
|
<sql id="selectRuleVo">
|
||||||
<result property="platformName" column="platformName"/>
|
select id, name, scene_type, conditions, actions, priority, enabled, created_time, updated_time
|
||||||
<collection property="componentNames" ofType="java.lang.String">
|
from rule
|
||||||
<result column="componentName"/>
|
</sql>
|
||||||
</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 id="selectRuleById" parameterType="Integer" resultMap="RuleResult">
|
||||||
|
<include refid="selectRuleVo"/>
|
||||||
|
where id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getPlatformComponentNames" resultType="com.solution.rule.domain.vo.WeaponModelVO">
|
<select id="selectRuleList" parameterType="com.solution.rule.domain.Rule" resultMap="RuleResult">
|
||||||
SELECT DISTINCT
|
<include refid="selectRuleVo"/>
|
||||||
p.name AS platformName,
|
<where>
|
||||||
pc.name AS componentName
|
<if test="name != null and name != ''">
|
||||||
FROM platform p
|
AND name like concat('%', #{name}, '%')
|
||||||
INNER JOIN platform_component pc ON p.id = pc.platform_id
|
</if>
|
||||||
WHERE pc.name IS NOT NULL
|
<if test="sceneType != null">
|
||||||
ORDER BY p.name, pc.name
|
AND scene_type = #{sceneType}
|
||||||
|
</if>
|
||||||
|
<if test="enabled != null">
|
||||||
|
AND enabled = #{enabled}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
</select>
|
</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">
|
<update id="updateRule" parameterType="com.solution.rule.domain.Rule">
|
||||||
SELECT
|
update rule
|
||||||
name AS componentName,
|
<set>
|
||||||
COUNT(*) AS count
|
<if test="name != null and name != ''">name = #{name},</if>
|
||||||
FROM platform_component
|
<if test="sceneType != null">scene_type = #{sceneType},</if>
|
||||||
WHERE name IS NOT NULL
|
<if test="conditions != null">conditions = #{conditions},</if>
|
||||||
GROUP BY name
|
<if test="actions != null">actions = #{actions},</if>
|
||||||
ORDER BY count DESC;
|
<if test="priority != null">priority = #{priority},</if>
|
||||||
</select>
|
<if test="enabled != null">enabled = #{enabled},</if>
|
||||||
|
updated_time = now()
|
||||||
|
</set>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
<select id="getCommPlatformComponentNames" resultMap="PlatformComponentNamesVOResultMap"
|
<delete id="deleteRuleById" parameterType="Integer">
|
||||||
parameterType="java.lang.Integer">
|
delete from rule where id = #{id}
|
||||||
SELECT
|
</delete>
|
||||||
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="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>
|
</mapper>
|
||||||
Reference in New Issue
Block a user