liuyao 1 жил өмнө
parent
commit
c1af2a3943

+ 10 - 0
src/main/java/com/dk/mdm/controller/report/ReportController.java

@@ -277,6 +277,16 @@ public class ReportController  {
         return reportService.getMacPayCurrentItemReport(param);
     }
 
+    /**
+     * @desc   : 客户收支表查询
+     * @author : 刘尧
+     * @date   : 2024/6/5 13:17
+     */
+    @PostMapping("get_cus_rec_pay_report_item")
+    public ResponseResultVO<List<Map<String, Object>>> getCusRecPayReportItem(@RequestBody Map<String, Object> params) {
+        return reportService.getCusRecPayReportItem(params);
+    }
+
 }
 
 

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

@@ -258,4 +258,18 @@ public interface ReportMapper extends BaseMapper<JSONObject> {
      * @date   : 2024/5/10 10:37
      */
     List<Map<String, Object>> getMacPayCurrentItemReport(Map param);
+
+    /**
+     * @desc   : 根据用户信息和筛选信息查询账款明细
+     * @author : 刘尧
+     * @date   : 2024/6/5 17:25
+     * */
+    List<Map<String, Object>> getCusRecPayReportItemByUser(Map params);
+
+    /**
+     * @desc   : 查询用户欠款
+     * @author : 刘尧
+     * @date   : 2024/6/5 17:28
+     * */
+    List<Map<String, Object>> getUserArrears(Map params);
 }

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

@@ -1644,8 +1644,7 @@
     </select>
 
     <select id="getSalesTrackingReportDetail"  resultType="java.util.Map">
-        SELECT T
-                   ."id",
+        SELECT T."id",
                T."no",
                T."itemId",
                T."type",
@@ -2933,5 +2932,89 @@
         select dkic_b.f_query_mac_pay_current_item(#{cpId},#{objectId} ::uuid,#{orgId} ::uuid,#{macType},#{accDateStart} ::date
                    ,#{accDateEnd} ::date,#{i18n} ,#{currentPage},#{pageSize})
     </select>
+    <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(tmrp.sum_amt_rec), 0) as "sumAmtRec"
+        , a.acc_date as "accDate"
+        FROM
+            dkic_b.t_mac_account_item a
+                LEFT JOIN dkic_b.t_psi_outbound tpo ON tpo.out_id = a.biznis_id
+                LEFT JOIN dkic_b.t_mac_rec_pay tmrp ON tmrp.rp_id = a.biznis_id
+        WHERE a.flg_valid
+        <if test="objectId != null and objectId != ''">
+            AND a.object_id = #{objectId}::uuid
+        </if>
+        <if test="staffId != null and staffId != ''">
+            AND a.staff_id = #{staffId}::uuid
+        </if>
+        <if test="orgId != null and orgId != ''">
+            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="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="recTypeIds != null and recTypeIds.size() > 0">
+            <foreach collection="recTypeIds" item="item">
+                <if test="item != null and item != '' and item == '收支类型-出库'">
+                    AND tpo.out_amt &gt; 0
+                </if>
+                <if test="item != null and item != '' and item == '收支类型-退货'">
+                    AND tpo.out_amt &lt; 0
+                </if>
+                <if test="item != null and item != '' and item == '收支类型-收款'">
+                    AND tmrp.sum_amt_rec &gt; 0
+                </if>
+                <if test="item != null and item != '' and item == '收支类型-退款'">
+                    AND tmrp.sum_amt_rec &lt; 0
+                </if>
+            </foreach>
+        </if>
+        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"
+        , tmc.cus_phone as "cusPhone"
+        , SUM(COALESCE(tpo.out_amt, 0) + COALESCE(tpo.return_amt, 0)) - SUM(COALESCE(tmrp.sum_amt_rec, 0)) as arrears
+        FROM
+        dkic_b.t_mac_account_item a
+        LEFT JOIN dkic_b.t_psi_outbound tpo ON tpo.out_id = a.biznis_id
+        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
+        WHERE a.flg_valid
+        AND tmc.cus_name IS NOT NULL AND tmc.cus_name != ''
+        GROUP BY a.object_id, tmc.cus_name, tmc.cus_phone, tmc.address_full
+        HAVING SUM(COALESCE(tpo.out_amt, 0) + COALESCE(tpo.return_amt, 0)) - SUM(COALESCE(tmrp.sum_amt_rec, 0)) > 0
+        <if test="objectId != null">
+            AND a.object_id = #{objectId}::uuid
+        </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="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
+            LIMIT #{pageSize} OFFSET #{currentPage}
+        </if>
+    </select>
 
 </mapper>

+ 5 - 0
src/main/java/com/dk/mdm/service/common/CommonService.java

@@ -800,6 +800,11 @@ public class CommonService extends BaseService<Map<String, Object>> {
             map.put("kindType", "初始款项");
             list = commonMapper.getDataKind(map);
         }
+        // 收支类型
+        if (dataSourceCode.equals("recType")) {
+            map.put("kindType", "收支类型");
+            list = commonMapper.getDataKind(map);
+        }
 
         return ResponseResultUtil.success(list);
     }

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

@@ -1,22 +1,14 @@
 package com.dk.mdm.service.report;
 
 import com.alibaba.fastjson.JSONObject;
-import com.dk.common.infrastructure.constant.Constant;
-import com.dk.common.infrastructure.enums.ErrorCodeEnum;
-import com.dk.common.mapper.BaseMapper;
 import com.dk.common.model.pojo.PageList;
 import com.dk.common.response.ResponseCodeEnum;
 import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultVO;
-import com.dk.common.service.BaseService;
-import com.dk.mdm.infrastructure.util.AuthUtils;
-import com.dk.mdm.mapper.common.CommonMapper;
 import com.dk.mdm.mapper.ivt.InboundItemMapper;
 import com.dk.mdm.mapper.ivt.OutboundItemMapper;
-import com.dk.mdm.mapper.mst.StaffMapper;
 import com.dk.mdm.mapper.report.ReportMapper;
 import lombok.extern.slf4j.Slf4j;
-import org.postgresql.util.PGobject;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -24,6 +16,8 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
 
 /**
  * @desc   : 报表数据源
@@ -623,5 +617,43 @@ public class ReportService {
         }
     }
 
+    /**
+     * @desc   : 客户收支表查询
+     * @author : 刘尧
+     * @date   : 2024/6/6 14:27
+     */
+    public ResponseResultVO<List<Map<String, Object>>> getCusRecPayReportItem(Map<String, Object> params) {
+        List<Map<String, Object>> items = reportMapper.getCusRecPayReportItemByUser(params);
+        List<Map<String, Object>> arrears = reportMapper.getUserArrears(params);
+        // 判断类型
+        for (Map<String, Object> item : items) {
+            if (Double.valueOf(String.valueOf(item.get("outAmt")).equals("null") ? "0": String.valueOf(item.get("outAmt"))) > 0) {
+                item.put("type", "销售出库");
+            } else if (Double.valueOf(String.valueOf(item.get("outAmt")).equals("null") ? "0": String.valueOf(item.get("outAmt"))) < 0) {
+                item.put("type", "销售退货");
+            } else if (Double.valueOf(String.valueOf(item.get("sumAmtRec")).equals("null") ? "0": String.valueOf(item.get("sumAmtRec"))) > 0) {
+                item.put("type", "客户收款");
+            } else if (Double.valueOf(String.valueOf(item.get("sumAmtRec")).equals("null") ? "0": String.valueOf(item.get("sumAmtRec"))) < 0) {
+                item.put("type", "客户退款");
+            }
+        }
+        for (Map<String, Object> map : arrears) {
+            // 筛选出符合条件的明细
+            List<Map<String, Object>> userArrearsItem = items.stream()
+                                                        .filter(item -> item.get("objectId").equals(map.get("objectId")))
+                                                        .filter(item -> (Double.valueOf(String.valueOf(item.get("outAmt")).equals("null") ? "0" : String.valueOf(item.get("outAmt"))) != 0
+                                                                || Double.valueOf(String.valueOf(item.get("sumAmtRec")).equals("null") ? "0" : String.valueOf(item.get("sumAmtRec"))) != 0))
+                                                        .collect(Collectors.toList());
+            AtomicReference<Double> total = new AtomicReference<>(0.00);
+            // 计算单用户的总计
+            userArrearsItem.forEach(item -> {
+                total.updateAndGet(v -> v + 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("totalMoney", total);
+        }
 
+        return ResponseResultUtil.success(arrears);
+    }
 }