Ver código fonte

客户收支表内容异常修复

liuyao 1 ano atrás
pai
commit
41b3b9f1ca

+ 2 - 0
src/main/java/com/dk/mdm/mapper/report/ReportMapper.java

@@ -361,4 +361,6 @@ public interface ReportMapper extends BaseMapper<JSONObject> {
      * @date   : 2024-07-04 11:34
      */
     Map<String, Object> getOrderSummaryItem(Map param);
+
+    List<Map<String, Object>> getOutboundAmtByUser(Map<String, Object> params);
 }

+ 28 - 79
src/main/java/com/dk/mdm/mapper/report/ReportMapper.xml

@@ -2993,82 +2993,16 @@
     <!--  根据用户信息和筛选信息查询账款明细  -->
     <select id="getCusRecPayReportItemByUser" resultType="java.util.Map">
         SELECT a.object_id as "objectId"
-        , a.biznis_no as "biznisNo"
-        , COALESCE(SUM(tpo.out_amt), 0) as "outAmt"
-        , COALESCE(SUM(tpo.return_amt), 0) as "returnAmt"
-        , COALESCE(SUM(a.amt_rec), 0) as "sumAmtRec"
-        , COALESCE(SUM(tmrp.sum_amt_pay), 0) as "sumAmtPay"
-        , COALESCE(SUM(a.amt_handle), 0) as "amtHandle"
-        , a.acc_date as "accDate"
+             , COALESCE(SUM(a.amt_rec), 0) as "sumAmtRec"
         FROM
-            dkic_b.t_psi_order tpio
-            LEFT JOIN dkic_b.t_mac_account_item a ON a.object_id = tpio.cus_id
-            LEFT JOIN dkic_b.t_psi_outbound tpo ON tpo.out_id = a.biznis_id and tpo.out_type = '出库类型-销退回库'
-            LEFT JOIN dkic_b.t_mac_rec_pay tmrp ON tmrp.rp_id = a.biznis_id
-            LEFT JOIN dkic_b.t_mst_customer tmc ON tmc.cus_id = a.object_id
-            LEFT JOIN dkic_b.t_mac_rec_pay_item tmrpi ON tmrpi.rp_id = tmrp.rp_id
-            <if test="moneyAccountList != null and moneyAccountList.size() > 0">
-               LEFT JOIN dkic_b.t_mst_money_account tmma ON tmma.mac_id = tmrpi.mac_id
-            </if>
+            dkic_b.t_mac_account_item a
         WHERE a.flg_valid
-        AND a.cp_id = #{cpId}
-        <if test="objectId != null">
-            AND a.object_id = #{objectId}::uuid
-        </if>
-        <if test="staffId != null">
-            AND a.staff_id = #{staffId}::uuid
-        </if>
-        <if test="orgId != null">
-            AND a.org_id = #{orgId}::uuid
-        </if>
-        <if test="makeTimeStart != null and makeTi8meStart != ''">
-            AND a.acc_date &gt;= #{makeTimeStart}::timestamp with time zone
-        </if>
-        <if test="makeTimeEnd != null and makeTimeEnd != ''">
-            AND a.acc_date &lt;= #{makeTimeStart}::timestamp with time zone
-        </if>
-        <if test="staffIds != null and staffIds.size() > 0">
-            AND a.staff_id IN
-            <foreach collection="staffIds" index="index" item="item" separator="," open="(" close=")">
-                #{item}::uuid
-            </foreach>
-        </if>
-        <if test="searchText != null and searchText != ''">
-            AND (tmc.cus_name LIKE concat('%',#{searchText},'%')
-            OR tmc.cus_phone LIKE concat('%',#{searchText},'%')
-            OR tmc.address_full LIKE concat('%',#{searchText},'%'))
-        </if>
-        <if test="orgIds != null and orgIds.size() > 0">
-            AND a.org_id IN
-            <foreach collection="orgIds" index="index" item="item" separator="," open="(" close=")">
-                #{item}::uuid
-            </foreach>
-        </if>
-        <if test="recTypeList != null and recTypeList.size() > 0">
-            <foreach collection="recTypeList" item="item">
-                <if test="item != null and item != '' and item == '收支类型-退货'">
-                    AND tpo.out_amt &lt; 0
-                </if>
-                <if test="item != null and item != '' and item == '收支类型-收款'">
-                    AND a.amt_rec &gt; 0
-                </if>
-                <if test="item != null and item != '' and item == '收支类型-退款'">
-                    AND a.amt_rec &lt; 0
-                </if>
-            </foreach>
-        </if>
-        <if test="moneyAccountList != null and moneyAccountList.size() > 0">
-            AND
-            <foreach collection="moneyAccountList" item="item" separator="OR" open="(" close=")">
-                <if test="item != null and item != ''">
-                    tmma.mac_code = #{item}
-                </if>
-            </foreach>
-        </if>
+          AND a.cp_id = #{cpId}
+          AND a.object_id = #{objectId}::uuid
         group by a.object_id, a.biznis_no, a.acc_date, a.staff_id
     </select>
 
-    <!--  查询用户欠款  -->
+    <!--  查询欠款用户信息  -->
     <select id="getUserArrears" resultType="java.util.Map">
         SELECT a.object_id as "objectId"
         , tmc.cus_name as "cusName"
@@ -3102,8 +3036,6 @@
     <select id="getPsiOrderCount" resultType="java.util.Map">
         SELECT
         tpo.cus_id as "objectId"
-        , tpo.order_no as "biznisNo"
-        , tpo.make_time as "accDate"
         , COALESCE(SUM(tpo.fact_amt), 0) as "facAmt"
         FROM dkic_b.t_psi_order tpo
         WHERE tpo.flg_valid
@@ -3126,6 +3058,20 @@
         group by tpo.cus_id, tpo.make_time, tpo.fact_amt, tpo.order_no
     </select>
 
+    <select id="getOutboundAmtByUser" resultType="java.util.Map">
+        select
+            tpo.cus_id as "objectId"
+            ,COALESCE(SUM(tpo.out_amt), 0) as "outAmt"
+        from dkic_b.t_psi_outbound tpo
+        where tpo.flg_valid
+        and tpo.out_type = '出库类型-销退回库'
+        AND tpo.cp_id = #{cpId}
+        <if test="objectId != null">
+            AND tpo.cus_id = #{objectId}::uuid
+        </if>
+        group by tpo.cus_id, tpo.out_amt
+    </select>
+
     <select id="getPsiOrderByUser" resultType="java.util.Map">
         SELECT
             tpo.cus_id as "objectId"
@@ -3150,12 +3096,6 @@
                 #{item}::uuid
             </foreach>
         </if>
-        <!--  改好再说  -->
-<!--        <if test="searchText != null and searchText != ''">-->
-<!--            AND (tmc.cus_name LIKE concat('%',#{searchText},'%')-->
-<!--            OR tmc.cus_phone LIKE concat('%',#{searchText},'%')-->
-<!--            OR tmc.address_full LIKE concat('%',#{searchText},'%'))-->
-<!--        </if>-->
         <if test="orgIds != null and orgIds.size() > 0">
             AND tpo.org_id IN
             <foreach collection="orgIds" index="index" item="item" separator="," open="(" close=")">
@@ -3169,12 +3109,18 @@
     <select id="getOrderAmt" resultType="java.util.Map">
         select COALESCE(SUM(tpio.fact_amt), 0) as "orderAmt" from dkic_b.t_psi_order tpio where tpio.flg_valid
         AND tpio.cp_id = #{cpId}
+        <if test="objectId != null">
+            AND tpio.cus_id = #{objectId}::uuid
+        </if>
         AND tpio.make_time::date &lt;= CURRENT_DATE
     </select>
     <!--获取退货额-->
     <select id="getOutboundAmt" resultType="java.util.Map">
         select COALESCE(SUM(tpo.out_amt), 0) as "outboundAmt" from dkic_b.t_psi_outbound tpo where tpo.flg_valid and tpo.out_type = '出库类型-销退回库'
       AND tpo.cp_id = #{cpId}
+        <if test="objectId != null">
+            AND tpo.cus_id = #{objectId}::uuid
+        </if>
       AND tpo.make_time::date &lt;= CURRENT_DATE
     </select>
     <!--获取收支额-->
@@ -3186,6 +3132,9 @@
         WHERE a.flg_valid
         AND a.cp_id = #{cpId}
         AND tmc.cus_name IS NOT NULL AND tmc.cus_name != ''
+            <if test="objectId != null">
+                AND tmc.cus_id = #{objectId}::uuid
+            </if>
         AND a.make_time::date &lt;= CURRENT_DATE
     </select>
     <!--获取欠款额-->

+ 16 - 8
src/main/java/com/dk/mdm/service/report/ReportService.java

@@ -815,8 +815,20 @@ public class ReportService {
         List<Map<String, Object>> arrears = reportMapper.getUserArrears(params);
         for (Map<String, Object> map : arrears) {
             params.put("objectId", map.get("objectId"));
+            Map<String, Object> orderAmt = reportMapper.getOrderAmt(params);
+            Map<String, Object> outBoundAmt = reportMapper.getOutboundAmt(params);
+            Map<String, Object> sales = new HashMap<>();
+            sales.put("facAmt", Double.valueOf(String.valueOf(orderAmt.get("orderAmt")).equals("null") ? "0" : String.valueOf(orderAmt.get("orderAmt")))
+                    + Double.valueOf(String.valueOf(outBoundAmt.get("outboundAmt")).equals("null") ? "0" : String.valueOf(outBoundAmt.get("outboundAmt"))));
+            // 获取收支额
+            Map<String, Object> incomeExpenditure = reportMapper.getIncomeExpenditure(params);
+            map.put("arrears", Double.valueOf(String.valueOf(sales.get("facAmt")).equals("null") ? "0" : String.valueOf(sales.get("facAmt")))
+                    - Double.valueOf(String.valueOf(incomeExpenditure.get("arrears")).equals("null") ? "0" : String.valueOf(incomeExpenditure.get("arrears"))));
+/*            params.put("objectId", map.get("objectId"));
             List<Map<String, Object>> items = reportMapper.getCusRecPayReportItemByUser(params);
             List<Map<String, Object>> psiOrderByUser = reportMapper.getPsiOrderByUser(params);
+            List<Map<String, Object>> outAmtByUser = reportMapper.getOutboundAmtByUser(params);
+            items.addAll(outAmtByUser);
             items.addAll(psiOrderByUser);
             // 筛选出符合条件的明细
             List<Map<String, Object>> userArrearsItem = items.stream()
@@ -833,8 +845,7 @@ public class ReportService {
                         + Double.valueOf(String.valueOf(item.get("outAmt")).equals("null") ? "0" : String.valueOf(item.get("outAmt")))
                         - Double.valueOf(String.valueOf(item.get("sumAmtRec")).equals("null") ? "0" : String.valueOf(item.get("sumAmtRec"))));
             });
-//            map.put("item", userArrearsItem);
-            map.put("arrears", total);
+            map.put("arrears", total);*/
         }
         switch (String.valueOf(params.get("sort"))) {
             case "order":
@@ -852,6 +863,7 @@ public class ReportService {
         if (Integer.parseInt(params.get("currentPage").toString()) == 1) {
             // 查询公司概况
             // 获取销售额
+            params.put("objectId", null);
             Map<String, Object> orderAmt = reportMapper.getOrderAmt(params);
             Map<String, Object> outBoundAmt = reportMapper.getOutboundAmt(params);
             Map<String, Object> sales = new HashMap<>();
@@ -859,13 +871,9 @@ public class ReportService {
                     + Double.valueOf(String.valueOf(outBoundAmt.get("outboundAmt")).equals("null") ? "0" : String.valueOf(outBoundAmt.get("outboundAmt"))));
             // 获取收支额
             Map<String, Object> incomeExpenditure = reportMapper.getIncomeExpenditure(params);
-            // 获取欠款额
-            //  Map<String, Object> debt = reportMapper.getDebt(params);
             Map<String, Object> debt = new HashMap<>();
-            if (debt != null) {
-                debt.put("outAmt", Double.valueOf(String.valueOf(sales.get("facAmt")).equals("null") ? "0" : String.valueOf(sales.get("facAmt")))
-                        - Double.valueOf(String.valueOf(incomeExpenditure.get("arrears")).equals("null") ? "0" : String.valueOf(incomeExpenditure.get("arrears"))));
-            }
+            debt.put("outAmt", Double.valueOf(String.valueOf(sales.get("facAmt")).equals("null") ? "0" : String.valueOf(sales.get("facAmt")))
+                    - Double.valueOf(String.valueOf(incomeExpenditure.get("arrears")).equals("null") ? "0" : String.valueOf(incomeExpenditure.get("arrears"))));
             List<Map<String, Object>> overviewList = new ArrayList<>();
             overviewList.add(sales);
             overviewList.add(incomeExpenditure);