ソースを参照

新增参数配置接口

wangliang 2 年 前
コミット
a582cf6a2b

+ 80 - 0
themis-admin/src/main/java/com/qmth/themis/admin/api/SysConfigController.java

@@ -0,0 +1,80 @@
+package com.qmth.themis.admin.api;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qmth.themis.business.constant.SystemConstant;
+import com.qmth.themis.business.dto.response.SysConfigBean;
+import com.qmth.themis.business.entity.SysConfig;
+import com.qmth.themis.business.service.SysConfigService;
+import com.qmth.themis.common.exception.BusinessException;
+import com.qmth.themis.common.util.GsonUtil;
+import com.qmth.themis.common.util.Result;
+import com.qmth.themis.common.util.ResultUtil;
+import io.swagger.annotations.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import java.util.Optional;
+
+/**
+ * @Description: 系统参数 前端控制器
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/6/25
+ */
+@Api(tags = "系统参数Controller")
+@RestController
+@RequestMapping(SystemConstant.PREFIX_URL_ADMIN + "/sys/config")
+@Validated
+public class SysConfigController {
+    private final static Logger log = LoggerFactory.getLogger(SysConfigController.class);
+
+    @Resource
+    SysConfigService sysConfigService;
+
+    @ApiOperation(value = "系统参数查询接口")
+    @RequestMapping(value = "/select", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "系统参数信息", response = SysConfigBean.class)})
+    public Result select(@ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) int pageNumber,
+                         @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) int pageSize) {
+        return ResultUtil.ok(sysConfigService.select(new Page<>(pageNumber, pageSize)));
+    }
+
+    @ApiOperation(value = "系统参数新增/编辑接口")
+    @RequestMapping(value = "/save", method = RequestMethod.POST)
+    @Transactional
+    @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = Result.class)})
+    public Result save(@Validated @ApiParam(value = "机构信息", required = true) @RequestBody SysConfigBean sysConfigBean, BindingResult bindingResult) {
+        if (bindingResult.hasErrors()) {
+            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
+        }
+        SysConfig sysConfig = GsonUtil.fromJson(GsonUtil.toJson(sysConfigBean), SysConfig.class);
+        sysConfig.setEditor(1);
+        sysConfigService.saveOrUpdate(sysConfig);
+        return ResultUtil.ok(true);
+    }
+
+    @ApiOperation(value = "系统参数启用/禁用接口")
+    @RequestMapping(value = "/enable", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = Result.class)})
+    @Transactional
+    public Result enable(@ApiParam(value = "系统参数id", required = true) @RequestParam Long id,
+                         @ApiParam(value = "启用/禁用", required = true) @RequestParam Boolean enable) {
+        Optional.ofNullable(id).orElseThrow(() -> new BusinessException("系统参数id不能为空"));
+        Optional.ofNullable(enable).orElseThrow(() -> new BusinessException("启用/禁用不能为空"));
+
+        SysConfig sysConfig = sysConfigService.getById(id);
+        Optional.ofNullable(sysConfig).orElseThrow(() -> new BusinessException("系统参数信息为空"));
+
+        sysConfig.setEnable(enable);
+        sysConfigService.saveOrUpdate(sysConfig);
+        return ResultUtil.ok(true);
+    }
+}

+ 11 - 0
themis-business/src/main/java/com/qmth/themis/business/dao/SysConfigMapper.java

@@ -1,9 +1,13 @@
 package com.qmth.themis.business.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.qmth.themis.business.dto.response.SysConfigBean;
 import com.qmth.themis.business.entity.SysConfig;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.Map;
+
 /**
  * @Description: 系统参数 Mapper 接口
  * @Param:
@@ -14,4 +18,11 @@ import org.apache.ibatis.annotations.Mapper;
 @Mapper
 public interface SysConfigMapper extends BaseMapper<SysConfig> {
 
+    /**
+     * 系统配置分页查询
+     *
+     * @param iPage
+     * @return
+     */
+    public IPage<SysConfigBean> select(IPage<Map> iPage);
 }

+ 125 - 0
themis-business/src/main/java/com/qmth/themis/business/dto/response/SysConfigBean.java

@@ -0,0 +1,125 @@
+package com.qmth.themis.business.dto.response;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModelProperty;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+/**
+ * @Description: 机构 bean
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/8/3
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class SysConfigBean implements Serializable {
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "主键")
+    private Long id;
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "机构id")
+    private Long orgId;
+
+    /**
+     * 参数键值
+     */
+    @TableField("config_key")
+    @NotNull(message = "参数名称不能为空")
+    private String configKey;
+
+    /**
+     * 参数名称
+     */
+    @TableField("config_name")
+    @NotNull(message = "描述不能为空")
+    private String configName;
+
+    /**
+     * 参数键值
+     */
+    @TableField("config_value")
+    @NotNull(message = "参数值不能为空")
+    private String configValue;
+
+    @ApiModelProperty(value = "是否启用,false:停用,true:启用")
+    @TableField(value = "enable")
+    private Boolean enable;
+
+    @ApiModelProperty(value = "备注")
+    private String remark;
+
+    @ApiModelProperty(value = "排序")
+    private Integer sort = 1;
+
+    public Long getOrgId() {
+        return orgId;
+    }
+
+    public void setOrgId(Long orgId) {
+        this.orgId = orgId;
+    }
+
+    public Integer getSort() {
+        return sort;
+    }
+
+    public void setSort(Integer sort) {
+        this.sort = sort;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getConfigKey() {
+        return configKey;
+    }
+
+    public void setConfigKey(String configKey) {
+        this.configKey = configKey;
+    }
+
+    public String getConfigName() {
+        return configName;
+    }
+
+    public void setConfigName(String configName) {
+        this.configName = configName;
+    }
+
+    public String getConfigValue() {
+        return configValue;
+    }
+
+    public void setConfigValue(String configValue) {
+        this.configValue = configValue;
+    }
+
+    public Boolean getEnable() {
+        return enable;
+    }
+
+    public void setEnable(Boolean enable) {
+        this.enable = enable;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+}

+ 38 - 4
themis-business/src/main/java/com/qmth/themis/business/entity/SysConfig.java

@@ -33,15 +33,49 @@ public class SysConfig extends BaseEntity {
      */
     @TableField("config_name")
     private String configName;
+
     /**
      * 参数键值
      */
     @TableField("config_value")
     private String configValue;
 
-    @ApiModelProperty(value = "是否启用,0:停用,1:启用")
+    @ApiModelProperty(value = "是否启用,false:停用,true:启用")
     @TableField(value = "enable")
-    private Integer enable;
+    private Boolean enable;
+
+    @ApiModelProperty(value = "备注")
+    private String remark;
+
+    @ApiModelProperty(value = "排序")
+    private Integer sort = 1;
+
+    @ApiModelProperty(value = "是否可编辑,1:是,0:否")
+    private Integer editor;
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
+    public Integer getSort() {
+        return sort;
+    }
+
+    public void setSort(Integer sort) {
+        this.sort = sort;
+    }
+
+    public Integer getEditor() {
+        return editor;
+    }
+
+    public void setEditor(Integer editor) {
+        this.editor = editor;
+    }
 
     public Long getOrgId() {
         return orgId;
@@ -75,11 +109,11 @@ public class SysConfig extends BaseEntity {
         this.configValue = configValue;
     }
 
-    public Integer getEnable() {
+    public Boolean getEnable() {
         return enable;
     }
 
-    public void setEnable(Integer enable) {
+    public void setEnable(Boolean enable) {
         this.enable = enable;
     }
 }

+ 12 - 0
themis-business/src/main/java/com/qmth/themis/business/service/SysConfigService.java

@@ -1,9 +1,13 @@
 package com.qmth.themis.business.service;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.themis.business.dto.response.SysConfigBean;
 import com.qmth.themis.business.entity.SysConfig;
+import com.qmth.themis.business.entity.TSNotify;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: 系统参数 服务类
@@ -20,4 +24,12 @@ public interface SysConfigService extends IService<SysConfig> {
      * @return
      */
     List<SysConfig> selectAll();
+
+    /**
+     * 系统配置分页查询
+     *
+     * @param iPage
+     * @return
+     */
+    public IPage<SysConfigBean> select(IPage<Map> iPage);
 }

+ 18 - 1
themis-business/src/main/java/com/qmth/themis/business/service/impl/SysConfigServiceImpl.java

@@ -1,17 +1,20 @@
 package com.qmth.themis.business.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dao.SysConfigMapper;
+import com.qmth.themis.business.dto.response.SysConfigBean;
 import com.qmth.themis.business.entity.SysConfig;
-import com.qmth.themis.business.service.ThemisCacheService;
 import com.qmth.themis.business.service.SysConfigService;
+import com.qmth.themis.business.service.ThemisCacheService;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: 系统参数 服务实现类
@@ -26,6 +29,9 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
     @Resource
     ThemisCacheService themisCacheService;
 
+    @Resource
+    SysConfigMapper sysConfigMapper;
+
     /**
      * 查询所有系统配置项
      *
@@ -48,4 +54,15 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
         }
         return sysConfigList;
     }
+
+    /**
+     * 系统配置分页查询
+     *
+     * @param iPage
+     * @return
+     */
+    @Override
+    public IPage<SysConfigBean> select(IPage<Map> iPage) {
+        return sysConfigMapper.select(iPage);
+    }
 }

+ 11 - 0
themis-business/src/main/resources/mapper/SysConfigMapper.xml

@@ -2,4 +2,15 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.qmth.themis.business.dao.SysConfigMapper">
 
+    <select id="select" resultType="com.qmth.themis.business.dto.response.SysConfigBean">
+        select t.id,
+              t.org_id as orgId,
+              t.config_key as configKey,
+              t.config_name as configName,
+              t.config_value as configValue,
+              t.enable,
+              t.remark,
+              t.sort
+        from sys_config t where t.editor = 1
+    </select>
 </mapper>