liulingling.177216
2024-08-26 349f1cfc5fa77fbc636d542df0d8050fddec48c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?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.dingzhuo.energy.project.electricity.mapper.statisticsMapper">
    <resultMap type="TimePeriodPrice" id="TimePeriodPriceResult">
        <result property="id"    column="id"    />
        <result property="effectiveDate"    column="effective_date"    />
        <result property="timePeriod"    column="time_period"    />
        <result property="price"    column="price"    />
        <result property="dictType"    column="dict_type"    />
        <result property="dictValue"    column="dict_value"    />
        <result property="dictLabel"    column="dict_label"    />
    </resultMap>
 
    <resultMap type="stagseDataEntry" id="stagseDataEntryResult">
        <result property="code" column="code"/>
        <result property="name" column="name"/>
        <result property="indexId" column="index_id"/>
        <result property="timeType" column="time_type"/>
        <result property="unitId" column="unit_id"/>
        <result property="calcType" column="calc_type"/>
        <result property="value" column="value"/>
        <result property="timeCode" column="time_code"/>
        <result property="dataTime" column="data_time"/>
    </resultMap>
    <resultMap id="dataItemMap" type="com.dingzhuo.energy.project.electricity.domain.electricityDataItem">
        <id column="index_id" property="indexId"/>
        <id column="time_code" property="timeCode"/>
        <id column="index_code" property="indexCode"/>
        <id column="index_name" property="indexName"/>
        <result column="begin_time" property="beginTime"/>
        <result column="end_time" property="endTime"/>
        <result column="data_time" property="dataTime"/>
        <result column="value" property="value"/>
        <result column="time_type" property="timeType"/>
        <result column="quality" property="quality"/>
        <result column="unit_id" property="unitId"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="remark" property="remark"/>
    </resultMap>
    <select id="getStatisticsList" resultType="com.dingzhuo.energy.data.model.domain.EnergyIndex">
        SELECT
        ei.index_id indexId,
        code,
        NAME,
        si.time_type timeType,
        ei.unit_id unitId
        FROM
        energy_index ei
        LEFT JOIN node_index ni ON ei.index_id = ni.index_id
        LEFT JOIN index_storage si ON si.index_id = ei.index_id
        WHERE
        ni.node_id IN (
            SELECT node_id FROM model_node WHERE address LIKE (SELECT address FROM model_node WHERE node_id = #{nodeId} )
            <if test='eierarchyFlag=="ALL"'>
               || '%'
            </if>
        )
    </select>
    <select id="getElectricityPriceList" parameterType="TimePeriodPrice" resultMap="TimePeriodPriceResult">
        SELECT A.ID,
            A.effective_date,
            A.time_period,
            A.price prices,
            ( SELECT dict_label FROM sys_dict_data WHERE dict_type = 'electricity_price' AND status = '0' AND dict_value = A.time_period ) electricityName
        FROM
            time_period_price A
        WHERE
            NOT EXISTS ( SELECT 1 FROM time_period_price b WHERE b.time_period = A.time_period AND b.effective_date > A.effective_date )
        <if test="endTime !=null ">AND A.effective_date &lt; #{endTime}</if>
    </select>
    <!--<select id="getElectricityPriceList" parameterType="ElectricityPrice" resultMap="ElectricityPriceResult">
        select e.id,
            e.effective_date,
            e.price_id,
            e.begin_date,
            e.end_date,
            e.effective_name,
            t.price as prices,
            (SELECT dict_label FROM sys_dict_data WHERE dict_type = 'electricity_price' AND status = '0' AND dict_value = e.effective_name) electricityName
        from electricity_price e LEFT JOIN time_period_price t ON e.price_id=t.id
        <where> 1=1
            <if test="endTime !=null ">AND e.effective_date &lt; #{endTime}</if>
        </where>
        order by e.effective_date desc
    </select>-->
    <select id="getDatasByIndex" resultMap="dataItemMap">
        SELECT
        d.index_id,
        i.code AS index_code,
        i.NAME AS index_name,
        i.unit_id,
        sum(value) as value
        FROM
        data_item d
        LEFT JOIN energy_index i ON d.index_id = i.index_id
        WHERE
        i.index_id IN
        <foreach item="indexId" index="index" collection="indexIds" open="(" separator="," close=")">
            #{indexId}
        </foreach>
        AND time_type = #{timeType}
        AND data_time &gt;= #{beginTime}
        AND data_time &lt;= #{endTime}
        GROUP BY
        d.index_id,
        i.code,
        i.unit_id,
        i.NAME
    </select>
    <select id="getPeriodDatasByIndex" resultMap="dataItemMap">
        SELECT
        d.index_id,
        i.code AS index_code,
        i.NAME AS index_name,
        i.unit_id,
        sum(value) as value,
        to_char(d.data_time, 'YYYY-MM' ) as formatdate
        FROM
        data_item d
        LEFT JOIN energy_index i ON d.index_id = i.index_id
        WHERE
        i.index_id IN
        <foreach item="indexId" index="index" collection="indexIds" open="(" separator="," close=")">
            #{indexId}
        </foreach>
        AND time_type = #{timeType}
        AND data_time &gt;= #{beginTime}
        AND data_time &lt;= #{endTime}
        GROUP BY
        d.index_id,
        i.code,
        i.unit_id,
        i.NAME,to_char(d.data_time, 'YYYY-MM' )
    </select>
 
</mapper>