新增:域名授权模块
This commit is contained in:
@@ -69,6 +69,7 @@ public class MybatisPlusConfig {
|
||||
"sys_plug",
|
||||
"sys_version",
|
||||
"sys_order",
|
||||
"sys_domain",
|
||||
"sys_white_domain",
|
||||
"sys_website_field",
|
||||
"sys_modules",
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.DomainService;
|
||||
import com.gxwebsoft.common.system.entity.Domain;
|
||||
import com.gxwebsoft.common.system.param.DomainParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
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.List;
|
||||
|
||||
/**
|
||||
* 授权域名控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-08-30 16:15:58
|
||||
*/
|
||||
@Api(tags = "授权域名管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/domain")
|
||||
public class DomainController extends BaseController {
|
||||
@Resource
|
||||
private DomainService domainService;
|
||||
|
||||
@ApiOperation("根据域名查询授权")
|
||||
@GetMapping("/{domain}")
|
||||
public ApiResult<Domain> get(@PathVariable("domain") String domain) {
|
||||
final Domain one = domainService.getOne(new LambdaQueryWrapper<Domain>().eq(Domain::getDomain, domain).eq(Domain::getDeleted, 0));
|
||||
if (ObjectUtil.isEmpty(one)) {
|
||||
return fail("域名未授权.",null);
|
||||
}
|
||||
if (one.getStatus().equals(0)) {
|
||||
return fail("域名审核中.",null);
|
||||
}
|
||||
return success(one);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
@ApiOperation("分页查询授权域名")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Domain>> page(DomainParam param) {
|
||||
// 使用关联查询
|
||||
return success(domainService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
@ApiOperation("查询全部授权域名")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Domain>> list(DomainParam param) {
|
||||
// 使用关联查询
|
||||
return success(domainService.listRel(param));
|
||||
}
|
||||
|
||||
// @PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
// @ApiOperation("根据id查询授权域名")
|
||||
// @GetMapping("/{id}")
|
||||
// public ApiResult<Domain> get(@PathVariable("id") Integer id) {
|
||||
// // 使用关联查询
|
||||
// return success(domainService.getByIdRel(id));
|
||||
// }
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加授权域名")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Domain domain) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
domain.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (domainService.save(domain)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改授权域名")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Domain domain) {
|
||||
if (domainService.updateById(domain)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除授权域名")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (domainService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加授权域名")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Domain> list) {
|
||||
if (domainService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改授权域名")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Domain> batchParam) {
|
||||
if (batchParam.update(domainService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除授权域名")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (domainService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,21 +35,21 @@ public class WebsiteFieldController extends BaseController {
|
||||
@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()));
|
||||
// PageParam<WebsiteField, WebsiteFieldParam> page = new PageParam<>(param);
|
||||
// page.setDefaultOrder("create_time desc");
|
||||
// return success(websiteFieldService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(websiteFieldService.pageRel(param));
|
||||
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()));
|
||||
// PageParam<WebsiteField, WebsiteFieldParam> page = new PageParam<>(param);
|
||||
// page.setDefaultOrder("create_time desc");
|
||||
// return success(websiteFieldService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(websiteFieldService.listRel(param));
|
||||
return success(websiteFieldService.listRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("根据id查询应用参数")
|
||||
|
||||
69
src/main/java/com/gxwebsoft/common/system/entity/Domain.java
Normal file
69
src/main/java/com/gxwebsoft/common/system/entity/Domain.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package com.gxwebsoft.common.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
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-30 16:15:58
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value = "Domain对象", description = "授权域名")
|
||||
@TableName("sys_domain")
|
||||
public class Domain implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "ID")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "域名")
|
||||
private String domain;
|
||||
|
||||
@ApiModelProperty(value = "主机记录")
|
||||
private String hostName;
|
||||
|
||||
@ApiModelProperty(value = "记录值")
|
||||
private String hostValue;
|
||||
|
||||
@ApiModelProperty(value = "状态")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "排序号")
|
||||
private Integer sortNumber;
|
||||
|
||||
@ApiModelProperty(value = "用户ID")
|
||||
private Integer userId;
|
||||
|
||||
@ApiModelProperty(value = "是否删除, 0否, 1是")
|
||||
@TableLogic
|
||||
private Integer deleted;
|
||||
|
||||
@ApiModelProperty(value = "租户id")
|
||||
private Integer tenantId;
|
||||
|
||||
@ApiModelProperty(value = "租户名称")
|
||||
@TableField(exist = false)
|
||||
private String tenantName;
|
||||
|
||||
@ApiModelProperty("驳回原因")
|
||||
private String comments;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
}
|
||||
@@ -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.Domain;
|
||||
import com.gxwebsoft.common.system.param.DomainParam;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 授权域名Mapper
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-08-30 16:15:58
|
||||
*/
|
||||
public interface DomainMapper extends BaseMapper<Domain> {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param param 查询参数
|
||||
* @return List<Domain>
|
||||
*/
|
||||
List<Domain> selectPageRel(@Param("page") IPage<Domain> page,
|
||||
@Param("param") DomainParam param);
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return List<User>
|
||||
*/
|
||||
List<Domain> selectListRel(@Param("param") DomainParam param);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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.DomainMapper">
|
||||
|
||||
<!-- 关联查询sql -->
|
||||
<sql id="selectSql">
|
||||
SELECT a.*,b.tenant_name
|
||||
FROM sys_domain a
|
||||
LEFT JOIN sys_tenant b ON a.tenant_id = b.tenant_id
|
||||
<where>
|
||||
<if test="param.id != null">
|
||||
AND a.id = #{param.id}
|
||||
</if>
|
||||
<if test="param.domain != null">
|
||||
AND a.domain LIKE CONCAT('%', #{param.domain}, '%')
|
||||
</if>
|
||||
<if test="param.hostName != null">
|
||||
AND a.host_name LIKE CONCAT('%', #{param.hostName}, '%')
|
||||
</if>
|
||||
<if test="param.hostValue != null">
|
||||
AND a.host_value LIKE CONCAT('%', #{param.hostValue}, '%')
|
||||
</if>
|
||||
<if test="param.status != null">
|
||||
AND a.status = #{param.status}
|
||||
</if>
|
||||
<if test="param.sortNumber != null">
|
||||
AND a.sort_number = #{param.sortNumber}
|
||||
</if>
|
||||
<if test="param.userId != null">
|
||||
AND a.user_id = #{param.userId}
|
||||
</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.createTimeStart != null">
|
||||
AND a.create_time >= #{param.createTimeStart}
|
||||
</if>
|
||||
<if test="param.createTimeEnd != null">
|
||||
AND a.create_time <= #{param.createTimeEnd}
|
||||
</if>
|
||||
<if test="param.keywords != null">
|
||||
AND (
|
||||
a.domain LIKE CONCAT('%', #{param.keywords}, '%')
|
||||
OR a.user_id = #{param.keywords}
|
||||
)
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询 -->
|
||||
<select id="selectPageRel" resultType="com.gxwebsoft.common.system.entity.Domain">
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
<!-- 查询全部 -->
|
||||
<select id="selectListRel" resultType="com.gxwebsoft.common.system.entity.Domain">
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -45,7 +45,10 @@
|
||||
</if>
|
||||
<if test="param.keywords != null">
|
||||
AND (
|
||||
a.name = #{param.keywords}
|
||||
a.name LIKE CONCAT('%', #{param.keywords}, '%')
|
||||
OR a.comments LIKE CONCAT('%', #{param.keywords}, '%')
|
||||
OR a.value LIKE CONCAT('%', #{param.keywords}, '%')
|
||||
OR a.default_value LIKE CONCAT('%', #{param.keywords}, '%')
|
||||
OR a.comments = #{param.keywords}
|
||||
)
|
||||
</if>
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
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-30 16:15:57
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@ApiModel(value = "DomainParam对象", description = "授权域名查询参数")
|
||||
public class DomainParam extends BaseParam {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "ID")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "域名")
|
||||
private String domain;
|
||||
|
||||
@ApiModelProperty(value = "主机记录")
|
||||
private String hostName;
|
||||
|
||||
@ApiModelProperty(value = "记录值")
|
||||
private String hostValue;
|
||||
|
||||
@ApiModelProperty(value = "状态")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "排序号")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer sortNumber;
|
||||
|
||||
@ApiModelProperty(value = "用户ID")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer userId;
|
||||
|
||||
@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.Domain;
|
||||
import com.gxwebsoft.common.system.param.DomainParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 授权域名Service
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-08-30 16:15:58
|
||||
*/
|
||||
public interface DomainService extends IService<Domain> {
|
||||
|
||||
/**
|
||||
* 分页关联查询
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return PageResult<Domain>
|
||||
*/
|
||||
PageResult<Domain> pageRel(DomainParam param);
|
||||
|
||||
/**
|
||||
* 关联查询全部
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return List<Domain>
|
||||
*/
|
||||
List<Domain> listRel(DomainParam param);
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
*
|
||||
* @param id ID
|
||||
* @return Domain
|
||||
*/
|
||||
Domain 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.DomainMapper;
|
||||
import com.gxwebsoft.common.system.service.DomainService;
|
||||
import com.gxwebsoft.common.system.entity.Domain;
|
||||
import com.gxwebsoft.common.system.param.DomainParam;
|
||||
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-30 16:15:58
|
||||
*/
|
||||
@Service
|
||||
public class DomainServiceImpl extends ServiceImpl<DomainMapper, Domain> implements DomainService {
|
||||
|
||||
@Override
|
||||
public PageResult<Domain> pageRel(DomainParam param) {
|
||||
PageParam<Domain, DomainParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
List<Domain> list = baseMapper.selectPageRel(page, param);
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Domain> listRel(DomainParam param) {
|
||||
List<Domain> list = baseMapper.selectListRel(param);
|
||||
// 排序
|
||||
PageParam<Domain, DomainParam> page = new PageParam<>();
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return page.sortRecords(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Domain getByIdRel(Integer id) {
|
||||
DomainParam param = new DomainParam();
|
||||
param.setId(id);
|
||||
return param.getOne(baseMapper.selectListRel(param));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
package com.gxwebsoft.generator;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.InjectionConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 代码生成工具
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2021-09-05 00:31:14
|
||||
*/
|
||||
public class Sys2Generator {
|
||||
// 输出位置
|
||||
private static final String OUTPUT_LOCATION = System.getProperty("user.dir");
|
||||
//private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径
|
||||
// 输出目录
|
||||
private static final String OUTPUT_DIR = "/src/main/java";
|
||||
// Vue文件输出位置
|
||||
private static final String OUTPUT_LOCATION_VUE = "/Users/gxwebsoft/VUE/com.gxwebsoft.core-web";
|
||||
// Vue文件输出目录
|
||||
private static final String OUTPUT_DIR_VUE = "/src";
|
||||
// 作者名称
|
||||
private static final String AUTHOR = "科技小王子";
|
||||
// 是否在xml中添加二级缓存配置
|
||||
private static final boolean ENABLE_CACHE = false;
|
||||
// 数据库连接配置
|
||||
private static final String DB_URL = "jdbc:mysql://47.119.165.234:3308/gxwebsoft_core?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
|
||||
private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
|
||||
private static final String DB_USERNAME = "gxwebsoft_core";
|
||||
private static final String DB_PASSWORD = "jdj7HYEdYHnYEFBy";
|
||||
// 包名
|
||||
private static final String PACKAGE_NAME = "com.gxwebsoft";
|
||||
// 模块名
|
||||
private static final String MODULE_NAME = "common.system";
|
||||
// 需要生成的表
|
||||
private static final String[] TABLE_NAMES = new String[]{
|
||||
"sys_website_field"
|
||||
};
|
||||
// 需要去除的表前缀
|
||||
private static final String[] TABLE_PREFIX = new String[]{
|
||||
"sys_",
|
||||
"tb_"
|
||||
};
|
||||
// 不需要作为查询参数的字段
|
||||
private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{
|
||||
"tenant_id",
|
||||
"create_time",
|
||||
"update_time"
|
||||
};
|
||||
// 查询参数使用String的类型
|
||||
private static final String[] PARAM_TO_STRING_TYPE = new String[]{
|
||||
"Date",
|
||||
"LocalDate",
|
||||
"LocalTime",
|
||||
"LocalDateTime"
|
||||
};
|
||||
// 查询参数使用EQ的类型
|
||||
private static final String[] PARAM_EQ_TYPE = new String[]{
|
||||
"Integer",
|
||||
"Boolean",
|
||||
"BigDecimal"
|
||||
};
|
||||
// 是否添加权限注解
|
||||
private static final boolean AUTH_ANNOTATION = true;
|
||||
// 是否添加日志注解
|
||||
private static final boolean LOG_ANNOTATION = true;
|
||||
// controller的mapping前缀
|
||||
private static final String CONTROLLER_MAPPING_PREFIX = "/api";
|
||||
// 模板所在位置
|
||||
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates";
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR);
|
||||
gc.setAuthor(AUTHOR);
|
||||
gc.setOpen(false);
|
||||
gc.setFileOverride(true);
|
||||
gc.setEnableCache(ENABLE_CACHE);
|
||||
gc.setSwagger2(true);
|
||||
gc.setIdType(IdType.AUTO);
|
||||
gc.setServiceName("%sService");
|
||||
mpg.setGlobalConfig(gc);
|
||||
|
||||
// 数据源配置
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
dsc.setUrl(DB_URL);
|
||||
// dsc.setSchemaName("public");
|
||||
dsc.setDriverName(DB_DRIVER);
|
||||
dsc.setUsername(DB_USERNAME);
|
||||
dsc.setPassword(DB_PASSWORD);
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 包配置
|
||||
PackageConfig pc = new PackageConfig();
|
||||
pc.setModuleName(MODULE_NAME);
|
||||
pc.setParent(PACKAGE_NAME);
|
||||
mpg.setPackageInfo(pc);
|
||||
|
||||
// 策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setInclude(TABLE_NAMES);
|
||||
strategy.setTablePrefix(TABLE_PREFIX);
|
||||
strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController");
|
||||
strategy.setEntityLombokModel(true);
|
||||
strategy.setRestControllerStyle(true);
|
||||
strategy.setControllerMappingHyphenStyle(true);
|
||||
strategy.setLogicDeleteFieldName("deleted");
|
||||
mpg.setStrategy(strategy);
|
||||
|
||||
// 模板配置
|
||||
TemplateConfig templateConfig = new TemplateConfig();
|
||||
templateConfig.setController(TEMPLATES_DIR + "/controller.java");
|
||||
templateConfig.setEntity(TEMPLATES_DIR + "/entity.java");
|
||||
templateConfig.setMapper(TEMPLATES_DIR + "/mapper.java");
|
||||
templateConfig.setXml(TEMPLATES_DIR + "/mapper.xml");
|
||||
templateConfig.setService(TEMPLATES_DIR + "/service.java");
|
||||
templateConfig.setServiceImpl(TEMPLATES_DIR + "/serviceImpl.java");
|
||||
mpg.setTemplate(templateConfig);
|
||||
mpg.setTemplateEngine(new BeetlTemplateEnginePlus());
|
||||
|
||||
// 自定义模板配置
|
||||
InjectionConfig cfg = new InjectionConfig() {
|
||||
@Override
|
||||
public void initMap() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("packageName", PACKAGE_NAME);
|
||||
map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS);
|
||||
map.put("paramToStringType", PARAM_TO_STRING_TYPE);
|
||||
map.put("paramEqType", PARAM_EQ_TYPE);
|
||||
map.put("authAnnotation", AUTH_ANNOTATION);
|
||||
map.put("logAnnotation", LOG_ANNOTATION);
|
||||
map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX);
|
||||
this.setMap(map);
|
||||
}
|
||||
};
|
||||
String templatePath = TEMPLATES_DIR + "/param.java.btl";
|
||||
List<FileOutConfig> focList = new ArrayList<>();
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION + OUTPUT_DIR + "/"
|
||||
+ PACKAGE_NAME.replace(".", "/")
|
||||
+ "/" + pc.getModuleName() + "/param/"
|
||||
+ tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA;
|
||||
}
|
||||
});
|
||||
/**
|
||||
* 以下是生成VUE项目代码
|
||||
* 生成文件的路径 /api/shop/goods/index.ts
|
||||
*/
|
||||
templatePath = TEMPLATES_DIR + "/index.ts.btl";
|
||||
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/api/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/" + "index.ts";
|
||||
}
|
||||
});
|
||||
// 生成TS文件 (/api/shop/goods/model/index.ts)
|
||||
templatePath = TEMPLATES_DIR + "/model.ts.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/api/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/model/" + "index.ts";
|
||||
}
|
||||
});
|
||||
// 生成Vue文件(/views/shop/goods/index.vue)
|
||||
templatePath = TEMPLATES_DIR + "/index.vue.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/views/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/" + "index.vue";
|
||||
}
|
||||
});
|
||||
|
||||
// 生成components文件(/views/shop/goods/components/edit.vue)
|
||||
templatePath = TEMPLATES_DIR + "/components.edit.vue.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/views/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/components/" + tableInfo.getEntityPath() + "Edit.vue";
|
||||
}
|
||||
});
|
||||
|
||||
// 生成components文件(/views/shop/goods/components/search.vue)
|
||||
templatePath = TEMPLATES_DIR + "/components.search.vue.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/views/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/components/" + "search.vue";
|
||||
}
|
||||
});
|
||||
|
||||
cfg.setFileOutConfigList(focList);
|
||||
mpg.setCfg(cfg);
|
||||
|
||||
mpg.execute();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,6 +26,12 @@ public class SysGenerator {
|
||||
//private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径
|
||||
// 输出目录
|
||||
private static final String OUTPUT_DIR = "/src/main/java";
|
||||
// Vue文件输出位置
|
||||
private static final String OUTPUT_LOCATION_VUE = "/Users/gxwebsoft/VUE/gxtyzx-admin-vue";
|
||||
// Vue文件输出目录
|
||||
private static final String OUTPUT_LOCATION_UNIAPP = "/Users/gxwebsoft/VUE/nbg";
|
||||
// Vue文件输出目录
|
||||
private static final String OUTPUT_DIR_VUE = "/src";
|
||||
// 作者名称
|
||||
private static final String AUTHOR = "科技小王子";
|
||||
// 是否在xml中添加二级缓存配置
|
||||
@@ -41,39 +47,8 @@ public class SysGenerator {
|
||||
private static final String MODULE_NAME = "common.system";
|
||||
// 需要生成的表
|
||||
private static final String[] TABLE_NAMES = new String[]{
|
||||
|
||||
// "sys_user",
|
||||
// "sys_tenant",
|
||||
// "sys_setting"
|
||||
// "sys_access_key"
|
||||
// "sys_company",
|
||||
// "sys_industry"
|
||||
// "sys_plug",
|
||||
// "sys_company"
|
||||
// "sys_user_oauth",
|
||||
// "sys_user_grade"
|
||||
// "sys_user_referee"
|
||||
// "sys_notice"
|
||||
// "sys_plug"
|
||||
// "sys_plug_record",
|
||||
// "sys_modules"
|
||||
// "sys_chat_message",
|
||||
// "sys_chat_conversation"
|
||||
// "sys_user_group"
|
||||
// "sys_app",
|
||||
// "sys_app_user",
|
||||
// "sys_app_url",
|
||||
// "sys_app_renew"
|
||||
// "sys_version",
|
||||
// "sys_website",
|
||||
// "sys_website_field",
|
||||
// "sys_white_domain"
|
||||
// "sys_order",
|
||||
// "sys_order_info",
|
||||
// "sys_user_collection",
|
||||
// "sys_user",
|
||||
// "sys_payment"
|
||||
// "sys_components"
|
||||
// "sys_website_field"
|
||||
"sys_domain"
|
||||
};
|
||||
// 需要去除的表前缀
|
||||
private static final String[] TABLE_PREFIX = new String[]{
|
||||
@@ -189,6 +164,79 @@ public class SysGenerator {
|
||||
+ tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA;
|
||||
}
|
||||
});
|
||||
/**
|
||||
* 以下是生成VUE项目代码
|
||||
* 生成文件的路径 /api/shop/goods/index.ts
|
||||
*/
|
||||
templatePath = TEMPLATES_DIR + "/index.ts.btl";
|
||||
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/api/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/" + "index.ts";
|
||||
}
|
||||
});
|
||||
focList.add(new FileOutConfig() {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_UNIAPP + OUTPUT_DIR_VUE
|
||||
+ "/api/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/" + "index.ts";
|
||||
}
|
||||
});
|
||||
// 生成TS文件 (/api/shop/goods/model/index.ts)
|
||||
templatePath = TEMPLATES_DIR + "/model.ts.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/api/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/model/" + "index.ts";
|
||||
}
|
||||
});
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_UNIAPP + OUTPUT_DIR_VUE
|
||||
+ "/api/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/model/" + "index.ts";
|
||||
}
|
||||
});
|
||||
// 生成Vue文件(/views/shop/goods/index.vue)
|
||||
templatePath = TEMPLATES_DIR + "/index.vue.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/views/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/" + "index.vue";
|
||||
}
|
||||
});
|
||||
|
||||
// 生成components文件(/views/shop/goods/components/edit.vue)
|
||||
templatePath = TEMPLATES_DIR + "/components.edit.vue.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/views/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/components/" + tableInfo.getEntityPath() + "Edit.vue";
|
||||
}
|
||||
});
|
||||
|
||||
// 生成components文件(/views/shop/goods/components/search.vue)
|
||||
templatePath = TEMPLATES_DIR + "/components.search.vue.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/views/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/components/" + "search.vue";
|
||||
}
|
||||
});
|
||||
|
||||
cfg.setFileOutConfigList(focList);
|
||||
mpg.setCfg(cfg);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user