fix():格式规范修改
parent
fdd5cd030f
commit
3f32325c9b
|
@ -152,7 +152,12 @@ public @interface Excel {
|
|||
* 字段类型
|
||||
*/
|
||||
enum Type {
|
||||
ALL(0), EXPORT(1), IMPORT(2);
|
||||
// 所有
|
||||
ALL(0),
|
||||
// 仅导出
|
||||
EXPORT(1),
|
||||
// 仅导入
|
||||
IMPORT(2);
|
||||
private final int value;
|
||||
|
||||
Type (int value) {
|
||||
|
@ -168,7 +173,18 @@ public @interface Excel {
|
|||
* 列类型
|
||||
*/
|
||||
enum ColumnType {
|
||||
NUMERIC(0), STRING(1), IMAGE(2);
|
||||
/**
|
||||
* 字典
|
||||
*/
|
||||
NUMERIC(0),
|
||||
/**
|
||||
* 字符串
|
||||
*/
|
||||
STRING(1),
|
||||
/**
|
||||
* 图片
|
||||
*/
|
||||
IMAGE(2);
|
||||
private final int value;
|
||||
|
||||
ColumnType (int value) {
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.muyu.common.core.constant;
|
||||
|
||||
/**
|
||||
* @author dongzeliang
|
||||
* @version 1.0
|
||||
* @description: 文件常量
|
||||
* @date 2025/2/26 22:56
|
||||
*/
|
||||
public class FileConstants {
|
||||
|
||||
|
||||
// GIF
|
||||
public static final int PHOTO_BYTE_GIF_ZERO = 71;
|
||||
// GIF
|
||||
public static final int PHOTO_BYTE_GIF_ONE = 73;
|
||||
// GIF
|
||||
public static final int PHOTO_BYTE_GIF_TWO = 70;
|
||||
// GIF
|
||||
public static final int PHOTO_BYTE_GIF_THREE = 56;
|
||||
// GIF
|
||||
public static final int PHOTO_BYTE_GIF_FOUR = 55;
|
||||
// GIF
|
||||
public static final int PHOTO_BYTE_GIF_FOUR_OR = 57;
|
||||
// GIF
|
||||
public static final int PHOTO_BYTE_GIF_FIVE = 97;
|
||||
// JPG
|
||||
public static final int PHOTO_BYTE_JPG_SIX = 74;
|
||||
// JPG
|
||||
public static final int PHOTO_BYTE_JPG_SEVEN = 70;
|
||||
// JPG
|
||||
public static final int PHOTO_BYTE_JPG_EIGHT = 73;
|
||||
// JPG
|
||||
public static final int PHOTO_BYTE_JPG_NINE = 70;
|
||||
// BMP
|
||||
public static final int PHOTO_BYTE_BMP_ZERO = 66;
|
||||
// BMP
|
||||
public static final int PHOTO_BYTE_BMP_ONE = 77;
|
||||
// PNG
|
||||
public static final int PHOTO_BYTE_PNG_ONE = 80;
|
||||
// PNG
|
||||
public static final int PHOTO_BYTE_PNG_TWO = 78;
|
||||
// PNG
|
||||
public static final int PHOTO_BYTE_PNG_THREE = 71;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.common.core.constant;
|
||||
|
||||
/**
|
||||
* @author dongzeliang
|
||||
* @version 1.0
|
||||
* @description: HTTP常量
|
||||
* @date 2025/2/26 22:37
|
||||
*/
|
||||
public class HttpConstants {
|
||||
// json请求
|
||||
public static final String APPLICATION_JSON = "application/json";
|
||||
|
||||
// ACCEPT
|
||||
public static final String ACCEPT = "accept";
|
||||
|
||||
// 请求
|
||||
public static final String X_REQUESTED_WITH = "X-Requested-With";
|
||||
|
||||
// XMLHttpRequest
|
||||
public static final String XML_HTTP_REQUEST = "XMLHttpRequest";
|
||||
|
||||
// 内容忽略
|
||||
public static final String[] XML_HTTP_REQUEST_IGNORE = new String[]{".json", ".xml"};
|
||||
// ajax
|
||||
public static final String AJAX = "__ajax";
|
||||
// ajax内容忽略
|
||||
public static final String[] AJAX_IGNORE = new String[]{"json", "xml"};
|
||||
}
|
|
@ -12,7 +12,13 @@ import lombok.Getter;
|
|||
@Getter
|
||||
public enum SysWhetherEnum {
|
||||
|
||||
/**
|
||||
* 系统是
|
||||
*/
|
||||
YES("Y", "是"),
|
||||
/**
|
||||
* 系统否
|
||||
*/
|
||||
NO("N", "否");
|
||||
private final String code;
|
||||
private final String info;
|
||||
|
|
|
@ -1,12 +1,26 @@
|
|||
package com.muyu.common.core.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 用户状态
|
||||
*
|
||||
* @author muyu
|
||||
*/
|
||||
@Getter
|
||||
public enum UserStatusEnum {
|
||||
OK("0", "正常"), DISABLE("1", "停用"), DELETED("2", "删除");
|
||||
/**
|
||||
* 正常
|
||||
*/
|
||||
OK("0", "正常"),
|
||||
/**
|
||||
* 停用
|
||||
*/
|
||||
DISABLE("1", "停用"),
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
DELETED("2", "删除");
|
||||
|
||||
private final String code;
|
||||
private final String info;
|
||||
|
@ -16,11 +30,4 @@ public enum UserStatusEnum {
|
|||
this.info = info;
|
||||
}
|
||||
|
||||
public String getCode () {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getInfo () {
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.muyu.common.core.utils;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.muyu.common.core.constant.Constants;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.text.Convert;
|
||||
import jakarta.servlet.ServletRequest;
|
||||
|
@ -21,12 +20,14 @@ import reactor.core.publisher.Mono;
|
|||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
import static com.muyu.common.core.constant.HttpConstants.*;
|
||||
import static org.springframework.http.HttpHeaders.ACCEPT;
|
||||
|
||||
/**
|
||||
* 客户端工具类
|
||||
*
|
||||
|
@ -37,42 +38,42 @@ public class ServletUtils {
|
|||
* 获取String参数
|
||||
*/
|
||||
public static String getParameter (String name) {
|
||||
return getRequest().getParameter(name);
|
||||
return Objects.requireNonNull(getRequest()).getParameter(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取String参数
|
||||
*/
|
||||
public static String getParameter (String name, String defaultValue) {
|
||||
return Convert.toStr(getRequest().getParameter(name), defaultValue);
|
||||
return Convert.toStr(Objects.requireNonNull(getRequest()).getParameter(name), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Integer参数
|
||||
*/
|
||||
public static Integer getParameterToInt (String name) {
|
||||
return Convert.toInt(getRequest().getParameter(name));
|
||||
return Convert.toInt(Objects.requireNonNull(getRequest()).getParameter(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Integer参数
|
||||
*/
|
||||
public static Integer getParameterToInt (String name, Integer defaultValue) {
|
||||
return Convert.toInt(getRequest().getParameter(name), defaultValue);
|
||||
return Convert.toInt(Objects.requireNonNull(getRequest()).getParameter(name), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Boolean参数
|
||||
*/
|
||||
public static Boolean getParameterToBool (String name) {
|
||||
return Convert.toBool(getRequest().getParameter(name));
|
||||
return Convert.toBool(Objects.requireNonNull(getRequest()).getParameter(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Boolean参数
|
||||
*/
|
||||
public static Boolean getParameterToBool (String name, Boolean defaultValue) {
|
||||
return Convert.toBool(getRequest().getParameter(name), defaultValue);
|
||||
return Convert.toBool(Objects.requireNonNull(getRequest()).getParameter(name), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,8 +171,8 @@ public class ServletUtils {
|
|||
public static void renderString (HttpServletResponse response, String string) {
|
||||
try {
|
||||
response.setStatus(200);
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setContentType(APPLICATION_JSON);
|
||||
response.setCharacterEncoding(StandardCharsets.UTF_8);
|
||||
response.getWriter().print(string);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -181,26 +182,26 @@ public class ServletUtils {
|
|||
/**
|
||||
* 是否是Ajax异步请求
|
||||
*
|
||||
* @param request
|
||||
* @param request 请求作用域
|
||||
*/
|
||||
public static boolean isAjaxRequest (HttpServletRequest request) {
|
||||
String accept = request.getHeader("accept");
|
||||
if (accept != null && accept.contains("application/json")) {
|
||||
String accept = request.getHeader(ACCEPT);
|
||||
if (accept != null && accept.contains(APPLICATION_JSON)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String xRequestedWith = request.getHeader("X-Requested-With");
|
||||
if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest")) {
|
||||
String xRequestedWith = request.getHeader(X_REQUESTED_WITH);
|
||||
if (xRequestedWith != null && xRequestedWith.contains(XML_HTTP_REQUEST)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String uri = request.getRequestURI();
|
||||
if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml")) {
|
||||
if (StringUtils.inStringIgnoreCase(uri, XML_HTTP_REQUEST_IGNORE)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String ajax = request.getParameter("__ajax");
|
||||
return StringUtils.inStringIgnoreCase(ajax, "json", "xml");
|
||||
String ajax = request.getParameter(AJAX);
|
||||
return StringUtils.inStringIgnoreCase(ajax, AJAX_IGNORE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -211,11 +212,7 @@ public class ServletUtils {
|
|||
* @return 编码后的内容
|
||||
*/
|
||||
public static String urlEncode (String str) {
|
||||
try {
|
||||
return URLEncoder.encode(str, Constants.UTF8);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
return URLEncoder.encode(str, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -311,9 +311,9 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// 前置字符是否大写
|
||||
boolean preCharIsUpperCase = true;
|
||||
boolean preCharIsUpperCase;
|
||||
// 当前字符是否大写
|
||||
boolean curreCharIsUpperCase = true;
|
||||
boolean curreCharIsUpperCase;
|
||||
// 下一字符是否大写
|
||||
boolean nexteCharIsUpperCase = true;
|
||||
for (int i = 0 ; i < str.length() ; i++) {
|
||||
|
@ -345,13 +345,13 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||
* 是否包含字符串
|
||||
*
|
||||
* @param str 验证字符串
|
||||
* @param strs 字符串组
|
||||
* @param strArr 字符串组
|
||||
*
|
||||
* @return 包含返回true
|
||||
*/
|
||||
public static boolean inStringIgnoreCase (String str, String... strs) {
|
||||
if (str != null && strs != null) {
|
||||
for (String s : strs) {
|
||||
public static boolean inStringIgnoreCase (String str, String... strArr) {
|
||||
if (str != null && strArr != null) {
|
||||
for (String s : strArr) {
|
||||
if (str.equalsIgnoreCase(trim(s))) {
|
||||
return true;
|
||||
}
|
||||
|
@ -448,8 +448,6 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||
*
|
||||
* @param pattern 匹配规则
|
||||
* @param url 需要匹配的url
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isMatch (String pattern, String url) {
|
||||
AntPathMatcher matcher = new AntPathMatcher();
|
||||
|
@ -469,7 +467,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||
*
|
||||
* @return 返回数字的字符串格式,该字符串为指定长度。
|
||||
*/
|
||||
public static final String padl (final Number num, final int size) {
|
||||
public static String padl(final Number num, final int size) {
|
||||
return padl(num.toString(), size, '0');
|
||||
}
|
||||
|
||||
|
@ -482,7 +480,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||
*
|
||||
* @return 返回指定长度的字符串,由原字符串左补齐或截取得到。
|
||||
*/
|
||||
public static final String padl (final String s, final int size, final char c) {
|
||||
public static String padl(final String s, final int size, final char c) {
|
||||
final StringBuilder sb = new StringBuilder(size);
|
||||
if (s != null) {
|
||||
final int len = s.length();
|
||||
|
|
|
@ -7,6 +7,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.muyu.common.core.constant.FileConstants.*;
|
||||
|
||||
/**
|
||||
* 文件类型工具类
|
||||
*
|
||||
|
@ -53,7 +55,7 @@ public class FileTypeUtils {
|
|||
*
|
||||
* @return 后缀名
|
||||
*/
|
||||
public static final String getExtension (MultipartFile file) {
|
||||
public static String getExtension(MultipartFile file) {
|
||||
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
||||
if (StringUtils.isEmpty(extension)) {
|
||||
extension = MimeTypeUtils.getExtension(Objects.requireNonNull(file.getContentType()));
|
||||
|
@ -70,14 +72,14 @@ public class FileTypeUtils {
|
|||
*/
|
||||
public static String getFileExtendName (byte[] photoByte) {
|
||||
String strFileExtendName = "JPG";
|
||||
if ((photoByte[0] == 71) && (photoByte[1] == 73) && (photoByte[2] == 70) && (photoByte[3] == 56)
|
||||
&& ((photoByte[4] == 55) || (photoByte[4] == 57)) && (photoByte[5] == 97)) {
|
||||
if ((photoByte[0] == PHOTO_BYTE_GIF_ZERO) && (photoByte[1] == PHOTO_BYTE_GIF_ONE) && (photoByte[2] == PHOTO_BYTE_GIF_TWO) && (photoByte[3] == PHOTO_BYTE_GIF_THREE)
|
||||
&& ((photoByte[4] == PHOTO_BYTE_GIF_FOUR) || (photoByte[4] == PHOTO_BYTE_GIF_FOUR_OR)) && (photoByte[5] == PHOTO_BYTE_GIF_FIVE)) {
|
||||
strFileExtendName = "GIF";
|
||||
} else if ((photoByte[6] == 74) && (photoByte[7] == 70) && (photoByte[8] == 73) && (photoByte[9] == 70)) {
|
||||
} else if ((photoByte[6] == PHOTO_BYTE_JPG_SIX) && (photoByte[7] == PHOTO_BYTE_JPG_SEVEN) && (photoByte[8] == PHOTO_BYTE_JPG_EIGHT) && (photoByte[9] == PHOTO_BYTE_JPG_NINE)) {
|
||||
strFileExtendName = "JPG";
|
||||
} else if ((photoByte[0] == 66) && (photoByte[1] == 77)) {
|
||||
} else if ((photoByte[0] == PHOTO_BYTE_BMP_ZERO) && (photoByte[1] == PHOTO_BYTE_BMP_ONE)) {
|
||||
strFileExtendName = "BMP";
|
||||
} else if ((photoByte[1] == 80) && (photoByte[2] == 78) && (photoByte[3] == 71)) {
|
||||
} else if ((photoByte[1] == PHOTO_BYTE_PNG_ONE) && (photoByte[2] == PHOTO_BYTE_PNG_TWO) && (photoByte[3] == PHOTO_BYTE_PNG_THREE)) {
|
||||
strFileExtendName = "PNG";
|
||||
}
|
||||
return strFileExtendName;
|
||||
|
|
|
@ -154,7 +154,7 @@ public class ExcelUtil<T> {
|
|||
if (StringUtils.containsAny(propertyValue, separator)) {
|
||||
for (String value : propertyValue.split(separator)) {
|
||||
if (itemArray[0].equals(value)) {
|
||||
propertyString.append(itemArray[1] + separator);
|
||||
propertyString.append(itemArray[1]).append(separator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ public class ExcelUtil<T> {
|
|||
if (StringUtils.containsAny(propertyValue, separator)) {
|
||||
for (String value : propertyValue.split(separator)) {
|
||||
if (itemArray[1].equals(value)) {
|
||||
propertyString.append(itemArray[0] + separator);
|
||||
propertyString.append(itemArray[0]).append(separator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -201,8 +201,6 @@ public class ExcelUtil<T> {
|
|||
* 隐藏Excel中列属性
|
||||
*
|
||||
* @param fields 列属性名 示例[单个"name"/多个"id","name"]
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void hideColumn (String... fields) {
|
||||
this.excludeFields = fields;
|
||||
|
@ -275,7 +273,7 @@ public class ExcelUtil<T> {
|
|||
* @return 转换后集合
|
||||
*/
|
||||
public List<T> importExcel (InputStream is) {
|
||||
List<T> list = null;
|
||||
List<T> list;
|
||||
try {
|
||||
list = importExcel(is, 0);
|
||||
} catch (Exception e) {
|
||||
|
@ -393,18 +391,16 @@ public class ExcelUtil<T> {
|
|||
} else if (Boolean.TYPE == fieldType || Boolean.class == fieldType) {
|
||||
val = Convert.toBool(val, false);
|
||||
}
|
||||
if (StringUtils.isNotNull(fieldType)) {
|
||||
String propertyName = field.getName();
|
||||
if (StringUtils.isNotEmpty(attr.targetAttr())) {
|
||||
propertyName = field.getName() + "." + attr.targetAttr();
|
||||
}
|
||||
if (StringUtils.isNotEmpty(attr.readConverterExp())) {
|
||||
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
|
||||
} else if (!attr.handler().equals(ExcelHandlerAdapter.class)) {
|
||||
val = dataFormatHandlerAdapter(val, attr, null);
|
||||
}
|
||||
ReflectUtils.invokeSetter(entity, propertyName, val);
|
||||
String propertyName = field.getName();
|
||||
if (StringUtils.isNotEmpty(attr.targetAttr())) {
|
||||
propertyName = field.getName() + "." + attr.targetAttr();
|
||||
}
|
||||
if (StringUtils.isNotEmpty(attr.readConverterExp())) {
|
||||
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
|
||||
} else if (!attr.handler().equals(ExcelHandlerAdapter.class)) {
|
||||
val = dataFormatHandlerAdapter(val, attr, null);
|
||||
}
|
||||
ReflectUtils.invokeSetter(entity, propertyName, val);
|
||||
}
|
||||
list.add(entity);
|
||||
}
|
||||
|
@ -418,8 +414,6 @@ public class ExcelUtil<T> {
|
|||
* @param response 返回数据
|
||||
* @param list 导出数据集合
|
||||
* @param sheetName 工作表的名称
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
public void exportExcel (HttpServletResponse response, List<T> list, String sheetName) {
|
||||
exportExcel(response, list, sheetName, StringUtils.EMPTY);
|
||||
|
@ -433,7 +427,6 @@ public class ExcelUtil<T> {
|
|||
* @param sheetName 工作表的名称
|
||||
* @param title 标题
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
public void exportExcel (HttpServletResponse response, List<T> list, String sheetName, String title) {
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
|
@ -446,8 +439,6 @@ public class ExcelUtil<T> {
|
|||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
* @param sheetName 工作表的名称
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
public void importTemplateExcel (HttpServletResponse response, String sheetName) {
|
||||
importTemplateExcel(response, sheetName, StringUtils.EMPTY);
|
||||
|
@ -458,8 +449,6 @@ public class ExcelUtil<T> {
|
|||
*
|
||||
* @param sheetName 工作表的名称
|
||||
* @param title 标题
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
public void importTemplateExcel (HttpServletResponse response, String sheetName, String title) {
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
|
@ -470,8 +459,6 @@ public class ExcelUtil<T> {
|
|||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
public void exportExcel (HttpServletResponse response) {
|
||||
try {
|
||||
|
@ -510,7 +497,7 @@ public class ExcelUtil<T> {
|
|||
}
|
||||
}
|
||||
if (Type.EXPORT.equals(type)) {
|
||||
fillExcelData(index, row);
|
||||
fillExcelData(index);
|
||||
addStatisticsRow();
|
||||
}
|
||||
}
|
||||
|
@ -520,18 +507,17 @@ public class ExcelUtil<T> {
|
|||
* 填充excel数据
|
||||
*
|
||||
* @param index 序号
|
||||
* @param row 单元格行
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void fillExcelData (int index, Row row) {
|
||||
public void fillExcelData (int index) {
|
||||
int startNo = index * SHEET_SIZE;
|
||||
int endNo = Math.min(startNo + SHEET_SIZE, list.size());
|
||||
int rowNo = (1 + rownum) - startNo;
|
||||
for (int i = startNo ; i < endNo ; i++) {
|
||||
rowNo = isSubList() ? (i > 1 ? rowNo + 1 : rowNo + i) : i + 1 + rownum - startNo;
|
||||
row = sheet.createRow(rowNo);
|
||||
Row row = sheet.createRow(rowNo);
|
||||
// 得到导出对象.
|
||||
T vo = (T) list.get(i);
|
||||
T vo = list.get(i);
|
||||
Collection<?> subList = null;
|
||||
if (isSubList()) {
|
||||
if (isSubListValue(vo)) {
|
||||
|
@ -702,7 +688,7 @@ public class ExcelUtil<T> {
|
|||
Cell cell = row.createCell(column);
|
||||
// 写入列信息
|
||||
cell.setCellValue(attr.name());
|
||||
setDataValidation(attr, row, column);
|
||||
setDataValidation(attr, column);
|
||||
cell.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor())));
|
||||
if (isSubList()) {
|
||||
// 填充默认样式,防止合并单元格样式失效
|
||||
|
@ -762,7 +748,7 @@ public class ExcelUtil<T> {
|
|||
/**
|
||||
* 创建表格样式
|
||||
*/
|
||||
public void setDataValidation (Excel attr, Row row, int column) {
|
||||
public void setDataValidation (Excel attr, int column) {
|
||||
if (attr.name().contains("注:")) {
|
||||
sheet.setColumnWidth(column, 6000);
|
||||
} else {
|
||||
|
@ -772,7 +758,7 @@ public class ExcelUtil<T> {
|
|||
if (StringUtils.isNotEmpty(attr.prompt()) || attr.combo().length > 0) {
|
||||
if (attr.combo().length > 15 || StringUtils.join(attr.combo()).length() > 255) {
|
||||
// 如果下拉数大于15或字符串长度大于255,则使用一个新sheet存储,避免生成的模板下拉值获取不到
|
||||
setXSSFValidationWithHidden(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
|
||||
setXssfValidationWithHidden(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
|
||||
} else {
|
||||
// 提示信息或只能选择不能输入的列内容.
|
||||
setPromptOrValidation(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
|
||||
|
@ -784,7 +770,7 @@ public class ExcelUtil<T> {
|
|||
* 添加单元格
|
||||
*/
|
||||
public void addCell (Excel attr, Row row, T vo, Field field, int column) {
|
||||
Cell cell = null;
|
||||
Cell cell;
|
||||
try {
|
||||
// 设置行高
|
||||
row.setHeight(maxHeight);
|
||||
|
@ -858,24 +844,24 @@ public class ExcelUtil<T> {
|
|||
* 设置某些列的值只能输入预制的数据,显示下拉框(兼容超出一定数量的下拉框).
|
||||
*
|
||||
* @param sheet 要设置的sheet.
|
||||
* @param textlist 下拉框显示的内容
|
||||
* @param textList 下拉框显示的内容
|
||||
* @param promptContent 提示内容
|
||||
* @param firstRow 开始行
|
||||
* @param endRow 结束行
|
||||
* @param firstCol 开始列
|
||||
* @param endCol 结束列
|
||||
*/
|
||||
public void setXSSFValidationWithHidden (Sheet sheet, String[] textlist, String promptContent, int firstRow, int endRow, int firstCol, int endCol) {
|
||||
public void setXssfValidationWithHidden(Sheet sheet, String[] textList, String promptContent, int firstRow, int endRow, int firstCol, int endCol) {
|
||||
String hideSheetName = "combo_" + firstCol + "_" + endCol;
|
||||
// 用于存储 下拉菜单数据
|
||||
Sheet hideSheet = wb.createSheet(hideSheetName);
|
||||
for (int i = 0 ; i < textlist.length ; i++) {
|
||||
hideSheet.createRow(i).createCell(0).setCellValue(textlist[i]);
|
||||
for (int i = 0 ; i < textList.length ; i++) {
|
||||
hideSheet.createRow(i).createCell(0).setCellValue(textList[i]);
|
||||
}
|
||||
// 创建名称,可被其他单元格引用
|
||||
Name name = wb.createName();
|
||||
name.setNameName(hideSheetName + "_data");
|
||||
name.setRefersToFormula(hideSheetName + "!$A$1:$A$" + textlist.length);
|
||||
name.setRefersToFormula(hideSheetName + "!$A$1:$A$" + textList.length);
|
||||
DataValidationHelper helper = sheet.getDataValidationHelper();
|
||||
// 加载下拉列表内容
|
||||
DataValidationConstraint constraint = helper.createFormulaListConstraint(hideSheetName + "_data");
|
||||
|
@ -906,13 +892,11 @@ public class ExcelUtil<T> {
|
|||
*
|
||||
* @param value 数据值
|
||||
* @param excel 数据注解
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String dataFormatHandlerAdapter (Object value, Excel excel, Cell cell) {
|
||||
try {
|
||||
Object instance = excel.handler().getDeclaredConstructor().newInstance();
|
||||
Method formatMethod = excel.handler().getMethod("format", new Class[]{Object.class, String[].class, Cell.class, Workbook.class});
|
||||
Method formatMethod = excel.handler().getMethod("format", Object.class, String[].class, Cell.class, Workbook.class);
|
||||
value = formatMethod.invoke(instance, value, excel.args(), cell, this.wb);
|
||||
} catch (Exception e) {
|
||||
log.error("不能格式化数据 「{}-{}」", excel.handler() , e.getMessage());
|
||||
|
@ -931,7 +915,7 @@ public class ExcelUtil<T> {
|
|||
}
|
||||
try {
|
||||
temp = Double.valueOf(text);
|
||||
} catch (NumberFormatException e) {
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
statistics.put(index, statistics.get(index) + temp);
|
||||
}
|
||||
|
@ -941,7 +925,7 @@ public class ExcelUtil<T> {
|
|||
* 创建统计行
|
||||
*/
|
||||
public void addStatisticsRow () {
|
||||
if (statistics.size() > 0) {
|
||||
if (!statistics.isEmpty()) {
|
||||
Row row = sheet.createRow(sheet.getLastRowNum() + 1);
|
||||
Set<Integer> keys = statistics.keySet();
|
||||
Cell cell = row.createCell(0);
|
||||
|
@ -965,8 +949,6 @@ public class ExcelUtil<T> {
|
|||
* @param excel 注解
|
||||
*
|
||||
* @return 最终的属性值
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private Object getTargetValue (T vo, Field field, Excel excel) throws Exception {
|
||||
Object o = field.get(vo);
|
||||
|
@ -987,12 +969,10 @@ public class ExcelUtil<T> {
|
|||
/**
|
||||
* 以类的属性的get方法方法形式获取值
|
||||
*
|
||||
* @param o
|
||||
* @param name
|
||||
* @param o 对象
|
||||
* @param name 属性
|
||||
*
|
||||
* @return value
|
||||
*
|
||||
* @throws Exception
|
||||
* @return value 结果值
|
||||
*/
|
||||
private Object getValue (Object o, String name) throws Exception {
|
||||
if (StringUtils.isNotNull(o) && StringUtils.isNotEmpty(name)) {
|
||||
|
@ -1043,8 +1023,7 @@ public class ExcelUtil<T> {
|
|||
Excels attrs = field.getAnnotation(Excels.class);
|
||||
Excel[] excels = attrs.value();
|
||||
for (Excel attr : excels) {
|
||||
if (!ArrayUtils.contains(this.excludeFields, field.getName() + "." + attr.targetAttr())
|
||||
&& (attr != null && (attr.type() == Type.ALL || attr.type() == type))) {
|
||||
if (!ArrayUtils.contains(this.excludeFields, field.getName() + "." + attr.targetAttr()) && (attr.type() == Type.ALL || attr.type() == type)) {
|
||||
field.setAccessible(true);
|
||||
fields.add(new Object[]{field, attr});
|
||||
}
|
||||
|
@ -1102,7 +1081,7 @@ public class ExcelUtil<T> {
|
|||
*/
|
||||
public Object getCellValue (Row row, int column) {
|
||||
if (row == null) {
|
||||
return row;
|
||||
return null;
|
||||
}
|
||||
Object val = "";
|
||||
try {
|
||||
|
@ -1139,8 +1118,6 @@ public class ExcelUtil<T> {
|
|||
* 判断是否是空行
|
||||
*
|
||||
* @param row 判断的行
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private boolean isRowEmpty (Row row) {
|
||||
if (row == null) {
|
||||
|
@ -1184,14 +1161,14 @@ public class ExcelUtil<T> {
|
|||
* 是否有对象的子列表
|
||||
*/
|
||||
public boolean isSubList () {
|
||||
return StringUtils.isNotNull(subFields) && subFields.size() > 0;
|
||||
return StringUtils.isNotNull(subFields) && !subFields.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有对象的子列表,集合不为空
|
||||
*/
|
||||
public boolean isSubListValue (T vo) {
|
||||
return StringUtils.isNotNull(subFields) && subFields.size() > 0 && StringUtils.isNotNull(getListCellValue(vo)) && getListCellValue(vo).size() > 0;
|
||||
return StringUtils.isNotNull(subFields) && !subFields.isEmpty() && StringUtils.isNotNull(getListCellValue(vo)) && !getListCellValue(vo).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1200,7 +1177,7 @@ public class ExcelUtil<T> {
|
|||
public Collection<?> getListCellValue (Object obj) {
|
||||
Object value;
|
||||
try {
|
||||
value = subMethod.invoke(obj, new Object[]{});
|
||||
value = subMethod.invoke(obj);
|
||||
} catch (Exception e) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
@ -1221,7 +1198,7 @@ public class ExcelUtil<T> {
|
|||
getMethodName.append(name.substring(1));
|
||||
Method method = null;
|
||||
try {
|
||||
method = pojoClass.getMethod(getMethodName.toString(), new Class[]{});
|
||||
method = pojoClass.getMethod(getMethodName.toString());
|
||||
} catch (Exception e) {
|
||||
log.error("获取对象异常{}", e.getMessage());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue