Browse Source

feat(mapper): 新增时段价格查询映射及SQL语句

- 创建PolicyFeeMapper.xml映射文件
- 定义TimePeriodPriceResultMap结果映射,映射多字段价格信息
- 添加selectTimePeriodPriceList查询,支持多表联合查询时段价格数据
- 查询中根据销售类型动态过滤数据(firmId或thirdPartyId)
- 计算并返回含税价、服务费、增值费等多价格字段
- 使用分组及排序保证数据按时段正确展示
SheepHy 2 ngày trước cách đây
mục cha
commit
4f21c304ee
1 tập tin đã thay đổi với 80 bổ sung0 xóa
  1. 80 0
      src/main/resources/mapper/business/PolicyFeeMapper.xml

+ 80 - 0
src/main/resources/mapper/business/PolicyFeeMapper.xml

@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zsElectric.boot.business.mapper.PolicyFeeMapper">
+
+    <!-- 时段价格结果映射 -->
+    <resultMap id="TimePeriodPriceResultMap" type="com.zsElectric.boot.business.model.vo.TimePeriodPriceVO">
+        <result property="timePeriod" column="time_period"/>
+        <result property="periodFlag" column="period_flag"/>
+        <result property="electricityPrice" column="elec_price"/>
+        <result property="settlementServiceFee" column="service_price"/>
+        <result property="settlementTotalPrice" column="settlement_total_price"/>
+        <result property="operationServiceFee" column="op_fee"/>
+        <result property="valueAddedFees" column="value_added_fees"/>
+        <result property="saleTotalPrice" column="sale_total_price"/>
+    </resultMap>
+
+    <!-- 查询时段价格列表 -->
+    <select id="selectTimePeriodPriceList" resultMap="TimePeriodPriceResultMap">
+        SELECT
+            tppi.start_time AS time_period,
+            tppi.period_flag,
+            tppi.elec_price,
+            tppi.service_price,
+            ROUND(tppi.elec_price + tppi.service_price, 4) AS settlement_total_price,
+            IFNULL(pf.op_fee, 0) AS op_fee,
+            IFNULL(
+                (SELECT CAST(di.value AS DECIMAL(10,4))
+                 FROM sys_dict_item di
+                 WHERE di.dict_code = 'time_period_flag'
+                   AND di.status = 1
+                   AND di.label = CASE tppi.period_flag
+                       WHEN 1 THEN '尖'
+                       WHEN 2 THEN '峰'
+                       WHEN 3 THEN '平'
+                       WHEN 4 THEN '谷'
+                       ELSE ''
+                   END
+                 LIMIT 1),
+                0
+            ) AS value_added_fees,
+            ROUND(
+                tppi.elec_price + tppi.service_price + IFNULL(pf.op_fee, 0) +
+                IFNULL(
+                    (SELECT CAST(di.value AS DECIMAL(10,4))
+                     FROM sys_dict_item di
+                     WHERE di.dict_code = 'time_period_flag'
+                       AND di.status = 1
+                       AND di.label = CASE tppi.period_flag
+                           WHEN 1 THEN '尖'
+                           WHEN 2 THEN '峰'
+                           WHEN 3 THEN '平'
+                           WHEN 4 THEN '谷'
+                           ELSE ''
+                       END
+                     LIMIT 1),
+                    0
+                ),
+                4
+            ) AS sale_total_price
+        FROM third_party_policy_info tppi
+        INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
+        INNER JOIN third_party_connector_info tpci ON tpepp.connector_id = tpci.connector_id AND tpci.is_deleted = 0
+        INNER JOIN third_party_station_info tpsi ON tpci.station_id = tpsi.station_id AND tpsi.is_deleted = 0
+        LEFT JOIN c_policy_fee pf ON pf.station_info_id = tpsi.id
+            AND pf.start_time = tppi.start_time
+            AND pf.is_deleted = 0
+            AND pf.sales_type = #{salesType}
+            <if test="salesType == 1">
+                AND pf.firm_id = #{firmId}
+            </if>
+            <if test="salesType == 2">
+                AND pf.third_party_id = #{thirdPartyId}
+            </if>
+        WHERE tpsi.id = #{stationId}
+            AND tppi.is_deleted = 0
+        GROUP BY tppi.start_time, tppi.period_flag
+        ORDER BY tppi.start_time ASC
+    </select>
+
+</mapper>