优化代码生成

This commit is contained in:
AlanScipio
2024-02-18 16:58:39 +08:00
parent 09b96b5cfa
commit 7a257eb264
39 changed files with 3614 additions and 436 deletions

View File

@@ -92,7 +92,7 @@ public class ExcelUtil<T> {
/**
* 当前行号
*/
private int rownum;
private int rowNum;
/**
* 标题
@@ -159,7 +159,7 @@ public class ExcelUtil<T> {
public void init(List<T> list, String sheetName, String title, Type type) {
if (list == null) {
list = new ArrayList<T>();
list = new ArrayList<>();
}
this.list = list;
this.sheetName = sheetName;
@@ -182,7 +182,7 @@ public class ExcelUtil<T> {
if (isSubList()) {
titleLastCol = titleLastCol + subFields.size() - 1;
}
Row titleRow = sheet.createRow(rownum == 0 ? rownum++ : 0);
Row titleRow = sheet.createRow(rowNum == 0 ? rowNum++ : 0);
titleRow.setHeightInPoints(30);
Cell titleCell = titleRow.createCell(0);
titleCell.setCellStyle(styles.get("title"));
@@ -198,7 +198,7 @@ public class ExcelUtil<T> {
if (isSubList()) {
subMergedFirstRowNum++;
subMergedLastRowNum++;
Row subRow = sheet.createRow(rownum);
Row subRow = sheet.createRow(rowNum);
int excelNum = 0;
for (Object[] objects : fields) {
Excel attr = (Excel) objects[1];
@@ -210,9 +210,9 @@ public class ExcelUtil<T> {
int headFirstRow = excelNum - 1;
int headLastRow = headFirstRow + subFields.size() - 1;
if (headLastRow > headFirstRow) {
sheet.addMergedRegion(new CellRangeAddress(rownum, rownum, headFirstRow, headLastRow));
sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, headFirstRow, headLastRow));
}
rownum++;
rowNum++;
}
}
@@ -257,7 +257,7 @@ public class ExcelUtil<T> {
public List<T> importExcel(String sheetName, InputStream is, int titleNum) throws Exception {
this.type = Type.IMPORT;
this.wb = WorkbookFactory.create(is);
List<T> list = new ArrayList<T>();
List<T> list = new ArrayList<>();
// 如果指定sheet名,则取指定sheet中的内容 否则默认指向第1个sheet
Sheet sheet = StringUtils.isNotEmpty(sheetName) ? wb.getSheet(sheetName) : wb.getSheetAt(0);
if (sheet == null) {
@@ -268,7 +268,7 @@ public class ExcelUtil<T> {
int rows = sheet.getLastRowNum();
if (rows > 0) {
// 定义一个map用于存放excel列的序号和field.
Map<String, Integer> cellMap = new HashMap<String, Integer>();
Map<String, Integer> cellMap = new HashMap<>();
// 获取表头
Row heard = sheet.getRow(titleNum);
for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++) {
@@ -282,7 +282,7 @@ public class ExcelUtil<T> {
}
// 有数据时才处理 得到类的所有field.
List<Object[]> fields = this.getFields();
Map<Integer, Object[]> fieldsMap = new HashMap<Integer, Object[]>();
Map<Integer, Object[]> fieldsMap = new HashMap<>();
for (Object[] objects : fields) {
Excel attr = (Excel) objects[1];
Integer column = cellMap.get(attr.name());
@@ -428,7 +428,7 @@ public class ExcelUtil<T> {
createSheet(sheetNo, index);
// 产生一行
Row row = sheet.createRow(rownum);
Row row = sheet.createRow(rowNum);
int column = 0;
// 写入各个字段的列头名称
for (Object[] os : fields) {
@@ -460,9 +460,9 @@ public class ExcelUtil<T> {
public void fillExcelData(int index, Row row) {
int startNo = index * sheetSize;
int endNo = Math.min(startNo + sheetSize, list.size());
int rowNo = (1 + rownum) - startNo;
int rowNo = (1 + rowNum) - startNo;
for (int i = startNo; i < endNo; i++) {
rowNo = isSubList() ? (i > 1 ? rowNo + 1 : rowNo + i) : i + 1 + rownum - startNo;
rowNo = isSubList() ? (i > 1 ? rowNo + 1 : rowNo + i) : i + 1 + rowNum - startNo;
row = sheet.createRow(rowNo);
// 得到导出对象.
T vo = (T) list.get(i);
@@ -515,7 +515,7 @@ public class ExcelUtil<T> {
*/
private Map<String, CellStyle> createStyles(Workbook wb) {
// 写入各条记录,每条记录对应excel表中的一行
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
Map<String, CellStyle> styles = new HashMap<>();
CellStyle style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
@@ -566,7 +566,7 @@ public class ExcelUtil<T> {
* @return 自定义样式列表
*/
private Map<String, CellStyle> annotationHeaderStyles(Workbook wb, Map<String, CellStyle> styles) {
Map<String, CellStyle> headerStyles = new HashMap<String, CellStyle>();
Map<String, CellStyle> headerStyles = new HashMap<>();
for (Object[] os : fields) {
Excel excel = (Excel) os[1];
String key = StringUtils.format("header_{}_{}", excel.headerColor(), excel.headerBackgroundColor());
@@ -596,7 +596,7 @@ public class ExcelUtil<T> {
* @return 自定义样式列表
*/
private Map<String, CellStyle> annotationDataStyles(Workbook wb) {
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
Map<String, CellStyle> styles = new HashMap<>();
for (Object[] os : fields) {
Excel excel = (Excel) os[1];
String key = StringUtils.format("data_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor());
@@ -639,7 +639,7 @@ public class ExcelUtil<T> {
// 填充默认样式,防止合并单元格样式失效
sheet.setDefaultColumnStyle(column, styles.get(StringUtils.format("data_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor())));
if (attr.needMerge()) {
sheet.addMergedRegion(new CellRangeAddress(rownum - 1, rownum, column, column));
sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum, column, column));
}
}
return cell;
@@ -1005,7 +1005,7 @@ public class ExcelUtil<T> {
* 获取字段注解信息
*/
public List<Object[]> getFields() {
List<Object[]> fields = new ArrayList<Object[]>();
List<Object[]> fields = new ArrayList<>();
List<Field> tempFields = new ArrayList<>();
tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields()));
tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
@@ -1184,7 +1184,7 @@ public class ExcelUtil<T> {
try {
value = subMethod.invoke(obj, new Object[]{});
} catch (Exception e) {
return new ArrayList<Object>();
return new ArrayList<>();
}
return (Collection<?>) value;
}

View File

@@ -1,21 +1,18 @@
package com.ruoyi.common.core.utils.reflect;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Date;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.utils.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.poi.ss.usermodel.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.utils.DateUtils;
import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* 反射工具类. 提供调用getter/setter方法, 访问私有变量, 调用私有方法, 获取泛型类型Class, 被AOP过的真实类等工具函数.
@@ -326,4 +323,52 @@ public class ReflectUtils {
}
return new RuntimeException(msg, e);
}
/**
* 深度寻找字段(不断往父类上去找)
*
* @param clazz 目标类
* @param fieldName 字段名
* @return 字段对象
* @throws NoSuchFieldException 最终还是找不到
*/
public static Field getFieldDeep(Class<?> clazz, String fieldName) throws NoSuchFieldException {
if (clazz == Object.class) {
throw new NoSuchFieldException(fieldName);
}
try {
return clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException e0) {
Class<?> superClass = clazz.getSuperclass();
return getFieldDeep(superClass, fieldName);
}
}
/**
* 获取所有字段(包括父类的)
*
* @param clazz 起始类(包含)
* @param endClass 终止类(不包含)
* @return 所有字段
*/
public static Field[] getFieldsDeep(Class<?> clazz, Class<?> endClass) {
List<Field> fieldList = new ArrayList<>();
while (clazz != endClass) {
Field[] fields = clazz.getDeclaredFields();
fieldList.addAll(Arrays.asList(fields));
clazz = clazz.getSuperclass();
}
Field[] f = new Field[fieldList.size()];
return fieldList.toArray(f);
}
/**
* 获取所有字段包括父类的一直查到Object类为止不包括Object的字段
*
* @param clazz 起始类
* @return 所有字段
*/
public static Field[] getFieldsDeep(Class<?> clazz) {
return getFieldsDeep(clazz, Object.class);
}
}

View File

@@ -0,0 +1,459 @@
package com.ruoyi.common.datasource.mybatis.gen;
import org.mybatis.generator.api.CommentGenerator;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.api.dom.kotlin.KotlinFile;
import org.mybatis.generator.api.dom.xml.TextElement;
import org.mybatis.generator.api.dom.xml.XmlElement;
import org.mybatis.generator.config.MergeConstants;
import org.mybatis.generator.config.PropertyRegistry;
import org.mybatis.generator.internal.util.StringUtility;
import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Properties;
import java.util.Set;
import static org.mybatis.generator.internal.util.StringUtility.isTrue;
/**
* 抄录自{@link org.mybatis.generator.internal.DefaultCommentGenerator},并作个性化修改
*
* @author Alan Scipio
* created on 2024/2/18
*/
public class MyCommentGenerator implements CommentGenerator {
private final Properties properties = new Properties();
private boolean suppressDate;
private boolean suppressAllComments;
/** If suppressAllComments is true, this option is ignored. */
private boolean addRemarkComments;
private SimpleDateFormat dateFormat;
private FullyQualifiedJavaType generatedImport =
new FullyQualifiedJavaType("jakarta.annotation.Generated");
public MyCommentGenerator() {
super();
suppressDate = false;
suppressAllComments = false;
addRemarkComments = false;
}
/**
* Adds a suitable comment to warn users that the element was generated, and
* when it was generated.
*
* @param xmlElement the xml element
*/
@Override
public void addComment(XmlElement xmlElement) {
if (suppressAllComments) {
return;
}
xmlElement.addElement(new TextElement("<!--"));
StringBuilder sb = new StringBuilder();
sb.append(" WARNING - ");
sb.append(MergeConstants.NEW_ELEMENT_TAG);
xmlElement.addElement(new TextElement(sb.toString()));
xmlElement.addElement(
new TextElement(" This element is automatically generated by MyBatis Generator,"
+ " do not modify."));
String s = getDateString();
if (s != null) {
sb.setLength(0);
sb.append(" This element was generated on ");
sb.append(s);
sb.append('.');
xmlElement.addElement(new TextElement(sb.toString()));
}
xmlElement.addElement(new TextElement("-->"));
}
@Override
public void addConfigurationProperties(Properties props) {
this.properties.putAll(props);
suppressDate = isTrue(properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_SUPPRESS_DATE));
suppressAllComments = isTrue(properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_SUPPRESS_ALL_COMMENTS));
addRemarkComments = isTrue(properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_ADD_REMARK_COMMENTS));
if (isTrue(properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_USE_LEGACY_GENERATED_ANNOTATION))) {
generatedImport = new FullyQualifiedJavaType("javax.annotation.Generated");
}
String dateFormatString = properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_DATE_FORMAT);
if (StringUtility.stringHasValue(dateFormatString)) {
dateFormat = new SimpleDateFormat(dateFormatString);
} else {
dateFormat = new SimpleDateFormat("yyyy-MM-dd");
}
}
/**
* This method adds the custom javadoc tag for. You may do nothing if you do not
* wish to include the Javadoc tag - however, if you do not include the Javadoc
* tag then the Java merge capability of the eclipse plugin will break.
*
* @param javaElement the java element
* @param markAsDoNotDelete the mark as do not delete
*/
protected void addJavadocTag(JavaElement javaElement, boolean markAsDoNotDelete) {
javaElement.addJavaDocLine(" *");
StringBuilder sb = new StringBuilder();
sb.append(" * ");
sb.append(MergeConstants.NEW_ELEMENT_TAG);
if (markAsDoNotDelete) {
sb.append(" do_not_delete_during_merge");
}
String s = getDateString();
if (s != null) {
sb.append(' ');
sb.append(s);
}
javaElement.addJavaDocLine(sb.toString());
}
/**
* Returns a formatted date string to include in the Javadoc tag and XML
* comments. You may return null if you do not want the date in these
* documentation elements.
*
* @return a string representing the current timestamp, or null
*/
protected String getDateString() {
if (suppressDate) {
return null;
} else if (dateFormat != null) {
return dateFormat.format(new Date());
} else {
return new Date().toString();
}
}
@Override
public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {
if (suppressAllComments) {
return;
}
StringBuilder sb = new StringBuilder();
innerClass.addJavaDocLine("/**");
sb.append(introspectedTable.getFullyQualifiedTable());
innerClass.addJavaDocLine(sb.toString());
addJavadocTag(innerClass, false);
innerClass.addJavaDocLine(" */");
}
@Override
public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable, boolean markAsDoNotDelete) {
if (suppressAllComments) {
return;
}
StringBuilder sb = new StringBuilder();
innerClass.addJavaDocLine("/**");
sb.append(introspectedTable.getFullyQualifiedTable());
innerClass.addJavaDocLine(sb.toString());
addJavadocTag(innerClass, markAsDoNotDelete);
innerClass.addJavaDocLine(" */");
}
@Override
public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
if (suppressAllComments || !addRemarkComments) {
return;
}
topLevelClass.addJavaDocLine("/**");
topLevelClass.addJavaDocLine(" * This class was generated by MyBatis Generator.");
topLevelClass.addJavaDocLine(" *");
topLevelClass.addJavaDocLine(" * <ul>");
//表名
String s = " * <li> Table: " + introspectedTable.getFullyQualifiedTable() + " </li>";
topLevelClass.addJavaDocLine(s);
//表注释
String remarks = introspectedTable.getRemarks() == null ? "" : introspectedTable.getRemarks();
StringBuilder remarksSb = new StringBuilder();
if (addRemarkComments && StringUtility.stringHasValue(remarks)) {
remarksSb.append(" * <li> Remarks: ");
remarksSb.append(remarks);
remarksSb.append(" </li>");
topLevelClass.addJavaDocLine(remarksSb.toString());
}
topLevelClass.addJavaDocLine(" * </ul>");
topLevelClass.addJavaDocLine(" *");
//作者
topLevelClass.addJavaDocLine(" * @author ryas");
if (!suppressDate && !suppressAllComments) {
topLevelClass.addJavaDocLine(" * created on " + getDateString());
}
topLevelClass.addJavaDocLine(" */");
}
@Override
public void addEnumComment(InnerEnum innerEnum, IntrospectedTable introspectedTable) {
if (suppressAllComments) {
return;
}
StringBuilder sb = new StringBuilder();
innerEnum.addJavaDocLine("/**");
sb.append(introspectedTable.getFullyQualifiedTable());
innerEnum.addJavaDocLine(sb.toString());
addJavadocTag(innerEnum, false);
innerEnum.addJavaDocLine(" */");
}
@Override
public void addFieldComment(Field field, IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
if (suppressAllComments) {
return;
}
field.addJavaDocLine("/**");
String remarks = introspectedTable.getRemarks() == null ? "" : introspectedTable.getRemarks();
if (addRemarkComments && StringUtility.stringHasValue(remarks)) {
String[] remarkLines = remarks.split(System.lineSeparator());
for (String remarkLine : remarkLines) {
field.addJavaDocLine(" * " + remarkLine);
}
}
String s = ""
+ introspectedTable.getFullyQualifiedTable()
+ '.'
+ introspectedColumn.getActualColumnName();
field.addJavaDocLine(s);
addJavadocTag(field, false);
field.addJavaDocLine(" */");
}
@Override
public void addFieldComment(Field field, IntrospectedTable introspectedTable) {
if (suppressAllComments) {
return;
}
StringBuilder sb = new StringBuilder();
field.addJavaDocLine("/**");
sb.append(introspectedTable.getFullyQualifiedTable());
field.addJavaDocLine(sb.toString());
addJavadocTag(field, false);
field.addJavaDocLine(" */");
}
@Override
public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {
if (suppressAllComments) {
return;
}
StringBuilder sb = new StringBuilder();
method.addJavaDocLine("/**");
sb.append(introspectedTable.getFullyQualifiedTable());
method.addJavaDocLine(sb.toString());
addJavadocTag(method, false);
method.addJavaDocLine(" */");
}
@Override
public void addGetterComment(Method method, IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
if (suppressAllComments) {
return;
}
StringBuilder sb = new StringBuilder();
method.addJavaDocLine("/**");
sb.append(introspectedTable.getFullyQualifiedTable());
sb.append('.');
sb.append(introspectedColumn.getActualColumnName());
method.addJavaDocLine(sb.toString());
sb.setLength(0);
sb.append(" * @return the value of ");
sb.append(introspectedTable.getFullyQualifiedTable());
sb.append('.');
sb.append(introspectedColumn.getActualColumnName());
method.addJavaDocLine(sb.toString());
addJavadocTag(method, false);
method.addJavaDocLine(" */");
}
@Override
public void addSetterComment(Method method, IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
if (suppressAllComments) {
return;
}
StringBuilder sb = new StringBuilder();
method.addJavaDocLine("/**");
sb.append(introspectedTable.getFullyQualifiedTable());
sb.append('.');
sb.append(introspectedColumn.getActualColumnName());
method.addJavaDocLine(sb.toString());
method.addJavaDocLine(" *");
Parameter parm = method.getParameters().getFirst();
sb.setLength(0);
sb.append(" * @param ");
sb.append(parm.getName());
sb.append(" the value for ");
sb.append(introspectedTable.getFullyQualifiedTable());
sb.append('.');
sb.append(introspectedColumn.getActualColumnName());
method.addJavaDocLine(sb.toString());
addJavadocTag(method, false);
method.addJavaDocLine(" */");
}
@Override
public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable,
Set<FullyQualifiedJavaType> imports) {
// imports.add(generatedImport);
// String comment = "Source Table: " + introspectedTable.getFullyQualifiedTable().toString();
// method.addAnnotation(getGeneratedAnnotation(comment));
}
@Override
public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn, Set<FullyQualifiedJavaType> imports) {
// imports.add(generatedImport);
// String comment = "Source field: "
// + introspectedTable.getFullyQualifiedTable().toString() + "."
// + introspectedColumn.getActualColumnName();
// method.addAnnotation(getGeneratedAnnotation(comment));
}
@Override
public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable,
Set<FullyQualifiedJavaType> imports) {
// imports.add(generatedImport);
// String comment = "Source Table: " + introspectedTable.getFullyQualifiedTable().toString();
// field.addAnnotation(getGeneratedAnnotation(comment));
}
@Override
public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn, Set<FullyQualifiedJavaType> imports) {
// imports.add(generatedImport);
// String comment = "Source field: "
// + introspectedTable.getFullyQualifiedTable().toString() + "."
// + introspectedColumn.getActualColumnName();
// field.addAnnotation(getGeneratedAnnotation(comment));
if (!suppressAllComments && addRemarkComments) {
String remarks = introspectedColumn.getRemarks();
if (addRemarkComments && StringUtility.stringHasValue(remarks)) {
field.addJavaDocLine("/**");
String[] remarkLines = remarks.split(System.lineSeparator());
for (String remarkLine : remarkLines) {
field.addJavaDocLine(" * " + remarkLine);
}
field.addJavaDocLine(" */");
}
}
}
@Override
public void addClassAnnotation(InnerClass innerClass, IntrospectedTable introspectedTable,
Set<FullyQualifiedJavaType> imports) {
// imports.add(generatedImport);
// String comment = "Source Table: " + introspectedTable.getFullyQualifiedTable().toString();
// innerClass.addAnnotation(getGeneratedAnnotation(comment));
}
private String getGeneratedAnnotation(String comment) {
StringBuilder buffer = new StringBuilder();
buffer.append("@Generated(");
if (suppressAllComments) {
buffer.append('\"');
} else {
buffer.append("value=\"");
}
buffer.append(MyBatisGenerator.class.getName());
buffer.append('\"');
if (!suppressDate && !suppressAllComments) {
buffer.append(", date=\"");
buffer.append(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()));
buffer.append('\"');
}
if (!suppressAllComments) {
buffer.append(", comments=\"");
buffer.append(comment);
buffer.append('\"');
}
buffer.append(')');
return buffer.toString();
}
@Override
public void addFileComment(KotlinFile kotlinFile) {
if (suppressAllComments) {
return;
}
kotlinFile.addFileCommentLine("/*");
kotlinFile.addFileCommentLine(" * Auto-generated file. Created by MyBatis Generator");
if (!suppressDate) {
kotlinFile.addFileCommentLine(" * Generation date: "
+ DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()));
}
kotlinFile.addFileCommentLine(" */");
}
}

View File

@@ -5,6 +5,7 @@ import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.Interface;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.TopLevelClass;
import org.mybatis.generator.internal.util.StringUtility;
import java.util.List;
@@ -15,6 +16,8 @@ import java.util.List;
*/
public class RyasMyBatisDynamicPlugin extends PluginAdapter {
private String modelClassName;
// 校验插件配置的正确性
@Override
public boolean validate(List<String> warnings) {
@@ -26,6 +29,13 @@ public class RyasMyBatisDynamicPlugin extends PluginAdapter {
return true;
}
@Override
public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
// 获取模型类的完整名称
modelClassName = topLevelClass.getType().getShortName();
return true;
}
// int insert(UnitInfo row)
@Override
public boolean clientInsertMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
@@ -82,7 +92,7 @@ public class RyasMyBatisDynamicPlugin extends PluginAdapter {
//从头插入,所以需要倒着
bodyLines.addFirst("}");
bodyLines.addFirst("row.setCommonForInsert(SecurityUtilsExt.getUserIdStr());");
bodyLines.addFirst("for (UnitInfo row : records) {");
bodyLines.addFirst("for (" + modelClassName + " row : records) {");
}
private void setForUpdate(Method method, Interface interfaze) {

View File

@@ -9,12 +9,11 @@ import com.ruoyi.system.api.domain.SysOperLog;
/**
* 异步调用日志服务
*
*
* @author ruoyi
*/
@Service
public class AsyncLogService
{
public class AsyncLogService {
@Autowired
private RemoteLogService remoteLogService;
@@ -22,8 +21,7 @@ public class AsyncLogService
* 保存系统日志记录
*/
@Async
public void saveSysLog(SysOperLog sysOperLog) throws Exception
{
public void saveSysLog(SysOperLog sysOperLog) throws Exception {
remoteLogService.saveLog(sysOperLog, SecurityConstants.INNER);
}
}