增加各实体类导出excel时增加序号一列

This commit is contained in:
weiweiw 2024-08-23 15:22:20 +08:00
parent 87b4ae1944
commit 30a0e861a3
8 changed files with 23 additions and 15 deletions

View File

@ -18,6 +18,10 @@ public class SysDictData extends BaseEntity
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
//用于excel导出的序号一列,不需要业务逻辑处理
@Excel(name = "序号", isSequence = true, type = Excel.Type.EXPORT)
int sequence;
/** 字典编码 */ /** 字典编码 */
@Excel(name = "字典编码", cellType = ColumnType.NUMERIC) @Excel(name = "字典编码", cellType = ColumnType.NUMERIC)
private Long dictCode; private Long dictCode;

View File

@ -18,6 +18,10 @@ public class SysDictType extends BaseEntity
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
//用于excel导出的序号一列,不需要业务逻辑处理
@Excel(name = "序号", isSequence = true, type = Excel.Type.EXPORT)
int sequence;
/** 字典主键 */ /** 字典主键 */
@Excel(name = "字典主键", cellType = ColumnType.NUMERIC) @Excel(name = "字典主键", cellType = ColumnType.NUMERIC)
private Long dictId; private Long dictId;

View File

@ -31,6 +31,7 @@ import java.util.UUID;
@Data @Data
@Alias("SysLogsVo") @Alias("SysLogsVo")
public class SysLogsVo { public class SysLogsVo {
/** /**
* 日志id * 日志id
*/ */

View File

@ -19,6 +19,10 @@ public class SysRole extends BaseEntity
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
//用于excel导出的序号一列,不需要业务逻辑处理
@Excel(name = "序号", isSequence = true, type = Excel.Type.EXPORT)
int sequence;
/** 角色ID */ /** 角色ID */
@Excel(name = "角色序号", cellType = ColumnType.NUMERIC) @Excel(name = "角色序号", cellType = ColumnType.NUMERIC)
private Long roleId; private Long roleId;

View File

@ -21,6 +21,9 @@ import com.bonus.common.core.xss.Xss;
public class SysUser extends BaseEntity { public class SysUser extends BaseEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
//用于excel导出的序号一列,不需要业务逻辑处理
@Excel(name = "序号", isSequence = true, type = Excel.Type.EXPORT)
int sequence;
/** /**
* 用户ID * 用户ID
*/ */

View File

@ -1618,9 +1618,12 @@ public class ExcelUtil<T>
} }
private int getColumnIndexByFieldName(String fieldName) { private int getColumnIndexByFieldName(String fieldName) {
for (int columnIndex = 0; columnIndex <= sheet.getRow(0).getLastCellNum(); columnIndex++) { for (int columnIndex = 0; columnIndex <= sheet.getRow(0).getLastCellNum(); columnIndex++) {
if (fieldName.equals(sheet.getRow(0).getCell(columnIndex).getStringCellValue())) { Cell cell = sheet.getRow(0).getCell(columnIndex);
if (cell == null) {
continue;
}
else if (fieldName.equals(cell.getStringCellValue())){
return columnIndex; return columnIndex;
} }
} }

View File

@ -44,9 +44,9 @@ public class ExcelUtilTests {
String currentPath = System.getProperty("user.dir"); String currentPath = System.getProperty("user.dir");
System.out.println("当前执行路径: " + currentPath); System.out.println("当前执行路径: " + currentPath);
ExcelUtil<Person> excelUtil = new ExcelUtil<Person>(Person.class); ExcelUtil<Person> excelUtil = new ExcelUtil<Person>(Person.class);
Person p1 = new Person("admin",10,""); Person p1 = new Person("admin",10,"0");
p1.setImportErrorMessage("用户名存在"); p1.setImportErrorMessage("用户名存在");
Person p2 = new Person("admin2",20,""); Person p2 = new Person("admin2",20,"1");
p2.setImportErrorMessage("数据格式不正确"); p2.setImportErrorMessage("数据格式不正确");
List <Person> personList = new ArrayList<>(); List <Person> personList = new ArrayList<>();
personList.add(p1); personList.add(p1);

View File

@ -1,23 +1,12 @@
package com.bonus.common.security.interceptor; package com.bonus.common.security.interceptor;
import com.bonus.common.core.context.SecurityContextHolder; import com.bonus.common.core.context.SecurityContextHolder;
import com.bonus.common.core.utils.JwtUtils;
import com.bonus.common.core.utils.SafeUtil; import com.bonus.common.core.utils.SafeUtil;
import com.bonus.common.core.utils.StringUtils; import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.system.api.RemoteLogService;
import com.bonus.system.api.model.LoginUser;
import org.springframework.web.servlet.AsyncHandlerInterceptor; import org.springframework.web.servlet.AsyncHandlerInterceptor;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.github.pagehelper.util.StringUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;