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
140
141
142
143
144
145
146
<?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.plannedOutput.mapper.PlannedOutputMapper">
 
    <resultMap type="PlannedOutput" id="PlannedOutputResult">
        <result property="palnType"    column="paln_type"    />
        <result property="productId"    column="product_id"    />
        <result property="planValue"    column="plan_value"    />
        <result property="waterValue"    column="water_value"    />
        <result property="coalValue"    column="coal_value"    />
        <result property="value"    column="value"    />
        <result property="steamValue"    column="steam_value"    />
        <result property="dataTime"    column="data_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="productname"    column="productname"    />
        <result property="productsno"    column="productsno"    />
        <result property="muid"    column="muid"    />
        <result property="timeCode"    column="time_code"    />
    </resultMap>
 
    <sql id="selectPlannedOutputVo">
        SELECT
            productid as product_id,
            productsno,
            productname,
            p.muid,
            po.plan_value,
            po.paln_type,
            po."value",
            po.coal_value,
            po.steam_value,
            po.water_value
        FROM
            sys_product P
          left JOIN planned_output po on po.product_id= p.productid
    </sql>
 
    <select id="selectPlannedOutputList" parameterType="PlannedOutput" resultMap="PlannedOutputResult">
        <include refid="selectPlannedOutputVo"/>
        <where>
          p.productid in <foreach item="indexId" index="index" collection="indexIds"
                                open="(" separator="," close=")">
            #{indexId}
        </foreach>
          <if test="palnType != null  and palnType !=''"> AND po.paln_type = #{palnType} </if>
          <if test="timeCode != null  and timeCode !=''"> AND po.time_code = #{timeCode} </if>
        </where>
    </select>
    <select id="selectPlanList" parameterType="PlannedOutput" resultMap="PlannedOutputResult">
        SELECT
            productid as product_id,
            productsno,
            productname,
            p.muid
        FROM
            sys_product P
        <where>
             p.productid in <foreach item="indexId" index="index" collection="indexIds"
                                open="(" separator="," close=")">
            #{indexId}
            </foreach>
        </where>
    </select>
    <insert id="insertPlannedOutput" parameterType="PlannedOutput">
        insert into planned_output
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="palnType != null  and palnType != ''">paln_type,</if>
            <if test="productId != null ">product_id,</if>
            <if test="planValue != null  and planValue != ''">plan_value,</if>
            <if test="dataTime != null ">data_time,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="updateTime != null ">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="palnType != null  and palnType != ''">#{palnType},</if>
            <if test="productId != null ">#{productId},</if>
            <if test="planValue != null  and planValue != ''">#{planValue},</if>
            <if test="dataTime != null ">#{dataTime},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="updateTime != null ">#{updateTime},</if>
        </trim>
    </insert>
 
    <insert id="save">
        insert into planned_output (
                               time_code,
                               paln_type,
                               product_id,
                               plan_value,
                               value,
                               coal_value,
                               steam_value,
                               water_value,
                               data_time,
                               create_time)
        select #{plannedOutput.timeCode},
               #{plannedOutput.palnType},
               #{plannedOutput.productId},
               #{plannedOutput.planValue,jdbcType = DOUBLE},
               #{plannedOutput.value,jdbcType = DOUBLE},
               #{plannedOutput.coalValue,jdbcType = DOUBLE},
               #{plannedOutput.steamValue,jdbcType = DOUBLE},
               #{plannedOutput.waterValue,jdbcType = DOUBLE},
               #{plannedOutput.dataTime},
               now()
        on conflict
          (product_id,time_code)
        do update
        set plan_value = #{plannedOutput.planValue, jdbcType = DOUBLE},
            <if test="plannedOutput.value !='' and plannedOutput.value !=null">value = #{plannedOutput.value, jdbcType = DOUBLE},</if>
            <if test="plannedOutput.coalValue !='' and plannedOutput.coalValue !=null">coal_value = #{plannedOutput.coalValue, jdbcType = DOUBLE},</if>
            <if test="plannedOutput.steamValue !='' and plannedOutput.steamValue !=null">steam_value = #{plannedOutput.steamValue, jdbcType = DOUBLE},</if>
            <if test="plannedOutput.waterValue !='' and plannedOutput.waterValue !=null">water_value = #{plannedOutput.waterValue, jdbcType = DOUBLE},</if>
            update_time = now();
 
  </insert>
    <insert id="saveDataList" parameterType="java.util.List">
        <foreach item="PlannedOutput" collection="ItemVlues">
            <if test="PlannedOutput != null">
                insert into planned_output (
                time_code,
                paln_type,
                product_id,
                plan_value,
                data_time,
                create_time)
                select #{plannedOutput.timeCode},
                #{plannedOutput.palnType},
                #{plannedOutput.productId},
                #{plannedOutput.planValue,jdbcType = DOUBLE},
                #{plannedOutput.dataTime},
                now()
                on conflict
                (product_id,time_code)
                do update
                set plan_value = #{plannedOutput.planValue, jdbcType = DOUBLE},
                update_time = now();
            </if>
        </foreach>
    </insert>
 
 
</mapper>