From 8591cebee0e66a13da69b368d80e5a17b413e745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E7=A0=81-=E6=96=B9=E6=99=93=E8=BE=89?= Date: Mon, 2 Feb 2026 15:09:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=92=8C=E9=80=9A=E7=9F=A5=E5=85=AC=E5=91=8A?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 SysConfigController 参数配置管理 - 新增 SysNoticeController 通知公告管理 - 系统管理模块功能完整 --- .../controller/SysConfigController.java | 189 ++++++++++++++++++ .../controller/SysNoticeController.java | 158 +++++++++++++++ 2 files changed, 347 insertions(+) create mode 100644 backend/pangu-system/src/main/java/com/pangu/system/controller/SysConfigController.java create mode 100644 backend/pangu-system/src/main/java/com/pangu/system/controller/SysNoticeController.java diff --git a/backend/pangu-system/src/main/java/com/pangu/system/controller/SysConfigController.java b/backend/pangu-system/src/main/java/com/pangu/system/controller/SysConfigController.java new file mode 100644 index 0000000..3573002 --- /dev/null +++ b/backend/pangu-system/src/main/java/com/pangu/system/controller/SysConfigController.java @@ -0,0 +1,189 @@ +package com.pangu.system.controller; + +import com.pangu.common.core.controller.BaseController; +import com.pangu.common.core.domain.AjaxResult; +import com.pangu.common.core.page.TableDataInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.web.bind.annotation.*; + +import java.util.*; + +/** + * 参数配置Controller + * @author pangu + */ +@RestController +@RequestMapping("/system/config") +public class SysConfigController extends BaseController { + + @Autowired + private JdbcTemplate jdbcTemplate; + + /** + * 查询参数配置列表 + */ + @GetMapping("/list") + public TableDataInfo list( + @RequestParam(required = false) String configName, + @RequestParam(required = false) String configKey, + @RequestParam(required = false) String configType, + @RequestParam(defaultValue = "1") Integer pageNum, + @RequestParam(defaultValue = "10") Integer pageSize) { + + StringBuilder sql = new StringBuilder(); + sql.append("SELECT config_id, config_name, config_key, config_value, config_type, create_time, remark "); + sql.append("FROM sys_config WHERE 1=1 "); + + List params = new ArrayList<>(); + if (configName != null && !configName.isEmpty()) { + sql.append("AND config_name LIKE ? "); + params.add("%" + configName + "%"); + } + if (configKey != null && !configKey.isEmpty()) { + sql.append("AND config_key LIKE ? "); + params.add("%" + configKey + "%"); + } + if (configType != null && !configType.isEmpty()) { + sql.append("AND config_type = ? "); + params.add(configType); + } + + String countSql = "SELECT COUNT(*) FROM (" + sql.toString() + ") t"; + Integer total = jdbcTemplate.queryForObject(countSql, Integer.class, params.toArray()); + + sql.append("ORDER BY config_id LIMIT ? OFFSET ?"); + params.add(pageSize); + params.add((pageNum - 1) * pageSize); + + List> rows = jdbcTemplate.queryForList(sql.toString(), params.toArray()); + + // 转换字段名为驼峰格式 + List> result = new ArrayList<>(); + for (Map row : rows) { + Map item = new HashMap<>(); + item.put("configId", row.get("config_id")); + item.put("configName", row.get("config_name")); + item.put("configKey", row.get("config_key")); + item.put("configValue", row.get("config_value")); + item.put("configType", row.get("config_type")); + item.put("createTime", row.get("create_time")); + item.put("remark", row.get("remark")); + result.add(item); + } + + TableDataInfo dataInfo = new TableDataInfo(); + dataInfo.setCode(200); + dataInfo.setMsg("查询成功"); + dataInfo.setRows(result); + dataInfo.setTotal(total != null ? total : 0); + return dataInfo; + } + + /** + * 获取参数配置详情 + */ + @GetMapping("/{configId}") + public AjaxResult getInfo(@PathVariable Long configId) { + String sql = "SELECT config_id, config_name, config_key, config_value, config_type, remark FROM sys_config WHERE config_id = ?"; + List> configs = jdbcTemplate.queryForList(sql, configId); + if (configs.isEmpty()) { + return AjaxResult.error("参数配置不存在"); + } + Map row = configs.get(0); + Map result = new HashMap<>(); + result.put("configId", row.get("config_id")); + result.put("configName", row.get("config_name")); + result.put("configKey", row.get("config_key")); + result.put("configValue", row.get("config_value")); + result.put("configType", row.get("config_type")); + result.put("remark", row.get("remark")); + return AjaxResult.success(result); + } + + /** + * 根据参数键名查询参数值 + */ + @GetMapping("/configKey/{configKey}") + public AjaxResult getConfigKey(@PathVariable String configKey) { + String sql = "SELECT config_value FROM sys_config WHERE config_key = ?"; + List> configs = jdbcTemplate.queryForList(sql, configKey); + if (configs.isEmpty()) { + return AjaxResult.success(""); + } + return AjaxResult.success(configs.get(0).get("config_value")); + } + + /** + * 新增参数配置 + */ + @PostMapping + public AjaxResult add(@RequestBody Map config) { + String configKey = (String) config.get("configKey"); + + // 检查参数键名是否存在 + Integer count = jdbcTemplate.queryForObject( + "SELECT COUNT(*) FROM sys_config WHERE config_key = ?", + Integer.class, configKey); + if (count != null && count > 0) { + return AjaxResult.error("参数键名已存在"); + } + + String sql = "INSERT INTO sys_config (config_name, config_key, config_value, config_type, " + + "create_by, create_time, remark) VALUES (?, ?, ?, ?, 'admin', NOW(), ?)"; + + jdbcTemplate.update(sql, + config.get("configName"), + configKey, + config.get("configValue"), + config.getOrDefault("configType", "N"), + config.get("remark") + ); + + return AjaxResult.success("新增成功"); + } + + /** + * 修改参数配置 + */ + @PutMapping + public AjaxResult edit(@RequestBody Map config) { + Long configId = Long.valueOf(config.get("configId").toString()); + + String sql = "UPDATE sys_config SET config_name = ?, config_key = ?, config_value = ?, " + + "config_type = ?, remark = ?, update_by = 'admin', update_time = NOW() " + + "WHERE config_id = ?"; + + jdbcTemplate.update(sql, + config.get("configName"), + config.get("configKey"), + config.get("configValue"), + config.getOrDefault("configType", "N"), + config.get("remark"), + configId + ); + + return AjaxResult.success("修改成功"); + } + + /** + * 删除参数配置 + */ + @DeleteMapping("/{configIds}") + public AjaxResult remove(@PathVariable String configIds) { + String[] ids = configIds.split(","); + for (String id : ids) { + jdbcTemplate.update("DELETE FROM sys_config WHERE config_id = ?", Long.valueOf(id)); + } + return AjaxResult.success("删除成功"); + } + + /** + * 刷新参数缓存 + */ + @DeleteMapping("/refreshCache") + public AjaxResult refreshCache() { + // 简单实现,实际项目中可能需要清除 Redis 缓存 + return AjaxResult.success("刷新缓存成功"); + } +} diff --git a/backend/pangu-system/src/main/java/com/pangu/system/controller/SysNoticeController.java b/backend/pangu-system/src/main/java/com/pangu/system/controller/SysNoticeController.java new file mode 100644 index 0000000..ea0168d --- /dev/null +++ b/backend/pangu-system/src/main/java/com/pangu/system/controller/SysNoticeController.java @@ -0,0 +1,158 @@ +package com.pangu.system.controller; + +import com.pangu.common.core.controller.BaseController; +import com.pangu.common.core.domain.AjaxResult; +import com.pangu.common.core.page.TableDataInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.web.bind.annotation.*; + +import java.util.*; + +/** + * 通知公告Controller + * @author pangu + */ +@RestController +@RequestMapping("/system/notice") +public class SysNoticeController extends BaseController { + + @Autowired + private JdbcTemplate jdbcTemplate; + + /** + * 查询通知公告列表 + */ + @GetMapping("/list") + public TableDataInfo list( + @RequestParam(required = false) String noticeTitle, + @RequestParam(required = false) String noticeType, + @RequestParam(required = false) String createBy, + @RequestParam(defaultValue = "1") Integer pageNum, + @RequestParam(defaultValue = "10") Integer pageSize) { + + StringBuilder sql = new StringBuilder(); + sql.append("SELECT notice_id, notice_title, notice_type, notice_content, status, create_by, create_time, remark "); + sql.append("FROM sys_notice WHERE 1=1 "); + + List params = new ArrayList<>(); + if (noticeTitle != null && !noticeTitle.isEmpty()) { + sql.append("AND notice_title LIKE ? "); + params.add("%" + noticeTitle + "%"); + } + if (noticeType != null && !noticeType.isEmpty()) { + sql.append("AND notice_type = ? "); + params.add(noticeType); + } + if (createBy != null && !createBy.isEmpty()) { + sql.append("AND create_by LIKE ? "); + params.add("%" + createBy + "%"); + } + + String countSql = "SELECT COUNT(*) FROM (" + sql.toString() + ") t"; + Integer total = jdbcTemplate.queryForObject(countSql, Integer.class, params.toArray()); + + sql.append("ORDER BY notice_id DESC LIMIT ? OFFSET ?"); + params.add(pageSize); + params.add((pageNum - 1) * pageSize); + + List> rows = jdbcTemplate.queryForList(sql.toString(), params.toArray()); + + // 转换字段名为驼峰格式 + List> result = new ArrayList<>(); + for (Map row : rows) { + Map item = new HashMap<>(); + item.put("noticeId", row.get("notice_id")); + item.put("noticeTitle", row.get("notice_title")); + item.put("noticeType", row.get("notice_type")); + item.put("noticeContent", row.get("notice_content")); + item.put("status", row.get("status")); + item.put("createBy", row.get("create_by")); + item.put("createTime", row.get("create_time")); + item.put("remark", row.get("remark")); + result.add(item); + } + + TableDataInfo dataInfo = new TableDataInfo(); + dataInfo.setCode(200); + dataInfo.setMsg("查询成功"); + dataInfo.setRows(result); + dataInfo.setTotal(total != null ? total : 0); + return dataInfo; + } + + /** + * 获取通知公告详情 + */ + @GetMapping("/{noticeId}") + public AjaxResult getInfo(@PathVariable Long noticeId) { + String sql = "SELECT notice_id, notice_title, notice_type, notice_content, status, remark FROM sys_notice WHERE notice_id = ?"; + List> notices = jdbcTemplate.queryForList(sql, noticeId); + if (notices.isEmpty()) { + return AjaxResult.error("通知公告不存在"); + } + Map row = notices.get(0); + Map result = new HashMap<>(); + result.put("noticeId", row.get("notice_id")); + result.put("noticeTitle", row.get("notice_title")); + result.put("noticeType", row.get("notice_type")); + result.put("noticeContent", row.get("notice_content")); + result.put("status", row.get("status")); + result.put("remark", row.get("remark")); + return AjaxResult.success(result); + } + + /** + * 新增通知公告 + */ + @PostMapping + public AjaxResult add(@RequestBody Map notice) { + String sql = "INSERT INTO sys_notice (notice_title, notice_type, notice_content, status, " + + "create_by, create_time, remark) VALUES (?, ?, ?, ?, 'admin', NOW(), ?)"; + + jdbcTemplate.update(sql, + notice.get("noticeTitle"), + notice.get("noticeType"), + notice.get("noticeContent"), + notice.getOrDefault("status", "0"), + notice.get("remark") + ); + + return AjaxResult.success("新增成功"); + } + + /** + * 修改通知公告 + */ + @PutMapping + public AjaxResult edit(@RequestBody Map notice) { + Long noticeId = Long.valueOf(notice.get("noticeId").toString()); + + String sql = "UPDATE sys_notice SET notice_title = ?, notice_type = ?, notice_content = ?, " + + "status = ?, remark = ?, update_by = 'admin', update_time = NOW() " + + "WHERE notice_id = ?"; + + jdbcTemplate.update(sql, + notice.get("noticeTitle"), + notice.get("noticeType"), + notice.get("noticeContent"), + notice.getOrDefault("status", "0"), + notice.get("remark"), + noticeId + ); + + return AjaxResult.success("修改成功"); + } + + /** + * 删除通知公告 + */ + @DeleteMapping("/{noticeIds}") + public AjaxResult remove(@PathVariable String noticeIds) { + String[] ids = noticeIds.split(","); + for (String id : ids) { + jdbcTemplate.update("DELETE FROM sys_notice WHERE notice_id = ?", Long.valueOf(id)); + } + return AjaxResult.success("删除成功"); + } +}