hongxudong 1 год назад
Родитель
Сommit
e369b517ae
1 измененных файлов с 30 добавлено и 32 удалено
  1. 30 32
      src/main/java/com/dk/mdm/mapper/report/ReportMapper.xml

+ 30 - 32
src/main/java/com/dk/mdm/mapper/report/ReportMapper.xml

@@ -3064,6 +3064,9 @@
     </select>
 
     <!--region 销售利润-->
+    <!--
+    2024-06-24 11:25 成本和销售额都从出库明细中取
+    -->
 
     <select id="getSaleProfit" resultType="java.util.Map">
         select
@@ -3073,16 +3076,14 @@
         from (
         select
         <include refid="getSaleProfitInOutBound"/>
-        from dkic_b.t_psi_in_out_record tpr
+        from dkic_b.t_psi_outbound_item tpoi
         <if test="orgIds!=null and orgIds.size()>0">
-            left join dkic_b.t_psi_inbound tpi on tpi.into_id = biznis_id
-            left join dkic_b.t_psi_outbound tpo on tpo.out_id = biznis_id
+            left join dkic_b.t_psi_outbound tpo on tpo.out_id = tpoi.out_id
         </if>
         <include refid="getSaleProfitCond"/>
         <if test="orgIds!=null and orgIds.size()>0">
             and (
-            (tpo.org_id = any(#{orgIds, typeHandler=UuidListTypeHanlder}) and tpi.org_id is null)
-            or (tpi.org_id = any(#{orgIds, typeHandler=UuidListTypeHanlder}) and tpo.org_id is null)
+            tpo.org_id = any(#{orgIds, typeHandler=com.dk.common.infrastructure.handler.UuidListTypeHandler})
             )
         </if>
         ) t
@@ -3094,28 +3095,28 @@
         <include refid="getSaleProfitRate"/>
         from (select
         <if test="byDate==null or (byDate!=null and byDate=='false')">
-            to_char(acc_date, 'yyyy-mm') acc_date,
+            to_char(tpoi.op_create_time, 'yyyy-mm') acc_date,
         </if>
         <if test="byDate!=null and byDate=='true'">
-            to_char(acc_date, 'mm-dd') acc_date,
+            to_char(tpoi.op_create_time, 'mm-dd') acc_date,
         </if>
         <include refid="getSaleProfitInOutBound"/>
-        from dkic_b.t_psi_in_out_record tpr
-        where tpr.cp_id = #{cpId}
-        AND tpr.op_create_time >= now() - interval
+        from dkic_b.t_psi_outbound_item tpoi
+        where tpoi.cp_id = #{cpId} and tpoi.out_status = '出库状态-已出库'
+        AND tpoi.op_create_time >= now() - interval
         <if test="byDate==null or (byDate!=null and byDate=='false')">
             '1 year'
         </if>
         <if test="byDate!=null and byDate=='true'">
             '1 month'
         </if>
-        AND tpr.op_create_time &lt; now()
+        AND tpoi.op_create_time &lt; now()
         group by
         <if test="byDate==null or (byDate!=null and byDate=='false')">
-            to_char(acc_date, 'yyyy-mm')
+            to_char(tpoi.op_create_time, 'yyyy-mm')
         </if>
         <if test="byDate!=null and byDate=='true'">
-            to_char(acc_date, 'mm-dd')
+            to_char(tpoi.op_create_time, 'mm-dd')
         </if>
         ) t
         order by t.acc_date
@@ -3127,13 +3128,12 @@
         select t.org_id,
         t.outbound - t.inbound "profit",
         <include refid="getSaleProfitRate"/>
-        from (select coalesce(tpi.org_id, tpo.org_id) org_id,
+        from (select tpo.org_id org_id,
         <include refid="getSaleProfitInOutBound"/>
-        from dkic_b.t_psi_in_out_record tpr
-        left join dkic_b.t_psi_inbound tpi on tpi.into_id = biznis_id
-        left join dkic_b.t_psi_outbound tpo on tpo.out_id = biznis_id
+        from dkic_b.t_psi_outbound_item tpoi
+        left join dkic_b.t_psi_outbound tpo on tpo.out_id = tpoi.out_id
         <include refid="getSaleProfitCond"/>
-        group by coalesce(tpi.org_id, tpo.org_id)) t
+        group by tpo.org_id) t
         ) tt
         left join dkic_b.t_mst_org tmo on tmo.org_id = tt.org_id
         <include refid="getSaleProfitLimit"/>
@@ -3145,33 +3145,31 @@
         select t.staff_id,
         t.outbound - t.inbound "profit",
         <include refid="getSaleProfitRate"/>
-        from (select coalesce(tpi.staff_id, tpo.staff_id) staff_id,
+        from (select tpo.staff_id staff_id,
         <include refid="getSaleProfitInOutBound"/>
-        from dkic_b.t_psi_in_out_record tpr
-        left join dkic_b.t_psi_inbound tpi on tpi.into_id = biznis_id
-        left join dkic_b.t_psi_outbound tpo on tpo.out_id = biznis_id
+        from dkic_b.t_psi_outbound_item tpoi
+        left join dkic_b.t_psi_outbound tpo on tpo.out_id = tpoi.out_id
         <include refid="getSaleProfitCond"/>
         <if test="orgIds!=null and orgIds.size()>0">
             and (
-            (tpo.org_id = any(#{orgIds, typeHandler=UuidListTypeHanlder}) and tpi.org_id is null)
-            or (tpi.org_id = any(#{orgIds, typeHandler=UuidListTypeHanlder}) and tpo.org_id is null)
+            tpo.org_id = any(#{orgIds, typeHandler=com.dk.common.infrastructure.handler.UuidListTypeHandler})
             )
         </if>
-        group by coalesce(tpi.staff_id, tpo.staff_id)) t
+        group by tpo.staff_id) t
         ) tt
         left join dkic_b.t_mst_staff tms on tms.staff_id = tt.staff_id
         <include refid="getSaleProfitLimit"/>
     </select>
 
     <select id="getSaleProfitGroupBySku" resultType="java.util.Map">
-        select tmgs.sku_name "skuName", tt.profit, tt."profitRate"
+        select tmgs.sku_model || coalesce('(' || tmgs.sku_name || ')', '') "skuName", tt.profit, tt."profitRate"
         from (
         select t.sku_id,
         t.outbound - t.inbound "profit",
         <include refid="getSaleProfitRate"/>
         from (select sku_id sku_id,
         <include refid="getSaleProfitInOutBound"/>
-        from dkic_b.t_psi_in_out_record tpr
+        from dkic_b.t_psi_outbound_item tpoi
         <include refid="getSaleProfitCond"/>
         group by sku_id) t
         ) tt
@@ -3180,15 +3178,15 @@
     </select>
 
     <sql id="getSaleProfitInOutBound">
-        SUM(case biznis_type when 't_psi_outbound' then abs(tpr.into_amt) else 0 end) outbound,
-        SUM(case biznis_type when 't_psi_inbound' then abs(tpr.into_amt) else 0 end) inbound
+        sum(tpoi.fact_amt - tpoi.return_amt) outbound,
+        sum(tpoi.cost_amt) inbound
     </sql>
 
     <sql id="getSaleProfitCond">
-        where tpr.cp_id = #{cpId}
+        where tpoi.cp_id = #{cpId} and tpoi.out_status = '出库状态-已出库'
         <if test="makeTimeStart != null and makeTimeEnd != null">
-            AND tpr.op_create_time &gt;= #{makeTimeStart}::timestamp with time zone
-            AND tpr.op_create_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
+            AND tpoi.op_create_time &gt;= #{makeTimeStart}::timestamp with time zone
+            AND tpoi.op_create_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
         </if>
     </sql>