ustcyc
2025-01-07 de5d55508afd27fb2b47e6d4d6fd9984525c222c
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?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.zhitan.gatewaysetting.mapper.GatewaySettingMapper">
 
    <resultMap type="GatewaySetting" id="GatewaySettingResult">
        <result property="id"    column="id"    />
        <result property="gatewayNum"    column="gateway_num"    />
        <result property="gatewayName"    column="gateway_name"    />
        <result property="specsModel"    column="specs_model"    />
        <result property="installLocation"    column="install_location"    />
        <result property="ipAdd"    column="ip_add"    />
        <result property="runStatus"    column="run_status"    />
        <result property="hbtTime"    column="hbt_time"    />
        <result property="deviceNum"    column="device_num"    />
        <result property="ptNum"    column="pt_num"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>
 
    <sql id="selectGatewaySettingVo">
        select id, gateway_num, gateway_name, specs_model, install_location, ip_add, run_status, hbt_time, device_num, pt_num, create_by, create_time, update_by, update_time from gateway_setting
    </sql>
 
    <select id="selectGatewaySettingList" parameterType="GatewaySetting" resultMap="GatewaySettingResult">
        <include refid="selectGatewaySettingVo"/>
        <where>
            <if test="gatewayNum != null  and gatewayNum != ''"> and gateway_num = #{gatewayNum}</if>
            <if test="gatewayName != null  and gatewayName != ''"> and gateway_name like concat('%', #{gatewayName}, '%')</if>
            <if test="specsModel != null  and specsModel != ''"> and specs_model = #{specsModel}</if>
            <if test="installLocation != null  and installLocation != ''"> and install_location = #{installLocation}</if>
            <if test="ipAdd != null  and ipAdd != ''"> and ip_add = #{ipAdd}</if>
            <if test="runStatus != null  and runStatus != ''"> and run_status = #{runStatus}</if>
            <if test="hbtTime != null "> and hbt_time = #{hbtTime}</if>
            <if test="deviceNum != null  and deviceNum != ''"> and device_num = #{deviceNum}</if>
            <if test="ptNum != null  and ptNum != ''"> and pt_num = #{ptNum}</if>
        </where>
    </select>
 
    <select id="selectGatewaySettingById" parameterType="String" resultMap="GatewaySettingResult">
        <include refid="selectGatewaySettingVo"/>
        where id = #{id}
    </select>
 
    <insert id="insertGatewaySetting" parameterType="GatewaySetting">
        insert into gateway_setting
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">id,</if>
            <if test="gatewayNum != null">gateway_num,</if>
            <if test="gatewayName != null">gateway_name,</if>
            <if test="specsModel != null">specs_model,</if>
            <if test="installLocation != null">install_location,</if>
            <if test="ipAdd != null">ip_add,</if>
            <if test="runStatus != null">run_status,</if>
            <if test="hbtTime != null">hbt_time,</if>
            <if test="deviceNum != null">device_num,</if>
            <if test="ptNum != null">pt_num,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">#{id},</if>
            <if test="gatewayNum != null">#{gatewayNum},</if>
            <if test="gatewayName != null">#{gatewayName},</if>
            <if test="specsModel != null">#{specsModel},</if>
            <if test="installLocation != null">#{installLocation},</if>
            <if test="ipAdd != null">#{ipAdd},</if>
            <if test="runStatus != null">#{runStatus},</if>
            <if test="hbtTime != null">#{hbtTime},</if>
            <if test="deviceNum != null">#{deviceNum},</if>
            <if test="ptNum != null">#{ptNum},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>
 
    <update id="updateGatewaySetting" parameterType="GatewaySetting">
        update gateway_setting
        <trim prefix="SET" suffixOverrides=",">
            <if test="gatewayNum != null">gateway_num = #{gatewayNum},</if>
            <if test="gatewayName != null">gateway_name = #{gatewayName},</if>
            <if test="specsModel != null">specs_model = #{specsModel},</if>
            <if test="installLocation != null">install_location = #{installLocation},</if>
            <if test="ipAdd != null">ip_add = #{ipAdd},</if>
            <if test="runStatus != null">run_status = #{runStatus},</if>
            <if test="hbtTime != null">hbt_time = #{hbtTime},</if>
            <if test="deviceNum != null">device_num = #{deviceNum},</if>
            <if test="ptNum != null">pt_num = #{ptNum},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>
 
    <delete id="deleteGatewaySettingById" parameterType="String">
        delete from gateway_setting where id = #{id}
    </delete>
 
    <delete id="deleteGatewaySettingByIds" parameterType="String">
        delete from gateway_setting where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
 
    <select id="checkOne" resultType="int" parameterType="GatewaySetting">
        select count(1) from gateway_setting
        where
        gateway_num=#{gatewayNum}
        <if test="id!=null and id !=''">
            and id != #{id}
        </if>
 
    </select>
 
    <select id="ptNum" resultType="com.zhitan.gatewaysetting.domain.GatewaySetting" parameterType="GatewaySetting">
            select sum(device_num) device_num,sum(pt_num) pt_num from gateway_setting
        <where>
        <if test="gatewayNum != null  and gatewayNum != ''"> and gateway_num = #{gatewayNum}</if>
        <if test="gatewayName != null  and gatewayName != ''"> and gateway_name like concat('%', #{gatewayName}, '%')</if>
        <if test="specsModel != null  and specsModel != ''"> and specs_model = #{specsModel}</if>
        <if test="installLocation != null  and installLocation != ''"> and install_location = #{installLocation}</if>
        <if test="ipAdd != null  and ipAdd != ''"> and ip_add = #{ipAdd}</if>
        <if test="runStatus != null  and runStatus != ''"> and run_status = #{runStatus}</if>
        <if test="hbtTime != null "> and hbt_time = #{hbtTime}</if>
        <if test="deviceNum != null  and deviceNum != ''"> and device_num = #{deviceNum}</if>
        <if test="ptNum != null  and ptNum != ''"> and pt_num = #{ptNum}</if>
    </where>
    </select>
 
    <update id="addNum" parameterType="GatewaySetting">
        update gateway_setting set device_num = COALESCE(NULLIF(device_num,null),'0')+ #{deviceNum}, pt_num = COALESCE(NULLIF(pt_num,null),'0')+#{ptNum},update_time=now(),update_by=#{updateBy}
        where id = #{id}
    </update>
 
    <update id="subNum" parameterType="GatewaySetting">
        update gateway_setting set device_num =
            CASE
 
                WHEN COALESCE(NULLIF(device_num,null),'0')- #{deviceNum} > 0 THEN
                    COALESCE(NULLIF(device_num,null),'0')- #{deviceNum} ELSE 0
                END
            , pt_num =
                CASE
 
                    WHEN COALESCE(NULLIF(pt_num,null),'0')-#{ptNum} > 0 THEN
                        COALESCE(NULLIF(pt_num,null),'0')-#{ptNum} ELSE 0
                    END,update_time=now(),update_by=#{updateBy}
        where id = #{id}
    </update>
</mapper>