固定模板头导入

public ResultVO importFinacePayrollExcel(MultipartFile file, HttpServletRequest req, SysUser user) {
        try {
            if (!file.getOriginalFilename().endsWith(".xls") && !file.getOriginalFilename().endsWith(".xlsx")) {
                throw new IOException("导入文件格式错误!");
            }
            ImportParams params = new ImportParams();
            // 固定模板头部标题
            params.setNeedVerfiy(true);
            ExcelImportResult<FinacePayrollVo> result = null;
            try {
            	//主要部分
                result = ExcelImportUtil.importExcelMore(file.getInputStream(),
                        FinacePayrollVo.class, params);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVO.ERROR("数据校验异常", null);
            }

        if (result.isVerfiyFail()) {
            StringJoiner errorMsgs = new StringJoiner("," + "<br/>");
            for (FinacePayrollVo vo : result.getFailList()) {
                errorMsgs.add("第" + vo.getRowNum() + "行的错误是:" + vo.getErrorMsg());
            }
            return ResultVO.FAIL(errorMsgs.toString(), null);
        } else if (result.getList() != null && !result.getList().isEmpty()) {
            List<FinacePayrollVo> successlist = result.getList();
            if (successlist != null && !successlist.isEmpty()) {
            	// 具体数据导入,根据情况编写
                return importFinacePayrollFile(file, successlist, user);
            }
        }else {
            return ResultVO.FAIL("导入表中数据异常,或没有数据", null);
        }
        return ResultVO.SUCCESS();
    } catch (Exception e) {
        e.printStackTrace();
        return ResultVO.ERROR();
    }
}

/-------------------------------实体---------------------------------/
@Data
@NoArgsConstructor
public class FinacePayrollVo  implements IExcelDataModel, IExcelModel {

private int rowNum;

private String errorMsg;

@Excel(name = "人员代码" )
@NotBlank(message = "[人员代码]不能为空")
private String empNo;

@Excel(name = "姓名")
@NotBlank(message = "[姓名]不能为空")
private String empName;

@Excel(name = "年月")
@NotBlank(message = "[年月]不能为空")
private String  payrollMonth;

@Excel(name = "部门代码")
private Integer empDeptId;

@Excel(name = "部门名称")
private String  empDeptName;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值