manailin
2021-08-20 51508c8c63bb072739a0e3ae45cb11e7599c8f66
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComMngPopulationRehabilitationExcelListen.java
@@ -50,31 +50,18 @@
    private Long communityId;
    private Long userId;
    private static int headSize = 0;
    private Map<Integer, String> headData;
    private String userName;
    // FTP 登录密码
    private String password;
    // FTP 服务器地址IP地址
    private String host;
    // FTP 端口
    private int port;
    private String excelUrl;
    private StringRedisTemplate stringRedisTemplate;
    public static String loadUrl;
    public ComMngPopulationRehabilitationExcelListen(CommunityService communityService, Long communityId, String userName, String password, String host, int port, String excelUrl, StringRedisTemplate stringRedisTemplate) {
    public ComMngPopulationRehabilitationExcelListen(CommunityService communityService, Long communityId, Long userId, StringRedisTemplate stringRedisTemplate) {
            this.communityService = communityService;
            this.communityId = communityId;
            this.userName = userName;
            this.password = password;
            this.host = host;
            this.port = port;
            this.excelUrl = excelUrl;
            this.userId = userId;
            this.stringRedisTemplate = stringRedisTemplate;
        }
@@ -479,7 +466,7 @@
                //根据list中的IdCard城市来去重
                List<ComMngPopulationRehabilitationExcelVO> newVoList = voList.stream().filter(ListUtils.distinctByKey(ComMngPopulationRehabilitationExcelVO::getDistinctPass)).collect(Collectors.toList());
                log.info("开始进入业务层处理逻辑");
                R r = communityService.listSavePopulationRehabilitationExcelVO(newVoList, communityId);
                R r = communityService.listSavePopulationRehabilitationExcelVO(newVoList, communityId, userId);
                log.info("业务层处理逻辑完成");
                if (!R.isOk(r)) {
                    log.info("业务层处理成功");
@@ -557,51 +544,6 @@
        vo.setHelpSituation(map.get(37));
        vo.setRemark(map.get(38));
    }
        private R mistakeExportPopulation(List<ComMngPopulationMistakeExcelVO> vo) {
            //生成动态模板excel通过ftp工具上传到主节点,然后返回模板下载地址
            String ftpUrl = "/mnt/data/web/excel/";
            String name = "实有人口错误数据.xlsx";
            try {
                SFTPUtil sftp = new SFTPUtil(userName, password, host, port);
                sftp.login();
                boolean existDir = sftp.isExistDir(ftpUrl + name);
                if (!existDir) {
                    String property = System.getProperty("user.dir");
                    String fileName = property + File.separator + name;
                    // 这里 需要指定写用哪个class去写
                    ExcelWriter excelWriter = null;
                    InputStream inputStream = null;
                    try {
                        excelWriter = EasyExcel.write(fileName, ComMngPopulationMistakeExcelVO.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).registerWriteHandler(new CustomSheetWriteHandler()).build();
                        WriteSheet writeSheet = EasyExcel.writerSheet("实有人口错误数据").build();
                        excelWriter.write(vo, writeSheet);
                        excelWriter.finish();
                        File file = new File(fileName);
                        inputStream = new FileInputStream(file);
                        sftp.uploadMore(ftpUrl, name, inputStream);
                        sftp.logout();
                        inputStream.close();
                        String absolutePath = file.getAbsolutePath();
                        boolean delete = file.delete();
                        log.info("删除excel【{}】结果【{}】", absolutePath, delete);
                    } finally {
                        // 千万别忘记finish 会帮忙关闭流
                        if (inputStream != null) {
                            inputStream.close();
                        }
                        if (excelWriter != null) {
                            excelWriter.finish();
                        }
                    }
                }
                return R.ok(excelUrl + name);
            } catch (Exception e) {
                e.printStackTrace();
                log.error("文件传输失败【{}】", e.getMessage());
                return R.fail();
            }
        }
        private String convertMarriage(String ma) {