update mp化

This commit is contained in:
疯狂的狮子li 2021-04-14 12:01:26 +08:00
parent 48d61a3cdf
commit adeaa77864
21 changed files with 473 additions and 1068 deletions

View File

@ -4,13 +4,13 @@ import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.constant.GenConstants; import com.ruoyi.common.constant.GenConstants;
import lombok.Data; import lombok.*;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -26,75 +26,110 @@ import java.util.Map;
@NoArgsConstructor @NoArgsConstructor
@Accessors(chain = true) @Accessors(chain = true)
@TableName("gen_table") @TableName("gen_table")
public class GenTable public class GenTable implements Serializable {
{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 编号 */ /**
* 编号
*/
@TableId(value = "table_id", type = IdType.AUTO) @TableId(value = "table_id", type = IdType.AUTO)
private Long tableId; private Long tableId;
/** 表名称 */ /**
* 表名称
*/
@NotBlank(message = "表名称不能为空") @NotBlank(message = "表名称不能为空")
private String tableName; private String tableName;
/** 表描述 */ /**
* 表描述
*/
@NotBlank(message = "表描述不能为空") @NotBlank(message = "表描述不能为空")
private String tableComment; private String tableComment;
/** 关联父表的表名 */ /**
* 关联父表的表名
*/
private String subTableName; private String subTableName;
/** 本表关联父表的外键名 */ /**
* 本表关联父表的外键名
*/
private String subTableFkName; private String subTableFkName;
/** 实体类名称(首字母大写) */ /**
* 实体类名称(首字母大写)
*/
@NotBlank(message = "实体类名称不能为空") @NotBlank(message = "实体类名称不能为空")
private String className; private String className;
/** 使用的模板crud单表操作 tree树表操作 sub主子表操作 */ /**
* 使用的模板crud单表操作 tree树表操作 sub主子表操作
*/
private String tplCategory; private String tplCategory;
/** 生成包路径 */ /**
* 生成包路径
*/
@NotBlank(message = "生成包路径不能为空") @NotBlank(message = "生成包路径不能为空")
private String packageName; private String packageName;
/** 生成模块名 */ /**
* 生成模块名
*/
@NotBlank(message = "生成模块名不能为空") @NotBlank(message = "生成模块名不能为空")
private String moduleName; private String moduleName;
/** 生成业务名 */ /**
* 生成业务名
*/
@NotBlank(message = "生成业务名不能为空") @NotBlank(message = "生成业务名不能为空")
private String businessName; private String businessName;
/** 生成功能名 */ /**
* 生成功能名
*/
@NotBlank(message = "生成功能名不能为空") @NotBlank(message = "生成功能名不能为空")
private String functionName; private String functionName;
/** 生成作者 */ /**
* 生成作者
*/
@NotBlank(message = "作者不能为空") @NotBlank(message = "作者不能为空")
private String functionAuthor; private String functionAuthor;
/** 生成代码方式0zip压缩包 1自定义路径 */ /**
* 生成代码方式0zip压缩包 1自定义路径
*/
private String genType; private String genType;
/** 生成路径(不填默认项目路径) */ /**
* 生成路径不填默认项目路径
*/
private String genPath; private String genPath;
/** 主键信息 */ /**
* 主键信息
*/
@TableField(exist = false) @TableField(exist = false)
private GenTableColumn pkColumn; private GenTableColumn pkColumn;
/** 子表信息 */ /**
* 子表信息
*/
@TableField(exist = false) @TableField(exist = false)
private GenTable subTable; private GenTable subTable;
/** 表列信息 */ /**
* 表列信息
*/
@Valid @Valid
@TableField(exist = false) @TableField(exist = false)
private List<GenTableColumn> columns; private List<GenTableColumn> columns;
/** 其它生成选项 */ /**
* 其它生成选项
*/
private String options; private String options;
/** /**
@ -132,65 +167,66 @@ public class GenTable
@TableField(exist = false) @TableField(exist = false)
private Map<String, Object> params = new HashMap<>(); private Map<String, Object> params = new HashMap<>();
/** 树编码字段 */ /**
* 树编码字段
*/
@TableField(exist = false) @TableField(exist = false)
private String treeCode; private String treeCode;
/** 树父编码字段 */ /**
* 树父编码字段
*/
@TableField(exist = false) @TableField(exist = false)
private String treeParentCode; private String treeParentCode;
/** 树名称字段 */ /**
* 树名称字段
*/
@TableField(exist = false) @TableField(exist = false)
private String treeName; private String treeName;
/** 上级菜单ID字段 */ /**
* 上级菜单ID字段
*/
@TableField(exist = false) @TableField(exist = false)
private String parentMenuId; private String parentMenuId;
/** 上级菜单名称字段 */ /**
* 上级菜单名称字段
*/
@TableField(exist = false) @TableField(exist = false)
private String parentMenuName; private String parentMenuName;
public boolean isSub() public boolean isSub() {
{
return isSub(this.tplCategory); 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); return tplCategory != null && StrUtil.equals(GenConstants.TPL_SUB, tplCategory);
} }
public boolean isTree() public boolean isTree() {
{
return isTree(this.tplCategory); 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); return tplCategory != null && StrUtil.equals(GenConstants.TPL_TREE, tplCategory);
} }
public boolean isCrud() public boolean isCrud() {
{
return isCrud(this.tplCategory); 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); return tplCategory != null && StrUtil.equals(GenConstants.TPL_CRUD, tplCategory);
} }
public boolean isSuperColumn(String javaField) public boolean isSuperColumn(String javaField) {
{
return isSuperColumn(this.tplCategory, javaField); return isSuperColumn(this.tplCategory, javaField);
} }
public static boolean isSuperColumn(String tplCategory, String javaField) public static boolean isSuperColumn(String tplCategory, String javaField) {
{ if (isTree(tplCategory)) {
if (isTree(tplCategory))
{
return StrUtil.equalsAnyIgnoreCase(javaField, return StrUtil.equalsAnyIgnoreCase(javaField,
ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY)); ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY));
} }

View File

@ -3,12 +3,11 @@ package com.ruoyi.generator.domain;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.domain.BaseEntity; import lombok.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -23,64 +22,99 @@ import java.util.Map;
@NoArgsConstructor @NoArgsConstructor
@Accessors(chain = true) @Accessors(chain = true)
@TableName("gen_table_column") @TableName("gen_table_column")
public class GenTableColumn extends BaseEntity public class GenTableColumn implements Serializable {
{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 编号 */ /**
* 编号
*/
@TableId(value = "column_id", type = IdType.AUTO) @TableId(value = "column_id", type = IdType.AUTO)
private Long columnId; private Long columnId;
/** 归属表编号 */ /**
* 归属表编号
*/
private Long tableId; private Long tableId;
/** 列名称 */ /**
* 列名称
*/
private String columnName; private String columnName;
/** 列描述 */ /**
* 列描述
*/
private String columnComment; private String columnComment;
/** 列类型 */ /**
* 列类型
*/
private String columnType; private String columnType;
/** JAVA类型 */ /**
* JAVA类型
*/
private String javaType; private String javaType;
/** JAVA字段名 */ /**
* JAVA字段名
*/
@NotBlank(message = "Java属性不能为空") @NotBlank(message = "Java属性不能为空")
private String javaField; private String javaField;
/** 是否主键1是 */ /**
* 是否主键1
*/
private String isPk; private String isPk;
/** 是否自增1是 */ /**
* 是否自增1
*/
private String isIncrement; private String isIncrement;
/** 是否必填1是 */ /**
* 是否必填1
*/
private String isRequired; private String isRequired;
/** 是否为插入字段1是 */ /**
* 是否为插入字段1
*/
private String isInsert; private String isInsert;
/** 是否编辑字段1是 */ /**
* 是否编辑字段1
*/
private String isEdit; private String isEdit;
/** 是否列表字段1是 */ /**
* 是否列表字段1
*/
private String isList; private String isList;
/** 是否查询字段1是 */ /**
* 是否查询字段1
*/
private String isQuery; private String isQuery;
/** 查询方式EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围 */ /**
* 查询方式EQ等于NE不等于GT大于LT小于LIKE模糊BETWEEN范围
*/
private String queryType; 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 htmlType;
/** 字典类型 */ /**
* 字典类型
*/
private String dictType; private String dictType;
/** 排序 */ /**
* 排序
*/
private Integer sort; private Integer sort;
/** /**
@ -113,88 +147,71 @@ public class GenTableColumn extends BaseEntity
@TableField(exist = false) @TableField(exist = false)
private Map<String, Object> params = new HashMap<>(); private Map<String, Object> params = new HashMap<>();
public String getCapJavaField() public String getCapJavaField() {
{
return StrUtil.upperFirst(javaField); return StrUtil.upperFirst(javaField);
} }
public boolean isPk() public boolean isPk() {
{
return isPk(this.isPk); return isPk(this.isPk);
} }
public boolean isPk(String isPk) public boolean isPk(String isPk) {
{
return isPk != null && StrUtil.equals("1", isPk); return isPk != null && StrUtil.equals("1", isPk);
} }
public boolean isIncrement() public boolean isIncrement() {
{
return isIncrement(this.isIncrement); return isIncrement(this.isIncrement);
} }
public boolean isIncrement(String isIncrement) public boolean isIncrement(String isIncrement) {
{
return isIncrement != null && StrUtil.equals("1", isIncrement); return isIncrement != null && StrUtil.equals("1", isIncrement);
} }
public boolean isRequired() public boolean isRequired() {
{
return isRequired(this.isRequired); return isRequired(this.isRequired);
} }
public boolean isRequired(String isRequired) public boolean isRequired(String isRequired) {
{
return isRequired != null && StrUtil.equals("1", isRequired); return isRequired != null && StrUtil.equals("1", isRequired);
} }
public boolean isInsert() public boolean isInsert() {
{
return isInsert(this.isInsert); return isInsert(this.isInsert);
} }
public boolean isInsert(String isInsert) public boolean isInsert(String isInsert) {
{
return isInsert != null && StrUtil.equals("1", isInsert); return isInsert != null && StrUtil.equals("1", isInsert);
} }
public boolean isEdit() public boolean isEdit() {
{
return isInsert(this.isEdit); return isInsert(this.isEdit);
} }
public boolean isEdit(String isEdit) public boolean isEdit(String isEdit) {
{
return isEdit != null && StrUtil.equals("1", isEdit); return isEdit != null && StrUtil.equals("1", isEdit);
} }
public boolean isList() public boolean isList() {
{
return isList(this.isList); return isList(this.isList);
} }
public boolean isList(String isList) public boolean isList(String isList) {
{
return isList != null && StrUtil.equals("1", isList); return isList != null && StrUtil.equals("1", isList);
} }
public boolean isQuery() public boolean isQuery() {
{
return isQuery(this.isQuery); return isQuery(this.isQuery);
} }
public boolean isQuery(String isQuery) public boolean isQuery(String isQuery) {
{
return isQuery != null && StrUtil.equals("1", isQuery); return isQuery != null && StrUtil.equals("1", isQuery);
} }
public boolean isSuperColumn() public boolean isSuperColumn() {
{
return isSuperColumn(this.javaField); return isSuperColumn(this.javaField);
} }
public static boolean isSuperColumn(String javaField) public static boolean isSuperColumn(String javaField) {
{
return StrUtil.equalsAnyIgnoreCase(javaField, return StrUtil.equalsAnyIgnoreCase(javaField,
// BaseEntity // BaseEntity
"createBy", "createTime", "updateBy", "updateTime", "remark", "createBy", "createTime", "updateBy", "updateTime", "remark",
@ -202,36 +219,28 @@ public class GenTableColumn extends BaseEntity
"parentName", "parentId", "orderNum", "ancestors"); "parentName", "parentId", "orderNum", "ancestors");
} }
public boolean isUsableColumn() public boolean isUsableColumn() {
{
return isUsableColumn(javaField); return isUsableColumn(javaField);
} }
public static boolean isUsableColumn(String javaField) public static boolean isUsableColumn(String javaField) {
{
// isSuperColumn()中的名单用于避免生成多余Domain属性若某些属性在生成页面时需要用到不能忽略则放在此处白名单 // isSuperColumn()中的名单用于避免生成多余Domain属性若某些属性在生成页面时需要用到不能忽略则放在此处白名单
return StrUtil.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark"); return StrUtil.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark");
} }
public String readConverterExp() public String readConverterExp() {
{
String remarks = StrUtil.subBetween(this.columnComment, "", ""); String remarks = StrUtil.subBetween(this.columnComment, "", "");
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
if (StrUtil.isNotEmpty(remarks)) if (StrUtil.isNotEmpty(remarks)) {
{ for (String value : remarks.split(" ")) {
for (String value : remarks.split(" ")) if (StrUtil.isNotEmpty(value)) {
{
if (StrUtil.isNotEmpty(value))
{
Object startStr = value.subSequence(0, 1); Object startStr = value.subSequence(0, 1);
String endStr = value.substring(1); String endStr = value.substring(1);
sb.append("").append(startStr).append("=").append(endStr).append(","); sb.append("").append(startStr).append("=").append(endStr).append(",");
} }
} }
return sb.deleteCharAt(sb.length() - 1).toString(); return sb.deleteCharAt(sb.length() - 1).toString();
} } else {
else
{
return this.columnComment; return this.columnComment;
} }
} }

View File

@ -10,8 +10,7 @@ import java.util.List;
* *
* @author ruoyi * @author ruoyi
*/ */
public interface GenTableColumnMapper extends BaseMapper<GenTableColumn> public interface GenTableColumnMapper extends BaseMapper<GenTableColumn> {
{
/** /**
* 根据表名称查询列信息 * 根据表名称查询列信息
* *
@ -20,43 +19,4 @@ public interface GenTableColumnMapper extends BaseMapper<GenTableColumn>
*/ */
public List<GenTableColumn> selectDbTableColumnsByName(String tableName); 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);
} }

View File

@ -10,8 +10,7 @@ import java.util.List;
* *
* @author ruoyi * @author ruoyi
*/ */
public interface GenTableMapper extends BaseMapper<GenTable> public interface GenTableMapper extends BaseMapper<GenTable> {
{
/** /**
* 查询业务列表 * 查询业务列表
* *
@ -59,27 +58,4 @@ public interface GenTableMapper extends BaseMapper<GenTable>
*/ */
public GenTable selectGenTableByName(String tableName); 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);
} }

View File

@ -1,13 +1,13 @@
package com.ruoyi.generator.service; 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 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.domain.GenTableColumn;
import com.ruoyi.generator.mapper.GenTableColumnMapper; import com.ruoyi.generator.mapper.GenTableColumnMapper;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
/** /**
* 业务字段 服务层实现 * 业务字段 服务层实现
@ -15,10 +15,7 @@ import com.ruoyi.generator.mapper.GenTableColumnMapper;
* @author ruoyi * @author ruoyi
*/ */
@Service @Service
public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper, GenTableColumn> implements IGenTableColumnService public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper, GenTableColumn> implements IGenTableColumnService {
{
@Autowired
private GenTableColumnMapper genTableColumnMapper;
/** /**
* 查询业务字段列表 * 查询业务字段列表
@ -27,9 +24,10 @@ public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper,
* @return 业务字段集合 * @return 业务字段集合
*/ */
@Override @Override
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
{ return list(new LambdaQueryWrapper<GenTableColumn>()
return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); .eq(GenTableColumn::getTableId,tableId)
.orderByAsc(GenTableColumn::getSort));
} }
/** /**
@ -39,9 +37,8 @@ public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper,
* @return 结果 * @return 结果
*/ */
@Override @Override
public int insertGenTableColumn(GenTableColumn genTableColumn) public int insertGenTableColumn(GenTableColumn genTableColumn) {
{ return baseMapper.insert(genTableColumn);
return genTableColumnMapper.insertGenTableColumn(genTableColumn);
} }
/** /**
@ -51,9 +48,8 @@ public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper,
* @return 结果 * @return 结果
*/ */
@Override @Override
public int updateGenTableColumn(GenTableColumn genTableColumn) public int updateGenTableColumn(GenTableColumn genTableColumn) {
{ return baseMapper.updateById(genTableColumn);
return genTableColumnMapper.updateGenTableColumn(genTableColumn);
} }
/** /**
@ -63,8 +59,7 @@ public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper,
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteGenTableColumnByIds(String ids) public int deleteGenTableColumnByIds(String ids) {
{ return baseMapper.deleteBatchIds(Arrays.asList(ids.split(",")));
return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
} }
} }

View File

@ -5,6 +5,7 @@ import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.GenConstants; import com.ruoyi.common.constant.GenConstants;
@ -18,12 +19,11 @@ import com.ruoyi.generator.mapper.GenTableMapper;
import com.ruoyi.generator.util.GenUtils; import com.ruoyi.generator.util.GenUtils;
import com.ruoyi.generator.util.VelocityInitializer; import com.ruoyi.generator.util.VelocityInitializer;
import com.ruoyi.generator.util.VelocityUtils; import com.ruoyi.generator.util.VelocityUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template; import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext; import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity; import org.apache.velocity.app.Velocity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -32,6 +32,7 @@ import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.Arrays;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -44,13 +45,9 @@ import java.util.zip.ZipOutputStream;
* *
* @author ruoyi * @author ruoyi
*/ */
@Slf4j
@Service @Service
public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> implements IGenTableService public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> implements IGenTableService {
{
private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class);
@Autowired
private GenTableMapper genTableMapper;
@Autowired @Autowired
private GenTableColumnMapper genTableColumnMapper; private GenTableColumnMapper genTableColumnMapper;
@ -62,9 +59,8 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
* @return 业务信息 * @return 业务信息
*/ */
@Override @Override
public GenTable selectGenTableById(Long id) public GenTable selectGenTableById(Long id) {
{ GenTable genTable = baseMapper.selectGenTableById(id);
GenTable genTable = genTableMapper.selectGenTableById(id);
setTableFromOptions(genTable); setTableFromOptions(genTable);
return genTable; return genTable;
} }
@ -76,9 +72,8 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
* @return 业务集合 * @return 业务集合
*/ */
@Override @Override
public List<GenTable> selectGenTableList(GenTable genTable) public List<GenTable> selectGenTableList(GenTable genTable) {
{ return baseMapper.selectGenTableList(genTable);
return genTableMapper.selectGenTableList(genTable);
} }
/** /**
@ -88,9 +83,8 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
* @return 数据库表集合 * @return 数据库表集合
*/ */
@Override @Override
public List<GenTable> selectDbTableList(GenTable genTable) public List<GenTable> selectDbTableList(GenTable genTable) {
{ return baseMapper.selectDbTableList(genTable);
return genTableMapper.selectDbTableList(genTable);
} }
/** /**
@ -100,9 +94,8 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
* @return 数据库表集合 * @return 数据库表集合
*/ */
@Override @Override
public List<GenTable> selectDbTableListByNames(String[] tableNames) public List<GenTable> selectDbTableListByNames(String[] tableNames) {
{ return baseMapper.selectDbTableListByNames(tableNames);
return genTableMapper.selectDbTableListByNames(tableNames);
} }
/** /**
@ -111,9 +104,8 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
* @return 表信息集合 * @return 表信息集合
*/ */
@Override @Override
public List<GenTable> selectGenTableAll() public List<GenTable> selectGenTableAll() {
{ return baseMapper.selectGenTableAll();
return genTableMapper.selectGenTableAll();
} }
/** /**
@ -124,16 +116,13 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
*/ */
@Override @Override
@Transactional @Transactional
public void updateGenTable(GenTable genTable) public void updateGenTable(GenTable genTable) {
{
String options = JSON.toJSONString(genTable.getParams()); String options = JSON.toJSONString(genTable.getParams());
genTable.setOptions(options); genTable.setOptions(options);
int row = genTableMapper.updateGenTable(genTable); int row = baseMapper.updateById(genTable);
if (row > 0) if (row > 0) {
{ for (GenTableColumn cenTableColumn : genTable.getColumns()) {
for (GenTableColumn cenTableColumn : genTable.getColumns()) genTableColumnMapper.updateById(cenTableColumn);
{
genTableColumnMapper.updateGenTableColumn(cenTableColumn);
} }
} }
} }
@ -146,10 +135,10 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
*/ */
@Override @Override
@Transactional @Transactional
public void deleteGenTableByIds(Long[] tableIds) public void deleteGenTableByIds(Long[] tableIds) {
{ List<Long> ids = Arrays.asList(tableIds);
genTableMapper.deleteGenTableByIds(tableIds); removeByIds(ids);
genTableColumnMapper.deleteGenTableColumnByIds(tableIds); genTableColumnMapper.delete(new LambdaQueryWrapper<GenTableColumn>().in(GenTableColumn::getTableId, ids));
} }
/** /**
@ -159,30 +148,23 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
*/ */
@Override @Override
@Transactional @Transactional
public void importGenTable(List<GenTable> tableList) public void importGenTable(List<GenTable> tableList) {
{
String operName = SecurityUtils.getUsername(); String operName = SecurityUtils.getUsername();
try try {
{ for (GenTable table : tableList) {
for (GenTable table : tableList)
{
String tableName = table.getTableName(); String tableName = table.getTableName();
GenUtils.initTable(table, operName); GenUtils.initTable(table, operName);
int row = genTableMapper.insertGenTable(table); int row = baseMapper.insert(table);
if (row > 0) if (row > 0) {
{
// 保存列信息 // 保存列信息
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
for (GenTableColumn column : genTableColumns) for (GenTableColumn column : genTableColumns) {
{
GenUtils.initColumnField(column, table); GenUtils.initColumnField(column, table);
genTableColumnMapper.insertGenTableColumn(column); genTableColumnMapper.insert(column);
} }
} }
} }
} } catch (Exception e) {
catch (Exception e)
{
throw new CustomException("导入失败:" + e.getMessage()); throw new CustomException("导入失败:" + e.getMessage());
} }
} }
@ -194,11 +176,10 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
* @return 预览数据列表 * @return 预览数据列表
*/ */
@Override @Override
public Map<String, String> previewCode(Long tableId) public Map<String, String> previewCode(Long tableId) {
{
Map<String, String> dataMap = new LinkedHashMap<>(); Map<String, String> dataMap = new LinkedHashMap<>();
// 查询表信息 // 查询表信息
GenTable table = genTableMapper.selectGenTableById(tableId); GenTable table = baseMapper.selectGenTableById(tableId);
// 设置主子表信息 // 设置主子表信息
setSubTable(table); setSubTable(table);
// 设置主键列信息 // 设置主键列信息
@ -209,8 +190,7 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
// 获取模板列表 // 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
for (String template : templates) for (String template : templates) {
{
// 渲染模板 // 渲染模板
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, Constants.UTF8); Template tpl = Velocity.getTemplate(template, Constants.UTF8);
@ -227,8 +207,7 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
* @return 数据 * @return 数据
*/ */
@Override @Override
public byte[] downloadCode(String tableName) public byte[] downloadCode(String tableName) {
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream); ZipOutputStream zip = new ZipOutputStream(outputStream);
generatorCode(tableName, zip); generatorCode(tableName, zip);
@ -242,10 +221,9 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
* @param tableName 表名称 * @param tableName 表名称
*/ */
@Override @Override
public void generatorCode(String tableName) public void generatorCode(String tableName) {
{
// 查询表信息 // 查询表信息
GenTable table = genTableMapper.selectGenTableByName(tableName); GenTable table = baseMapper.selectGenTableByName(tableName);
// 设置主子表信息 // 设置主子表信息
setSubTable(table); setSubTable(table);
// 设置主键列信息 // 设置主键列信息
@ -257,21 +235,16 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
// 获取模板列表 // 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
for (String template : templates) for (String template : templates) {
{ if (!StrUtil.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) {
if (!StrUtil.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm"))
{
// 渲染模板 // 渲染模板
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, Constants.UTF8); Template tpl = Velocity.getTemplate(template, Constants.UTF8);
tpl.merge(context, sw); tpl.merge(context, sw);
try try {
{
String path = getGenPath(table, template); String path = getGenPath(table, template);
FileUtils.writeStringToFile(new File(path), sw.toString(), Constants.UTF8); FileUtils.writeStringToFile(new File(path), sw.toString(), Constants.UTF8);
} } catch (IOException e) {
catch (IOException e)
{
throw new CustomException("渲染模板失败,表名:" + table.getTableName()); throw new CustomException("渲染模板失败,表名:" + table.getTableName());
} }
} }
@ -285,31 +258,28 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
*/ */
@Override @Override
@Transactional @Transactional
public void synchDb(String tableName) public void synchDb(String tableName) {
{ GenTable table = baseMapper.selectGenTableByName(tableName);
GenTable table = genTableMapper.selectGenTableByName(tableName);
List<GenTableColumn> tableColumns = table.getColumns(); List<GenTableColumn> tableColumns = table.getColumns();
List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
if (Validator.isEmpty(dbTableColumns)) if (Validator.isEmpty(dbTableColumns)) {
{
throw new CustomException("同步数据失败,原表结构不存在"); throw new CustomException("同步数据失败,原表结构不存在");
} }
List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
dbTableColumns.forEach(column -> { dbTableColumns.forEach(column -> {
if (!tableColumnNames.contains(column.getColumnName())) if (!tableColumnNames.contains(column.getColumnName())) {
{
GenUtils.initColumnField(column, table); GenUtils.initColumnField(column, table);
genTableColumnMapper.insertGenTableColumn(column); genTableColumnMapper.insert(column);
} }
}); });
List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList()); List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(delColumns)) if (CollUtil.isNotEmpty(delColumns)) {
{ List<Long> ids = delColumns.stream().map(GenTableColumn::getColumnId).collect(Collectors.toList());
genTableColumnMapper.deleteGenTableColumns(delColumns); genTableColumnMapper.deleteBatchIds(ids);
} }
} }
@ -320,12 +290,10 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
* @return 数据 * @return 数据
*/ */
@Override @Override
public byte[] downloadCode(String[] tableNames) public byte[] downloadCode(String[] tableNames) {
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream); ZipOutputStream zip = new ZipOutputStream(outputStream);
for (String tableName : tableNames) for (String tableName : tableNames) {
{
generatorCode(tableName, zip); generatorCode(tableName, zip);
} }
IOUtils.closeQuietly(zip); IOUtils.closeQuietly(zip);
@ -335,10 +303,9 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
/** /**
* 查询表信息并生成代码 * 查询表信息并生成代码
*/ */
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); setSubTable(table);
// 设置主键列信息 // 设置主键列信息
@ -350,23 +317,19 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
// 获取模板列表 // 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
for (String template : templates) for (String template : templates) {
{
// 渲染模板 // 渲染模板
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, Constants.UTF8); Template tpl = Velocity.getTemplate(template, Constants.UTF8);
tpl.merge(context, sw); tpl.merge(context, sw);
try try {
{
// 添加到zip // 添加到zip
zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
IOUtils.write(sw.toString(), zip, Constants.UTF8); IOUtils.write(sw.toString(), zip, Constants.UTF8);
IOUtils.closeQuietly(sw); IOUtils.closeQuietly(sw);
zip.flush(); zip.flush();
zip.closeEntry(); zip.closeEntry();
} } catch (IOException e) {
catch (IOException e)
{
log.error("渲染模板失败,表名:" + table.getTableName(), e); log.error("渲染模板失败,表名:" + table.getTableName(), e);
} }
} }
@ -378,32 +341,20 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
* @param genTable 业务信息 * @param genTable 业务信息
*/ */
@Override @Override
public void validateEdit(GenTable genTable) public void validateEdit(GenTable genTable) {
{ if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) {
if (GenConstants.TPL_TREE.equals(genTable.getTplCategory()))
{
String options = JSON.toJSONString(genTable.getParams()); String options = JSON.toJSONString(genTable.getParams());
JSONObject paramsObj = JSONObject.parseObject(options); JSONObject paramsObj = JSONObject.parseObject(options);
if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) {
{
throw new CustomException("树编码字段不能为空"); 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("树父编码字段不能为空"); throw new CustomException("树父编码字段不能为空");
} } else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) {
else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_NAME)))
{
throw new CustomException("树名称字段不能为空"); throw new CustomException("树名称字段不能为空");
} } else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) {
else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) if (Validator.isEmpty(genTable.getSubTableName())) {
{
if (Validator.isEmpty(genTable.getSubTableName()))
{
throw new CustomException("关联子表的表名不能为空"); throw new CustomException("关联子表的表名不能为空");
} } else if (Validator.isEmpty(genTable.getSubTableFkName())) {
else if (Validator.isEmpty(genTable.getSubTableFkName()))
{
throw new CustomException("子表关联的外键名不能为空"); throw new CustomException("子表关联的外键名不能为空");
} }
} }
@ -415,32 +366,24 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
* *
* @param table 业务表信息 * @param table 业务表信息
*/ */
public void setPkColumn(GenTable table) public void setPkColumn(GenTable table) {
{ for (GenTableColumn column : table.getColumns()) {
for (GenTableColumn column : table.getColumns()) if (column.isPk()) {
{
if (column.isPk())
{
table.setPkColumn(column); table.setPkColumn(column);
break; break;
} }
} }
if (Validator.isNull(table.getPkColumn())) if (Validator.isNull(table.getPkColumn())) {
{
table.setPkColumn(table.getColumns().get(0)); table.setPkColumn(table.getColumns().get(0));
} }
if (GenConstants.TPL_SUB.equals(table.getTplCategory())) if (GenConstants.TPL_SUB.equals(table.getTplCategory())) {
{ for (GenTableColumn column : table.getSubTable().getColumns()) {
for (GenTableColumn column : table.getSubTable().getColumns()) if (column.isPk()) {
{
if (column.isPk())
{
table.getSubTable().setPkColumn(column); table.getSubTable().setPkColumn(column);
break; break;
} }
} }
if (Validator.isNull(table.getSubTable().getPkColumn())) if (Validator.isNull(table.getSubTable().getPkColumn())) {
{
table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0)); table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0));
} }
} }
@ -451,12 +394,10 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
* *
* @param table 业务表信息 * @param table 业务表信息
*/ */
public void setSubTable(GenTable table) public void setSubTable(GenTable table) {
{
String subTableName = table.getSubTableName(); String subTableName = table.getSubTableName();
if (Validator.isNotEmpty(subTableName)) if (Validator.isNotEmpty(subTableName)) {
{ table.setSubTable(baseMapper.selectGenTableByName(subTableName));
table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
} }
} }
@ -465,11 +406,9 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
* *
* @param genTable 设置后的生成对象 * @param genTable 设置后的生成对象
*/ */
public void setTableFromOptions(GenTable genTable) public void setTableFromOptions(GenTable genTable) {
{
JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions()); JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions());
if (Validator.isNotNull(paramsObj)) if (Validator.isNotNull(paramsObj)) {
{
String treeCode = paramsObj.getString(GenConstants.TREE_CODE); String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE); String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
String treeName = paramsObj.getString(GenConstants.TREE_NAME); String treeName = paramsObj.getString(GenConstants.TREE_NAME);
@ -491,11 +430,9 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
* @param template 模板文件路径 * @param template 模板文件路径
* @return 生成地址 * @return 生成地址
*/ */
public static String getGenPath(GenTable table, String template) public static String getGenPath(GenTable table, String template) {
{
String genPath = table.getGenPath(); 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 System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
} }
return genPath + File.separator + VelocityUtils.getFileName(template, table); return genPath + File.separator + VelocityUtils.getFileName(template, table);

View File

@ -10,8 +10,7 @@ import java.util.List;
* *
* @author ruoyi * @author ruoyi
*/ */
public interface IGenTableColumnService extends IService<GenTableColumn> public interface IGenTableColumnService extends IService<GenTableColumn> {
{
/** /**
* 查询业务字段列表 * 查询业务字段列表
* *

View File

@ -11,8 +11,7 @@ import java.util.Map;
* *
* @author ruoyi * @author ruoyi
*/ */
public interface IGenTableService extends IService<GenTable> public interface IGenTableService extends IService<GenTable> {
{
/** /**
* 查询业务列表 * 查询业务列表
* *

View File

@ -29,99 +29,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time" />
</resultMap> </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 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 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}) from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
order by ordinal_position order by ordinal_position
</select> </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> </mapper>

View File

@ -133,69 +133,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by c.sort order by c.sort
</select> </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> </mapper>

View File

@ -3,64 +3,11 @@ package com.ruoyi.quartz.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.quartz.domain.SysJobLog; import com.ruoyi.quartz.domain.SysJobLog;
import java.util.List;
/** /**
* 调度任务日志信息 数据层 * 调度任务日志信息 数据层
* *
* @author ruoyi * @author ruoyi
*/ */
public interface SysJobLogMapper extends BaseMapper<SysJobLog> public interface SysJobLogMapper extends BaseMapper<SysJobLog> {
{
/**
* 获取quartz调度器日志的计划任务
*
* @param jobLog 调度日志信息
* @return 调度任务日志集合
*/
public List<SysJobLog> selectJobLogList(SysJobLog jobLog);
/**
* 查询所有调度任务日志
*
* @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();
} }

View File

@ -3,67 +3,11 @@ package com.ruoyi.quartz.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.quartz.domain.SysJob; import com.ruoyi.quartz.domain.SysJob;
import java.util.List;
/** /**
* 调度任务信息 数据层 * 调度任务信息 数据层
* *
* @author ruoyi * @author ruoyi
*/ */
public interface SysJobMapper extends BaseMapper<SysJob> public interface SysJobMapper extends BaseMapper<SysJob> {
{
/**
* 查询调度任务日志集合
*
* @param job 调度信息
* @return 操作日志集合
*/
public List<SysJob> selectJobList(SysJob job);
/**
* 查询所有调度任务
*
* @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);
} }

View File

@ -10,8 +10,7 @@ import java.util.List;
* *
* @author ruoyi * @author ruoyi
*/ */
public interface ISysJobLogService extends IService<SysJobLog> public interface ISysJobLogService extends IService<SysJobLog> {
{
/** /**
* 获取quartz调度器日志的计划任务 * 获取quartz调度器日志的计划任务
* *

View File

@ -12,8 +12,7 @@ import java.util.List;
* *
* @author ruoyi * @author ruoyi
*/ */
public interface ISysJobService extends IService<SysJob> public interface ISysJobService extends IService<SysJob> {
{
/** /**
* 获取quartz调度器的计划任务 * 获取quartz调度器的计划任务
* *

View File

@ -1,13 +1,17 @@
package com.ruoyi.quartz.service.impl; 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 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.domain.SysJobLog;
import com.ruoyi.quartz.mapper.SysJobLogMapper; import com.ruoyi.quartz.mapper.SysJobLogMapper;
import com.ruoyi.quartz.service.ISysJobLogService; import com.ruoyi.quartz.service.ISysJobLogService;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/** /**
* 定时任务调度日志信息 服务层 * 定时任务调度日志信息 服务层
@ -15,10 +19,7 @@ import com.ruoyi.quartz.service.ISysJobLogService;
* @author ruoyi * @author ruoyi
*/ */
@Service @Service
public class SysJobLogServiceImpl extends ServiceImpl<SysJobLogMapper, SysJobLog> implements ISysJobLogService public class SysJobLogServiceImpl extends ServiceImpl<SysJobLogMapper, SysJobLog> implements ISysJobLogService {
{
@Autowired
private SysJobLogMapper jobLogMapper;
/** /**
* 获取quartz调度器日志的计划任务 * 获取quartz调度器日志的计划任务
@ -27,9 +28,19 @@ public class SysJobLogServiceImpl extends ServiceImpl<SysJobLogMapper, SysJobLog
* @return 调度任务日志集合 * @return 调度任务日志集合
*/ */
@Override @Override
public List<SysJobLog> selectJobLogList(SysJobLog jobLog) public List<SysJobLog> selectJobLogList(SysJobLog jobLog) {
{ Map<String, Object> params = jobLog.getParams();
return jobLogMapper.selectJobLogList(jobLog); 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")));
} }
/** /**
@ -39,9 +50,8 @@ public class SysJobLogServiceImpl extends ServiceImpl<SysJobLogMapper, SysJobLog
* @return 调度任务日志对象信息 * @return 调度任务日志对象信息
*/ */
@Override @Override
public SysJobLog selectJobLogById(Long jobLogId) public SysJobLog selectJobLogById(Long jobLogId) {
{ return getById(jobLogId);
return jobLogMapper.selectJobLogById(jobLogId);
} }
/** /**
@ -50,9 +60,8 @@ public class SysJobLogServiceImpl extends ServiceImpl<SysJobLogMapper, SysJobLog
* @param jobLog 调度日志信息 * @param jobLog 调度日志信息
*/ */
@Override @Override
public void addJobLog(SysJobLog jobLog) public void addJobLog(SysJobLog jobLog) {
{ baseMapper.insert(jobLog);
jobLogMapper.insertJobLog(jobLog);
} }
/** /**
@ -62,9 +71,8 @@ public class SysJobLogServiceImpl extends ServiceImpl<SysJobLogMapper, SysJobLog
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteJobLogByIds(Long[] logIds) public int deleteJobLogByIds(Long[] logIds) {
{ return baseMapper.deleteBatchIds(Arrays.asList(logIds));
return jobLogMapper.deleteJobLogByIds(logIds);
} }
/** /**
@ -73,17 +81,15 @@ public class SysJobLogServiceImpl extends ServiceImpl<SysJobLogMapper, SysJobLog
* @param jobId 调度日志ID * @param jobId 调度日志ID
*/ */
@Override @Override
public int deleteJobLogById(Long jobId) public int deleteJobLogById(Long jobId) {
{ return baseMapper.deleteById(jobId);
return jobLogMapper.deleteJobLogById(jobId);
} }
/** /**
* 清空任务日志 * 清空任务日志
*/ */
@Override @Override
public void cleanJobLog() public void cleanJobLog() {
{ remove(new LambdaQueryWrapper<>());
jobLogMapper.cleanJobLog();
} }
} }

View File

@ -1,16 +1,8 @@
package com.ruoyi.quartz.service.impl; package com.ruoyi.quartz.service.impl;
import java.util.List; import cn.hutool.core.util.StrUtil;
import javax.annotation.PostConstruct; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 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.constant.ScheduleConstants;
import com.ruoyi.common.exception.job.TaskException; import com.ruoyi.common.exception.job.TaskException;
import com.ruoyi.quartz.domain.SysJob; import com.ruoyi.quartz.domain.SysJob;
@ -18,6 +10,16 @@ import com.ruoyi.quartz.mapper.SysJobMapper;
import com.ruoyi.quartz.service.ISysJobService; import com.ruoyi.quartz.service.ISysJobService;
import com.ruoyi.quartz.util.CronUtils; import com.ruoyi.quartz.util.CronUtils;
import com.ruoyi.quartz.util.ScheduleUtils; 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;
/** /**
* 定时任务调度信息 服务层 * 定时任务调度信息 服务层
@ -25,24 +27,18 @@ import com.ruoyi.quartz.util.ScheduleUtils;
* @author ruoyi * @author ruoyi
*/ */
@Service @Service
public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> implements ISysJobService public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> implements ISysJobService {
{
@Autowired @Autowired
private Scheduler scheduler; private Scheduler scheduler;
@Autowired
private SysJobMapper jobMapper;
/** /**
* 项目启动时初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理不能手动修改数据库ID和任务组名否则会导致脏数据 * 项目启动时初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理不能手动修改数据库ID和任务组名否则会导致脏数据
*/ */
@PostConstruct @PostConstruct
public void init() throws SchedulerException, TaskException public void init() throws SchedulerException, TaskException {
{
scheduler.clear(); scheduler.clear();
List<SysJob> jobList = jobMapper.selectJobAll(); List<SysJob> jobList = list();
for (SysJob job : jobList) for (SysJob job : jobList) {
{
ScheduleUtils.createScheduleJob(scheduler, job); ScheduleUtils.createScheduleJob(scheduler, job);
} }
} }
@ -54,9 +50,12 @@ public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> impleme
* @return * @return
*/ */
@Override @Override
public List<SysJob> selectJobList(SysJob job) public List<SysJob> selectJobList(SysJob job) {
{ return list(new LambdaQueryWrapper<SysJob>()
return jobMapper.selectJobList(job); .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()));
} }
/** /**
@ -66,9 +65,8 @@ public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> impleme
* @return 调度任务对象信息 * @return 调度任务对象信息
*/ */
@Override @Override
public SysJob selectJobById(Long jobId) public SysJob selectJobById(Long jobId) {
{ return getById(jobId);
return jobMapper.selectJobById(jobId);
} }
/** /**
@ -78,14 +76,12 @@ public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> impleme
*/ */
@Override @Override
@Transactional @Transactional
public int pauseJob(SysJob job) throws SchedulerException public int pauseJob(SysJob job) throws SchedulerException {
{
Long jobId = job.getJobId(); Long jobId = job.getJobId();
String jobGroup = job.getJobGroup(); String jobGroup = job.getJobGroup();
job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
int rows = jobMapper.updateJob(job); int rows = baseMapper.updateById(job);
if (rows > 0) if (rows > 0) {
{
scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
} }
return rows; return rows;
@ -98,14 +94,12 @@ public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> impleme
*/ */
@Override @Override
@Transactional @Transactional
public int resumeJob(SysJob job) throws SchedulerException public int resumeJob(SysJob job) throws SchedulerException {
{
Long jobId = job.getJobId(); Long jobId = job.getJobId();
String jobGroup = job.getJobGroup(); String jobGroup = job.getJobGroup();
job.setStatus(ScheduleConstants.Status.NORMAL.getValue()); job.setStatus(ScheduleConstants.Status.NORMAL.getValue());
int rows = jobMapper.updateJob(job); int rows = baseMapper.updateById(job);
if (rows > 0) if (rows > 0) {
{
scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup)); scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup));
} }
return rows; return rows;
@ -118,13 +112,11 @@ public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> impleme
*/ */
@Override @Override
@Transactional @Transactional
public int deleteJob(SysJob job) throws SchedulerException public int deleteJob(SysJob job) throws SchedulerException {
{
Long jobId = job.getJobId(); Long jobId = job.getJobId();
String jobGroup = job.getJobGroup(); String jobGroup = job.getJobGroup();
int rows = jobMapper.deleteJobById(jobId); int rows = baseMapper.deleteById(jobId);
if (rows > 0) if (rows > 0) {
{
scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup)); scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup));
} }
return rows; return rows;
@ -138,11 +130,9 @@ public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> impleme
*/ */
@Override @Override
@Transactional @Transactional
public void deleteJobByIds(Long[] jobIds) throws SchedulerException public void deleteJobByIds(Long[] jobIds) throws SchedulerException {
{ for (Long jobId : jobIds) {
for (Long jobId : jobIds) SysJob job = getById(jobId);
{
SysJob job = jobMapper.selectJobById(jobId);
deleteJob(job); deleteJob(job);
} }
} }
@ -154,16 +144,12 @@ public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> impleme
*/ */
@Override @Override
@Transactional @Transactional
public int changeStatus(SysJob job) throws SchedulerException public int changeStatus(SysJob job) throws SchedulerException {
{
int rows = 0; int rows = 0;
String status = job.getStatus(); String status = job.getStatus();
if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) {
{
rows = resumeJob(job); rows = resumeJob(job);
} } else if (ScheduleConstants.Status.PAUSE.getValue().equals(status)) {
else if (ScheduleConstants.Status.PAUSE.getValue().equals(status))
{
rows = pauseJob(job); rows = pauseJob(job);
} }
return rows; return rows;
@ -176,8 +162,7 @@ public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> impleme
*/ */
@Override @Override
@Transactional @Transactional
public void run(SysJob job) throws SchedulerException public void run(SysJob job) throws SchedulerException {
{
Long jobId = job.getJobId(); Long jobId = job.getJobId();
String jobGroup = job.getJobGroup(); String jobGroup = job.getJobGroup();
SysJob properties = selectJobById(job.getJobId()); SysJob properties = selectJobById(job.getJobId());
@ -194,12 +179,10 @@ public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> impleme
*/ */
@Override @Override
@Transactional @Transactional
public int insertJob(SysJob job) throws SchedulerException, TaskException public int insertJob(SysJob job) throws SchedulerException, TaskException {
{
job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
int rows = jobMapper.insertJob(job); int rows = baseMapper.insert(job);
if (rows > 0) if (rows > 0) {
{
ScheduleUtils.createScheduleJob(scheduler, job); ScheduleUtils.createScheduleJob(scheduler, job);
} }
return rows; return rows;
@ -212,12 +195,10 @@ public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> impleme
*/ */
@Override @Override
@Transactional @Transactional
public int updateJob(SysJob job) throws SchedulerException, TaskException public int updateJob(SysJob job) throws SchedulerException, TaskException {
{
SysJob properties = selectJobById(job.getJobId()); SysJob properties = selectJobById(job.getJobId());
int rows = jobMapper.updateJob(job); int rows = baseMapper.updateById(job);
if (rows > 0) if (rows > 0) {
{
updateSchedulerJob(job, properties.getJobGroup()); updateSchedulerJob(job, properties.getJobGroup());
} }
return rows; return rows;
@ -229,13 +210,11 @@ public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> impleme
* @param job 任务对象 * @param job 任务对象
* @param jobGroup 任务组名 * @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(); Long jobId = job.getJobId();
// 判断是否存在 // 判断是否存在
JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup); JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
if (scheduler.checkExists(jobKey)) if (scheduler.checkExists(jobKey)) {
{
// 防止创建时存在数据问题 先移除,然后在执行创建操作 // 防止创建时存在数据问题 先移除,然后在执行创建操作
scheduler.deleteJob(jobKey); scheduler.deleteJob(jobKey);
} }
@ -249,8 +228,7 @@ public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> impleme
* @return 结果 * @return 结果
*/ */
@Override @Override
public boolean checkCronExpressionIsValid(String cronExpression) public boolean checkCronExpressionIsValid(String cronExpression) {
{
return CronUtils.isValid(cronExpression); return CronUtils.isValid(cronExpression);
} }
} }

View File

@ -15,79 +15,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
</resultMap> </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') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(create_time,'%y%m%d') &lt;= 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> </mapper>

View File

@ -20,92 +20,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="remark" column="remark" /> <result property="remark" column="remark" />
</resultMap> </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> </mapper>

View File

@ -2,46 +2,12 @@ package com.ruoyi.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.common.core.domain.entity.SysDictType; import com.ruoyi.common.core.domain.entity.SysDictType;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/** /**
* 字典表 数据层 * 字典表 数据层
* *
* @author ruoyi * @author ruoyi
*/ */
@Mapper
public interface SysDictTypeMapper extends BaseMapper<SysDictType> { 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);
} }

View File

@ -16,8 +16,7 @@ import com.ruoyi.system.domain.SysUserRole;
import com.ruoyi.system.mapper.*; import com.ruoyi.system.mapper.*;
import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.service.ISysUserService;
import org.slf4j.Logger; import lombok.extern.slf4j.Slf4j;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -31,12 +30,9 @@ import java.util.List;
* *
* @author ruoyi * @author ruoyi
*/ */
@Slf4j
@Service @Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService { public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
@Autowired
private SysUserMapper userMapper;
@Autowired @Autowired
private SysRoleMapper roleMapper; private SysRoleMapper roleMapper;
@ -62,7 +58,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override @Override
@DataScope(deptAlias = "d", userAlias = "u") @DataScope(deptAlias = "d", userAlias = "u")
public List<SysUser> selectUserList(SysUser user) { public List<SysUser> selectUserList(SysUser user) {
return userMapper.selectUserList(user); return baseMapper.selectUserList(user);
} }
/** /**
@ -73,7 +69,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
*/ */
@Override @Override
public SysUser selectUserByUserName(String userName) { public SysUser selectUserByUserName(String userName) {
return userMapper.selectUserByUserName(userName); return baseMapper.selectUserByUserName(userName);
} }
/** /**
@ -84,7 +80,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
*/ */
@Override @Override
public SysUser selectUserById(Long userId) { public SysUser selectUserById(Long userId) {
return userMapper.selectUserById(userId); return baseMapper.selectUserById(userId);
} }
/** /**
@ -198,7 +194,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Transactional @Transactional
public int insertUser(SysUser user) { public int insertUser(SysUser user) {
// 新增用户信息 // 新增用户信息
int rows = userMapper.insert(user); int rows = baseMapper.insert(user);
// 新增用户岗位关联 // 新增用户岗位关联
insertUserPost(user); insertUserPost(user);
// 新增用户与角色管理 // 新增用户与角色管理
@ -224,7 +220,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getUserId,userId)); userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getUserId,userId));
// 新增用户与岗位管理 // 新增用户与岗位管理
insertUserPost(user); insertUserPost(user);
return userMapper.updateById(user); return baseMapper.updateById(user);
} }
/** /**
@ -235,7 +231,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
*/ */
@Override @Override
public int updateUserStatus(SysUser user) { public int updateUserStatus(SysUser user) {
return userMapper.updateById(user); return baseMapper.updateById(user);
} }
/** /**
@ -246,7 +242,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
*/ */
@Override @Override
public int updateUserProfile(SysUser user) { public int updateUserProfile(SysUser user) {
return userMapper.updateById(user); return baseMapper.updateById(user);
} }
/** /**
@ -258,7 +254,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
*/ */
@Override @Override
public boolean updateUserAvatar(String userName, String avatar) { public boolean updateUserAvatar(String userName, String avatar) {
return userMapper.update(null, return baseMapper.update(null,
new LambdaUpdateWrapper<SysUser>() new LambdaUpdateWrapper<SysUser>()
.set(SysUser::getAvatar,avatar) .set(SysUser::getAvatar,avatar)
.eq(SysUser::getUserName,userName)) > 0; .eq(SysUser::getUserName,userName)) > 0;
@ -272,7 +268,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
*/ */
@Override @Override
public int resetPwd(SysUser user) { public int resetPwd(SysUser user) {
return userMapper.updateById(user); return baseMapper.updateById(user);
} }
/** /**
@ -284,7 +280,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
*/ */
@Override @Override
public int resetUserPwd(String userName, String password) { public int resetUserPwd(String userName, String password) {
return userMapper.update(null, return baseMapper.update(null,
new LambdaUpdateWrapper<SysUser>() new LambdaUpdateWrapper<SysUser>()
.set(SysUser::getPassword,password) .set(SysUser::getPassword,password)
.eq(SysUser::getUserName,userName)); .eq(SysUser::getUserName,userName));
@ -351,7 +347,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId,userId)); userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId,userId));
// 删除用户与岗位表 // 删除用户与岗位表
userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getUserId,userId)); userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getUserId,userId));
return userMapper.deleteById(userId); return baseMapper.deleteById(userId);
} }
/** /**
@ -371,7 +367,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getUserId,ids)); userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getUserId,ids));
// 删除用户与岗位表 // 删除用户与岗位表
userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().in(SysUserPost::getUserId,ids)); userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().in(SysUserPost::getUserId,ids));
return userMapper.deleteBatchIds(ids); return baseMapper.deleteBatchIds(ids);
} }
/** /**
@ -395,7 +391,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
for (SysUser user : userList) { for (SysUser user : userList) {
try { try {
// 验证是否存在这个用户 // 验证是否存在这个用户
SysUser u = userMapper.selectUserByUserName(user.getUserName()); SysUser u = baseMapper.selectUserByUserName(user.getUserName());
if (Validator.isNull(u)) { if (Validator.isNull(u)) {
user.setPassword(SecurityUtils.encryptPassword(password)); user.setPassword(SecurityUtils.encryptPassword(password));
user.setCreateBy(operName); user.setCreateBy(operName);

View File

@ -15,28 +15,4 @@
<result property="updateTime" column="update_time"/> <result property="updateTime" column="update_time"/>
</resultMap> </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> </mapper>