正在显示
4 个修改的文件
包含
54 行增加
和
11 行删除
| @@ -86,6 +86,11 @@ public class AiragButtonController extends JeecgController<AiragButton, IAiragBu | @@ -86,6 +86,11 @@ public class AiragButtonController extends JeecgController<AiragButton, IAiragBu | ||
| 86 | @RequiresPermissions("airagbutton:airag_button:add") | 86 | @RequiresPermissions("airagbutton:airag_button:add") |
| 87 | @PostMapping(value = "/add") | 87 | @PostMapping(value = "/add") |
| 88 | public Result<String> add(@RequestBody AiragButton airagButton) { | 88 | public Result<String> add(@RequestBody AiragButton airagButton) { |
| 89 | + // 唯一性校验 | ||
| 90 | + if (!airagButtonService.isCodeUnique(airagButton.getCode(), null)) { | ||
| 91 | + return Result.error("按钮编码已存在,请重新输入!"); | ||
| 92 | + } | ||
| 93 | + | ||
| 89 | // 检查按钮开关是否为开启状态 | 94 | // 检查按钮开关是否为开启状态 |
| 90 | if ("Y".equals(airagButton.getButtonSwitch())) { | 95 | if ("Y".equals(airagButton.getButtonSwitch())) { |
| 91 | // 查询当前已开启的按钮数量 | 96 | // 查询当前已开启的按钮数量 |
| @@ -113,6 +118,11 @@ public class AiragButtonController extends JeecgController<AiragButton, IAiragBu | @@ -113,6 +118,11 @@ public class AiragButtonController extends JeecgController<AiragButton, IAiragBu | ||
| 113 | @RequiresPermissions("airagbutton:airag_button:edit") | 118 | @RequiresPermissions("airagbutton:airag_button:edit") |
| 114 | @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) | 119 | @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) |
| 115 | public Result<String> edit(@RequestBody AiragButton airagButton) { | 120 | public Result<String> edit(@RequestBody AiragButton airagButton) { |
| 121 | + // 唯一性校验 | ||
| 122 | + if (!airagButtonService.isCodeUnique(airagButton.getCode(), null)) { | ||
| 123 | + return Result.error("按钮编码已存在,请重新输入!"); | ||
| 124 | + } | ||
| 125 | + | ||
| 116 | // 检查按钮开关是否为开启状态 | 126 | // 检查按钮开关是否为开启状态 |
| 117 | if ("Y".equals(airagButton.getButtonSwitch())) { | 127 | if ("Y".equals(airagButton.getButtonSwitch())) { |
| 118 | // 查询当前已开启的按钮数量(排除自身) | 128 | // 查询当前已开启的按钮数量(排除自身) |
| @@ -49,21 +49,37 @@ | @@ -49,21 +49,37 @@ | ||
| 49 | 49 | ||
| 50 | <select id="getMonthlyCount" resultType="java.util.Map"> | 50 | <select id="getMonthlyCount" resultType="java.util.Map"> |
| 51 | SELECT | 51 | SELECT |
| 52 | - DATE_FORMAT(create_time, '%Y-%m') AS month, | ||
| 53 | - COUNT(*) AS count | ||
| 54 | - FROM airag_log | ||
| 55 | - WHERE create_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH) | ||
| 56 | - GROUP BY DATE_FORMAT(create_time, '%Y-%m') | ||
| 57 | - ORDER BY month ASC | 52 | + DATE_FORMAT(date_range.month, '%Y-%m') AS month, |
| 53 | + IFNULL(log_counts.count, 0) AS count | ||
| 54 | + FROM ( | ||
| 55 | + SELECT DATE_SUB(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL n MONTH) AS month | ||
| 56 | + FROM ( | ||
| 57 | + SELECT 0 AS n UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 | ||
| 58 | + UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 | ||
| 59 | + UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 | ||
| 60 | + UNION SELECT 10 UNION SELECT 11 | ||
| 61 | + ) months | ||
| 62 | + ) date_range | ||
| 63 | + LEFT JOIN ( | ||
| 64 | + SELECT | ||
| 65 | + DATE_FORMAT(create_time, '%Y-%m-01') AS month, | ||
| 66 | + COUNT(*) AS count | ||
| 67 | + FROM airag_log | ||
| 68 | + WHERE create_time >= DATE_SUB(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL 12 MONTH) | ||
| 69 | + GROUP BY DATE_FORMAT(create_time, '%Y-%m-01') | ||
| 70 | + ) log_counts ON date_range.month = log_counts.month | ||
| 71 | + WHERE date_range.month >= DATE_SUB(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL 12 MONTH) | ||
| 72 | + ORDER BY date_range.month ASC | ||
| 58 | </select> | 73 | </select> |
| 59 | 74 | ||
| 60 | <select id="getButtonRankList" resultType="java.util.Map"> | 75 | <select id="getButtonRankList" resultType="java.util.Map"> |
| 61 | SELECT | 76 | SELECT |
| 62 | - question, COUNT(*) as count | ||
| 63 | - FROM airag_log | ||
| 64 | - WHERE code IS NOT NULL AND code != '' | ||
| 65 | - GROUP BY question | ||
| 66 | - ORDER BY count DESC | 77 | + b.button_name AS name, |
| 78 | + COUNT(l.id) AS total | ||
| 79 | + FROM airag_button b | ||
| 80 | + LEFT JOIN airag_log l ON b.code = l.code | ||
| 81 | + GROUP BY b.id, b.button_name | ||
| 82 | + ORDER BY total DESC | ||
| 67 | LIMIT 7 | 83 | LIMIT 7 |
| 68 | </select> | 84 | </select> |
| 69 | </mapper> | 85 | </mapper> |
| @@ -14,4 +14,6 @@ import java.util.List; | @@ -14,4 +14,6 @@ import java.util.List; | ||
| 14 | */ | 14 | */ |
| 15 | public interface IAiragButtonService extends IService<AiragButton> { | 15 | public interface IAiragButtonService extends IService<AiragButton> { |
| 16 | 16 | ||
| 17 | + boolean isCodeUnique(String code, String excludeId); | ||
| 18 | + | ||
| 17 | } | 19 | } |
| 1 | package org.jeecg.modules.airag.app.service.impl; | 1 | package org.jeecg.modules.airag.app.service.impl; |
| 2 | 2 | ||
| 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| 4 | +import org.apache.commons.lang.StringUtils; | ||
| 4 | import org.jeecg.modules.airag.app.entity.AiragButton; | 5 | import org.jeecg.modules.airag.app.entity.AiragButton; |
| 5 | import org.jeecg.modules.airag.app.entity.Embeddings; | 6 | import org.jeecg.modules.airag.app.entity.Embeddings; |
| 6 | import org.jeecg.modules.airag.app.mapper.AiragButtonMapper; | 7 | import org.jeecg.modules.airag.app.mapper.AiragButtonMapper; |
| @@ -8,6 +9,7 @@ import org.jeecg.modules.airag.app.mapper.PgVectorMapper; | @@ -8,6 +9,7 @@ import org.jeecg.modules.airag.app.mapper.PgVectorMapper; | ||
| 8 | import org.jeecg.modules.airag.app.service.IAiragButtonService; | 9 | import org.jeecg.modules.airag.app.service.IAiragButtonService; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 12 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
| 11 | 13 | ||
| 12 | import java.util.List; | 14 | import java.util.List; |
| 13 | 15 | ||
| @@ -20,5 +22,18 @@ import java.util.List; | @@ -20,5 +22,18 @@ import java.util.List; | ||
| 20 | @Service | 22 | @Service |
| 21 | public class AiragButtonServiceImpl extends ServiceImpl<AiragButtonMapper, AiragButton> implements IAiragButtonService { | 23 | public class AiragButtonServiceImpl extends ServiceImpl<AiragButtonMapper, AiragButton> implements IAiragButtonService { |
| 22 | 24 | ||
| 25 | + @Autowired | ||
| 26 | + private AiragButtonMapper airagButtonMapper; | ||
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + public boolean isCodeUnique(String code, String excludeId) { | ||
| 30 | + QueryWrapper<AiragButton> queryWrapper = new QueryWrapper<>(); | ||
| 31 | + queryWrapper.eq("code", code); | ||
| 32 | + // 编辑时排除当前记录 | ||
| 33 | + if (StringUtils.isNotBlank(excludeId)) { | ||
| 34 | + queryWrapper.ne("id", excludeId); | ||
| 35 | + } | ||
| 36 | + return airagButtonMapper.selectCount(queryWrapper) == 0; | ||
| 37 | + } | ||
| 23 | 38 | ||
| 24 | } | 39 | } |
-
请 注册 或 登录 后发表评论