From 77e1b8cbe93ca0907588ae97a478f5fe437c66e9 Mon Sep 17 00:00:00 2001 From: chentaisen <14615430+chentaisen@user.noreply.gitee.com> Date: Wed, 25 Sep 2024 15:49:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8C=E6=AC=A1=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/muyu/warning/domain/WarnRuleDTO.java | 4 ++ .../controller/WarnRuleController.java | 27 +++---- .../controller/WarnRulesController.java | 6 ++ .../muyu/warning/mapper/WarnRuleMapper.java | 3 +- .../muyu/warning/mapper/WarnRulesMapper.java | 2 +- .../warning/service/IWarRulesService.java | 2 +- .../warning/service/IWarnRuleService.java | 21 +++--- .../service/impl/WarnRuleServiceImpl.java | 72 +++++++++---------- .../service/impl/WarnRulesServiceImpl.java | 1 - 9 files changed, 70 insertions(+), 68 deletions(-) diff --git a/cloud-modules/cloud-modules-warn/cloud-warn-common/src/main/java/com/muyu/warning/domain/WarnRuleDTO.java b/cloud-modules/cloud-modules-warn/cloud-warn-common/src/main/java/com/muyu/warning/domain/WarnRuleDTO.java index e908257..6a8d311 100644 --- a/cloud-modules/cloud-modules-warn/cloud-warn-common/src/main/java/com/muyu/warning/domain/WarnRuleDTO.java +++ b/cloud-modules/cloud-modules-warn/cloud-warn-common/src/main/java/com/muyu/warning/domain/WarnRuleDTO.java @@ -3,7 +3,9 @@ package com.muyu.warning.domain; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.muyu.common.core.annotation.Excel; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; /** * @ClassName WarnRule @@ -12,6 +14,8 @@ import lombok.Data; * @Date 2024/9/22 11:53 */ @Data +@AllArgsConstructor +@NoArgsConstructor public class WarnRuleDTO { /** 规则id */ @TableId( type = IdType.AUTO) diff --git a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/controller/WarnRuleController.java b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/controller/WarnRuleController.java index 20e7798..f549518 100644 --- a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/controller/WarnRuleController.java +++ b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/controller/WarnRuleController.java @@ -6,6 +6,7 @@ import java.util.List; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.github.yulichang.query.MPJLambdaQueryWrapper; import com.muyu.warning.domain.WarnRule; +import com.muyu.warning.domain.WarnRuleDTO; import com.muyu.warning.domain.WarnStrategy; import jakarta.servlet.http.HttpServletResponse; @@ -45,9 +46,9 @@ public class WarnRuleController extends BaseController { */ @RequiresPermissions("warning:list") @GetMapping("/list") - public Result> list(WarnRule warnRule) { + public Result> list(WarnRuleDTO warnRuleDTO) { startPage(); - List list = warnRuleService.selectWarnRuleList(warnRule); + List list = warnRuleService.selectWarnRuleList(warnRuleDTO); // MPJLambdaQueryWrapper objectMPJLambdaQueryWrapper = new MPJLambdaQueryWrapper<>() // .selectAll(WarnRule.class) // .select(WarnStrategy::getStrategyName) @@ -61,9 +62,9 @@ public class WarnRuleController extends BaseController { */ @RequiresPermissions("warning:export") @PostMapping("/export") - public void export(HttpServletResponse response, WarnRule warnRule) { - List list = warnRuleService.selectWarnRuleList(warnRule); - ExcelUtil util = new ExcelUtil(WarnRule.class); + public void export(HttpServletResponse response, WarnRuleDTO warnRuleDTO) { + List list = warnRuleService.selectWarnRuleList(warnRuleDTO); + ExcelUtil util = new ExcelUtil(WarnRuleDTO.class); util.exportExcel(response, list, "预警规则数据"); } @@ -82,11 +83,11 @@ public class WarnRuleController extends BaseController { @RequiresPermissions("warning:add") @PostMapping public Result add( - @Validated @RequestBody WarnRule warnRule) { - if (warnRuleService.checkIdUnique(warnRule)) { - return error("新增 预警规则 '" + warnRule + "'失败,预警规则已存在"); + @Validated @RequestBody WarnRuleDTO warnRuleDTO) { + if (warnRuleService.checkIdUnique(warnRuleDTO)) { + return error("新增 预警规则 '" + warnRuleDTO + "'失败,预警规则已存在"); } - return toAjax(warnRuleService.save(warnRule)); + return toAjax(warnRuleService.save(warnRuleDTO)); } /** @@ -95,11 +96,11 @@ public class WarnRuleController extends BaseController { @RequiresPermissions("warning:edit") @PutMapping public Result edit( - @Validated @RequestBody WarnRule warnRule) { - if (!warnRuleService.checkIdUnique(warnRule)) { - return error("修改 预警规则 '" + warnRule + "'失败,预警规则不存在"); + @Validated @RequestBody WarnRuleDTO warnRuleDTO) { + if (!warnRuleService.checkIdUnique(warnRuleDTO)) { + return error("修改 预警规则 '" + warnRuleDTO + "'失败,预警规则不存在"); } - return toAjax(warnRuleService.updateById(warnRule)); + return toAjax(warnRuleService.updateById(warnRuleDTO)); } /** diff --git a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/controller/WarnRulesController.java b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/controller/WarnRulesController.java index d59b114..8a87908 100644 --- a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/controller/WarnRulesController.java +++ b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/controller/WarnRulesController.java @@ -35,6 +35,12 @@ public class WarnRulesController { return Result.success(list); } + /** + * 联查 + * + * @param warnRuleDTO + * @return + */ @PostMapping("/listAll") public Result> listAll(WarnRuleDTO warnRuleDTO) { List list = warnRulesService.selectWarnRulesListAll(warnRuleDTO); diff --git a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/mapper/WarnRuleMapper.java b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/mapper/WarnRuleMapper.java index e190368..e3d67d3 100644 --- a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/mapper/WarnRuleMapper.java +++ b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/mapper/WarnRuleMapper.java @@ -4,6 +4,7 @@ import com.github.yulichang.base.MPJBaseMapper; import com.muyu.warning.domain.WarnRule; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.muyu.warning.domain.WarnRule; +import com.muyu.warning.domain.WarnRuleDTO; import org.apache.ibatis.annotations.Mapper; /** @@ -13,6 +14,6 @@ import org.apache.ibatis.annotations.Mapper; * @date 2024-09-20 */ @Mapper -public interface WarnRuleMapper extends MPJBaseMapper { +public interface WarnRuleMapper extends BaseMapper { } diff --git a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/mapper/WarnRulesMapper.java b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/mapper/WarnRulesMapper.java index df0a62b..61a6d1a 100644 --- a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/mapper/WarnRulesMapper.java +++ b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/mapper/WarnRulesMapper.java @@ -15,7 +15,7 @@ import java.util.List; */ @Mapper public interface WarnRulesMapper extends BaseMapper { - @Select("select r.*,s.strategy_name FROM warn_rule r left join warn_strategy s on r.strategy_id=s.id") + @Select("select r.*,s.id,s.strategy_name FROM warn_rule r left join warn_strategy s on r.strategy_id=s.id where r.strategy_id = #{s.id}") List selectWarnRulesListAll(WarnRuleDTO warnRuleDTO); } diff --git a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/IWarRulesService.java b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/IWarRulesService.java index 0bd505f..25f71e8 100644 --- a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/IWarRulesService.java +++ b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/IWarRulesService.java @@ -8,7 +8,7 @@ import java.util.List; public interface IWarRulesService extends IService { List selectWarnRulesList(); - + //联查 List selectWarnRulesListAll(WarnRuleDTO warnRuleDTO); } diff --git a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/IWarnRuleService.java b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/IWarnRuleService.java index 08664d6..ef327d0 100644 --- a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/IWarnRuleService.java +++ b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/IWarnRuleService.java @@ -1,11 +1,10 @@ package com.muyu.warning.service; -import java.util.List; - -import com.github.yulichang.base.MPJBaseService; -import com.muyu.warning.domain.WarnRule; import com.baomidou.mybatisplus.extension.service.IService; -import com.muyu.warning.domain.WarnRule; +import com.github.yulichang.base.MPJBaseService; +import com.muyu.warning.domain.WarnRuleDTO; + +import java.util.List; /** * 预警规则Service接口 @@ -13,28 +12,28 @@ import com.muyu.warning.domain.WarnRule; * @author muyu * @date 2024-09-20 */ -public interface IWarnRuleService extends MPJBaseService { +public interface IWarnRuleService extends IService { /** * 精确查询预警规则 * * @param id 预警规则主键 * @return 预警规则 */ - public WarnRule selectWarnRuleById(Long id); + public WarnRuleDTO selectWarnRuleById(Long id); /** * 查询预警规则列表 * - * @param warnRule 预警规则 + * @param warnRuleDTO 预警规则 * @return 预警规则集合 */ - public List selectWarnRuleList(WarnRule warnRule); + public List selectWarnRuleList(WarnRuleDTO warnRuleDTO); /** * 判断 预警规则 id是否唯一 - * @param warnRule 预警规则 + * @param warnRuleDTO 预警规则 * @return 结果 */ - Boolean checkIdUnique(WarnRule warnRule); + Boolean checkIdUnique(WarnRuleDTO warnRuleDTO); } diff --git a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/impl/WarnRuleServiceImpl.java b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/impl/WarnRuleServiceImpl.java index 766bdb7..4fa0aab 100644 --- a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/impl/WarnRuleServiceImpl.java +++ b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/impl/WarnRuleServiceImpl.java @@ -1,25 +1,18 @@ package com.muyu.warning.service.impl; -import java.util.List; - -import com.github.yulichang.base.MPJBaseServiceImpl; -import com.github.yulichang.query.MPJLambdaQueryWrapper; -import com.github.yulichang.query.MPJQueryWrapper; -import com.github.yulichang.toolkit.JoinWrappers; -import com.github.yulichang.wrapper.MPJLambdaWrapper; -import com.muyu.warning.domain.WarnLogs; -import com.muyu.warning.domain.WarnRule; -import com.muyu.warning.domain.WarnStrategy; -import com.muyu.warning.mapper.WarnRuleMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import com.muyu.warning.domain.WarnRule; -import com.muyu.warning.service.IWarnRuleService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.github.yulichang.base.MPJBaseServiceImpl; import com.muyu.common.core.utils.StringUtils; +import com.muyu.warning.domain.WarnRuleDTO; +import com.muyu.warning.mapper.WarnRuleMapper; +import com.muyu.warning.service.IWarnRuleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; import org.springframework.util.Assert; +import java.util.List; + /** * 预警规则Service业务层处理 * @@ -28,10 +21,9 @@ import org.springframework.util.Assert; */ @Service public class WarnRuleServiceImpl - extends MPJBaseServiceImpl + extends ServiceImpl implements IWarnRuleService { - @Autowired - private WarnRuleMapper warnRuleMapper; + /** * 精确查询预警规则 @@ -40,10 +32,10 @@ public class WarnRuleServiceImpl * @return 预警规则 */ @Override - public WarnRule selectWarnRuleById(Long id) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + public WarnRuleDTO selectWarnRuleById(Long id) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); Assert.notNull(id, "id不可为空"); - queryWrapper.eq(WarnRule::getId, id); + queryWrapper.eq(WarnRuleDTO::getId, id); return this.getOne(queryWrapper); } @@ -51,11 +43,11 @@ public class WarnRuleServiceImpl /** * 查询预警规则列表 * - * @param warnRule 预警规则 + * @param warnRuleDTO 预警规则 * @return 预警规则 */ @Override - public List selectWarnRuleList(WarnRule warnRule) { + public List selectWarnRuleList(WarnRuleDTO warnRuleDTO) { // MPJLambdaWrapper queryWrapper = new MPJLambdaWrapper() // .selectAll(WarnRule.class) @@ -75,25 +67,25 @@ public class WarnRuleServiceImpl // } // - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - if (StringUtils.isNotNull(warnRule.getStrategyId())) { - queryWrapper.eq(WarnRule::getStrategyId, warnRule.getStrategyId()); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + if (StringUtils.isNotNull(warnRuleDTO.getStrategyId())) { + queryWrapper.eq(WarnRuleDTO::getStrategyId, warnRuleDTO.getStrategyId()); // queryWrapper.eq("strategy_id", warnRule.getStrategyId()); } - if (StringUtils.isNotNull(warnRule.getMsgTypeId())) { - queryWrapper.eq(WarnRule::getMsgTypeId, warnRule.getMsgTypeId()); + if (StringUtils.isNotNull(warnRuleDTO.getMsgTypeId())) { + queryWrapper.eq(WarnRuleDTO::getMsgTypeId, warnRuleDTO.getMsgTypeId()); } - if (StringUtils.isNotNull(warnRule.getSlideTime())) { - queryWrapper.eq(WarnRule::getSlideTime, warnRule.getSlideTime()); + if (StringUtils.isNotNull(warnRuleDTO.getSlideTime())) { + queryWrapper.eq(WarnRuleDTO::getSlideTime, warnRuleDTO.getSlideTime()); } - if (StringUtils.isNotNull(warnRule.getSlideFrequency())) { - queryWrapper.eq(WarnRule::getSlideFrequency, warnRule.getSlideFrequency()); + if (StringUtils.isNotNull(warnRuleDTO.getSlideFrequency())) { + queryWrapper.eq(WarnRuleDTO::getSlideFrequency, warnRuleDTO.getSlideFrequency()); } - if (StringUtils.isNotNull(warnRule.getMaxValue())) { - queryWrapper.eq(WarnRule::getMaxValue, warnRule.getMaxValue()); + if (StringUtils.isNotNull(warnRuleDTO.getMaxValue())) { + queryWrapper.eq(WarnRuleDTO::getMaxValue, warnRuleDTO.getMaxValue()); } - if (StringUtils.isNotNull(warnRule.getMinValue())) { - queryWrapper.eq(WarnRule::getMinValue, warnRule.getMinValue()); + if (StringUtils.isNotNull(warnRuleDTO.getMinValue())) { + queryWrapper.eq(WarnRuleDTO::getMinValue, warnRuleDTO.getMinValue()); } return this.list(queryWrapper); @@ -103,13 +95,13 @@ public class WarnRuleServiceImpl /** * 唯一 判断 * - * @param warnRule 预警规则 + * @param warnRuleDTO 预警规则 * @return 预警规则 */ @Override - public Boolean checkIdUnique(WarnRule warnRule) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(WarnRule::getId, warnRule.getId()); + public Boolean checkIdUnique(WarnRuleDTO warnRuleDTO) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(WarnRuleDTO::getId, warnRuleDTO.getId()); return this.count(queryWrapper) > 0; } diff --git a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/impl/WarnRulesServiceImpl.java b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/impl/WarnRulesServiceImpl.java index 6a8cd3b..54de66e 100644 --- a/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/impl/WarnRulesServiceImpl.java +++ b/cloud-modules/cloud-modules-warn/cloud-warn-server/src/main/java/com/muyu/warning/service/impl/WarnRulesServiceImpl.java @@ -41,7 +41,6 @@ public class WarnRulesServiceImpl */ @Override public List selectWarnRulesListAll(WarnRuleDTO warnRuleDTO) { - warnRuleDTO.setStrategyId(warnRuleDTO.getId()); List list = warnRulesMapper.selectWarnRulesListAll(warnRuleDTO); return list; }