update 优化命名注释等细节

This commit is contained in:
phanes 2022-03-30 19:35:47 +08:00
parent c74b878372
commit 4799228bb2
13 changed files with 117 additions and 86 deletions

View File

@ -49,46 +49,46 @@ public interface GenConstants {
/**
* 数据库字符串类型
*/
String[] COLUMNTYPE_STR = {"char", "varchar", "nvarchar", "varchar2"};
String[] COLUMN_TYPE_STR = {"char", "varchar", "nvarchar", "varchar2"};
/**
* 数据库文本类型
*/
String[] COLUMNTYPE_TEXT = {"tinytext", "text", "mediumtext", "longtext"};
String[] COLUMN_TYPE_TEXT = {"tinytext", "text", "mediumtext", "longtext"};
/**
* 数据库时间类型
*/
String[] COLUMNTYPE_TIME = {"datetime", "time", "date", "timestamp"};
String[] COLUMN_TYPE_TIME = {"datetime", "time", "date", "timestamp"};
/**
* 数据库数字类型
*/
String[] COLUMNTYPE_NUMBER = {"tinyint", "smallint", "mediumint", "int", "number", "integer",
String[] COLUMN_TYPE_NUMBER = {"tinyint", "smallint", "mediumint", "int", "number", "integer",
"bit", "bigint", "float", "double", "decimal"};
/**
* BO对象 不需要添加字段
*/
String[] COLUMNNAME_NOT_ADD = {"create_by", "create_time", "del_flag", "update_by",
String[] COLUMN_NAME_NOT_ADD = {"create_by", "create_time", "del_flag", "update_by",
"update_time", "version"};
/**
* BO对象 不需要编辑字段
*/
String[] COLUMNNAME_NOT_EDIT = {"create_by", "create_time", "del_flag", "update_by",
String[] COLUMN_NAME_NOT_EDIT = {"create_by", "create_time", "del_flag", "update_by",
"update_time", "version"};
/**
* VO对象 不需要返回字段
*/
String[] COLUMNNAME_NOT_LIST = {"create_by", "create_time", "del_flag", "update_by",
String[] COLUMN_NAME_NOT_LIST = {"create_by", "create_time", "del_flag", "update_by",
"update_time", "version"};
/**
* BO对象 不需要查询字段
*/
String[] COLUMNNAME_NOT_QUERY = {"id", "create_by", "create_time", "del_flag", "update_by",
String[] COLUMN_NAME_NOT_QUERY = {"id", "create_by", "create_time", "del_flag", "update_by",
"update_time", "remark", "version"};
/**
@ -169,7 +169,7 @@ public interface GenConstants {
/**
* 高精度计算类型
*/
String TYPE_BIGDECIMAL = "BigDecimal";
String TYPE_BIG_DECIMAL = "BigDecimal";
/**
* 时间类型

View File

@ -89,7 +89,7 @@ public class DefaultExcelListener<T> extends AnalysisEventListener<T> implements
@Override
public void invoke(T data, AnalysisContext context) {
if (isValidate) {
if (Boolean.TRUE.equals(isValidate)) {
ValidatorUtils.validate(data);
}
excelResult.getList().add(data);

View File

@ -66,10 +66,7 @@ public class BeanCopyUtils {
* @return desc
*/
public static <T, V> List<V> copyList(List<T> sourceList, Class<V> desc) {
if (ObjectUtil.isNull(sourceList)) {
return null;
}
if (CollUtil.isEmpty(sourceList)) {
if (ObjectUtil.isNull(sourceList) || CollUtil.isEmpty(sourceList)) {
return CollUtil.newArrayList();
}
return CglibUtil.copyList(sourceList, () -> ReflectUtil.newInstanceIfPossible(desc));
@ -83,7 +80,7 @@ public class BeanCopyUtils {
*/
public static <T> Map<String, Object> copyToMap(T bean) {
if (ObjectUtil.isNull(bean)) {
return null;
return MapUtil.newHashMap();
}
return CglibUtil.toMap(bean);
}

View File

@ -22,17 +22,17 @@ import java.util.Date;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
public static String YYYY = "yyyy";
public static final String YYYY = "yyyy";
public static String YYYY_MM = "yyyy-MM";
public static final String YYYY_MM = "yyyy-MM";
public static String YYYY_MM_DD = "yyyy-MM-dd";
public static final String YYYY_MM_DD = "yyyy-MM-dd";
public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
public static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
private static String[] parsePatterns = {
private static final String[] PARSE_PATTERNS = {
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
@ -107,7 +107,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
return null;
}
try {
return parseDate(str.toString(), parsePatterns);
return parseDate(str.toString(), PARSE_PATTERNS);
} catch (ParseException e) {
return null;
}
@ -124,8 +124,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
/**
* 计算相差天数
*/
public static int differentDaysByMillisecond(Date date1, Date date2)
{
public static int differentDaysByMillisecond(Date date1, Date date2) {
return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24)));
}
@ -133,10 +132,10 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
* 计算两个时间差
*/
public static String getDatePoor(Date endDate, Date nowDate) {
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
// long ns = 1000;
long nd = 1000L * 24 * 60 * 60;
long nh = 1000L * 60 * 60;
long nm = 1000L * 60;
// long ns = 1000L;
// 获得两个时间的毫秒时间差异
long diff = endDate.getTime() - nowDate.getTime();
// 计算差多少天

View File

@ -18,10 +18,10 @@ import java.awt.*;
@Configuration
public class CaptchaConfig {
private final int width = 160;
private final int height = 60;
private final Color background = Color.PINK;
private final Font font = new Font("Arial", Font.BOLD, 48);
private static final int WIDTH = 160;
private static final int HEIGHT = 60;
private static final Color BACKGROUND = Color.PINK;
private static final Font FONT = new Font("Arial", Font.BOLD, 48);
/**
* 圆圈干扰验证码
@ -29,9 +29,9 @@ public class CaptchaConfig {
@Lazy
@Bean
public CircleCaptcha circleCaptcha() {
CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(width, height);
captcha.setBackground(background);
captcha.setFont(font);
CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(WIDTH, HEIGHT);
captcha.setBackground(BACKGROUND);
captcha.setFont(FONT);
return captcha;
}
@ -41,9 +41,9 @@ public class CaptchaConfig {
@Lazy
@Bean
public LineCaptcha lineCaptcha() {
LineCaptcha captcha = CaptchaUtil.createLineCaptcha(width, height);
captcha.setBackground(background);
captcha.setFont(font);
LineCaptcha captcha = CaptchaUtil.createLineCaptcha(WIDTH, HEIGHT);
captcha.setBackground(BACKGROUND);
captcha.setFont(FONT);
return captcha;
}
@ -53,9 +53,9 @@ public class CaptchaConfig {
@Lazy
@Bean
public ShearCaptcha shearCaptcha() {
ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(width, height);
captcha.setBackground(background);
captcha.setFont(font);
ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(WIDTH, HEIGHT);
captcha.setBackground(BACKGROUND);
captcha.setFont(FONT);
return captcha;
}

View File

@ -1,5 +1,6 @@
package com.ruoyi.framework.config;
import cn.hutool.core.map.MapUtil;
import com.ruoyi.common.filter.RepeatableFilter;
import com.ruoyi.common.filter.XssFilter;
import com.ruoyi.common.utils.StringUtils;
@ -11,7 +12,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.DispatcherType;
import java.util.HashMap;
import java.util.Map;
/**
@ -35,7 +35,7 @@ public class FilterConfig {
registration.addUrlPatterns(StringUtils.split(xssProperties.getUrlPatterns(), ","));
registration.setName("xssFilter");
registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE);
Map<String, String> initParameters = new HashMap<String, String>();
Map<String, String> initParameters = MapUtil.newHashMap(1);
initParameters.put("excludes", xssProperties.getExcludes());
registration.setInitParameters(initParameters);
return registration;

View File

@ -3,6 +3,7 @@ package com.ruoyi.generator.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.map.MapUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
@ -16,11 +17,17 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -58,7 +65,7 @@ public class GenController extends BaseController {
GenTable table = genTableService.selectGenTableById(tableId);
List<GenTable> tables = genTableService.selectGenTableAll();
List<GenTableColumn> list = genTableService.selectGenTableColumnListByTableId(tableId);
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = MapUtil.newHashMap(3);
map.put("info", table);
map.put("rows", list);
map.put("tables", tables);

View File

@ -39,7 +39,11 @@ import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
@ -59,6 +63,21 @@ public class GenTableServiceImpl implements IGenTableService {
private final GenTableMapper baseMapper;
private final GenTableColumnMapper genTableColumnMapper;
/**
* 获取代码生成地址
*
* @param table 业务表信息
* @param template 模板文件路径
* @return 生成地址
*/
public static String getGenPath(GenTable table, String template) {
String genPath = table.getGenPath();
if (StringUtils.equals(genPath, "/")) {
return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
}
return genPath + File.separator + VelocityUtils.getFileName(template, table);
}
/**
* 查询业务字段列表
*
@ -101,7 +120,6 @@ public class GenTableServiceImpl implements IGenTableService {
return wrapper;
}
@Override
public TableDataInfo<GenTable> selectPageDbTableList(GenTable genTable, PageQuery pageQuery) {
Page<GenTable> page = baseMapper.selectPageDbTableList(pageQuery.build(), genTable);
@ -294,7 +312,7 @@ public class GenTableServiceImpl implements IGenTableService {
if (CollUtil.isEmpty(dbTableColumns)) {
throw new ServiceException("同步数据失败,原表结构不存在");
}
List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
Map<String, String> dbTableColumnNameMap = dbTableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, GenTableColumn::getColumnName));
List<GenTableColumn> saveColumns = new ArrayList<>();
dbTableColumns.forEach(column -> {
@ -323,10 +341,9 @@ public class GenTableServiceImpl implements IGenTableService {
genTableColumnMapper.insertBatch(saveColumns);
}
List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(delColumns)) {
List<Long> ids = delColumns.stream().map(GenTableColumn::getColumnId).collect(Collectors.toList());
genTableColumnMapper.deleteBatchIds(ids);
List<Long> delColumnIds = tableColumns.stream().filter(column -> !dbTableColumnNameMap.containsKey(column.getColumnName())).map(GenTableColumn::getColumnId).collect(Collectors.toList());
if (CollUtil.isNotEmpty(delColumnIds)) {
genTableColumnMapper.deleteBatchIds(delColumnIds);
}
}
@ -475,20 +492,5 @@ public class GenTableServiceImpl implements IGenTableService {
genTable.setParentMenuName(parentMenuName);
}
}
/**
* 获取代码生成地址
*
* @param table 业务表信息
* @param template 模板文件路径
* @return 生成地址
*/
public static String getGenPath(GenTable table, String template) {
String genPath = table.getGenPath();
if (StringUtils.equals(genPath, "/")) {
return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
}
return genPath + File.separator + VelocityUtils.getFileName(template, table);
}
}

View File

@ -5,6 +5,8 @@ import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.generator.config.GenConfig;
import com.ruoyi.generator.domain.GenTable;
import com.ruoyi.generator.domain.GenTableColumn;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.RegExUtils;
import java.util.Arrays;
@ -14,6 +16,7 @@ import java.util.Arrays;
*
* @author ruoyi
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class GenUtils {
/**
@ -43,21 +46,21 @@ public class GenUtils {
column.setJavaType(GenConstants.TYPE_STRING);
column.setQueryType(GenConstants.QUERY_EQ);
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) {
if (arraysContains(GenConstants.COLUMN_TYPE_STR, dataType) || arraysContains(GenConstants.COLUMN_TYPE_TEXT, dataType)) {
// 字符串长度超过500设置为文本域
Integer columnLength = getColumnLength(column.getColumnType());
String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMN_TYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
column.setHtmlType(htmlType);
} else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) {
} else if (arraysContains(GenConstants.COLUMN_TYPE_TIME, dataType)) {
column.setJavaType(GenConstants.TYPE_DATE);
column.setHtmlType(GenConstants.HTML_DATETIME);
} else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
} else if (arraysContains(GenConstants.COLUMN_TYPE_NUMBER, dataType)) {
column.setHtmlType(GenConstants.HTML_INPUT);
// 如果是浮点型 统一用BigDecimal
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
column.setJavaType(GenConstants.TYPE_BIG_DECIMAL);
}
// 如果是整形
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
@ -70,23 +73,23 @@ public class GenUtils {
}
// BO对象 默认插入勾选
if (!arraysContains(GenConstants.COLUMNNAME_NOT_ADD, columnName) && !column.isPk()) {
if (!arraysContains(GenConstants.COLUMN_NAME_NOT_ADD, columnName) && !column.isPk()) {
column.setIsInsert(GenConstants.REQUIRE);
}
// BO对象 默认编辑勾选
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName)) {
if (!arraysContains(GenConstants.COLUMN_NAME_NOT_EDIT, columnName)) {
column.setIsEdit(GenConstants.REQUIRE);
}
// BO对象 默认是否必填勾选
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName)) {
if (!arraysContains(GenConstants.COLUMN_NAME_NOT_EDIT, columnName)) {
column.setIsRequired(GenConstants.REQUIRE);
}
// VO对象 默认返回勾选
if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName)) {
if (!arraysContains(GenConstants.COLUMN_NAME_NOT_LIST, columnName)) {
column.setIsList(GenConstants.REQUIRE);
}
// BO对象 默认查询勾选
if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) {
if (!arraysContains(GenConstants.COLUMN_NAME_NOT_QUERY, columnName) && !column.isPk()) {
column.setIsQuery(GenConstants.REQUIRE);
}

View File

@ -1,6 +1,8 @@
package com.ruoyi.generator.util;
import com.ruoyi.common.constant.Constants;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.velocity.app.Velocity;
import java.util.Properties;
@ -10,6 +12,7 @@ import java.util.Properties;
*
* @author ruoyi
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class VelocityInitializer {
/**

View File

@ -11,15 +11,22 @@ import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.generator.domain.GenTable;
import com.ruoyi.generator.domain.GenTableColumn;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.velocity.VelocityContext;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* 模板处理工具类
*
* @author ruoyi
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class VelocityUtils {
/**
@ -127,7 +134,7 @@ public class VelocityUtils {
* @return 模板列表
*/
public static List<String> getTemplateList(String tplCategory) {
List<String> templates = new ArrayList<String>();
List<String> templates = new ArrayList<>();
templates.add("vm/java/domain.java.vm");
templates.add("vm/java/vo.java.vm");
templates.add("vm/java/bo.java.vm");
@ -226,10 +233,10 @@ public class VelocityUtils {
* @param genTable 业务表对象
* @return 返回需要导入的包列表
*/
public static HashSet<String> getImportList(GenTable genTable) {
public static Set<String> getImportList(GenTable genTable) {
List<GenTableColumn> columns = genTable.getColumns();
GenTable subGenTable = genTable.getSubTable();
HashSet<String> importList = new HashSet<String>();
Set<String> importList = new HashSet<>();
if (ObjectUtil.isNotNull(subGenTable)) {
importList.add("java.util.List");
}
@ -237,7 +244,7 @@ public class VelocityUtils {
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) {
importList.add("java.util.Date");
importList.add("com.fasterxml.jackson.annotation.JsonFormat");
} else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) {
} else if (!column.isSuperColumn() && GenConstants.TYPE_BIG_DECIMAL.equals(column.getJavaType())) {
importList.add("java.math.BigDecimal");
}
}
@ -252,7 +259,7 @@ public class VelocityUtils {
*/
public static String getDicts(GenTable genTable) {
List<GenTableColumn> columns = genTable.getColumns();
Set<String> dicts = new HashSet<String>();
Set<String> dicts = new HashSet<>();
addDicts(dicts, columns);
if (ObjectUtil.isNotNull(genTable.getSubTable())) {
List<GenTableColumn> subColumns = genTable.getSubTable().getColumns();

View File

@ -12,11 +12,15 @@ import java.io.InputStream;
*/
public interface IOssStrategy {
/**
* 创建存储桶
*/
void createBucket();
/**
* 获取服务商类型
* @return
*
* @return 对象存储服务商枚举
*/
OssEnumd getServiceType();
@ -25,6 +29,7 @@ public interface IOssStrategy {
*
* @param data 文件字节数组
* @param path 文件路径包含文件名
* @param contentType 文件类型
* @return 返回http地址
*/
UploadResult upload(byte[] data, String path, String contentType);
@ -41,6 +46,7 @@ public interface IOssStrategy {
*
* @param data 文件字节数组
* @param suffix 后缀
* @param contentType 文件类型
* @return 返回http地址
*/
UploadResult uploadSuffix(byte[] data, String suffix, String contentType);
@ -50,6 +56,7 @@ public interface IOssStrategy {
*
* @param inputStream 字节流
* @param path 文件路径包含文件名
* @param contentType 文件类型
* @return 返回http地址
*/
UploadResult upload(InputStream inputStream, String path, String contentType);
@ -59,6 +66,7 @@ public interface IOssStrategy {
*
* @param inputStream 字节流
* @param suffix 后缀
* @param contentType 文件类型
* @return 返回http地址
*/
UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType);

View File

@ -18,8 +18,8 @@ import java.io.InputStream;
*/
public abstract class AbstractOssStrategy implements IOssStrategy {
protected OssProperties properties;
public boolean isInit = false;
protected OssProperties properties;
public void init(OssProperties properties) {
this.properties = properties;
@ -60,5 +60,10 @@ public abstract class AbstractOssStrategy implements IOssStrategy {
@Override
public abstract UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType);
/**
* 获取域名访问链接
*
* @return 域名访问链接
*/
public abstract String getEndpointLink();
}