liusheng
2024-07-22 9e99e7e192c62c2274f8f5362b354cbf55c3d80f
ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceReimbursementServiceImpl.java
@@ -100,8 +100,14 @@
        if (serviceReimbursement.getRecordstatus() != null) {
            wrappers.eq(ServiceReimbursement::getRecordstatus, serviceReimbursement.getRecordstatus());
        }
        if (serviceReimbursement.getUploadStates() != null) {
            wrappers.eq(ServiceReimbursement::getUploadStates, serviceReimbursement.getUploadStates());
        }
        if (StringUtils.isNotBlank(serviceReimbursement.getUploadflag())) {
            wrappers.eq(ServiceReimbursement::getUploadflag, serviceReimbursement.getUploadflag());
        }
        if (serviceReimbursement.getFlowlevel() != null) {
            wrappers.eq(ServiceReimbursement::getFlowlevel, serviceReimbursement.getFlowlevel());
        }
       /* if (serviceReimbursement.getStarttime()!=null && serviceReimbursement.getEndtime()!=null){
@@ -150,7 +156,7 @@
    }
    @Override
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public Boolean addSharedData(Long id) {
        log.info("addSharedData方法的入参id :{}", id);
        //先判断一下share表是否已经插入
@@ -190,7 +196,18 @@
            serviceReimbursementdetailShareds.get(i).setId(null);
            //上传OA文件
            log.info("上传OA文件方法的入参:{}", serviceReimbursementdetailShareds.get(i));
            uploadOAFileAndUpdateDb(serviceReimbursementdetailShareds.get(i));
            try {
                uploadOAFileAndUpdateDb(serviceReimbursementdetailShareds.get(i));
            } catch (Exception e) {
                log.error("Exception中reimShare的入参id为:{}", serviceReimbursementShared.getId());
                if (serviceReimbursementShared.getId() != null) {
                    Boolean aBoolean = sharedService.delResharedInfoById(serviceReimbursementShared.getId());
                    log.error("文件上传失败,将分享表数据回滚:{}", aBoolean);
                }
                e.getMessage();
                return false;
            }
        }
//        detailSharedService.saveBatch(serviceReimbursementdetailShareds);
@@ -245,7 +262,7 @@
    }
    public int uploadOAFileAndUpdateDb(ServiceReimbursementdetailShared remShare) {
    public int uploadOAFileAndUpdateDb(ServiceReimbursementdetailShared remShare) throws Exception {
        log.info("uploadOAFileAndUpdate方法的入参:{}", remShare);
        System.out.println("uploadOAFileAndUpdate方法的入参:" + remShare);
        //上传OA文件
@@ -279,13 +296,12 @@
        List<RbDetailFile> invoicefilesArray = JSON.parseArray(remShare.getInvoicefiles(), RbDetailFile.class);
        //普通附件
        uploadFile(filePath, strFUrl, parseArray2, parseArray, remShare, "1");
        //发票附件
        uploadFile(filePath, strFUrl, invoicefilesList, invoicefilesArray, remShare, "2");
        return 0;
    }
    private Integer uploadFile(String filePath, String strFUrl, List<RbDetailFile> parseArray2, List<RbDetailFile> parseArray, ServiceReimbursementdetailShared remShare, String flag) {
    private Integer uploadFile(String filePath, String strFUrl, List<RbDetailFile> parseArray2, List<RbDetailFile> parseArray, ServiceReimbursementdetailShared remShare, String flag) throws Exception {
        if (!CollectionUtils.isEmpty(parseArray)) {
            for (int i = 0; i < parseArray.size(); i++) {
                RbDetailFile rbDetailFile = parseArray.get(i);
@@ -293,30 +309,24 @@
                log.info("filePath的修改:{}", filePath);
                String url = rbDetailFile.getUrl();
                //file用的是绝对位置
                String substring = url.substring(url.indexOf("/profile/upload") + "/profile/upload".length());
                String fileName = url.substring(url.indexOf("/profile/upload") + "/profile/upload".length());
                String strFile = rbDetailFile.getUrl().replace(filePath, "/profile/upload");
                System.out.println("reimbursement服务的filePath + substring是乱码吗: " + filePath + substring);
                File filetest = new File(filePath + substring);
                try {
                    log.info("请求第三方的入参strFile : {}, strFUrl : {}", strFile, filePath);
                    String struploadResult = HttpClientKit.sendPostWithFile(filetest, strFUrl);
                    log.info("第三方传回的数据: {}", struploadResult);
                    if (StringUtils.isEmpty(struploadResult)) {
                        log.info("HttpClientKit.sendPostWithFile 请求为空了 filetest:{},  strFUrl:{} ", filetest, strFUrl);
                        return 0;
                    }
                File fileUpload = new File(filePath + fileName);
                log.info("请求第三方的入参strFile : {}, strFUrl : {}", strFile, filePath);
                String struploadResult = HttpClientKit.sendPostWithFile(fileUpload, strFUrl);
                log.info("第三方传回的数据: {}", struploadResult);
                if (StringUtils.isEmpty(struploadResult)) {
                    log.info("HttpClientKit.sendPostWithFile 请求为空了 struploadResult:{},  strFUrl:{} ", struploadResult, strFUrl);
                    return 0;
                }
                    //获取fileid
                    JSONObject jsonR = JSONObject.parseObject(struploadResult);
                    JSONArray jsonArr = jsonR.getJSONArray("atts");
                    log.info("第三方传回的数据获取的atts : {}", jsonArr);
                    for (int j = 0; j < jsonArr.size(); j++) {
                        JSONObject jsonRet = jsonArr.getJSONObject(j);
                        rbDetailFile.setFileid(jsonRet.get("fileUrl").toString());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    log.error("HttpClientKit.sendPostWithFile 报错了 : " + e.getMessage());
                //获取fileid
                JSONObject jsonR = JSONObject.parseObject(struploadResult);
                JSONArray jsonArr = jsonR.getJSONArray("atts");
                log.info("第三方传回的数据获取的atts : {}", jsonArr);
                for (int j = 0; j < jsonArr.size(); j++) {
                    JSONObject jsonRet = jsonArr.getJSONObject(j);
                    rbDetailFile.setFileid(jsonRet.get("fileUrl").toString());
                }
                parseArray2.add(rbDetailFile);
            }