init
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.newyetai.config.constant;
|
||||
|
||||
/**
|
||||
* 配置常量类
|
||||
* @author sr on 2019-10-20
|
||||
*/
|
||||
public class ConfigConstants {
|
||||
|
||||
/**
|
||||
* -----校验信息-----
|
||||
**/
|
||||
public static final String CONFIG_ID_NULL = "配置id不能为空";
|
||||
public static final String CONFIG_CODE_EMPTY = "配置编码不能为空";
|
||||
/** -----校验信息----- **/
|
||||
|
||||
|
||||
/**
|
||||
* -----异常信息-----
|
||||
**/
|
||||
public static final String CONFIG_CODE_EXIST = "配置编码已存在";
|
||||
public static final String CONFIG_NOT_EXIST = "未找到对应配置";
|
||||
/** -----异常信息----- **/
|
||||
|
||||
/**
|
||||
* 业务数据忽略机构配置
|
||||
*/
|
||||
public static final String CONFIG_IGNORE_ORG_INFO = "ignore_org_info";
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.newyetai.config.controller;
|
||||
|
||||
import com.newyetai.common.AlitaResult;
|
||||
import com.newyetai.common.util.UserContextHolder;
|
||||
import com.newyetai.common.validation.Create;
|
||||
import com.newyetai.config.dao.ConfigMapper;
|
||||
import com.newyetai.config.dto.*;
|
||||
import com.newyetai.config.service.ConfigService;
|
||||
import com.newyetai.tkmybatis.pojo.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 配置操作
|
||||
*
|
||||
* @author on 2019-11-05
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("config")
|
||||
@Api(tags = "配置操作")
|
||||
public class ConfigController {
|
||||
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
@Resource
|
||||
private ConfigMapper configMapper;
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation("配置表-创建")
|
||||
public AlitaResult<ConfigDTO> create(@RequestBody ConfigOperatorDTO operatorDTO) {
|
||||
return AlitaResult.success(configService.create(operatorDTO));
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@ApiOperation("配置表-修改")
|
||||
public AlitaResult<ConfigDTO> modify(@RequestBody ConfigOperatorDTO operatorDTO) {
|
||||
return AlitaResult.success(configService.modify(operatorDTO));
|
||||
}
|
||||
|
||||
@DeleteMapping("{id}")
|
||||
@ApiOperation("配置表-删除")
|
||||
public AlitaResult<ConfigDTO> delete(@PathVariable("id") Long id) {
|
||||
return AlitaResult.success(configService.delete(id));
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
@ApiOperation("配置表-查询单个")
|
||||
public AlitaResult<ConfigDTO> findById(@PathVariable("id") Long id) {
|
||||
return AlitaResult.success(configService.findById(id));
|
||||
}
|
||||
|
||||
@GetMapping("list")
|
||||
@ApiOperation("配置表-列表查询")
|
||||
public AlitaResult<List<ConfigDTO>> list(ConfigQueryDTO queryDTO) {
|
||||
return AlitaResult.success(configService.list(queryDTO));
|
||||
}
|
||||
|
||||
@GetMapping("page")
|
||||
@ApiOperation("配置表-分页查询")
|
||||
public AlitaResult<Page<ConfigDTO>> page(ConfigPageQueryDTO queryDTO) {
|
||||
configService.page(queryDTO);
|
||||
return AlitaResult.success(queryDTO.getPageResult());
|
||||
}
|
||||
|
||||
@GetMapping("org_list/{configCode}")
|
||||
@ApiOperation("可分配的机构列表")
|
||||
public AlitaResult<List<OrgInfoDTO>> orgListCanSelect(@PathVariable("configCode") String configCode) {
|
||||
return AlitaResult.success(configMapper.orgList(configCode));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ApiOperation("根据编码获取配置")
|
||||
@GetMapping("/code/{configCode}")
|
||||
public AlitaResult<ConfigDTO> getTemplate(@PathVariable("configCode") String configCode) {
|
||||
return AlitaResult
|
||||
.success(configService.queryConfigByCode(UserContextHolder.getExistLoginOrgId(), configCode));
|
||||
}
|
||||
|
||||
@ApiOperation("根据编码获取配置")
|
||||
@GetMapping("/org_code/{configCode}")
|
||||
public AlitaResult<ConfigDTO> getOrgConfig(@PathVariable("configCode") String configCode) {
|
||||
return AlitaResult
|
||||
.success(configService.queryOrgConfigByCode(UserContextHolder.getExistLoginOrgId(), configCode));
|
||||
}
|
||||
|
||||
}
|
||||
25
src/main/java/com/newyetai/config/convert/ConfigConvert.java
Normal file
25
src/main/java/com/newyetai/config/convert/ConfigConvert.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.newyetai.config.convert;
|
||||
|
||||
import com.newyetai.config.dto.ConfigDTO;
|
||||
import com.newyetai.config.dto.ConfigOperatorDTO;
|
||||
import com.newyetai.config.entity.Config;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 配置表
|
||||
*
|
||||
* @author chenyun chenyun.home@outlook.com
|
||||
* @since 1.0.0 2023-01-04
|
||||
*/
|
||||
@Mapper
|
||||
public interface ConfigConvert {
|
||||
ConfigConvert INSTANCE = Mappers.getMapper(ConfigConvert.class);
|
||||
|
||||
Config convert(ConfigDTO dto);
|
||||
|
||||
ConfigDTO convert(Config entity);
|
||||
|
||||
Config convert(ConfigOperatorDTO dto);
|
||||
|
||||
}
|
||||
94
src/main/java/com/newyetai/config/dao/ConfigMapper.java
Normal file
94
src/main/java/com/newyetai/config/dao/ConfigMapper.java
Normal file
@@ -0,0 +1,94 @@
|
||||
package com.newyetai.config.dao;
|
||||
|
||||
import com.newyetai.config.dto.ConfigDTO;
|
||||
import com.newyetai.config.dto.ConfigPageQueryDTO;
|
||||
import com.newyetai.config.dto.ConfigQueryDTO;
|
||||
import com.newyetai.config.dto.OrgInfoDTO;
|
||||
import com.newyetai.config.entity.Config;
|
||||
import com.newyetai.tkmybatis.mybatis.MyMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 配置mapper
|
||||
*
|
||||
* @author sr on 2019-10-20
|
||||
*/
|
||||
public interface ConfigMapper extends MyMapper<Config> {
|
||||
|
||||
/**
|
||||
* 排除已经被分配的配置机构,剩余的机构
|
||||
*
|
||||
* @param configCode 配置代码
|
||||
* @return {@link List}<{@link OrgInfoDTO}>
|
||||
*/
|
||||
List<OrgInfoDTO> orgList(@Param("configCode") String configCode);
|
||||
|
||||
List<ConfigDTO> page(@Param("param") ConfigPageQueryDTO queryDTO);
|
||||
|
||||
List<ConfigDTO> list(@Param("param") ConfigQueryDTO queryDTO);
|
||||
|
||||
/**
|
||||
* 查询配置
|
||||
*
|
||||
* @param config
|
||||
* @return
|
||||
* @author sr on 2019-11-05
|
||||
*/
|
||||
List<Config> find(@Param("param") Config config);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param configCode
|
||||
* @param orgIds
|
||||
* @return
|
||||
*/
|
||||
List<Config> listByCodeAndOrgIds(@Param("configCode") String configCode, @Param("orgIds") Set<Long> orgIds);
|
||||
|
||||
/**
|
||||
* 校验配置编码是否存在
|
||||
* @param orgId
|
||||
* @param configCode
|
||||
* @param configId 为空则判断所有(新增),不为空代表判断除该id之外的(修改)
|
||||
* @return
|
||||
* @author sr on 2019-10-20
|
||||
*/
|
||||
int existConfigCode(@Param("orgId") Long orgId, @Param("configCode") String configCode, @Param("configId") Long configId);
|
||||
|
||||
/**
|
||||
* 根据编码获取配置
|
||||
* @param platformOrgId
|
||||
* @param orgId
|
||||
* @param configCode
|
||||
* @return
|
||||
* @author sr on 2019-10-23
|
||||
*/
|
||||
ConfigDTO queryConfigByCode(@Param("platformOrgId") Long platformOrgId,
|
||||
@Param("orgId") Long orgId, @Param("configCode") String configCode);
|
||||
|
||||
/**
|
||||
* 根据编码获取机构配置
|
||||
* @param orgId
|
||||
* @param configCode
|
||||
* @return
|
||||
* @author sr on 2019-10-23
|
||||
*/
|
||||
ConfigDTO queryOrgConfigByCode(@Param("orgId") Long orgId, @Param("configCode") String configCode);
|
||||
|
||||
/**
|
||||
* 新增并校验是否重复(org_id,config_code),重复则不新增
|
||||
*
|
||||
* @param config
|
||||
*/
|
||||
int saveAndCheckExist(@Param("param") Config config, @Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param configCode 配置代码
|
||||
* @param userId 用户id
|
||||
*/
|
||||
void batchDelete(@Param("configCode") String configCode, @Param("userId") Long userId);
|
||||
}
|
||||
52
src/main/java/com/newyetai/config/dto/ConfigDTO.java
Normal file
52
src/main/java/com/newyetai/config/dto/ConfigDTO.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.newyetai.config.dto;
|
||||
|
||||
import com.newyetai.common.dto.BaseDTO;
|
||||
import com.newyetai.common.validation.Create;
|
||||
import com.newyetai.common.validation.Update;
|
||||
import com.newyetai.config.constant.ConfigConstants;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 配置
|
||||
*
|
||||
* @author on 2019-11-05
|
||||
*/
|
||||
@ApiModel("配置")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ConfigDTO extends BaseDTO implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
**/
|
||||
private static final long serialVersionUID = -7378966546274876887L;
|
||||
|
||||
@ApiModelProperty("配置id")
|
||||
@NotNull(message = ConfigConstants.CONFIG_ID_NULL, groups = {Update.class})
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty("机构名称")
|
||||
private String orgName;
|
||||
|
||||
private Long orgId;
|
||||
|
||||
@ApiModelProperty("编码")
|
||||
@NotBlank(message = ConfigConstants.CONFIG_CODE_EMPTY, groups = {Create.class, Update.class})
|
||||
private String configCode;
|
||||
|
||||
@ApiModelProperty("配置值")
|
||||
private String configValue;
|
||||
|
||||
@ApiModelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty("是否启用")
|
||||
private Boolean enable;
|
||||
}
|
||||
45
src/main/java/com/newyetai/config/dto/ConfigOperatorDTO.java
Normal file
45
src/main/java/com/newyetai/config/dto/ConfigOperatorDTO.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package com.newyetai.config.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 配置表
|
||||
*
|
||||
* @author chenyun chenyun.home@outlook.com
|
||||
* @since 1.0.0 2023-01-04
|
||||
*/
|
||||
@ApiModel("配置表")
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ConfigOperatorDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6593867699038600971L;
|
||||
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty("编码")
|
||||
private String configCode;
|
||||
|
||||
@ApiModelProperty("配置值")
|
||||
private String configValue;
|
||||
|
||||
@ApiModelProperty("机构")
|
||||
private Long orgId;
|
||||
|
||||
@ApiModelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty("是否启用")
|
||||
private Boolean enable;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.newyetai.config.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.newyetai.common.annotation.trimAndUpper.TrimAndUpper;
|
||||
import com.newyetai.common.dto.PageQueryDTO;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 配置表
|
||||
*
|
||||
* @author chenyun chenyun.home@outlook.com
|
||||
* @since 1.0.0 2023-01-04
|
||||
*/
|
||||
|
||||
@ApiModel("配置表")
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ConfigPageQueryDTO extends PageQueryDTO<ConfigDTO> {
|
||||
|
||||
private static final long serialVersionUID = -2457835934025456625L;
|
||||
|
||||
@ApiModelProperty("主键ID")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty("机构名称 (模糊匹配)")
|
||||
@TrimAndUpper(TrimAndUpper.ExecuteType.TRIM)
|
||||
private String orgNameLike;
|
||||
|
||||
@ApiModelProperty("编码")
|
||||
private String configCode;
|
||||
|
||||
@ApiModelProperty("编码(模糊匹配)")
|
||||
@TrimAndUpper(TrimAndUpper.ExecuteType.TRIM)
|
||||
private String configCodeLike;
|
||||
|
||||
@ApiModelProperty("配置值")
|
||||
private String configValue;
|
||||
|
||||
@ApiModelProperty("机构")
|
||||
private Long orgId;
|
||||
|
||||
@ApiModelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty("是否启用")
|
||||
private Boolean enable;
|
||||
|
||||
@ApiModelProperty("创建时间起,格式 (yyyy-MM-dd HH:mm:ss)")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createTimeStart;
|
||||
|
||||
@ApiModelProperty("创建时间止,格式 (yyyy-MM-dd HH:mm:ss)")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createTimeEnd;
|
||||
|
||||
@ApiModelProperty("修改时间起,格式 (yyyy-MM-dd HH:mm:ss)")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTimeStart;
|
||||
|
||||
@ApiModelProperty("修改时间止,格式 (yyyy-MM-dd HH:mm:ss)")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTimeEnd;
|
||||
|
||||
|
||||
}
|
||||
76
src/main/java/com/newyetai/config/dto/ConfigQueryDTO.java
Normal file
76
src/main/java/com/newyetai/config/dto/ConfigQueryDTO.java
Normal file
@@ -0,0 +1,76 @@
|
||||
package com.newyetai.config.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 配置表
|
||||
*
|
||||
* @author chenyun chenyun.home@outlook.com
|
||||
* @since 1.0.0 2023-01-04
|
||||
*/
|
||||
@ApiModel("配置表")
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ConfigQueryDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 2141446474852301916L;
|
||||
|
||||
@ApiModelProperty("主键ID")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty("编码")
|
||||
private String configCode;
|
||||
|
||||
@ApiModelProperty("编码(模糊匹配)")
|
||||
private String configCodeLike;
|
||||
|
||||
@ApiModelProperty("配置值")
|
||||
private String configValue;
|
||||
|
||||
@ApiModelProperty("机构")
|
||||
private Long orgId;
|
||||
|
||||
@ApiModelProperty("机构集合")
|
||||
private Set<Long> orgIds;
|
||||
|
||||
@ApiModelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty("是否启用")
|
||||
private Boolean enable;
|
||||
|
||||
@ApiModelProperty("创建时间起,格式 (yyyy-MM-dd HH:mm:ss)")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createTimeStart;
|
||||
|
||||
@ApiModelProperty("创建时间止,格式 (yyyy-MM-dd HH:mm:ss)")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createTimeEnd;
|
||||
|
||||
@ApiModelProperty("修改时间起,格式 (yyyy-MM-dd HH:mm:ss)")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTimeStart;
|
||||
|
||||
@ApiModelProperty("修改时间止,格式 (yyyy-MM-dd HH:mm:ss)")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTimeEnd;
|
||||
|
||||
|
||||
}
|
||||
26
src/main/java/com/newyetai/config/dto/OrgInfoDTO.java
Normal file
26
src/main/java/com/newyetai/config/dto/OrgInfoDTO.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package com.newyetai.config.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class OrgInfoDTO implements Serializable {
|
||||
private static final long serialVersionUID = 4030022865543182548L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 机构名字
|
||||
*/
|
||||
private String orgName;
|
||||
}
|
||||
64
src/main/java/com/newyetai/config/entity/Config.java
Normal file
64
src/main/java/com/newyetai/config/entity/Config.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package com.newyetai.config.entity;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.newyetai.common.entity.BaseEntity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 配置
|
||||
*
|
||||
* @author on 2019-11-05
|
||||
*/
|
||||
@TableName(value = "xs_config")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class Config extends BaseEntity {
|
||||
|
||||
/** **/
|
||||
private static final long serialVersionUID = -4915635782620683517L;
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
private String configCode;
|
||||
/**
|
||||
* 配置值
|
||||
*/
|
||||
private String configValue;
|
||||
/**
|
||||
* 机构
|
||||
*/
|
||||
private Long orgId;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Boolean enable;
|
||||
|
||||
@Builder
|
||||
public Config(Long id, Boolean deleted, Long createBy, Date createTime, Long updateBy,
|
||||
Date updateTime, Long proxyBy, String configCode, String configValue, Long orgId,
|
||||
String remark, Boolean enable) {
|
||||
super(id, deleted, createBy, createTime, updateBy, updateTime, proxyBy);
|
||||
this.configCode = configCode;
|
||||
this.configValue = configValue;
|
||||
this.orgId = orgId;
|
||||
this.remark = remark;
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
222
src/main/java/com/newyetai/config/mapper/ConfigMapper.xml
Normal file
222
src/main/java/com/newyetai/config/mapper/ConfigMapper.xml
Normal file
@@ -0,0 +1,222 @@
|
||||
<?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.newyetai.config.dao.ConfigMapper">
|
||||
<update id="batchDelete">
|
||||
UPDATE xs_config
|
||||
SET deleted = TRUE,
|
||||
update_time = NOW(),
|
||||
update_by = #{userId}
|
||||
WHERE deleted = 0
|
||||
AND config_code = #{configCode}
|
||||
</update>
|
||||
|
||||
<select id="list" resultType="com.newyetai.config.dto.ConfigDTO">
|
||||
SELECT t.*
|
||||
<include refid="queryFromSql"></include>
|
||||
</select>
|
||||
|
||||
<select id="page" resultType="com.newyetai.config.dto.ConfigDTO">
|
||||
SELECT t.* ,o.org_name,o.id orgId
|
||||
FROM
|
||||
xs_config t
|
||||
LEFT JOIN xs_org o ON t.org_id = o.id AND o.deleted = 0
|
||||
WHERE t.deleted = 0
|
||||
<if test='param.id != null'>
|
||||
AND t.id = #{param.id}
|
||||
</if>
|
||||
<if test='param.orgNameLike != null and param.orgNameLike != "" '>
|
||||
<bind name="orgNameLike" value="'%' + param.orgNameLike + '%'"/>
|
||||
AND o.org_name like #{orgNameLike}
|
||||
</if>
|
||||
<if test='param.configCode != null and param.configCode.trim() != ""'>
|
||||
AND t.config_code = #{param.configCode}
|
||||
</if>
|
||||
<if test='param.configValue != null and param.configValue.trim() != ""'>
|
||||
AND t.config_value = #{param.configValue}
|
||||
</if>
|
||||
<if test='param.configCodeLike != null and param.configCodeLike.trim() != ""'>
|
||||
<bind name="configCodeLike" value="'%' + param.configCodeLike + '%'"/>
|
||||
and config_code like #{configCodeLike}
|
||||
</if>
|
||||
<if test='param.orgId != null'>
|
||||
AND t.org_id = #{param.orgId}
|
||||
</if>
|
||||
<if test='param.remark != null and param.remark.trim() != ""'>
|
||||
AND t.remark = #{param.remark}
|
||||
</if>
|
||||
<if test='param.enable != null'>
|
||||
AND t.enable = #{param.enable}
|
||||
</if>
|
||||
<if test='param.createTimeStart != null'>
|
||||
AND t.create_time >= #{param.createTimeStart}
|
||||
</if>
|
||||
<if test='param.createTimeEnd != null'>
|
||||
AND t.create_time <= #{param.createTimeEnd}
|
||||
</if>
|
||||
<if test='param.updateTimeStart != null'>
|
||||
AND t.update_time >= #{param.updateTimeStart}
|
||||
</if>
|
||||
<if test='param.updateTimeEnd != null'>
|
||||
AND t.update_time <= #{param.updateTimeEnd}
|
||||
</if>
|
||||
ORDER BY t.id DESC
|
||||
</select>
|
||||
|
||||
<sql id="queryFromSql">
|
||||
FROM
|
||||
xs_config t
|
||||
WHERE t.deleted = 0
|
||||
<if test='param.id != null'>
|
||||
AND t.id = #{param.id}
|
||||
</if>
|
||||
<if test='param.configCode != null and param.configCode.trim() != ""'>
|
||||
AND t.config_code = #{param.configCode}
|
||||
</if>
|
||||
<if test='param.configValue != null and param.configValue.trim() != ""'>
|
||||
AND t.config_value = #{param.configValue}
|
||||
</if>
|
||||
<if test='param.configCodeLike != null and param.configCodeLike.trim() != ""'>
|
||||
<bind name="configCodeLike" value="'%' + param.configCodeLike + '%'"/>
|
||||
and config_code like #{configCodeLike}
|
||||
</if>
|
||||
<if test='param.orgId != null'>
|
||||
AND t.org_id = #{param.orgId}
|
||||
</if>
|
||||
<if test='param.remark != null and param.remark.trim() != ""'>
|
||||
AND t.remark = #{param.remark}
|
||||
</if>
|
||||
<if test='param.enable != null'>
|
||||
AND t.enable = #{param.enable}
|
||||
</if>
|
||||
<if test='param.createTimeStart != null'>
|
||||
AND t.create_time >= #{param.createTimeStart}
|
||||
</if>
|
||||
<if test='param.createTimeEnd != null'>
|
||||
AND t.create_time <= #{param.createTimeEnd}
|
||||
</if>
|
||||
<if test='param.updateTimeStart != null'>
|
||||
AND t.update_time >= #{param.updateTimeStart}
|
||||
</if>
|
||||
<if test='param.updateTimeEnd != null'>
|
||||
AND t.update_time <= #{param.updateTimeEnd}
|
||||
</if>
|
||||
ORDER BY t.id DESC
|
||||
</sql>
|
||||
|
||||
<select id="find" resultType="com.newyetai.config.entity.Config">
|
||||
SELECT * FROM xs_config
|
||||
<where>
|
||||
<choose>
|
||||
<when test="param.deleted != null">
|
||||
AND deleted = #{param.deleted}
|
||||
</when>
|
||||
<otherwise>
|
||||
AND deleted = 0
|
||||
</otherwise>
|
||||
</choose>
|
||||
<choose>
|
||||
<when test="param.enable != null">
|
||||
AND enable = #{param.enable}
|
||||
</when>
|
||||
<otherwise>
|
||||
AND enable = 1
|
||||
</otherwise>
|
||||
</choose>
|
||||
<if test='param.orgId != null'>
|
||||
AND org_id = #{param.orgId}
|
||||
</if>
|
||||
<if test='param.configCode != null and param.configCode.trim() != ""'>
|
||||
AND config_code = #{param.configCode}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="listByCodeAndOrgIds" resultType="com.newyetai.config.entity.Config">
|
||||
SELECT
|
||||
c.*
|
||||
FROM
|
||||
xs_config c
|
||||
WHERE
|
||||
c.deleted = 0
|
||||
AND c.enable = 1
|
||||
<if test="orgIds != null">
|
||||
AND org_id in
|
||||
<foreach close=")" collection="orgIds" index="index" item="orgId" open="("
|
||||
separator=",">#{orgId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="configCode != null">
|
||||
AND config_code = #{configCode}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="existConfigCode" resultType="int">
|
||||
select count(*)
|
||||
from xs_config
|
||||
where org_id = #{orgId} and config_code = #{configCode} and deleted = 0
|
||||
<if test="configId != null">
|
||||
and id != #{configId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="queryConfigByCode" resultType="com.newyetai.config.dto.ConfigDTO">
|
||||
select a.*
|
||||
from (select *
|
||||
from xs_config
|
||||
where config_code = #{configCode}
|
||||
and org_id = #{orgId}
|
||||
and deleted = 0
|
||||
union
|
||||
select *
|
||||
from xs_config
|
||||
where config_code = #{configCode}
|
||||
and org_id = #{platformOrgId}
|
||||
and deleted = 0) a limit 1
|
||||
</select>
|
||||
|
||||
<select id="queryOrgConfigByCode" resultType="com.newyetai.config.dto.ConfigDTO">
|
||||
select *
|
||||
from xs_config
|
||||
where deleted = 0
|
||||
and org_id = #{orgId}
|
||||
and config_code = #{configCode} limit 1
|
||||
</select>
|
||||
<select id="orgList" resultType="com.newyetai.config.dto.OrgInfoDTO">
|
||||
SELECT o.id,
|
||||
o.org_name
|
||||
FROM xs_org o
|
||||
WHERE o.deleted = 0
|
||||
AND o.enable = 1
|
||||
AND o.id NOT IN (SELECT t.org_id
|
||||
FROM xs_config t
|
||||
WHERE t.deleted = 0
|
||||
AND t.config_code = #{configCode})
|
||||
</select>
|
||||
|
||||
<insert id="saveAndCheckExist">
|
||||
INSERT INTO xs_config (config_code,
|
||||
config_value,
|
||||
org_id,
|
||||
remark,
|
||||
enable,
|
||||
deleted,
|
||||
create_time,
|
||||
create_by)
|
||||
SELECT #{param.configCode},
|
||||
#{param.configValue},
|
||||
#{param.orgId},
|
||||
#{param.remark},
|
||||
#{param.enable},
|
||||
0 AS deleted,
|
||||
NOW() AS create_time,
|
||||
#{userId} AS create_by
|
||||
FROM DUAL
|
||||
WHERE NOT EXISTS(SELECT 1
|
||||
FROM xs_config
|
||||
WHERE org_id = #{param.orgId}
|
||||
and config_code = #{param.configCode}
|
||||
and deleted = 0)
|
||||
</insert>
|
||||
</mapper>
|
||||
132
src/main/java/com/newyetai/config/service/ConfigService.java
Normal file
132
src/main/java/com/newyetai/config/service/ConfigService.java
Normal file
@@ -0,0 +1,132 @@
|
||||
package com.newyetai.config.service;
|
||||
|
||||
import com.newyetai.config.dto.ConfigDTO;
|
||||
import com.newyetai.config.dto.ConfigOperatorDTO;
|
||||
import com.newyetai.config.dto.ConfigPageQueryDTO;
|
||||
import com.newyetai.config.dto.ConfigQueryDTO;
|
||||
import com.newyetai.config.entity.Config;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 配置
|
||||
*
|
||||
* @author sr on 2019-10-20
|
||||
*/
|
||||
public interface ConfigService {
|
||||
|
||||
|
||||
/**
|
||||
* 配置表 - 创建
|
||||
*
|
||||
* @param operatorDto 操作dto
|
||||
* @return {@link com.newyetai.config.dto.ConfigDTO}
|
||||
*/
|
||||
ConfigDTO create(@Valid ConfigOperatorDTO operatorDto);
|
||||
|
||||
/**
|
||||
* 配置表 - 修改
|
||||
*
|
||||
* @param operatorDto 操作dto
|
||||
* @return {@link com.newyetai.config.dto.ConfigDTO}
|
||||
*/
|
||||
ConfigDTO modify(@Valid ConfigOperatorDTO operatorDto);
|
||||
|
||||
/**
|
||||
* 配置表 - 删除
|
||||
*
|
||||
* @param id id
|
||||
* @return {@link com.newyetai.config.dto.ConfigDTO}
|
||||
*/
|
||||
ConfigDTO delete(Long id);
|
||||
|
||||
/**
|
||||
* 配置表 - 根据ID查询单个
|
||||
*
|
||||
* @param id id
|
||||
* @return {@link com.newyetai.config.dto.ConfigDTO}
|
||||
*/
|
||||
ConfigDTO findById(Long id);
|
||||
|
||||
/**
|
||||
* 配置表 - 列表查询
|
||||
*
|
||||
* @param queryDTO 列表查询dto
|
||||
* @return {@link List}<{@link com.newyetai.config.dto.ConfigDTO}>
|
||||
*/
|
||||
List<ConfigDTO> list(ConfigQueryDTO queryDTO);
|
||||
|
||||
/**
|
||||
* 配置表 - 分页查询
|
||||
*
|
||||
* @param queryDTO 分页查询dto
|
||||
* @return {@link com.newyetai.config.dto.ConfigDTO}
|
||||
*/
|
||||
List<ConfigDTO> page(ConfigPageQueryDTO queryDTO);
|
||||
|
||||
/**
|
||||
* 查询配置
|
||||
*
|
||||
* @param config
|
||||
* @return
|
||||
* @author sr on 2019-11-05
|
||||
*/
|
||||
List<Config> find(Config config);
|
||||
|
||||
/**
|
||||
* 根据code和机构id集合查询配置
|
||||
* @param code
|
||||
* @param orgIds
|
||||
* @return
|
||||
*/
|
||||
List<Config> findByCodeAndOrgIds(String code, Set<Long> orgIds);
|
||||
|
||||
/**
|
||||
* 获取配置值
|
||||
* @param code
|
||||
* @param orgId
|
||||
* @param enable
|
||||
* @return
|
||||
*/
|
||||
String getConfigValue(String code, Long orgId, boolean enable);
|
||||
|
||||
|
||||
/**
|
||||
* 根据code查询配置
|
||||
* @param orgId
|
||||
* @param configCode
|
||||
* @return
|
||||
* @author sr on 2019-10-23
|
||||
*/
|
||||
ConfigDTO queryConfigByCode(Long orgId, String configCode);
|
||||
|
||||
/**
|
||||
* 根据code查询配置
|
||||
* @param orgId
|
||||
* @param configCode
|
||||
* @return
|
||||
* @author sr on 2019-10-23
|
||||
*/
|
||||
ConfigDTO queryOrgConfigByCode(Long orgId, String configCode);
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
* @param code
|
||||
* @param orgId
|
||||
* @param enable
|
||||
* @return
|
||||
*/
|
||||
Config getConfig(String code, Long orgId, boolean enable);
|
||||
|
||||
/**
|
||||
* 获取配置的dto
|
||||
* @param code
|
||||
* @param orgId
|
||||
* @param enable
|
||||
* @return
|
||||
*/
|
||||
ConfigDTO getConfigDto(String code, Long orgId, boolean enable);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.newyetai.config.service.impl;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.newyetai.common.constant.CommonConstants;
|
||||
import com.newyetai.common.exception.util.ExceptionUtils;
|
||||
import com.newyetai.common.util.UserContextHolder;
|
||||
import com.newyetai.config.constant.ConfigConstants;
|
||||
import com.newyetai.config.convert.ConfigConvert;
|
||||
import com.newyetai.config.dao.ConfigMapper;
|
||||
import com.newyetai.config.dto.ConfigDTO;
|
||||
import com.newyetai.config.dto.ConfigOperatorDTO;
|
||||
import com.newyetai.config.dto.ConfigPageQueryDTO;
|
||||
import com.newyetai.config.dto.ConfigQueryDTO;
|
||||
import com.newyetai.config.entity.Config;
|
||||
import com.newyetai.config.service.ConfigService;
|
||||
|
||||
/**
|
||||
* 配置
|
||||
*
|
||||
* @author sr on 2019-10-20
|
||||
*/
|
||||
@Service
|
||||
public class ConfigServiceImpl implements ConfigService {
|
||||
|
||||
@Autowired
|
||||
private ConfigMapper configMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigDTO create(ConfigOperatorDTO operatorDto) {
|
||||
Config config = ConfigConvert.INSTANCE.convert(operatorDto);
|
||||
configMapper.saveEntity(config);
|
||||
|
||||
return ConfigConvert.INSTANCE.convert(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigDTO modify(ConfigOperatorDTO operatorDto) {
|
||||
ConfigDTO configDto = this.findById(operatorDto.getId());
|
||||
if (Objects.isNull(configDto)) {
|
||||
return null;
|
||||
}
|
||||
Config config = ConfigConvert.INSTANCE.convert(operatorDto);
|
||||
configMapper.updateEntity(config);
|
||||
return this.findById(operatorDto.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigDTO delete(Long id) {
|
||||
ConfigDTO configDto = this.findById(id);
|
||||
if (Objects.isNull(configDto)) {
|
||||
return null;
|
||||
}
|
||||
Config config = Config.builder().build();
|
||||
config.setId(id);
|
||||
configMapper.deleteEntity(config, UserContextHolder.getLoginUserId());
|
||||
return configDto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigDTO findById(Long id) {
|
||||
Config config = configMapper.getById(id);
|
||||
if (Objects.isNull(config)) {
|
||||
return null;
|
||||
}
|
||||
return ConfigConvert.INSTANCE.convert(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConfigDTO> list(ConfigQueryDTO queryDTO) {
|
||||
return configMapper.list(queryDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConfigDTO> page(ConfigPageQueryDTO queryDTO) {
|
||||
return configMapper.page(queryDTO);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Config> find(Config config) {
|
||||
return configMapper.find(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Config> findByCodeAndOrgIds(String code, Set<Long> orgIds) {
|
||||
return configMapper.listByCodeAndOrgIds(code, orgIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigValue(String code, Long orgId, boolean enable) {
|
||||
List<Config> configs = find(Config.builder().configCode(code).orgId(orgId).enable(enable).deleted(false).build());
|
||||
if(CollectionUtils.isEmpty(configs)) {
|
||||
return null;
|
||||
}
|
||||
return configs.get(0).getConfigValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验配置编码是否存在
|
||||
* @param
|
||||
* @param
|
||||
*/
|
||||
private void checkTemplateCode(Long orgId, String configCode, Long configId) {
|
||||
int num = configMapper.existConfigCode(orgId, configCode, configId);
|
||||
ExceptionUtils.throwBusinessException(num > 0, ConfigConstants.CONFIG_CODE_EXIST);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = RuntimeException.class)
|
||||
public ConfigDTO queryConfigByCode(Long orgId, String configCode) {
|
||||
return configMapper.queryConfigByCode(CommonConstants.PLATFORM_ORG_ID, orgId, configCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigDTO queryOrgConfigByCode(Long orgId, String configCode) {
|
||||
return configMapper.queryOrgConfigByCode(orgId, configCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Config getConfig(String code, Long orgId, boolean enable) {
|
||||
Config query = Config.builder().configCode(code).orgId(orgId).enable(enable).build();
|
||||
List<Config> configs = find(query);
|
||||
if(CollectionUtils.isEmpty(configs) && ObjectUtils.notEqual(CommonConstants.PLATFORM_ORG_ID, orgId)) {
|
||||
query.setOrgId(CommonConstants.PLATFORM_ORG_ID);
|
||||
configs = find(query);
|
||||
}
|
||||
if(CollectionUtils.isEmpty(configs)){
|
||||
return null;
|
||||
}
|
||||
return configs.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigDTO getConfigDto(String code, Long orgId, boolean enable) {
|
||||
Config config = getConfig(code, orgId, enable);
|
||||
if(config == null){
|
||||
return null;
|
||||
}
|
||||
ConfigDTO dto = new ConfigDTO();
|
||||
BeanUtils.copyProperties(config, dto);
|
||||
return dto;
|
||||
}
|
||||
|
||||
}
|
||||
40
src/main/java/com/newyetai/config/util/ConfigUtils.java
Normal file
40
src/main/java/com/newyetai/config/util/ConfigUtils.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package com.newyetai.config.util;
|
||||
|
||||
import com.newyetai.config.dto.ConfigDTO;
|
||||
import com.newyetai.config.entity.Config;
|
||||
|
||||
/**
|
||||
* 配置工具类
|
||||
*
|
||||
* @author sr on 2019-10-20
|
||||
*/
|
||||
public class ConfigUtils {
|
||||
|
||||
/**
|
||||
* dto转entity, 新增
|
||||
*
|
||||
* @param
|
||||
* @param orgId
|
||||
* @return
|
||||
*/
|
||||
public static Config toCreate(ConfigDTO configDTO, Long orgId) {
|
||||
Config config = Config.builder().configCode(configDTO.getConfigCode())
|
||||
.configValue(configDTO.getConfigValue()).remark(configDTO.getRemark())
|
||||
.enable(!Boolean.FALSE.equals(configDTO.getEnable())).orgId(orgId).build();
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* dto转entity,修改,有id;orgId不变(置空)
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public static Config toUpdate(ConfigDTO configDTO) {
|
||||
Config config = Config.builder().id(configDTO.getId()).configCode(configDTO.getConfigCode())
|
||||
.configValue(configDTO.getConfigValue()).remark(configDTO.getRemark())
|
||||
.enable(!Boolean.FALSE.equals(configDTO.getEnable())).build();
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user