From c1c67e826b2cf35c981b615d6abb33e5557bc149 Mon Sep 17 00:00:00 2001 From: MHW Date: Sat, 14 Mar 2026 14:30:52 +0800 Subject: [PATCH] =?UTF-8?q?26-03-14-14:30=20=E8=A7=84=E5=88=99CRUD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/rule/FireRuleController.java | 55 ++++++ .../web/controller/rule/RuleController.java | 80 +++++---- ...lgorithmMapper.xml => FireRuleService.xml} | 0 ...meterdefMapper.xml => FireRuleService.xml} | 0 ...GenTableMapper.xml => FireRuleService.xml} | 0 .../java/com/solution/rule/domain/Rule.java | 37 +++++ .../solution/rule/mapper/FireRuleMapper.java | 35 ++++ .../com/solution/rule/mapper/RuleMapper.java | 42 ++--- ...{RuleService.java => FireRuleService.java} | 6 +- .../solution/rule/service/IRuleService.java | 36 ++++ .../service/impl/FireRuleServiceImpl.java | 156 ++++++++++++++++++ .../rule/service/impl/RuleServiceImpl.java | 150 +++-------------- .../resources/mapper/rule/FireRuleService.xml | 66 ++++++++ .../main/resources/mapper/rule/RuleMapper.xml | 133 +++++++++------ 14 files changed, 556 insertions(+), 240 deletions(-) create mode 100644 auto-solution-admin/src/main/java/com/solution/web/controller/rule/FireRuleController.java rename auto-solution-algo/src/main/resources/mapper/algo/{AlgorithmMapper.xml => FireRuleService.xml} (100%) rename auto-solution-behaviour/src/main/resources/mapper/system/{TemplateparameterdefMapper.xml => FireRuleService.xml} (100%) rename auto-solution-generator/src/main/resources/mapper/generator/{GenTableMapper.xml => FireRuleService.xml} (100%) create mode 100644 auto-solution-rule/src/main/java/com/solution/rule/domain/Rule.java create mode 100644 auto-solution-rule/src/main/java/com/solution/rule/mapper/FireRuleMapper.java rename auto-solution-rule/src/main/java/com/solution/rule/service/{RuleService.java => FireRuleService.java} (79%) create mode 100644 auto-solution-rule/src/main/java/com/solution/rule/service/IRuleService.java create mode 100644 auto-solution-rule/src/main/java/com/solution/rule/service/impl/FireRuleServiceImpl.java create mode 100644 auto-solution-rule/src/main/resources/mapper/rule/FireRuleService.xml diff --git a/auto-solution-admin/src/main/java/com/solution/web/controller/rule/FireRuleController.java b/auto-solution-admin/src/main/java/com/solution/web/controller/rule/FireRuleController.java new file mode 100644 index 0000000..9ab473c --- /dev/null +++ b/auto-solution-admin/src/main/java/com/solution/web/controller/rule/FireRuleController.java @@ -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)); + } +} diff --git a/auto-solution-admin/src/main/java/com/solution/web/controller/rule/RuleController.java b/auto-solution-admin/src/main/java/com/solution/web/controller/rule/RuleController.java index c662afa..a7ef814 100644 --- a/auto-solution-admin/src/main/java/com/solution/web/controller/rule/RuleController.java +++ b/auto-solution-admin/src/main/java/com/solution/web/controller/rule/RuleController.java @@ -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 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)); + } +} \ No newline at end of file diff --git a/auto-solution-algo/src/main/resources/mapper/algo/AlgorithmMapper.xml b/auto-solution-algo/src/main/resources/mapper/algo/FireRuleService.xml similarity index 100% rename from auto-solution-algo/src/main/resources/mapper/algo/AlgorithmMapper.xml rename to auto-solution-algo/src/main/resources/mapper/algo/FireRuleService.xml diff --git a/auto-solution-behaviour/src/main/resources/mapper/system/TemplateparameterdefMapper.xml b/auto-solution-behaviour/src/main/resources/mapper/system/FireRuleService.xml similarity index 100% rename from auto-solution-behaviour/src/main/resources/mapper/system/TemplateparameterdefMapper.xml rename to auto-solution-behaviour/src/main/resources/mapper/system/FireRuleService.xml diff --git a/auto-solution-generator/src/main/resources/mapper/generator/GenTableMapper.xml b/auto-solution-generator/src/main/resources/mapper/generator/FireRuleService.xml similarity index 100% rename from auto-solution-generator/src/main/resources/mapper/generator/GenTableMapper.xml rename to auto-solution-generator/src/main/resources/mapper/generator/FireRuleService.xml diff --git a/auto-solution-rule/src/main/java/com/solution/rule/domain/Rule.java b/auto-solution-rule/src/main/java/com/solution/rule/domain/Rule.java new file mode 100644 index 0000000..0df5018 --- /dev/null +++ b/auto-solution-rule/src/main/java/com/solution/rule/domain/Rule.java @@ -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; +} \ No newline at end of file diff --git a/auto-solution-rule/src/main/java/com/solution/rule/mapper/FireRuleMapper.java b/auto-solution-rule/src/main/java/com/solution/rule/mapper/FireRuleMapper.java new file mode 100644 index 0000000..12f4a74 --- /dev/null +++ b/auto-solution-rule/src/main/java/com/solution/rule/mapper/FireRuleMapper.java @@ -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 getWeapon(); + + List getPlatformComponentNames(); + + /** + * 获取所有组件以及数量 + * @return + */ + List getModuleAndCount(); + + /** + * 获取通信组件的所有平台和组件 + * @param scenarioId + * @return + */ + List getCommPlatformComponentNames(Integer scenarioId); + + +} diff --git a/auto-solution-rule/src/main/java/com/solution/rule/mapper/RuleMapper.java b/auto-solution-rule/src/main/java/com/solution/rule/mapper/RuleMapper.java index 0f4f2ac..d540b94 100644 --- a/auto-solution-rule/src/main/java/com/solution/rule/mapper/RuleMapper.java +++ b/auto-solution-rule/src/main/java/com/solution/rule/mapper/RuleMapper.java @@ -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 getWeapon(); - - List getPlatformComponentNames(); + List selectRuleList(Rule rule); /** - * 获取所有组件以及数量 - * @return + * 新增规则 */ - List getModuleAndCount(); + int insertRule(Rule rule); /** - * 获取通信组件的所有平台和组件 - * @param scenarioId - * @return + * 修改规则 */ - List getCommPlatformComponentNames(Integer scenarioId); -} + int updateRule(Rule rule); + + /** + * 删除规则 + */ + int deleteRuleById(Integer id); + + /** + * 批量删除规则 + */ + int deleteRuleByIds(@Param("ids")Integer[] ids); +} \ No newline at end of file diff --git a/auto-solution-rule/src/main/java/com/solution/rule/service/RuleService.java b/auto-solution-rule/src/main/java/com/solution/rule/service/FireRuleService.java similarity index 79% rename from auto-solution-rule/src/main/java/com/solution/rule/service/RuleService.java rename to auto-solution-rule/src/main/java/com/solution/rule/service/FireRuleService.java index 580366f..1993655 100644 --- a/auto-solution-rule/src/main/java/com/solution/rule/service/RuleService.java +++ b/auto-solution-rule/src/main/java/com/solution/rule/service/FireRuleService.java @@ -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 { /** * 开始执行规则匹配 diff --git a/auto-solution-rule/src/main/java/com/solution/rule/service/IRuleService.java b/auto-solution-rule/src/main/java/com/solution/rule/service/IRuleService.java new file mode 100644 index 0000000..fdd1c11 --- /dev/null +++ b/auto-solution-rule/src/main/java/com/solution/rule/service/IRuleService.java @@ -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 selectRuleList(Rule rule); + + /** + * 新增规则 + */ + int insertRule(Rule rule); + + /** + * 修改规则 + */ + int updateRule(Rule rule); + + /** + * 删除规则 + */ + int deleteRuleById(Integer id); + + /** + * 批量删除规则 + */ + int deleteRuleByIds(Integer[] ids); +} \ No newline at end of file diff --git a/auto-solution-rule/src/main/java/com/solution/rule/service/impl/FireRuleServiceImpl.java b/auto-solution-rule/src/main/java/com/solution/rule/service/impl/FireRuleServiceImpl.java new file mode 100644 index 0000000..0554f36 --- /dev/null +++ b/auto-solution-rule/src/main/java/com/solution/rule/service/impl/FireRuleServiceImpl.java @@ -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 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 execute(FireRuleExecuteDTO fireRuleExecuteDTO) { + if(ObjectUtil.isEmpty(fireRuleExecuteDTO)){ + throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION); + } + List weaponModelDTOs = fireRuleExecuteDTO.getWeaponModelDTOs(); + Integer sceneType = fireRuleExecuteDTO.getSceneType(); + // 查数据库获取我方装备 + List weapon = this.getModuleAndCount(); + + // 创建RuleParam并设置数据 + RuleParam ruleParam = new RuleParam(); + ruleParam.setWeaponModelDTOList(weaponModelDTOs); + ruleParam.setDatabaseWeapons(weapon); + + // 执行策略 + SceneStrategy strategy = strategyFactory.getStrategy(sceneType); + List result = strategy.execute(ruleParam); + + return result; + } + + @Override + public List getWeapon() { + List flatList = ruleMapper.getWeapon(); + if (CollUtil.isEmpty(flatList)) { + throw new RuntimeException(ExceptionConstants.RESULT_EXCEPTION); + } + + Map> groupByPlatform = flatList.stream() + .collect(Collectors.groupingBy(WeaponModelVO::getPlatformName)); + + List result = new ArrayList<>(); + for (Map.Entry> entry : groupByPlatform.entrySet()) { + PlatformWeaponAggregateVO platformVO = new PlatformWeaponAggregateVO(); + platformVO.setPlatformName(entry.getKey()); + + List 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 getPlatformComponentNames() { + List flatList = ruleMapper.getPlatformComponentNames(); + if (CollUtil.isEmpty(flatList)) { + throw new RuntimeException(ExceptionConstants.RESULT_EXCEPTION); + } + + + Map> 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 getCommPlatformComponentNames(Integer scenarioId) { + return ruleMapper.getCommPlatformComponentNames(scenarioId); + } + + /** + * 获取所有组件以及数量 + * @return + */ + private List getModuleAndCount(){ + List componentCountVOS = ruleMapper.getModuleAndCount(); + if(CollUtil.isEmpty(componentCountVOS)){ + return new ArrayList<>(); + } + return componentCountVOS; + } +} diff --git a/auto-solution-rule/src/main/java/com/solution/rule/service/impl/RuleServiceImpl.java b/auto-solution-rule/src/main/java/com/solution/rule/service/impl/RuleServiceImpl.java index ab3d925..d9f7c95 100644 --- a/auto-solution-rule/src/main/java/com/solution/rule/service/impl/RuleServiceImpl.java +++ b/auto-solution-rule/src/main/java/com/solution/rule/service/impl/RuleServiceImpl.java @@ -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 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 execute(FireRuleExecuteDTO fireRuleExecuteDTO) { - if(ObjectUtil.isEmpty(fireRuleExecuteDTO)){ - throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION); - } - List weaponModelDTOs = fireRuleExecuteDTO.getWeaponModelDTOs(); - Integer sceneType = fireRuleExecuteDTO.getSceneType(); - // 查数据库获取我方装备 - List weapon = this.getModuleAndCount(); - - // 创建RuleParam并设置数据 - RuleParam ruleParam = new RuleParam(); - ruleParam.setWeaponModelDTOList(weaponModelDTOs); - ruleParam.setDatabaseWeapons(weapon); - - // 执行策略 - SceneStrategy strategy = strategyFactory.getStrategy(sceneType); - List result = strategy.execute(ruleParam); - - return result; + public Rule selectRuleById(Integer id) { + return ruleMapper.selectRuleById(id); } @Override - public List getWeapon() { - List flatList = ruleMapper.getWeapon(); - if (CollUtil.isEmpty(flatList)) { - throw new RuntimeException(ExceptionConstants.RESULT_EXCEPTION); - } - - Map> groupByPlatform = flatList.stream() - .collect(Collectors.groupingBy(WeaponModelVO::getPlatformName)); - - List result = new ArrayList<>(); - for (Map.Entry> entry : groupByPlatform.entrySet()) { - PlatformWeaponAggregateVO platformVO = new PlatformWeaponAggregateVO(); - platformVO.setPlatformName(entry.getKey()); - - List 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 selectRuleList(Rule rule) { + return ruleMapper.selectRuleList(rule); } - - /** - * 获取所有武器平台和组件 - * @return - */ @Override - public List getPlatformComponentNames() { - List flatList = ruleMapper.getPlatformComponentNames(); - if (CollUtil.isEmpty(flatList)) { - throw new RuntimeException(ExceptionConstants.RESULT_EXCEPTION); - } - - - Map> 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 getCommPlatformComponentNames(Integer scenarioId) { - return ruleMapper.getCommPlatformComponentNames(scenarioId); + public int updateRule(Rule rule) { + return ruleMapper.updateRule(rule); } - /** - * 获取所有组件以及数量 - * @return - */ - private List getModuleAndCount(){ - List 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); + } +} \ No newline at end of file diff --git a/auto-solution-rule/src/main/resources/mapper/rule/FireRuleService.xml b/auto-solution-rule/src/main/resources/mapper/rule/FireRuleService.xml new file mode 100644 index 0000000..2a01110 --- /dev/null +++ b/auto-solution-rule/src/main/resources/mapper/rule/FireRuleService.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/auto-solution-rule/src/main/resources/mapper/rule/RuleMapper.xml b/auto-solution-rule/src/main/resources/mapper/rule/RuleMapper.xml index 541b652..f4e4223 100644 --- a/auto-solution-rule/src/main/resources/mapper/rule/RuleMapper.xml +++ b/auto-solution-rule/src/main/resources/mapper/rule/RuleMapper.xml @@ -1,66 +1,97 @@ - + - - - - - + + + + + + + + + + - - - - - - - - + + where id = #{id} - + + + + AND name like concat('%', #{name}, '%') + + + AND scene_type = #{sceneType} + + + AND enabled = #{enabled} + + + + insert into rule + + name, + scene_type, + conditions, + actions, + priority, + enabled, + created_time, + updated_time + + + #{name}, + #{sceneType}, + #{conditions}, + #{actions}, + #{priority}, + #{enabled}, + now(), + now() + + - + + update rule + + name = #{name}, + scene_type = #{sceneType}, + conditions = #{conditions}, + actions = #{actions}, + priority = #{priority}, + enabled = #{enabled}, + updated_time = now() + + where id = #{id} + - + + delete from rule where id = #{id} + + + + delete from rule where id in + + #{id} + + \ No newline at end of file