@@ -20,7 +20,6 @@ | |||
<!-- 子模块依赖 --> | |||
<modules> | |||
<module>tuoheng-common</module> | |||
<module>tuoheng-generator</module> | |||
<module>tuoheng-system</module> | |||
<module>tuoheng-admin</module> | |||
</modules> | |||
@@ -51,11 +50,6 @@ | |||
<artifactId>tuoheng-common</artifactId> | |||
<version>${version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.tuoheng</groupId> | |||
<artifactId>tuoheng-generator</artifactId> | |||
<version>${version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.tuoheng</groupId> | |||
<artifactId>tuoheng-system</artifactId> |
@@ -29,11 +29,6 @@ | |||
<groupId>com.tuoheng</groupId> | |||
<artifactId>tuoheng-system</artifactId> | |||
</dependency> | |||
<!-- 代码生成 --> | |||
<dependency> | |||
<groupId>com.tuoheng</groupId> | |||
<artifactId>tuoheng-generator</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.projectlombok</groupId> | |||
<artifactId>lombok</artifactId> |
@@ -0,0 +1,10 @@ | |||
-- 修改部门表开始 | |||
ALTER TABLE sys_dept_copy DROP code; | |||
ALTER TABLE sys_dept_copy DROP fullname; | |||
ALTER TABLE sys_dept_copy DROP type; | |||
ALTER TABLE sys_dept_copy DROP sort; | |||
ALTER TABLE sys_dept_copy DROP note; | |||
ALTER TABLE sys_dept_copy ADD COLUMN airport_id int COMMENT '机场ID' AFTER pid; | |||
-- 修改部门表结束 | |||
@@ -17,6 +17,12 @@ | |||
<!-- 依赖声明 --> | |||
<dependencies> | |||
<!-- MySql驱动 --> | |||
<dependency> | |||
<groupId>mysql</groupId> | |||
<artifactId>mysql-connector-java</artifactId> | |||
<scope>runtime</scope> | |||
</dependency> | |||
<!--mybatis-plus 起始依赖 --> | |||
<dependency> | |||
<groupId>com.baomidou</groupId> |
@@ -1,54 +0,0 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<project xmlns="http://maven.apache.org/POM/4.0.0" | |||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
<!-- 子模块的parent要使用顶层的父模块--> | |||
<parent> | |||
<artifactId>tuoheng_airport_platform</artifactId> | |||
<groupId>com.tuoheng</groupId> | |||
<version>0.0.1-SNAPSHOT</version> | |||
</parent> | |||
<modelVersion>4.0.0</modelVersion> | |||
<artifactId>tuoheng-generator</artifactId> | |||
<packaging>jar</packaging> | |||
<name>tuoheng-generator</name> | |||
<description>Demo project for Spring Boot</description> | |||
<!-- 依赖声明 --> | |||
<dependencies> | |||
<!-- 基础依赖 --> | |||
<dependency> | |||
<groupId>com.tuoheng</groupId> | |||
<artifactId>tuoheng-common</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.tuoheng</groupId> | |||
<artifactId>tuoheng-system</artifactId> | |||
</dependency> | |||
<!-- MySql驱动 --> | |||
<dependency> | |||
<groupId>mysql</groupId> | |||
<artifactId>mysql-connector-java</artifactId> | |||
<scope>runtime</scope> | |||
</dependency> | |||
<!--mybatis-plus 代码自动生成 --> | |||
<dependency> | |||
<groupId>com.baomidou</groupId> | |||
<artifactId>mybatis-plus-generator</artifactId> | |||
<version>3.2.0</version> | |||
</dependency> | |||
<!-- freemarker模板引擎依赖 --> | |||
<dependency> | |||
<groupId>org.freemarker</groupId> | |||
<artifactId>freemarker</artifactId> | |||
<version>2.3.28</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.projectlombok</groupId> | |||
<artifactId>lombok</artifactId> | |||
<optional>true</optional> | |||
</dependency> | |||
</dependencies> | |||
</project> |
@@ -1,78 +0,0 @@ | |||
package com.tuoheng.generator.config; | |||
import org.springframework.boot.context.properties.ConfigurationProperties; | |||
import org.springframework.stereotype.Component; | |||
/** | |||
* 代码生成器相关配置 | |||
*/ | |||
@Component | |||
@ConfigurationProperties(prefix = "generate") | |||
public class GenConfig { | |||
/** | |||
* 作者 | |||
*/ | |||
public static String author; | |||
/** | |||
* 生成包路径 | |||
*/ | |||
public static String packageName; | |||
/** | |||
* 模块名 | |||
*/ | |||
public static String moduleName; | |||
/** | |||
* 自动去除表前缀,默认是true | |||
*/ | |||
public static boolean autoRemovePre; | |||
/** | |||
* 表前缀(类名不会包含表前缀) | |||
*/ | |||
public static String tablePrefix; | |||
public static String getAuthor() { | |||
return author; | |||
} | |||
public void setAuthor(String author) { | |||
GenConfig.author = author; | |||
} | |||
public static String getPackageName() { | |||
return packageName; | |||
} | |||
public void setPackageName(String packageName) { | |||
GenConfig.packageName = packageName; | |||
} | |||
public static String getModuleName() { | |||
return moduleName; | |||
} | |||
public void setModuleName(String moduleName) { | |||
GenConfig.moduleName = moduleName; | |||
} | |||
public static boolean getAutoRemovePre() { | |||
return autoRemovePre; | |||
} | |||
public void setAutoRemovePre(boolean autoRemovePre) { | |||
GenConfig.autoRemovePre = autoRemovePre; | |||
} | |||
public static String getTablePrefix() { | |||
return tablePrefix; | |||
} | |||
public void setTablePrefix(String tablePrefix) { | |||
GenConfig.tablePrefix = tablePrefix; | |||
} | |||
} |
@@ -1,147 +0,0 @@ | |||
package com.tuoheng.generator.constant; | |||
/** | |||
* 代码生成通用常量 | |||
*/ | |||
public class GenConstants { | |||
/** | |||
* 单表(增删改查) | |||
*/ | |||
public static final String TPL_CRUD = "crud"; | |||
/** | |||
* 树表(增删改查) | |||
*/ | |||
public static final String TPL_TREE = "tree"; | |||
/** | |||
* 树编码字段 | |||
*/ | |||
public static final String TREE_CODE = "treeCode"; | |||
/** | |||
* 树父编码字段 | |||
*/ | |||
public static final String TREE_PARENT_CODE = "treeParentCode"; | |||
/** | |||
* 树名称字段 | |||
*/ | |||
public static final String TREE_NAME = "treeName"; | |||
/** | |||
* 数据库字符串类型 | |||
*/ | |||
public static final String[] COLUMNTYPE_STR = {"char", "varchar", "narchar", "varchar2", "tinytext", "text", | |||
"mediumtext", "longtext"}; | |||
/** | |||
* 数据库时间类型 | |||
*/ | |||
public static final String[] COLUMNTYPE_TIME = {"datetime", "time", "date", "timestamp"}; | |||
/** | |||
* 数据库数字类型 | |||
*/ | |||
public static final String[] COLUMNTYPE_NUMBER = {"tinyint", "smallint", "mediumint", "int", "number", "integer", | |||
"bigint", "float", "float", "double", "decimal"}; | |||
/** | |||
* 页面不需要编辑字段 | |||
*/ | |||
public static final String[] COLUMNNAME_NOT_EDIT = {"id", "create_by", "create_time", "del_flag"}; | |||
/** | |||
* 页面不需要显示的列表字段 | |||
*/ | |||
public static final String[] COLUMNNAME_NOT_LIST = {"id", "create_by", "create_time", "del_flag", "update_by", | |||
"update_time"}; | |||
/** | |||
* 页面不需要查询字段 | |||
*/ | |||
public static final String[] COLUMNNAME_NOT_QUERY = {"id", "create_by", "create_time", "del_flag", "update_by", | |||
"update_time", "remark"}; | |||
/** | |||
* Entity基类字段 | |||
*/ | |||
public static final String[] BASE_ENTITY = {"createBy", "createTime", "updateBy", "updateTime", "remark"}; | |||
/** | |||
* Tree基类字段 | |||
*/ | |||
public static final String[] TREE_ENTITY = {"parentName", "parentId", "orderNum", "ancestors", "children"}; | |||
/** | |||
* 文本框 | |||
*/ | |||
public static final String HTML_INPUT = "input"; | |||
/** | |||
* 文本域 | |||
*/ | |||
public static final String HTML_TEXTAREA = "textarea"; | |||
/** | |||
* 下拉框 | |||
*/ | |||
public static final String HTML_SELECT = "select"; | |||
/** | |||
* 单选框 | |||
*/ | |||
public static final String HTML_RADIO = "radio"; | |||
/** | |||
* 复选框 | |||
*/ | |||
public static final String HTML_CHECKBOX = "checkbox"; | |||
/** | |||
* 日期控件 | |||
*/ | |||
public static final String HTML_DATETIME = "datetime"; | |||
/** | |||
* 字符串类型 | |||
*/ | |||
public static final String TYPE_STRING = "String"; | |||
/** | |||
* 整型 | |||
*/ | |||
public static final String TYPE_INTEGER = "Integer"; | |||
/** | |||
* 长整型 | |||
*/ | |||
public static final String TYPE_LONG = "Long"; | |||
/** | |||
* 浮点型 | |||
*/ | |||
public static final String TYPE_DOUBLE = "Double"; | |||
/** | |||
* 高精度计算类型 | |||
*/ | |||
public static final String TYPE_BIGDECIMAL = "BigDecimal"; | |||
/** | |||
* 时间类型 | |||
*/ | |||
public static final String TYPE_DATE = "Date"; | |||
/** | |||
* 模糊查询 | |||
*/ | |||
public static final String QUERY_LIKE = "LIKE"; | |||
/** | |||
* 需要 | |||
*/ | |||
public static final String REQUIRE = "1"; | |||
} |
@@ -1,20 +0,0 @@ | |||
package com.tuoheng.generator.controller; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
/** | |||
* <p> | |||
* 代码生成业务表字段 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
@RestController | |||
@RequestMapping("/gentablecolumn") | |||
public class GenTableColumnController { | |||
} |
@@ -1,128 +0,0 @@ | |||
package com.tuoheng.generator.controller; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.tuoheng.common.config.CommonConfig; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.generator.dto.GenTableDto; | |||
import com.tuoheng.generator.entity.GenTable; | |||
import com.tuoheng.generator.entity.GenTableColumn; | |||
import com.tuoheng.generator.query.GenTableQuery; | |||
import com.tuoheng.generator.service.IGenTableColumnService; | |||
import com.tuoheng.generator.service.IGenTableService; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.validation.annotation.Validated; | |||
import org.springframework.web.bind.annotation.*; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* <p> | |||
* 代码生成业务表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
@RestController | |||
@RequestMapping("/gentable") | |||
public class GenTableController { | |||
@Autowired | |||
private IGenTableService genTableService; | |||
@Autowired | |||
private IGenTableColumnService genTableColumnService; | |||
/** | |||
* 获取业务表列表 | |||
* | |||
* @param genTableQuery 查询条件 | |||
* @return | |||
*/ | |||
@GetMapping("/index") | |||
public JsonResult index(GenTableQuery genTableQuery) { | |||
return genTableService.getList(genTableQuery); | |||
} | |||
/** | |||
* 获取数据库表 | |||
* | |||
* @param query 查询条件 | |||
* @return | |||
*/ | |||
@GetMapping("/genDbTableList") | |||
public JsonResult genDbTableList(GenTableQuery query) { | |||
IPage<GenTable> pageData = genTableService.genDbTableList(query); | |||
return JsonResult.success(pageData, "操作成功"); | |||
} | |||
/** | |||
* 导入表 | |||
* | |||
* @param tableNames 数据表 | |||
* @return | |||
*/ | |||
@PostMapping("/importTable") | |||
public JsonResult importTable(@RequestBody String[] tableNames) { | |||
// 查询表信息 | |||
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames); | |||
genTableService.importGenTable(tableList); | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 获取表详情信息 | |||
* | |||
* @param tableId 表ID | |||
* @return | |||
*/ | |||
@GetMapping("/getTableInfo/{tableId}") | |||
public JsonResult getTableInfo(@PathVariable("tableId") String tableId) { | |||
GenTable table = genTableService.selectGenTableById(Integer.valueOf(tableId)); | |||
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(Integer.valueOf(tableId)); | |||
Map<String, Object> map = new HashMap<String, Object>(); | |||
map.put("info", table); | |||
map.put("records", list); | |||
return JsonResult.success(map, "操作成功"); | |||
} | |||
/** | |||
* 更新代码生成表信息 | |||
* | |||
* @param genTable 生成表 | |||
* @return | |||
*/ | |||
@PutMapping("/updateGenTable") | |||
public JsonResult updateGenTable(@Validated @RequestBody GenTable genTable) { | |||
genTableService.validateEdit(genTable); | |||
genTableService.updateGenTable(genTable); | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 删除业务表 | |||
* | |||
* @param tableIds 业务表ID | |||
* @return | |||
*/ | |||
@DeleteMapping("/delete/{tableIds}") | |||
public JsonResult delete(@PathVariable("tableIds") Integer[] tableIds) { | |||
return genTableService.delete(tableIds); | |||
} | |||
/** | |||
* 生成代码 | |||
* | |||
* @param genTableDto 一键生成参数 | |||
* @throws Exception | |||
*/ | |||
@PostMapping("/batchGenCode") | |||
public JsonResult batchGenCode(@RequestBody GenTableDto genTableDto) { | |||
String[] tableNames = genTableDto.getTableNames().split(","); | |||
return genTableService.generatorCode(tableNames); | |||
} | |||
} |
@@ -1,16 +0,0 @@ | |||
package com.tuoheng.generator.dto; | |||
import lombok.Data; | |||
/** | |||
* 一键生成Dto | |||
*/ | |||
@Data | |||
public class GenTableDto { | |||
/** | |||
* 业务表名称(多个使用逗号“,”分隔) | |||
*/ | |||
private String tableNames; | |||
} |
@@ -1,153 +0,0 @@ | |||
package com.tuoheng.generator.entity; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
import java.util.List; | |||
import com.baomidou.mybatisplus.annotation.IdType; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import lombok.Data; | |||
import lombok.experimental.Accessors; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import javax.validation.Valid; | |||
/** | |||
* <p> | |||
* 代码生成业务表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
@Data | |||
@Accessors(chain = true) | |||
public class GenTable implements Serializable { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 表ID | |||
*/ | |||
@TableId(value = "id", type = IdType.AUTO) | |||
private Integer id; | |||
/** | |||
* 表名称 | |||
*/ | |||
private String tableName; | |||
/** | |||
* 表描述 | |||
*/ | |||
private String tableComment; | |||
/** | |||
* 实体类名称 | |||
*/ | |||
private String className; | |||
/** | |||
* 使用的模板(crud单表操作 tree树表操作) | |||
*/ | |||
private String tplCategory; | |||
/** | |||
* 生成包路径 | |||
*/ | |||
private String packageName; | |||
/** | |||
* 生成模块名 | |||
*/ | |||
private String moduleName; | |||
/** | |||
* 生成业务名 | |||
*/ | |||
private String businessName; | |||
/** | |||
* 生成功能名 | |||
*/ | |||
private String functionName; | |||
/** | |||
* 生成功能作者 | |||
*/ | |||
private String functionAuthor; | |||
/** | |||
* 其它生成选项 | |||
*/ | |||
private String options; | |||
/** | |||
* 备注 | |||
*/ | |||
private String note; | |||
/** | |||
* 添加人 | |||
*/ | |||
private Integer createUser; | |||
/** | |||
* 创建时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date createTime; | |||
/** | |||
* 更新人 | |||
*/ | |||
private Integer updateUser; | |||
/** | |||
* 更新时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date updateTime; | |||
/** | |||
* 有效标识 | |||
*/ | |||
private Integer mark; | |||
/** | |||
* 主键信息 | |||
*/ | |||
@TableField(exist = false) | |||
private GenTableColumn pkColumn; | |||
/** | |||
* 表列信息 | |||
*/ | |||
@Valid | |||
@TableField(exist = false) | |||
private List<GenTableColumn> columns; | |||
/** | |||
* 树编码字段 | |||
*/ | |||
@TableField(exist = false) | |||
private String treeCode; | |||
/** | |||
* 树父编码字段 | |||
*/ | |||
@TableField(exist = false) | |||
private String treeParentCode; | |||
/** | |||
* 树名称字段 | |||
*/ | |||
@TableField(exist = false) | |||
private String treeName; | |||
} |
@@ -1,148 +0,0 @@ | |||
package com.tuoheng.generator.entity; | |||
import com.baomidou.mybatisplus.annotation.IdType; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
import lombok.Data; | |||
import lombok.experimental.Accessors; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
/** | |||
* <p> | |||
* 代码生成业务表字段 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
@Data | |||
public class GenTableColumn implements Serializable { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 表ID | |||
*/ | |||
@TableId(value = "id", type = IdType.AUTO) | |||
private Integer id; | |||
/** | |||
* 归属表编号 | |||
*/ | |||
private Integer tableId; | |||
/** | |||
* 列名称 | |||
*/ | |||
private String columnName; | |||
/** | |||
* 列描述 | |||
*/ | |||
private String columnComment; | |||
/** | |||
* 列类型 | |||
*/ | |||
private String columnType; | |||
/** | |||
* JAVA类型 | |||
*/ | |||
private String javaType; | |||
/** | |||
* JAVA字段名 | |||
*/ | |||
private String javaField; | |||
/** | |||
* 是否主键(1是) | |||
*/ | |||
private Integer isPk; | |||
/** | |||
* 是否自增(1是) | |||
*/ | |||
private String isIncrement; | |||
/** | |||
* 是否必填(1是) | |||
*/ | |||
private String isRequired; | |||
/** | |||
* 是否为插入字段(1是) | |||
*/ | |||
private String isInsert; | |||
/** | |||
* 是否编辑字段(1是) | |||
*/ | |||
private String isEdit; | |||
/** | |||
* 是否列表字段(1是) | |||
*/ | |||
private String isList; | |||
/** | |||
* 是否查询字段(1是) | |||
*/ | |||
private String isQuery; | |||
/** | |||
* 查询方式(等于、不等于、大于、小于、范围) | |||
*/ | |||
private String queryType; | |||
/** | |||
* 显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件) | |||
*/ | |||
private String htmlType; | |||
/** | |||
* 字典类型 | |||
*/ | |||
private String dictType; | |||
/** | |||
* 排序 | |||
*/ | |||
private Integer sort; | |||
/** | |||
* 添加人 | |||
*/ | |||
private Integer createUser; | |||
/** | |||
* 创建时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date createTime; | |||
/** | |||
* 更新人 | |||
*/ | |||
private Integer updateUser; | |||
/** | |||
* 更新时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date updateTime; | |||
/** | |||
* 有效标识 | |||
*/ | |||
private Integer mark; | |||
} |
@@ -1,50 +0,0 @@ | |||
package com.tuoheng.generator.mapper; | |||
import com.tuoheng.generator.entity.GenTableColumn; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import java.util.List; | |||
/** | |||
* <p> | |||
* 代码生成业务表字段 Mapper 接口 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
public interface GenTableColumnMapper extends BaseMapper<GenTableColumn> { | |||
/** | |||
* 根据表名查询列信息 | |||
* | |||
* @param tableName 数据表名 | |||
* @return | |||
*/ | |||
List<GenTableColumn> selectDbTableColumnsByName(String tableName); | |||
/** | |||
* 插入数据表列 | |||
* | |||
* @param TableColumn 数据表列 | |||
* @return | |||
*/ | |||
int insertGenTableColumn(GenTableColumn TableColumn); | |||
/** | |||
* 获取表字段列表 | |||
* | |||
* @param tableId 表ID | |||
* @return | |||
*/ | |||
List<GenTableColumn> selectGenTableColumnListByTableId(Integer tableId); | |||
/** | |||
* 修改业务表字段 | |||
* | |||
* @param TableColumn 表字段 | |||
* @return | |||
*/ | |||
int updateGenTableColumn(GenTableColumn TableColumn); | |||
} |
@@ -1,80 +0,0 @@ | |||
package com.tuoheng.generator.mapper; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.tuoheng.generator.entity.GenTable; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import com.tuoheng.generator.query.GenTableQuery; | |||
import org.springframework.web.bind.annotation.RequestParam; | |||
import java.util.List; | |||
/** | |||
* <p> | |||
* 代码生成业务表 Mapper 接口 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
public interface GenTableMapper extends BaseMapper<GenTable> { | |||
/** | |||
* 获取业务表列表 | |||
* | |||
* @param page 分页信息 | |||
* @param param 参数 | |||
* @return | |||
*/ | |||
IPage<GenTable> selectGenTableList(IPage<GenTable> page, @RequestParam("param") GenTableQuery param); | |||
/** | |||
* 获取数据库表 | |||
* | |||
* @param page 分页信息 | |||
* @param param 查询条件 | |||
* @return | |||
*/ | |||
IPage<GenTable> selectDbTableList(IPage<GenTable> page, @RequestParam("param") GenTableQuery param); | |||
/** | |||
* 根据表明获取数据库列表 | |||
* | |||
* @param tableNames 数据库名 | |||
* @return | |||
*/ | |||
List<GenTable> selectDbTableListByNames(String[] tableNames); | |||
/** | |||
* 插入数据表 | |||
* | |||
* @param genTable 待生成数据表 | |||
* @return | |||
*/ | |||
int insertGenTable(GenTable genTable); | |||
/** | |||
* 根据表ID获取表信息 | |||
* | |||
* @param tableId 表ID | |||
* @return | |||
*/ | |||
GenTable selectGenTableById(Integer tableId); | |||
/** | |||
* 修改业务表信息 | |||
* | |||
* @param genTable 业务表 | |||
* @return | |||
*/ | |||
int updateGenTable(GenTable genTable); | |||
/** | |||
* 根据表名查询业务表 | |||
* | |||
* @param tableName 表名 | |||
* @return | |||
*/ | |||
GenTable selectGenTableByName(String tableName); | |||
} |
@@ -1,31 +0,0 @@ | |||
package com.tuoheng.generator.query; | |||
import lombok.Data; | |||
/** | |||
* 表生成查询条件 | |||
*/ | |||
@Data | |||
public class GenTableQuery { | |||
/** | |||
* 页码 | |||
*/ | |||
private Integer page; | |||
/** | |||
* 每页数 | |||
*/ | |||
private Integer limit; | |||
/** | |||
* 表名 | |||
*/ | |||
private String tableName; | |||
/** | |||
* 表描述 | |||
*/ | |||
private String tableComment; | |||
} |
@@ -1,26 +0,0 @@ | |||
package com.tuoheng.generator.service; | |||
import com.tuoheng.generator.entity.GenTableColumn; | |||
import com.baomidou.mybatisplus.extension.service.IService; | |||
import java.util.List; | |||
/** | |||
* <p> | |||
* 代码生成业务表字段 服务类 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
public interface IGenTableColumnService extends IService<GenTableColumn> { | |||
/** | |||
* 查询表字段信息 | |||
* | |||
* @param tableId 表ID | |||
* @return | |||
*/ | |||
List<GenTableColumn> selectGenTableColumnListByTableId(Integer tableId); | |||
} |
@@ -1,90 +0,0 @@ | |||
package com.tuoheng.generator.service; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.generator.entity.GenTable; | |||
import com.baomidou.mybatisplus.extension.service.IService; | |||
import com.tuoheng.generator.query.GenTableQuery; | |||
import java.util.List; | |||
/** | |||
* <p> | |||
* 代码生成业务表 服务类 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
public interface IGenTableService extends IService<GenTable> { | |||
/** | |||
* 根据查询条件获取数据列表 | |||
* | |||
* @param genTableQuery 查询条件 | |||
* @return | |||
*/ | |||
JsonResult getList(GenTableQuery genTableQuery); | |||
/** | |||
* 获取数据库表 | |||
* | |||
* @param query 查询条件 | |||
* @return | |||
*/ | |||
IPage<GenTable> genDbTableList(GenTableQuery query); | |||
/** | |||
* 查询据库列表 | |||
* | |||
* @param tableNames 表数组 | |||
* @return | |||
*/ | |||
List<GenTable> selectDbTableListByNames(String[] tableNames); | |||
/** | |||
* 导入表结构 | |||
* | |||
* @param tableList 导入表列表 | |||
*/ | |||
void importGenTable(List<GenTable> tableList); | |||
/** | |||
* 根据表ID获取表信息 | |||
* | |||
* @param tableId 表ID | |||
* @return | |||
*/ | |||
GenTable selectGenTableById(Integer tableId); | |||
/** | |||
* 业务表保存参数校验 | |||
* | |||
* @param Table 生成表 | |||
*/ | |||
void validateEdit(GenTable Table); | |||
/** | |||
* 更新业务表信息 | |||
* | |||
* @param Table 业务表 | |||
*/ | |||
void updateGenTable(GenTable Table); | |||
/** | |||
* 生成代码 | |||
* | |||
* @param tableNames 数据表 | |||
* @return | |||
*/ | |||
JsonResult generatorCode(String[] tableNames); | |||
/** | |||
* 删除记录 | |||
* | |||
* @param ids 业务表ID | |||
* @return | |||
*/ | |||
JsonResult delete(Integer[] ids); | |||
} |
@@ -1,37 +0,0 @@ | |||
package com.tuoheng.generator.service.impl; | |||
import com.tuoheng.generator.entity.GenTableColumn; | |||
import com.tuoheng.generator.mapper.GenTableColumnMapper; | |||
import com.tuoheng.generator.service.IGenTableColumnService; | |||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.List; | |||
/** | |||
* <p> | |||
* 代码生成业务表字段 服务实现类 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
@Service | |||
public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper, GenTableColumn> implements IGenTableColumnService { | |||
@Autowired | |||
private GenTableColumnMapper genTableColumnMapper; | |||
/** | |||
* 获取表字段信息 | |||
* | |||
* @param tableId 表ID | |||
* @return | |||
*/ | |||
@Override | |||
public List<GenTableColumn> selectGenTableColumnListByTableId(Integer tableId) { | |||
return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); | |||
} | |||
} |
@@ -1,227 +0,0 @@ | |||
package com.tuoheng.generator.service.impl; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.tuoheng.common.exception.CustomException; | |||
import com.tuoheng.common.utils.DateUtils; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.common.utils.StringUtils; | |||
import com.tuoheng.generator.constant.GenConstants; | |||
import com.tuoheng.generator.entity.GenTable; | |||
import com.tuoheng.generator.entity.GenTableColumn; | |||
import com.tuoheng.generator.mapper.GenTableColumnMapper; | |||
import com.tuoheng.generator.mapper.GenTableMapper; | |||
import com.tuoheng.generator.query.GenTableQuery; | |||
import com.tuoheng.generator.service.IGenTableService; | |||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
import com.tuoheng.generator.utils.CodeGenerateUtils; | |||
import com.tuoheng.generator.utils.GenUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Transactional; | |||
import java.util.List; | |||
/** | |||
* <p> | |||
* 代码生成业务表 服务实现类 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
@Service | |||
public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> implements IGenTableService { | |||
@Autowired | |||
private GenTableMapper genTableMapper; | |||
@Autowired | |||
private GenTableColumnMapper genTableColumnMapper; | |||
@Autowired | |||
private CodeGenerateUtils codeGenerateUtils; | |||
/** | |||
* 获取业务表列表 | |||
* | |||
* @param genTableQuery 查询条件 | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult getList(GenTableQuery genTableQuery) { | |||
IPage<GenTable> page = new Page<>(genTableQuery.getPage(), genTableQuery.getLimit()); | |||
IPage<GenTable> pageData = genTableMapper.selectGenTableList(page, genTableQuery); | |||
return JsonResult.success(pageData, "操作成功"); | |||
} | |||
/** | |||
* 获取数据库表 | |||
* | |||
* @param query 查询条件 | |||
* @return | |||
*/ | |||
@Override | |||
public IPage<GenTable> genDbTableList(GenTableQuery query) { | |||
IPage<GenTable> page = new Page<>(query.getPage(), query.getLimit()); | |||
return genTableMapper.selectDbTableList(page, query); | |||
} | |||
/** | |||
* 查询据库列表 | |||
* | |||
* @param tableNames 表数组 | |||
* @return | |||
*/ | |||
@Override | |||
public List<GenTable> selectDbTableListByNames(String[] tableNames) { | |||
return genTableMapper.selectDbTableListByNames(tableNames); | |||
} | |||
/** | |||
* 导入表结构 | |||
* | |||
* @param tableList 导入表列表 | |||
*/ | |||
@Transactional | |||
@Override | |||
public void importGenTable(List<GenTable> tableList) { | |||
String operName = "内部人员";//SecurityUtils.getUsername(); | |||
for (GenTable table : tableList) { | |||
try { | |||
String tableName = table.getTableName(); | |||
GenUtils.initTable(table, operName); | |||
int row = genTableMapper.insertGenTable(table); | |||
if (row > 0) { | |||
// 保存列信息 | |||
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); | |||
for (GenTableColumn column : genTableColumns) { | |||
GenUtils.initColumnField(column, table); | |||
genTableColumnMapper.insertGenTableColumn(column); | |||
} | |||
} | |||
} catch (Exception e) { | |||
log.error("表名 " + table.getTableName() + " 导入失败:", e); | |||
} | |||
} | |||
} | |||
/** | |||
* 根据表ID获取表信息 | |||
* | |||
* @param tableId 表ID | |||
* @return | |||
*/ | |||
@Override | |||
public GenTable selectGenTableById(Integer tableId) { | |||
GenTable genTable = genTableMapper.selectGenTableById(tableId); | |||
setTableFromOptions(genTable); | |||
return genTable; | |||
} | |||
/** | |||
* 设置代码生成其他选项 | |||
* | |||
* @param genTable 待生成表 | |||
*/ | |||
public void setTableFromOptions(GenTable genTable) { | |||
JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions()); | |||
if (StringUtils.isNotNull(paramsObj)) { | |||
String treeCode = paramsObj.getString(GenConstants.TREE_CODE); | |||
String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE); | |||
String treeName = paramsObj.getString(GenConstants.TREE_NAME); | |||
genTable.setTreeCode(treeCode); | |||
genTable.setTreeParentCode(treeParentCode); | |||
genTable.setTreeName(treeName); | |||
} | |||
} | |||
/** | |||
* 验证编辑信息 | |||
* | |||
* @param genTable 生成表 | |||
*/ | |||
@Override | |||
public void validateEdit(GenTable genTable) { | |||
if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { | |||
String options = "{}";//JSON.toJSONString(genTable.getParams()); | |||
JSONObject paramsObj = JSONObject.parseObject(options); | |||
if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) { | |||
throw new CustomException("树编码字段不能为空"); | |||
} else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) { | |||
throw new CustomException("树父编码字段不能为空"); | |||
} else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) { | |||
throw new CustomException("树名称字段不能为空"); | |||
} | |||
} | |||
} | |||
/** | |||
* 编辑业务表生成信息 | |||
* | |||
* @param genTable 业务表 | |||
*/ | |||
@Override | |||
public void updateGenTable(GenTable genTable) { | |||
String options = "{}";//JSON.toJSONString(genTable.getParams()); | |||
genTable.setOptions(options); | |||
int row = genTableMapper.updateGenTable(genTable); | |||
if (row > 0) { | |||
for (GenTableColumn cenTableColumn : genTable.getColumns()) { | |||
genTableColumnMapper.updateGenTableColumn(cenTableColumn); | |||
} | |||
} | |||
} | |||
/** | |||
* 生成数据表 | |||
* | |||
* @param tableNames 数据表 | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult generatorCode(String[] tableNames) { | |||
Integer totalNum = 0; | |||
for (String tableName : tableNames) { | |||
// 查询表信息 | |||
GenTable tableInfo = genTableMapper.selectGenTableByName(tableName); | |||
try { | |||
// 生成文件 | |||
codeGenerateUtils.generateFile(tableInfo.getTableName(), tableInfo.getTableComment()); | |||
totalNum++; | |||
} catch (Exception e) { | |||
} | |||
} | |||
return JsonResult.success(String.format("本地共生成【%s】个模块", totalNum)); | |||
} | |||
/** | |||
* 删除业务表 | |||
* | |||
* @param ids 业务表ID | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult delete(Integer[] ids) { | |||
Integer totalNum = 0; | |||
for (Integer id : ids) { | |||
GenTable entity = genTableMapper.selectById(id); | |||
if (entity == null) { | |||
return JsonResult.error("业务表不存在"); | |||
} | |||
entity.setUpdateUser(0); | |||
entity.setUpdateTime(DateUtils.now()); | |||
entity.setMark(0); | |||
boolean result = updateById(entity); | |||
if (result) { | |||
totalNum++; | |||
} | |||
} | |||
if (totalNum != ids.length) { | |||
return JsonResult.error("删除失败"); | |||
} | |||
return JsonResult.success("删除成功"); | |||
} | |||
} |
@@ -1,916 +0,0 @@ | |||
package com.tuoheng.generator.utils; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.common.utils.CommonUtils; | |||
import com.tuoheng.common.utils.DateUtils; | |||
import com.tuoheng.common.utils.StringUtils; | |||
import com.tuoheng.system.entity.Menu; | |||
import com.tuoheng.system.mapper.MenuMapper; | |||
import com.tuoheng.system.utils.ShiroUtils; | |||
import freemarker.template.Template; | |||
import lombok.Data; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Value; | |||
import org.springframework.stereotype.Component; | |||
import java.io.*; | |||
import java.sql.Connection; | |||
import java.sql.DatabaseMetaData; | |||
import java.sql.DriverManager; | |||
import java.sql.ResultSet; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.regex.Pattern; | |||
@Component | |||
@Data | |||
public class CodeGenerateUtils { | |||
@Autowired | |||
private MenuMapper menuMapper; | |||
/** | |||
* 作者 | |||
*/ | |||
@Value("${generate.author}") | |||
private String author = ""; | |||
/** | |||
* 创建时间 | |||
*/ | |||
private String createTime = DateUtils.getDate(); | |||
/** | |||
* 数据表名 | |||
*/ | |||
private String tableName = ""; | |||
/** | |||
* 数据表前缀 | |||
*/ | |||
@Value("${generate.tablePrefix}") | |||
private String tablePredix = ""; | |||
/** | |||
* 表描述 | |||
*/ | |||
private String tableAnnotation = ""; | |||
/** | |||
* 包名 | |||
*/ | |||
@Value("${generate.packageName}") | |||
private String packageName = ""; | |||
/** | |||
* 模块名 | |||
*/ | |||
@Value("${generate.moduleName}") | |||
private String moduleName = ""; | |||
/** | |||
* 自动去除表前缀 | |||
*/ | |||
@Value("${generate.autoRemovePre}") | |||
private boolean autoRemovePre = false; | |||
/** | |||
* 数据库连接池 | |||
*/ | |||
@Value("${spring.datasource.url}") | |||
private String url = ""; | |||
/** | |||
* 数据库用户名 | |||
*/ | |||
@Value("${spring.datasource.username}") | |||
private String username = ""; | |||
/** | |||
* 数据库密码 | |||
*/ | |||
@Value("${spring.datasource.password}") | |||
private String password = ""; | |||
/** | |||
* 数据库驱动 | |||
*/ | |||
private String driver = "com.mysql.cj.jdbc.Driver"; | |||
/** | |||
* 项目根目录 | |||
*/ | |||
String projectPath = System.getProperty("user.dir"); | |||
private String targetPath = ""; | |||
/** | |||
* 实体对象名 | |||
*/ | |||
private String entityName = ""; | |||
/** | |||
* 连接数据库 | |||
* | |||
* @return | |||
* @throws Exception | |||
*/ | |||
public Connection getConnection() throws Exception { | |||
Class.forName(driver); | |||
Connection connection = DriverManager.getConnection(url, username, password); | |||
return connection; | |||
} | |||
// /** | |||
// * 程序主入口 | |||
// * | |||
// * @param args | |||
// * @throws Exception | |||
// */ | |||
// public static void main(String[] args) throws Exception { | |||
// CodeGenerateUtils codeGenerateUtils = new CodeGenerateUtils(); | |||
// codeGenerateUtils.generateFile("sys_demo", "演示"); | |||
// } | |||
/** | |||
* 根据模板创建文件 | |||
* | |||
* @throws Exception | |||
*/ | |||
public void generateFile(String tableName, String tableAnnotation) throws Exception { | |||
try { | |||
// 数据表名 | |||
this.tableName = tableName; | |||
// 数据表描述 | |||
this.tableAnnotation = tableAnnotation; | |||
// 实体对象名 | |||
if (this.autoRemovePre) { | |||
this.entityName = replaceUnderLineAndUpperCase(tableName.replace(this.tablePredix, "")); | |||
} else { | |||
this.entityName = replaceUnderLineAndUpperCase(tableName); | |||
} | |||
// 目标文件路径 | |||
String[] packageArr = packageName.split("\\."); | |||
targetPath = projectPath + "/" + moduleName + "/src/main/java/" + StringUtils.join(packageArr, "/"); | |||
// 获取数据表信息 | |||
Connection connection = getConnection(); | |||
DatabaseMetaData databaseMetaData = connection.getMetaData(); | |||
ResultSet resultSet = databaseMetaData.getColumns(null, "%", tableName, "%"); | |||
// 获取数据表列信息 | |||
Map<String, Object> dataMap = getColumnsList(resultSet); | |||
/** | |||
* 生成实体Entity文件 | |||
*/ | |||
generateEntityFile(dataMap); | |||
/** | |||
* 生成Mapper文件 | |||
*/ | |||
generateMapperFile(); | |||
/** | |||
* 生成Dao文件 | |||
*/ | |||
generateDaoFile(); | |||
/** | |||
* 生成查询条件文件 | |||
*/ | |||
generateQueryFile(dataMap); | |||
/** | |||
* 生成服务类接口文件 | |||
*/ | |||
generateIServiceFile(dataMap); | |||
/** | |||
* 生成服务类接口实现文件 | |||
*/ | |||
generateServiceImplFile(dataMap); | |||
/** | |||
* 生成实体列表Vo | |||
*/ | |||
generateEntityListVoFile(dataMap); | |||
/** | |||
* 生成实体表单Vo | |||
*/ | |||
generateEntityInfoVoFile(dataMap); | |||
/** | |||
* 生成模块常亮 | |||
*/ | |||
generateConstantFile(dataMap); | |||
/** | |||
* 生成控制器 | |||
*/ | |||
generateControllerFile(dataMap); | |||
/** | |||
* 生成Vue文件 | |||
*/ | |||
generateVueFile(dataMap); | |||
/** | |||
* 生成菜单权限 | |||
*/ | |||
generatePermission(entityName); | |||
} catch (Exception e) { | |||
throw new RuntimeException(e); | |||
} finally { | |||
} | |||
} | |||
/** | |||
* 生成实体对象Entity.java文件 | |||
* | |||
* @param dataMap 参数 | |||
* @throws Exception | |||
*/ | |||
private void generateEntityFile(Map<String, Object> dataMap) throws Exception { | |||
// 文件路径 | |||
String path = targetPath + "/entity/"; | |||
// 初始化文件路径 | |||
initFileDir(path); | |||
// 文件后缀 | |||
String suffix = ".java"; | |||
// 完整的文件路径 | |||
String filePath = path + entityName + suffix; | |||
// 模板文件 | |||
String templateName = "Entity.ftl"; | |||
File entityFile = new File(filePath); | |||
generateFileByTemplate(templateName, entityFile, dataMap); | |||
} | |||
/** | |||
* 生成Mapper.xml文件 | |||
* | |||
* @throws Exception | |||
*/ | |||
private void generateMapperFile() throws Exception { | |||
// 文件路径 | |||
String path = projectPath + "/" + moduleName + "/src/main/resources/mapper/"; | |||
// 初始化文件路径 | |||
initFileDir(path); | |||
// 文件后缀 | |||
String suffix = "Mapper.xml"; | |||
// 完整的文件路径 | |||
String filePath = path + entityName + suffix; | |||
// 模板文件 | |||
String templateName = "Mapper.ftl"; | |||
File mapperFile = new File(filePath); | |||
Map<String, Object> dataMap = new HashMap<>(); | |||
generateFileByTemplate(templateName, mapperFile, dataMap); | |||
} | |||
/** | |||
* 生成Dao.java文件 | |||
* | |||
* @throws Exception | |||
*/ | |||
private void generateDaoFile() throws Exception { | |||
// 文件路径 | |||
String path = targetPath + "/mapper/"; | |||
// 初始化文件路径 | |||
initFileDir(path); | |||
// 文件后缀 | |||
String suffix = "Mapper.java"; | |||
// 完整的文件路径 | |||
String filePath = path + entityName + suffix; | |||
// 模板文件 | |||
String templateName = "Dao.ftl"; | |||
File daoFile = new File(filePath); | |||
Map<String, Object> dataMap = new HashMap<>(); | |||
generateFileByTemplate(templateName, daoFile, dataMap); | |||
} | |||
/** | |||
* 生成Query.java查询文件 | |||
* | |||
* @param dataMap 参数 | |||
* @throws Exception | |||
*/ | |||
private void generateQueryFile(Map<String, Object> dataMap) throws Exception { | |||
// 文件路径 | |||
String path = targetPath + "/query/"; | |||
// 初始化文件路径 | |||
initFileDir(path); | |||
// 文件后缀 | |||
String suffix = "Query.java"; | |||
// 完整的文件路径 | |||
String filePath = path + entityName + suffix; | |||
// 模板文件 | |||
String templateName = "Query.ftl"; | |||
File queryFile = new File(filePath); | |||
generateFileByTemplate(templateName, queryFile, dataMap); | |||
} | |||
/** | |||
* 生成服务接口文件 | |||
* | |||
* @throws Exception | |||
*/ | |||
private void generateIServiceFile(Map<String, Object> dataMap) throws Exception { | |||
// 文件路径 | |||
String path = targetPath + "/service/"; | |||
// 初始化文件路径 | |||
initFileDir(path); | |||
// 文件前缀 | |||
String prefix = "I"; | |||
// 文件后缀 | |||
String suffix = "Service.java"; | |||
// 完整的文件路径 | |||
String filePath = path + prefix + entityName + suffix; | |||
// 模板文件 | |||
String templateName = "IService.ftl"; | |||
File serviceFile = new File(filePath); | |||
generateFileByTemplate(templateName, serviceFile, dataMap); | |||
} | |||
/** | |||
* 生成服务类实现文件 | |||
* | |||
* @throws Exception | |||
*/ | |||
private void generateServiceImplFile(Map<String, Object> dataMap) throws Exception { | |||
// 文件路径 | |||
String path = targetPath + "/service/impl/"; | |||
// 初始化文件路径 | |||
initFileDir(path); | |||
// 文件后缀 | |||
String suffix = "ServiceImpl.java"; | |||
// 完整的文件路径 | |||
String filePath = path + entityName + suffix; | |||
// 模板文件 | |||
String templateName = "ServiceImpl.ftl"; | |||
File serviceImplFile = new File(filePath); | |||
generateFileByTemplate(templateName, serviceImplFile, dataMap); | |||
} | |||
/** | |||
* 生成列表ListVo文件 | |||
* | |||
* @param dataMap 参数 | |||
* @throws Exception | |||
*/ | |||
private void generateEntityListVoFile(Map<String, Object> dataMap) throws Exception { | |||
// 文件路径 | |||
String path = targetPath + "/vo/" + entityName.toLowerCase() + "/"; | |||
// 初始化文件路径 | |||
initFileDir(path); | |||
// 文件后缀 | |||
String suffix = ".java"; | |||
// 完整的文件路径 | |||
String filePath = path + entityName + "ListVo" + suffix; | |||
// 模板文件 | |||
String templateName = "EntityListVo.ftl"; | |||
File listVoFile = new File(filePath); | |||
generateFileByTemplate(templateName, listVoFile, dataMap); | |||
} | |||
/** | |||
* 生成表单InfoVo文件 | |||
* | |||
* @param dataMap 参数 | |||
* @throws Exception | |||
*/ | |||
private void generateEntityInfoVoFile(Map<String, Object> dataMap) throws Exception { | |||
// 文件路径 | |||
String path = targetPath + "/vo/" + entityName.toLowerCase() + "/"; | |||
// 初始化文件路径 | |||
initFileDir(path); | |||
// 文件后缀 | |||
String suffix = ".java"; | |||
// 完整的文件路径 | |||
String filePath = path + entityName + "InfoVo" + suffix; | |||
// 模板文件 | |||
String templateName = "EntityInfoVo.ftl"; | |||
File infoVoFile = new File(filePath); | |||
generateFileByTemplate(templateName, infoVoFile, dataMap); | |||
} | |||
/** | |||
* 生成模块常量 | |||
* | |||
* @param dataMap 参数 | |||
* @throws Exception | |||
*/ | |||
private void generateConstantFile(Map<String, Object> dataMap) throws Exception { | |||
// 文件路径 | |||
String path = targetPath + "/constant/"; | |||
// 初始化文件路径 | |||
initFileDir(path); | |||
// 文件后缀 | |||
String suffix = "Constant.java"; | |||
// 完整的文件路径 | |||
String filePath = path + entityName + suffix; | |||
// 模板文件 | |||
String templateName = "Constant.ftl"; | |||
File controllerFile = new File(filePath); | |||
generateFileByTemplate(templateName, controllerFile, dataMap); | |||
} | |||
/** | |||
* 生成控制器文件 | |||
* | |||
* @throws Exception | |||
*/ | |||
private void generateControllerFile(Map<String, Object> dataMap) throws Exception { | |||
// 文件路径 | |||
String path = targetPath + "/controller/"; | |||
// 初始化文件路径 | |||
initFileDir(path); | |||
// 文件后缀 | |||
String suffix = "Controller.java"; | |||
// 完整的文件路径 | |||
String filePath = path + entityName + suffix; | |||
// 模板文件 | |||
String templateName = "Controller.ftl"; | |||
File controllerFile = new File(filePath); | |||
generateFileByTemplate(templateName, controllerFile, dataMap); | |||
} | |||
/** | |||
* 生成Vue文件 | |||
* | |||
* @param dataMap 列数据源 | |||
* @throws Exception | |||
*/ | |||
private void generateVueFile(Map<String, Object> dataMap) throws Exception { | |||
// 文件路径 | |||
String path = projectPath + "/tuoheng-ui/src/views/system/" + entityName.toLowerCase() + "/"; | |||
// 初始化文件路径 | |||
initFileDir(path); | |||
// 文件后缀 | |||
String suffix = "index.vue"; | |||
// 完整的文件路径 | |||
String filePath = path + suffix; | |||
// 模板文件 | |||
String templateName = "Index.vue.ftl"; | |||
File entityFile = new File(filePath); | |||
List<ColumnClass> columnClasses = (List<ColumnClass>) dataMap.get("model_column"); | |||
List<ColumnClass> arrayList = new ArrayList<>(); | |||
List<ColumnClass> tempList = new ArrayList<>(); | |||
List<ColumnClass> rowList = new ArrayList<>(); | |||
for (ColumnClass columnClass : columnClasses) { | |||
if (columnClass.getChangeColumnName().equals("CreateUser")) { | |||
continue; | |||
} | |||
if (columnClass.getChangeColumnName().equals("CreateTime")) { | |||
continue; | |||
} | |||
if (columnClass.getChangeColumnName().equals("UpdateUser")) { | |||
continue; | |||
} | |||
if (columnClass.getChangeColumnName().equals("UpdateTime")) { | |||
continue; | |||
} | |||
if (columnClass.getChangeColumnName().equals("Mark")) { | |||
continue; | |||
} | |||
// 图片 | |||
if (columnClass.getColumnName().contains("cover") | |||
|| columnClass.getColumnName().contains("avatar") | |||
|| columnClass.getColumnName().contains("image") | |||
|| columnClass.getColumnName().contains("logo") | |||
|| columnClass.getColumnName().contains("pic")) { | |||
tempList.add(columnClass); | |||
continue; | |||
} | |||
// 单行显示常用字段处理 | |||
if (columnClass.getColumnName().contains("note") | |||
|| columnClass.getColumnName().contains("remark") | |||
|| columnClass.getColumnName().contains("content") | |||
|| columnClass.getColumnName().contains("description") | |||
|| columnClass.getColumnName().contains("intro")) { | |||
rowList.add(columnClass); | |||
continue; | |||
} | |||
arrayList.add(columnClass); | |||
} | |||
if (arrayList.size() + rowList.size() + tempList.size() > 20) { | |||
List<List<ColumnClass>> columnClassesList = CommonUtils.split(arrayList, 2); | |||
if (tempList.size() > 0) { | |||
columnClassesList.add(0, tempList); | |||
} | |||
if (rowList.size() > 0) { | |||
List<List<ColumnClass>> arrayColumnList = CommonUtils.split(rowList, 1); | |||
arrayColumnList.forEach(item -> { | |||
columnClassesList.add(item); | |||
}); | |||
} | |||
dataMap.put("model_column", columnClassesList); | |||
dataMap.put("is_split", true); | |||
} else { | |||
dataMap.put("is_split", false); | |||
} | |||
generateFileByTemplate(templateName, entityFile, dataMap); | |||
} | |||
/** | |||
* 生成权限节点 | |||
* | |||
* @param entityName 实体名称 | |||
*/ | |||
private void generatePermission(String entityName) { | |||
// 查询菜单是否存在 | |||
Menu entity = menuMapper.selectOne(new LambdaQueryWrapper<Menu>() | |||
.eq(Menu::getPath, String.format("/system/%s", entityName.toLowerCase())) | |||
.eq(Menu::getMark, 1) | |||
.last("limit 1")); | |||
Integer result = 0; | |||
if (entity != null) { | |||
// 更新 | |||
entity.setTitle(tableAnnotation); | |||
entity.setPath(String.format("/system/%s", entityName.toLowerCase())); | |||
entity.setComponent(String.format("/system/%s", entityName.toLowerCase())); | |||
entity.setPermission(String.format("sys:%s:view", entityName.toLowerCase())); | |||
entity.setUpdateUser(ShiroUtils.getUserId()); | |||
entity.setUpdateTime(DateUtils.now()); | |||
result = menuMapper.updateById(entity); | |||
} else { | |||
// 创建 | |||
entity = new Menu(); | |||
entity.setTitle(tableAnnotation); | |||
entity.setIcon("el-icon-_setting"); | |||
entity.setPath(String.format("/system/%s", entityName.toLowerCase())); | |||
entity.setComponent(String.format("/system/%s", entityName.toLowerCase())); | |||
entity.setPermission(String.format("sys:%s:view", entityName.toLowerCase())); | |||
entity.setPid(158); // 系统工具菜单ID | |||
entity.setType(0); | |||
entity.setStatus(1); | |||
entity.setSort(5); | |||
entity.setTarget("_self"); | |||
entity.setCreateUser(ShiroUtils.getUserId()); | |||
entity.setCreateTime(DateUtils.now()); | |||
result = menuMapper.insert(entity); | |||
} | |||
if (result == 1) { | |||
// 创建或更新权限节点 | |||
String[] strings = entity.getPath().split("/"); | |||
// 模块名称 | |||
String moduleName = strings[strings.length - 1]; | |||
// 目标标题 | |||
String moduleTitle = entity.getTitle().replace("管理", ""); | |||
// 遍历权限节点 | |||
Integer[] permissionList = new Integer[]{1, 5, 10, 15, 25}; | |||
for (Integer item : permissionList) { | |||
Menu funcInfo = new Menu(); | |||
funcInfo.setPid(entity.getId()); | |||
funcInfo.setType(1); | |||
funcInfo.setStatus(1); | |||
funcInfo.setSort(item); | |||
funcInfo.setTarget(entity.getTarget()); | |||
if (item.equals(1)) { | |||
// 查看 | |||
Menu menuInfo = menuMapper.selectOne(new LambdaQueryWrapper<Menu>() | |||
.eq(Menu::getPid, entity.getId()) | |||
.eq(Menu::getType, 1) | |||
.eq(Menu::getSort, item) | |||
.eq(Menu::getMark, 1) | |||
.last("limit 1")); | |||
if (menuInfo != null) { | |||
funcInfo.setId(menuInfo.getId()); | |||
funcInfo.setUpdateUser(ShiroUtils.getUserId()); | |||
funcInfo.setUpdateTime(DateUtils.now()); | |||
} | |||
funcInfo.setTitle(String.format("查询%s", moduleTitle)); | |||
funcInfo.setPermission(String.format("sys:%s:index", moduleName)); | |||
} else if (item.equals(5)) { | |||
// 添加 | |||
Menu menuInfo = menuMapper.selectOne(new LambdaQueryWrapper<Menu>() | |||
.eq(Menu::getPid, entity.getId()) | |||
.eq(Menu::getType, 1) | |||
.eq(Menu::getSort, item) | |||
.eq(Menu::getMark, 1) | |||
.last("limit 1")); | |||
if (menuInfo != null) { | |||
funcInfo.setId(menuInfo.getId()); | |||
funcInfo.setUpdateUser(ShiroUtils.getUserId()); | |||
funcInfo.setUpdateTime(DateUtils.now()); | |||
} | |||
funcInfo.setTitle(String.format("添加%s", moduleTitle)); | |||
funcInfo.setPermission(String.format("sys:%s:add", moduleName)); | |||
} else if (item.equals(10)) { | |||
// 修改 | |||
Menu menuInfo = menuMapper.selectOne(new LambdaQueryWrapper<Menu>() | |||
.eq(Menu::getPid, entity.getId()) | |||
.eq(Menu::getType, 1) | |||
.eq(Menu::getSort, item) | |||
.eq(Menu::getMark, 1) | |||
.last("limit 1")); | |||
if (menuInfo != null) { | |||
funcInfo.setId(menuInfo.getId()); | |||
funcInfo.setUpdateUser(ShiroUtils.getUserId()); | |||
funcInfo.setUpdateTime(DateUtils.now()); | |||
} | |||
funcInfo.setTitle(String.format("修改%s", moduleTitle)); | |||
funcInfo.setPermission(String.format("sys:%s:edit", moduleName)); | |||
} else if (item.equals(15)) { | |||
// 删除 | |||
Menu menuInfo = menuMapper.selectOne(new LambdaQueryWrapper<Menu>() | |||
.eq(Menu::getPid, entity.getId()) | |||
.eq(Menu::getType, 1) | |||
.eq(Menu::getSort, item) | |||
.eq(Menu::getMark, 1) | |||
.last("limit 1")); | |||
if (menuInfo != null) { | |||
funcInfo.setId(menuInfo.getId()); | |||
funcInfo.setUpdateUser(ShiroUtils.getUserId()); | |||
funcInfo.setUpdateTime(DateUtils.now()); | |||
} | |||
funcInfo.setTitle(String.format("删除%s", moduleTitle)); | |||
funcInfo.setPermission(String.format("sys:%s:delete", moduleName)); | |||
} else if (item.equals(20)) { | |||
// 状态 | |||
Menu menuInfo = menuMapper.selectOne(new LambdaQueryWrapper<Menu>() | |||
.eq(Menu::getPid, entity.getId()) | |||
.eq(Menu::getType, 1) | |||
.eq(Menu::getSort, item) | |||
.eq(Menu::getMark, 1) | |||
.last("limit 1")); | |||
if (menuInfo != null) { | |||
funcInfo.setId(menuInfo.getId()); | |||
funcInfo.setUpdateUser(ShiroUtils.getUserId()); | |||
funcInfo.setUpdateTime(DateUtils.now()); | |||
} | |||
funcInfo.setTitle("设置状态"); | |||
funcInfo.setPermission(String.format("sys:%s:status", moduleName)); | |||
} else if (item.equals(25)) { | |||
// 批量删除 | |||
Menu menuInfo = menuMapper.selectOne(new LambdaQueryWrapper<Menu>() | |||
.eq(Menu::getPid, entity.getId()) | |||
.eq(Menu::getType, 1) | |||
.eq(Menu::getSort, item) | |||
.eq(Menu::getMark, 1) | |||
.last("limit 1")); | |||
if (menuInfo != null) { | |||
funcInfo.setId(menuInfo.getId()); | |||
funcInfo.setUpdateUser(ShiroUtils.getUserId()); | |||
funcInfo.setUpdateTime(DateUtils.now()); | |||
} | |||
funcInfo.setTitle("批量删除"); | |||
funcInfo.setPermission(String.format("sys:%s:dall", moduleName)); | |||
} else if (item.equals(30)) { | |||
// 全部展开 | |||
Menu menuInfo = menuMapper.selectOne(new LambdaQueryWrapper<Menu>() | |||
.eq(Menu::getPid, entity.getId()) | |||
.eq(Menu::getType, 1) | |||
.eq(Menu::getSort, item) | |||
.eq(Menu::getMark, 1) | |||
.last("limit 1")); | |||
if (menuInfo != null) { | |||
funcInfo.setId(menuInfo.getId()); | |||
funcInfo.setUpdateUser(ShiroUtils.getUserId()); | |||
funcInfo.setUpdateTime(DateUtils.now()); | |||
} | |||
funcInfo.setTitle("全部展开"); | |||
funcInfo.setPermission(String.format("sys:%s:expand", moduleName)); | |||
} else if (item.equals(35)) { | |||
// 全部折叠 | |||
Menu menuInfo = menuMapper.selectOne(new LambdaQueryWrapper<Menu>() | |||
.eq(Menu::getPid, entity.getId()) | |||
.eq(Menu::getType, 1) | |||
.eq(Menu::getSort, item) | |||
.eq(Menu::getMark, 1) | |||
.last("limit 1")); | |||
if (menuInfo != null) { | |||
funcInfo.setId(menuInfo.getId()); | |||
funcInfo.setUpdateUser(ShiroUtils.getUserId()); | |||
funcInfo.setUpdateTime(DateUtils.now()); | |||
} | |||
funcInfo.setTitle("全部折叠"); | |||
funcInfo.setPermission(String.format("sys:%s:collapse", moduleName)); | |||
} else if (item.equals(40)) { | |||
// 添加子级 | |||
Menu menuInfo = menuMapper.selectOne(new LambdaQueryWrapper<Menu>() | |||
.eq(Menu::getPid, entity.getId()) | |||
.eq(Menu::getType, 1) | |||
.eq(Menu::getSort, item) | |||
.eq(Menu::getMark, 1) | |||
.last("limit 1")); | |||
if (menuInfo != null) { | |||
funcInfo.setId(menuInfo.getId()); | |||
funcInfo.setUpdateUser(ShiroUtils.getUserId()); | |||
funcInfo.setUpdateTime(DateUtils.now()); | |||
} | |||
funcInfo.setTitle("添加子级"); | |||
funcInfo.setPermission(String.format("sys:%s:addz", moduleName)); | |||
} else if (item.equals(45)) { | |||
// 导出数据 | |||
Menu menuInfo = menuMapper.selectOne(new LambdaQueryWrapper<Menu>() | |||
.eq(Menu::getPid, entity.getId()) | |||
.eq(Menu::getType, 1) | |||
.eq(Menu::getSort, item) | |||
.eq(Menu::getMark, 1) | |||
.last("limit 1")); | |||
if (menuInfo != null) { | |||
funcInfo.setId(menuInfo.getId()); | |||
funcInfo.setUpdateUser(ShiroUtils.getUserId()); | |||
funcInfo.setUpdateTime(DateUtils.now()); | |||
} | |||
funcInfo.setTitle("导出数据"); | |||
funcInfo.setPermission(String.format("sys:%s:export", moduleName)); | |||
} else if (item.equals(50)) { | |||
// 导入数据 | |||
Menu menuInfo = menuMapper.selectOne(new LambdaQueryWrapper<Menu>() | |||
.eq(Menu::getPid, entity.getId()) | |||
.eq(Menu::getType, 1) | |||
.eq(Menu::getSort, item) | |||
.eq(Menu::getMark, 1) | |||
.last("limit 1")); | |||
if (menuInfo != null) { | |||
funcInfo.setId(menuInfo.getId()); | |||
funcInfo.setUpdateUser(ShiroUtils.getUserId()); | |||
funcInfo.setUpdateTime(DateUtils.now()); | |||
} | |||
funcInfo.setTitle("导入数据"); | |||
funcInfo.setPermission(String.format("sys:%s:import", moduleName)); | |||
} else if (item.equals(55)) { | |||
// 分配权限 | |||
Menu menuInfo = menuMapper.selectOne(new LambdaQueryWrapper<Menu>() | |||
.eq(Menu::getPid, entity.getId()) | |||
.eq(Menu::getType, 1) | |||
.eq(Menu::getSort, item) | |||
.eq(Menu::getMark, 1) | |||
.last("limit 1")); | |||
if (menuInfo != null) { | |||
funcInfo.setId(menuInfo.getId()); | |||
funcInfo.setUpdateUser(ShiroUtils.getUserId()); | |||
funcInfo.setUpdateTime(DateUtils.now()); | |||
} | |||
funcInfo.setTitle("分配权限"); | |||
funcInfo.setPermission(String.format("sys:%s:permission", moduleName)); | |||
} | |||
if (StringUtils.isEmpty(funcInfo.getTitle())) { | |||
continue; | |||
} | |||
if (StringUtils.isNull(funcInfo.getId())) { | |||
// 创建 | |||
menuMapper.insert(funcInfo); | |||
} else { | |||
// 更新 | |||
menuMapper.updateById(funcInfo); | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* 生成模板文件 | |||
* | |||
* @param templateName 模板名称 | |||
* @param file 生成文件 | |||
* @param dataMap 生成参数 | |||
* @throws Exception | |||
*/ | |||
private void generateFileByTemplate(String templateName, File file, Map<String, Object> dataMap) throws Exception { | |||
Template template = FreeMarkerUtils.getTemplate(templateName); | |||
FileOutputStream fos = new FileOutputStream(file); | |||
dataMap.put("tableName", tableName); | |||
dataMap.put("entityName", entityName); | |||
dataMap.put("author", author); | |||
dataMap.put("date", createTime); | |||
dataMap.put("packageName", packageName); | |||
dataMap.put("tableAnnotation", tableAnnotation); | |||
Writer out = new BufferedWriter(new OutputStreamWriter(fos, "utf-8"), 10240); | |||
template.process(dataMap, out); | |||
} | |||
/** | |||
* 获取数据表列信息 | |||
* | |||
* @param resultSet | |||
* @return | |||
* @throws IOException | |||
*/ | |||
private Map<String, Object> getColumnsList(ResultSet resultSet) throws IOException { | |||
// 初始化Map对象 | |||
Map<String, Object> dataMap = new HashMap<>(); | |||
try { | |||
// 获取列信息 | |||
List<ColumnClass> columnClassList = new ArrayList<>(); | |||
ColumnClass columnClass = null; | |||
boolean hasPid = false; | |||
boolean columnNumberValue = false; | |||
while (resultSet.next()) { | |||
//id字段略过 | |||
if (resultSet.getString("COLUMN_NAME").equals("id")) { | |||
continue; | |||
} | |||
// 判断是否存在pid | |||
if (resultSet.getString("COLUMN_NAME").equals("pid")) { | |||
hasPid = true; | |||
} | |||
columnClass = new ColumnClass(); | |||
//获取字段名称 | |||
columnClass.setColumnName(resultSet.getString("COLUMN_NAME")); | |||
//获取字段类型 | |||
columnClass.setColumnType(resultSet.getString("TYPE_NAME")); | |||
//转换字段名称,如 sys_name 变成 SysName | |||
columnClass.setChangeColumnName(replaceUnderLineAndUpperCase(resultSet.getString("COLUMN_NAME"))); | |||
//字段在数据库的注释 | |||
String remarks = resultSet.getString("REMARKS"); | |||
columnClass.setColumnComment(remarks); | |||
// 注解分析 | |||
if (remarks.contains(":") || remarks.contains(":")) { | |||
// 获取数字 | |||
String regets = ":|:|\\s"; | |||
//在分割的时候顺带把空格给去掉,data的格式基本为: 18:00 | |||
String[] times = remarks.split(regets); | |||
// 标题描述 | |||
remarks = times[0]; | |||
Map<String, String> map = new HashMap<>(); | |||
List<String> columnValue = new ArrayList<>(); | |||
List<String> columnValue2 = new ArrayList<>(); | |||
Map<Integer, String> columnValueList = new HashMap<>(); | |||
for (int i = 1; i < times.length; i++) { | |||
if (StringUtils.isEmpty(times[i])) { | |||
continue; | |||
} | |||
if (times[i].contains("=")) { | |||
String[] item = times[i].split("="); | |||
System.out.println("Key:" + item[0] + " " + "Val:" + item[1]); | |||
map.put(item[0], item[1]); | |||
columnValue.add(String.format("'%s'", item[1])); | |||
columnValue2.add(String.format("%s", item[1])); | |||
columnValueList.put(Integer.valueOf(item[0]), item[1]); | |||
columnNumberValue = false; | |||
} else { | |||
String key = Pattern.compile("[^0-9]").matcher(times[i]).replaceAll("").trim(); | |||
String value = times[i].replaceAll(key, "").trim(); | |||
System.out.println("Key:" + key + " " + "Val:" + value); | |||
map.put(key, value); | |||
columnValue.add(String.format("'%s'", value)); | |||
columnValue2.add(String.format("%s", value)); | |||
columnValueList.put(Integer.valueOf(key), value); | |||
columnNumberValue = true; | |||
} | |||
} | |||
columnClass.setHasColumnCommentValue(true); | |||
columnClass.setColumnCommentName(remarks); | |||
columnClass.setColumnCommentValue(map); | |||
columnClass.setColumnNumberValue(columnNumberValue); | |||
// 列值 | |||
if ((columnClass.getColumnName().equals("status") && columnValue2.size() == 2) || columnClass.getColumnName().startsWith("is_")) { | |||
columnClass.setColumnSwitchValue(StringUtils.join(columnValue2, "|")); | |||
columnClass.setColumnSwitch(true); | |||
} else { | |||
columnClass.setColumnSwitch(false); | |||
} | |||
columnClass.setColumnValue(StringUtils.join(columnValue, ",")); | |||
columnClass.setColumnValueList(columnValueList); | |||
} | |||
// 判断是否是图片字段 | |||
if (columnClass.getColumnName().contains("cover") | |||
|| columnClass.getColumnName().contains("avatar") | |||
|| columnClass.getColumnName().contains("image") | |||
|| columnClass.getColumnName().contains("logo") | |||
|| columnClass.getColumnName().contains("pic")) { | |||
// 设置图片字段标识 | |||
columnClass.setColumnImage(true); | |||
} | |||
// 判断是否是多行文本字段 | |||
if (columnClass.getColumnName().contains("note") | |||
|| columnClass.getColumnName().contains("remark") | |||
|| columnClass.getColumnName().contains("content") | |||
|| columnClass.getColumnName().contains("description") | |||
|| columnClass.getColumnName().contains("intro")) { | |||
// 设置多行文本标识 | |||
columnClass.setColumnTextArea(true); | |||
} | |||
columnClassList.add(columnClass); | |||
} | |||
dataMap.put("model_column", columnClassList); | |||
dataMap.put("hasPid", hasPid); | |||
} catch (Exception e) { | |||
System.out.println(e.getMessage()); | |||
} | |||
return dataMap; | |||
} | |||
/** | |||
* 根据路径创建文件夹 | |||
* | |||
* @param path 路径 | |||
*/ | |||
private void initFileDir(String path) { | |||
// 文件路径 | |||
File file = new File(path); | |||
// 判断文件路径是否存在 | |||
if (!file.exists()) { | |||
// 创建文件路径 | |||
file.mkdirs(); | |||
} | |||
} | |||
/** | |||
* 字符串转换函数 | |||
* 如:sys_name 变成 SysName | |||
* | |||
* @param str 字符串 | |||
* @return | |||
*/ | |||
public String replaceUnderLineAndUpperCase(String str) { | |||
StringBuffer sb = new StringBuffer(); | |||
sb.append(str); | |||
int count = sb.indexOf("_"); | |||
while (count != 0) { | |||
int num = sb.indexOf("_", count); | |||
count = num + 1; | |||
if (num != -1) { | |||
char ss = sb.charAt(count); | |||
char ia = (char) (ss - 32); | |||
sb.replace(count, count + 1, ia + ""); | |||
} | |||
} | |||
String result = sb.toString().replaceAll("_", ""); | |||
return StringUtils.capitalize(result); | |||
} | |||
} |
@@ -1,140 +0,0 @@ | |||
package com.tuoheng.generator.utils; | |||
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException; | |||
import com.baomidou.mybatisplus.core.toolkit.StringPool; | |||
import com.baomidou.mybatisplus.core.toolkit.StringUtils; | |||
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.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Scanner; | |||
/** | |||
* 代码生成类 | |||
* | |||
* @author 牧羊人 | |||
* @date 2019/11/28 | |||
*/ | |||
public class CodeGenerator { | |||
/** | |||
* <p> | |||
* 读取控制台内容 | |||
* </p> | |||
*/ | |||
public static String scanner(String tip) { | |||
Scanner scanner = new Scanner(System.in); | |||
StringBuilder help = new StringBuilder(); | |||
help.append("请输入" + tip + ":"); | |||
System.out.println(help.toString()); | |||
if (scanner.hasNext()) { | |||
String ipt = scanner.next(); | |||
if (StringUtils.isNotEmpty(ipt)) { | |||
return ipt; | |||
} | |||
} | |||
throw new MybatisPlusException("请输入正确的" + tip + "!"); | |||
} | |||
public static void main(String[] args) { | |||
// 代码生成器 | |||
AutoGenerator mpg = new AutoGenerator(); | |||
// 全局配置 | |||
GlobalConfig gc = new GlobalConfig(); | |||
String projectPath = System.getProperty("user.dir"); | |||
gc.setOutputDir(projectPath + "/tuoheng-admin/src/main/java"); | |||
gc.setAuthor("拓恒"); | |||
gc.setOpen(false); | |||
// gc.setSwagger2(true); 实体属性 Swagger2 注解 | |||
mpg.setGlobalConfig(gc); | |||
// 数据源配置 | |||
DataSourceConfig dsc = new DataSourceConfig(); | |||
dsc.setUrl("jdbc:mysql://127.0.0.1:3306/tuoheng_airport?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=UTC"); | |||
// dsc.setSchemaName("public"); | |||
dsc.setDriverName("com.mysql.cj.jdbc.Driver"); | |||
dsc.setUsername("root"); | |||
dsc.setPassword(""); | |||
mpg.setDataSource(dsc); | |||
// 包配置 | |||
PackageConfig pc = new PackageConfig(); | |||
// pc.setModuleName(scanner("模块名")); | |||
// pc.setModuleName("university"); | |||
// pc.setParent("com.think"); | |||
pc.setParent("com.tuoheng.admin"); | |||
mpg.setPackageInfo(pc); | |||
// 自定义配置 | |||
InjectionConfig cfg = new InjectionConfig() { | |||
@Override | |||
public void initMap() { | |||
// to do nothing | |||
} | |||
}; | |||
// 如果模板引擎是 freemarker | |||
String templatePath = "/templates/mapper.xml.ftl"; | |||
// 如果模板引擎是 velocity | |||
// String templatePath = "/templates/mapper.xml.vm"; | |||
// 自定义输出配置 | |||
List<FileOutConfig> focList = new ArrayList<>(); | |||
// 自定义配置会被优先输出 | |||
focList.add(new FileOutConfig(templatePath) { | |||
@Override | |||
public String outputFile(TableInfo tableInfo) { | |||
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!! | |||
return projectPath + "/tuoheng-admin/src/main/resources/mapper/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML; | |||
} | |||
}); | |||
/* | |||
cfg.setFileCreate(new IFileCreate() { | |||
@Override | |||
public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) { | |||
// 判断自定义文件夹是否需要创建 | |||
checkDir("调用默认方法创建的目录"); | |||
return false; | |||
} | |||
}); | |||
*/ | |||
cfg.setFileOutConfigList(focList); | |||
mpg.setCfg(cfg); | |||
// 配置模板 | |||
TemplateConfig templateConfig = new TemplateConfig(); | |||
// 配置自定义输出模板 | |||
//指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别 | |||
// templateConfig.setEntity("templates/entity2.java"); | |||
// templateConfig.setService(); | |||
// templateConfig.setController(); | |||
templateConfig.setXml(null); | |||
mpg.setTemplate(templateConfig); | |||
// 策略配置 | |||
StrategyConfig strategy = new StrategyConfig(); | |||
strategy.setNaming(NamingStrategy.underline_to_camel); | |||
strategy.setColumnNaming(NamingStrategy.underline_to_camel); | |||
strategy.setSuperEntityClass("com.tuoheng.common.common.BaseEntity"); | |||
strategy.setEntityLombokModel(true); | |||
strategy.setRestControllerStyle(true); | |||
// 公共父类 | |||
strategy.setSuperControllerClass("com.tuoheng.common.common.BaseController"); | |||
// 写于父类中的公共字段 | |||
strategy.setSuperEntityColumns("id"); | |||
strategy.setInclude(scanner("表名,多个英文逗号分割").split(",")); | |||
strategy.setControllerMappingHyphenStyle(true); | |||
// strategy.setTablePrefix(pc.getModuleName() + "_"); | |||
strategy.setTablePrefix("th_"); | |||
mpg.setStrategy(strategy); | |||
mpg.setTemplateEngine(new FreemarkerTemplateEngine()); | |||
mpg.execute(); | |||
} | |||
} |
@@ -1,89 +0,0 @@ | |||
package com.tuoheng.generator.utils; | |||
import lombok.Data; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
/** | |||
* 数据表列 | |||
*/ | |||
@Data | |||
public class ColumnClass { | |||
/** | |||
* 数据库字段名称 | |||
**/ | |||
private String columnName; | |||
/** | |||
* 数据库字段类型 | |||
**/ | |||
private String columnType; | |||
/** | |||
* 数据库字段首字母小写且去掉下划线字符串 | |||
**/ | |||
private String changeColumnName; | |||
/** | |||
* 数据库字段注释 | |||
**/ | |||
private String columnComment; | |||
/** | |||
* 是否有注解值 | |||
*/ | |||
private boolean hasColumnCommentValue; | |||
/** | |||
* 是否选择开关 | |||
*/ | |||
private boolean columnSwitch; | |||
/** | |||
* 数据库字段注释(仅包含名称) | |||
**/ | |||
private String columnCommentName; | |||
/** | |||
* 数据库字段注解值 | |||
*/ | |||
private Map<String, String> columnCommentValue = new HashMap<>(); | |||
/** | |||
* 字段值(如:1淘宝 2京东 3拼多多,需转换成:1=淘宝,2=京东,3=拼多多) | |||
*/ | |||
private String columnValue; | |||
/** | |||
* 字段值列表 | |||
*/ | |||
private Map<Integer, String> columnValueList; | |||
/** | |||
* 字段配置至是否是数字(特殊情况下,值不一定是数字,如:hidden=隐藏) | |||
*/ | |||
private boolean columnNumberValue; | |||
/** | |||
* 字段值开关(如:淘宝|京东) | |||
*/ | |||
private String columnSwitchValue; | |||
/** | |||
* 字段默认值 | |||
*/ | |||
private String columnDefaultValue; | |||
/** | |||
* 是否是图片字段 | |||
*/ | |||
private boolean columnImage; | |||
/** | |||
* 是否是多行文本 | |||
*/ | |||
private boolean columnTextArea; | |||
} |
@@ -1,41 +0,0 @@ | |||
package com.tuoheng.generator.utils; | |||
import freemarker.cache.ClassTemplateLoader; | |||
import freemarker.cache.NullCacheStorage; | |||
import freemarker.template.Configuration; | |||
import freemarker.template.Template; | |||
import freemarker.template.TemplateExceptionHandler; | |||
import java.io.IOException; | |||
/** | |||
* FreeMarker工具类 | |||
*/ | |||
public class FreeMarkerUtils { | |||
private FreeMarkerUtils() { | |||
} | |||
private static final Configuration CONFIGURATION = new Configuration(Configuration.VERSION_2_3_22); | |||
static { | |||
//这里比较重要,用来指定加载模板所在的路径 | |||
CONFIGURATION.setTemplateLoader(new ClassTemplateLoader(FreeMarkerUtils.class, "/templates")); | |||
CONFIGURATION.setDefaultEncoding("UTF-8"); | |||
CONFIGURATION.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); | |||
CONFIGURATION.setCacheStorage(NullCacheStorage.INSTANCE); | |||
} | |||
public static Template getTemplate(String templateName) throws IOException { | |||
try { | |||
return CONFIGURATION.getTemplate(templateName); | |||
} catch (IOException e) { | |||
throw e; | |||
} | |||
} | |||
public static void clearCache() { | |||
CONFIGURATION.clearTemplateCache(); | |||
} | |||
} |
@@ -1,209 +0,0 @@ | |||
package com.tuoheng.generator.utils; | |||
import com.tuoheng.common.utils.StringUtils; | |||
import com.tuoheng.generator.config.GenConfig; | |||
import com.tuoheng.generator.constant.GenConstants; | |||
import com.tuoheng.generator.entity.GenTable; | |||
import com.tuoheng.generator.entity.GenTableColumn; | |||
import org.apache.commons.lang3.RegExUtils; | |||
import java.util.Arrays; | |||
/** | |||
* 代码生成器工具类 | |||
*/ | |||
public class GenUtils { | |||
/** | |||
* 初始化表信息 | |||
*/ | |||
public static void initTable(GenTable genTable, String operName) { | |||
genTable.setClassName(convertClassName(genTable.getTableName())); | |||
genTable.setPackageName(GenConfig.getPackageName()); | |||
genTable.setModuleName(getModuleName(GenConfig.getPackageName())); | |||
genTable.setBusinessName(getBusinessName(genTable.getTableName())); | |||
genTable.setFunctionName(replaceText(genTable.getTableComment())); | |||
genTable.setFunctionAuthor(GenConfig.getAuthor()); | |||
genTable.setCreateUser(0); | |||
} | |||
/** | |||
* 初始化列属性字段 | |||
*/ | |||
public static void initColumnField(GenTableColumn column, GenTable table) { | |||
String dataType = getDbType(column.getColumnType()); | |||
String columnName = column.getColumnName(); | |||
column.setTableId(table.getId()); | |||
column.setCreateUser(table.getCreateUser()); | |||
// 设置java字段名 | |||
column.setJavaField(StringUtils.toCamelCase(columnName)); | |||
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType)) { | |||
column.setJavaType(GenConstants.TYPE_STRING); | |||
// 字符串长度超过500设置为文本域 | |||
Integer columnLength = getColumnLength(column.getColumnType()); | |||
String htmlType = columnLength >= 500 ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT; | |||
column.setHtmlType(htmlType); | |||
} else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) { | |||
column.setJavaType(GenConstants.TYPE_DATE); | |||
column.setHtmlType(GenConstants.HTML_DATETIME); | |||
} else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) { | |||
column.setHtmlType(GenConstants.HTML_INPUT); | |||
// 如果是浮点型 | |||
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ","); | |||
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) { | |||
column.setJavaType(GenConstants.TYPE_DOUBLE); | |||
} | |||
// 如果是整形 | |||
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) { | |||
column.setJavaType(GenConstants.TYPE_INTEGER); | |||
} | |||
// 长整形 | |||
else { | |||
column.setJavaType(GenConstants.TYPE_LONG); | |||
} | |||
} | |||
// 插入字段(默认所有字段都需要插入) | |||
column.setIsInsert(GenConstants.REQUIRE); | |||
// 编辑字段 | |||
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && column.getIsPk() != 1) { | |||
column.setIsEdit(GenConstants.REQUIRE); | |||
} | |||
// 列表字段 | |||
if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && column.getIsPk() != 1) { | |||
column.setIsList(GenConstants.REQUIRE); | |||
} | |||
// 查询字段 | |||
if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && column.getIsPk() != 1) { | |||
column.setIsQuery(GenConstants.REQUIRE); | |||
} | |||
// 查询字段类型 | |||
if (StringUtils.endsWithIgnoreCase(columnName, "name")) { | |||
column.setQueryType(GenConstants.QUERY_LIKE); | |||
} | |||
// 状态字段设置单选框 | |||
if (StringUtils.endsWithIgnoreCase(columnName, "status")) { | |||
column.setHtmlType(GenConstants.HTML_RADIO); | |||
} | |||
// 类型&性别字段设置下拉框 | |||
else if (StringUtils.endsWithIgnoreCase(columnName, "type") | |||
|| StringUtils.endsWithIgnoreCase(columnName, "sex")) { | |||
column.setHtmlType(GenConstants.HTML_SELECT); | |||
} | |||
} | |||
/** | |||
* 校验数组是否包含指定值 | |||
* | |||
* @param arr 数组 | |||
* @param targetValue 值 | |||
* @return 是否包含 | |||
*/ | |||
public static boolean arraysContains(String[] arr, String targetValue) { | |||
return Arrays.asList(arr).contains(targetValue); | |||
} | |||
/** | |||
* 获取模块名 | |||
* | |||
* @param packageName 包名 | |||
* @return 模块名 | |||
*/ | |||
public static String getModuleName(String packageName) { | |||
int lastIndex = packageName.lastIndexOf("."); | |||
int nameLength = packageName.length(); | |||
String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength); | |||
return moduleName; | |||
} | |||
/** | |||
* 获取业务名 | |||
* | |||
* @param tableName 表名 | |||
* @return 业务名 | |||
*/ | |||
public static String getBusinessName(String tableName) { | |||
int lastIndex = tableName.lastIndexOf("_"); | |||
int nameLength = tableName.length(); | |||
String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength); | |||
return businessName; | |||
} | |||
/** | |||
* 表名转换成Java类名 | |||
* | |||
* @param tableName 表名称 | |||
* @return 类名 | |||
*/ | |||
public static String convertClassName(String tableName) { | |||
boolean autoRemovePre = GenConfig.getAutoRemovePre(); | |||
String tablePrefix = GenConfig.getTablePrefix(); | |||
if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) { | |||
String[] searchList = StringUtils.split(tablePrefix, ","); | |||
tableName = replaceFirst(tableName, searchList); | |||
} | |||
return StringUtils.convertToCamelCase(tableName); | |||
} | |||
/** | |||
* 批量替换前缀 | |||
* | |||
* @param replacementm 替换值 | |||
* @param searchList 替换列表 | |||
* @return | |||
*/ | |||
public static String replaceFirst(String replacementm, String[] searchList) { | |||
String text = replacementm; | |||
for (String searchString : searchList) { | |||
if (replacementm.startsWith(searchString)) { | |||
text = replacementm.replaceFirst(searchString, ""); | |||
break; | |||
} | |||
} | |||
return text; | |||
} | |||
/** | |||
* 关键字替换 | |||
* | |||
* @param text 需要被替换的名字 | |||
* @return 替换后的名字 | |||
*/ | |||
public static String replaceText(String text) { | |||
return RegExUtils.replaceAll(text, "(?:表|若依)", ""); | |||
} | |||
/** | |||
* 获取数据库类型字段 | |||
* | |||
* @param columnType 列类型 | |||
* @return 截取后的列类型 | |||
*/ | |||
public static String getDbType(String columnType) { | |||
if (StringUtils.indexOf(columnType, "(") > 0) { | |||
return StringUtils.substringBefore(columnType, "("); | |||
} else { | |||
return columnType; | |||
} | |||
} | |||
/** | |||
* 获取字段长度 | |||
* | |||
* @param columnType 列类型 | |||
* @return 截取后的列类型 | |||
*/ | |||
public static Integer getColumnLength(String columnType) { | |||
if (StringUtils.indexOf(columnType, "(") > 0) { | |||
String length = StringUtils.substringBetween(columnType, "(", ")"); | |||
return Integer.valueOf(length); | |||
} else { | |||
return 0; | |||
} | |||
} | |||
} |
@@ -1,116 +0,0 @@ | |||
<?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.tuoheng.generator.mapper.GenTableColumnMapper"> | |||
<resultMap type="com.tuoheng.generator.entity.GenTableColumn" id="GenTableColumnResult"> | |||
<id property="id" column="id"/> | |||
<result property="tableId" column="table_id"/> | |||
<result property="columnName" column="column_name"/> | |||
<result property="columnComment" column="column_comment"/> | |||
<result property="columnType" column="column_type"/> | |||
<result property="javaType" column="java_type"/> | |||
<result property="javaField" column="java_field"/> | |||
<result property="isPk" column="is_pk"/> | |||
<result property="isIncrement" column="is_increment"/> | |||
<result property="isRequired" column="is_required"/> | |||
<result property="isInsert" column="is_insert"/> | |||
<result property="isEdit" column="is_edit"/> | |||
<result property="isList" column="is_list"/> | |||
<result property="isQuery" column="is_query"/> | |||
<result property="queryType" column="query_type"/> | |||
<result property="htmlType" column="html_type"/> | |||
<result property="dictType" column="dict_type"/> | |||
<result property="sort" column="sort"/> | |||
<result property="createUser" column="create_user"/> | |||
<result property="createTime" column="create_time"/> | |||
<result property="updateUser" column="update_user"/> | |||
<result property="updateTime" column="update_time"/> | |||
</resultMap> | |||
<!-- 根据表明获取列信息 --> | |||
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult"> | |||
select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type | |||
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName}) | |||
order by ordinal_position | |||
</select> | |||
<!-- 插入表列信息 --> | |||
<insert id="insertGenTableColumn" parameterType="com.tuoheng.generator.entity.GenTableColumn" useGeneratedKeys="true" | |||
keyProperty="id"> | |||
insert into gen_table_column ( | |||
<if test="tableId != null and tableId != ''">table_id,</if> | |||
<if test="columnName != null and columnName != ''">column_name,</if> | |||
<if test="columnComment != null and columnComment != ''">column_comment,</if> | |||
<if test="columnType != null and columnType != ''">column_type,</if> | |||
<if test="javaType != null and javaType != ''">java_type,</if> | |||
<if test="javaField != null and javaField != ''">java_field,</if> | |||
<if test="isPk != null and isPk != ''">is_pk,</if> | |||
<if test="isIncrement != null and isIncrement != ''">is_increment,</if> | |||
<if test="isRequired != null and isRequired != ''">is_required,</if> | |||
<if test="isInsert != null and isInsert != ''">is_insert,</if> | |||
<if test="isEdit != null and isEdit != ''">is_edit,</if> | |||
<if test="isList != null and isList != ''">is_list,</if> | |||
<if test="isQuery != null and isQuery != ''">is_query,</if> | |||
<if test="queryType != null and queryType != ''">query_type,</if> | |||
<if test="htmlType != null and htmlType != ''">html_type,</if> | |||
<if test="dictType != null and dictType != ''">dict_type,</if> | |||
<if test="sort != null">sort,</if> | |||
<if test="createUser != null and createUser != ''">create_user,</if> | |||
create_time | |||
)values( | |||
<if test="tableId != null and tableId != ''">#{tableId},</if> | |||
<if test="columnName != null and columnName != ''">#{columnName},</if> | |||
<if test="columnComment != null and columnComment != ''">#{columnComment},</if> | |||
<if test="columnType != null and columnType != ''">#{columnType},</if> | |||
<if test="javaType != null and javaType != ''">#{javaType},</if> | |||
<if test="javaField != null and javaField != ''">#{javaField},</if> | |||
<if test="isPk != null and isPk != ''">#{isPk},</if> | |||
<if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if> | |||
<if test="isRequired != null and isRequired != ''">#{isRequired},</if> | |||
<if test="isInsert != null and isInsert != ''">#{isInsert},</if> | |||
<if test="isEdit != null and isEdit != ''">#{isEdit},</if> | |||
<if test="isList != null and isList != ''">#{isList},</if> | |||
<if test="isQuery != null and isQuery != ''">#{isQuery},</if> | |||
<if test="queryType != null and queryType != ''">#{queryType},</if> | |||
<if test="htmlType != null and htmlType != ''">#{htmlType},</if> | |||
<if test="dictType != null and dictType != ''">#{dictType},</if> | |||
<if test="sort != null">#{sort},</if> | |||
<if test="createUser != null and createUser != ''">#{createUser},</if> | |||
sysdate() | |||
) | |||
</insert> | |||
<sql id="selectGenTableColumnVo"> | |||
select id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_user, create_time, update_user, update_time from gen_table_column | |||
</sql> | |||
<!-- 获取表字段列表 --> | |||
<select id="selectGenTableColumnListByTableId" parameterType="Integer" resultMap="GenTableColumnResult"> | |||
<include refid="selectGenTableColumnVo"/> | |||
where table_id = #{tableId} | |||
order by sort | |||
</select> | |||
<!-- 更新业务表字段 --> | |||
<update id="updateGenTableColumn" parameterType="com.tuoheng.generator.entity.GenTableColumn"> | |||
update gen_table_column | |||
<set> | |||
column_comment = #{columnComment}, | |||
java_type = #{javaType}, | |||
java_field = #{javaField}, | |||
is_insert = #{isInsert}, | |||
is_edit = #{isEdit}, | |||
is_list = #{isList}, | |||
is_query = #{isQuery}, | |||
is_required = #{isRequired}, | |||
query_type = #{queryType}, | |||
html_type = #{htmlType}, | |||
dict_type = #{dictType}, | |||
sort = #{sort}, | |||
update_user = #{updateUser}, | |||
update_time = sysdate() | |||
</set> | |||
where id = #{id} | |||
</update> | |||
</mapper> |
@@ -1,162 +0,0 @@ | |||
<?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.tuoheng.generator.mapper.GenTableMapper"> | |||
<resultMap type="com.tuoheng.generator.entity.GenTable" id="GenTableResult"> | |||
<id property="id" column="id"/> | |||
<result property="tableName" column="table_name"/> | |||
<result property="tableComment" column="table_comment"/> | |||
<result property="className" column="class_name"/> | |||
<result property="tplCategory" column="tpl_category"/> | |||
<result property="packageName" column="package_name"/> | |||
<result property="moduleName" column="module_name"/> | |||
<result property="businessName" column="business_name"/> | |||
<result property="functionName" column="function_name"/> | |||
<result property="functionAuthor" column="function_author"/> | |||
<result property="options" column="options"/> | |||
<result property="createUser" column="create_user"/> | |||
<result property="createTime" column="create_time"/> | |||
<result property="updateUser" column="update_user"/> | |||
<result property="updateTime" column="update_time"/> | |||
<result property="note" column="note"/> | |||
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult"/> | |||
</resultMap> | |||
<resultMap type="com.tuoheng.generator.entity.GenTableColumn" id="GenTableColumnResult"> | |||
<id property="id" column="id"/> | |||
<result property="tableId" column="table_id"/> | |||
<result property="columnName" column="column_name"/> | |||
<result property="columnComment" column="column_comment"/> | |||
<result property="columnType" column="column_type"/> | |||
<result property="javaType" column="java_type"/> | |||
<result property="javaField" column="java_field"/> | |||
<result property="isPk" column="is_pk"/> | |||
<result property="isIncrement" column="is_increment"/> | |||
<result property="isRequired" column="is_required"/> | |||
<result property="isInsert" column="is_insert"/> | |||
<result property="isEdit" column="is_edit"/> | |||
<result property="isList" column="is_list"/> | |||
<result property="isQuery" column="is_query"/> | |||
<result property="queryType" column="query_type"/> | |||
<result property="htmlType" column="html_type"/> | |||
<result property="dictType" column="dict_type"/> | |||
<result property="sort" column="sort"/> | |||
<result property="createUser" column="create_user"/> | |||
<result property="createTime" column="create_time"/> | |||
<result property="updateUser" column="update_user"/> | |||
<result property="updateTime" column="update_time"/> | |||
</resultMap> | |||
<sql id="selectGenTableVo"> | |||
select id, table_name, table_comment, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, options, note, create_user, create_time, update_user, update_time, mark from gen_table | |||
</sql> | |||
<!-- 获取数据表列表 --> | |||
<select id="selectGenTableList" parameterType="com.tuoheng.generator.entity.GenTable" resultMap="GenTableResult"> | |||
<include refid="selectGenTableVo"/> | |||
<where> | |||
<if test="param.tableName != null and param.tableName != ''"> | |||
AND lower(table_name) like lower(concat('%', #{param.tableName}, '%')) | |||
</if> | |||
<if test="param.tableComment != null and param.tableComment != ''"> | |||
AND lower(table_comment) like lower(concat('%', #{param.tableComment}, '%')) | |||
</if> | |||
AND mark = 1 | |||
</where> | |||
</select> | |||
<!-- 获取数据库表 --> | |||
<select id="selectDbTableList" parameterType="com.tuoheng.generator.entity.GenTable" resultMap="GenTableResult"> | |||
select table_name, table_comment, create_time, update_time from information_schema.tables | |||
where table_schema = (select database()) | |||
AND table_name NOT LIKE 'gen_%' | |||
AND table_name NOT IN (select table_name from gen_table) | |||
<if test="param.tableName != null and param.tableName != ''"> | |||
AND lower(table_name) like lower(concat('%', #{param.tableName}, '%')) | |||
</if> | |||
</select> | |||
<!-- 根据表名获取数据表 --> | |||
<select id="selectDbTableListByNames" resultMap="GenTableResult"> | |||
select table_name, table_comment, create_time, update_time from information_schema.tables | |||
where table_name NOT LIKE 'gen_%' and table_schema = (select database()) | |||
and table_name in | |||
<foreach collection="array" item="name" open="(" separator="," close=")"> | |||
#{name} | |||
</foreach> | |||
</select> | |||
<!-- 插入表结构 --> | |||
<insert id="insertGenTable" parameterType="com.tuoheng.generator.entity.GenTable" useGeneratedKeys="true" | |||
keyProperty="id"> | |||
insert into gen_table ( | |||
<if test="tableName != null">table_name,</if> | |||
<if test="tableComment != null and tableComment != ''">table_comment,</if> | |||
<if test="className != null and className != ''">class_name,</if> | |||
<if test="tplCategory != null and tplCategory != ''">tpl_category,</if> | |||
<if test="packageName != null and packageName != ''">package_name,</if> | |||
<if test="moduleName != null and moduleName != ''">module_name,</if> | |||
<if test="businessName != null and businessName != ''">business_name,</if> | |||
<if test="functionName != null and functionName != ''">function_name,</if> | |||
<if test="functionAuthor != null and functionAuthor != ''">function_author,</if> | |||
<if test="note != null and note != ''">note,</if> | |||
<if test="createUser != null and createUser != ''">create_user,</if> | |||
create_time | |||
)values( | |||
<if test="tableName != null">#{tableName},</if> | |||
<if test="tableComment != null and tableComment != ''">#{tableComment},</if> | |||
<if test="className != null and className != ''">#{className},</if> | |||
<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if> | |||
<if test="packageName != null and packageName != ''">#{packageName},</if> | |||
<if test="moduleName != null and moduleName != ''">#{moduleName},</if> | |||
<if test="businessName != null and businessName != ''">#{businessName},</if> | |||
<if test="functionName != null and functionName != ''">#{functionName},</if> | |||
<if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if> | |||
<if test="note != null and note != ''">#{note},</if> | |||
<if test="createUser != null and createUser != ''">#{createUser},</if> | |||
sysdate() | |||
) | |||
</insert> | |||
<!-- 获取表详情信息 --> | |||
<select id="selectGenTableById" parameterType="Integer" resultMap="GenTableResult"> | |||
SELECT t.id, t.table_name, t.table_comment, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.note, | |||
c.id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort | |||
FROM gen_table t | |||
LEFT JOIN gen_table_column c ON t.id = c.table_id | |||
where c.table_id = #{tableId} | |||
</select> | |||
<!-- 更新业务表 --> | |||
<update id="updateGenTable" parameterType="com.tuoheng.generator.entity.GenTable"> | |||
update gen_table | |||
<set> | |||
<if test="tableName != null">table_name = #{tableName},</if> | |||
<if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if> | |||
<if test="className != null and className != ''">class_name = #{className},</if> | |||
<if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if> | |||
<if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if> | |||
<if test="packageName != null and packageName != ''">package_name = #{packageName},</if> | |||
<if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if> | |||
<if test="businessName != null and businessName != ''">business_name = #{businessName},</if> | |||
<if test="functionName != null and functionName != ''">function_name = #{functionName},</if> | |||
<if test="options != null and options != ''">options = #{options},</if> | |||
<if test="updateUser != null and updateUser != ''">update_user = #{updateUser},</if> | |||
<if test="note != null">note = #{note},</if> | |||
update_time = sysdate() | |||
</set> | |||
where id = #{id} | |||
</update> | |||
<!-- 根据表名获取业务表 --> | |||
<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult"> | |||
SELECT t.id, t.table_name, t.table_comment, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.note, | |||
c.id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort | |||
FROM gen_table t | |||
LEFT JOIN gen_table_column c ON t.id = c.table_id | |||
where t.table_name = #{tableName} | |||
</select> | |||
</mapper> |
@@ -1,46 +0,0 @@ | |||
package ${packageName}.constant; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
/** | |||
* <p> | |||
* ${tableAnnotation} 模块常量 | |||
* </p> | |||
* | |||
* @author ${author} | |||
* @since ${date} | |||
*/ | |||
public class ${entityName}Constant { | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.hasColumnCommentValue = true> | |||
/** | |||
* ${model.columnCommentName} | |||
*/ | |||
<#if model.columnNumberValue = true> | |||
public static Map<Integer, String> ${entityName?upper_case}_${model.changeColumnName?upper_case}_LIST = new HashMap<Integer, String>() { | |||
{ | |||
<#if model.columnCommentValue?exists> | |||
<#list model.columnCommentValue?keys as key> | |||
put(${key}, "${model.columnCommentValue[key]}"); | |||
</#list> | |||
</#if> | |||
} | |||
}; | |||
<#else> | |||
public static Map<String, String> ${entityName?upper_case}_${model.changeColumnName?upper_case}_LIST = new HashMap<String, String>() { | |||
{ | |||
<#if model.columnCommentValue?exists> | |||
<#list model.columnCommentValue?keys as key> | |||
put("${key}", "${model.columnCommentValue[key]}"); | |||
</#list> | |||
</#if> | |||
} | |||
}; | |||
</#if> | |||
</#if> | |||
</#list> | |||
</#if> | |||
} |
@@ -1,109 +0,0 @@ | |||
package ${packageName}.controller; | |||
import LogType; | |||
import BaseController; | |||
import ${packageName}.entity.${entityName}; | |||
import ${packageName}.query.${entityName}Query; | |||
import ${packageName}.service.I${entityName}Service; | |||
import Log; | |||
import JsonResult; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
/** | |||
* <p> | |||
* ${tableAnnotation} 前端控制器 | |||
* </p> | |||
* | |||
* @author ${author} | |||
* @since ${date} | |||
*/ | |||
@RestController | |||
@RequestMapping("/${entityName?lower_case}") | |||
public class ${entityName}Controller extends BaseController { | |||
@Autowired | |||
private I${entityName}Service ${entityName?uncap_first}Service; | |||
/** | |||
* 获取数据列表 | |||
* | |||
* @param query 查询条件 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:${entityName?lower_case}:index") | |||
@GetMapping("/index") | |||
public JsonResult index(${entityName}Query query) { | |||
return ${entityName?uncap_first}Service.getList(query); | |||
} | |||
/** | |||
* 添加记录 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "${tableAnnotation}", logType = LogType.INSERT) | |||
//@RequiresPermissions("sys:${entityName?lower_case}:add") | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody ${entityName} entity) { | |||
return ${entityName?uncap_first}Service.edit(entity); | |||
} | |||
/** | |||
* 获取详情 | |||
* | |||
* @param ${entityName?lower_case}Id 记录ID | |||
* @return | |||
*/ | |||
@GetMapping("/info/{${entityName?lower_case}Id}") | |||
public JsonResult info(@PathVariable("${entityName?lower_case}Id") Integer ${entityName?lower_case}Id) { | |||
return ${entityName?uncap_first}Service.info(${entityName?lower_case}Id); | |||
} | |||
/** | |||
* 更新记录 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "${tableAnnotation}", logType = LogType.UPDATE) | |||
//@RequiresPermissions("sys:${entityName?lower_case}:edit") | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody ${entityName} entity) { | |||
return ${entityName?uncap_first}Service.edit(entity); | |||
} | |||
/** | |||
* 删除记录 | |||
* | |||
* @param ${entityName?lower_case}Ids 记录ID | |||
* @return | |||
*/ | |||
@Log(title = "${tableAnnotation}", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:${entityName?lower_case}:drop") | |||
@DeleteMapping("/delete/{${entityName?lower_case}Ids}") | |||
public JsonResult delete(@PathVariable("${entityName?lower_case}Ids") Integer[] ${entityName?lower_case}Ids) { | |||
return ${entityName?uncap_first}Service.deleteByIds(${entityName?lower_case}Ids); | |||
} | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.columnSwitch == true> | |||
/** | |||
* 设置${model.columnCommentName} | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "${tableAnnotation}", logType = LogType.STATUS) | |||
//@RequiresPermissions("sys:${entityName?lower_case}:${model.columnName}") | |||
@PutMapping("/set${model.changeColumnName?cap_first}") | |||
public JsonResult set${model.changeColumnName?cap_first}(@RequestBody ${entityName} entity) { | |||
return ${entityName?uncap_first}Service.set${model.changeColumnName?cap_first}(entity); | |||
} | |||
</#if> | |||
</#list> | |||
</#if> | |||
} |
@@ -1,16 +0,0 @@ | |||
package ${packageName}.mapper; | |||
import ${packageName}.entity.${entityName}; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
/** | |||
* <p> | |||
* ${tableAnnotation} Mapper 接口 | |||
* </p> | |||
* | |||
* @author ${author} | |||
* @since ${date} | |||
*/ | |||
public interface ${entityName}Mapper extends BaseMapper<${entityName}> { | |||
} |
@@ -1,82 +0,0 @@ | |||
package ${packageName}.entity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import BaseEntity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import java.util.Date; | |||
/** | |||
* <p> | |||
* ${tableAnnotation} | |||
* </p> | |||
* | |||
* @author ${author} | |||
* @since ${date} | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("${tableName}") | |||
public class ${entityName} extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.changeColumnName?uncap_first != 'createUser' && model.changeColumnName?uncap_first != 'createTime' && model.changeColumnName?uncap_first != 'updateUser' && model.changeColumnName?uncap_first != 'updateTime' && model.changeColumnName?uncap_first != 'mark'> | |||
/** | |||
* ${model.columnComment!} | |||
*/ | |||
<#if (model.columnType = 'VARCHAR' || model.columnType = 'CHAR' || model.columnType = 'TEXT' || model.columnType = 'MEDIUMTEXT')> | |||
private String ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'DATETIME' || model.columnType = 'DATE' || model.columnType = 'TIME' || model.columnType = 'YEAR' || model.columnType = 'TIMESTAMP') > | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
private Date ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'TINYINT UNSIGNED' || model.columnType = 'TINYINT')> | |||
private Integer ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'SMALLINT UNSIGNED' || model.columnType = 'SMALLINT' || model.columnType = 'MEDIUMINT UNSIGNED' || model.columnType = 'MEDIUMINT')> | |||
private Integer ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'INT UNSIGNED' || model.columnType = 'INT')> | |||
private Integer ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'BIGINT UNSIGNED' || model.columnType = 'BIGINT')> | |||
private Integer ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'DECIMAL UNSIGNED' || model.columnType = 'DECIMAL')> | |||
private BigDecimal ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'FLOAT UNSIGNED' || model.columnType = 'FLOAT')> | |||
private Float ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'DOUBLE UNSIGNED' || model.columnType = 'DOUBLE')> | |||
private Double ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if model.columnType = 'BLOB'> | |||
private byte[] ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
</#if> | |||
</#list> | |||
</#if> | |||
} |
@@ -1,75 +0,0 @@ | |||
package ${packageName}.vo.${entityName?lower_case}; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import lombok.Data; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import java.math.BigDecimal; | |||
import java.util.Date; | |||
/** | |||
* <p> | |||
* ${tableAnnotation}表单Vo | |||
* </p> | |||
* | |||
* @author ${author} | |||
* @since ${date} | |||
*/ | |||
@Data | |||
public class ${entityName}InfoVo { | |||
/** | |||
* ${tableAnnotation}ID | |||
*/ | |||
private Integer id; | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
/** | |||
* ${model.columnComment!} | |||
*/ | |||
<#if (model.columnType = 'VARCHAR' || model.columnType = 'CHAR' || model.columnType = 'TEXT' || model.columnType = 'MEDIUMTEXT')> | |||
private String ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'DATETIME' || model.columnType = 'DATE' || model.columnType = 'TIME' || model.columnType = 'YEAR' || model.columnType = 'TIMESTAMP') > | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
private Date ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'TINYINT UNSIGNED' || model.columnType = 'TINYINT')> | |||
private Integer ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'SMALLINT UNSIGNED' || model.columnType = 'SMALLINT' || model.columnType = 'MEDIUMINT UNSIGNED' || model.columnType = 'MEDIUMINT')> | |||
private Integer ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'INT UNSIGNED' || model.columnType = 'INT')> | |||
private Integer ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'BIGINT UNSIGNED' || model.columnType = 'BIGINT')> | |||
private Integer ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'DECIMAL UNSIGNED' || model.columnType = 'DECIMAL')> | |||
private BigDecimal ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'FLOAT UNSIGNED' || model.columnType = 'FLOAT')> | |||
private Float ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'DOUBLE UNSIGNED' || model.columnType = 'DOUBLE')> | |||
private Double ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if model.columnType = 'BLOB'> | |||
private byte[] ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
</#list> | |||
</#if> | |||
} |
@@ -1,83 +0,0 @@ | |||
package ${packageName}.vo.${entityName?lower_case}; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import lombok.Data; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import java.math.BigDecimal; | |||
import java.util.Date; | |||
/** | |||
* <p> | |||
* ${tableAnnotation}列表Vo | |||
* </p> | |||
* | |||
* @author ${author} | |||
* @since ${date} | |||
*/ | |||
@Data | |||
public class ${entityName}ListVo { | |||
/** | |||
* ${tableAnnotation}ID | |||
*/ | |||
private Integer id; | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
/** | |||
* ${model.columnComment!} | |||
*/ | |||
<#if (model.columnType = 'VARCHAR' || model.columnType = 'CHAR' || model.columnType = 'TEXT' || model.columnType = 'MEDIUMTEXT')> | |||
private String ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'DATETIME' || model.columnType = 'DATE' || model.columnType = 'TIME' || model.columnType = 'YEAR' || model.columnType = 'TIMESTAMP') > | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
private Date ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'TINYINT UNSIGNED' || model.columnType = 'TINYINT')> | |||
private Integer ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if model.hasColumnCommentValue = true> | |||
/** | |||
* ${model.columnCommentName}描述 | |||
*/ | |||
private String ${model.changeColumnName?uncap_first}Name; | |||
</#if> | |||
<#if (model.columnType = 'SMALLINT UNSIGNED' || model.columnType = 'SMALLINT' || model.columnType = 'MEDIUMINT UNSIGNED' || model.columnType = 'MEDIUMINT')> | |||
private Integer ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'INT UNSIGNED' || model.columnType = 'INT')> | |||
private Integer ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'BIGINT UNSIGNED' || model.columnType = 'BIGINT')> | |||
private Integer ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'DECIMAL UNSIGNED' || model.columnType = 'DECIMAL')> | |||
private BigDecimal ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'FLOAT UNSIGNED' || model.columnType = 'FLOAT')> | |||
private Float ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if (model.columnType = 'DOUBLE UNSIGNED' || model.columnType = 'DOUBLE')> | |||
private Double ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if model.columnType = 'BLOB'> | |||
private byte[] ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
</#list> | |||
</#if> | |||
} |
@@ -1,32 +0,0 @@ | |||
package ${packageName}.service; | |||
import JsonResult; | |||
import ${packageName}.entity.${entityName}; | |||
import IBaseService; | |||
/** | |||
* <p> | |||
* ${tableAnnotation} 服务类 | |||
* </p> | |||
* | |||
* @author ${author} | |||
* @since ${date} | |||
*/ | |||
public interface I${entityName}Service extends IBaseService<${entityName}> { | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.columnSwitch == true && model.changeColumnName?uncap_first != 'status'> | |||
/** | |||
* 设置${model.columnCommentName} | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
JsonResult set${model.changeColumnName?cap_first}(${entityName} entity); | |||
</#if> | |||
</#list> | |||
</#if> | |||
} |
@@ -1,335 +0,0 @@ | |||
<template> | |||
<div class="ele-body"> | |||
<el-card shadow="never"> | |||
<!-- 搜索表单 --> | |||
<el-form :model="table.where" label-width="77px" class="ele-form-search" | |||
@keyup.enter.native="$refs.table.reload()" @submit.native.prevent> | |||
<el-row :gutter="15"> | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.columnName = 'name' || model.columnName = 'title'> | |||
<el-col :md="4" :sm="12"> | |||
<el-form-item label="${model.columnComment}:"> | |||
<el-input v-model="table.where.${model.columnName}" placeholder="请输入${model.columnComment}" clearable/> | |||
</el-form-item> | |||
</el-col> | |||
</#if> | |||
<#if model.hasColumnCommentValue = true> | |||
<!-- ${model.columnCommentName}下拉单选 --> | |||
<el-col :md="4" :sm="12"> | |||
<el-form-item label="${model.columnCommentName}:"> | |||
<el-select v-model="table.where.${model.columnName}" placeholder="请选择${model.columnCommentName}" clearable class="ele-fluid"> | |||
<el-option label="全部" :value="''"/> | |||
<#if model.columnCommentValue?exists> | |||
<#list model.columnCommentValue?keys as key> | |||
<el-option label="${model.columnCommentValue[key]}" :value="${key}"/> | |||
</#list> | |||
</#if> | |||
</el-select> | |||
</el-form-item> | |||
</el-col> | |||
</#if> | |||
</#list> | |||
</#if> | |||
<el-col :md="6" :sm="12"> | |||
<div class="ele-form-actions"> | |||
<el-button type="primary" @click="$refs.table.reload()" icon="el-icon-search" class="ele-btn-icon">查询 | |||
</el-button> | |||
<el-button @click="(table.where={})&&$refs.table.reload()">重置</el-button> | |||
</div> | |||
</el-col> | |||
</el-row> | |||
</el-form> | |||
<!-- 操作按钮 --> | |||
<div class="ele-table-tool ele-table-tool-default"> | |||
<el-button @click="showEdit=true" type="primary" icon="el-icon-plus" class="ele-btn-icon" size="small" v-if="permission.includes('sys:${entityName?lower_case}:add')">添加 | |||
</el-button> | |||
<el-button @click="remove()" type="danger" icon="el-icon-delete" class="ele-btn-icon" size="small" v-if="permission.includes('sys:${entityName?lower_case}:dall')">批量删除 | |||
</el-button> | |||
</div> | |||
<!-- 数据表格 --> | |||
<ele-data-table ref="table" :config="table" :choose.sync="choose" height="calc(100vh - 315px)" highlight-current-row> | |||
<template slot-scope="{index}"> | |||
<el-table-column type="selection" width="45" align="center" fixed="left"/> | |||
<el-table-column type="index" :index="index" label="编号" width="60" align="center" fixed="left" show-overflow-tooltip/> | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.changeColumnName?uncap_first != 'createUser' && model.changeColumnName?uncap_first != 'updateUser' && model.changeColumnName?uncap_first != 'mark'> | |||
<#if (model.columnType = 'DATETIME' || model.columnType = 'DATE' || model.columnType = 'TIME' || model.columnType = 'YEAR' || model.columnType = 'TIMESTAMP')> | |||
<el-table-column label="${model.columnComment}" align="center" show-overflow-tooltip min-width="160"> | |||
<template slot-scope="{row}">{{ row.${model.changeColumnName?uncap_first} | toDateString }}</template> | |||
</el-table-column> | |||
<#elseif model.hasColumnCommentValue = true> | |||
<#if model.columnSwitch == true> | |||
<el-table-column prop="${model.columnName}" label="${model.columnCommentName}" align="center" :resizable="false" min-width="120"> | |||
<template slot-scope="{row}"> | |||
<el-switch v-model="row.${model.columnName}" @change="set${model.changeColumnName?cap_first}(row)" :active-value="1" :inactive-value="2"/> | |||
</template> | |||
</el-table-column> | |||
<#else> | |||
<el-table-column prop="${model.changeColumnName?uncap_first}" label="${model.columnCommentName}" align="center" min-width="100"> | |||
<template slot-scope="{row}"> | |||
<ele-dot :type="['success', 'danger', 'primary', 'warning', 'info'][row.${model.changeColumnName?uncap_first}-1]" :ripple="row.${model.changeColumnName?uncap_first}===0" | |||
:text="[${model.columnValue}][row.${model.changeColumnName?uncap_first}-1]"/> | |||
</template> | |||
</el-table-column> | |||
</#if> | |||
<#elseif model.columnImage == true> | |||
<el-table-column label="${model.columnComment}" min-width="60" align="center"> | |||
<template slot-scope="{row}"> | |||
<el-avatar shape="square" :size="35" :src="row.${model.changeColumnName?uncap_first}"/> | |||
</template> | |||
</el-table-column> | |||
<#else> | |||
<el-table-column prop="${model.changeColumnName?uncap_first}" label="${model.columnComment}" align="center" show-overflow-tooltip min-width="200"/> | |||
</#if> | |||
</#if> | |||
</#list> | |||
</#if> | |||
<el-table-column label="操作" width="130px" align="center" :resizable="false" fixed="right"> | |||
<template slot-scope="{row}"> | |||
<el-link @click="edit(row)" icon="el-icon-edit" type="primary" :underline="false" v-if="permission.includes('sys:${entityName?lower_case}:edit')">修改</el-link> | |||
<el-popconfirm title="确定要删除此${tableAnnotation}吗?" @confirm="remove(row)" class="ele-action"> | |||
<el-link slot="reference" icon="el-icon-delete" type="danger" :underline="false" v-if="permission.includes('sys:${entityName?lower_case}:delete')">删除</el-link> | |||
</el-popconfirm> | |||
</template> | |||
</el-table-column> | |||
</template> | |||
</ele-data-table> | |||
</el-card> | |||
<!-- 编辑弹窗 --> | |||
<el-dialog :title="editForm.id?'修改${tableAnnotation}':'修改${tableAnnotation}'" :visible.sync="showEdit" width="400px" | |||
@closed="editForm={}" :destroy-on-close="true" :lock-scroll="false"> | |||
<el-form :model="editForm" ref="editForm" :rules="editRules" label-width="82px"> | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.changeColumnName?uncap_first != "createUser" && model.changeColumnName?uncap_first != "createTime" && model.changeColumnName?uncap_first != "updateUser" && model.changeColumnName?uncap_first != "updateTime" && model.changeColumnName?uncap_first != "mark"> | |||
<#if (model.columnType = 'VARCHAR' || model.columnType = 'CHAR' || model.columnType = 'TEXT' || model.columnType = 'MEDIUMTEXT')> | |||
<#if model.columnImage == true> | |||
<el-form-item label="${model.columnComment}:"> | |||
<uploadImage :limit="1" :updDir="updDir" v-model="editForm.${model.changeColumnName?uncap_first}"></uploadImage> | |||
</el-form-item> | |||
<#elseif model.columnTextArea == true> | |||
<el-form-item label="${model.columnComment}:"> | |||
<el-input v-model="editForm.${model.columnName}" placeholder="请输入${model.columnComment}" :rows="3" type="textarea"/> | |||
</el-form-item> | |||
<#else> | |||
<el-form-item label="${model.columnComment}:" prop="${model.columnName}"> | |||
<el-input v-model="editForm.${model.columnName}" placeholder="请输入${model.columnComment}" clearable/> | |||
</el-form-item> | |||
</#if> | |||
</#if> | |||
<#if (model.columnType = 'DATETIME' || model.columnType = 'DATE' || model.columnType = 'TIME' || model.columnType = 'YEAR' || model.columnType = 'TIMESTAMP') > | |||
<el-form-item label="${model.columnComment}:" prop="${model.columnName}"> | |||
<el-date-picker | |||
v-model="editForm.${model.columnName}" | |||
type="datetime" | |||
placeholder="选择${model.columnComment}" | |||
size="small" | |||
value-format="yyyy-MM-dd HH:mm:ss" | |||
format="yyyy-MM-dd HH:mm:ss"> | |||
</el-date-picker> | |||
</el-form-item> | |||
</#if> | |||
<#if (model.columnType = 'TINYINT UNSIGNED' || model.columnType = 'TINYINT')> | |||
<#if model.columnSwitch == true> | |||
<el-form-item label="${model.columnCommentName}:"> | |||
<el-radio-group v-model="editForm.${model.columnName}"> | |||
<#if model.columnCommentValue?exists> | |||
<#list model.columnCommentValue?keys as key> | |||
<el-radio :label="${key}">${model.columnCommentValue[key]}</el-radio> | |||
</#list> | |||
</#if> | |||
</el-radio-group> | |||
</el-form-item> | |||
<#else> | |||
<el-form-item label="${model.columnCommentName}:" prop="${model.columnName}"> | |||
<el-select v-model="editForm.${model.columnName}" placeholder="请选择${model.columnCommentName}" class="ele-block" clearable> | |||
<#if model.columnCommentValue?exists> | |||
<#list model.columnCommentValue?keys as key> | |||
<el-option label="${model.columnCommentValue[key]}" :value="${key}"/> | |||
</#list> | |||
</#if> | |||
</el-select> | |||
</el-form-item> | |||
</#if> | |||
</#if> | |||
<#if (model.columnType = 'INT UNSIGNED' || model.columnType = 'INT' || model.columnType = 'SMALLINT UNSIGNED' || model.columnType = 'SMALLINT' || model.columnType = 'BIGINT UNSIGNED' || model.columnType = 'BIGINT' || model.columnType = 'MEDIUMINT UNSIGNED' || model.columnType = 'MEDIUMINT')> | |||
<#if model.hasColumnCommentValue = true> | |||
<el-form-item label="${model.columnCommentName}:" prop="${model.columnName}"> | |||
<el-select v-model="editForm.${model.columnName}" placeholder="请选择${model.columnCommentName}" class="ele-block" clearable> | |||
<#if model.columnCommentValue?exists> | |||
<#list model.columnCommentValue?keys as key> | |||
<el-option label="${model.columnCommentValue[key]}" :value="${key}"/> | |||
</#list> | |||
</#if> | |||
</el-select> | |||
</el-form-item> | |||
<#else> | |||
<el-form-item label="${model.columnComment}:" prop="${model.columnName}"> | |||
<el-input-number v-model="editForm.${model.columnName}" controls-position="right" :min="0" | |||
placeholder="请输入${model.columnComment}" class="ele-fluid ele-text-left"/> | |||
</el-form-item> | |||
</#if> | |||
</#if> | |||
</#if> | |||
</#list> | |||
</#if> | |||
</el-form> | |||
<div slot="footer"> | |||
<el-button @click="showEdit=false">取消</el-button> | |||
<el-button type="primary" @click="save">保存</el-button> | |||
</div> | |||
</el-dialog> | |||
</div> | |||
</template> | |||
<script> | |||
import { mapGetters } from "vuex"; | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.columnImage == true> | |||
import uploadImage from '@/components/uploadImage' | |||
</#if> | |||
</#list> | |||
</#if> | |||
export default { | |||
name: "Sys${entityName}", | |||
data() { | |||
return { | |||
table: {url: '/${entityName?lower_case}/index', where: {}}, // 表格配置 | |||
choose: [], // 表格选中数据 | |||
showEdit: false, // 是否显示表单弹窗 | |||
editForm: {}, // 表单数据 | |||
editRules: { // 表单验证规则 | |||
}, | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.columnImage == true> | |||
updDir: '${entityName?lower_case}', | |||
</#if> | |||
</#list> | |||
</#if> | |||
} | |||
}, | |||
computed: { | |||
...mapGetters(["permission"]), | |||
}, | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.columnImage == true> | |||
components: {uploadImage}, | |||
</#if> | |||
</#list> | |||
</#if> | |||
mounted() { | |||
}, | |||
methods: { | |||
/* 显示编辑 */ | |||
edit(row) { | |||
this.$http.get('/${entityName?lower_case}/info/' + row.id).then(res => { | |||
if (res.data.code === 0) { | |||
this.editForm = res.data.data; | |||
this.showEdit = true; | |||
} else { | |||
this.$message.error(res.data.msg); | |||
} | |||
}).catch(e => { | |||
this.$message.error(e.message); | |||
}); | |||
}, | |||
/* 保存编辑 */ | |||
save() { | |||
this.$refs['editForm'].validate((valid) => { | |||
if (valid) { | |||
const loading = this.$loading({lock: true}); | |||
this.$http[this.editForm.id ? 'put' : 'post'](this.editForm.id ? '/${entityName?lower_case}/edit' : '/${entityName?lower_case}/add', this.editForm).then(res => { | |||
loading.close(); | |||
if (res.data.code === 0) { | |||
this.showEdit = false; | |||
this.$message({type: 'success', message: res.data.msg}); | |||
this.$refs.table.reload(); | |||
} else { | |||
this.$message.error(res.data.msg); | |||
} | |||
}).catch(e => { | |||
loading.close(); | |||
this.$message.error(e.message); | |||
}); | |||
} else { | |||
return false; | |||
} | |||
}); | |||
}, | |||
/* 删除 */ | |||
remove(row) { | |||
if (!row) { // 批量删除 | |||
if (this.choose.length === 0) return this.$message.error('请至少选择一条数据'); | |||
let ids = this.choose.map(d => d.id); | |||
this.$confirm('确定要删除选中的${tableAnnotation}吗?', '提示', {type: 'warning'}).then(() => { | |||
const loading = this.$loading({lock: true}); | |||
this.$http.delete('/${entityName?lower_case}/delete/' + ids).then(res => { | |||
loading.close(); | |||
if (res.data.code === 0) { | |||
this.$message({type: 'success', message: res.data.msg}); | |||
this.$refs.table.reload(); | |||
} else { | |||
this.$message.error(res.data.msg); | |||
} | |||
}).catch(e => { | |||
loading.close(); | |||
this.$message.error(e.message); | |||
}); | |||
}).catch(() => 0); | |||
} else { // 单个删除 | |||
const loading = this.$loading({lock: true}); | |||
this.$http.delete('/${entityName?lower_case}/delete/' + [row.id]).then(res => { | |||
loading.close(); | |||
if (res.data.code === 0) { | |||
this.$message({type: 'success', message: res.data.msg}); | |||
this.$refs.table.reload(); | |||
} else { | |||
this.$message.error(res.data.msg); | |||
} | |||
}).catch(e => { | |||
loading.close(); | |||
this.$message.error(e.message); | |||
}); | |||
} | |||
}, | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.columnSwitch == true> | |||
/* 更改状态 */ | |||
set${model.changeColumnName?cap_first}(row) { | |||
const loading = this.$loading({lock: true}); | |||
//let params = new FormData(); | |||
// params.append('status', row.status); | |||
let params = {"id":row.id, '${model.changeColumnName?uncap_first}': row.${model.changeColumnName?uncap_first}}; | |||
this.$http.put('/${entityName?lower_case}/set${model.changeColumnName?cap_first}', params).then(res => { | |||
loading.close(); | |||
if (res.data.code === 0) { | |||
this.$message({type: 'success', message: res.data.msg}); | |||
} else { | |||
this.$message.error(res.data.msg); | |||
} | |||
}).catch(e => { | |||
loading.close(); | |||
this.$message.error(e.message); | |||
}); | |||
}, | |||
</#if> | |||
</#list> | |||
</#if> | |||
} | |||
} | |||
</script> | |||
<style scoped> | |||
.ele-block >>> .el-upload, .ele-block >>> .el-upload-dragger { | |||
width: 100%; | |||
} | |||
</style> |
@@ -1,5 +0,0 @@ | |||
<?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="${packageName}.mapper.${entityName}Mapper"> | |||
</mapper> |
@@ -1,56 +0,0 @@ | |||
package ${packageName}.query; | |||
import BaseQuery; | |||
import lombok.Data; | |||
/** | |||
* <p> | |||
* ${tableAnnotation}查询条件 | |||
* </p> | |||
* | |||
* @author ${author} | |||
* @since ${date} | |||
*/ | |||
@Data | |||
public class ${entityName}Query extends BaseQuery { | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.columnName = 'name'> | |||
/** | |||
* ${model.columnComment!} | |||
*/ | |||
private String ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if model.columnName = 'title'> | |||
/** | |||
* ${model.columnComment!} | |||
*/ | |||
private String ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if model.columnName = 'mobile'> | |||
/** | |||
* ${model.columnComment!} | |||
*/ | |||
private String ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if model.columnName = 'type'> | |||
/** | |||
* ${model.columnComment!} | |||
*/ | |||
private Integer ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
<#if model.columnName = 'status'> | |||
/** | |||
* ${model.columnComment!} | |||
*/ | |||
private Integer ${model.changeColumnName?uncap_first}; | |||
</#if> | |||
</#list> | |||
</#if> | |||
} |
@@ -1,248 +0,0 @@ | |||
package ${packageName}.service.impl; | |||
import cn.hutool.core.convert.Convert; | |||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import CommonConfig; | |||
import CommonUtils; | |||
import BaseQuery; | |||
import BaseServiceImpl; | |||
import ${packageName}.constant.${entityName}Constant; | |||
import ${packageName}.entity.${entityName}; | |||
import ${packageName}.mapper.${entityName}Mapper; | |||
import ${packageName}.query.${entityName}Query; | |||
import ${packageName}.service.I${entityName}Service; | |||
import ShiroUtils; | |||
import ${packageName}.vo.${entityName?lower_case}.${entityName}InfoVo; | |||
import ${packageName}.vo.${entityName?lower_case}.${entityName}ListVo; | |||
import DateUtils; | |||
import JsonResult; | |||
import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.util.StringUtils; | |||
import java.io.Serializable; | |||
import java.util.*; | |||
/** | |||
* <p> | |||
* ${tableAnnotation} 服务类实现 | |||
* </p> | |||
* | |||
* @author ${author} | |||
* @since ${date} | |||
*/ | |||
@Service | |||
public class ${entityName}ServiceImpl extends BaseServiceImpl<${entityName}Mapper, ${entityName}> implements I${entityName}Service { | |||
@Autowired | |||
private ${entityName}Mapper ${entityName?uncap_first}Mapper; | |||
/** | |||
* 获取数据列表 | |||
* | |||
* @param query 查询条件 | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult getList(BaseQuery query) { | |||
${entityName}Query ${entityName?uncap_first}Query = (${entityName}Query) query; | |||
// 查询条件 | |||
QueryWrapper<${entityName}> queryWrapper = new QueryWrapper<>(); | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.columnName = 'name'> | |||
// ${model.columnComment!} | |||
if (!StringUtils.isEmpty(${entityName?uncap_first}Query.getName())) { | |||
queryWrapper.like("name", ${entityName?uncap_first}Query.getName()); | |||
} | |||
</#if> | |||
<#if model.columnName = 'title'> | |||
// ${model.columnComment!} | |||
if (!StringUtils.isEmpty(${entityName?uncap_first}Query.getTitle())) { | |||
queryWrapper.like("title", ${entityName?uncap_first}Query.getTitle()); | |||
} | |||
</#if> | |||
<#if model.columnName = 'mobile'> | |||
// ${model.columnComment!} | |||
if (!StringUtils.isEmpty(${entityName?uncap_first}Query.getMobile())) { | |||
queryWrapper.like("mobile", ${entityName?uncap_first}Query.getMobile()); | |||
} | |||
</#if> | |||
<#if model.columnName = 'type'> | |||
// ${model.columnComment!} | |||
if (!StringUtils.isEmpty(${entityName?uncap_first}Query.getType())) { | |||
queryWrapper.eq("type", ${entityName?uncap_first}Query.getType()); | |||
} | |||
</#if> | |||
<#if model.columnName = 'status'> | |||
// ${model.columnComment!} | |||
if (!StringUtils.isEmpty(${entityName?uncap_first}Query.getStatus())) { | |||
queryWrapper.eq("status", ${entityName?uncap_first}Query.getStatus()); | |||
} | |||
</#if> | |||
</#list> | |||
</#if> | |||
queryWrapper.eq("mark", 1); | |||
queryWrapper.orderByDesc("id"); | |||
// 获取数据列表 | |||
IPage<${entityName}> page = new Page<>(${entityName?uncap_first}Query.getPage(), ${entityName?uncap_first}Query.getLimit()); | |||
IPage<${entityName}> pageData = ${entityName?uncap_first}Mapper.selectPage(page, queryWrapper); | |||
pageData.convert(x -> { | |||
${entityName}ListVo ${entityName?uncap_first}ListVo = Convert.convert(${entityName}ListVo.class, x); | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.hasColumnCommentValue = true> | |||
// ${model.columnCommentName}描述 | |||
<#if model.columnNumberValue = true> | |||
if (${entityName?uncap_first}ListVo.get${model.changeColumnName}() != null && ${entityName?uncap_first}ListVo.get${model.changeColumnName}() > 0) { | |||
${entityName?uncap_first}ListVo.set${model.changeColumnName}Name(${entityName}Constant.${entityName?upper_case}_${model.changeColumnName?upper_case}_LIST.get(${entityName?uncap_first}ListVo.get${model.changeColumnName}())); | |||
} | |||
<#else> | |||
if (!StringUtils.isEmpty(${entityName?uncap_first}ListVo.get${model.changeColumnName}())) { | |||
${entityName?uncap_first}ListVo.set${model.changeColumnName}Name(${entityName}Constant.${entityName?upper_case}_${model.changeColumnName?upper_case}_LIST.get(${entityName?uncap_first}ListVo.get${model.changeColumnName}())); | |||
} | |||
</#if> | |||
</#if> | |||
<#if model.columnImage == true> | |||
// ${model.columnComment}地址 | |||
if (!StringUtils.isEmpty(${entityName?uncap_first}ListVo.get${model.changeColumnName}())) { | |||
${entityName?uncap_first}ListVo.set${model.changeColumnName}(CommonUtils.getImageURL(${entityName?uncap_first}ListVo.get${model.changeColumnName}())); | |||
} | |||
</#if> | |||
</#list> | |||
</#if> | |||
return ${entityName?uncap_first}ListVo; | |||
}); | |||
return JsonResult.success(pageData); | |||
} | |||
/** | |||
* 获取详情Vo | |||
* | |||
* @param id 记录ID | |||
* @return | |||
*/ | |||
@Override | |||
public Object getInfo(Serializable id) { | |||
${entityName} entity = (${entityName}) super.getInfo(id); | |||
// 返回视图Vo | |||
${entityName}InfoVo ${entityName?uncap_first}InfoVo = new ${entityName}InfoVo(); | |||
// 拷贝属性 | |||
BeanUtils.copyProperties(entity, ${entityName?uncap_first}InfoVo); | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.columnImage == true> | |||
// ${model.columnComment} | |||
if (!StringUtils.isEmpty(${entityName?uncap_first}InfoVo.get${model.changeColumnName}())) { | |||
${entityName?uncap_first}InfoVo.set${model.changeColumnName}(CommonUtils.getImageURL(${entityName?uncap_first}InfoVo.get${model.changeColumnName}())); | |||
} | |||
</#if> | |||
</#list> | |||
</#if> | |||
return ${entityName?uncap_first}InfoVo; | |||
} | |||
/** | |||
* 添加、更新记录 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult edit(${entityName} entity) { | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.columnImage == true> | |||
// ${model.columnComment} | |||
if (entity.get${model.changeColumnName}().contains(CommonConfig.imageURL)) { | |||
entity.set${model.changeColumnName}(entity.get${model.changeColumnName}().replaceAll(CommonConfig.imageURL, "")); | |||
} | |||
</#if> | |||
</#list> | |||
</#if> | |||
if (entity.getId() != null && entity.getId() > 0) { | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.changeColumnName?uncap_first = 'updateUser'> | |||
entity.setUpdateUser(1); | |||
</#if> | |||
<#if model.changeColumnName?uncap_first = 'updateTime'> | |||
entity.setUpdateTime(DateUtils.now()); | |||
</#if> | |||
</#list> | |||
</#if> | |||
} else { | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.changeColumnName?uncap_first = 'createUser'> | |||
entity.setCreateUser(1); | |||
</#if> | |||
<#if model.changeColumnName?uncap_first = 'createTime'> | |||
entity.setCreateTime(DateUtils.now()); | |||
</#if> | |||
</#list> | |||
</#if> | |||
} | |||
return super.edit(entity); | |||
} | |||
/** | |||
* 删除记录 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult delete(${entityName} entity) { | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.changeColumnName?uncap_first = 'updateUser'> | |||
entity.setUpdateUser(1); | |||
</#if> | |||
<#if model.changeColumnName?uncap_first = 'updateTime'> | |||
entity.setUpdateTime(DateUtils.now()); | |||
</#if> | |||
</#list> | |||
</#if> | |||
entity.setMark(0); | |||
return super.delete(entity); | |||
} | |||
<#if model_column?exists> | |||
<#list model_column as model> | |||
<#if model.columnSwitch == true> | |||
/** | |||
* 设置${model.columnCommentName} | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult set${model.changeColumnName?cap_first}(${entityName} entity) { | |||
if (entity.getId() == null || entity.getId() <= 0) { | |||
return JsonResult.error("记录ID不能为空"); | |||
} | |||
if (entity.get${model.changeColumnName?cap_first}() == null) { | |||
return JsonResult.error("记录${model.columnCommentName}不能为空"); | |||
} | |||
<#if model.changeColumnName?uncap_first = 'status'> | |||
return super.set${model.changeColumnName?cap_first}(entity); | |||
<#else> | |||
entity.setUpdateUser(ShiroUtils.getUserId()); | |||
entity.setUpdateTime(DateUtils.now()); | |||
boolean result = this.updateById(entity); | |||
if (!result) { | |||
return JsonResult.error(); | |||
} | |||
return JsonResult.success(); | |||
</#if> | |||
} | |||
</#if> | |||
</#list> | |||
</#if> | |||
} |
@@ -45,6 +45,10 @@ | |||
<artifactId>druid-spring-boot-starter</artifactId> | |||
<version>1.1.10</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.hibernate.validator</groupId> | |||
<artifactId>hibernate-validator</artifactId> | |||
</dependency> | |||
</dependencies> | |||
</project> |
@@ -1,188 +0,0 @@ | |||
package com.tuoheng.system.aspect; | |||
import com.alibaba.fastjson.JSON; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.enums.LogStatus; | |||
import com.tuoheng.common.utils.IpUtils; | |||
import com.tuoheng.common.utils.ServletUtils; | |||
import com.tuoheng.common.utils.StringUtils; | |||
import com.tuoheng.system.entity.OperLog; | |||
import com.tuoheng.system.entity.User; | |||
import com.tuoheng.system.manager.AsyncFactory; | |||
import com.tuoheng.system.manager.AsyncManager; | |||
import com.tuoheng.system.utils.ShiroUtils; | |||
import org.aspectj.lang.JoinPoint; | |||
import org.aspectj.lang.Signature; | |||
import org.aspectj.lang.annotation.AfterReturning; | |||
import org.aspectj.lang.annotation.AfterThrowing; | |||
import org.aspectj.lang.annotation.Aspect; | |||
import org.aspectj.lang.annotation.Pointcut; | |||
import org.aspectj.lang.reflect.MethodSignature; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.http.HttpMethod; | |||
import org.springframework.stereotype.Component; | |||
import org.springframework.web.multipart.MultipartFile; | |||
import org.springframework.web.servlet.HandlerMapping; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
import java.lang.reflect.Method; | |||
import java.util.Map; | |||
/** | |||
* 自定义操作日志切面处理类 | |||
*/ | |||
@Aspect | |||
@Component | |||
public class LogAspect { | |||
private static final Logger log = LoggerFactory.getLogger(LogAspect.class); | |||
// 配置织入点 | |||
@Pointcut("@annotation(com.tuoheng.common.annotation.Log)") | |||
public void logPointCut() { | |||
} | |||
/** | |||
* 处理完请求后执行 | |||
* | |||
* @param joinPoint 切点 | |||
*/ | |||
@AfterReturning(pointcut = "logPointCut()", returning = "jsonResult") | |||
public void doAfterReturning(JoinPoint joinPoint, Object jsonResult) { | |||
handleLog(joinPoint, null, jsonResult); | |||
} | |||
/** | |||
* 拦截异常操作 | |||
* | |||
* @param joinPoint 切点 | |||
* @param e 异常 | |||
*/ | |||
@AfterThrowing(value = "logPointCut()", throwing = "e") | |||
public void doAfterThrowing(JoinPoint joinPoint, Exception e) { | |||
handleLog(joinPoint, e, null); | |||
} | |||
protected void handleLog(final JoinPoint joinPoint, final Exception e, Object jsonResult) { | |||
try { | |||
// 获得注解 | |||
Log controllerLog = getAnnotationLog(joinPoint); | |||
if (controllerLog == null) { | |||
return; | |||
} | |||
// *========数据库日志=========*// | |||
OperLog operLog = new OperLog(); | |||
User user = ShiroUtils.getUserInfo(); | |||
operLog.setOperName(StringUtils.isNull(user) ? "系统异常" : user.getUsername()); | |||
operLog.setTenantId(StringUtils.isNull(user) ? -1 : user.getTenantId()); | |||
operLog.setStatus(LogStatus.SUCCESS.ordinal()); | |||
// 请求的地址 | |||
String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); | |||
operLog.setOperIp(ip); | |||
// 返回参数 | |||
operLog.setJsonResult(JSON.toJSONString(jsonResult)); | |||
operLog.setOperUrl(ServletUtils.getRequest().getRequestURI()); | |||
if (e != null) { | |||
operLog.setStatus(LogStatus.FAIL.ordinal()); | |||
operLog.setNote(StringUtils.substring(e.getMessage(), 0, 2000)); | |||
} | |||
// 设置方法名称 | |||
String className = joinPoint.getTarget().getClass().getName(); | |||
String methodName = joinPoint.getSignature().getName(); | |||
operLog.setOperMethod(className + "." + methodName + "()"); | |||
// 设置请求方式 | |||
operLog.setRequestMethod(ServletUtils.getRequest().getMethod()); | |||
// 处理设置注解上的参数 | |||
getControllerMethodDescription(joinPoint, controllerLog, operLog); | |||
// 保存数据库 | |||
AsyncManager.me().execute(AsyncFactory.recordOper(operLog)); | |||
} catch (Exception exp) { | |||
// 记录本地异常日志 | |||
log.error("==前置通知异常=="); | |||
log.error("异常信息:{}", exp.getMessage()); | |||
exp.printStackTrace(); | |||
} | |||
} | |||
/** | |||
* 获取注解中对方法的描述信息 用于Controller层注解 | |||
* | |||
* @param log 日志 | |||
* @param operLog 操作日志 | |||
* @throws Exception | |||
*/ | |||
public void getControllerMethodDescription(JoinPoint joinPoint, Log log, OperLog operLog) throws Exception { | |||
// 设置action动作 | |||
operLog.setLogType(log.logType().ordinal()); | |||
// 设置标题 | |||
operLog.setTitle(log.title()); | |||
// 设置操作人类别 | |||
operLog.setOperType(log.operType().ordinal()); | |||
// 是否需要保存request,参数和值 | |||
if (log.isSaveRequestData()) { | |||
// 获取参数的信息,传入到数据库中。 | |||
setRequestValue(joinPoint, operLog); | |||
} | |||
} | |||
/** | |||
* 获取请求的参数,放到log中 | |||
* | |||
* @param operLog 操作日志 | |||
* @throws Exception 异常 | |||
*/ | |||
private void setRequestValue(JoinPoint joinPoint, OperLog operLog) throws Exception { | |||
String requestMethod = operLog.getRequestMethod(); | |||
if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) { | |||
String params = argsArrayToString(joinPoint.getArgs()); | |||
operLog.setOperParam(StringUtils.substring(params, 0, 2000)); | |||
} else { | |||
Map<?, ?> paramsMap = (Map<?, ?>) ServletUtils.getRequest().getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); | |||
operLog.setOperParam(StringUtils.substring(paramsMap.toString(), 0, 2000)); | |||
} | |||
} | |||
/** | |||
* 是否存在注解,如果存在就获取 | |||
*/ | |||
private Log getAnnotationLog(JoinPoint joinPoint) throws Exception { | |||
Signature signature = joinPoint.getSignature(); | |||
MethodSignature methodSignature = (MethodSignature) signature; | |||
Method method = methodSignature.getMethod(); | |||
if (method != null) { | |||
return method.getAnnotation(Log.class); | |||
} | |||
return null; | |||
} | |||
/** | |||
* 参数拼装 | |||
*/ | |||
private String argsArrayToString(Object[] paramsArray) { | |||
String params = ""; | |||
if (paramsArray != null && paramsArray.length > 0) { | |||
for (int i = 0; i < paramsArray.length; i++) { | |||
if (!isFilterObject(paramsArray[i])) { | |||
Object jsonObj = JSON.toJSON(paramsArray[i]); | |||
params += jsonObj.toString() + " "; | |||
} | |||
} | |||
} | |||
return params.trim(); | |||
} | |||
/** | |||
* 判断是否需要过滤的对象。 | |||
* | |||
* @param o 对象信息。 | |||
* @return 如果是需要过滤的对象,则返回true;否则返回false。 | |||
*/ | |||
public boolean isFilterObject(final Object o) { | |||
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse; | |||
} | |||
} |
@@ -1,310 +0,0 @@ | |||
package com.tuoheng.system.config; | |||
import com.tuoheng.common.utils.StringUtils; | |||
import com.tuoheng.system.filter.KickoutSessionFilter; | |||
import com.tuoheng.system.filter.ShiroLoginFilter; | |||
import com.tuoheng.system.filter.ShiroLogoutFilter; | |||
import com.tuoheng.system.shiro.CustomCredentialsMatcher; | |||
import com.tuoheng.system.shiro.MySessionManager; | |||
import com.tuoheng.system.shiro.MyShiroRealm; | |||
import lombok.Data; | |||
import org.apache.shiro.authc.credential.HashedCredentialsMatcher; | |||
import org.apache.shiro.codec.Base64; | |||
import org.apache.shiro.mgt.SecurityManager; | |||
import org.apache.shiro.session.mgt.SessionManager; | |||
import org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator; | |||
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; | |||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; | |||
import org.apache.shiro.web.mgt.CookieRememberMeManager; | |||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager; | |||
import org.apache.shiro.web.servlet.SimpleCookie; | |||
import org.crazycake.shiro.RedisCacheManager; | |||
import org.crazycake.shiro.RedisManager; | |||
import org.crazycake.shiro.RedisSessionDAO; | |||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; | |||
import org.springframework.beans.factory.annotation.Value; | |||
import org.springframework.context.annotation.Bean; | |||
import org.springframework.context.annotation.Configuration; | |||
import redis.clients.jedis.JedisPool; | |||
import javax.servlet.Filter; | |||
import java.util.LinkedHashMap; | |||
import java.util.Map; | |||
/** | |||
* Shiro配置类 | |||
*/ | |||
@Configuration | |||
//@PropertySource("classpath:redis.properties") | |||
@Data | |||
public class ShiroConfig { | |||
private final String CACHE_KEY = "shiro:cache:"; | |||
private final String SESSION_KEY = "shiro:session:"; | |||
private Integer EXPIRE = 86400 * 7; | |||
@Value("${spring.redis.host}") | |||
private String host; | |||
@Value("${spring.redis.port}") | |||
private Integer port; | |||
@Value("${spring.redis.password}") | |||
private String password; | |||
@Value("${spring.redis.timeout}") | |||
private Integer timeout; | |||
@Value("${shiro.kickoutAfter}") | |||
private boolean kickoutAfter; | |||
@Value("${shiro.maxSession}") | |||
private Integer maxSession; | |||
@Bean | |||
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) { | |||
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); | |||
shiroFilterFactoryBean.setSecurityManager(securityManager); | |||
// 过滤器链定义映射 | |||
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>(); | |||
/* | |||
* anon:所有url都都可以匿名访问,authc:所有url都必须认证通过才可以访问; | |||
* 过滤链定义,从上向下顺序执行,authc 应放在 anon 下面 | |||
* */ | |||
filterChainDefinitionMap.put("/**/**", "anon"); | |||
filterChainDefinitionMap.put("/common/**", "anon"); | |||
filterChainDefinitionMap.put("/login/**", "anon"); | |||
filterChainDefinitionMap.put("/webSocket/**", "anon"); | |||
filterChainDefinitionMap.put("/druid/**", "anon"); | |||
// 配置不会被拦截的链接 顺序判断,因为前端模板采用了thymeleaf,这里不能直接使用 ("/static/**", "anon")来配置匿名访问,必须配置到每个静态目录 | |||
filterChainDefinitionMap.put("/css/**", "anon"); | |||
filterChainDefinitionMap.put("/fonts/**", "anon"); | |||
filterChainDefinitionMap.put("/img/**", "anon"); | |||
filterChainDefinitionMap.put("/js/**", "anon"); | |||
filterChainDefinitionMap.put("/html/**", "anon"); | |||
filterChainDefinitionMap.put("/images/**", "anon"); | |||
//swagger接口权限 开放 | |||
filterChainDefinitionMap.put("/swagger-ui.html", "anon"); | |||
filterChainDefinitionMap.put("/swagger/**", "anon"); | |||
filterChainDefinitionMap.put("/webjars/**", "anon"); | |||
filterChainDefinitionMap.put("/swagger-resources/**", "anon"); | |||
filterChainDefinitionMap.put("/v2/**", "anon"); | |||
filterChainDefinitionMap.put("/doc.html", "anon"); | |||
filterChainDefinitionMap.put("/airportInterface/**", "anon"); | |||
//生成唯一序列号放白名单 | |||
filterChainDefinitionMap.put("/dronecode/generate", "anon"); | |||
//文件上传 | |||
filterChainDefinitionMap.put("/oss/uploadFile", "anon"); | |||
filterChainDefinitionMap.put("/health/**", "anon"); | |||
// 所有url都必须认证通过才可以访问 | |||
filterChainDefinitionMap.put("/**", "anon"); | |||
// 配置退出 过滤器,其中的具体的退出代码Shiro已经替我们实现了, 位置放在 anon、authc下面 | |||
filterChainDefinitionMap.put("/login/logout", "logout"); | |||
// 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面 | |||
// 配器shirot认登录累面地址,前后端分离中登录累面跳转应由前端路由控制,后台仅返回json数据, 对应LoginController中unauth请求 | |||
shiroFilterFactoryBean.setLoginUrl("/login/un_auth"); | |||
Map<String, Filter> filters = shiroFilterFactoryBean.getFilters(); | |||
//自定义过滤器 | |||
filters.put("kickout",kickoutSessionFilter()); | |||
shiroFilterFactoryBean.setFilters(filters); | |||
filterChainDefinitionMap.put("/**","kickout,authc"); | |||
filters.put("authc", new ShiroLoginFilter()); | |||
// 退出过滤器 | |||
filters.put("logout", logoutFilter()); | |||
// shiroFilterFactoryBean.setFilters(filters); | |||
// 登录成功后要跳转的链接, 此项目是前后端分离,故此行注释掉,登录成功之后返回用户基本信息及token给前端 | |||
// shiroFilterFactoryBean.setSuccessUrl("/index"); | |||
// 未授权界面, 对应LoginController中 unauthorized 请求 | |||
shiroFilterFactoryBean.setUnauthorizedUrl("/login/unauthorized"); | |||
// // 自动跳去登录的地址 | |||
// shiroFilterFactoryBean.setLoginUrl("/login"); | |||
// // 未授权页面 | |||
// shiroFilterFactoryBean.setUnauthorizedUrl("/403"); | |||
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); | |||
return shiroFilterFactoryBean; | |||
} | |||
/** | |||
* 凭证匹配器(由于我们的密码校验交给Shiro的SimpleAuthenticationInfo进行处理了) | |||
* 下面调用了自定义的验证类 这个方法就没有了 | |||
* | |||
* @return | |||
*/ | |||
@Bean | |||
public HashedCredentialsMatcher hashedCredentialsMatcher() { | |||
HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher(); | |||
//散列算法:这里使用MD5算法 | |||
hashedCredentialsMatcher.setHashAlgorithmName("md5"); | |||
//散列的次数,比如散列两次,相当于md5(md5("")) | |||
hashedCredentialsMatcher.setHashIterations(1); | |||
return hashedCredentialsMatcher; | |||
} | |||
/** | |||
* 将自己的验证方式加入容器 | |||
* | |||
* @return | |||
*/ | |||
@Bean | |||
public MyShiroRealm myShiroRealm() { | |||
MyShiroRealm myShiroRealm = new MyShiroRealm(); | |||
myShiroRealm.setCredentialsMatcher(new CustomCredentialsMatcher()); | |||
return myShiroRealm; | |||
} | |||
/** | |||
* RedisSessionDAOI shiro sessionDao层的实现 通过redis,使用的是shiro-redis开源插件 | |||
* | |||
* @return | |||
*/ | |||
@Bean | |||
public RedisSessionDAO redisSessionDAO() { | |||
RedisSessionDAO redisSessionDAO = new RedisSessionDAO(); | |||
redisSessionDAO.setRedisManager(redisManager()); | |||
redisSessionDAO.setSessionIdGenerator(sessionIdGenerator()); | |||
redisSessionDAO.setKeyPrefix(SESSION_KEY); | |||
redisSessionDAO.setExpire(EXPIRE); | |||
return redisSessionDAO; | |||
} | |||
/** | |||
* Session ID生成器 | |||
* | |||
* @return | |||
*/ | |||
@Bean | |||
public JavaUuidSessionIdGenerator sessionIdGenerator() { | |||
return new JavaUuidSessionIdGenerator(); | |||
} | |||
/** | |||
* 自定义的sessionManager | |||
* | |||
* @return | |||
*/ | |||
@Bean | |||
public SessionManager sessionManager() { | |||
MySessionManager mySessionManager = new MySessionManager(); | |||
mySessionManager.setSessionDAO(redisSessionDAO()); | |||
mySessionManager.setGlobalSessionTimeout(86400000L); | |||
return mySessionManager; | |||
} | |||
/** | |||
* 配置shiro RedisManager,使用的是shiro-redis开源插件 | |||
* | |||
* @return | |||
*/ | |||
private RedisManager redisManager() { | |||
RedisManager redisManager = new RedisManager(); | |||
redisManager.setHost(host + ":" + port); | |||
//redisManager.setPort(port); | |||
redisManager.setTimeout(timeout); | |||
if (!StringUtils.isEmpty(password)) { | |||
redisManager.setPassword(password); | |||
} | |||
return redisManager; | |||
} | |||
/** | |||
* 缓存redis实现,使用的shiro-redis开源查看 | |||
* | |||
* @return | |||
*/ | |||
@Bean | |||
public RedisCacheManager cacheManager() { | |||
RedisCacheManager redisCacheManager = new RedisCacheManager(); | |||
redisCacheManager.setRedisManager(redisManager()); | |||
redisCacheManager.setKeyPrefix(CACHE_KEY); | |||
// 配置缓存的话要求放在session里面的实体类必须有个id标识 | |||
redisCacheManager.setPrincipalIdFieldName("id"); | |||
return redisCacheManager; | |||
} | |||
/** | |||
* 安全管理器,授权管理,配置主要是Realm的管理认证 | |||
* | |||
* @return | |||
*/ | |||
@Bean | |||
public SecurityManager securityManager() { | |||
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); | |||
// 自定义session管理 使用redis,将自定义的会话管理器注册到安全管理器中 | |||
securityManager.setSessionManager(sessionManager()); | |||
// 自定义缓存实现 使用redis,将自定义的redis缓存管理器注册到安全管理器中 | |||
securityManager.setCacheManager(cacheManager()); | |||
// 自定义Realm验证 | |||
securityManager.setRealm(myShiroRealm()); | |||
// 记住我 | |||
securityManager.setRememberMeManager(rememberMeManager()); | |||
return securityManager; | |||
} | |||
/** | |||
* 记住我 | |||
*/ | |||
public CookieRememberMeManager rememberMeManager() { | |||
CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager(); | |||
cookieRememberMeManager.setCookie(cookie()); | |||
cookieRememberMeManager.setCipherKey(Base64.decode("fCq+/xW488hMTCD+cmJ3aQ==")); | |||
return cookieRememberMeManager; | |||
} | |||
/** | |||
* 退出过滤器 | |||
* | |||
* @return | |||
*/ | |||
public ShiroLogoutFilter logoutFilter() { | |||
ShiroLogoutFilter logoutFilter = new ShiroLogoutFilter(); | |||
return logoutFilter; | |||
} | |||
/** | |||
* 开启Shiro的注解(如@RequiresRoles,//@RequiresPermissions),需借助SpringAOP扫描使用Shiro注解的类,并在必要时进行安全逻辑验证 | |||
* 配置以下两个bean(DefaultAdvisorAutoProxyCreator(可选)和AuthorizationAttributeSourceAdvisor)即可实现此功能 | |||
* | |||
* @return | |||
*/ | |||
@Bean | |||
public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator() { | |||
DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator(); | |||
advisorAutoProxyCreator.setProxyTargetClass(true); | |||
return advisorAutoProxyCreator; | |||
} | |||
@Bean | |||
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) { | |||
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor(); | |||
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager); | |||
return authorizationAttributeSourceAdvisor; | |||
} | |||
@Bean | |||
public SimpleCookie cookie() { | |||
//cookie的name,对应的默认是JSESSIONID | |||
SimpleCookie cookie = new SimpleCookie("SHARE_JSESSIONID"); | |||
cookie.setHttpOnly(true); | |||
//path 为/ 用于多个系统共享JSESSIONID | |||
cookie.setPath("/"); | |||
return cookie; | |||
} | |||
@Bean | |||
public KickoutSessionFilter kickoutSessionFilter(){ | |||
KickoutSessionFilter kickoutSessionFilter = new KickoutSessionFilter(); | |||
kickoutSessionFilter.setMaxSession(maxSession); | |||
kickoutSessionFilter.setKickoutUrl("/login?kickout=1"); | |||
kickoutSessionFilter.setKickoutBefore(kickoutAfter); | |||
kickoutSessionFilter.setSessionManager(sessionManager()); | |||
kickoutSessionFilter.setCacheManager(cacheManager()); | |||
return kickoutSessionFilter; | |||
} | |||
} |
@@ -1,95 +0,0 @@ | |||
package com.tuoheng.system.constant; | |||
public class Constants { | |||
/** | |||
* UTF-8 字符集 | |||
*/ | |||
public static final String UTF8 = "UTF-8"; | |||
/** | |||
* 通用成功标识 | |||
*/ | |||
public static final String SUCCESS = "0"; | |||
/** | |||
* 通用失败标识 | |||
*/ | |||
public static final String FAIL = "1"; | |||
/** | |||
* 登录成功 | |||
*/ | |||
public static final String LOGIN_SUCCESS = "Success"; | |||
/** | |||
* 注销 | |||
*/ | |||
public static final String LOGOUT = "Logout"; | |||
/** | |||
* 登录失败 | |||
*/ | |||
public static final String LOGIN_FAIL = "Error"; | |||
/** | |||
* 验证码 redis key | |||
*/ | |||
public static final String CAPTCHA_CODE_KEY = "captcha_codes:"; | |||
/** | |||
* 登录用户 redis key | |||
*/ | |||
public static final String LOGIN_TOKEN_KEY = "login_tokens:"; | |||
/** | |||
* 验证码有效期(分钟) | |||
*/ | |||
public static final Integer CAPTCHA_EXPIRATION = 2; | |||
/** | |||
* 令牌 | |||
*/ | |||
public static final String TOKEN = "token"; | |||
/** | |||
* 令牌前缀 | |||
*/ | |||
public static final String TOKEN_PREFIX = "Bearer "; | |||
/** | |||
* 令牌前缀 | |||
*/ | |||
public static final String LOGIN_USER_KEY = "login_user_key"; | |||
/** | |||
* 用户ID | |||
*/ | |||
public static final String JWT_USERID = "userid"; | |||
// /** | |||
// * 用户名称 | |||
// */ | |||
// public static final String JWT_USERNAME = Claims.SUBJECT; | |||
/** | |||
* 用户头像 | |||
*/ | |||
public static final String JWT_AVATAR = "avatar"; | |||
/** | |||
* 创建时间 | |||
*/ | |||
public static final String JWT_CREATED = "created"; | |||
/** | |||
* 用户权限 | |||
*/ | |||
public static final String JWT_AUTHORITIES = "authorities"; | |||
/** | |||
* 资源映射路径 前缀 | |||
*/ | |||
public static final String RESOURCE_PREFIX = "/profile"; | |||
} |
@@ -1,16 +0,0 @@ | |||
package com.tuoheng.system.constant; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
/** | |||
* <p> | |||
* 字典类型表 模块常量 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2021-03-26 | |||
*/ | |||
public class DictTypeConstant { | |||
} |
@@ -1,36 +0,0 @@ | |||
package com.tuoheng.system.constant; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
/** | |||
* <p> | |||
* 演示案例表 模块常量 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2021-03-27 | |||
*/ | |||
public class ExampleConstant { | |||
/** | |||
* 状态 | |||
*/ | |||
public static Map<Integer, String> EXAMPLE_STATUS_LIST = new HashMap<Integer, String>() { | |||
{ | |||
put(1, "正常"); | |||
put(2, "停用"); | |||
} | |||
}; | |||
/** | |||
* 类型 | |||
*/ | |||
public static Map<Integer, String> EXAMPLE_TYPE_LIST = new HashMap<Integer, String>() { | |||
{ | |||
put(1, "京东"); | |||
put(2, "淘宝"); | |||
put(3, "拼多多"); | |||
put(4, "唯品会"); | |||
} | |||
}; | |||
} |
@@ -1,73 +0,0 @@ | |||
package com.tuoheng.system.constant; | |||
/** | |||
* Shiro相关常量 | |||
*/ | |||
public interface ShiroConstants { | |||
/** | |||
* 当前登录的用户 | |||
*/ | |||
public static final String CURRENT_USER = "currentUser"; | |||
/** | |||
* 用户名 | |||
*/ | |||
public static final String CURRENT_USERNAME = "username"; | |||
/** | |||
* 消息key | |||
*/ | |||
public static String MESSAGE = "message"; | |||
/** | |||
* 错误key | |||
*/ | |||
public static String ERROR = "errorMsg"; | |||
/** | |||
* 编码格式 | |||
*/ | |||
public static String ENCODING = "UTF-8"; | |||
/** | |||
* 当前在线会话 | |||
*/ | |||
public String ONLINE_SESSION = "online_session"; | |||
/** | |||
* 验证码key | |||
*/ | |||
public static final String CURRENT_CAPTCHA = "captcha"; | |||
/** | |||
* 验证码开关 | |||
*/ | |||
public static final String CURRENT_ENABLED = "captchaEnabled"; | |||
/** | |||
* 验证码类型 | |||
*/ | |||
public static final String CURRENT_TYPE = "captchaType"; | |||
/** | |||
* 验证码 | |||
*/ | |||
public static final String CURRENT_VALIDATECODE = "validateCode"; | |||
/** | |||
* 验证码错误 | |||
*/ | |||
public static final String CAPTCHA_ERROR = "captchaError"; | |||
/** | |||
* 登录记录缓存 | |||
*/ | |||
public static final String LOGINRECORDCACHE = "loginRecordCache"; | |||
/** | |||
* 系统活跃用户缓存 | |||
*/ | |||
public static final String SYS_USERCACHE = "sys-userCache"; | |||
} |
@@ -1,35 +0,0 @@ | |||
package com.tuoheng.system.constant; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
/** | |||
* <p> | |||
* 用户管理 模块常量 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-04-20 | |||
*/ | |||
public class UserConstant { | |||
/** | |||
* 性别 | |||
*/ | |||
public static Map<Integer, String> USER_GENDER_LIST = new HashMap<Integer, String>() { | |||
{ | |||
put(1, "男"); | |||
put(2, "女"); | |||
put(3, "保密"); | |||
} | |||
}; | |||
/** | |||
* 状态 | |||
*/ | |||
public static Map<Integer, String> USER_STATUS_LIST = new HashMap<Integer, String>() { | |||
{ | |||
put(1, "正常"); | |||
put(2, "禁用"); | |||
} | |||
}; | |||
} |
@@ -1,94 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.enums.LogType; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.entity.City; | |||
import com.tuoheng.system.query.CityQuery; | |||
import com.tuoheng.system.service.ICityService; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import com.tuoheng.common.common.BaseController; | |||
import java.util.List; | |||
/** | |||
* <p> | |||
* 高德城市表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-03 | |||
*/ | |||
@RestController | |||
@RequestMapping("/city") | |||
public class CityController extends BaseController { | |||
@Autowired | |||
private ICityService cityService; | |||
/** | |||
* 获取城市列表 | |||
* | |||
* @param cityQuery 查询条件 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:city:index") | |||
@GetMapping("/index") | |||
public JsonResult index(CityQuery cityQuery) { | |||
return cityService.getList(cityQuery); | |||
} | |||
/** | |||
* 查询行政区列表(树结构) | |||
* | |||
* @return 行政区列表(树结构) | |||
*/ | |||
@GetMapping("/queryCityList") | |||
public List<City> queryCityList() { | |||
return cityService.getCityList(); | |||
} | |||
/** | |||
* 添加城市 | |||
* | |||
* @param entity 查询条件 | |||
* @return | |||
*/ | |||
@Log(title = "城市管理", logType = LogType.INSERT) | |||
//@RequiresPermissions("sys:city:add") | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody City entity) { | |||
return cityService.add(entity); | |||
} | |||
/** | |||
* 编辑城市 | |||
* | |||
* @param entity 查询条件 | |||
* @return | |||
*/ | |||
@Log(title = "城市管理", logType = LogType.UPDATE) | |||
//@RequiresPermissions("sys:city:edit") | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody City entity) { | |||
return cityService.edit(entity); | |||
} | |||
/** | |||
* 删除城市 | |||
* | |||
* @param cityId 城市ID | |||
* @return | |||
*/ | |||
@Log(title = "城市管理", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:city:delete") | |||
@DeleteMapping("/delete/{cityId}") | |||
public JsonResult delete(@PathVariable("cityId") Integer cityId) { | |||
return cityService.deleteById(cityId); | |||
} | |||
} |
@@ -1,82 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.enums.LogType; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.entity.Config; | |||
import com.tuoheng.system.query.ConfigQuery; | |||
import com.tuoheng.system.service.IConfigService; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import com.tuoheng.common.common.BaseController; | |||
/** | |||
* <p> | |||
* 配置表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
@RestController | |||
@RequestMapping("/config") | |||
public class ConfigController extends BaseController { | |||
@Autowired | |||
private IConfigService configService; | |||
/** | |||
* 获取配置列表 | |||
* | |||
* @param configQuery 查询条件 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:config:index") | |||
@GetMapping("/index") | |||
public JsonResult index(ConfigQuery configQuery) { | |||
return configService.getList(configQuery); | |||
} | |||
/** | |||
* 添加配置 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "配置管理", logType = LogType.INSERT) | |||
//@RequiresPermissions("sys:config:add") | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody Config entity) { | |||
return configService.edit(entity); | |||
} | |||
/** | |||
* 编辑配置 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "配置管理", logType = LogType.UPDATE) | |||
//@RequiresPermissions("sys:config:edit") | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody Config entity) { | |||
return configService.edit(entity); | |||
} | |||
/** | |||
* 删除配置 | |||
* | |||
* @param configId 配置ID | |||
* @return | |||
*/ | |||
@Log(title = "配置管理", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:config:delete") | |||
@DeleteMapping("/delete/{configId}") | |||
public JsonResult delete(@PathVariable("configId") Integer configId) { | |||
return configService.deleteById(configId); | |||
} | |||
} |
@@ -1,95 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.enums.LogType; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.entity.ConfigData; | |||
import com.tuoheng.system.query.ConfigDataQuery; | |||
import com.tuoheng.system.service.IConfigDataService; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import com.tuoheng.common.common.BaseController; | |||
/** | |||
* <p> | |||
* 配置表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
@RestController | |||
@RequestMapping("/configdata") | |||
public class ConfigDataController extends BaseController { | |||
@Autowired | |||
private IConfigDataService configDataService; | |||
/** | |||
* 获取配置列表 | |||
* | |||
* @param configDataQuery 查询条件 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:config:index") | |||
@GetMapping("/index") | |||
public JsonResult index(ConfigDataQuery configDataQuery) { | |||
return configDataService.getList(configDataQuery); | |||
} | |||
/** | |||
* 添加配置 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "配置管理", logType = LogType.INSERT) | |||
//@RequiresPermissions("sys:config:add") | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody ConfigData entity) { | |||
return configDataService.edit(entity); | |||
} | |||
/** | |||
* 编辑配置 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "配置管理", logType = LogType.UPDATE) | |||
//@RequiresPermissions("sys:config:edit") | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody ConfigData entity) { | |||
return configDataService.edit(entity); | |||
} | |||
/** | |||
* 删除配置 | |||
* | |||
* @param configIds 配置ID | |||
* @return | |||
*/ | |||
@Log(title = "配置管理", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:config:delete") | |||
@DeleteMapping("/delete/{configIds}") | |||
public JsonResult delete(@PathVariable("configIds") Integer[] configIds) { | |||
return configDataService.deleteByIds(configIds); | |||
} | |||
/** | |||
* 更新状态 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "配置管理", logType = LogType.STATUS) | |||
//@RequiresPermissions("sys:config:status") | |||
@PutMapping("/status") | |||
public JsonResult status(@RequestBody ConfigData entity) { | |||
return configDataService.setStatus(entity); | |||
} | |||
} |
@@ -1,42 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.common.common.BaseController; | |||
import com.tuoheng.system.service.IConfigWebService; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import java.util.Map; | |||
@RestController | |||
@RequestMapping("/configweb") | |||
public class ConfigWebController extends BaseController { | |||
@Autowired | |||
private IConfigWebService configWebService; | |||
/** | |||
* 获取配置列表 | |||
* | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:configweb:index") | |||
@GetMapping("/index") | |||
public JsonResult index() { | |||
return configWebService.getList(); | |||
} | |||
/** | |||
* 保存配置信息 | |||
* | |||
* @param info 表单信息 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:configweb:edit") | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody Map<String, Object> info) { | |||
return configWebService.edit(info); | |||
} | |||
} |
@@ -1,96 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.enums.LogType; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.entity.Dept; | |||
import com.tuoheng.system.query.DeptQuery; | |||
import com.tuoheng.system.service.IDeptService; | |||
import com.tuoheng.system.service.ITenantService; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import com.tuoheng.common.common.BaseController; | |||
/** | |||
* <p> | |||
* 部门表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-03 | |||
*/ | |||
@RestController | |||
@RequestMapping("/dept") | |||
public class DeptController extends BaseController { | |||
@Autowired | |||
private IDeptService deptService; | |||
@Autowired | |||
private ITenantService iTenantService; | |||
/** | |||
* 获取部门列表 | |||
* | |||
* @param deptQuery 查询条件 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:dept:index") | |||
@GetMapping("/index") | |||
public JsonResult index(DeptQuery deptQuery) { | |||
return deptService.getList(deptQuery); | |||
} | |||
/** | |||
* 添加部门 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "部门管理", logType = LogType.INSERT) | |||
//@RequiresPermissions("sys:dept:add") | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody Dept entity) { | |||
entity.setTenantId(iTenantService.getCurrentTenantId()); | |||
return deptService.edit(entity); | |||
} | |||
/** | |||
* 编辑部门 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "部门管理", logType = LogType.UPDATE) | |||
//@RequiresPermissions("sys:dept:edit") | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody Dept entity) { | |||
entity.setTenantId(iTenantService.getCurrentTenantId()); | |||
return deptService.edit(entity); | |||
} | |||
/** | |||
* 删除部门 | |||
* | |||
* @param deptId 部门ID | |||
* @return | |||
*/ | |||
@Log(title = "部门管理", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:dept:delete") | |||
@DeleteMapping("/delete/{deptId}") | |||
public JsonResult delete(@PathVariable("deptId") Integer deptId) { | |||
return deptService.deleteById(deptId); | |||
} | |||
/** | |||
* 获取部门列表 | |||
* | |||
* @return | |||
*/ | |||
@GetMapping("/getDeptList") | |||
public JsonResult getDeptList() { | |||
return deptService.getDeptList(); | |||
} | |||
} |
@@ -1,86 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.enums.LogType; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.common.common.BaseController; | |||
import com.tuoheng.system.entity.Dict; | |||
import com.tuoheng.system.query.DictQuery; | |||
import com.tuoheng.system.service.IDictService; | |||
import com.tuoheng.system.service.ITenantService; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
/** | |||
* <p> | |||
* 字典类型表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-01 | |||
*/ | |||
@RestController | |||
@RequestMapping("/dict") | |||
public class DictController extends BaseController { | |||
@Autowired | |||
private IDictService dictService; | |||
@Autowired | |||
private ITenantService iTenantService; | |||
/** | |||
* 获取字典列表 | |||
* | |||
* @param dictQuery 查询条件 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:dictionary:index") | |||
@GetMapping("/index") | |||
public JsonResult index(DictQuery dictQuery) { | |||
return dictService.getList(dictQuery); | |||
} | |||
/** | |||
* 添加字典 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "字典分组", logType = LogType.INSERT) | |||
//@RequiresPermissions("sys:dictionary:add") | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody Dict entity) { | |||
entity.setTenantId(iTenantService.getCurrentTenantId()); | |||
return dictService.edit(entity); | |||
} | |||
/** | |||
* 编辑字典 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "字典分组", logType = LogType.UPDATE) | |||
//@RequiresPermissions("sys:dictionary:edit") | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody Dict entity) { | |||
entity.setTenantId(iTenantService.getCurrentTenantId()); | |||
return dictService.edit(entity); | |||
} | |||
/** | |||
* 删除字典 | |||
* | |||
* @param dicTypeId 字典ID | |||
* @return | |||
*/ | |||
@Log(title = "字典分组", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:dictionary:delete") | |||
@DeleteMapping("/delete/{dicTypeId}") | |||
public JsonResult delete(@PathVariable("dicTypeId") Integer dicTypeId) { | |||
return dictService.deleteById(dicTypeId); | |||
} | |||
} |
@@ -1,85 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.enums.LogType; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.common.common.BaseController; | |||
import com.tuoheng.system.entity.DictData; | |||
import com.tuoheng.system.query.DictDataQuery; | |||
import com.tuoheng.system.service.IDictDataService; | |||
import com.tuoheng.system.service.ITenantService; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
/** | |||
* <p> | |||
* 字典项管理表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-01 | |||
*/ | |||
@RestController | |||
@RequestMapping("/dictdata") | |||
public class DictDataController extends BaseController { | |||
@Autowired | |||
private IDictDataService dictDataService; | |||
@Autowired | |||
private ITenantService iTenantService; | |||
/** | |||
* 获取字典项列表 | |||
* | |||
* @param dictDataQuery 查询条件 | |||
* @return | |||
*/ | |||
////@RequiresPermissions("sys:dictionary:index") | |||
@GetMapping("/index") | |||
public JsonResult index(DictDataQuery dictDataQuery) { | |||
return dictDataService.getList(dictDataQuery); | |||
} | |||
/** | |||
* 添加字典项 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "字典管理", logType = LogType.INSERT) | |||
//@RequiresPermissions("sys:dictionary:add") | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody DictData entity) { | |||
entity.setTenantId(iTenantService.getCurrentTenantId()); | |||
return dictDataService.edit(entity); | |||
} | |||
/** | |||
* 编辑字典项 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "字典管理", logType = LogType.UPDATE) | |||
//@RequiresPermissions("sys:dictionary:edit") | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody DictData entity) { | |||
entity.setTenantId(iTenantService.getCurrentTenantId()); | |||
return dictDataService.edit(entity); | |||
} | |||
/** | |||
* 删除字典项 | |||
* | |||
* @param dicIds 字典项ID | |||
* @return | |||
*/ | |||
@Log(title = "字典管理", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:dictionary:delete") | |||
@DeleteMapping("/delete/{dicIds}") | |||
public JsonResult delete(@PathVariable("dicIds") Integer[] dicIds) { | |||
return dictDataService.deleteByIds(dicIds); | |||
} | |||
} |
@@ -1,76 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.common.BaseController; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.dto.UpdatePwdDto; | |||
import com.tuoheng.system.dto.UpdateUserInfoDto; | |||
import com.tuoheng.system.entity.Menu; | |||
import com.tuoheng.system.service.IMenuService; | |||
import com.tuoheng.system.service.IUserService; | |||
import com.tuoheng.system.utils.ShiroUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import java.util.List; | |||
/** | |||
* <p> | |||
* 系统主页 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-30 | |||
*/ | |||
@RestController | |||
@RequestMapping("/index") | |||
public class IndexController extends BaseController { | |||
@Autowired | |||
private IMenuService menuService; | |||
@Autowired | |||
private IUserService userService; | |||
/** | |||
* 获取导航菜单 | |||
* | |||
* @return | |||
*/ | |||
@GetMapping("/getMenuList") | |||
public JsonResult getMenuList() { | |||
List<Menu> menuList = menuService.getMenuList(ShiroUtils.getUserId()); | |||
return JsonResult.success(menuList); | |||
} | |||
/** | |||
* 获取用户信息 | |||
* | |||
* @return | |||
*/ | |||
@GetMapping("/getUserInfo") | |||
public JsonResult getUserInfo() { | |||
return userService.getUserInfo(); | |||
} | |||
/** | |||
* 修改密码 | |||
* | |||
* @param updatePwdDto 参数 | |||
* @return | |||
*/ | |||
@PutMapping("/updatePwd") | |||
public JsonResult updatePwd(@RequestBody UpdatePwdDto updatePwdDto) { | |||
return userService.updatePwd(updatePwdDto); | |||
} | |||
/** | |||
* 更新个人资料 | |||
* | |||
* @param updateUserInfoDto 参数 | |||
* @return | |||
*/ | |||
@PutMapping("/updateUserInfo") | |||
public JsonResult updateUserInfo(@RequestBody UpdateUserInfoDto updateUserInfoDto) { | |||
return userService.updateUserInfo(updateUserInfoDto); | |||
} | |||
} |
@@ -1,122 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.enums.LogType; | |||
import com.tuoheng.common.utils.ExcelUtils; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.entity.Level; | |||
import com.tuoheng.system.query.LevelQuery; | |||
import com.tuoheng.system.service.ILevelService; | |||
import com.tuoheng.system.vo.level.LevelInfoVo; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import com.tuoheng.common.common.BaseController; | |||
import java.util.List; | |||
/** | |||
* <p> | |||
* 职级表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-02 | |||
*/ | |||
@RestController | |||
@RequestMapping("/level") | |||
public class LevelController extends BaseController { | |||
@Autowired | |||
private ILevelService levelService; | |||
/** | |||
* 获取职级列表 | |||
* | |||
* @param levelQuery 查询条件 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:level:index") | |||
@GetMapping("/index") | |||
public JsonResult index(LevelQuery levelQuery) { | |||
return levelService.getList(levelQuery); | |||
} | |||
/** | |||
* 添加职级 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "职级管理", logType = LogType.INSERT) | |||
//@RequiresPermissions("sys:level:add") | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody Level entity) { | |||
return levelService.edit(entity); | |||
} | |||
/** | |||
* 编辑职级 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "职级管理", logType = LogType.UPDATE) | |||
//@RequiresPermissions("sys:level:edit") | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody Level entity) { | |||
return levelService.edit(entity); | |||
} | |||
/** | |||
* 删除职级 | |||
* | |||
* @param levelIds 职级ID | |||
* @return | |||
*/ | |||
@Log(title = "职级管理", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:level:delete") | |||
@DeleteMapping("/delete/{levelIds}") | |||
public JsonResult delete(@PathVariable("levelIds") Integer[] levelIds) { | |||
return levelService.deleteByIds(levelIds); | |||
} | |||
/** | |||
* 设置状态 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "职级管理", logType = LogType.STATUS) | |||
//@RequiresPermissions("sys:level:status") | |||
@PutMapping("/status") | |||
public JsonResult status(@RequestBody Level entity) { | |||
return levelService.setStatus(entity); | |||
} | |||
/** | |||
* 获取职级列表 | |||
* | |||
* @return | |||
*/ | |||
@GetMapping("/getLevelList") | |||
public JsonResult getLevelList() { | |||
return levelService.getLevelList(); | |||
} | |||
/** | |||
* 导出Excel | |||
* | |||
* @param levelQuery 查询条件 | |||
* @return | |||
*/ | |||
@PostMapping("/exportExcel") | |||
public JsonResult exportExcel(@RequestBody LevelQuery levelQuery) { | |||
List<LevelInfoVo> levelInfoVoList = levelService.exportExcel(levelQuery); | |||
ExcelUtils<LevelInfoVo> excelUtils = new ExcelUtils<LevelInfoVo>(LevelInfoVo.class); | |||
return excelUtils.exportExcel(levelInfoVoList, "职级列表"); | |||
} | |||
} |
@@ -1,96 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.common.BaseController; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.dto.LoginDto; | |||
import com.tuoheng.system.dto.ThirdAuthenticationDto; | |||
import com.tuoheng.system.service.ILoginService; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.http.HttpStatus; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
/** | |||
* <p> | |||
* 系统登录 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-31 | |||
*/ | |||
@RestController | |||
@RequestMapping("/login") | |||
public class LoginController extends BaseController { | |||
@Autowired | |||
private ILoginService loginService; | |||
/** | |||
* 获取验证码 | |||
* | |||
* @param response 网络请求 | |||
* @return | |||
*/ | |||
@GetMapping("/captcha") | |||
public JsonResult captcha(HttpServletResponse response) { | |||
return loginService.captcha(response); | |||
} | |||
/** | |||
* 系统登录 | |||
* | |||
* @param loginDto 参数 | |||
* @param request 网络请求 | |||
* @return | |||
*/ | |||
@PostMapping("/login") | |||
public JsonResult login(@RequestBody LoginDto loginDto, HttpServletRequest request) { | |||
return loginService.login(loginDto, request); | |||
} | |||
/** | |||
* 退出登录 | |||
* | |||
* @return | |||
*/ | |||
@GetMapping("/logout") | |||
public JsonResult logout() { | |||
return loginService.logout(); | |||
} | |||
/** | |||
* 用户未登录 | |||
* | |||
* @return | |||
*/ | |||
@GetMapping("/un_auth") | |||
public JsonResult unAuth() { | |||
return JsonResult.error(HttpStatus.UNAUTHORIZED, ""); | |||
} | |||
/** | |||
* 用户无权限 | |||
* | |||
* @return | |||
*/ | |||
@GetMapping("/unauthorized") | |||
public JsonResult unauthorized() { | |||
return JsonResult.error(HttpStatus.FORBIDDEN, "用户无权限"); | |||
} | |||
/** | |||
* 第三方鉴权 | |||
* | |||
* @param thirdAuthenticationDto 参数 | |||
* @param request 网络请求 | |||
* @return | |||
*/ | |||
@PostMapping("/thirdAuthentication") | |||
public JsonResult thirdLogin(@RequestBody ThirdAuthenticationDto thirdAuthenticationDto, HttpServletRequest request) { | |||
return loginService.thirdAuthentication(thirdAuthenticationDto, request); | |||
} | |||
} |
@@ -1,55 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.enums.LogType; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.query.LoginLogQuery; | |||
import com.tuoheng.system.service.ILoginLogService; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import com.tuoheng.common.common.BaseController; | |||
/** | |||
* <p> | |||
* 登录日志表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-31 | |||
*/ | |||
@RestController | |||
@RequestMapping("/loginlog") | |||
public class LoginLogController extends BaseController { | |||
@Autowired | |||
private ILoginLogService loginLogService; | |||
/** | |||
* 获取登录日志列表 | |||
* | |||
* @param loginLogQuery 查询条件 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:loginlog:index") | |||
@GetMapping("/index") | |||
public JsonResult index(LoginLogQuery loginLogQuery) { | |||
return loginLogService.getList(loginLogQuery); | |||
} | |||
/** | |||
* 删除登录日志 | |||
* | |||
* @param loginLogIds 登录日志ID | |||
* @return | |||
*/ | |||
@Log(title = "登录日志", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:loginlog:delete") | |||
@DeleteMapping("/delete/{loginLogIds}") | |||
public JsonResult delete(@PathVariable("loginLogIds") Integer[] loginLogIds) { | |||
return loginLogService.deleteByIds(loginLogIds); | |||
} | |||
} |
@@ -1,106 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.enums.LogType; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.entity.Menu; | |||
import com.tuoheng.system.query.MenuQuery; | |||
import com.tuoheng.system.service.IMenuService; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import com.tuoheng.common.common.BaseController; | |||
import java.util.List; | |||
/** | |||
* <p> | |||
* 系统菜单表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-30 | |||
*/ | |||
@RestController | |||
@RequestMapping("/menu") | |||
public class MenuController extends BaseController { | |||
@Autowired | |||
private IMenuService menuService; | |||
/** | |||
* 获取菜单列表 | |||
* | |||
* @param menuQuery 查询条件 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:menu:index") | |||
@GetMapping("/index") | |||
public JsonResult index(MenuQuery menuQuery) { | |||
return menuService.getList(menuQuery); | |||
} | |||
/** | |||
* 获取菜单详情 | |||
* | |||
* @param menuId 菜单ID | |||
* @return | |||
*/ | |||
@GetMapping("/info/{menuId}") | |||
public JsonResult info(@PathVariable("menuId") Integer menuId) { | |||
return menuService.info(menuId); | |||
} | |||
/** | |||
* 添加菜单 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "菜单管理", logType = LogType.INSERT) | |||
//@RequiresPermissions("sys:menu:add") | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody Menu entity) { | |||
return menuService.edit(entity); | |||
} | |||
/** | |||
* 编辑菜单 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "菜单管理", logType = LogType.UPDATE) | |||
//@RequiresPermissions("sys:menu:edit") | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody Menu entity) { | |||
return menuService.edit(entity); | |||
} | |||
/** | |||
* 删除菜单 | |||
* | |||
* @param menuId 菜单ID | |||
* @return | |||
*/ | |||
@Log(title = "菜单管理", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:menu:delete") | |||
@DeleteMapping("/delete/{menuId}") | |||
public JsonResult delete(@PathVariable("menuId") Integer menuId) { | |||
return menuService.deleteById(menuId); | |||
} | |||
/** | |||
* 获取所有菜单列表 | |||
* | |||
* @return | |||
*/ | |||
@GetMapping("/getMenuAll") | |||
public JsonResult getMenuAll() { | |||
List<Menu> menuList = menuService.getMenuAll(); | |||
return JsonResult.success(menuList); | |||
} | |||
} |
@@ -1,107 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.enums.LogType; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.entity.Notice; | |||
import com.tuoheng.system.query.NoticeQuery; | |||
import com.tuoheng.system.service.INoticeService; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import com.tuoheng.common.common.BaseController; | |||
/** | |||
* <p> | |||
* 通知公告表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-07 | |||
*/ | |||
@RestController | |||
@RequestMapping("/notice") | |||
public class NoticeController extends BaseController { | |||
@Autowired | |||
private INoticeService noticeService; | |||
/** | |||
* 获取通知公告列表 | |||
* | |||
* @param noticeQuery 查询条件 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:notice:index") | |||
@GetMapping("/index") | |||
public JsonResult index(NoticeQuery noticeQuery) { | |||
return noticeService.getList(noticeQuery); | |||
} | |||
/** | |||
* 添加通知公告 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "通知公告", logType = LogType.INSERT) | |||
//@RequiresPermissions("sys:notice:add") | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody Notice entity) { | |||
return noticeService.edit(entity); | |||
} | |||
/** | |||
* 编辑通知公告 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "通知公告", logType = LogType.UPDATE) | |||
//@RequiresPermissions("sys:notice:edit") | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody Notice entity) { | |||
return noticeService.edit(entity); | |||
} | |||
/** | |||
* 删除通知公告 | |||
* | |||
* @param noticeIds 通知公告ID | |||
* @return | |||
*/ | |||
@Log(title = "通知公告", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:notice:delete") | |||
@DeleteMapping("/delete/{noticeIds}") | |||
public JsonResult delete(@PathVariable("noticeIds") Integer[] noticeIds) { | |||
return noticeService.deleteByIds(noticeIds); | |||
} | |||
/** | |||
* 设置状态 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "通知公告", logType = LogType.STATUS) | |||
//@RequiresPermissions("sys:notice:status") | |||
@PutMapping("/status") | |||
public JsonResult status(@RequestBody Notice entity) { | |||
return noticeService.setStatus(entity); | |||
} | |||
/** | |||
* 设置指定 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:notice:setIsTop") | |||
@PutMapping("/setIsTop") | |||
public JsonResult setIsTop(@RequestBody Notice entity) { | |||
return noticeService.setIsTop(entity); | |||
} | |||
} |
@@ -1,55 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.enums.LogType; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.query.OperLogQuery; | |||
import com.tuoheng.system.service.IOperLogService; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import com.tuoheng.common.common.BaseController; | |||
/** | |||
* <p> | |||
* 操作日志记录 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-31 | |||
*/ | |||
@RestController | |||
@RequestMapping("/operlog") | |||
public class OperLogController extends BaseController { | |||
@Autowired | |||
private IOperLogService operLogService; | |||
/** | |||
* 获取操作日志列表 | |||
* | |||
* @param operLogQuery 查询条件 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:operlog:index") | |||
@GetMapping("/index") | |||
public JsonResult index(OperLogQuery operLogQuery) { | |||
return operLogService.getList(operLogQuery); | |||
} | |||
/** | |||
* 删除操作日志 | |||
* | |||
* @param operLogId 操作日志ID | |||
* @return | |||
*/ | |||
@Log(title = "操作日志", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:operlog:delete") | |||
@DeleteMapping("/delete/{operLogId}") | |||
public JsonResult delete(@PathVariable("operLogId") Integer operLogId) { | |||
return operLogService.deleteById(operLogId); | |||
} | |||
} |
@@ -1,109 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.enums.LogType; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.entity.Position; | |||
import com.tuoheng.system.query.PositionQuery; | |||
import com.tuoheng.system.service.IPositionService; | |||
import com.tuoheng.system.service.ITenantService; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import com.tuoheng.common.common.BaseController; | |||
/** | |||
* <p> | |||
* 岗位表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-02 | |||
*/ | |||
@RestController | |||
@RequestMapping("/position") | |||
public class PositionController extends BaseController { | |||
@Autowired | |||
private IPositionService positionService; | |||
@Autowired | |||
private ITenantService iTenantService; | |||
/** | |||
* 获取岗位列表 | |||
* | |||
* @param positionQuery 查询条件 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:position:index") | |||
@GetMapping("/index") | |||
public JsonResult index(PositionQuery positionQuery) { | |||
return positionService.getList(positionQuery); | |||
} | |||
/** | |||
* 添加岗位 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "岗位管理", logType = LogType.INSERT) | |||
//@RequiresPermissions("sys:position:add") | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody Position entity) { | |||
entity.setTenantId(iTenantService.getCurrentTenantId()); | |||
return positionService.edit(entity); | |||
} | |||
/** | |||
* 编辑岗位 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "岗位管理", logType = LogType.UPDATE) | |||
//@RequiresPermissions("sys:position:edit") | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody Position entity) { | |||
entity.setTenantId(iTenantService.getCurrentTenantId()); | |||
return positionService.edit(entity); | |||
} | |||
/** | |||
* 删除岗位 | |||
* | |||
* @param positionIds 岗位ID | |||
* @return | |||
*/ | |||
@Log(title = "岗位管理", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:position:delete") | |||
@DeleteMapping("/delete/{positionIds}") | |||
public JsonResult delete(@PathVariable("positionIds") Integer[] positionIds) { | |||
return positionService.deleteByIds(positionIds); | |||
} | |||
/** | |||
* 设置状态 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "岗位管理", logType = LogType.STATUS) | |||
//@RequiresPermissions("sys:position:status") | |||
@PutMapping("/status") | |||
public JsonResult status(@RequestBody Position entity) { | |||
return positionService.setStatus(entity); | |||
} | |||
/** | |||
* 获取岗位列表 | |||
* | |||
* @return | |||
*/ | |||
@GetMapping("/getPositionList") | |||
public JsonResult getPositionList() { | |||
return positionService.getPositionList(); | |||
} | |||
} |
@@ -1,124 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.enums.LogType; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.dto.RoleMenuDto; | |||
import com.tuoheng.system.entity.Role; | |||
import com.tuoheng.system.entity.User; | |||
import com.tuoheng.system.query.RoleQuery; | |||
import com.tuoheng.system.service.IRoleService; | |||
import com.tuoheng.system.service.ITenantService; | |||
import org.apache.shiro.SecurityUtils; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import com.tuoheng.common.common.BaseController; | |||
/** | |||
* <p> | |||
* 系统角色表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-31 | |||
*/ | |||
@RestController | |||
@RequestMapping("/role") | |||
public class RoleController extends BaseController { | |||
@Autowired | |||
private IRoleService roleService; | |||
@Autowired | |||
private ITenantService iTenantService; | |||
/** | |||
* 获取角色列表 | |||
* | |||
* @param roleQuery 查询条件 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:role:index") | |||
@GetMapping("/index") | |||
public JsonResult index(RoleQuery roleQuery) { | |||
return roleService.getList(roleQuery); | |||
} | |||
/** | |||
* 添加角色 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "角色管理", logType = LogType.INSERT) | |||
//@RequiresPermissions("sys:role:add") | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody Role entity) { | |||
entity.setCreateUser(iTenantService.getCurrentUserId()); | |||
entity.setTenantId(iTenantService.getCurrentTenantId()); | |||
return roleService.edit(entity); | |||
} | |||
/** | |||
* 编辑角色 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "角色管理", logType = LogType.UPDATE) | |||
//@RequiresPermissions("sys:role:edit") | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody Role entity) { | |||
entity.setUpdateUser(iTenantService.getCurrentUserId()); | |||
entity.setTenantId(iTenantService.getCurrentTenantId()); | |||
return roleService.edit(entity); | |||
} | |||
/** | |||
* 删除角色 | |||
* | |||
* @param roleIds 角色ID | |||
* @return | |||
*/ | |||
@Log(title = "角色管理", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:role:delete") | |||
@DeleteMapping("/delete/{roleIds}") | |||
public JsonResult delete(@PathVariable("roleIds") Integer[] roleIds) { | |||
return roleService.deleteByIds(roleIds); | |||
} | |||
/** | |||
* 获取角色列表 | |||
* | |||
* @return | |||
*/ | |||
@GetMapping("/getRoleList") | |||
public JsonResult getRoleList() { | |||
return roleService.getRoleList(); | |||
} | |||
/** | |||
* 获取角色菜单列表 | |||
* | |||
* @param roleId 角色ID | |||
* @return | |||
*/ | |||
@GetMapping("/getMenuList/{roleId}") | |||
public JsonResult getMenuList(@PathVariable("roleId") Integer roleId) { | |||
return roleService.getMenuList(roleId); | |||
} | |||
/** | |||
* 保存角色权限数据 | |||
* | |||
* @param roleMenuDto 角色菜单Dto | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:role:permission") | |||
@PostMapping("/savePermission") | |||
public JsonResult savePermission(@RequestBody RoleMenuDto roleMenuDto) { | |||
return roleService.savePermission(roleMenuDto); | |||
} | |||
} |
@@ -1,21 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import com.tuoheng.common.common.BaseController; | |||
/** | |||
* <p> | |||
* 角色菜单关联表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-30 | |||
*/ | |||
@RestController | |||
@RequestMapping("/role-menu") | |||
public class RoleMenuController extends BaseController { | |||
} |
@@ -1,87 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.alibaba.fastjson.JSON; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.common.BaseController; | |||
import com.tuoheng.common.enums.LogType; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.entity.Tenant; | |||
import com.tuoheng.system.entity.User; | |||
import com.tuoheng.system.query.TenantQuery; | |||
import com.tuoheng.system.service.ITenantService; | |||
import net.sf.cglib.beans.BeanMap; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import java.util.Map; | |||
/** | |||
* <p> | |||
* 系统租户表 前端控制器 | |||
* </p> | |||
* | |||
* @author | |||
* @since 2022-12-31 | |||
*/ | |||
@RestController | |||
@RequestMapping("/tenant") | |||
public class TenantController extends BaseController { | |||
@Autowired | |||
private ITenantService tenantService; | |||
/** | |||
* 获取租户列表 | |||
* @param tenantQuery 查询条件 | |||
* @return | |||
*/ | |||
@GetMapping("/index") | |||
public JsonResult index(TenantQuery tenantQuery) { | |||
return tenantService.getList(tenantQuery); | |||
} | |||
/** | |||
* 添加租户 | |||
* @param jsonObject 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "租户管理", logType = LogType.INSERT) | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody JSONObject jsonObject) { | |||
String username = jsonObject.get("username").toString(); | |||
String password = jsonObject.get("password").toString(); | |||
String tenantName = jsonObject.get("tenantName").toString(); | |||
String tenantCode = jsonObject.get("tenantCode").toString(); | |||
return tenantService.add(new Tenant().setName(tenantName).setCode(tenantCode), | |||
new User().setUsername(username).setPassword(password)); | |||
} | |||
/** | |||
* 编辑租户 | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "租户管理", logType = LogType.UPDATE) | |||
//@RequiresPermissions("sys:tenant:edit") | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody Tenant entity) { | |||
return tenantService.edit(entity); | |||
} | |||
/** | |||
* 删除租户 | |||
* @param tenantIds 租户ID | |||
* @return | |||
*/ | |||
@Log(title = "租户管理", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:tenant:delete") | |||
@DeleteMapping("/delete/{tenantIds}") | |||
public JsonResult delete(@PathVariable("tenantIds") Integer[] tenantIds) { | |||
return tenantService.deleteByIds(tenantIds); | |||
} | |||
} |
@@ -1,137 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import com.tuoheng.common.annotation.Log; | |||
import com.tuoheng.common.enums.LogType; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.dto.ResetPwdDto; | |||
import com.tuoheng.system.entity.User; | |||
import com.tuoheng.system.query.UserQuery; | |||
import com.tuoheng.system.service.ITenantService; | |||
import com.tuoheng.system.service.IUserService; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import com.tuoheng.common.common.BaseController; | |||
/** | |||
* <p> | |||
* 后台用户管理表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-30 | |||
*/ | |||
@RestController | |||
@RequestMapping("/user") | |||
public class UserController extends BaseController { | |||
@Autowired | |||
private IUserService userService; | |||
@Autowired | |||
private ITenantService iTenantService; | |||
/** | |||
* 获取用户列表 | |||
* | |||
* @param userQuery 查询条件 | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:user:index") | |||
@GetMapping("/index") | |||
public JsonResult index(UserQuery userQuery) { | |||
return userService.getList(userQuery); | |||
} | |||
/** | |||
* 获取会员详情 | |||
* | |||
* @param userId 用户ID | |||
* @return | |||
*/ | |||
//@RequiresPermissions("sys:user:detail") | |||
@GetMapping("/detail/{userId}") | |||
public JsonResult detail(@PathVariable("userId") Integer userId) { | |||
return userService.detail(userId); | |||
} | |||
/** | |||
* 添加用户 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "用户管理", logType = LogType.INSERT) | |||
//@RequiresPermissions("sys:user:add") | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody User entity) { | |||
entity.setTenantId(iTenantService.getCurrentTenantId()); | |||
return userService.edit(entity); | |||
} | |||
/** | |||
* 编辑用户 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "用户管理", logType = LogType.UPDATE) | |||
//@RequiresPermissions("sys:user:edit") | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody User entity) { | |||
User user = userService.getById(entity.getId()); | |||
entity.setTenantId(user.getTenantId()); | |||
return userService.edit(entity); | |||
} | |||
/** | |||
* 删除用户 | |||
* | |||
* @param userIds 用户ID | |||
* @return | |||
*/ | |||
@Log(title = "用户管理", logType = LogType.DELETE) | |||
//@RequiresPermissions("sys:user:delete") | |||
@DeleteMapping("/delete/{userIds}") | |||
public JsonResult delete(@PathVariable("userIds") Integer[] userIds) { | |||
return userService.deleteByIds(userIds); | |||
} | |||
/** | |||
* 设置状态 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Log(title = "用户管理", logType = LogType.STATUS) | |||
//@RequiresPermissions("sys:user:status") | |||
@PutMapping("/status") | |||
public JsonResult status(@RequestBody User entity) { | |||
return userService.setStatus(entity); | |||
} | |||
/** | |||
* 重置密码 | |||
* | |||
* @param resetPwdDto 参数 | |||
* @return | |||
*/ | |||
@Log(title = "用户管理", logType = LogType.RESETPWD) | |||
//@RequiresPermissions("sys:user:resetPwd") | |||
@PutMapping("/resetPwd") | |||
public JsonResult resetPwd(@RequestBody ResetPwdDto resetPwdDto) { | |||
return userService.resetPwd(resetPwdDto); | |||
} | |||
/** | |||
* 获取用户列表 | |||
* | |||
* @param type 用户类型:1普通用户 2飞手 | |||
* @return | |||
*/ | |||
@GetMapping("/getUserList/{type}") | |||
public JsonResult getUserList(@PathVariable("type") Integer type) { | |||
return userService.getUserList(type); | |||
} | |||
} |
@@ -1,21 +0,0 @@ | |||
package com.tuoheng.system.controller; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import com.tuoheng.common.common.BaseController; | |||
/** | |||
* <p> | |||
* 人员角色表 前端控制器 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-30 | |||
*/ | |||
@RestController | |||
@RequestMapping("/user-role") | |||
public class UserRoleController extends BaseController { | |||
} |
@@ -1,31 +0,0 @@ | |||
package com.tuoheng.system.dto; | |||
import lombok.Data; | |||
/** | |||
* 登录Dto | |||
*/ | |||
@Data | |||
public class LoginDto { | |||
/** | |||
* 登录用户名 | |||
*/ | |||
private String username; | |||
/** | |||
* 登录密码 | |||
*/ | |||
private String password; | |||
/** | |||
* 验证码 | |||
*/ | |||
private String captcha; | |||
/** | |||
* 验证码KEY | |||
*/ | |||
private String key; | |||
} |
@@ -1,16 +0,0 @@ | |||
package com.tuoheng.system.dto; | |||
import lombok.Data; | |||
/** | |||
* 重置密码 | |||
*/ | |||
@Data | |||
public class ResetPwdDto { | |||
/** | |||
* 用户ID | |||
*/ | |||
private Integer id; | |||
} |
@@ -1,21 +0,0 @@ | |||
package com.tuoheng.system.dto; | |||
import lombok.Data; | |||
/** | |||
* 角色菜单Dto | |||
*/ | |||
@Data | |||
public class RoleMenuDto { | |||
/** | |||
* 角色ID | |||
*/ | |||
private Integer roleId; | |||
/** | |||
* 菜单ID | |||
*/ | |||
private Integer[] menuIds; | |||
} |
@@ -1,23 +0,0 @@ | |||
package com.tuoheng.system.dto; | |||
import lombok.Data; | |||
/** | |||
* @Author: 吴彬 | |||
* @CreateTime: 2023-04-12 14:17 | |||
* @Description: 第三方获取授权Dto | |||
* @Version: 1.0 | |||
*/ | |||
@Data | |||
public class ThirdAuthenticationDto { | |||
/** | |||
* 登录用户名 | |||
*/ | |||
private String username; | |||
/** | |||
* 登录密码 | |||
*/ | |||
private String password; | |||
} |
@@ -1,21 +0,0 @@ | |||
package com.tuoheng.system.dto; | |||
import lombok.Data; | |||
/** | |||
* 修改密码Dto | |||
*/ | |||
@Data | |||
public class UpdatePwdDto { | |||
/** | |||
* 旧密码 | |||
*/ | |||
private String oldPassword; | |||
/** | |||
* 新密码 | |||
*/ | |||
private String newPassword; | |||
} |
@@ -1,46 +0,0 @@ | |||
package com.tuoheng.system.dto; | |||
import lombok.Data; | |||
/** | |||
* 更新个人资料 | |||
*/ | |||
@Data | |||
public class UpdateUserInfoDto { | |||
/** | |||
* 个人头像 | |||
*/ | |||
private String avatar; | |||
/** | |||
* 真实姓名 | |||
*/ | |||
private String realname; | |||
/** | |||
* 昵称 | |||
*/ | |||
private String nickname; | |||
/** | |||
* 性别 | |||
*/ | |||
private String gender; | |||
/** | |||
* 手机号码 | |||
*/ | |||
private String mobile; | |||
/** | |||
* 个人简介 | |||
*/ | |||
private String intro; | |||
/** | |||
* 个性签名 | |||
*/ | |||
private String signature; | |||
} |
@@ -1,87 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
import java.util.List; | |||
/** | |||
* <p> | |||
* 高德城市表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-03 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("sys_city") | |||
public class City extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 父级编号 | |||
*/ | |||
private Integer pid; | |||
/** | |||
* 城市级别(1省;2市;3区;4街道;5村;) | |||
*/ | |||
private Integer level; | |||
/** | |||
* 城市名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 城市编号(区号) | |||
*/ | |||
private String citycode; | |||
/** | |||
* 父级地理编号 | |||
*/ | |||
private String pAdcode; | |||
/** | |||
* 地理编号 | |||
*/ | |||
private String adcode; | |||
/** | |||
* 城市坐标中心点经度(* 1e6):如果是中国,此值是 1e7 | |||
*/ | |||
private Integer lng; | |||
/** | |||
* 城市坐标中心点纬度(* 1e6) | |||
*/ | |||
private Integer lat; | |||
/** | |||
* 排序号 | |||
*/ | |||
private Integer sort; | |||
/** | |||
* 是否含有子级 | |||
*/ | |||
@TableField(exist = false) | |||
private boolean hasChildren; | |||
/** | |||
* 行政区 子集 | |||
*/ | |||
@TableField(exist = false) | |||
List<City> itemList; | |||
} |
@@ -1,47 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 配置表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("sys_config") | |||
public class Config extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 配置名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 配置编码 | |||
*/ | |||
private String code; | |||
/** | |||
* 排序 | |||
*/ | |||
private Integer sort; | |||
/** | |||
* 配置备注 | |||
*/ | |||
private String note; | |||
} |
@@ -1,72 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 配置表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("sys_config_data") | |||
public class ConfigData extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 配置标题 | |||
*/ | |||
private String title; | |||
/** | |||
* 配置编码 | |||
*/ | |||
private String code; | |||
/** | |||
* 配置值 | |||
*/ | |||
private String value; | |||
/** | |||
* 配置项 | |||
*/ | |||
private String options; | |||
/** | |||
* 配置ID | |||
*/ | |||
private Integer configId; | |||
/** | |||
* 配置类型 | |||
*/ | |||
private String type; | |||
/** | |||
* 状态:1正常 2停用 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 排序 | |||
*/ | |||
private Integer sort; | |||
/** | |||
* 配置说明 | |||
*/ | |||
private String note; | |||
} |
@@ -1,62 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 部门表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-03 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("sys_dept") | |||
public class Dept extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 部门名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 部门编码 | |||
*/ | |||
private String code; | |||
/** | |||
* 部门全称 | |||
*/ | |||
private String fullname; | |||
/** | |||
* 类型:1公司 2子公司 3部门 4小组 | |||
*/ | |||
private Integer type; | |||
/** | |||
* 上级ID | |||
*/ | |||
private Integer pid; | |||
/** | |||
* 排序 | |||
*/ | |||
private Integer sort; | |||
/** | |||
* 备注说明 | |||
*/ | |||
private String note; | |||
} |
@@ -1,46 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 字典类型表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-01 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("sys_dict") | |||
public class Dict extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 字典名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 字典值 | |||
*/ | |||
private String code; | |||
/** | |||
* 显示顺序 | |||
*/ | |||
private Integer sort; | |||
/** | |||
* 字典备注 | |||
*/ | |||
private String note; | |||
} |
@@ -1,56 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 字典项管理表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-01 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("sys_dict_data") | |||
public class DictData extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 字典项名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 字典项值 | |||
*/ | |||
private String code; | |||
/** | |||
* 字典类型ID | |||
*/ | |||
private Integer dictId; | |||
/** | |||
* 状态:1在用 2停用 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 备注 | |||
*/ | |||
private String note; | |||
/** | |||
* 显示顺序 | |||
*/ | |||
private Integer sort; | |||
} |
@@ -1,41 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 职级表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-02 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("sys_level") | |||
public class Level extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 职级名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 状态:1正常 2停用 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 显示顺序 | |||
*/ | |||
private Integer sort; | |||
} |
@@ -1,71 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 登录日志表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-31 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("sys_login_log") | |||
public class LoginLog extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 日志标题 | |||
*/ | |||
private String title; | |||
/** | |||
* 登录账号 | |||
*/ | |||
private String username; | |||
/** | |||
* 登录IP地址 | |||
*/ | |||
private String loginIp; | |||
/** | |||
* 登录地区 | |||
*/ | |||
private String loginLocation; | |||
/** | |||
* 浏览器类型 | |||
*/ | |||
private String browser; | |||
/** | |||
* 操作系统 | |||
*/ | |||
private String os; | |||
/** | |||
* 登录状态:0成功 1失败 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 操作类型:1登录系统 2退出系统 | |||
*/ | |||
private Integer type; | |||
/** | |||
* 登录备注 | |||
*/ | |||
private String note; | |||
} |
@@ -1,113 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import java.util.List; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 系统菜单表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-30 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("sys_menu") | |||
public class Menu extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 父级ID | |||
*/ | |||
private Integer pid; | |||
/** | |||
* 菜单标题 | |||
*/ | |||
private String title; | |||
/** | |||
* 图标 | |||
*/ | |||
private String icon; | |||
/** | |||
* 菜单路径 | |||
*/ | |||
private String path; | |||
/** | |||
* 菜单组件 | |||
*/ | |||
private String component; | |||
/** | |||
* 目标 | |||
*/ | |||
private String target; | |||
/** | |||
* 权限标识 | |||
*/ | |||
private String permission; | |||
/** | |||
* 类型:1目录 2菜单 3节点 | |||
*/ | |||
private Integer type; | |||
/** | |||
* 是否显示:1显示 2不显示 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 是否可见:0可见 1不可见 | |||
*/ | |||
private Integer hide; | |||
/** | |||
* 备注 | |||
*/ | |||
private String note; | |||
/** | |||
* 显示顺序 | |||
*/ | |||
private Integer sort; | |||
/** | |||
* 子级菜单 | |||
*/ | |||
@TableField(exist = false) | |||
private List<Menu> children; | |||
/** | |||
* 是否选中 | |||
*/ | |||
@TableField(exist = false) | |||
private boolean checked; | |||
/** | |||
* 是否打开 | |||
*/ | |||
@TableField(exist = false) | |||
private boolean open; | |||
/** | |||
* 权限节点参数 | |||
*/ | |||
@TableField(exist = false) | |||
private Integer[] checkedList; | |||
} |
@@ -1,57 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 通知公告表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-07 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("sys_notice") | |||
public class Notice extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 通知标题 | |||
*/ | |||
private String title; | |||
/** | |||
* 通知内容 | |||
*/ | |||
private String content; | |||
/** | |||
* 来源:1内部通知 2外部新闻 | |||
*/ | |||
private Integer source; | |||
/** | |||
* 是否置顶:1是 2否 | |||
*/ | |||
private Integer isTop; | |||
/** | |||
* 阅读量 | |||
*/ | |||
private Integer browse; | |||
/** | |||
* 状态:1已发布 2待发布 | |||
*/ | |||
private Integer status; | |||
} |
@@ -1,92 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 操作日志记录 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-31 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("sys_oper_log") | |||
public class OperLog extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 日志标题 | |||
*/ | |||
private String title; | |||
/** | |||
* 业务类型(0其它 1新增 2修改 3删除) | |||
*/ | |||
private Integer logType; | |||
/** | |||
* 操作方法 | |||
*/ | |||
private String operMethod; | |||
/** | |||
* 请求方式 | |||
*/ | |||
private String requestMethod; | |||
/** | |||
* 操作类型:0其他 1后台用户 2WAP用户 | |||
*/ | |||
private Integer operType; | |||
/** | |||
* 操作人员 | |||
*/ | |||
private String operName; | |||
/** | |||
* 请求URL | |||
*/ | |||
private String operUrl; | |||
/** | |||
* 主机地址 | |||
*/ | |||
private String operIp; | |||
/** | |||
* 操作地点 | |||
*/ | |||
private String operLocation; | |||
/** | |||
* 请求参数 | |||
*/ | |||
private String operParam; | |||
/** | |||
* 返回参数 | |||
*/ | |||
private String jsonResult; | |||
/** | |||
* 操作状态(0正常 1异常) | |||
*/ | |||
private Integer status; | |||
/** | |||
* 备注 | |||
*/ | |||
private String note; | |||
} |
@@ -1,42 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 岗位表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-02 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("sys_position") | |||
public class Position extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 岗位名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 状态:1正常 2停用 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 显示顺序 | |||
*/ | |||
private Integer sort; | |||
} |
@@ -1,53 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 系统角色表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-31 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("sys_role") | |||
public class Role extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 角色名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 角色标签 | |||
*/ | |||
private String code; | |||
/** | |||
* 状态:1正常 2禁用 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 备注 | |||
*/ | |||
private String note; | |||
/** | |||
* 排序 | |||
*/ | |||
private Integer sort; | |||
} |
@@ -1,36 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 角色菜单关联表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-30 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("sys_role_menu") | |||
public class RoleMenu extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 角色ID | |||
*/ | |||
private Integer roleId; | |||
/** | |||
* 菜单ID | |||
*/ | |||
private Integer menuId; | |||
} |
@@ -1,121 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.baomidou.mybatisplus.annotation.*; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
/** | |||
* <p> | |||
* 后台租户管理表 | |||
* </p> | |||
* | |||
* @author ww | |||
* @since 2022-12-6 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = false) | |||
@Accessors(chain = true) | |||
@TableName("th_tenant") | |||
public class Tenant implements Serializable { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 用户ID | |||
*/ | |||
/* @TableId(value = "id", type = IdType.AUTO) | |||
private Integer id; | |||
*/ | |||
/** | |||
* 真实姓名 | |||
*/ | |||
private String name; | |||
private String code; | |||
/** | |||
* 关联用户id | |||
*/ | |||
private int userId; | |||
/** | |||
* logo | |||
*/ | |||
private String logo; | |||
/** | |||
*租户类型 | |||
*/ | |||
private Integer type; | |||
/** | |||
* 手机号码 | |||
*/ | |||
private String phone; | |||
/** | |||
* 邮箱地址 | |||
*/ | |||
private String email; | |||
/** | |||
* 平台名称 | |||
*/ | |||
private String platformName; | |||
/** | |||
* 地址 | |||
*/ | |||
private String address; | |||
/** | |||
* 备注 | |||
*/ | |||
private String note; | |||
/** | |||
* 主键ID | |||
*/ | |||
@TableId(value = "id", type = IdType.AUTO) | |||
private Integer id; | |||
/** | |||
* 添加人 | |||
*/ | |||
private Integer createUser; | |||
/** | |||
* 创建时间 | |||
*/ | |||
@TableField(fill = FieldFill.INSERT_UPDATE) | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date createTime; | |||
/** | |||
* 更新人 | |||
*/ | |||
private Integer updateUser; | |||
/** | |||
* 更新时间 | |||
*/ | |||
@TableField(fill = FieldFill.INSERT_UPDATE) | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date updateTime; | |||
/** | |||
* 有效标识 | |||
*/ | |||
private Integer mark; | |||
} |
@@ -1,231 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.baomidou.mybatisplus.annotation.IdType; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
/** | |||
* <p> | |||
* 后台用户管理表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-30 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = false) | |||
@Accessors(chain = true) | |||
@TableName("sys_user") | |||
public class User extends BaseEntity implements Serializable { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 用户ID | |||
*/ | |||
/* @TableId(value = "id", type = IdType.AUTO) | |||
private Integer id; | |||
*/ | |||
/** | |||
* 用户编号 | |||
*/ | |||
private String code; | |||
/** | |||
* 真实姓名 | |||
*/ | |||
private String realname; | |||
/** | |||
* 昵称 | |||
*/ | |||
private String nickname; | |||
/** | |||
* 性别:1男 2女 3保密 | |||
*/ | |||
private Integer gender; | |||
/** | |||
* 头像 | |||
*/ | |||
private String avatar; | |||
/** | |||
* 手机号码 | |||
*/ | |||
private String mobile; | |||
/** | |||
* 邮箱地址 | |||
*/ | |||
private String email; | |||
/** | |||
* 出生日期 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd") | |||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") | |||
private Date birthday; | |||
/** | |||
* 部门ID | |||
*/ | |||
private Integer deptId; | |||
/** | |||
* 职级ID | |||
*/ | |||
private Integer levelId; | |||
/** | |||
* 岗位ID | |||
*/ | |||
private Integer positionId; | |||
/** | |||
* 省份编码 | |||
*/ | |||
private String provinceCode; | |||
/** | |||
* 城市编码 | |||
*/ | |||
private String cityCode; | |||
/** | |||
* 区县编码 | |||
*/ | |||
private String districtCode; | |||
/** | |||
* 详细地址 | |||
*/ | |||
private String address; | |||
/** | |||
* 所属城市 | |||
*/ | |||
private String cityName; | |||
/** | |||
* 登录用户名 | |||
*/ | |||
private String username; | |||
/** | |||
* 登录密码 | |||
*/ | |||
private String password; | |||
/** | |||
* 用户类型:1普通用户 2飞手 | |||
*/ | |||
private Integer type; | |||
/** | |||
* 驾照类型:1飞行执照 2飞行许可证 | |||
*/ | |||
private Integer driverType; | |||
/** | |||
* 驾照编号 | |||
*/ | |||
private String driverCode; | |||
/** | |||
* 盐加密 | |||
*/ | |||
private String salt; | |||
/** | |||
* 个人简介 | |||
*/ | |||
private String intro; | |||
/** | |||
* 状态:1正常 2禁用 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 备注 | |||
*/ | |||
private String note; | |||
/** | |||
* 显示顺序 | |||
*/ | |||
private Integer sort; | |||
/** | |||
* 登录次数 | |||
*/ | |||
private Integer loginNum; | |||
/** | |||
* 最近登录IP | |||
*/ | |||
private String loginIp; | |||
/** | |||
* 最近登录时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date loginTime; | |||
/** | |||
* 添加人 | |||
*/ | |||
/* private Integer createUser; | |||
*//** | |||
* 创建时间 | |||
*//* | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date createTime; | |||
*//** | |||
* 更新人 | |||
*//* | |||
private Integer updateUser; | |||
*//** | |||
* 更新时间 | |||
*//* | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date updateTime; | |||
*//** | |||
* 有效标识 | |||
*//* | |||
private Integer mark;*/ | |||
/** | |||
* 角色ID | |||
*/ | |||
@TableField(exist = false) | |||
private Integer[] roleIds; | |||
/** | |||
* 城市集合 | |||
*/ | |||
@TableField(exist = false) | |||
private String[] city; | |||
} |
@@ -1,36 +0,0 @@ | |||
package com.tuoheng.system.entity; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 人员角色表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-30 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
@TableName("sys_user_role") | |||
public class UserRole extends BaseEntity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 人员ID | |||
*/ | |||
private Integer userId; | |||
/** | |||
* 角色ID | |||
*/ | |||
private Integer roleId; | |||
} |
@@ -1,63 +0,0 @@ | |||
package com.tuoheng.system.filter; | |||
import com.tuoheng.system.constant.ShiroConstants; | |||
import com.tuoheng.system.utils.ShiroUtils; | |||
import org.apache.commons.lang3.StringUtils; | |||
import org.apache.shiro.web.filter.AccessControlFilter; | |||
import javax.servlet.ServletRequest; | |||
import javax.servlet.ServletResponse; | |||
import javax.servlet.http.HttpServletRequest; | |||
public class CaptchaFilter extends AccessControlFilter { | |||
/** | |||
* 是否开启验证码 | |||
*/ | |||
private boolean captchaEnabled = true; | |||
/** | |||
* 验证码类型 | |||
*/ | |||
private String captchaType = "math"; | |||
public void setCaptchaEnabled(boolean captchaEnabled) { | |||
this.captchaEnabled = captchaEnabled; | |||
} | |||
public void setCaptchaType(String captchaType) { | |||
this.captchaType = captchaType; | |||
} | |||
@Override | |||
public boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { | |||
request.setAttribute(ShiroConstants.CURRENT_ENABLED, captchaEnabled); | |||
request.setAttribute(ShiroConstants.CURRENT_TYPE, captchaType); | |||
return super.onPreHandle(request, response, mappedValue); | |||
} | |||
@Override | |||
protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object o) throws Exception { | |||
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; | |||
// 验证码禁用 或不是表单提交 允许访问 | |||
if (captchaEnabled == false || !"post".equals(httpServletRequest.getMethod().toLowerCase())) { | |||
return true; | |||
} | |||
return validateResponse(httpServletRequest, httpServletRequest.getParameter(ShiroConstants.CURRENT_VALIDATECODE)); | |||
} | |||
public boolean validateResponse(HttpServletRequest servletRequest, String validateCode) { | |||
Object obj = ShiroUtils.getSession().getAttribute("captcha"); | |||
String code = String.valueOf(obj != null ? obj : ""); | |||
if (StringUtils.isEmpty(validateCode) || !validateCode.equalsIgnoreCase(code)) { | |||
return false; | |||
} | |||
return true; | |||
} | |||
@Override | |||
protected boolean onAccessDenied(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception { | |||
servletRequest.setAttribute(ShiroConstants.CURRENT_CAPTCHA, ShiroConstants.CAPTCHA_ERROR); | |||
return true; | |||
} | |||
} |
@@ -1,173 +0,0 @@ | |||
package com.tuoheng.system.filter; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.system.entity.User; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.apache.shiro.cache.Cache; | |||
import org.apache.shiro.cache.CacheManager; | |||
import org.apache.shiro.session.Session; | |||
import org.apache.shiro.session.mgt.DefaultSessionKey; | |||
import org.apache.shiro.session.mgt.SessionManager; | |||
import org.apache.shiro.subject.Subject; | |||
import org.apache.shiro.web.filter.AccessControlFilter; | |||
import org.apache.shiro.web.util.WebUtils; | |||
import javax.servlet.ServletRequest; | |||
import javax.servlet.ServletResponse; | |||
import javax.servlet.http.HttpServletRequest; | |||
import java.io.PrintWriter; | |||
import java.io.Serializable; | |||
import java.util.*; | |||
@Slf4j | |||
public class KickoutSessionFilter extends AccessControlFilter { | |||
// 用户被踢出后重定向的地址 | |||
private String kickoutUrl = "/api/"; | |||
// 使用RedisCacheManager 存储的cache前缀名 | |||
public static String ONLINE_USER = "online_user"; | |||
// 踢出当前登录用户还是之前用户 | |||
private boolean kickoutAfter = true; | |||
// 同一个账号最大同时在线人数 | |||
private int maxSession = 1; | |||
// SessionManager session管理器 | |||
private SessionManager sessionManager; | |||
// 缓存 | |||
private Cache<String, LinkedList<Serializable>> cache; | |||
public void setCacheManager(CacheManager cacheManager) { | |||
this.cache = cacheManager.getCache(ONLINE_USER); | |||
} | |||
public void setSessionManager(SessionManager sessionManager) { | |||
this.sessionManager = sessionManager; | |||
} | |||
public void setMaxSession(int maxSession) { | |||
this.maxSession = maxSession; | |||
} | |||
public void setKickoutUrl(String kickoutUrl) { | |||
this.kickoutUrl = kickoutUrl; | |||
} | |||
public void setKickoutBefore(boolean kickoutAfter) { | |||
this.kickoutAfter = kickoutAfter; | |||
} | |||
/** | |||
* 是否允许访问,true表示允许访问 | |||
* @param servletRequest | |||
* @param servletResponse | |||
* @param o | |||
* @return | |||
* @throws Exception | |||
*/ | |||
@Override | |||
protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object o) throws Exception { | |||
return false; | |||
} | |||
/** | |||
* 访问拒绝时是否自己处理,return false表示已经自己处理,true 表示自己不处理,继续由下一个拦截器执行 | |||
* @param request | |||
* @param response | |||
* @return | |||
* @throws Exception | |||
*/ | |||
@Override | |||
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception { | |||
Subject subject = getSubject(request, response); | |||
//如果用户未登录,跳过此过程 | |||
if(!subject.isAuthenticated() && !subject.isRemembered()) { | |||
return true; | |||
} | |||
// -1表示无人数限制 | |||
if (maxSession == -1){ | |||
return true; | |||
} | |||
// 获取当前登录的sessionId | |||
Session session = subject.getSession(); | |||
Serializable sessionId = session.getId(); | |||
// 获取当前登录用户信息 | |||
User user = (User) subject.getPrincipal(); | |||
String username = user.getUsername(); | |||
// 读取当前用户的Redis缓存,没有就创建一个空队列 | |||
LinkedList<Serializable> deque = cache.get(username); | |||
if(deque==null){ | |||
deque = new LinkedList<>(); | |||
} | |||
//如果队列里没有此sessionId,且用户没有被踢出;放入队列 | |||
if(!deque.contains(sessionId) && session.getAttribute("kickout") == null) { | |||
//将sessionId存入队列 | |||
deque.add(sessionId); | |||
//将用户的sessionId队列缓存 | |||
cache.put(username, deque); | |||
} | |||
//如果队列里的sessionId数超出最大会话数,开始踢人 | |||
while(deque.size() > maxSession) { | |||
// 保存待踢出用户的sessionId | |||
Serializable kickoutSessionId = null; | |||
//如果踢出后登录者,更新队列 | |||
if(kickoutAfter) { | |||
kickoutSessionId = deque.removeFirst(); | |||
cache.put(username, deque); | |||
} else { | |||
//否则踢出前者,更新队列 | |||
kickoutSessionId = deque.removeLast(); | |||
cache.put(username, deque); | |||
} | |||
// 对即将踢出的用户标记 | |||
try { | |||
Session kickoutSession = sessionManager.getSession(new DefaultSessionKey(kickoutSessionId)); | |||
if(kickoutSession != null) { | |||
//设置会话的kickout属性表示踢出 | |||
kickoutSession.setAttribute("kickout", true); | |||
} | |||
} catch (Exception e) { | |||
log.error("踢出用户异常!"); | |||
} | |||
} | |||
//如果被踢出了,直接退出,重定向到踢出后的地址 | |||
if (session.getAttribute("kickout")!=null && (Boolean)session.getAttribute("kickout")) { | |||
try { | |||
//退出登录 | |||
subject.logout(); | |||
} catch (Exception e) { //ignore | |||
log.error("用户退出异常!"); | |||
} | |||
// 保存请求 | |||
saveRequest(request); | |||
//若为Ajax请求 | |||
//if ("XMLHttpRequest".equalsIgnoreCase(((HttpServletRequest) request).getHeader("X-Requested-With"))) { | |||
// 自定义ajax返回结果 | |||
try { | |||
response.setContentType("application/json; charset=utf-8"); | |||
response.setCharacterEncoding("UTF-8"); | |||
PrintWriter out = response.getWriter(); | |||
JSONObject result = new JSONObject(); | |||
result.put("msg", "登录过期!"); | |||
result.put("code", 401); | |||
out.println(result); | |||
out.flush(); | |||
out.close(); | |||
} catch (Exception e) { | |||
log.error("未知异常,请联系管理员,或刷新重试!"); | |||
} | |||
/*}else{ | |||
//重定向到踢出地址 | |||
WebUtils.issueRedirect(request, response,"/api"+kickoutUrl); | |||
}*/ | |||
return false; | |||
} | |||
return true; | |||
} | |||
} | |||
@@ -1,54 +0,0 @@ | |||
package com.tuoheng.system.filter; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; | |||
import javax.servlet.ServletRequest; | |||
import javax.servlet.ServletResponse; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
/** | |||
* 自定义登录过滤器 | |||
*/ | |||
public class ShiroLoginFilter extends FormAuthenticationFilter { | |||
/** | |||
* 判断是否登录(已登录状态下不会走此方法) | |||
* | |||
* @param request | |||
* @param response | |||
* @param mappedValue | |||
* @return | |||
*/ | |||
@Override | |||
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) { | |||
if (request instanceof HttpServletRequest) { | |||
if ("OPTIONS".equals(((HttpServletRequest) request).getMethod().toUpperCase())) { | |||
return true; | |||
} | |||
} | |||
return super.isAccessAllowed(request, response, mappedValue); | |||
} | |||
/** | |||
* 是否是拒绝登录(没有登录的情况下会走此方法) | |||
* | |||
* @param request | |||
* @param response | |||
* @return | |||
* @throws Exception | |||
*/ | |||
@Override | |||
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception { | |||
HttpServletResponse httpServletResponse = (HttpServletResponse) response; | |||
httpServletResponse.setHeader("Access-Control-Allow-Origin", ((HttpServletRequest) request).getHeader("Origin")); | |||
httpServletResponse.setHeader("Access-Control-Allow-Credentials", "true"); | |||
httpServletResponse.setCharacterEncoding("UTF-8"); | |||
httpServletResponse.setContentType("application/json"); | |||
JsonResult jsonResult = new JsonResult(); | |||
httpServletResponse.getWriter().write(JSONObject.toJSON(jsonResult.error(401, "请先登录")).toString()); | |||
return false; | |||
} | |||
} |
@@ -1,58 +0,0 @@ | |||
package com.tuoheng.system.filter; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.common.utils.MessageUtils; | |||
import com.tuoheng.common.utils.StringUtils; | |||
import com.tuoheng.system.constant.Constants; | |||
import com.tuoheng.system.entity.User; | |||
import com.tuoheng.system.manager.AsyncFactory; | |||
import com.tuoheng.system.manager.AsyncManager; | |||
import com.tuoheng.system.utils.ShiroUtils; | |||
import org.apache.shiro.cache.Cache; | |||
import org.apache.shiro.session.SessionException; | |||
import org.apache.shiro.subject.Subject; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import javax.servlet.ServletRequest; | |||
import javax.servlet.ServletResponse; | |||
import java.io.Serializable; | |||
import java.util.Deque; | |||
/** | |||
* 退出过滤器 | |||
*/ | |||
public class ShiroLogoutFilter extends org.apache.shiro.web.filter.authc.LogoutFilter { | |||
private static final Logger log = LoggerFactory.getLogger(ShiroLogoutFilter.class); | |||
private Cache<String, Deque<Serializable>> cache; | |||
@Override | |||
protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception { | |||
try { | |||
Subject subject = getSubject(request, response); | |||
try { | |||
User user = ShiroUtils.getUserInfo(); | |||
if (StringUtils.isNotNull(user)) { | |||
String loginName = user.getUsername(); | |||
// 记录用户退出日志 | |||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, Constants.LOGOUT, MessageUtils.message("user.logout.success"))); | |||
// 清理缓存 | |||
cache.remove(loginName); | |||
} | |||
// 退出登录 | |||
subject.logout(); | |||
} catch (SessionException ise) { | |||
log.error("logout fail.", ise); | |||
} | |||
// 提示注销成功 | |||
JsonResult jsonResult = new JsonResult(); | |||
response.getWriter().write(JSONObject.toJSON(jsonResult.success("注销成功")).toString()); | |||
} catch (Exception e) { | |||
log.error("Encountered session exception during logout. This can generally safely be ignored.", e); | |||
} | |||
return false; | |||
} | |||
} |
@@ -1,129 +0,0 @@ | |||
package com.tuoheng.system.manager; | |||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
import com.tuoheng.common.utils.*; | |||
import com.tuoheng.system.constant.Constants; | |||
import com.tuoheng.system.entity.LoginLog; | |||
import com.tuoheng.system.entity.OperLog; | |||
import com.tuoheng.system.entity.Tenant; | |||
import com.tuoheng.system.entity.User; | |||
import com.tuoheng.system.mapper.TenantMapper; | |||
import com.tuoheng.system.query.UserQuery; | |||
import com.tuoheng.system.service.ILoginLogService; | |||
import com.tuoheng.system.service.IOperLogService; | |||
import com.tuoheng.system.service.impl.TenantServiceImpl; | |||
import com.tuoheng.system.service.impl.UserServiceImpl; | |||
import com.tuoheng.system.utils.ShiroUtils; | |||
import eu.bitwalker.useragentutils.UserAgent; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import java.util.List; | |||
import java.util.TimerTask; | |||
/** | |||
* 异步工厂(产生任务用) | |||
*/ | |||
@Slf4j | |||
public class AsyncFactory { | |||
private static final Logger sys_user_logger = LoggerFactory.getLogger("sys-user"); | |||
/** | |||
* 记录登陆信息 | |||
* | |||
* @param username 用户名 | |||
* @param status 状态 | |||
* @param message 消息 | |||
* @param args 列表 | |||
* @return 任务task | |||
*/ | |||
public static TimerTask recordLogininfor(final String username, final String status, final String message, | |||
final Object... args) { | |||
final UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); | |||
final String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); | |||
//final String ip = ShiroUtils.getIp(); | |||
log.info("获取ip地址为:" + ip); | |||
String ipArr[] = ip.split(","); | |||
return new TimerTask() { | |||
@Override | |||
public void run() { | |||
//String address = IpUtils.getRealAddressByIP(ip); | |||
StringBuilder s = new StringBuilder(); | |||
s.append(LogUtils.getBlock(ipArr[0])); | |||
//s.append(address); | |||
s.append(LogUtils.getBlock(username)); | |||
s.append(LogUtils.getBlock(status)); | |||
s.append(LogUtils.getBlock(message)); | |||
// 打印信息到日志 | |||
sys_user_logger.info(s.toString(), args); | |||
// 获取客户端操作系统 | |||
String os = userAgent.getOperatingSystem().getName(); | |||
// 获取客户端浏览器 | |||
String browser = userAgent.getBrowser().getName(); | |||
// 封装对象 | |||
LoginLog loginLog = new LoginLog(); | |||
if (Constants.LOGIN_SUCCESS.equals(status)) { | |||
loginLog.setType(1); | |||
loginLog.setTitle("登录系统"); | |||
} else if (Constants.LOGOUT.equals(status)) { | |||
loginLog.setType(2); | |||
loginLog.setTitle("注销系统"); | |||
} | |||
loginLog.setUsername(username); | |||
loginLog.setLoginIp(ipArr[0]); | |||
//loginLog.setLoginLocation(address); | |||
loginLog.setBrowser(browser); | |||
//add tenantId 2023.1.12 | |||
loginLog.setTenantId(getTenantId(username)); | |||
//end | |||
loginLog.setOs(os); | |||
loginLog.setNote(message); | |||
// 日志状态 | |||
if (Constants.LOGIN_SUCCESS.equals(status) || Constants.LOGOUT.equals(status)) { | |||
loginLog.setStatus(Integer.valueOf(Constants.SUCCESS)); | |||
} else if (Constants.LOGIN_FAIL.equals(status)) { | |||
loginLog.setStatus(Integer.valueOf(Constants.FAIL)); | |||
} | |||
// 插入数据 | |||
SpringUtils.getBean(ILoginLogService.class).insertLoginLog(loginLog); | |||
} | |||
}; | |||
} | |||
/** | |||
* 操作日志记录 | |||
* | |||
* @param operLog 操作日志信息 | |||
* @return 任务task | |||
*/ | |||
public static TimerTask recordOper(final OperLog operLog) { | |||
return new TimerTask() { | |||
@Override | |||
public void run() { | |||
operLog.setTenantId(getTenantId(operLog.getOperName())); | |||
// 远程查询操作地点 | |||
operLog.setOperLocation(IpUtils.getRealAddressByIP(operLog.getOperIp())); | |||
SpringUtils.getBean(IOperLogService.class).insertOperlog(operLog); | |||
} | |||
}; | |||
} | |||
public static int getTenantId(String username){ | |||
//add tenantId 2023.1.12 | |||
QueryWrapper queryWrapper = new QueryWrapper(); | |||
queryWrapper.eq("username",username); | |||
queryWrapper.eq("mark",1); | |||
User user = SpringUtils.getBean(UserServiceImpl.class).getOne(queryWrapper); | |||
if (user.getTenantId()==0){ | |||
queryWrapper =new QueryWrapper(); | |||
queryWrapper.eq("user_id",user.getId()); | |||
queryWrapper.eq("mark",1); | |||
Tenant tenant = SpringUtils.getBean(TenantMapper.class).selectOne(queryWrapper); | |||
return tenant.getId(); | |||
} | |||
return user.getTenantId(); | |||
//end add tenantId | |||
} | |||
} |
@@ -1,53 +0,0 @@ | |||
package com.tuoheng.system.manager; | |||
import com.tuoheng.common.utils.SpringUtils; | |||
import com.tuoheng.common.utils.ThreadUtils; | |||
import java.util.TimerTask; | |||
import java.util.concurrent.ScheduledExecutorService; | |||
import java.util.concurrent.TimeUnit; | |||
/** | |||
* 异步任务管理器 | |||
*/ | |||
public class AsyncManager { | |||
/** | |||
* 操作延迟10毫秒 | |||
*/ | |||
private final int OPERATE_DELAY_TIME = 10; | |||
/** | |||
* 异步操作任务调度线程池 | |||
*/ | |||
private ScheduledExecutorService executor = SpringUtils.getBean("scheduledExecutorService"); | |||
/** | |||
* 单例模式 | |||
*/ | |||
private AsyncManager() { | |||
} | |||
private static AsyncManager me = new AsyncManager(); | |||
public static AsyncManager me() { | |||
return me; | |||
} | |||
/** | |||
* 执行任务 | |||
* | |||
* @param task 任务 | |||
*/ | |||
public void execute(TimerTask task) { | |||
executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS); | |||
} | |||
/** | |||
* 停止任务线程池 | |||
*/ | |||
public void shutdown() { | |||
ThreadUtils.shutdownAndAwaitTermination(executor); | |||
} | |||
} |
@@ -1,34 +0,0 @@ | |||
package com.tuoheng.system.manager; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.stereotype.Component; | |||
import javax.annotation.PreDestroy; | |||
/** | |||
* 确保应用退出时关闭后台线程 | |||
*/ | |||
@Component | |||
public class ShutdownManager { | |||
private static final Logger logger = LoggerFactory.getLogger("sys-user"); | |||
@PreDestroy | |||
public void destroy() { | |||
shutdownAsyncManager(); | |||
} | |||
/** | |||
* 停止异步执行任务 | |||
*/ | |||
private void shutdownAsyncManager() { | |||
try { | |||
logger.info("====关闭后台任务任务线程池===="); | |||
AsyncManager.me().shutdown(); | |||
} catch (Exception e) { | |||
logger.error(e.getMessage(), e); | |||
} | |||
} | |||
} |
@@ -1,16 +0,0 @@ | |||
package com.tuoheng.system.mapper; | |||
import com.tuoheng.system.entity.City; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
/** | |||
* <p> | |||
* 高德城市表 Mapper 接口 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-03 | |||
*/ | |||
public interface CityMapper extends BaseMapper<City> { | |||
} |
@@ -1,16 +0,0 @@ | |||
package com.tuoheng.system.mapper; | |||
import com.tuoheng.system.entity.ConfigData; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
/** | |||
* <p> | |||
* 配置表 Mapper 接口 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
public interface ConfigDataMapper extends BaseMapper<ConfigData> { | |||
} |
@@ -1,16 +0,0 @@ | |||
package com.tuoheng.system.mapper; | |||
import com.tuoheng.system.entity.Config; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
/** | |||
* <p> | |||
* 配置表 Mapper 接口 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-06 | |||
*/ | |||
public interface ConfigMapper extends BaseMapper<Config> { | |||
} |
@@ -1,16 +0,0 @@ | |||
package com.tuoheng.system.mapper; | |||
import com.tuoheng.system.entity.Dept; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
/** | |||
* <p> | |||
* 部门表 Mapper 接口 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-11-03 | |||
*/ | |||
public interface DeptMapper extends BaseMapper<Dept> { | |||
} |