Compare commits
No commits in common. "8591cebee0e66a13da69b368d80e5a17b413e745" and "7753ddbfbd415b6a8dc9c17cbfd6e9edf9673fb3" have entirely different histories.
8591cebee0
...
7753ddbfbd
|
|
@ -3,10 +3,6 @@ server:
|
|||
port: 8080
|
||||
servlet:
|
||||
context-path: /
|
||||
encoding:
|
||||
charset: UTF-8
|
||||
enabled: true
|
||||
force: true
|
||||
|
||||
spring:
|
||||
application:
|
||||
|
|
|
|||
|
|
@ -1,189 +0,0 @@
|
|||
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<Object> 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<Map<String, Object>> rows = jdbcTemplate.queryForList(sql.toString(), params.toArray());
|
||||
|
||||
// 转换字段名为驼峰格式
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
for (Map<String, Object> row : rows) {
|
||||
Map<String, Object> 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<Map<String, Object>> configs = jdbcTemplate.queryForList(sql, configId);
|
||||
if (configs.isEmpty()) {
|
||||
return AjaxResult.error("参数配置不存在");
|
||||
}
|
||||
Map<String, Object> row = configs.get(0);
|
||||
Map<String, Object> 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<Map<String, Object>> 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<String, Object> 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<String, Object> 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("刷新缓存成功");
|
||||
}
|
||||
}
|
||||
|
|
@ -325,5 +325,4 @@ public class SysDictController extends BaseController {
|
|||
}
|
||||
return AjaxResult.success("删除成功");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,158 +0,0 @@
|
|||
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<Object> 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<Map<String, Object>> rows = jdbcTemplate.queryForList(sql.toString(), params.toArray());
|
||||
|
||||
// 转换字段名为驼峰格式
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
for (Map<String, Object> row : rows) {
|
||||
Map<String, Object> 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<Map<String, Object>> notices = jdbcTemplate.queryForList(sql, noticeId);
|
||||
if (notices.isEmpty()) {
|
||||
return AjaxResult.error("通知公告不存在");
|
||||
}
|
||||
Map<String, Object> row = notices.get(0);
|
||||
Map<String, Object> 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<String, Object> 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<String, Object> 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("删除成功");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue