前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >将 公共文件夹下的数据,复制到自己的文件夹下,然后对数据进行入库与 去重。防止将相同数据入库

将 公共文件夹下的数据,复制到自己的文件夹下,然后对数据进行入库与 去重。防止将相同数据入库

作者头像
一写代码就开心
发布2024-01-09 14:17:51
1030
发布2024-01-09 14:17:51
举报
文章被收录于专栏:java和pythonjava和python
目录
  • 1 问题
  • 2 实现

1 问题

A 用户将自己的数据文件,放到 一个文件夹下,B 用户需要写一个代码,定时将 公共文件夹下的数据,复制到自己的文件夹下,然后对数据进行入库与 去重。防止将相同数据入库

2 实现

代码语言:javascript
复制
 @ApiOperation(value = "报告文件 数据入库", httpMethod = "POST")
    @PostMapping("/insertFileInfo")
    public Result insertFileInfo(String path) {
        ArrayList<String> elelist = new ArrayList<>();
        StringInfoUtils.readFiles(path,elelist, Pattern.compile("^*.docx$"));
        if(elelist!=null && elelist.size()>0){
            ArrayList<ZpReportContents> objects = new ArrayList<>();
            for(String item : elelist) {
                File file = new File(item);
                // 202309
                String data = file.getParentFile().getName();
                // 本地文件
                File tmpFile = new File(Const.reportPath + File.separator + data + File.separator + file.getName());
                if (!new File(tmpFile + ".ok").exists()) {
                    // 进行解析入库

             
                    String copyPath = Const.reportPath  + File.separator + data;
                    File copy = new File(copyPath + File.separator);
                    if (!copy.exists())
                        copy.mkdirs();
                    FileUtil.copy(file.getPath(),copyPath,true);
                    String copyFile = copyPath + File.separator + file.getName();

                    try {
                        ZpReportContents zpReportContents = zpReportContentsService.insertFileInfo(copyFile);
                        objects.add(zpReportContents);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    try{
                        new File(copyFile+".ok").createNewFile();
                    } catch (Exception e){
                        e.getMessage();
                    }
                }
            }


            System.out.println("解析完成");
            // 批量入库
            if(objects!=null && objects.size()>0){
                List<List<ZpReportContents>> lists = Lists.partition(objects,BJTYPHOON_LENHTH);
                for (List<ZpReportContents> list : lists){
                    // pg数据入库
                    zpReportContentsMapper.batchInsert(list);
                    System.out.println("插入成功-----");
                    //baseMapper.saveOrUpdateBatch(list);
                }
                System.out.println("插入成功");
            }
        }
        return ResultUtil.ok("录入成功");
    }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2024-01-08,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 目录
  • 1 问题
  • 2 实现
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档