场景:
导入案件的时候,由于导入数据量大的时候。loading的前台效果要转很久给用户体验不好,不知道进行了多少。想要能看到数据导入的状态和导入的数量的进度条。而且不是假的。现在网上大多数的做法是写个假的样式方式跟loading差不多。这里要写个真的
问题: 导入案件的后台操作比较复杂,没有想出在方法执行完毕之前去前台返回各个状态的值,方法里包含excel数据的校验和一条数据要分别导入4张表中的问题。所以这里的解决方法是个真的去查状态的方法,但也没法做到特别精准。
解决思路:
在导入方法的类中添加几个静态变量,在不同步骤的时候附上不同的值,在做一个全新的方法。用js定时器去,每隔1-2秒实时查询这些变量的值判断当前进入哪个步骤的导入量等。这样就能获得大致获得导入方法进行的进度
实现结果:
代码实现:
第一在导入方法的类定义静态变量再在进行到各步骤的时候赋值。
public static Integer checkStatus=null;//0正在进行 1成功
public static Integer caseCount=null;//案件导入个数
public static Integer contectStatus=null;//0正在进行 1成功
public static Integer lineNumber=null;//excel总行数
@Override
public Batch cuishouSaveCaseBatchData(final String batchcode, final Date wtdate, final Date wtenddate,
final String batchid, final String preCaseId, final String biztype, final String bankcode,
final ContractHead contractHead, final String companyid, MultipartFile file,
ContractLineService contractLineService, final Integer tabletype) throws Exception {
logger.error("进入导入方法");
//进入方法给checkStatus赋值0表示方法正在进行中
checkStatus=0;
//获取excel的行数
int allCounts = ExcelReader.readExcelRowCounts(file)