导入--单页签

1.前台传文件
2.后台接收文件并转为实体List
@RequestMapping(value = "/to_impt", method = RequestMethod.POST)
public WebResponseContext toImpt(HttpServletRequest request
    , @RequestParam("file") MultipartFile multipartFile
    , @RequestParam(value = "handbookNo", required = true) String handbookNo
) {
   List<HandbookExportExg> list = FileUtils.importExcel(multipartFile, 0, 1, HandbookExportExg.class);
//把File文件转为List
public static <T> List<T> importExcel(MultipartFile file, Integer titleRows, Integer headerRows, Class<T> pojoClass) {
    if (file == null) {
        return null;
    }
    ImportParams params = new ImportParams();
    params.setTitleRows(titleRows);
    params.setHeadRows(headerRows);

    List<T> list = null;
    try {
        list = ExcelImportUtil.importExcel(file.getInputStream(), pojoClass, params);
    } catch (NoSuchElementException e) {
        // throw new NormalException("excel文件不能为空");
        e.printStackTrace();
    } catch (Exception e) {
        //throw new NormalException(e.getMessage());
        e.printStackTrace();
    }
    return list;
}

3.进行相关效验后,批量保存到数据库

public void bacthUpdateExg(List<HandbookExgInput> exgInputList, String handbookNo) {
    if (exgInputList == null || exgInputList.size() == 0) {
        return;
    }

    //3是测试数据,后续改成50
    if (exgInputList.size() <= BATCH_PERSIZE) {
        exgInputRepository.batchUpdateExgInput(exgInputList, handbookNo);
        return;
    }

    //对于数量超过N条的分批执行
    int exgInputSize = exgInputList.size();
    int times = exgInputSize % BATCH_PERSIZE == 0 ? exgInputSize / BATCH_PERSIZE : exgInputSize / BATCH_PERSIZE + 1;
    for (int i = 0; i < times; i++) {
        int beginIndex = i * BATCH_PERSIZE;
        int endIndex = (i + 1) * BATCH_PERSIZE > exgInputSize ? exgInputSize : (i + 1) * BATCH_PERSIZE;

        logger.info("批量保存--成品---数据,beginIndex:" + beginIndex + ",endIndex:" + endIndex);

        exgInputRepository.batchUpdateExgInput(exgInputList.subList(beginIndex, endIndex), handbookNo);
    }

}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值