新增公共的网站参数数据源
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.WebsiteFieldService;
|
||||
import com.gxwebsoft.common.system.entity.WebsiteField;
|
||||
import com.gxwebsoft.common.system.param.WebsiteFieldParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 应用参数控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-08-27 15:18:05
|
||||
*/
|
||||
@Api(tags = "应用参数管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/website-field")
|
||||
public class WebsiteFieldController extends BaseController {
|
||||
@Resource
|
||||
private WebsiteFieldService websiteFieldService;
|
||||
|
||||
@ApiOperation("分页查询应用参数")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<WebsiteField>> page(WebsiteFieldParam param) {
|
||||
PageParam<WebsiteField, WebsiteFieldParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(websiteFieldService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(websiteFieldService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部应用参数")
|
||||
@GetMapping()
|
||||
public ApiResult<List<WebsiteField>> list(WebsiteFieldParam param) {
|
||||
PageParam<WebsiteField, WebsiteFieldParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(websiteFieldService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(websiteFieldService.listRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("根据id查询应用参数")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<WebsiteField> get(@PathVariable("id") Integer id) {
|
||||
return success(websiteFieldService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(websiteFieldService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('system:websiteField:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加应用参数")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody WebsiteField websiteField) {
|
||||
if (websiteFieldService.save(websiteField)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('system:websiteField:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改应用参数")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody WebsiteField websiteField) {
|
||||
if (websiteFieldService.updateById(websiteField)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('system:websiteField:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除应用参数")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (websiteFieldService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('system:websiteField:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加应用参数")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<WebsiteField> list) {
|
||||
if (websiteFieldService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('system:websiteField:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改应用参数")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<WebsiteField> batchParam) {
|
||||
if (batchParam.update(websiteFieldService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('system:websiteField:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除应用参数")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (websiteFieldService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("获取网站配置参数-对象形式")
|
||||
@GetMapping("/config")
|
||||
public ApiResult<?> getConfig(WebsiteFieldParam param) {
|
||||
// 使用关联查询
|
||||
final List<WebsiteField> fields = websiteFieldService.listRel(param);
|
||||
|
||||
HashMap<String, Object> config = new HashMap<>();
|
||||
fields.forEach(d -> {
|
||||
config.put(d.getName(), d.getValue());
|
||||
});
|
||||
System.out.println("config = " + config);
|
||||
return success(config);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.gxwebsoft.common.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 应用参数
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-08-27 15:18:05
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value = "WebsiteField对象", description = "应用参数")
|
||||
@TableName("sys_website_field")
|
||||
public class WebsiteField implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "自增ID")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "类型,0文本 1图片 2其他")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "默认值")
|
||||
private String defaultValue;
|
||||
|
||||
@ApiModelProperty(value = "可修改的值 [on|off]")
|
||||
private String modifyRange;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String comments;
|
||||
|
||||
@ApiModelProperty(value = "名称")
|
||||
private String value;
|
||||
|
||||
@ApiModelProperty(value = "排序(数字越小越靠前)")
|
||||
private Integer sortNumber;
|
||||
|
||||
@ApiModelProperty(value = "是否删除, 0否, 1是")
|
||||
@TableLogic
|
||||
private Integer deleted;
|
||||
|
||||
@ApiModelProperty(value = "租户id")
|
||||
private Integer tenantId;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.gxwebsoft.common.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.gxwebsoft.common.system.entity.WebsiteField;
|
||||
import com.gxwebsoft.common.system.param.WebsiteFieldParam;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 应用参数Mapper
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-08-27 15:18:05
|
||||
*/
|
||||
public interface WebsiteFieldMapper extends BaseMapper<WebsiteField> {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param param 查询参数
|
||||
* @return List<WebsiteField>
|
||||
*/
|
||||
List<WebsiteField> selectPageRel(@Param("page") IPage<WebsiteField> page,
|
||||
@Param("param") WebsiteFieldParam param);
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return List<User>
|
||||
*/
|
||||
List<WebsiteField> selectListRel(@Param("param") WebsiteFieldParam param);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?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.gxwebsoft.common.system.mapper.WebsiteFieldMapper">
|
||||
|
||||
<!-- 关联查询sql -->
|
||||
<sql id="selectSql">
|
||||
SELECT a.*
|
||||
FROM sys_website_field a
|
||||
<where>
|
||||
<if test="param.id != null">
|
||||
AND a.id = #{param.id}
|
||||
</if>
|
||||
<if test="param.type != null">
|
||||
AND a.type = #{param.type}
|
||||
</if>
|
||||
<if test="param.name != null">
|
||||
AND a.name LIKE CONCAT('%', #{param.name}, '%')
|
||||
</if>
|
||||
<if test="param.defaultValue != null">
|
||||
AND a.default_value LIKE CONCAT('%', #{param.defaultValue}, '%')
|
||||
</if>
|
||||
<if test="param.modifyRange != null">
|
||||
AND a.modify_range LIKE CONCAT('%', #{param.modifyRange}, '%')
|
||||
</if>
|
||||
<if test="param.comments != null">
|
||||
AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
|
||||
</if>
|
||||
<if test="param.value != null">
|
||||
AND a.value LIKE CONCAT('%', #{param.value}, '%')
|
||||
</if>
|
||||
<if test="param.sortNumber != null">
|
||||
AND a.sort_number = #{param.sortNumber}
|
||||
</if>
|
||||
<if test="param.deleted != null">
|
||||
AND a.deleted = #{param.deleted}
|
||||
</if>
|
||||
<if test="param.deleted == null">
|
||||
AND a.deleted = 0
|
||||
</if>
|
||||
<if test="param.tenantId == null">
|
||||
AND a.tenant_id = #{param.tenantId}
|
||||
</if>
|
||||
<if test="param.createTimeStart != null">
|
||||
AND a.create_time >= #{param.createTimeStart}
|
||||
</if>
|
||||
<if test="param.createTimeEnd != null">
|
||||
AND a.create_time <= #{param.createTimeEnd}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询 -->
|
||||
<select id="selectPageRel" resultType="com.gxwebsoft.common.system.entity.WebsiteField">
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
<!-- 查询全部 -->
|
||||
<select id="selectListRel" resultType="com.gxwebsoft.common.system.entity.WebsiteField">
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.gxwebsoft.common.system.param;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.gxwebsoft.common.core.annotation.QueryField;
|
||||
import com.gxwebsoft.common.core.annotation.QueryType;
|
||||
import com.gxwebsoft.common.core.web.BaseParam;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 应用参数查询参数
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-08-27 15:18:05
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@ApiModel(value = "WebsiteFieldParam对象", description = "应用参数查询参数")
|
||||
public class WebsiteFieldParam extends BaseParam {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "自增ID")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "类型,0文本 1图片 2其他")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "默认值")
|
||||
private String defaultValue;
|
||||
|
||||
@ApiModelProperty(value = "可修改的值 [on|off]")
|
||||
private String modifyRange;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String comments;
|
||||
|
||||
@ApiModelProperty(value = "名称")
|
||||
private String value;
|
||||
|
||||
@ApiModelProperty(value = "排序(数字越小越靠前)")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer sortNumber;
|
||||
|
||||
@ApiModelProperty(value = "是否删除, 0否, 1是")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer deleted;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.gxwebsoft.common.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.WebsiteField;
|
||||
import com.gxwebsoft.common.system.param.WebsiteFieldParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 应用参数Service
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-08-27 15:18:05
|
||||
*/
|
||||
public interface WebsiteFieldService extends IService<WebsiteField> {
|
||||
|
||||
/**
|
||||
* 分页关联查询
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return PageResult<WebsiteField>
|
||||
*/
|
||||
PageResult<WebsiteField> pageRel(WebsiteFieldParam param);
|
||||
|
||||
/**
|
||||
* 关联查询全部
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return List<WebsiteField>
|
||||
*/
|
||||
List<WebsiteField> listRel(WebsiteFieldParam param);
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
*
|
||||
* @param id 自增ID
|
||||
* @return WebsiteField
|
||||
*/
|
||||
WebsiteField getByIdRel(Integer id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.gxwebsoft.common.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gxwebsoft.common.system.mapper.WebsiteFieldMapper;
|
||||
import com.gxwebsoft.common.system.service.WebsiteFieldService;
|
||||
import com.gxwebsoft.common.system.entity.WebsiteField;
|
||||
import com.gxwebsoft.common.system.param.WebsiteFieldParam;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 应用参数Service实现
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-08-27 15:18:05
|
||||
*/
|
||||
@Service
|
||||
public class WebsiteFieldServiceImpl extends ServiceImpl<WebsiteFieldMapper, WebsiteField> implements WebsiteFieldService {
|
||||
|
||||
@Override
|
||||
public PageResult<WebsiteField> pageRel(WebsiteFieldParam param) {
|
||||
PageParam<WebsiteField, WebsiteFieldParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number asc, create_time asc");
|
||||
List<WebsiteField> list = baseMapper.selectPageRel(page, param);
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WebsiteField> listRel(WebsiteFieldParam param) {
|
||||
List<WebsiteField> list = baseMapper.selectListRel(param);
|
||||
// 排序
|
||||
PageParam<WebsiteField, WebsiteFieldParam> page = new PageParam<>();
|
||||
page.setDefaultOrder("sort_number asc, create_time asc");
|
||||
return page.sortRecords(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebsiteField getByIdRel(Integer id) {
|
||||
WebsiteFieldParam param = new WebsiteFieldParam();
|
||||
param.setId(id);
|
||||
return param.getOne(baseMapper.selectListRel(param));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user