feat();代码生成器更改

boot3.0
dongzeliang 2025-03-19 15:07:51 +08:00
parent 3ab7f9fec8
commit 72b0510f9e
12 changed files with 74 additions and 17 deletions

View File

@ -1,5 +1,6 @@
package com.muyu.common.core.web.domain; package com.muyu.common.core.web.domain;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
@ -36,12 +37,14 @@ public class BaseEntity implements Serializable {
/** /**
* *
*/ */
@TableField(fill = FieldFill.INSERT)
private String createBy; private String createBy;
/** /**
* *
*/ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(fill = FieldFill.INSERT)
private Date createTime; private Date createTime;
/** /**
@ -53,11 +56,13 @@ public class BaseEntity implements Serializable {
* *
*/ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(fill = FieldFill.UPDATE)
private Date updateTime; private Date updateTime;
/** /**
* *
*/ */
@TableField(fill = FieldFill.UPDATE)
private String remark; private String remark;
/** /**

View File

@ -2,6 +2,7 @@ package com.muyu.common.system.domain;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.core.annotation.Excel; import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.annotation.Excel.ColumnType; import com.muyu.common.core.annotation.Excel.ColumnType;
@ -21,6 +22,7 @@ import java.util.Date;
@SuperBuilder @SuperBuilder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@TableName(value = "sys_logininfor", autoResultMap = true)
public class SysLogininfor { public class SysLogininfor {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -28,7 +30,7 @@ public class SysLogininfor {
* ID * ID
*/ */
@Excel(name = "序号", cellType = ColumnType.NUMERIC) @Excel(name = "序号", cellType = ColumnType.NUMERIC)
@TableId(type = IdType.AUTO) @TableId(value = "info_id", type = IdType.AUTO)
private Long infoId; private Long infoId;
/** /**

View File

@ -1,5 +1,8 @@
package com.muyu.common.system.domain; package com.muyu.common.system.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.core.annotation.Excel; import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.annotation.Excel.ColumnType; import com.muyu.common.core.annotation.Excel.ColumnType;
@ -19,12 +22,14 @@ import java.util.Date;
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@TableName(value = "sys_oper_log", autoResultMap = true)
public class SysOperLog { public class SysOperLog {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* *
*/ */
@TableId(value = "oper_id", type = IdType.AUTO)
@Excel(name = "操作序号", cellType = ColumnType.NUMERIC) @Excel(name = "操作序号", cellType = ColumnType.NUMERIC)
private Long operId; private Long operId;

View File

@ -1,7 +1,6 @@
package com.muyu.common.system.domain; package com.muyu.common.system.domain;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.muyu.common.core.annotation.Excel; import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.annotation.Excel.ColumnType; import com.muyu.common.core.annotation.Excel.ColumnType;
import com.muyu.common.core.web.domain.BaseEntity; import com.muyu.common.core.web.domain.BaseEntity;
@ -26,12 +25,14 @@ import java.util.Set;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@TableName(value = "sys_role", autoResultMap = true)
public class SysRole extends BaseEntity { public class SysRole extends BaseEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* ID * ID
*/ */
@TableId(value = "role_id", type = IdType.AUTO)
@Excel(name = "角色序号", cellType = ColumnType.NUMERIC) @Excel(name = "角色序号", cellType = ColumnType.NUMERIC)
private Long roleId; private Long roleId;

View File

@ -1,5 +1,9 @@
package com.muyu.common.system.domain; package com.muyu.common.system.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.annotation.Excel; import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.annotation.Excel.ColumnType; import com.muyu.common.core.annotation.Excel.ColumnType;
import com.muyu.common.core.annotation.Excel.Type; import com.muyu.common.core.annotation.Excel.Type;
@ -28,12 +32,14 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@TableName(value = "sys_user", autoResultMap = true)
public class SysUser extends BaseEntity { public class SysUser extends BaseEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* ID * ID
*/ */
@TableId(value = "user_id", type = IdType.AUTO)
@Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号") @Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
private Long userId; private Long userId;
@ -113,26 +119,31 @@ public class SysUser extends BaseEntity {
@Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT), @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
@Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT) @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
}) })
@TableField(exist = false)
private SysDept dept; private SysDept dept;
/** /**
* *
*/ */
@TableField(exist = false)
private List<SysRole> roles; private List<SysRole> roles;
/** /**
* *
*/ */
@TableField(exist = false)
private Long[] roleIds; private Long[] roleIds;
/** /**
* *
*/ */
@TableField(exist = false)
private Long[] postIds; private Long[] postIds;
/** /**
* ID * ID
*/ */
@TableField(exist = false)
private Long roleId; private Long roleId;
public SysUser (Long userId) { public SysUser (Long userId) {

View File

@ -10,7 +10,6 @@ import org.springframework.stereotype.Component;
* *
* @author muyu * @author muyu
*/ */
@Data
@Component @Component
@ConfigurationProperties(prefix = "gen") @ConfigurationProperties(prefix = "gen")
public class GenConfig { public class GenConfig {
@ -40,4 +39,20 @@ public class GenConfig {
public static boolean getAutoRemovePre () { public static boolean getAutoRemovePre () {
return autoRemovePre; return autoRemovePre;
} }
public void setAuthor(String author) {
GenConfig.author = author;
}
public void setPackageName(String packageName) {
GenConfig.packageName = packageName;
}
public void setAutoRemovePre(boolean autoRemovePre) {
GenConfig.autoRemovePre = autoRemovePre;
}
public void setTablePrefix(String tablePrefix) {
GenConfig.tablePrefix = tablePrefix;
}
} }

View File

@ -66,7 +66,7 @@ public class GenController extends BaseController {
* *
*/ */
@RequiresPermissions("tool:gen:list") @RequiresPermissions("tool:gen:list")
@GetMapping("/db/list") @PostMapping("/db/list")
public Result<DataPageResp<GenTable>> dataList (GenTable genTable) { public Result<DataPageResp<GenTable>> dataList (GenTable genTable) {
List<GenTable> list = genTableService.selectDbTableList(genTable); List<GenTable> list = genTableService.selectDbTableList(genTable);
return Result.success(new DataPageResp<>(0,list)); return Result.success(new DataPageResp<>(0,list));
@ -92,7 +92,7 @@ public class GenController extends BaseController {
@RequiresPermissions("tool:gen:import") @RequiresPermissions("tool:gen:import")
@Log(title = "代码生成", businessType = BusinessType.IMPORT) @Log(title = "代码生成", businessType = BusinessType.IMPORT)
@PostMapping("/importTable") @PostMapping("/importTable")
public Result<String> importTableSave (String tables) { public Result<String> importTableSave (@RequestParam("tables") String tables) {
String[] tableNames = Convert.toStrArray(tables); String[] tableNames = Convert.toStrArray(tables);
// 查询表信息 // 查询表信息
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames); List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
@ -172,7 +172,7 @@ public class GenController extends BaseController {
@RequiresPermissions("tool:gen:code") @RequiresPermissions("tool:gen:code")
@Log(title = "代码生成", businessType = BusinessType.GENCODE) @Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/batchGenCode") @GetMapping("/batchGenCode")
public void batchGenCode (HttpServletResponse response, String tables) throws IOException { public void batchGenCode (HttpServletResponse response, @RequestParam("tables") String tables) throws IOException {
String[] tableNames = Convert.toStrArray(tables); String[] tableNames = Convert.toStrArray(tables);
byte[] data = genTableService.downloadCode(tableNames); byte[] data = genTableService.downloadCode(tableNames);
genCode(response, data); genCode(response, data);

View File

@ -1,5 +1,9 @@
package com.muyu.gen.domain; package com.muyu.gen.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.constant.GenConstants; import com.muyu.common.core.constant.GenConstants;
import com.muyu.common.core.utils.StringUtils; import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.core.web.domain.BaseEntity; import com.muyu.common.core.web.domain.BaseEntity;
@ -27,12 +31,14 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@TableName(value = "gen_table", autoResultMap = true)
public class GenTable extends BaseEntity { public class GenTable extends BaseEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* *
*/ */
@TableId(value = "table_id", type = IdType.AUTO)
private Long tableId; private Long tableId;
/** /**
@ -111,17 +117,20 @@ public class GenTable extends BaseEntity {
/** /**
* *
*/ */
@TableField(exist = false)
private GenTableColumn pkColumn; private GenTableColumn pkColumn;
/** /**
* *
*/ */
@TableField(exist = false)
private GenTable subTable; private GenTable subTable;
/** /**
* *
*/ */
@Valid @Valid
@TableField(exist = false)
private List<GenTableColumn> columns; private List<GenTableColumn> columns;
/** /**

View File

@ -1,5 +1,8 @@
package com.muyu.gen.domain; package com.muyu.gen.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.utils.StringUtils; import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.core.web.domain.BaseEntity; import com.muyu.common.core.web.domain.BaseEntity;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
@ -21,12 +24,14 @@ import static com.muyu.common.core.constant.SplitConstants.*;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@TableName(value = "gen_table_column", autoResultMap = true)
public class GenTableColumn extends BaseEntity { public class GenTableColumn extends BaseEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* *
*/ */
@TableId(value = "table_id", type = IdType.AUTO)
private Long columnId; private Long columnId;
/** /**

View File

@ -2,6 +2,7 @@ package com.muyu.gen.service.impl;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.muyu.common.core.constant.Constants; import com.muyu.common.core.constant.Constants;
import com.muyu.common.core.constant.GenConstants; import com.muyu.common.core.constant.GenConstants;
import com.muyu.common.core.exception.ServiceException; import com.muyu.common.core.exception.ServiceException;
@ -164,8 +165,10 @@ public class GenTableServiceImpl implements IGenTableService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deleteGenTableByIds (List<Long> tableIds) { public void deleteGenTableByIds (List<Long> tableIds) {
genTableMapper.deleteGenTableByIds(tableIds); this.genTableMapper.deleteByIds(tableIds);
genTableColumnMapper.deleteGenTableColumnByIds(tableIds); LambdaQueryWrapper<GenTableColumn> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(GenTableColumn::getTableId, tableIds);
this.genTableColumnMapper.delete(queryWrapper);
} }
/** /**
@ -192,6 +195,7 @@ public class GenTableServiceImpl implements IGenTableService {
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("代码生成器倒入表报错:「{}」", e.getMessage(),e);
throw new ServiceException("导入失败:" + e.getMessage()); throw new ServiceException("导入失败:" + e.getMessage());
} }
} }

View File

@ -182,9 +182,9 @@ public class SysUserController extends BaseController {
public Result<String> add (@Validated @RequestBody SysUser user) { public Result<String> add (@Validated @RequestBody SysUser user) {
if (userService.checkUserNameUnique(user)) { if (userService.checkUserNameUnique(user)) {
return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && userService.checkPhoneUnique(user)) {
return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
} else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { } else if (StringUtils.isNotEmpty(user.getEmail()) && userService.checkEmailUnique(user)) {
return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在"); return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
} }
user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
@ -203,9 +203,9 @@ public class SysUserController extends BaseController {
userService.checkUserDataScope(user.getUserId()); userService.checkUserDataScope(user.getUserId());
if (userService.checkUserNameUnique(user)) { if (userService.checkUserNameUnique(user)) {
return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && userService.checkPhoneUnique(user)) {
return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
} else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { } else if (StringUtils.isNotEmpty(user.getEmail()) && userService.checkEmailUnique(user)) {
return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
} }
userService.updateUser(user); userService.updateUser(user);

View File

@ -172,7 +172,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
LambdaQueryWrapper<SysUser> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(SysUser::getUserName, user.getUserName()); lambdaQueryWrapper.eq(SysUser::getUserName, user.getUserName());
lambdaQueryWrapper.eq(SysUser::getDelFlag, SysDelFlagEnum.EXIST.getCode()); lambdaQueryWrapper.eq(SysUser::getDelFlag, SysDelFlagEnum.EXIST.getCode());
lambdaQueryWrapper.eq(user.getUserId() != null,SysUser::getUserId, user.getUserId()); lambdaQueryWrapper.ne(user.getUserId() != null,SysUser::getUserId, user.getUserId());
if (this.count(lambdaQueryWrapper) > 0) { if (this.count(lambdaQueryWrapper) > 0) {
return UserConstants.UNIQUE; return UserConstants.UNIQUE;
} }
@ -191,7 +191,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
LambdaQueryWrapper<SysUser> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(SysUser::getPhonenumber, user.getPhonenumber()); lambdaQueryWrapper.eq(SysUser::getPhonenumber, user.getPhonenumber());
lambdaQueryWrapper.eq(SysUser::getDelFlag, SysDelFlagEnum.EXIST.getCode()); lambdaQueryWrapper.eq(SysUser::getDelFlag, SysDelFlagEnum.EXIST.getCode());
lambdaQueryWrapper.eq(user.getUserId() != null,SysUser::getUserId, user.getUserId()); lambdaQueryWrapper.ne(user.getUserId() != null,SysUser::getUserId, user.getUserId());
if (this.count(lambdaQueryWrapper) > 0) { if (this.count(lambdaQueryWrapper) > 0) {
return UserConstants.UNIQUE; return UserConstants.UNIQUE;
} }
@ -210,7 +210,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
LambdaQueryWrapper<SysUser> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(SysUser::getEmail, user.getEmail()); lambdaQueryWrapper.eq(SysUser::getEmail, user.getEmail());
lambdaQueryWrapper.eq(SysUser::getDelFlag, SysDelFlagEnum.EXIST.getCode()); lambdaQueryWrapper.eq(SysUser::getDelFlag, SysDelFlagEnum.EXIST.getCode());
lambdaQueryWrapper.eq(user.getUserId() != null,SysUser::getUserId, user.getUserId()); lambdaQueryWrapper.ne(user.getUserId() != null,SysUser::getUserId, user.getUserId());
if (this.count(lambdaQueryWrapper) > 0) { if (this.count(lambdaQueryWrapper) > 0) {
return UserConstants.UNIQUE; return UserConstants.UNIQUE;
} }
@ -352,7 +352,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
public void updateUserAvatar (String userName, String avatar) { public void updateUserAvatar (String userName, String avatar) {
LambdaUpdateWrapper<SysUser> lambdaUpdateWrapper = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<SysUser> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.eq(SysUser::getUserName, userName); lambdaUpdateWrapper.eq(SysUser::getUserName, userName);
lambdaUpdateWrapper.eq(SysUser::getAvatar, avatar); lambdaUpdateWrapper.set(SysUser::getAvatar, avatar);
this.update(lambdaUpdateWrapper); this.update(lambdaUpdateWrapper);
} }