liusheng
2023-09-14 fa8521a23af37854e7a23d35467147bd00e008b2
ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java
@@ -137,6 +137,7 @@
        ServiceFundShared serviceFundShared = DtoConversionUtils.sourceToTarget(serviceFund, ServiceFundShared.class);
        serviceFundShared.setSerfunid(serviceFundShared.getId());
        serviceFundShared.setId(null);
        log.info("数据都插进去了吗? {}", serviceFundShared);
        sharedService.save(serviceFundShared);
        //fundId为主表的ID
@@ -669,6 +670,7 @@
    @Transactional
    public Long addOrUpdateNew(ServiceFundVO serviceFundVO) {
        Long id = null;
        //将数据保存到fund表
        if (serviceFundVO.getId() == null) {
            save(serviceFundVO);
            id = serviceFundVO.getId();
@@ -681,71 +683,21 @@
            System.out.println("serviceFunddetails为空喽");
            return null;
        }
        // 用于记录税前、税后的总和
        double taxBefore = 0.0;
        double taxAfter = 0.0;
        // 保存详情数据
        for (ServiceFunddetailVO serviceFunddetailVO : serviceFunddetails) {
            serviceFunddetailVO.setFundid(id);
            //將附件转成json
            if (!CollectionUtils.isEmpty(serviceFunddetailVO.getAnnexfilesList())) {
                serviceFunddetailVO.setAnnexfiles(JSON.toJSONString(serviceFunddetailVO.getAnnexfilesList()));
            }
            if (serviceFunddetailVO.getTaxedamount() != null && serviceFunddetailVO.getAmount() != null && serviceFunddetailVO.getTaxedamount() != 0.0 && serviceFunddetailVO.getAmount() != 0.0) {
                // 税前税后都不为空
                ServiceFunddetail serviceFunddetail = DtoConversionUtils.sourceToTarget(serviceFunddetailVO, ServiceFunddetail.class);
                if (serviceFunddetailVO.getId() == null) {
                    serviceFunddetailService.save(serviceFunddetail);
                } else {
                    serviceFunddetailService.updateById(serviceFunddetail);
                }
                //计算税金
                if (serviceFunddetail.getAmount() != null) {
                    taxBefore = taxBefore + serviceFunddetail.getAmount();
                }
                if (serviceFunddetail.getTaxedamount() != null) {
                    taxAfter = taxAfter + serviceFunddetail.getTaxedamount();
                }
                continue;
            } else if (serviceFunddetailVO.getTaxedamount() != null && serviceFunddetailVO.getTaxedamount() != 0.0) {
                // 税后求税前,如果是专家费申请  或 伦理专家费申请   才会计算税前税后
                if (StringUtils.isNotEmpty(serviceFundVO.getApplytype()) && serviceFundVO.getApplytype().equals("1") || serviceFundVO.getApplytype().equals("2")) {
                    Double taxationBefore = Double.valueOf(TaxtUtils.getTaxationBefore(BigDecimal.valueOf(serviceFunddetailVO.getTaxedamount())));
                    // 税金
                    String taxation = TaxtUtils.getTaxation(BigDecimal.valueOf(taxationBefore));
                    serviceFunddetailVO.setAmount(Double.valueOf(taxationBefore));
                    serviceFunddetailVO.setTaxamount(Double.parseDouble(taxation));
                }
            } else if (serviceFunddetailVO.getAmount() != null && serviceFunddetailVO.getAmount() != 0.0) {
                // 税前求税后,如果是专家费申请  或 伦理专家费申请   才会计算税前税后
                if (StringUtils.isNotEmpty(serviceFundVO.getApplytype()) && serviceFundVO.getApplytype().equals("1") || serviceFundVO.getApplytype().equals("2")) {
                    double tax = Double.parseDouble(TaxtUtils.getTaxation(BigDecimal.valueOf(serviceFunddetailVO.getAmount())));
                    BigDecimal taxAfterMoney = BigDecimal.valueOf(serviceFunddetailVO.getAmount()).subtract(BigDecimal.valueOf(tax));
                    serviceFunddetailVO.setTaxamount(tax);
                    serviceFunddetailVO.setTaxedamount(taxAfterMoney.doubleValue());
                }
            }
            //根据id判断是新增还是修改
            ServiceFunddetail serviceFunddetail = DtoConversionUtils.sourceToTarget(serviceFunddetailVO, ServiceFunddetail.class);
            if (serviceFunddetailVO.getId() == null) {
                serviceFunddetailService.save(serviceFunddetail);
            } else {
                serviceFunddetailService.updateById(serviceFunddetail);
            }
//            if (serviceFundVO.getApplytype().equals("1") || serviceFundVO.getApplytype().equals("2")) {
            //如果是专家费申请  或 伦理专家费申请   才会计算税前税后
            if (serviceFunddetail.getAmount() != null) {
                taxBefore = taxBefore + serviceFunddetail.getAmount();
            }
            if (serviceFunddetail.getTaxedamount() != null) {
                taxAfter = taxAfter + serviceFunddetail.getTaxedamount();
            }
        }
        //将税前、税后金额更新到fund表中
        serviceFundVO.setPretaxcost(taxBefore);
        serviceFundVO.setTaxedcost(taxAfter);
        updateById(serviceFundVO);
        return id;
    }
@@ -774,38 +726,41 @@
        String strFUrl = "http://129.88.242.39:8899/seeyon/rest/attachment?token=" + strRes;
        List<RbDetailFile> parseArray2 = new ArrayList<>();
        List<RbDetailFile> parseArray = JSON.parseArray(remShare.getAnnexfiles(), RbDetailFile.class);
        for (int i = 0; i < parseArray.size(); i++) {
            RbDetailFile rbDetailFile = parseArray.get(i);
            log.info("filePath的修改:{}", filePath);
            String url = rbDetailFile.getUrl();
            //file用的是绝对位置
            String substring = url.substring(url.indexOf("/profile/upload") + "/profile/upload".length());
        log.info("parseArray的值 : {}", parseArray);
        if (!CollectionUtils.isEmpty(parseArray)) {
            for (int i = 0; i < parseArray.size(); i++) {
                RbDetailFile rbDetailFile = parseArray.get(i);
                log.info("filePath的修改:{}", filePath);
                String url = rbDetailFile.getUrl();
                //file用的是绝对位置
                String substring = url.substring(url.indexOf("/profile/upload") + "/profile/upload".length());
//            String strFile = rbDetailFile.getUrl().replace(filePath, "/profile/upload");
            File filetest = new File(filePath + substring);
                System.out.println("fund服务的filePath + substring: " + filePath + substring);
                File filetest = new File(filePath + substring);
            try {
                String struploadResult = HttpClientKit.sendPostWithFile(filetest, strFUrl);
                log.info("第三方传回的数据: {}", struploadResult);
                if (StringUtils.isEmpty(struploadResult)) {
                    log.info("HttpClientKit.sendPostWithFile 请求为空了 filetest:{},  strFUrl:{} ", filetest, strFUrl);
                    return 0;
                try {
                    String struploadResult = HttpClientKit.sendPostWithFile(filetest, strFUrl);
                    log.info("第三方传回的数据: {}", struploadResult);
                    if (StringUtils.isEmpty(struploadResult)) {
                        log.info("HttpClientKit.sendPostWithFile 请求为空了 filetest:{},  strFUrl:{} ", filetest, 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();
                }
                //获取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();
                parseArray2.add(rbDetailFile);
            }
            parseArray2.add(rbDetailFile);
            remShare.setAnnexfiles(JSON.toJSONString(parseArray2));
            log.info("ServiceReimbursementdetailShared 是否加上了fileid : {}", remShare);
        }
        remShare.setAnnexfiles(JSON.toJSONString(parseArray2));
        log.info("ServiceReimbursementdetailShared 是否加上了fileid : {}", remShare);
        return 0;
    }