ruoyi-tpl 文件模板打印后台

This commit is contained in:
lizhengwei 2026-01-06 11:38:11 +08:00
parent 61560691d9
commit c9423283da
2 changed files with 12 additions and 19 deletions

View File

@ -102,7 +102,7 @@ public class NiceDoc implements Closeable {
*
* @param entity
*/
public void pushLabels(Object entity) {
public void pushLabels(Object entity) throws IllegalAccessException {
pushLabels(NiceUtils.entityToMap(entity));
}

View File

@ -3,6 +3,7 @@ package com.lizhw.tpl.module.docx.ttt;
import org.apache.poi.util.StringUtil;
import java.lang.reflect.Field;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
@ -44,18 +45,14 @@ public class NiceUtils {
* @param entity
* @return
*/
public static Map<String, Object> entityToMap(Object entity) {
public static Map<String, Object> entityToMap(Object entity) throws IllegalAccessException {
Map<String, Object> map = new HashMap<>();
for (Field field : entity.getClass().getDeclaredFields()) {
try {
boolean flag = field.isAccessible();
field.setAccessible(true);
Object o = field.get(entity);
map.put(field.getName(), o);
field.setAccessible(flag);
} catch (Exception e) {
e.printStackTrace();
}
boolean flag = field.isAccessible();
field.setAccessible(true);
Object o = field.get(entity);
map.put(field.getName(), o);
field.setAccessible(flag);
}
return map;
}
@ -66,7 +63,7 @@ public class NiceUtils {
* @param entityList
* @return
*/
public static List<Map<String, Object>> listEntityToMap(List<Object> entityList) {
public static List<Map<String, Object>> listEntityToMap(List<Object> entityList) throws IllegalAccessException {
List<Map<String, Object>> list = new ArrayList<>();
for (Object entity : entityList) {
list.add(entityToMap(entity));
@ -121,18 +118,14 @@ public class NiceUtils {
* @return 解析成功返回Date对象解析失败抛出异常
* @throws Exception 如果无法解析日期字符串
*/
public static Date parseDate(String dateString, String[] formats) throws Exception {
public static Date parseDate(String dateString, String[] formats) throws ParseException {
for (String format : formats) {
SimpleDateFormat formatter = new SimpleDateFormat(format);
formatter.setTimeZone(TimeZone.getTimeZone("UTC")); // 设置时区根据需要调整
try {
return formatter.parse(dateString);
} catch (Exception e) {
// 当前格式不匹配尝试下一个格式
}
return formatter.parse(dateString);
}
// 所有格式都不匹配抛出异常
throw new Exception("无法解析日期: " + dateString);
throw new RuntimeException("无法解析日期: " + dateString);
}
/**