瀏覽代碼

解决选择合同BUG

caozj 1 年之前
父節點
當前提交
78802a8ce1

+ 28 - 14
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java

@@ -181,6 +181,16 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
     @Override
     public Page<ContractVo> getContractAndSamplePage(ContractSelectDto dto) {
         IWrapper<Contract> wrapper = getWrapper();
+        if (StringUtils.isNotEmpty(dto.getKeyword())) {
+            //归属公司
+            List<Long> corporationIds = corporationService.listObject(Corporation::getId, q -> q.like(Corporation::getName, dto.getKeyword()));
+            List<Long> customerIds = customerService.listObject(Customer::getId, q -> q.like(Customer::getName, dto.getKeyword()));
+            wrapper.and(q -> q
+                    .like("t1", Contract::getCode, dto.getKeyword())
+                    .or().in("t1", Contract::getSellCorporationId, corporationIds)
+                    .or().in("t1", Contract::getBuyCorporationId, customerIds)
+            );
+        }
         Page<ContractVo> contractAndSamplePage = baseMapper.getContractAndSamplePagez(dto.getPage(), wrapper);
         List<ContractVo> records = contractAndSamplePage.getRecords();
         //赋值原卖方公司名称 多公司
@@ -350,13 +360,12 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
             List<PurchaseDetailVo> otherAmountList = purchaseDetailService.getSumCountInDataResourceIds(contractIds);
             Map<Long, String> otherAmountMap = otherAmountList.stream().collect(Collectors.toMap(PurchaseDetailVo::getDataResourceId, PurchaseDetailVo::getSumAmountCurrency));
             //取出默认汇率
-            List<CurrencyRate> currencyRateList = currencyRateService.getList();
-            Map<String, BigDecimal> currencyRateMap = currencyRateList.stream().collect(Collectors.toMap(CurrencyRate::getType, CurrencyRate::getRate));
+//            List<CurrencyRate> currencyRateList = currencyRateService.getList();
+//            Map<String, BigDecimal> currencyRateMap = currencyRateList.stream().collect(Collectors.toMap(CurrencyRate::getType, CurrencyRate::getRate));
             for (ContractBudgetVo v : list) {
                 if (StringUtils.isNotEmpty(v.getCurrencyRateJson())) {//如果此条合同有汇率了
                     List<ContractCurrencyRate> contractCurrencyRates = JSON.parseArray(v.getCurrencyRateJson(), ContractCurrencyRate.class);
                     Map<String, BigDecimal> map = contractCurrencyRates.stream().collect(Collectors.toMap(ContractCurrencyRate::getType, ContractCurrencyRate::getRate));
-                    v.setRefundableAmount(BigDecimal.ZERO);//暂时先设置退税金额为0
                     if (MapUtils.isNotEmpty(ehsdAmountMap)) {    //计算EHSD租户应付货款
                         String concatAmountCurrency = ehsdAmountMap.getOrDefault(v.getContractId(), null);
                         if (StringUtils.isNotEmpty(concatAmountCurrency)) {
@@ -380,31 +389,36 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
                             (v.getOther() == null ? BigDecimal.ZERO : v.getOther().multiply(new BigDecimal(map.getOrDefault(v.getOtherCurrency(), BigDecimal.ONE).toString()))).add
                             (v.getEhsdSumAmount() == null ? BigDecimal.ZERO : v.getEhsdSumAmount()).add
                             (v.getOtherSumAmount() == null ? BigDecimal.ZERO : v.getOtherSumAmount()));
-                } else {//没有汇率取默认汇率
                     v.setRefundableAmount(BigDecimal.ZERO);//暂时先设置退税金额为0
+                    v.setRmbContractAmount(v.getAmount().multiply(new BigDecimal(map.getOrDefault(v.getCurrency(), BigDecimal.ONE).toString())));
+                } else {//没有汇率取默认汇率
+                    BigDecimal rate = v.getRate();
                     if (MapUtils.isNotEmpty(ehsdAmountMap)) {    //计算EHSD租户应付货款
                         String concatAmountCurrency = ehsdAmountMap.getOrDefault(v.getContractId(), null);
                         if (StringUtils.isNotEmpty(concatAmountCurrency)) {
                             BigDecimal amount = new BigDecimal(concatAmountCurrency.split("-")[0]);
-                            String currency = concatAmountCurrency.split("-")[1];
-                            BigDecimal rate = currencyRateMap.getOrDefault(currency, BigDecimal.ONE);
+//                            String currency = concatAmountCurrency.split("-")[1];
+//                            BigDecimal rate = v.getRate();
                             v.setEhsdSumAmount(amount.multiply(rate));
                         } else {
                             v.setEhsdSumAmount(BigDecimal.ZERO);
                         }
                     }
                     //计算收入总计=合同金额(转人民币)+应退税金额(转人民币)
-                    v.setIncomeAmount(v.getAmount().multiply(currencyRateMap.getOrDefault(v.getContractId(), new BigDecimal("1"))).add(v.getRefundableAmount()));
+                    v.setIncomeAmount(v.getAmount().multiply(rate).add(v.getRefundableAmount()));
                     //计算支出总计 除合同金额(转人民币)+应退税金额(转人民币) 其他金额相加
-                    v.setExpenditureAmount(v.getTrailerFee() == null ? BigDecimal.ZERO : v.getTrailerFee().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getTrailerFeeCurrency(), BigDecimal.ONE).toString())).add
-                            (v.getCustomsFee() == null ? BigDecimal.ZERO : v.getCustomsFee().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getCustomsFeeCurrency(), BigDecimal.ONE).toString()))).add
-                            (v.getAgencyFee() == null ? BigDecimal.ZERO : v.getAgencyFee().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getAgencyFeeCurrency(), BigDecimal.ONE).toString()))).add
-                            (v.getPortMixedFee() == null ? BigDecimal.ZERO : v.getPortMixedFee().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getPortMixedFeeCurrency(), BigDecimal.ONE).toString()))).add
-                            (v.getInspectionRedPack() == null ? BigDecimal.ZERO : v.getInspectionRedPack().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getInspectionRedPackCurrency(), BigDecimal.ONE).toString()))).add
-                            (v.getCommission() == null ? BigDecimal.ZERO : v.getCommission().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getCommissionCurrency(), BigDecimal.ONE).toString()))).add
-                            (v.getOther() == null ? BigDecimal.ZERO : v.getOther().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getOtherCurrency(), BigDecimal.ONE).toString()))).add
+                    v.setExpenditureAmount(
+                            v.getTrailerFee() == null ? BigDecimal.ZERO : v.getTrailerFee().multiply(rate).add
+                            (v.getCustomsFee() == null ? BigDecimal.ZERO : v.getCustomsFee().multiply(rate)).add
+                            (v.getAgencyFee() == null ? BigDecimal.ZERO : v.getAgencyFee().multiply(rate)).add
+                            (v.getPortMixedFee() == null ? BigDecimal.ZERO : v.getPortMixedFee().multiply(rate)).add
+                            (v.getInspectionRedPack() == null ? BigDecimal.ZERO : v.getInspectionRedPack().multiply(rate)).add
+                            (v.getCommission() == null ? BigDecimal.ZERO : v.getCommission().multiply(rate)).add
+                            (v.getOther() == null ? BigDecimal.ZERO : v.getOther().multiply(rate)).add
                             (v.getEhsdSumAmount() == null ? BigDecimal.ZERO : v.getEhsdSumAmount()).add
                             (v.getOtherSumAmount() == null ? BigDecimal.ZERO : v.getOtherSumAmount()));
+                    v.setRefundableAmount(BigDecimal.ZERO);//暂时先设置退税金额为0
+                    v.setRmbContractAmount(v.getAmount().multiply(rate));
                 }
                 //计算毛利 收入-支出
                 v.setGross(v.getIncomeAmount().subtract(v.getExpenditureAmount()));

+ 65 - 55
hx-sale/src/main/resources/mapper/contract/ContractMapper.xml

@@ -211,64 +211,74 @@
     </select>
     <select id="getContractAndSamplePagez" resultType="com.fjhx.sale.entity.contract.vo.ContractVo">
         SELECT
-            t1.id,
-            t1.sell_corporation_id,
-            t1.contract_type,
-            1 as dataType,
-            t1.`code`,
-            t1.buy_corporation_id,
-            t1.version,
-            t1.amount,
-            t1.create_user,
-            t1.create_time,
-            t1.refund_status,
-            t1.`status`,
-            (
-                SELECT
-                    IFNULL( SUM( IFNULL( cc.money, 0 ) * IFNULL( arw.rate, 1 )), 0 )
-                FROM
-                    claim_contract cc
-                        LEFT JOIN claim c ON cc.claim_id = c.id
-                        LEFT JOIN bytesailing_account.account_running_water arw ON c.business_id = arw.id
-                WHERE
-                    cc.contract_id = t1.id
-            ) AS sumClaimMoney
+        *
         FROM
-            contract t1
-            ${ew.customSqlSegment}
-        UNION
+        (
         SELECT
-            t1.id,
-            t1.sell_corporation_id,
-            3 AS contract_type,
-            2 AS dataType,
-            t1.`code`,
-            t1.buy_corporation_id,
-            t1.versions AS version,
-            t1.amount,
-            t1.create_user,
-            t1.create_time,
-            IF ( sumClaimMoney >= t1.amount, 20, IF ( sumClaimMoney != 0, 10, 0 ) ) AS refund_status,
-            t1.`status`,
-            t1.sumClaimMoney
+        t1.id,
+        t1.sell_corporation_id,
+        t1.contract_type,
+        1 AS dataType,
+        t1.`code`,
+        t1.buy_corporation_id,
+        t1.version,
+        t1.amount,
+        t1.create_user,
+        t1.create_time,
+        t1.refund_status,
+        t1.`status`,
+        (
+        SELECT
+        IFNULL( SUM( IFNULL( cc.money, 0 ) * IFNULL( arw.rate, 1 )), 0 )
         FROM
-            (
-                SELECT
-                    t1.*,
-                    (
-                        SELECT
-                            IFNULL( SUM( IFNULL( cc.money, 0 ) * IFNULL( arw.rate, 1 )), 0 )
-                        FROM
-                            claim_contract cc
-                                LEFT JOIN claim c ON cc.claim_id = c.id
-                                LEFT JOIN bytesailing_account.account_running_water arw ON c.business_id = arw.id
-                        WHERE
-                            cc.contract_id = t1.id
-                    ) AS sumClaimMoney
-                FROM
-                    sample t1
-            ) AS t1
-            ${ew.customSqlSegment}
+        claim_contract cc
+        LEFT JOIN claim c ON cc.claim_id = c.id
+        LEFT JOIN bytesailing_account.account_running_water arw ON c.business_id = arw.id
+        WHERE
+        cc.contract_id = t1.id
+        ) AS sumClaimMoney
+        FROM
+        contract t1
+        WHERE
+        t1.`status` >= 30
+        AND t1.`status` &lt; 88 UNION
+        SELECT
+        t1.id,
+        t1.sell_corporation_id,
+        3 AS contract_type,
+        2 AS dataType,
+        t1.`code`,
+        t1.buy_corporation_id,
+        t1.versions AS version,
+        t1.amount,
+        t1.create_user,
+        t1.create_time,
+        IF
+        ( sumClaimMoney >= t1.amount, 20, IF ( sumClaimMoney != 0, 10, 0 ) ) AS refund_status,
+        t1.`status`,
+        t1.sumClaimMoney
+        FROM
+        (
+        SELECT
+        t1.*,
+        (
+        SELECT
+        IFNULL( SUM( IFNULL( cc.money, 0 ) * IFNULL( arw.rate, 1 )), 0 )
+        FROM
+        claim_contract cc
+        LEFT JOIN claim c ON cc.claim_id = c.id
+        LEFT JOIN bytesailing_account.account_running_water arw ON c.business_id = arw.id
+        WHERE
+        cc.contract_id = t1.id
+        ) AS sumClaimMoney
+        FROM
+        sample t1
+        WHERE
+        t1.`status` >= 30
+        AND t1.`status` &lt; 88
+        ) AS t1
+        ) t1
+        ${ew.customSqlSegment}
     </select>
 
 </mapper>