| | |
| | | import com.vci.ubcs.starter.web.enumpck.VciFieldTypeEnum; |
| | | import com.vci.ubcs.starter.web.pagemodel.DataGrid; |
| | | import com.vci.ubcs.starter.web.pagemodel.KeyValue; |
| | | import com.vci.ubcs.starter.web.util.LangBaseUtil; |
| | | import com.vci.ubcs.starter.web.util.VciBaseUtil; |
| | | import com.vci.ubcs.starter.web.util.VciDateUtil; |
| | | import lombok.AllArgsConstructor; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | String redisUUid=batchImportCodes(orderDTO,templateVO,dataSet,errorMap,true); |
| | | CodeImProtRusultVO codeImProtRusultVO = new CodeImProtRusultVO(); |
| | | List<String> needRowIndexList = new ArrayList<>(); |
| | | // String filePath = returnErrorToExcel(dataSet.getRowData(), errorMap, needRowIndexList, dataSet.getColName()); |
| | | // if(StringUtils.isNotBlank(filePath)) { |
| | | // codeImProtRusultVO.setFilePath(filePath); |
| | | // } |
| | | // if(StringUtils.isNotBlank(redisUUid)){ |
| | | // codeImProtRusultVO.setRedisUuid(redisUUid); |
| | | // } |
| | | return null; |
| | | // return codeImProtRusultVO; |
| | | String filePath = returnErrorToExcel(dataSet.getRowData(), errorMap, needRowIndexList, dataSet.getColName()); |
| | | if(StringUtils.isNotBlank(filePath)) { |
| | | codeImProtRusultVO.setFilePath(filePath); |
| | | } |
| | | if(StringUtils.isNotBlank(redisUUid)){ |
| | | codeImProtRusultVO.setRedisUuid(redisUUid); |
| | | } |
| | | // return null; |
| | | return codeImProtRusultVO; |
| | | } |
| | | |
| | | /** |
| | | * 错误信息返回excel |
| | | * @param rowDataList 所有的导入数据 |
| | | * @param errorMap 错误的信息 |
| | | * @param needRowIndexList 需要写入的数据的行号 |
| | | * @param titleRowData 标题行 |
| | | * |
| | | * @return 错误的excel文件,没有错误会返回空 |
| | | */ |
| | | private String returnErrorToExcel(Collection<SheetRowData> rowDataList, |
| | | Map<String,String> errorMap, |
| | | List<String> needRowIndexList,List<String> titleRowData){ |
| | | if(CollectionUtils.isEmpty(errorMap)){ |
| | | return ""; |
| | | } |
| | | Map<String, SheetRowData> rowIndexDataMap = rowDataList.stream().filter(s -> !needRowIndexList.contains(s.getRowIndex())).collect(Collectors.toMap(s -> s.getRowIndex(), t -> t)); |
| | | List<WriteExcelData> errorDataList = new ArrayList<>(); |
| | | errorDataList.add(new WriteExcelData(0,0,"错误信息")); |
| | | for (int i = 0; i < titleRowData.size(); i++) { |
| | | //错误信息在最后 |
| | | errorDataList.add(new WriteExcelData(0,i+1,titleRowData.get(i))); |
| | | } |
| | | Integer[] newRowIndex = new Integer[]{1}; |
| | | errorMap.forEach((index,error)->{ |
| | | //错误信息全部组合到一起 |
| | | SheetRowData rowData = rowIndexDataMap.getOrDefault(index, null); |
| | | if(rowData!=null){ |
| | | errorDataList.add(new WriteExcelData(newRowIndex[0],0,error)); |
| | | rowData.getData().forEach((colIndex,value)->{ |
| | | errorDataList.add(new WriteExcelData(newRowIndex[0],colIndex+1,value)); |
| | | }); |
| | | newRowIndex[0]++; |
| | | } |
| | | }); |
| | | String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + "错误信息.xls"; |
| | | WriteExcelOption eo = new WriteExcelOption(errorDataList); |
| | | try { |
| | | new File(excelFileName).createNewFile(); |
| | | } catch (IOException e) { |
| | | throw new VciBaseException(LangBaseUtil.getErrorMsg(e)); |
| | | } |
| | | ExcelUtil.writeDataToFile(excelFileName,eo); |
| | | return excelFileName; |
| | | } |
| | | |
| | | /** |