| | |
| | | import com.baomidou.mybatisplus.annotation.*; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.ruoyi.common.constant.GenConstants; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | import lombok.*; |
| | | import lombok.experimental.Accessors; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | |
| | | import javax.validation.Valid; |
| | | import javax.validation.constraints.NotBlank; |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | |
| | | /** |
| | | * 业务表 gen_table |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | |
| | |
| | | @NoArgsConstructor |
| | | @Accessors(chain = true) |
| | | @TableName("gen_table") |
| | | public class GenTable |
| | | { |
| | | public class GenTable implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** 编号 */ |
| | | /** |
| | | * 编号 |
| | | */ |
| | | @TableId(value = "table_id", type = IdType.AUTO) |
| | | private Long tableId; |
| | | |
| | | /** 表名称 */ |
| | | /** |
| | | * 表名称 |
| | | */ |
| | | @NotBlank(message = "表名称不能为空") |
| | | private String tableName; |
| | | |
| | | /** 表描述 */ |
| | | /** |
| | | * 表描述 |
| | | */ |
| | | @NotBlank(message = "表描述不能为空") |
| | | private String tableComment; |
| | | |
| | | /** 关联父表的表名 */ |
| | | /** |
| | | * 关联父表的表名 |
| | | */ |
| | | private String subTableName; |
| | | |
| | | /** 本表关联父表的外键名 */ |
| | | /** |
| | | * 本表关联父表的外键名 |
| | | */ |
| | | private String subTableFkName; |
| | | |
| | | /** 实体类名称(首字母大写) */ |
| | | /** |
| | | * 实体类名称(首字母大写) |
| | | */ |
| | | @NotBlank(message = "实体类名称不能为空") |
| | | private String className; |
| | | |
| | | /** 使用的模板(crud单表操作 tree树表操作 sub主子表操作) */ |
| | | /** |
| | | * 使用的模板(crud单表操作 tree树表操作 sub主子表操作) |
| | | */ |
| | | private String tplCategory; |
| | | |
| | | /** 生成包路径 */ |
| | | /** |
| | | * 生成包路径 |
| | | */ |
| | | @NotBlank(message = "生成包路径不能为空") |
| | | private String packageName; |
| | | |
| | | /** 生成模块名 */ |
| | | /** |
| | | * 生成模块名 |
| | | */ |
| | | @NotBlank(message = "生成模块名不能为空") |
| | | private String moduleName; |
| | | |
| | | /** 生成业务名 */ |
| | | /** |
| | | * 生成业务名 |
| | | */ |
| | | @NotBlank(message = "生成业务名不能为空") |
| | | private String businessName; |
| | | |
| | | /** 生成功能名 */ |
| | | /** |
| | | * 生成功能名 |
| | | */ |
| | | @NotBlank(message = "生成功能名不能为空") |
| | | private String functionName; |
| | | |
| | | /** 生成作者 */ |
| | | /** |
| | | * 生成作者 |
| | | */ |
| | | @NotBlank(message = "作者不能为空") |
| | | private String functionAuthor; |
| | | |
| | | /** 生成代码方式(0zip压缩包 1自定义路径) */ |
| | | /** |
| | | * 生成代码方式(0zip压缩包 1自定义路径) |
| | | */ |
| | | private String genType; |
| | | |
| | | /** 生成路径(不填默认项目路径) */ |
| | | /** |
| | | * 生成路径(不填默认项目路径) |
| | | */ |
| | | private String genPath; |
| | | |
| | | /** 主键信息 */ |
| | | /** |
| | | * 主键信息 |
| | | */ |
| | | @TableField(exist = false) |
| | | private GenTableColumn pkColumn; |
| | | |
| | | /** 子表信息 */ |
| | | /** |
| | | * 子表信息 |
| | | */ |
| | | @TableField(exist = false) |
| | | private GenTable subTable; |
| | | |
| | | /** 表列信息 */ |
| | | /** |
| | | * 表列信息 |
| | | */ |
| | | @Valid |
| | | @TableField(exist = false) |
| | | private List<GenTableColumn> columns; |
| | | |
| | | /** 其它生成选项 */ |
| | | /** |
| | | * 其它生成选项 |
| | | */ |
| | | private String options; |
| | | |
| | | /** |
| | |
| | | @TableField(exist = false) |
| | | private Map<String, Object> params = new HashMap<>(); |
| | | |
| | | /** 树编码字段 */ |
| | | /** |
| | | * 树编码字段 |
| | | */ |
| | | @TableField(exist = false) |
| | | private String treeCode; |
| | | |
| | | /** 树父编码字段 */ |
| | | /** |
| | | * 树父编码字段 |
| | | */ |
| | | @TableField(exist = false) |
| | | private String treeParentCode; |
| | | |
| | | /** 树名称字段 */ |
| | | /** |
| | | * 树名称字段 |
| | | */ |
| | | @TableField(exist = false) |
| | | private String treeName; |
| | | |
| | | /** 上级菜单ID字段 */ |
| | | /** |
| | | * 上级菜单ID字段 |
| | | */ |
| | | @TableField(exist = false) |
| | | private String parentMenuId; |
| | | |
| | | /** 上级菜单名称字段 */ |
| | | /** |
| | | * 上级菜单名称字段 |
| | | */ |
| | | @TableField(exist = false) |
| | | private String parentMenuName; |
| | | |
| | | public boolean isSub() |
| | | { |
| | | public boolean isSub() { |
| | | return isSub(this.tplCategory); |
| | | } |
| | | |
| | | public static boolean isSub(String tplCategory) |
| | | { |
| | | public static boolean isSub(String tplCategory) { |
| | | return tplCategory != null && StrUtil.equals(GenConstants.TPL_SUB, tplCategory); |
| | | } |
| | | |
| | | public boolean isTree() |
| | | { |
| | | public boolean isTree() { |
| | | return isTree(this.tplCategory); |
| | | } |
| | | |
| | | public static boolean isTree(String tplCategory) |
| | | { |
| | | public static boolean isTree(String tplCategory) { |
| | | return tplCategory != null && StrUtil.equals(GenConstants.TPL_TREE, tplCategory); |
| | | } |
| | | |
| | | public boolean isCrud() |
| | | { |
| | | public boolean isCrud() { |
| | | return isCrud(this.tplCategory); |
| | | } |
| | | |
| | | public static boolean isCrud(String tplCategory) |
| | | { |
| | | public static boolean isCrud(String tplCategory) { |
| | | return tplCategory != null && StrUtil.equals(GenConstants.TPL_CRUD, tplCategory); |
| | | } |
| | | |
| | | public boolean isSuperColumn(String javaField) |
| | | { |
| | | public boolean isSuperColumn(String javaField) { |
| | | return isSuperColumn(this.tplCategory, javaField); |
| | | } |
| | | |
| | | public static boolean isSuperColumn(String tplCategory, String javaField) |
| | | { |
| | | if (isTree(tplCategory)) |
| | | { |
| | | public static boolean isSuperColumn(String tplCategory, String javaField) { |
| | | if (isTree(tplCategory)) { |
| | | return StrUtil.equalsAnyIgnoreCase(javaField, |
| | | ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY)); |
| | | } |
| | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.annotation.*; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.ruoyi.common.core.domain.BaseEntity; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | import lombok.*; |
| | | import lombok.experimental.Accessors; |
| | | |
| | | import javax.validation.constraints.NotBlank; |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 代码生成业务字段表 gen_table_column |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | |
| | |
| | | @NoArgsConstructor |
| | | @Accessors(chain = true) |
| | | @TableName("gen_table_column") |
| | | public class GenTableColumn extends BaseEntity |
| | | { |
| | | public class GenTableColumn implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** 编号 */ |
| | | /** |
| | | * 编号 |
| | | */ |
| | | @TableId(value = "column_id", type = IdType.AUTO) |
| | | private Long columnId; |
| | | |
| | | /** 归属表编号 */ |
| | | /** |
| | | * 归属表编号 |
| | | */ |
| | | private Long tableId; |
| | | |
| | | /** 列名称 */ |
| | | /** |
| | | * 列名称 |
| | | */ |
| | | private String columnName; |
| | | |
| | | /** 列描述 */ |
| | | /** |
| | | * 列描述 |
| | | */ |
| | | private String columnComment; |
| | | |
| | | /** 列类型 */ |
| | | /** |
| | | * 列类型 |
| | | */ |
| | | private String columnType; |
| | | |
| | | /** JAVA类型 */ |
| | | /** |
| | | * JAVA类型 |
| | | */ |
| | | private String javaType; |
| | | |
| | | /** JAVA字段名 */ |
| | | /** |
| | | * JAVA字段名 |
| | | */ |
| | | @NotBlank(message = "Java属性不能为空") |
| | | private String javaField; |
| | | |
| | | /** 是否主键(1是) */ |
| | | /** |
| | | * 是否主键(1是) |
| | | */ |
| | | private String isPk; |
| | | |
| | | /** 是否自增(1是) */ |
| | | /** |
| | | * 是否自增(1是) |
| | | */ |
| | | private String isIncrement; |
| | | |
| | | /** 是否必填(1是) */ |
| | | /** |
| | | * 是否必填(1是) |
| | | */ |
| | | private String isRequired; |
| | | |
| | | /** 是否为插入字段(1是) */ |
| | | /** |
| | | * 是否为插入字段(1是) |
| | | */ |
| | | private String isInsert; |
| | | |
| | | /** 是否编辑字段(1是) */ |
| | | /** |
| | | * 是否编辑字段(1是) |
| | | */ |
| | | private String isEdit; |
| | | |
| | | /** 是否列表字段(1是) */ |
| | | /** |
| | | * 是否列表字段(1是) |
| | | */ |
| | | private String isList; |
| | | |
| | | /** 是否查询字段(1是) */ |
| | | /** |
| | | * 是否查询字段(1是) |
| | | */ |
| | | private String isQuery; |
| | | |
| | | /** 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围) */ |
| | | /** |
| | | * 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围) |
| | | */ |
| | | private String queryType; |
| | | |
| | | /** 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、image图片上传控件、upload文件上传控件、editor富文本控件) */ |
| | | /** |
| | | * 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、image图片上传控件、upload文件上传控件、editor富文本控件) |
| | | */ |
| | | private String htmlType; |
| | | |
| | | /** 字典类型 */ |
| | | /** |
| | | * 字典类型 |
| | | */ |
| | | private String dictType; |
| | | |
| | | /** 排序 */ |
| | | /** |
| | | * 排序 |
| | | */ |
| | | private Integer sort; |
| | | |
| | | /** |
| | |
| | | @TableField(exist = false) |
| | | private Map<String, Object> params = new HashMap<>(); |
| | | |
| | | public String getCapJavaField() |
| | | { |
| | | public String getCapJavaField() { |
| | | return StrUtil.upperFirst(javaField); |
| | | } |
| | | |
| | | public boolean isPk() |
| | | { |
| | | public boolean isPk() { |
| | | return isPk(this.isPk); |
| | | } |
| | | |
| | | public boolean isPk(String isPk) |
| | | { |
| | | public boolean isPk(String isPk) { |
| | | return isPk != null && StrUtil.equals("1", isPk); |
| | | } |
| | | |
| | | public boolean isIncrement() |
| | | { |
| | | public boolean isIncrement() { |
| | | return isIncrement(this.isIncrement); |
| | | } |
| | | |
| | | public boolean isIncrement(String isIncrement) |
| | | { |
| | | public boolean isIncrement(String isIncrement) { |
| | | return isIncrement != null && StrUtil.equals("1", isIncrement); |
| | | } |
| | | |
| | | public boolean isRequired() |
| | | { |
| | | public boolean isRequired() { |
| | | return isRequired(this.isRequired); |
| | | } |
| | | |
| | | public boolean isRequired(String isRequired) |
| | | { |
| | | public boolean isRequired(String isRequired) { |
| | | return isRequired != null && StrUtil.equals("1", isRequired); |
| | | } |
| | | |
| | | public boolean isInsert() |
| | | { |
| | | public boolean isInsert() { |
| | | return isInsert(this.isInsert); |
| | | } |
| | | |
| | | public boolean isInsert(String isInsert) |
| | | { |
| | | public boolean isInsert(String isInsert) { |
| | | return isInsert != null && StrUtil.equals("1", isInsert); |
| | | } |
| | | |
| | | public boolean isEdit() |
| | | { |
| | | public boolean isEdit() { |
| | | return isInsert(this.isEdit); |
| | | } |
| | | |
| | | public boolean isEdit(String isEdit) |
| | | { |
| | | public boolean isEdit(String isEdit) { |
| | | return isEdit != null && StrUtil.equals("1", isEdit); |
| | | } |
| | | |
| | | public boolean isList() |
| | | { |
| | | public boolean isList() { |
| | | return isList(this.isList); |
| | | } |
| | | |
| | | public boolean isList(String isList) |
| | | { |
| | | public boolean isList(String isList) { |
| | | return isList != null && StrUtil.equals("1", isList); |
| | | } |
| | | |
| | | public boolean isQuery() |
| | | { |
| | | public boolean isQuery() { |
| | | return isQuery(this.isQuery); |
| | | } |
| | | |
| | | public boolean isQuery(String isQuery) |
| | | { |
| | | public boolean isQuery(String isQuery) { |
| | | return isQuery != null && StrUtil.equals("1", isQuery); |
| | | } |
| | | |
| | | public boolean isSuperColumn() |
| | | { |
| | | public boolean isSuperColumn() { |
| | | return isSuperColumn(this.javaField); |
| | | } |
| | | |
| | | public static boolean isSuperColumn(String javaField) |
| | | { |
| | | public static boolean isSuperColumn(String javaField) { |
| | | return StrUtil.equalsAnyIgnoreCase(javaField, |
| | | // BaseEntity |
| | | "createBy", "createTime", "updateBy", "updateTime", "remark", |
| | |
| | | "parentName", "parentId", "orderNum", "ancestors"); |
| | | } |
| | | |
| | | public boolean isUsableColumn() |
| | | { |
| | | public boolean isUsableColumn() { |
| | | return isUsableColumn(javaField); |
| | | } |
| | | |
| | | public static boolean isUsableColumn(String javaField) |
| | | { |
| | | public static boolean isUsableColumn(String javaField) { |
| | | // isSuperColumn()中的名单用于避免生成多余Domain属性,若某些属性在生成页面时需要用到不能忽略,则放在此处白名单 |
| | | return StrUtil.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark"); |
| | | } |
| | | |
| | | public String readConverterExp() |
| | | { |
| | | public String readConverterExp() { |
| | | String remarks = StrUtil.subBetween(this.columnComment, "(", ")"); |
| | | StringBuffer sb = new StringBuffer(); |
| | | if (StrUtil.isNotEmpty(remarks)) |
| | | { |
| | | for (String value : remarks.split(" ")) |
| | | { |
| | | if (StrUtil.isNotEmpty(value)) |
| | | { |
| | | if (StrUtil.isNotEmpty(remarks)) { |
| | | for (String value : remarks.split(" ")) { |
| | | if (StrUtil.isNotEmpty(value)) { |
| | | Object startStr = value.subSequence(0, 1); |
| | | String endStr = value.substring(1); |
| | | sb.append("").append(startStr).append("=").append(endStr).append(","); |
| | | } |
| | | } |
| | | return sb.deleteCharAt(sb.length() - 1).toString(); |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | return this.columnComment; |
| | | } |
| | | } |
| | |
| | | |
| | | /** |
| | | * 业务字段 数据层 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public interface GenTableColumnMapper extends BaseMapper<GenTableColumn> |
| | | { |
| | | public interface GenTableColumnMapper extends BaseMapper<GenTableColumn> { |
| | | /** |
| | | * 根据表名称查询列信息 |
| | | * |
| | | * |
| | | * @param tableName 表名称 |
| | | * @return 列信息 |
| | | */ |
| | | public List<GenTableColumn> selectDbTableColumnsByName(String tableName); |
| | | |
| | | /** |
| | | * 查询业务字段列表 |
| | | * |
| | | * @param tableId 业务字段编号 |
| | | * @return 业务字段集合 |
| | | */ |
| | | public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId); |
| | | |
| | | /** |
| | | * 新增业务字段 |
| | | * |
| | | * @param genTableColumn 业务字段信息 |
| | | * @return 结果 |
| | | */ |
| | | public int insertGenTableColumn(GenTableColumn genTableColumn); |
| | | |
| | | /** |
| | | * 修改业务字段 |
| | | * |
| | | * @param genTableColumn 业务字段信息 |
| | | * @return 结果 |
| | | */ |
| | | public int updateGenTableColumn(GenTableColumn genTableColumn); |
| | | |
| | | /** |
| | | * 删除业务字段 |
| | | * |
| | | * @param genTableColumns 列数据 |
| | | * @return 结果 |
| | | */ |
| | | public int deleteGenTableColumns(List<GenTableColumn> genTableColumns); |
| | | |
| | | /** |
| | | * 批量删除业务字段 |
| | | * |
| | | * @param ids 需要删除的数据ID |
| | | * @return 结果 |
| | | */ |
| | | public int deleteGenTableColumnByIds(Long[] ids); |
| | | } |
| | |
| | | |
| | | /** |
| | | * 业务 数据层 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public interface GenTableMapper extends BaseMapper<GenTable> |
| | | { |
| | | public interface GenTableMapper extends BaseMapper<GenTable> { |
| | | /** |
| | | * 查询业务列表 |
| | | * |
| | | * |
| | | * @param genTable 业务信息 |
| | | * @return 业务集合 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 查询据库列表 |
| | | * |
| | | * |
| | | * @param genTable 业务信息 |
| | | * @return 数据库表集合 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 查询据库列表 |
| | | * |
| | | * |
| | | * @param tableNames 表名称组 |
| | | * @return 数据库表集合 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 查询表ID业务信息 |
| | | * |
| | | * |
| | | * @param id 业务ID |
| | | * @return 业务信息 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 查询表名称业务信息 |
| | | * |
| | | * |
| | | * @param tableName 表名称 |
| | | * @return 业务信息 |
| | | */ |
| | | public GenTable selectGenTableByName(String tableName); |
| | | |
| | | /** |
| | | * 新增业务 |
| | | * |
| | | * @param genTable 业务信息 |
| | | * @return 结果 |
| | | */ |
| | | public int insertGenTable(GenTable genTable); |
| | | |
| | | /** |
| | | * 修改业务 |
| | | * |
| | | * @param genTable 业务信息 |
| | | * @return 结果 |
| | | */ |
| | | public int updateGenTable(GenTable genTable); |
| | | |
| | | /** |
| | | * 批量删除业务 |
| | | * |
| | | * @param ids 需要删除的数据ID |
| | | * @return 结果 |
| | | */ |
| | | public int deleteGenTableByIds(Long[] ids); |
| | | } |
| | |
| | | package com.ruoyi.generator.service; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import cn.hutool.core.convert.Convert; |
| | | import com.ruoyi.generator.domain.GenTableColumn; |
| | | import com.ruoyi.generator.mapper.GenTableColumnMapper; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 业务字段 服务层实现 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper, GenTableColumn> implements IGenTableColumnService |
| | | { |
| | | @Autowired |
| | | private GenTableColumnMapper genTableColumnMapper; |
| | | public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper, GenTableColumn> implements IGenTableColumnService { |
| | | |
| | | /** |
| | | /** |
| | | * 查询业务字段列表 |
| | | * |
| | | * |
| | | * @param tableId 业务字段编号 |
| | | * @return 业务字段集合 |
| | | */ |
| | | @Override |
| | | public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) |
| | | { |
| | | return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); |
| | | } |
| | | |
| | | @Override |
| | | public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) { |
| | | return list(new LambdaQueryWrapper<GenTableColumn>() |
| | | .eq(GenTableColumn::getTableId,tableId) |
| | | .orderByAsc(GenTableColumn::getSort)); |
| | | } |
| | | |
| | | /** |
| | | * 新增业务字段 |
| | | * |
| | | * |
| | | * @param genTableColumn 业务字段信息 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertGenTableColumn(GenTableColumn genTableColumn) |
| | | { |
| | | return genTableColumnMapper.insertGenTableColumn(genTableColumn); |
| | | } |
| | | |
| | | /** |
| | | * 修改业务字段 |
| | | * |
| | | * @param genTableColumn 业务字段信息 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateGenTableColumn(GenTableColumn genTableColumn) |
| | | { |
| | | return genTableColumnMapper.updateGenTableColumn(genTableColumn); |
| | | } |
| | | @Override |
| | | public int insertGenTableColumn(GenTableColumn genTableColumn) { |
| | | return baseMapper.insert(genTableColumn); |
| | | } |
| | | |
| | | /** |
| | | /** |
| | | * 修改业务字段 |
| | | * |
| | | * @param genTableColumn 业务字段信息 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateGenTableColumn(GenTableColumn genTableColumn) { |
| | | return baseMapper.updateById(genTableColumn); |
| | | } |
| | | |
| | | /** |
| | | * 删除业务字段对象 |
| | | * |
| | | * |
| | | * @param ids 需要删除的数据ID |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteGenTableColumnByIds(String ids) |
| | | { |
| | | return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids)); |
| | | } |
| | | @Override |
| | | public int deleteGenTableColumnByIds(String ids) { |
| | | return baseMapper.deleteBatchIds(Arrays.asList(ids.split(","))); |
| | | } |
| | | } |
| | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.GenConstants; |
| | |
| | | import com.ruoyi.generator.util.GenUtils; |
| | | import com.ruoyi.generator.util.VelocityInitializer; |
| | | import com.ruoyi.generator.util.VelocityUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.velocity.Template; |
| | | import org.apache.velocity.VelocityContext; |
| | | import org.apache.velocity.app.Velocity; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.StringWriter; |
| | | import java.util.Arrays; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | |
| | | /** |
| | | * 业务 服务层实现 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> implements IGenTableService |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class); |
| | | |
| | | @Autowired |
| | | private GenTableMapper genTableMapper; |
| | | public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> implements IGenTableService { |
| | | |
| | | @Autowired |
| | | private GenTableColumnMapper genTableColumnMapper; |
| | | |
| | | /** |
| | | * 查询业务信息 |
| | | * |
| | | * |
| | | * @param id 业务ID |
| | | * @return 业务信息 |
| | | */ |
| | | @Override |
| | | public GenTable selectGenTableById(Long id) |
| | | { |
| | | GenTable genTable = genTableMapper.selectGenTableById(id); |
| | | public GenTable selectGenTableById(Long id) { |
| | | GenTable genTable = baseMapper.selectGenTableById(id); |
| | | setTableFromOptions(genTable); |
| | | return genTable; |
| | | } |
| | | |
| | | /** |
| | | * 查询业务列表 |
| | | * |
| | | * |
| | | * @param genTable 业务信息 |
| | | * @return 业务集合 |
| | | */ |
| | | @Override |
| | | public List<GenTable> selectGenTableList(GenTable genTable) |
| | | { |
| | | return genTableMapper.selectGenTableList(genTable); |
| | | public List<GenTable> selectGenTableList(GenTable genTable) { |
| | | return baseMapper.selectGenTableList(genTable); |
| | | } |
| | | |
| | | /** |
| | | * 查询据库列表 |
| | | * |
| | | * |
| | | * @param genTable 业务信息 |
| | | * @return 数据库表集合 |
| | | */ |
| | | @Override |
| | | public List<GenTable> selectDbTableList(GenTable genTable) |
| | | { |
| | | return genTableMapper.selectDbTableList(genTable); |
| | | public List<GenTable> selectDbTableList(GenTable genTable) { |
| | | return baseMapper.selectDbTableList(genTable); |
| | | } |
| | | |
| | | /** |
| | | * 查询据库列表 |
| | | * |
| | | * |
| | | * @param tableNames 表名称组 |
| | | * @return 数据库表集合 |
| | | */ |
| | | @Override |
| | | public List<GenTable> selectDbTableListByNames(String[] tableNames) |
| | | { |
| | | return genTableMapper.selectDbTableListByNames(tableNames); |
| | | public List<GenTable> selectDbTableListByNames(String[] tableNames) { |
| | | return baseMapper.selectDbTableListByNames(tableNames); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 表信息集合 |
| | | */ |
| | | @Override |
| | | public List<GenTable> selectGenTableAll() |
| | | { |
| | | return genTableMapper.selectGenTableAll(); |
| | | public List<GenTable> selectGenTableAll() { |
| | | return baseMapper.selectGenTableAll(); |
| | | } |
| | | |
| | | /** |
| | | * 修改业务 |
| | | * |
| | | * |
| | | * @param genTable 业务信息 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void updateGenTable(GenTable genTable) |
| | | { |
| | | 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); |
| | | int row = baseMapper.updateById(genTable); |
| | | if (row > 0) { |
| | | for (GenTableColumn cenTableColumn : genTable.getColumns()) { |
| | | genTableColumnMapper.updateById(cenTableColumn); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除业务对象 |
| | | * |
| | | * |
| | | * @param tableIds 需要删除的数据ID |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void deleteGenTableByIds(Long[] tableIds) |
| | | { |
| | | genTableMapper.deleteGenTableByIds(tableIds); |
| | | genTableColumnMapper.deleteGenTableColumnByIds(tableIds); |
| | | public void deleteGenTableByIds(Long[] tableIds) { |
| | | List<Long> ids = Arrays.asList(tableIds); |
| | | removeByIds(ids); |
| | | genTableColumnMapper.delete(new LambdaQueryWrapper<GenTableColumn>().in(GenTableColumn::getTableId, ids)); |
| | | } |
| | | |
| | | /** |
| | | * 导入表结构 |
| | | * |
| | | * |
| | | * @param tableList 导入表列表 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void importGenTable(List<GenTable> tableList) |
| | | { |
| | | public void importGenTable(List<GenTable> tableList) { |
| | | String operName = SecurityUtils.getUsername(); |
| | | try |
| | | { |
| | | for (GenTable table : tableList) |
| | | { |
| | | try { |
| | | for (GenTable table : tableList) { |
| | | String tableName = table.getTableName(); |
| | | GenUtils.initTable(table, operName); |
| | | int row = genTableMapper.insertGenTable(table); |
| | | if (row > 0) |
| | | { |
| | | int row = baseMapper.insert(table); |
| | | if (row > 0) { |
| | | // 保存列信息 |
| | | List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); |
| | | for (GenTableColumn column : genTableColumns) |
| | | { |
| | | for (GenTableColumn column : genTableColumns) { |
| | | GenUtils.initColumnField(column, table); |
| | | genTableColumnMapper.insertGenTableColumn(column); |
| | | genTableColumnMapper.insert(column); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | } catch (Exception e) { |
| | | throw new CustomException("导入失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 预览代码 |
| | | * |
| | | * |
| | | * @param tableId 表编号 |
| | | * @return 预览数据列表 |
| | | */ |
| | | @Override |
| | | public Map<String, String> previewCode(Long tableId) |
| | | { |
| | | public Map<String, String> previewCode(Long tableId) { |
| | | Map<String, String> dataMap = new LinkedHashMap<>(); |
| | | // 查询表信息 |
| | | GenTable table = genTableMapper.selectGenTableById(tableId); |
| | | GenTable table = baseMapper.selectGenTableById(tableId); |
| | | // 设置主子表信息 |
| | | setSubTable(table); |
| | | // 设置主键列信息 |
| | |
| | | |
| | | // 获取模板列表 |
| | | List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); |
| | | for (String template : templates) |
| | | { |
| | | for (String template : templates) { |
| | | // 渲染模板 |
| | | StringWriter sw = new StringWriter(); |
| | | Template tpl = Velocity.getTemplate(template, Constants.UTF8); |
| | |
| | | |
| | | /** |
| | | * 生成代码(下载方式) |
| | | * |
| | | * |
| | | * @param tableName 表名称 |
| | | * @return 数据 |
| | | */ |
| | | @Override |
| | | public byte[] downloadCode(String tableName) |
| | | { |
| | | public byte[] downloadCode(String tableName) { |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | ZipOutputStream zip = new ZipOutputStream(outputStream); |
| | | generatorCode(tableName, zip); |
| | |
| | | |
| | | /** |
| | | * 生成代码(自定义路径) |
| | | * |
| | | * |
| | | * @param tableName 表名称 |
| | | */ |
| | | @Override |
| | | public void generatorCode(String tableName) |
| | | { |
| | | public void generatorCode(String tableName) { |
| | | // 查询表信息 |
| | | GenTable table = genTableMapper.selectGenTableByName(tableName); |
| | | GenTable table = baseMapper.selectGenTableByName(tableName); |
| | | // 设置主子表信息 |
| | | setSubTable(table); |
| | | // 设置主键列信息 |
| | |
| | | |
| | | // 获取模板列表 |
| | | List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); |
| | | for (String template : templates) |
| | | { |
| | | if (!StrUtil.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) |
| | | { |
| | | for (String template : templates) { |
| | | if (!StrUtil.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) { |
| | | // 渲染模板 |
| | | StringWriter sw = new StringWriter(); |
| | | Template tpl = Velocity.getTemplate(template, Constants.UTF8); |
| | | tpl.merge(context, sw); |
| | | try |
| | | { |
| | | try { |
| | | String path = getGenPath(table, template); |
| | | FileUtils.writeStringToFile(new File(path), sw.toString(), Constants.UTF8); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | } catch (IOException e) { |
| | | throw new CustomException("渲染模板失败,表名:" + table.getTableName()); |
| | | } |
| | | } |
| | |
| | | |
| | | /** |
| | | * 同步数据库 |
| | | * |
| | | * |
| | | * @param tableName 表名称 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void synchDb(String tableName) |
| | | { |
| | | GenTable table = genTableMapper.selectGenTableByName(tableName); |
| | | public void synchDb(String tableName) { |
| | | GenTable table = baseMapper.selectGenTableByName(tableName); |
| | | List<GenTableColumn> tableColumns = table.getColumns(); |
| | | List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); |
| | | |
| | | List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); |
| | | if (Validator.isEmpty(dbTableColumns)) |
| | | { |
| | | if (Validator.isEmpty(dbTableColumns)) { |
| | | throw new CustomException("同步数据失败,原表结构不存在"); |
| | | } |
| | | List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); |
| | | |
| | | dbTableColumns.forEach(column -> { |
| | | if (!tableColumnNames.contains(column.getColumnName())) |
| | | { |
| | | if (!tableColumnNames.contains(column.getColumnName())) { |
| | | GenUtils.initColumnField(column, table); |
| | | genTableColumnMapper.insertGenTableColumn(column); |
| | | genTableColumnMapper.insert(column); |
| | | } |
| | | }); |
| | | |
| | | List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList()); |
| | | if (CollUtil.isNotEmpty(delColumns)) |
| | | { |
| | | genTableColumnMapper.deleteGenTableColumns(delColumns); |
| | | if (CollUtil.isNotEmpty(delColumns)) { |
| | | List<Long> ids = delColumns.stream().map(GenTableColumn::getColumnId).collect(Collectors.toList()); |
| | | genTableColumnMapper.deleteBatchIds(ids); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 批量生成代码(下载方式) |
| | | * |
| | | * |
| | | * @param tableNames 表数组 |
| | | * @return 数据 |
| | | */ |
| | | @Override |
| | | public byte[] downloadCode(String[] tableNames) |
| | | { |
| | | public byte[] downloadCode(String[] tableNames) { |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | ZipOutputStream zip = new ZipOutputStream(outputStream); |
| | | for (String tableName : tableNames) |
| | | { |
| | | for (String tableName : tableNames) { |
| | | generatorCode(tableName, zip); |
| | | } |
| | | IOUtils.closeQuietly(zip); |
| | |
| | | /** |
| | | * 查询表信息并生成代码 |
| | | */ |
| | | private void generatorCode(String tableName, ZipOutputStream zip) |
| | | { |
| | | private void generatorCode(String tableName, ZipOutputStream zip) { |
| | | // 查询表信息 |
| | | GenTable table = genTableMapper.selectGenTableByName(tableName); |
| | | GenTable table = baseMapper.selectGenTableByName(tableName); |
| | | // 设置主子表信息 |
| | | setSubTable(table); |
| | | // 设置主键列信息 |
| | |
| | | |
| | | // 获取模板列表 |
| | | List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); |
| | | for (String template : templates) |
| | | { |
| | | for (String template : templates) { |
| | | // 渲染模板 |
| | | StringWriter sw = new StringWriter(); |
| | | Template tpl = Velocity.getTemplate(template, Constants.UTF8); |
| | | tpl.merge(context, sw); |
| | | try |
| | | { |
| | | try { |
| | | // 添加到zip |
| | | zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); |
| | | IOUtils.write(sw.toString(), zip, Constants.UTF8); |
| | | IOUtils.closeQuietly(sw); |
| | | zip.flush(); |
| | | zip.flush(); |
| | | zip.closeEntry(); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | } catch (IOException e) { |
| | | log.error("渲染模板失败,表名:" + table.getTableName(), e); |
| | | } |
| | | } |
| | |
| | | |
| | | /** |
| | | * 修改保存参数校验 |
| | | * |
| | | * |
| | | * @param genTable 业务信息 |
| | | */ |
| | | @Override |
| | | public void validateEdit(GenTable genTable) |
| | | { |
| | | if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) |
| | | { |
| | | public void validateEdit(GenTable genTable) { |
| | | if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { |
| | | String options = JSON.toJSONString(genTable.getParams()); |
| | | JSONObject paramsObj = JSONObject.parseObject(options); |
| | | if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) |
| | | { |
| | | if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) { |
| | | throw new CustomException("树编码字段不能为空"); |
| | | } |
| | | else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) |
| | | { |
| | | } else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) { |
| | | throw new CustomException("树父编码字段不能为空"); |
| | | } |
| | | else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) |
| | | { |
| | | } else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) { |
| | | throw new CustomException("树名称字段不能为空"); |
| | | } |
| | | else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) |
| | | { |
| | | if (Validator.isEmpty(genTable.getSubTableName())) |
| | | { |
| | | } else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) { |
| | | if (Validator.isEmpty(genTable.getSubTableName())) { |
| | | throw new CustomException("关联子表的表名不能为空"); |
| | | } |
| | | else if (Validator.isEmpty(genTable.getSubTableFkName())) |
| | | { |
| | | } else if (Validator.isEmpty(genTable.getSubTableFkName())) { |
| | | throw new CustomException("子表关联的外键名不能为空"); |
| | | } |
| | | } |
| | |
| | | |
| | | /** |
| | | * 设置主键列信息 |
| | | * |
| | | * |
| | | * @param table 业务表信息 |
| | | */ |
| | | public void setPkColumn(GenTable table) |
| | | { |
| | | for (GenTableColumn column : table.getColumns()) |
| | | { |
| | | if (column.isPk()) |
| | | { |
| | | public void setPkColumn(GenTable table) { |
| | | for (GenTableColumn column : table.getColumns()) { |
| | | if (column.isPk()) { |
| | | table.setPkColumn(column); |
| | | break; |
| | | } |
| | | } |
| | | if (Validator.isNull(table.getPkColumn())) |
| | | { |
| | | if (Validator.isNull(table.getPkColumn())) { |
| | | table.setPkColumn(table.getColumns().get(0)); |
| | | } |
| | | if (GenConstants.TPL_SUB.equals(table.getTplCategory())) |
| | | { |
| | | for (GenTableColumn column : table.getSubTable().getColumns()) |
| | | { |
| | | if (column.isPk()) |
| | | { |
| | | if (GenConstants.TPL_SUB.equals(table.getTplCategory())) { |
| | | for (GenTableColumn column : table.getSubTable().getColumns()) { |
| | | if (column.isPk()) { |
| | | table.getSubTable().setPkColumn(column); |
| | | break; |
| | | } |
| | | } |
| | | if (Validator.isNull(table.getSubTable().getPkColumn())) |
| | | { |
| | | if (Validator.isNull(table.getSubTable().getPkColumn())) { |
| | | table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0)); |
| | | } |
| | | } |
| | |
| | | * |
| | | * @param table 业务表信息 |
| | | */ |
| | | public void setSubTable(GenTable table) |
| | | { |
| | | public void setSubTable(GenTable table) { |
| | | String subTableName = table.getSubTableName(); |
| | | if (Validator.isNotEmpty(subTableName)) |
| | | { |
| | | table.setSubTable(genTableMapper.selectGenTableByName(subTableName)); |
| | | if (Validator.isNotEmpty(subTableName)) { |
| | | table.setSubTable(baseMapper.selectGenTableByName(subTableName)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置代码生成其他选项值 |
| | | * |
| | | * |
| | | * @param genTable 设置后的生成对象 |
| | | */ |
| | | public void setTableFromOptions(GenTable genTable) |
| | | { |
| | | public void setTableFromOptions(GenTable genTable) { |
| | | JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions()); |
| | | if (Validator.isNotNull(paramsObj)) |
| | | { |
| | | if (Validator.isNotNull(paramsObj)) { |
| | | String treeCode = paramsObj.getString(GenConstants.TREE_CODE); |
| | | String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE); |
| | | String treeName = paramsObj.getString(GenConstants.TREE_NAME); |
| | | String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID); |
| | | String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME); |
| | | |
| | | |
| | | genTable.setTreeCode(treeCode); |
| | | genTable.setTreeParentCode(treeParentCode); |
| | | genTable.setTreeName(treeName); |
| | |
| | | |
| | | /** |
| | | * 获取代码生成地址 |
| | | * |
| | | * @param table 业务表信息 |
| | | * |
| | | * @param table 业务表信息 |
| | | * @param template 模板文件路径 |
| | | * @return 生成地址 |
| | | */ |
| | | public static String getGenPath(GenTable table, String template) |
| | | { |
| | | public static String getGenPath(GenTable table, String template) { |
| | | String genPath = table.getGenPath(); |
| | | if (StrUtil.equals(genPath, "/")) |
| | | { |
| | | if (StrUtil.equals(genPath, "/")) { |
| | | return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table); |
| | | } |
| | | return genPath + File.separator + VelocityUtils.getFileName(template, table); |
| | |
| | | |
| | | /** |
| | | * 业务字段 服务层 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public interface IGenTableColumnService extends IService<GenTableColumn> |
| | | { |
| | | public interface IGenTableColumnService extends IService<GenTableColumn> { |
| | | /** |
| | | * 查询业务字段列表 |
| | | * |
| | | * |
| | | * @param tableId 业务字段编号 |
| | | * @return 业务字段集合 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 新增业务字段 |
| | | * |
| | | * |
| | | * @param genTableColumn 业务字段信息 |
| | | * @return 结果 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 修改业务字段 |
| | | * |
| | | * |
| | | * @param genTableColumn 业务字段信息 |
| | | * @return 结果 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 删除业务字段信息 |
| | | * |
| | | * |
| | | * @param ids 需要删除的数据ID |
| | | * @return 结果 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 业务 服务层 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public interface IGenTableService extends IService<GenTable> |
| | | { |
| | | public interface IGenTableService extends IService<GenTable> { |
| | | /** |
| | | * 查询业务列表 |
| | | * |
| | | * |
| | | * @param genTable 业务信息 |
| | | * @return 业务集合 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 查询据库列表 |
| | | * |
| | | * |
| | | * @param genTable 业务信息 |
| | | * @return 数据库表集合 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 查询据库列表 |
| | | * |
| | | * |
| | | * @param tableNames 表名称组 |
| | | * @return 数据库表集合 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 查询业务信息 |
| | | * |
| | | * |
| | | * @param id 业务ID |
| | | * @return 业务信息 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 修改业务 |
| | | * |
| | | * |
| | | * @param genTable 业务信息 |
| | | * @return 结果 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 删除业务信息 |
| | | * |
| | | * |
| | | * @param tableIds 需要删除的表数据ID |
| | | * @return 结果 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 导入表结构 |
| | | * |
| | | * |
| | | * @param tableList 导入表列表 |
| | | */ |
| | | public void importGenTable(List<GenTable> tableList); |
| | | |
| | | /** |
| | | * 预览代码 |
| | | * |
| | | * |
| | | * @param tableId 表编号 |
| | | * @return 预览数据列表 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 生成代码(下载方式) |
| | | * |
| | | * |
| | | * @param tableName 表名称 |
| | | * @return 数据 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 生成代码(自定义路径) |
| | | * |
| | | * |
| | | * @param tableName 表名称 |
| | | * @return 数据 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 同步数据库 |
| | | * |
| | | * |
| | | * @param tableName 表名称 |
| | | */ |
| | | public void synchDb(String tableName); |
| | | |
| | | /** |
| | | * 批量生成代码(下载方式) |
| | | * |
| | | * |
| | | * @param tableNames 表数组 |
| | | * @return 数据 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 修改保存参数校验 |
| | | * |
| | | * |
| | | * @param genTable 业务信息 |
| | | */ |
| | | public void validateEdit(GenTable genTable); |
| | |
| | | <result property="updateBy" column="update_by" /> |
| | | <result property="updateTime" column="update_time" /> |
| | | </resultMap> |
| | | |
| | | <sql id="selectGenTableColumnVo"> |
| | | select column_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_by, create_time, update_by, update_time from gen_table_column |
| | | </sql> |
| | | |
| | | <select id="selectGenTableColumnListByTableId" parameterType="Long" resultMap="GenTableColumnResult"> |
| | | <include refid="selectGenTableColumnVo"/> |
| | | where table_id = #{tableId} |
| | | order by sort |
| | | </select> |
| | | |
| | | <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="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId"> |
| | | 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="createBy != null and createBy != ''">create_by,</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="createBy != null and createBy != ''">#{createBy},</if> |
| | | sysdate() |
| | | ) |
| | | </insert> |
| | | |
| | | <update id="updateGenTableColumn" parameterType="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_by = #{updateBy}, |
| | | update_time = sysdate() |
| | | </set> |
| | | where column_id = #{columnId} |
| | | </update> |
| | | |
| | | <delete id="deleteGenTableColumnByIds" parameterType="Long"> |
| | | delete from gen_table_column where table_id in |
| | | <foreach collection="array" item="tableId" open="(" separator="," close=")"> |
| | | #{tableId} |
| | | </foreach> |
| | | </delete> |
| | | |
| | | <delete id="deleteGenTableColumns"> |
| | | delete from gen_table_column where column_id in |
| | | <foreach collection="list" item="item" open="(" separator="," close=")"> |
| | | #{item.columnId} |
| | | </foreach> |
| | | </delete> |
| | | |
| | | </mapper> |
| | |
| | | order by c.sort |
| | | </select> |
| | | |
| | | <insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId"> |
| | | 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="genType != null and genType != ''">gen_type,</if> |
| | | <if test="genPath != null and genPath != ''">gen_path,</if> |
| | | <if test="remark != null and remark != ''">remark,</if> |
| | | <if test="createBy != null and createBy != ''">create_by,</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="genType != null and genType != ''">#{genType},</if> |
| | | <if test="genPath != null and genPath != ''">#{genPath},</if> |
| | | <if test="remark != null and remark != ''">#{remark},</if> |
| | | <if test="createBy != null and createBy != ''">#{createBy},</if> |
| | | sysdate() |
| | | ) |
| | | </insert> |
| | | |
| | | <update id="updateGenTable" parameterType="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="subTableName != null">sub_table_name = #{subTableName},</if> |
| | | <if test="subTableFkName != null">sub_table_fk_name = #{subTableFkName},</if> |
| | | <if test="className != null and className != ''">class_name = #{className},</if> |
| | | <if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if> |
| | | <if test="genType != null and genType != ''">gen_type = #{genType},</if> |
| | | <if test="genPath != null and genPath != ''">gen_path = #{genPath},</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="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> |
| | | <if test="remark != null">remark = #{remark},</if> |
| | | update_time = sysdate() |
| | | </set> |
| | | where table_id = #{tableId} |
| | | </update> |
| | | |
| | | <delete id="deleteGenTableByIds" parameterType="Long"> |
| | | delete from gen_table where table_id in |
| | | <foreach collection="array" item="tableId" open="(" separator="," close=")"> |
| | | #{tableId} |
| | | </foreach> |
| | | </delete> |
| | | |
| | | </mapper> |
| | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
| | | import com.ruoyi.quartz.domain.SysJobLog;
|
| | |
|
| | | import java.util.List;
|
| | |
|
| | | /**
|
| | | * 调度任务日志信息 数据层
|
| | | * |
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | public interface SysJobLogMapper extends BaseMapper<SysJobLog>
|
| | | {
|
| | | /**
|
| | | * 获取quartz调度器日志的计划任务
|
| | | * |
| | | * @param jobLog 调度日志信息
|
| | | * @return 调度任务日志集合
|
| | | */
|
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog);
|
| | | public interface SysJobLogMapper extends BaseMapper<SysJobLog> {
|
| | |
|
| | | /**
|
| | | * 查询所有调度任务日志
|
| | | *
|
| | | * @return 调度任务日志列表
|
| | | */
|
| | | public List<SysJobLog> selectJobLogAll();
|
| | |
|
| | | /**
|
| | | * 通过调度任务日志ID查询调度信息
|
| | | * |
| | | * @param jobLogId 调度任务日志ID
|
| | | * @return 调度任务日志对象信息
|
| | | */
|
| | | public SysJobLog selectJobLogById(Long jobLogId);
|
| | |
|
| | | /**
|
| | | * 新增任务日志
|
| | | * |
| | | * @param jobLog 调度日志信息
|
| | | * @return 结果
|
| | | */
|
| | | public int insertJobLog(SysJobLog jobLog);
|
| | |
|
| | | /**
|
| | | * 批量删除调度日志信息
|
| | | * |
| | | * @param logIds 需要删除的数据ID
|
| | | * @return 结果
|
| | | */
|
| | | public int deleteJobLogByIds(Long[] logIds);
|
| | |
|
| | | /**
|
| | | * 删除任务日志
|
| | | * |
| | | * @param jobId 调度日志ID
|
| | | * @return 结果
|
| | | */
|
| | | public int deleteJobLogById(Long jobId);
|
| | |
|
| | | /**
|
| | | * 清空任务日志
|
| | | */
|
| | | public void cleanJobLog();
|
| | | }
|
| | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | |
|
| | | import java.util.List;
|
| | |
|
| | | /**
|
| | | * 调度任务信息 数据层
|
| | | * |
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | public interface SysJobMapper extends BaseMapper<SysJob>
|
| | | {
|
| | | /**
|
| | | * 查询调度任务日志集合
|
| | | * |
| | | * @param job 调度信息
|
| | | * @return 操作日志集合
|
| | | */
|
| | | public List<SysJob> selectJobList(SysJob job);
|
| | | public interface SysJobMapper extends BaseMapper<SysJob> {
|
| | |
|
| | | /**
|
| | | * 查询所有调度任务
|
| | | * |
| | | * @return 调度任务列表
|
| | | */
|
| | | public List<SysJob> selectJobAll();
|
| | |
|
| | | /**
|
| | | * 通过调度ID查询调度任务信息
|
| | | * |
| | | * @param jobId 调度ID
|
| | | * @return 角色对象信息
|
| | | */
|
| | | public SysJob selectJobById(Long jobId);
|
| | |
|
| | | /**
|
| | | * 通过调度ID删除调度任务信息
|
| | | * |
| | | * @param jobId 调度ID
|
| | | * @return 结果
|
| | | */
|
| | | public int deleteJobById(Long jobId);
|
| | |
|
| | | /**
|
| | | * 批量删除调度任务信息
|
| | | * |
| | | * @param ids 需要删除的数据ID
|
| | | * @return 结果
|
| | | */
|
| | | public int deleteJobByIds(Long[] ids);
|
| | |
|
| | | /**
|
| | | * 修改调度任务信息
|
| | | * |
| | | * @param job 调度任务信息
|
| | | * @return 结果
|
| | | */
|
| | | public int updateJob(SysJob job);
|
| | |
|
| | | /**
|
| | | * 新增调度任务信息
|
| | | * |
| | | * @param job 调度任务信息
|
| | | * @return 结果
|
| | | */
|
| | | public int insertJob(SysJob job);
|
| | | }
|
| | |
| | |
|
| | | /**
|
| | | * 定时任务调度日志信息信息 服务层
|
| | | * |
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | public interface ISysJobLogService extends IService<SysJobLog>
|
| | | {
|
| | | public interface ISysJobLogService extends IService<SysJobLog> {
|
| | | /**
|
| | | * 获取quartz调度器日志的计划任务
|
| | | * |
| | | *
|
| | | * @param jobLog 调度日志信息
|
| | | * @return 调度任务日志集合
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 通过调度任务日志ID查询调度信息
|
| | | * |
| | | *
|
| | | * @param jobLogId 调度任务日志ID
|
| | | * @return 调度任务日志对象信息
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 新增任务日志
|
| | | * |
| | | *
|
| | | * @param jobLog 调度日志信息
|
| | | */
|
| | | public void addJobLog(SysJobLog jobLog);
|
| | |
|
| | | /**
|
| | | * 批量删除调度日志信息
|
| | | * |
| | | *
|
| | | * @param logIds 需要删除的日志ID
|
| | | * @return 结果
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 删除任务日志
|
| | | * |
| | | *
|
| | | * @param jobId 调度日志ID
|
| | | * @return 结果
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 定时任务调度信息信息 服务层
|
| | | * |
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | public interface ISysJobService extends IService<SysJob>
|
| | | {
|
| | | public interface ISysJobService extends IService<SysJob> {
|
| | | /**
|
| | | * 获取quartz调度器的计划任务
|
| | | * |
| | | *
|
| | | * @param job 调度信息
|
| | | * @return 调度任务集合
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 通过调度任务ID查询调度信息
|
| | | * |
| | | *
|
| | | * @param jobId 调度任务ID
|
| | | * @return 调度任务对象信息
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 暂停任务
|
| | | * |
| | | *
|
| | | * @param job 调度信息
|
| | | * @return 结果
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 恢复任务
|
| | | * |
| | | *
|
| | | * @param job 调度信息
|
| | | * @return 结果
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 删除任务后,所对应的trigger也将被删除
|
| | | * |
| | | *
|
| | | * @param job 调度信息
|
| | | * @return 结果
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 批量删除调度信息
|
| | | * |
| | | *
|
| | | * @param jobIds 需要删除的任务ID
|
| | | * @return 结果
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 任务调度状态修改
|
| | | * |
| | | *
|
| | | * @param job 调度信息
|
| | | * @return 结果
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 立即运行任务
|
| | | * |
| | | *
|
| | | * @param job 调度信息
|
| | | * @return 结果
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 新增任务
|
| | | * |
| | | *
|
| | | * @param job 调度信息
|
| | | * @return 结果
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 更新任务
|
| | | * |
| | | *
|
| | | * @param job 调度信息
|
| | | * @return 结果
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 校验cron表达式是否有效
|
| | | * |
| | | *
|
| | | * @param cronExpression 表达式
|
| | | * @return 结果
|
| | | */
|
| | |
| | | package com.ruoyi.quartz.service.impl;
|
| | |
|
| | | import java.util.List;
|
| | |
|
| | | import cn.hutool.core.lang.Validator;
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import com.ruoyi.quartz.domain.SysJobLog;
|
| | | import com.ruoyi.quartz.mapper.SysJobLogMapper;
|
| | | import com.ruoyi.quartz.service.ISysJobLogService;
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import java.util.Arrays;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | /**
|
| | | * 定时任务调度日志信息 服务层
|
| | | * |
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | @Service
|
| | | public class SysJobLogServiceImpl extends ServiceImpl<SysJobLogMapper, SysJobLog> implements ISysJobLogService
|
| | | {
|
| | | @Autowired
|
| | | private SysJobLogMapper jobLogMapper;
|
| | | public class SysJobLogServiceImpl extends ServiceImpl<SysJobLogMapper, SysJobLog> implements ISysJobLogService {
|
| | |
|
| | | /**
|
| | | * 获取quartz调度器日志的计划任务
|
| | | * |
| | | *
|
| | | * @param jobLog 调度日志信息
|
| | | * @return 调度任务日志集合
|
| | | */
|
| | | @Override
|
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog)
|
| | | {
|
| | | return jobLogMapper.selectJobLogList(jobLog);
|
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog) {
|
| | | Map<String, Object> params = jobLog.getParams();
|
| | | return list(new LambdaQueryWrapper<SysJobLog>()
|
| | | .like(StrUtil.isNotBlank(jobLog.getJobName()), SysJobLog::getJobName, jobLog.getJobName())
|
| | | .eq(StrUtil.isNotBlank(jobLog.getJobGroup()), SysJobLog::getJobGroup, jobLog.getJobGroup())
|
| | | .eq(StrUtil.isNotBlank(jobLog.getStatus()), SysJobLog::getStatus, jobLog.getStatus())
|
| | | .like(StrUtil.isNotBlank(jobLog.getInvokeTarget()), SysJobLog::getInvokeTarget, jobLog.getInvokeTarget())
|
| | | .apply(Validator.isNotEmpty(params.get("beginTime")),
|
| | | "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')",
|
| | | params.get("beginTime"))
|
| | | .apply(Validator.isNotEmpty(params.get("endTime")),
|
| | | "date_format(create_time,'%y%m%d') <= date_format({0},'%y%m%d')",
|
| | | params.get("endTime")));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 通过调度任务日志ID查询调度信息
|
| | | * |
| | | *
|
| | | * @param jobLogId 调度任务日志ID
|
| | | * @return 调度任务日志对象信息
|
| | | */
|
| | | @Override
|
| | | public SysJobLog selectJobLogById(Long jobLogId)
|
| | | {
|
| | | return jobLogMapper.selectJobLogById(jobLogId);
|
| | | public SysJobLog selectJobLogById(Long jobLogId) {
|
| | | return getById(jobLogId);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 新增任务日志
|
| | | * |
| | | *
|
| | | * @param jobLog 调度日志信息
|
| | | */
|
| | | @Override
|
| | | public void addJobLog(SysJobLog jobLog)
|
| | | {
|
| | | jobLogMapper.insertJobLog(jobLog);
|
| | | public void addJobLog(SysJobLog jobLog) {
|
| | | baseMapper.insert(jobLog);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 批量删除调度日志信息
|
| | | * |
| | | *
|
| | | * @param logIds 需要删除的数据ID
|
| | | * @return 结果
|
| | | */
|
| | | @Override
|
| | | public int deleteJobLogByIds(Long[] logIds)
|
| | | {
|
| | | return jobLogMapper.deleteJobLogByIds(logIds);
|
| | | public int deleteJobLogByIds(Long[] logIds) {
|
| | | return baseMapper.deleteBatchIds(Arrays.asList(logIds));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 删除任务日志
|
| | | * |
| | | *
|
| | | * @param jobId 调度日志ID
|
| | | */
|
| | | @Override
|
| | | public int deleteJobLogById(Long jobId)
|
| | | {
|
| | | return jobLogMapper.deleteJobLogById(jobId);
|
| | | public int deleteJobLogById(Long jobId) {
|
| | | return baseMapper.deleteById(jobId);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 清空任务日志
|
| | | */
|
| | | @Override
|
| | | public void cleanJobLog()
|
| | | {
|
| | | jobLogMapper.cleanJobLog();
|
| | | public void cleanJobLog() {
|
| | | remove(new LambdaQueryWrapper<>());
|
| | | }
|
| | | }
|
| | |
| | | package com.ruoyi.quartz.service.impl;
|
| | |
|
| | | import java.util.List;
|
| | | import javax.annotation.PostConstruct;
|
| | |
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
| | | import org.quartz.JobDataMap;
|
| | | import org.quartz.JobKey;
|
| | | import org.quartz.Scheduler;
|
| | | import org.quartz.SchedulerException;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import com.ruoyi.common.constant.ScheduleConstants;
|
| | | import com.ruoyi.common.exception.job.TaskException;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | |
| | | import com.ruoyi.quartz.service.ISysJobService;
|
| | | import com.ruoyi.quartz.util.CronUtils;
|
| | | import com.ruoyi.quartz.util.ScheduleUtils;
|
| | | import org.quartz.JobDataMap;
|
| | | import org.quartz.JobKey;
|
| | | import org.quartz.Scheduler;
|
| | | import org.quartz.SchedulerException;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import javax.annotation.PostConstruct;
|
| | | import java.util.List;
|
| | |
|
| | | /**
|
| | | * 定时任务调度信息 服务层
|
| | | * |
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | @Service
|
| | | public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> implements ISysJobService
|
| | | {
|
| | | public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> implements ISysJobService {
|
| | | @Autowired
|
| | | private Scheduler scheduler;
|
| | |
|
| | | @Autowired
|
| | | private SysJobMapper jobMapper;
|
| | |
|
| | | /**
|
| | | * 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据)
|
| | | */
|
| | | @PostConstruct
|
| | | public void init() throws SchedulerException, TaskException
|
| | | {
|
| | | public void init() throws SchedulerException, TaskException {
|
| | | scheduler.clear();
|
| | | List<SysJob> jobList = jobMapper.selectJobAll();
|
| | | for (SysJob job : jobList)
|
| | | {
|
| | | List<SysJob> jobList = list();
|
| | | for (SysJob job : jobList) {
|
| | | ScheduleUtils.createScheduleJob(scheduler, job);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取quartz调度器的计划任务列表
|
| | | * |
| | | *
|
| | | * @param job 调度信息
|
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public List<SysJob> selectJobList(SysJob job)
|
| | | {
|
| | | return jobMapper.selectJobList(job);
|
| | | public List<SysJob> selectJobList(SysJob job) {
|
| | | return list(new LambdaQueryWrapper<SysJob>()
|
| | | .like(StrUtil.isNotBlank(job.getJobName()), SysJob::getJobName, job.getJobName())
|
| | | .eq(StrUtil.isNotBlank(job.getJobGroup()), SysJob::getJobGroup, job.getJobGroup())
|
| | | .eq(StrUtil.isNotBlank(job.getStatus()), SysJob::getStatus, job.getStatus())
|
| | | .like(StrUtil.isNotBlank(job.getInvokeTarget()), SysJob::getInvokeTarget, job.getInvokeTarget()));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 通过调度任务ID查询调度信息
|
| | | * |
| | | *
|
| | | * @param jobId 调度任务ID
|
| | | * @return 调度任务对象信息
|
| | | */
|
| | | @Override
|
| | | public SysJob selectJobById(Long jobId)
|
| | | {
|
| | | return jobMapper.selectJobById(jobId);
|
| | | public SysJob selectJobById(Long jobId) {
|
| | | return getById(jobId);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 暂停任务
|
| | | * |
| | | *
|
| | | * @param job 调度信息
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int pauseJob(SysJob job) throws SchedulerException
|
| | | {
|
| | | public int pauseJob(SysJob job) throws SchedulerException {
|
| | | Long jobId = job.getJobId();
|
| | | String jobGroup = job.getJobGroup();
|
| | | job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
|
| | | int rows = jobMapper.updateJob(job);
|
| | | if (rows > 0)
|
| | | {
|
| | | int rows = baseMapper.updateById(job);
|
| | | if (rows > 0) {
|
| | | scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
| | | }
|
| | | return rows;
|
| | |
| | |
|
| | | /**
|
| | | * 恢复任务
|
| | | * |
| | | *
|
| | | * @param job 调度信息
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int resumeJob(SysJob job) throws SchedulerException
|
| | | {
|
| | | public int resumeJob(SysJob job) throws SchedulerException {
|
| | | Long jobId = job.getJobId();
|
| | | String jobGroup = job.getJobGroup();
|
| | | job.setStatus(ScheduleConstants.Status.NORMAL.getValue());
|
| | | int rows = jobMapper.updateJob(job);
|
| | | if (rows > 0)
|
| | | {
|
| | | int rows = baseMapper.updateById(job);
|
| | | if (rows > 0) {
|
| | | scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
| | | }
|
| | | return rows;
|
| | |
| | |
|
| | | /**
|
| | | * 删除任务后,所对应的trigger也将被删除
|
| | | * |
| | | *
|
| | | * @param job 调度信息
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int deleteJob(SysJob job) throws SchedulerException
|
| | | {
|
| | | public int deleteJob(SysJob job) throws SchedulerException {
|
| | | Long jobId = job.getJobId();
|
| | | String jobGroup = job.getJobGroup();
|
| | | int rows = jobMapper.deleteJobById(jobId);
|
| | | if (rows > 0)
|
| | | {
|
| | | int rows = baseMapper.deleteById(jobId);
|
| | | if (rows > 0) {
|
| | | scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
| | | }
|
| | | return rows;
|
| | |
| | |
|
| | | /**
|
| | | * 批量删除调度信息
|
| | | * |
| | | *
|
| | | * @param jobIds 需要删除的任务ID
|
| | | * @return 结果
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public void deleteJobByIds(Long[] jobIds) throws SchedulerException
|
| | | {
|
| | | for (Long jobId : jobIds)
|
| | | {
|
| | | SysJob job = jobMapper.selectJobById(jobId);
|
| | | public void deleteJobByIds(Long[] jobIds) throws SchedulerException {
|
| | | for (Long jobId : jobIds) {
|
| | | SysJob job = getById(jobId);
|
| | | deleteJob(job);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 任务调度状态修改
|
| | | * |
| | | *
|
| | | * @param job 调度信息
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int changeStatus(SysJob job) throws SchedulerException
|
| | | {
|
| | | public int changeStatus(SysJob job) throws SchedulerException {
|
| | | int rows = 0;
|
| | | String status = job.getStatus();
|
| | | if (ScheduleConstants.Status.NORMAL.getValue().equals(status))
|
| | | {
|
| | | if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) {
|
| | | rows = resumeJob(job);
|
| | | }
|
| | | else if (ScheduleConstants.Status.PAUSE.getValue().equals(status))
|
| | | {
|
| | | } else if (ScheduleConstants.Status.PAUSE.getValue().equals(status)) {
|
| | | rows = pauseJob(job);
|
| | | }
|
| | | return rows;
|
| | |
| | |
|
| | | /**
|
| | | * 立即运行任务
|
| | | * |
| | | *
|
| | | * @param job 调度信息
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public void run(SysJob job) throws SchedulerException
|
| | | {
|
| | | public void run(SysJob job) throws SchedulerException {
|
| | | Long jobId = job.getJobId();
|
| | | String jobGroup = job.getJobGroup();
|
| | | SysJob properties = selectJobById(job.getJobId());
|
| | |
| | |
|
| | | /**
|
| | | * 新增任务
|
| | | * |
| | | *
|
| | | * @param job 调度信息 调度信息
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int insertJob(SysJob job) throws SchedulerException, TaskException
|
| | | {
|
| | | public int insertJob(SysJob job) throws SchedulerException, TaskException {
|
| | | job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
|
| | | int rows = jobMapper.insertJob(job);
|
| | | if (rows > 0)
|
| | | {
|
| | | int rows = baseMapper.insert(job);
|
| | | if (rows > 0) {
|
| | | ScheduleUtils.createScheduleJob(scheduler, job);
|
| | | }
|
| | | return rows;
|
| | |
| | |
|
| | | /**
|
| | | * 更新任务的时间表达式
|
| | | * |
| | | *
|
| | | * @param job 调度信息
|
| | | */
|
| | | @Override
|
| | | @Transactional
|
| | | public int updateJob(SysJob job) throws SchedulerException, TaskException
|
| | | {
|
| | | public int updateJob(SysJob job) throws SchedulerException, TaskException {
|
| | | SysJob properties = selectJobById(job.getJobId());
|
| | | int rows = jobMapper.updateJob(job);
|
| | | if (rows > 0)
|
| | | {
|
| | | int rows = baseMapper.updateById(job);
|
| | | if (rows > 0) {
|
| | | updateSchedulerJob(job, properties.getJobGroup());
|
| | | }
|
| | | return rows;
|
| | |
| | |
|
| | | /**
|
| | | * 更新任务
|
| | | * |
| | | * @param job 任务对象
|
| | | *
|
| | | * @param job 任务对象
|
| | | * @param jobGroup 任务组名
|
| | | */
|
| | | public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException
|
| | | {
|
| | | public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException {
|
| | | Long jobId = job.getJobId();
|
| | | // 判断是否存在
|
| | | JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
|
| | | if (scheduler.checkExists(jobKey))
|
| | | {
|
| | | if (scheduler.checkExists(jobKey)) {
|
| | | // 防止创建时存在数据问题 先移除,然后在执行创建操作
|
| | | scheduler.deleteJob(jobKey);
|
| | | }
|
| | |
| | |
|
| | | /**
|
| | | * 校验cron表达式是否有效
|
| | | * |
| | | *
|
| | | * @param cronExpression 表达式
|
| | | * @return 结果
|
| | | */
|
| | | @Override
|
| | | public boolean checkCronExpressionIsValid(String cronExpression)
|
| | | {
|
| | | public boolean checkCronExpressionIsValid(String cronExpression) {
|
| | | return CronUtils.isValid(cronExpression);
|
| | | }
|
| | | }
|
| | |
| | | <result property="exceptionInfo" column="exception_info" />
|
| | | <result property="createTime" column="create_time" />
|
| | | </resultMap>
|
| | | |
| | | <sql id="selectJobLogVo">
|
| | | select job_log_id, job_name, job_group, invoke_target, job_message, status, exception_info, create_time |
| | | from sys_job_log
|
| | | </sql>
|
| | | |
| | | <select id="selectJobLogList" parameterType="SysJobLog" resultMap="SysJobLogResult">
|
| | | <include refid="selectJobLogVo"/>
|
| | | <where>
|
| | | <if test="jobName != null and jobName != ''">
|
| | | AND job_name like concat('%', #{jobName}, '%')
|
| | | </if>
|
| | | <if test="jobGroup != null and jobGroup != ''">
|
| | | AND job_group = #{jobGroup}
|
| | | </if>
|
| | | <if test="status != null and status != ''">
|
| | | AND status = #{status}
|
| | | </if>
|
| | | <if test="invokeTarget != null and invokeTarget != ''">
|
| | | AND invoke_target like concat('%', #{invokeTarget}, '%')
|
| | | </if>
|
| | | <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
|
| | | and date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
|
| | | </if>
|
| | | <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
|
| | | and date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
|
| | | </if>
|
| | | </where>
|
| | | </select>
|
| | | |
| | | <select id="selectJobLogAll" resultMap="SysJobLogResult">
|
| | | <include refid="selectJobLogVo"/>
|
| | | </select>
|
| | | |
| | | <select id="selectJobLogById" parameterType="Long" resultMap="SysJobLogResult">
|
| | | <include refid="selectJobLogVo"/>
|
| | | where job_log_id = #{jobLogId}
|
| | | </select>
|
| | | |
| | | <delete id="deleteJobLogById" parameterType="Long">
|
| | | delete from sys_job_log where job_log_id = #{jobLogId}
|
| | | </delete>
|
| | | |
| | | <delete id="deleteJobLogByIds" parameterType="Long">
|
| | | delete from sys_job_log where job_log_id in
|
| | | <foreach collection="array" item="jobLogId" open="(" separator="," close=")">
|
| | | #{jobLogId}
|
| | | </foreach> |
| | | </delete>
|
| | | |
| | | <update id="cleanJobLog">
|
| | | truncate table sys_job_log
|
| | | </update>
|
| | | |
| | | <insert id="insertJobLog" parameterType="SysJobLog">
|
| | | insert into sys_job_log(
|
| | | <if test="jobLogId != null and jobLogId != 0">job_log_id,</if>
|
| | | <if test="jobName != null and jobName != ''">job_name,</if>
|
| | | <if test="jobGroup != null and jobGroup != ''">job_group,</if>
|
| | | <if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if>
|
| | | <if test="jobMessage != null and jobMessage != ''">job_message,</if>
|
| | | <if test="status != null and status != ''">status,</if>
|
| | | <if test="exceptionInfo != null and exceptionInfo != ''">exception_info,</if>
|
| | | create_time
|
| | | )values(
|
| | | <if test="jobLogId != null and jobLogId != 0">#{jobLogId},</if>
|
| | | <if test="jobName != null and jobName != ''">#{jobName},</if>
|
| | | <if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if>
|
| | | <if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if>
|
| | | <if test="jobMessage != null and jobMessage != ''">#{jobMessage},</if>
|
| | | <if test="status != null and status != ''">#{status},</if>
|
| | | <if test="exceptionInfo != null and exceptionInfo != ''">#{exceptionInfo},</if>
|
| | | sysdate()
|
| | | )
|
| | | </insert>
|
| | |
|
| | | </mapper> |
| | |
| | | <result property="updateTime" column="update_time" />
|
| | | <result property="remark" column="remark" />
|
| | | </resultMap>
|
| | | |
| | | <sql id="selectJobVo">
|
| | | select job_id, job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, remark |
| | | from sys_job
|
| | | </sql>
|
| | | |
| | | <select id="selectJobList" parameterType="SysJob" resultMap="SysJobResult">
|
| | | <include refid="selectJobVo"/>
|
| | | <where>
|
| | | <if test="jobName != null and jobName != ''">
|
| | | AND job_name like concat('%', #{jobName}, '%')
|
| | | </if>
|
| | | <if test="jobGroup != null and jobGroup != ''">
|
| | | AND job_group = #{jobGroup}
|
| | | </if>
|
| | | <if test="status != null and status != ''">
|
| | | AND status = #{status}
|
| | | </if>
|
| | | <if test="invokeTarget != null and invokeTarget != ''">
|
| | | AND invoke_target like concat('%', #{invokeTarget}, '%')
|
| | | </if>
|
| | | </where>
|
| | | </select>
|
| | | |
| | | <select id="selectJobAll" resultMap="SysJobResult">
|
| | | <include refid="selectJobVo"/>
|
| | | </select>
|
| | | |
| | | <select id="selectJobById" parameterType="Long" resultMap="SysJobResult">
|
| | | <include refid="selectJobVo"/>
|
| | | where job_id = #{jobId}
|
| | | </select>
|
| | | |
| | | <delete id="deleteJobById" parameterType="Long">
|
| | | delete from sys_job where job_id = #{jobId}
|
| | | </delete>
|
| | | |
| | | <delete id="deleteJobByIds" parameterType="Long">
|
| | | delete from sys_job where job_id in
|
| | | <foreach collection="array" item="jobId" open="(" separator="," close=")">
|
| | | #{jobId}
|
| | | </foreach> |
| | | </delete>
|
| | | |
| | | <update id="updateJob" parameterType="SysJob">
|
| | | update sys_job
|
| | | <set>
|
| | | <if test="jobName != null and jobName != ''">job_name = #{jobName},</if>
|
| | | <if test="jobGroup != null and jobGroup != ''">job_group = #{jobGroup},</if>
|
| | | <if test="invokeTarget != null and invokeTarget != ''">invoke_target = #{invokeTarget},</if>
|
| | | <if test="cronExpression != null and cronExpression != ''">cron_expression = #{cronExpression},</if>
|
| | | <if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy = #{misfirePolicy},</if>
|
| | | <if test="concurrent != null and concurrent != ''">concurrent = #{concurrent},</if>
|
| | | <if test="status !=null">status = #{status},</if>
|
| | | <if test="remark != null and remark != ''">remark = #{remark},</if>
|
| | | <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
| | | update_time = sysdate()
|
| | | </set>
|
| | | where job_id = #{jobId}
|
| | | </update>
|
| | | |
| | | <insert id="insertJob" parameterType="SysJob" useGeneratedKeys="true" keyProperty="jobId">
|
| | | insert into sys_job(
|
| | | <if test="jobId != null and jobId != 0">job_id,</if>
|
| | | <if test="jobName != null and jobName != ''">job_name,</if>
|
| | | <if test="jobGroup != null and jobGroup != ''">job_group,</if>
|
| | | <if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if>
|
| | | <if test="cronExpression != null and cronExpression != ''">cron_expression,</if>
|
| | | <if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy,</if>
|
| | | <if test="concurrent != null and concurrent != ''">concurrent,</if>
|
| | | <if test="status != null and status != ''">status,</if>
|
| | | <if test="remark != null and remark != ''">remark,</if>
|
| | | <if test="createBy != null and createBy != ''">create_by,</if>
|
| | | create_time
|
| | | )values(
|
| | | <if test="jobId != null and jobId != 0">#{jobId},</if>
|
| | | <if test="jobName != null and jobName != ''">#{jobName},</if>
|
| | | <if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if>
|
| | | <if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if>
|
| | | <if test="cronExpression != null and cronExpression != ''">#{cronExpression},</if>
|
| | | <if test="misfirePolicy != null and misfirePolicy != ''">#{misfirePolicy},</if>
|
| | | <if test="concurrent != null and concurrent != ''">#{concurrent},</if>
|
| | | <if test="status != null and status != ''">#{status},</if>
|
| | | <if test="remark != null and remark != ''">#{remark},</if>
|
| | | <if test="createBy != null and createBy != ''">#{createBy},</if>
|
| | | sysdate()
|
| | | )
|
| | | </insert>
|
| | |
|
| | | </mapper> |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.ruoyi.common.core.domain.entity.SysDictType; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 字典表 数据层 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Mapper |
| | | public interface SysDictTypeMapper extends BaseMapper<SysDictType> { |
| | | |
| | | /** |
| | | * 根据所有字典类型 |
| | | * |
| | | * @return 字典类型集合信息 |
| | | */ |
| | | public List<SysDictType> selectDictTypeAll(); |
| | | |
| | | /** |
| | | * 根据字典类型ID查询信息 |
| | | * |
| | | * @param dictId 字典类型ID |
| | | * @return 字典类型 |
| | | */ |
| | | public SysDictType selectDictTypeById(Long dictId); |
| | | |
| | | /** |
| | | * 根据字典类型查询信息 |
| | | * |
| | | * @param dictType 字典类型 |
| | | * @return 字典类型 |
| | | */ |
| | | public SysDictType selectDictTypeByType(String dictType); |
| | | |
| | | /** |
| | | * 校验字典类型称是否唯一 |
| | | * |
| | | * @param dictType 字典类型 |
| | | * @return 结果 |
| | | */ |
| | | public SysDictType checkDictTypeUnique(String dictType); |
| | | } |
| | |
| | | import com.ruoyi.system.mapper.*; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService { |
| | | private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class); |
| | | |
| | | @Autowired |
| | | private SysUserMapper userMapper; |
| | | |
| | | @Autowired |
| | | private SysRoleMapper roleMapper; |
| | |
| | | @Override |
| | | @DataScope(deptAlias = "d", userAlias = "u") |
| | | public List<SysUser> selectUserList(SysUser user) { |
| | | return userMapper.selectUserList(user); |
| | | return baseMapper.selectUserList(user); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public SysUser selectUserByUserName(String userName) { |
| | | return userMapper.selectUserByUserName(userName); |
| | | return baseMapper.selectUserByUserName(userName); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public SysUser selectUserById(Long userId) { |
| | | return userMapper.selectUserById(userId); |
| | | return baseMapper.selectUserById(userId); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Transactional |
| | | public int insertUser(SysUser user) { |
| | | // 新增用户信息 |
| | | int rows = userMapper.insert(user); |
| | | int rows = baseMapper.insert(user); |
| | | // 新增用户岗位关联 |
| | | insertUserPost(user); |
| | | // 新增用户与角色管理 |
| | |
| | | userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getUserId,userId)); |
| | | // 新增用户与岗位管理 |
| | | insertUserPost(user); |
| | | return userMapper.updateById(user); |
| | | return baseMapper.updateById(user); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public int updateUserStatus(SysUser user) { |
| | | return userMapper.updateById(user); |
| | | return baseMapper.updateById(user); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public int updateUserProfile(SysUser user) { |
| | | return userMapper.updateById(user); |
| | | return baseMapper.updateById(user); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public boolean updateUserAvatar(String userName, String avatar) { |
| | | return userMapper.update(null, |
| | | return baseMapper.update(null, |
| | | new LambdaUpdateWrapper<SysUser>() |
| | | .set(SysUser::getAvatar,avatar) |
| | | .eq(SysUser::getUserName,userName)) > 0; |
| | |
| | | */ |
| | | @Override |
| | | public int resetPwd(SysUser user) { |
| | | return userMapper.updateById(user); |
| | | return baseMapper.updateById(user); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public int resetUserPwd(String userName, String password) { |
| | | return userMapper.update(null, |
| | | return baseMapper.update(null, |
| | | new LambdaUpdateWrapper<SysUser>() |
| | | .set(SysUser::getPassword,password) |
| | | .eq(SysUser::getUserName,userName)); |
| | |
| | | userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId,userId)); |
| | | // 删除用户与岗位表 |
| | | userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getUserId,userId)); |
| | | return userMapper.deleteById(userId); |
| | | return baseMapper.deleteById(userId); |
| | | } |
| | | |
| | | /** |
| | |
| | | userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getUserId,ids)); |
| | | // 删除用户与岗位表 |
| | | userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().in(SysUserPost::getUserId,ids)); |
| | | return userMapper.deleteBatchIds(ids); |
| | | return baseMapper.deleteBatchIds(ids); |
| | | } |
| | | |
| | | /** |
| | |
| | | for (SysUser user : userList) { |
| | | try { |
| | | // 验证是否存在这个用户 |
| | | SysUser u = userMapper.selectUserByUserName(user.getUserName()); |
| | | SysUser u = baseMapper.selectUserByUserName(user.getUserName()); |
| | | if (Validator.isNull(u)) { |
| | | user.setPassword(SecurityUtils.encryptPassword(password)); |
| | | user.setCreateBy(operName); |
| | |
| | | <result property="updateTime" column="update_time"/> |
| | | </resultMap> |
| | | |
| | | <sql id="selectDictTypeVo"> |
| | | select dict_id, dict_name, dict_type, status, create_by, create_time, remark |
| | | from sys_dict_type |
| | | </sql> |
| | | |
| | | <select id="selectDictTypeAll" resultMap="SysDictTypeResult"> |
| | | <include refid="selectDictTypeVo"/> |
| | | </select> |
| | | |
| | | <select id="selectDictTypeById" parameterType="Long" resultMap="SysDictTypeResult"> |
| | | <include refid="selectDictTypeVo"/> |
| | | where dict_id = #{dictId} |
| | | </select> |
| | | |
| | | <select id="selectDictTypeByType" parameterType="String" resultMap="SysDictTypeResult"> |
| | | <include refid="selectDictTypeVo"/> |
| | | where dict_type = #{dictType} |
| | | </select> |
| | | |
| | | <select id="checkDictTypeUnique" parameterType="String" resultMap="SysDictTypeResult"> |
| | | <include refid="selectDictTypeVo"/> |
| | | where dict_type = #{dictType} limit 1 |
| | | </select> |
| | | |
| | | </mapper> |