Quellcode durchsuchen

完成系统配置功能

tsurumure vor 7 Monaten
Ursprung
Commit
d935b58811

+ 4 - 4
db/sys_common.sql

@@ -7,16 +7,16 @@ Date: 2023/05/23 17:09:22
 DROP TABLE IF EXISTS `sys_common`;
 CREATE TABLE `sys_common` (
     PRIMARY KEY (`id`),
-    `id` BIGINT AUTO_INCREMENT COMMENT 'ID',
+    `id` BIGINT NOT NULL COMMENT 'ID',
     `name` VARCHAR(100) NOT NULL COMMENT '配置名称',
     `value` TEXT COMMENT '配置值',
-    `value_type` VARCHAR(20) DEFAULT 'text' COMMENT '配置值类型 (text, textarea, number, radio, checkbox, select)',
+    `value_type` VARCHAR(20) DEFAULT 'text' COMMENT '配置值类型 (Text, Textarea, Number, Radio, Checkbox, Select)',
     `value_option` TEXT COMMENT '配置值选项 (除文本框外必填)',
     `tag` VARCHAR(20) NOT NULL COMMENT '标识',
     `sort` INT DEFAULT '1' COMMENT '排序',
     `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
 ) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='系统配置表';
 
-INSERT INTO sys_common(name, value, value_type, value_option, tag, sort) VALUES
-    ('单文件上传大小限制(MB)', 100, 'number', null, 'upload', 1)
+INSERT INTO sys_common(id, name, value, value_type, value_option, tag, sort) VALUES
+    (1, '单文件上传大小限制(MB)', 100, 'Number', null, 'upload', 1)
 ;

+ 5 - 0
db/sys_user_role_permission.sql

@@ -85,6 +85,11 @@ INSERT INTO sys_user_role_permission(id, parent_id, permission_name, sort) VALUE
     ('5', -1, '系统日志管理', 901),
         ('5.1', '5', '系统日志列表', null),
 
+    ('6', -1, '系统配置管理', 901),
+        ('6.1', '6', '系统日志列表', null),
+            ('6.1.1', '6.1', '系统日志详情', null),
+            ('6.1.3', '6.1', '编辑系统日志', null),
+
     ('10', -1, '内容管理', null),
         ('10.1', '10', '幻灯片列表', null),
             ('10.1.1', '10.1', '幻灯片详情', null),

+ 3 - 0
db/sys_user_role_permission_relation.sql

@@ -43,6 +43,9 @@ INSERT INTO sys_user_role_permission_relation(role_id, permission_id) VALUES
             (1, '4.3.1'), (1, '4.3.2'), (1, '4.3.3'), (1, '4.3.4'),
     (1, '5'),
         (1, '5.1'),
+    (1, '6'),
+        (1, '6.1'),
+            (1, '6.1.1'), (1, '6.1.3'),
     (1, '10'),
         (1, '10.1'),
             (1, '10.1.1'), (1, '10.1.2'), (1, '10.1.3'), (1, '10.1.4'),

+ 53 - 0
src/main/java/com/backendsys/modules/system/controller/SysCommonController.java

@@ -0,0 +1,53 @@
+package com.backendsys.modules.system.controller;
+
+import com.backendsys.modules.common.utils.Result;
+import com.backendsys.modules.system.entity.SysCommon;
+import com.backendsys.modules.system.entity.SysLogEntity;
+import com.backendsys.modules.system.service.SysCommonService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.ibatis.annotations.Update;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+@Validated
+@RestController
+@Tag(name = "系统配置")
+public class SysCommonController {
+
+    @Autowired
+    private SysCommonService sysCommonService;
+
+    @Operation(summary = "获取系统配置列表")
+    @PreAuthorize("@sr.hasPermission('6.1')")
+    @GetMapping("/api/system/common/getCommonList")
+    public Result getCommonList(String tag) {
+        return Result.success().put("data", sysCommonService.selectCommonList(tag));
+    }
+
+    @Operation(summary = "获取系统配置详情")
+    @PreAuthorize("@sr.hasPermission('6.1.1')")
+    @GetMapping("/api/system/common/getCommonDetail")
+    public Result getCommonDetail(@Validated(SysCommon.Detail.class) SysCommon sysCommon) {
+        return Result.success().put("data", sysCommonService.selectCommonDetail(sysCommon));
+    }
+
+    @Operation(summary = "编辑系统配置")
+    @PreAuthorize("@sr.hasPermission('6.1.3')")
+    @PutMapping("/api/system/common/updateCommon")
+    public Result updateCommon(@Validated(SysCommon.Update.class) @RequestBody SysCommon sysCommon) {
+        return Result.success().put("data", sysCommonService.updateCommon(sysCommon));
+    }
+
+//    // 测试后删除
+//    @GetMapping("/api/system/common/getCommonValue")
+//    public Object getCommonValue(Long id) {
+//        return sysCommonService.getCommonValue(id);
+//    }
+
+}

+ 14 - 0
src/main/java/com/backendsys/modules/system/dao/SysCommonDao.java

@@ -0,0 +1,14 @@
+package com.backendsys.modules.system.dao;
+
+import com.backendsys.modules.system.entity.SysCommon;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.Map;
+
+@Mapper
+public interface SysCommonDao extends BaseMapper<SysCommon> {
+
+    int updateCommon(SysCommon sysCommon);
+
+}

+ 16 - 1
src/main/java/com/backendsys/modules/system/entity/SysCommon.java

@@ -1,20 +1,35 @@
 package com.backendsys.modules.system.entity;
 
+import com.backendsys.entity.Ai.Aiivh.AiivhMakeBroadcastTask.AiivhMakeBroadcastTaskDTO;
+import com.backendsys.entity.validator.RangeStringArray;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+import jakarta.validation.constraints.NotEmpty;
+import jakarta.validation.constraints.NotNull;
+import jakarta.validation.constraints.Size;
 import lombok.Data;
 
 @Data
 @TableName("sys_common")
 public class SysCommon {
 
-    @TableId(type = IdType.AUTO)
+    public static interface Detail{}
+    public static interface Update{}
+
+    @TableId(type = IdType.NONE)
+    @NotNull(message = "id 不能为空", groups = { Detail.class, Update.class })
     private Long id;
+
+    @NotEmpty(message = "配置名称不能为空", groups = { Update.class })
+    @Size(max = 20, message = "配置名称长度不超过 {max} 个字符", groups = { Update.class })
     private String name;
     private String value;
+    @RangeStringArray(message="配置值类型取值有误,范围应是(Text, Textarea, Number, Radio, Checkbox, Select)", value = { "Text", "Textarea", "Number", "Radio", "Checkbox", "Select" }, groups = { Update.class })
     private String value_type;
     private String value_option;
+    @NotEmpty(message = "标识不能为空", groups = { Update.class })
+    @Size(max = 20, message = "标识长度不超过 {max} 个字符", groups = { Update.class })
     private String tag;
     private Integer sort;
     private String create_time;

+ 20 - 0
src/main/java/com/backendsys/modules/system/service/SysCommonService.java

@@ -0,0 +1,20 @@
+package com.backendsys.modules.system.service;
+
+import com.backendsys.modules.system.entity.SysCommon;
+import com.backendsys.utils.response.PageEntity;
+
+import java.util.Map;
+
+public interface SysCommonService {
+
+    // 获取系统配置列表
+    PageEntity selectCommonList(String tag);
+    // 获取系统配置详情
+    SysCommon selectCommonDetail(SysCommon sysCommon);
+    // 编辑系统配置
+    Map<String, Object> updateCommon(SysCommon sysCommon);
+
+    // 获取系统配置值
+    Object getCommonValue(Long id);
+
+}

+ 73 - 0
src/main/java/com/backendsys/modules/system/service/impl/SysCommonServiceImpl.java

@@ -0,0 +1,73 @@
+package com.backendsys.modules.system.service.impl;
+
+import cn.hutool.core.util.StrUtil;
+import com.backendsys.exception.CustException;
+import com.backendsys.modules.system.dao.SysCommonDao;
+import com.backendsys.modules.system.entity.SysCommon;
+import com.backendsys.modules.system.service.SysCommonService;
+import com.backendsys.utils.response.PageEntity;
+import com.backendsys.utils.response.PageInfoResult;
+import com.backendsys.utils.v2.PageUtils;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class SysCommonServiceImpl implements SysCommonService {
+
+    @Autowired
+    private SysCommonDao sysCommonDao;
+
+    /**
+     * 获得系统配置列表
+     */
+    @Override
+    public PageEntity selectCommonList(String tag) {
+        PageUtils.startPage();  // 分页
+
+        LambdaQueryWrapper<SysCommon> wrapper = new LambdaQueryWrapper<>();
+        if (StrUtil.isNotEmpty(tag)) wrapper.eq(SysCommon::getTag, tag);
+
+        wrapper.orderByDesc(SysCommon::getSort);
+        List<SysCommon> list = sysCommonDao.selectList(wrapper);
+        return new PageInfoResult(list).toEntity();
+    }
+
+    /**
+     * 获取系统配置详情
+     */
+    @Override
+    public SysCommon selectCommonDetail(SysCommon sysCommon) {
+        LambdaQueryWrapper<SysCommon> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(SysCommon::getId, sysCommon.getId());
+        return sysCommonDao.selectOne(wrapper);
+    }
+
+    /**
+     * 编辑系统配置
+     */
+    @Override
+    public Map<String, Object> updateCommon(SysCommon sysCommon) {
+
+        SysCommon detail = sysCommonDao.selectById(sysCommon.getId());
+        if (detail == null) throw new CustException("系统配置不存在");
+
+        return Map.of("id", sysCommonDao.updateCommon(sysCommon));
+    }
+
+
+
+
+    // 获取系统配置值
+    @Override
+    public Object getCommonValue(Long id) {
+        LambdaQueryWrapper<SysCommon> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(SysCommon::getId, id);
+        SysCommon sysCommon = sysCommonDao.selectOne(wrapper);
+        return (sysCommon != null) ? sysCommon.getValue() : null;
+    }
+
+}

+ 41 - 0
src/main/resources/mapper/system/SysCommonDao.xml

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.backendsys.modules.system.dao.SysCommonDao">
+
+<!--    <sql id="includeCommon">-->
+<!--        id,-->
+<!--        name,-->
+<!--        COALESCE(value, '') value,-->
+<!--        value_type,-->
+<!--        COALESCE(value_option, '') value_option,-->
+<!--        tag,-->
+<!--        COALESCE(sort, '') sort,-->
+<!--        create_time-->
+<!--    </sql>-->
+
+<!--    <resultMap id="resultMapCommonList" type="java.util.LinkedHashMap">-->
+<!--        <id property="id" column="id" jdbcType="BIGINT" />-->
+<!--        <result property="name" column="name" />-->
+<!--        <result property="value" column="value" />-->
+<!--        <result property="value_type" column="value_type" />-->
+<!--        <result property="value_option" column="value_option" />-->
+<!--        <result property="tag" column="tag" />-->
+<!--        <result property="sort" column="sort" javaType="java.lang.Integer" />-->
+<!--        <result property="create_time" column="create_time" />-->
+<!--    </resultMap>-->
+
+    <update id="updateCommon" parameterType="com.backendsys.modules.system.entity.SysCommon"
+            useGeneratedKeys="true" keyProperty="id">
+        UPDATE sys_common SET
+        <trim suffixOverrides="," suffix=" ">
+            <if test="name != null and name != ''">name = #{name},</if>
+            <if test="value != null and value != ''">value = #{value},</if>
+            <if test="value_type != null and value_type != ''">value_type = #{value_type},</if>
+            <if test="value_option != null and value_option != ''">value_option = #{value_option},</if>
+            <if test="tag != null and tag != ''">tag = #{tag},</if>
+            <if test="sort != null and sort != ''">sort = #{sort},</if>
+        </trim>
+        WHERE id = #{id};
+    </update>
+
+</mapper>