Browse Source

利润预算表BUG修复

caozj 1 năm trước cách đây
mục cha
commit
d6f60e91bb

+ 10 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/contract/vo/ContractBudgetVo.java

@@ -125,6 +125,16 @@ public class ContractBudgetVo extends Contract {
     private BigDecimal ehsdSumAmount;
 
     /**
+     * 包材
+     */
+    private BigDecimal peritectoidAmount;
+
+    /**
+     * 辅材
+     */
+    private BigDecimal accessoriesAmount;
+
+    /**
      * 其他租户应付货款
      */
     private BigDecimal otherSumAmount;

+ 10 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/vo/EhsdPurchaseProductVo.java

@@ -42,4 +42,14 @@ public class EhsdPurchaseProductVo extends EhsdPurchaseProduct {
      * 待采购数量
      */
     private BigDecimal expendQuantity;
+
+    /**
+     * 分类ID
+     */
+    private Long productCategoryId;
+
+    /**
+     * 分类ID集合
+     */
+    private String productCategoryIds;
 }

+ 7 - 0
hx-sale/src/main/java/com/fjhx/sale/mapper/contract/ContractMapper.java

@@ -38,6 +38,13 @@ public interface ContractMapper extends BaseMapper<Contract> {
     Page<ContractBudgetVo> getProfitBudgetPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<Contract> wrapper);
 
     /**
+     * 利润预算表头部统计
+     * @param wrapper
+     * @return
+     */
+    List<ContractBudgetVo> getProfitBudgetHeadStatistic(@Param("ew") IWrapper<Contract> wrapper);
+
+    /**
      * 利润结算表
      */
     Page<ContractBudgetVo> getProfitClearingPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<Contract> wrapper);

+ 7 - 0
hx-sale/src/main/java/com/fjhx/sale/mapper/purchase/EhsdPurchaseProductMapper.java

@@ -35,6 +35,13 @@ public interface EhsdPurchaseProductMapper extends BaseMapper<EhsdPurchaseProduc
     List<EhsdPurchaseProductVo> getGroupSumAmount(List<Long> contractIds);
 
     /**
+     * 查询采购产品,通过数据来源ID
+     * @param contractIds
+     * @return
+     */
+    List<EhsdPurchaseProductVo> getPurchaseByContractId(List<Long> contractIds);
+
+    /**
      * 根据合同ID查询采购产品列表
      * @param contractId
      * @return

+ 7 - 0
hx-sale/src/main/java/com/fjhx/sale/service/contract/ContractService.java

@@ -48,6 +48,13 @@ public interface ContractService extends BaseService<Contract> {
     Page<ContractBudgetVo> getProfitBudgetPage(ContractSelectDto dto);
 
     /**
+     * 利润预算表头部统计
+     * @param dto
+     * @return
+     */
+    Map<String,Object> getProfitBudgetHeadStatistic(ContractSelectDto dto);
+
+    /**
      * 利润结算分页
      */
     Page<ContractBudgetVo> getProfitClearingPage(ContractSelectDto dto);

+ 127 - 37
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java

@@ -386,32 +386,40 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
             });
             //取出EHSD采购所有金额和货币-通过合同ID分组
             List<Long> contractIds = list.stream().map(ContractBudgetVo::getContractId).collect(Collectors.toList());
-            List<EhsdPurchaseProductVo> ehsdAmountList = ehsdPurchaseProductService.getGroupSumAmount(contractIds);
-            //取出采购所有金额和货币-通过合同ID分组
-            Map<Long, String> ehsdAmountMap = ehsdAmountList.stream().collect(Collectors.toMap(EhsdPurchaseProductVo::getContractId, EhsdPurchaseProductVo::getCurrencyAmount));
-            List<PurchaseDetailVo> otherAmountList = purchaseDetailService.getSumCountInDataResourceIds(contractIds);
-            Map<Long, String> otherAmountMap = otherAmountList.stream().collect(Collectors.toMap(PurchaseDetailVo::getDataResourceId, PurchaseDetailVo::getSumAmountCurrency));
-            //通过合同ID查询到退税数据
-            List<TaxRefundDetails> refundDetails = taxRefundDetailsService.getSumMoneyByContractIds(contractIds);
-            Map<Long, List<TaxRefundDetails>> refundDetailsMap = refundDetails.stream().collect(Collectors.groupingBy(TaxRefundDetails::getContractId));
-
-            //取出默认汇率
-//            List<CurrencyRate> currencyRateList = currencyRateService.getList();
-//            Map<String, BigDecimal> currencyRateMap = currencyRateList.stream().collect(Collectors.toMap(CurrencyRate::getType, CurrencyRate::getRate));
+            List<EhsdPurchaseProductVo> ehsdAmountList = ehsdPurchaseProductService.getPurchaseByContractId(contractIds);
+            Map<Long, List<EhsdPurchaseProductVo>> ehsdAmountMap = ehsdAmountList.stream().collect(Collectors.groupingBy(EhsdPurchaseProductVo::getDataResourceId));
             for (ContractBudgetVo v : list) {
+                BigDecimal purchaseAmount = BigDecimal.ZERO;
+                BigDecimal peritectoidAmount = BigDecimal.ZERO;
+                BigDecimal accessoriesAmount = BigDecimal.ZERO;
                 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));
-                    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 = map.getOrDefault(currency, BigDecimal.ONE);
-                            v.setEhsdSumAmount(amount.multiply(rate));
-                        } else {
-                            v.setEhsdSumAmount(BigDecimal.ZERO);
+                    /**
+                     * 处理应付款金额-包材金额-配件金额
+                     */
+                    List<EhsdPurchaseProductVo> pList = ehsdAmountMap.getOrDefault(v.getContractId(), null);
+                    if (CollectionUtils.isNotEmpty(pList)) {
+                        for(EhsdPurchaseProductVo e : pList){
+                            //获取汇率
+                            BigDecimal rate = map.getOrDefault(e.getCurrency(), BigDecimal.ONE);
+                            // 获取认领金额
+                            BigDecimal money = e.getAmount();
+                            //总金额
+                            BigDecimal amount = rate.multiply(money);
+                            purchaseAmount = purchaseAmount.add(amount);
+                            if(ObjectUtil.isNotEmpty(e.getProductCategoryIds())){
+                                if(e.getProductCategoryIds().contains("1685534140512616449")||e.getProductCategoryId()==1685534140512616449L){//包材
+                                    peritectoidAmount = peritectoidAmount.add(amount);
+                                }
+                                if(e.getProductCategoryIds().contains("1685534141821239297")||e.getProductCategoryId()==1685534141821239297L){//配件
+                                    accessoriesAmount = accessoriesAmount.add(amount);
+                                }
+                            }
                         }
+                        v.setEhsdSumAmount(purchaseAmount);
+                        v.setPeritectoidAmount(peritectoidAmount);
+                        v.setAccessoriesAmount(accessoriesAmount);
                     }
                     //计算支出总计 除合同金额(转人民币)+应退税金额(转人民币) 其他金额相加
                     v.setExpenditureAmount(v.getTrailerFee() == null ? BigDecimal.ZERO : v.getTrailerFee().multiply(new BigDecimal(map.getOrDefault(v.getTrailerFeeCurrency(), BigDecimal.ONE).toString())).add
@@ -429,16 +437,31 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
                     //计算收入总计=合同金额(转人民币)+应退税金额(转人民币)
                     v.setIncomeAmount(v.getAmount().multiply(new BigDecimal(map.getOrDefault(v.getCurrency(), BigDecimal.ONE).toString())).add(v.getRefundableAmount()));
                 } else {//没有汇率取默认汇率
-                    if (MapUtils.isNotEmpty(ehsdAmountMap)) {    //计算EHSD租户应付货款
-                        String concatAmountCurrency = ehsdAmountMap.getOrDefault(v.getContractId(), null);
-                        if (StringUtils.isNotEmpty(concatAmountCurrency)) {
-                            BigDecimal amount = new BigDecimal(concatAmountCurrency.split("-")[0]);
-                            String rate = concatAmountCurrency.split("-")[2];
-                            BigDecimal DecimalRate = new BigDecimal(rate);
-                            v.setEhsdSumAmount(amount.multiply(DecimalRate));
-                        } else {
-                            v.setEhsdSumAmount(BigDecimal.ZERO);
+                    /**
+                     * 处理应付款金额-包材金额-配件金额
+                     */
+                    List<EhsdPurchaseProductVo> pList = ehsdAmountMap.getOrDefault(v.getContractId(), null);
+                    if (CollectionUtils.isNotEmpty(pList)) {
+                        for(EhsdPurchaseProductVo e : pList){
+                            //获取汇率
+                            BigDecimal rate = e.getRate();
+                            // 获取认领金额
+                            BigDecimal money = e.getAmount();
+                            //总金额
+                            BigDecimal amount = rate.multiply(money);
+                            purchaseAmount = purchaseAmount.add(amount);
+                            if(ObjectUtil.isNotEmpty(e.getProductCategoryIds())){
+                                if(e.getProductCategoryIds().contains("1685534140512616449")||e.getProductCategoryId()==1685534140512616449L){//包材
+                                    peritectoidAmount = peritectoidAmount.add(amount);
+                                }
+                                if(e.getProductCategoryIds().contains("1685534141821239297")||e.getProductCategoryId()==1685534141821239297L){//配件
+                                    accessoriesAmount = accessoriesAmount.add(amount);
+                                }
+                            }
                         }
+                        v.setEhsdSumAmount(purchaseAmount);
+                        v.setPeritectoidAmount(peritectoidAmount);
+                        v.setAccessoriesAmount(accessoriesAmount);
                     }
                     BigDecimal rate = v.getRate();
 
@@ -469,6 +492,70 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
     }
 
     /**
+     * 利润预算表头部统计
+     * @param dto
+     * @return
+     */
+    @Override
+    public Map<String, Object> getProfitBudgetHeadStatistic(ContractSelectDto dto) {
+        IWrapper<Contract> wrapper = getWrapper();
+        wrapper.orderByDesc("t1", Contract::getCreateTime);
+        wrapper.eq("t1", Contract::getIsChange, "0");//列表只展示未变更得数据
+        wrapper.ne("t1", Contract::getIsShow, 1);
+        wrapper.between("t1", Contract::getStatus, FlowStatusEnum1.PASS.getKey(), FlowStatusEnum1.CANCELLATION.getKey() - 1);
+        if (StringUtils.isNotEmpty(dto.getCustomerId())) {
+            wrapper.eq("t1", Contract::getBuyCorporationId, dto.getCustomerId());
+        }
+        if (StringUtils.isNotEmpty(dto.getUserId())) {
+            wrapper.eq("t1", Contract::getCreateUser, dto.getUserId());
+        }
+        if (StringUtils.isNotEmpty(dto.getKeyword())) {
+            wrapper.keyword(dto.getKeyword(), new SqlField("t1.code"));
+        }
+        List<ContractBudgetVo> list = this.baseMapper.getProfitBudgetHeadStatistic(wrapper);
+        List<Long> contractIds = list.stream().map(ContractBudgetVo::getContractId).collect(Collectors.toList());
+        if (CollectionUtils.isNotEmpty(list)) {
+
+            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));
+                    BigDecimal rate = map.getOrDefault(v.getCurrency(),BigDecimal.ONE);
+                } else {//没有汇率取默认汇率
+                    BigDecimal rate = v.getRate();
+                    v.setRmbContractAmount(v.getAmount().multiply(rate));
+                }
+            }
+        }
+        //统计金额
+        return sumStatistic(list);
+    }
+
+    /**
+     * 统计金额
+     * @return
+     */
+    private Map<String,Object> sumStatistic(List<ContractBudgetVo> list){
+        Map<String,Object> map = new HashMap<>();
+        map.put("contractAmount",BigDecimal.ZERO);
+        map.put("purchaseAmount",BigDecimal.ZERO);
+        map.put("contractAmount",BigDecimal.ZERO);
+        map.put("contractAmount",BigDecimal.ZERO);
+        map.put("contractAmount",BigDecimal.ZERO);
+        map.put("contractAmount",BigDecimal.ZERO);
+        map.put("contractAmount",BigDecimal.ZERO);
+        map.put("contractAmount",BigDecimal.ZERO);
+        map.put("contractAmount",BigDecimal.ZERO);
+        map.put("contractAmount",BigDecimal.ZERO);
+        map.put("contractAmount",BigDecimal.ZERO);
+        map.put("contractAmount",BigDecimal.ZERO);
+        map.put("contractAmount",BigDecimal.ZERO);
+        map.put("contractAmount",BigDecimal.ZERO);
+        map.put("contractAmount",BigDecimal.ZERO);
+        map.put("contractAmount",BigDecimal.ZERO);
+        return map;
+    }
+    /**
      * 利润结算表分页
      *
      * @param dto
@@ -1866,14 +1953,17 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
      */
     @Override
     public Page<ContractVo> getExportCopyList(ContractSelectDto dto) {
-        List<Long> authIdList = customerService.getAuthIdList();
-
-        if (authIdList.size() == 0) {
-            return new Page<>();
-        }
-
         IWrapper<Contract> wrapper = getWrapper();
-        wrapper.in("t1", Contract::getBuyCorporationId, authIdList);
+        SysUser sysUser = UserUtil.getUserInfo();
+        if (StringUtils.isEmpty(sysUser.getUserCode())) {//不是业务员看所有
+            return pageCommon(dto, wrapper);
+        } else {//是业务员
+            List<Long> authIdList = customerService.getAuthIdList();
+            if (authIdList.size() == 0) {
+                return new Page<>();
+            }
+            wrapper.in("t1", Contract::getBuyCorporationId, authIdList);
+        }
         wrapper.orderByDesc("t1", Contract::getCreateTime);
         wrapper.eq("t1", Contract::getIsChange, "0");//列表只展示未变更得数据
         wrapper.ne("t1", Contract::getIsShow, 1);

+ 7 - 0
hx-sale/src/main/java/com/fjhx/sale/service/purchase/EhsdPurchaseProductService.java

@@ -55,6 +55,13 @@ public interface EhsdPurchaseProductService extends BaseService<EhsdPurchaseProd
     List<EhsdPurchaseProductVo> getGroupSumAmount(List<Long> contractIds);
 
     /**
+     * 查询采购产品,通过数据来源ID
+     * @param contractIds
+     * @return
+     */
+    List<EhsdPurchaseProductVo> getPurchaseByContractId(List<Long> contractIds);
+
+    /**
      * 根据合同ID查询采购产品列表
      * @param contractId
      * @return

+ 30 - 0
hx-sale/src/main/java/com/fjhx/sale/service/purchase/impl/EhsdPurchaseProductServiceImpl.java

@@ -3,6 +3,10 @@ package com.fjhx.sale.service.purchase.impl;
 import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fjhx.item.service.product.ProductClassifyService;
+import com.fjhx.item.service.product.ProductInfoService;
+import com.fjhx.purchase.entity.arrival.po.ArrivalDetail;
+import com.fjhx.purchase.entity.arrival.vo.ArrivalDetailVo;
 import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseProductDto;
 import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseProductSelectDto;
 import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
@@ -10,6 +14,7 @@ import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo;
 import com.fjhx.sale.mapper.purchase.EhsdPurchaseProductMapper;
 import com.fjhx.sale.service.purchase.EhsdPurchaseProductService;
 import com.ruoyi.common.utils.wrapper.IWrapper;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
@@ -26,6 +31,12 @@ import java.util.List;
 @Service
 public class EhsdPurchaseProductServiceImpl extends ServiceImpl<EhsdPurchaseProductMapper, EhsdPurchaseProduct> implements EhsdPurchaseProductService {
 
+    @Autowired
+    private ProductInfoService productInfoService;
+
+    @Autowired
+    private ProductClassifyService productClassifyService;
+
     @Override
     public Page<EhsdPurchaseProductVo> getPage(EhsdPurchaseProductSelectDto dto) {
         IWrapper<EhsdPurchaseProduct> wrapper = getWrapper();
@@ -67,6 +78,25 @@ public class EhsdPurchaseProductServiceImpl extends ServiceImpl<EhsdPurchaseProd
     }
 
     /**
+     * 查询采购产品总,通过数据来源ID
+     * @param contractIds
+     * @return
+     */
+    @Override
+    public List<EhsdPurchaseProductVo> getPurchaseByContractId(List<Long> contractIds) {
+        List<EhsdPurchaseProductVo> list = baseMapper.getPurchaseByContractId(contractIds);
+        // 赋值产品属性
+        productInfoService.attributeAssign(list, EhsdPurchaseProductVo::getProductId, (item, product) -> {
+            item.setProductCategoryId(product.getProductClassifyId());
+        });
+        // 赋值产品分类名称
+        productClassifyService.attributeAssign(list, EhsdPurchaseProductVo::getProductCategoryId, (item, productClassify) -> {
+            item.setProductCategoryIds(productClassify.getParentIdSet());
+        });
+        return list;
+    }
+
+    /**
      * 根据合同ID查询采购产品列表
      * @param contractId
      * @return

+ 17 - 0
hx-sale/src/main/resources/mapper/contract/ContractMapper.xml

@@ -49,6 +49,23 @@
         ${ew.customSqlSegment}
     </select>
 
+    <select id="getProfitBudgetHeadStatistic" resultType="com.fjhx.sale.entity.contract.vo.ContractBudgetVo">
+        SELECT
+            t1.id                                                                     AS contractId,
+            t1.`code`,
+            t1.buy_corporation_id ,
+            t1.user_name,
+            t1.amount,
+            t1.currency,
+            t1.currency_rate_json,
+            t1.rate AS rate,
+            t2.*
+        FROM
+            contract t1
+        LEFT JOIN contract_budget t2 ON t1.id = t2.contract_id
+            ${ew.customSqlSegment}
+    </select>
+
     <select id="getNoPackContractByCustomerId" resultType="com.fjhx.sale.entity.contract.vo.ContractVo">
         SELECT
             *

+ 18 - 0
hx-sale/src/main/resources/mapper/purchase/EhsdPurchaseProductMapper.xml

@@ -47,6 +47,24 @@
         GROUP BY t1.contract_id
     </select>
 
+    <select id="getPurchaseByContractId" resultType="com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo">
+        SELECT
+            t2.data_resource_id,
+            IFNULL(t2.amount,0) AS amount ,
+            t2.currency,
+            IFNULL(t2.rate,0) AS rate,
+            t1.product_id
+        FROM
+            ehsd_purchase_product t1
+                LEFT JOIN ehsd_purchase t2 ON t1.purchase_id = t2.id
+        WHERE
+            t2.`status` IN ( 10, 30 )
+        <if test="contractIds neq null and contractIds.size() > 0">
+            <foreach collection="contractIds" item="contractId" open="AND t2.data_resource_id IN (" separator="," close=")">
+                #{contractId}
+            </foreach>
+        </if>
+    </select>
     <select id="getListByContractId" resultType="com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo">
         SELECT
             t1.*,