Source:
public ChannelPointDataDto importChannelPoint(String originalFileName, String loginName, InputStream inputStream) throws Exception { List<ChannelPointDetailDto> details = Lists.newArrayList(); try { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "GBK")); String line; while (null != (line = bufferedReader.readLine())) { String[] data = line.split(","); details.add(new ChannelPointDetailDto(null, data[0], data[1], data[2], Long.parseLong(data[3]), data.length >= 5 ? ("成功".equals(data[4]) ? true : false) : false)); } if (details.size() > 1000) { return new ChannelPointDataDto(false, "每次数据应该小于1000条"); } ChannelPointModel channelPointModel = new ChannelPointModel(originalFileName, 0l, 0l, loginName); channelPointMapper.create(channelPointModel); details.stream().forEach(detail -> { checkChannelPointDetailDto(detail); ChannelPointDetailModel channelPointDetailModel = new ChannelPointDetailModel(channelPointModel.getId(), detail); channelPointDetailMapper.create(channelPointDetailModel); pointBillService.createPointBill(channelPointDetailModel.getLoginName(), channelPointDetailModel.getId(), PointBusinessType.CHANNEL_IMPORT, channelPointDetailModel.getPoint()); userPointMapper.updateChannelIfNotExist(channelPointDetailModel.getLoginName(), channelPointDetailModel.getChannel()); }); List<ChannelPointDetailModel> successPointDetail = channelPointDetailMapper.findSuccessByChannelPointId(channelPointModel.getId()); channelPointModel.setTotalPoint(successPointDetail.stream().mapToLong(detail -> detail.getPoint()).sum()); channelPointModel.setHeadCount(successPointDetail.size()); channelPointMapper.update(channelPointModel); return new ChannelPointDataDto(true, channelPointModel.getId()); } catch (ArrayIndexOutOfBoundsException e) { return new ChannelPointDataDto(false, "上传失败！文件中部分数据格式不规范"); } catch (IOException e) { return new ChannelPointDataDto(false, "上传失败!文件内容读取错误"); } finally { if (null != inputStream) { inputStream.close(); } } }

Target:
public ChannelPointDataDto importChannelPoint(String originalFileName, String loginName, InputStream inputStream) throws Exception { List<ChannelPointDetailDto> details = Lists.newArrayList(); try { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "GBK")); String line; while (null != (line = bufferedReader.readLine())) { String[] data = line.split(","); details.add(new ChannelPointDetailDto(null, data[0], data[1], data[2], Long.parseLong(data[3]))); } if (details.size() > 1000) { return new ChannelPointDataDto(false, "每次数据应该小于1000条"); } ChannelPointModel channelPointModel = new ChannelPointModel(originalFileName, 0l, 0l, loginName); channelPointMapper.create(channelPointModel); details.stream().forEach(detail -> { boolean conform = checkChannelPointDetailDto(detail); ChannelPointDetailModel channelPointDetailModel = new ChannelPointDetailModel(channelPointModel.getId(), detail); channelPointDetailMapper.create(channelPointDetailModel); if(conform){ pointBillService.createPointBill(channelPointDetailModel.getLoginName(), channelPointDetailModel.getId(), PointBusinessType.CHANNEL_IMPORT, channelPointDetailModel.getPoint()); userPointMapper.updateChannelIfNotExist(channelPointDetailModel.getLoginName(), channelPointDetailModel.getChannel()); } }); List<ChannelPointDetailModel> successPointDetail = channelPointDetailMapper.findSuccessByChannelPointId(channelPointModel.getId()); channelPointModel.setTotalPoint(successPointDetail.stream().mapToLong(detail -> detail.getPoint()).sum()); channelPointModel.setHeadCount(successPointDetail.size()); channelPointMapper.update(channelPointModel); return new ChannelPointDataDto(true, channelPointModel.getId()); } catch (ArrayIndexOutOfBoundsException e) { return new ChannelPointDataDto(false, "上传失败！文件中部分数据格式不规范"); } catch (IOException e) { return new ChannelPointDataDto(false, "上传失败!文件内容读取错误"); } finally { if (null != inputStream) { inputStream.close(); } } }