import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
/**
* 上传账号清单辅助类
* @Author xiaoxin
* @Date 2022/5/24 22:07
* @Version 1.0
*/
@Data
public class UploadAccountDto {
//name表头、fixedindex列下标
@Excel(name = "应用系统",fixedIndex = 0)
private String applicationSystem;
@Excel(name = "应用从账号名称",fixedIndex = 1)
private String accountSon;
@Excel(name = "应用侧从账号姓名",fixedIndex = 2)
private String accountSonRealName;
@Excel(name = "应用账号状态",fixedIndex = 3)
private String accountSonStatus;
@Excel(name = "加锁原因",fixedIndex = 4)
private String accountSonLockCause;
@Excel(name = "从账号加锁时间",fixedIndex = 5)
private String accountSonLockTime;
@Excel(name = "从账号创建时间",fixedIndex = 6)
private String accountSonCreatorTime;
@Excel(name = "从账号最后更新时间",fixedIndex = 7)
private String accountSonLastUpdateTime;
@Excel(name = "从账号最后登录时间",fixedIndex = 8)
private String accountSonLastLoginTime;
@Excel(name = "授权生效时间",fixedIndex = 9)
private String accountMasterEmpowerStartTime;
@Excel(name = "授权失效时间",fixedIndex = 10)
private String accountMasterEmpowerEndTime;
@Excel(name = "账号类型",fixedIndex = 11)
private String accountType;
@Excel(name = "归属主账号",fixedIndex = 12)
private String accountMaster;
@Excel(name = "主账号姓名",fixedIndex = 13)
private String accountMasterRealName;
@Excel(name = "组织机构",fixedIndex = 14)
private String institution;
@Excel(name = "归属部门",fixedIndex = 15)
private String belongingDept;
@Excel(name = "主账号状态",fixedIndex = 16)
private String accountMasterStatus;
@Excel(name = "加锁类型",fixedIndex = 17)
private String accountMasterLockType;
@Excel(name = "主账号加锁原因",fixedIndex = 18)
private String accountMasterLockCause;
@Excel(name = "主账号加锁时间",fixedIndex = 19)
private String accountMasterLockTime;
@Excel(name = "主账号创建时间",fixedIndex = 20)
private String accountMasterCreatorTime;
@Excel(name = "主账号密码策略",fixedIndex = 21)
private String accountMasterPwdStrategy;
@Excel(name = "密码最后更新时间",fixedIndex = 22)
private String accountMasterLastUpdateTime;
@Excel(name = "账号到期时间",fixedIndex = 23)
private String accountMasterAbortTime;
}
需求是这样的,前端点击上传excel,后台读取并存入数据库,上面这个类是辅助类,name和下表设置好了,
@PostMapping("/accInfo/uploadContrast")
public Result accInfoUploadContrast(@RequestParam("file") MultipartFile file) throws IOException {
ImportParams importParams = new ImportParams();
importParams.setHeadRows(1);
importParams.setTitleRows(0);
importParams.setVerifyFileSplit(false);
//流校验文件
InputStream stream = new BufferedInputStream(file.getInputStream());
if (!ExcelFileUtil.isXlsx(stream)){
return new Result().error("-1", "文件类型错误");
}
try {
//读取并转换
ExcelImportResult<UploadAccountDto> result =
ExcelImportUtil.importExcelMore(file.getInputStream(),UploadAccountDto.class, importParams);
} catch (Exception e) {
e.printStackTrace();
}
return new Result();
}
}
然后把流、类型传进去就可以获得一个list了