@PostMapping ( "/importData" )
@ResponseBody
public AjaxResult importData ( MultipartFile file , boolean updateSupport ) throws Exception {
ExcelUtil < TZdfx > util = new ExcelUtil < TZdfx > ( TZdfx.class );
List < TZdfx > list = util.importExcel ( file.getInputStream ( ) );
String message = importTSylx ( list, updateSupport );
return AjaxResult.success ( message );
}
public String importTSylx ( List < TZdfx > list , Boolean isUpdateSupport ) {
if ( StringUtils.isNull ( list ) || list.size ( ) == 0 ) {
throw new BusinessException ( "导入商业流向数据不能为空!" );
}
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder ( );
StringBuilder failureMsg = new StringBuilder ( );
for ( TZdfx tZdfx : list ) {
log.warn ( tZdfx.toString () );
addSave(tZdfx);
}
if ( failureNum > 0 ) {
failureMsg.insert ( 0 , "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:" );
throw new BusinessException ( failureMsg.toString ( ) );
} else {
successMsg.insert ( 0 , "恭喜您,数据已全部导入成功!共 " + list.size () + " 条,数据如下:" +"\n"+list.toString ());
}
return successMsg.toString ( );
}
评论