付延余
2022-12-16 f0f8ee8c4a945adbc742d9bab69382b28ad311fb
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
161
162
163
164
165
166
167
168
<?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.wgcloud.mapper.CpuStateMapper">
    <resultMap id="resultMap" type="com.wgcloud.entity.CpuState">
        <id column="ID" property="id" jdbcType="CHAR" />
        <result column="HOST_NAME" property="hostname" jdbcType="CHAR" />
        <result column="USER_PER" property="userPer" jdbcType="CHAR" />
        <result column="SYS" property="sys" jdbcType="DOUBLE" />
        <result column="IDLE" property="idle" jdbcType="DOUBLE" />
        <result column="IOWAIT" property="iowait" jdbcType="DOUBLE" />
        <result column="IRQ" property="irq" jdbcType="CHAR" />
        <result column="SOFT" property="soft" jdbcType="CHAR" />
        <result column="CREATE_TIME" property="createTime" jdbcType="TIMESTAMP" />
    </resultMap>
    
    <sql id="tableColumnList">
        ID,HOST_NAME, USER_PER, SYS, IDLE,IOWAIT,IRQ,SOFT,CREATE_TIME
    </sql>
    
    <sql id="queryByParams">
        <if test="hostname != null">
            <![CDATA[ AND HOST_NAME = #{hostname} ]]>
        </if>
        <if test="startTime != null and endTime !=null and startTime !='' and endTime != '' ">
            <if test="_databaseId == 'mysql'">
                <![CDATA[ AND CREATE_TIME >= #{startTime} and CREATE_TIME <=#{endTime}]]>
            </if>
            <if test="_databaseId == 'postgresql'">
                <![CDATA[ AND CREATE_TIME >= cast(#{startTime} as timestamp) and CREATE_TIME <= cast(#{endTime} as timestamp)]]>
            </if>
            <if test="_databaseId == 'oracle'">
                <![CDATA[ AND CREATE_TIME >= to_date(#{startTime},'yyyy-MM-dd hh24:mi:ss') and CREATE_TIME <= to_date(#{endTime},'yyyy-MM-dd hh24:mi:ss')]]>
            </if>
        </if>
    </sql>
    
    
    <select id="selectById" resultMap="resultMap" parameterType="java.lang.String">
        SELECT
        <include refid="tableColumnList" />
        FROM CPU_STATE
        WHERE ID=#{id} 
    </select>
 
    <select id="selectMaxByHostname" resultType="java.lang.Double" parameterType="java.lang.String">
        SELECT MAX(SYS)
        FROM CPU_STATE
        WHERE HOST_NAME=#{hostname}
    </select>
 
    <select id="selectMaxByDate" resultType="java.lang.Double" parameterType="map">
        SELECT MAX(SYS)
        FROM CPU_STATE
        <where>
            <if test="startTime != null and endTime !=null and startTime !='' and endTime != '' ">
                <if test="_databaseId == 'mysql'">
                    <![CDATA[ AND CREATE_TIME >= #{startTime} and CREATE_TIME <=#{endTime}]]>
                </if>
                <if test="_databaseId == 'postgresql'">
                    <![CDATA[ AND CREATE_TIME >= cast(#{startTime} as timestamp) and CREATE_TIME <= cast(#{endTime} as timestamp)]]>
                </if>
                <if test="_databaseId == 'oracle'">
                    <![CDATA[ AND CREATE_TIME >= to_date(#{startTime},'yyyy-MM-dd hh24:mi:ss') and CREATE_TIME <= to_date(#{endTime},'yyyy-MM-dd hh24:mi:ss')]]>
                </if>
            </if>
            <if test="account != null">
                <![CDATA[ AND HOST_NAME IN (SELECT c.HOST_NAME FROM SYSTEM_INFO c WHERE c.ACCOUNT= #{account}) ]]>
            </if>
        </where>
    </select>
    
    
    <delete id="deleteByAccountAndDate"  parameterType="map">
        DELETE FROM CPU_STATE WHERE
        <if test="_databaseId == 'mysql'">
            <![CDATA[  CREATE_TIME <=#{endTime}]]>
        </if>
        <if test="_databaseId == 'postgresql'">
            <![CDATA[  CREATE_TIME <= cast(#{endTime} as timestamp)]]>
        </if>
        <if test="_databaseId == 'oracle'">
            <![CDATA[  CREATE_TIME <=  to_date(#{endTime},'yyyy-MM-dd hh24:mi:ss')]]>
        </if>
    </delete>
    
    
    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
        DELETE FROM CPU_STATE
        WHERE ID = #{id}
    </delete>
    
    <delete id="deleteById" parameterType="java.lang.String">
        DELETE FROM
        CPU_STATE
        WHERE ID IN
        <foreach item="item" index="index" collection="array" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>
 
    <insert id="save" parameterType="com.wgcloud.entity.CpuState">
        INSERT INTO CPU_STATE
        <trim prefix="(" suffix=")" suffixOverrides="," >
              <if test="id != null" >ID,</if>
              <if test="hostname != null" > HOST_NAME,</if>
              <if test="userPer != null">USER_PER,</if>
              <if test="sys != null">SYS,</if>
              <if test="idle != null">IDLE,</if>
              <if test="iowait != null">IOWAIT,</if>
              <if test="irq != null" >IRQ,</if>
              <if test="soft != null" >SOFT,</if>
              <if test="createTime != null" >CREATE_TIME</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
              <if test="id != null" >#{id},</if>
              <if test="hostname != null" >#{hostname},</if>
              <if test="userPer != null" >#{userPer},</if>
              <if test="sys != null" >#{sys},</if>
              <if test="idle != null" >#{idle},</if>
              <if test="iowait != null" >#{iowait},</if>
              <if test="irq != null" >#{irq},</if>
              <if test="soft != null" >#{soft},</if>
              <if test="createTime != null" >#{createTime}</if>
        </trim>
    </insert>
    
    <insert id="insertList" parameterType="java.util.List" >
        <choose>
            <when test="_databaseId == 'oracle'">
                begin
                <foreach collection="list" item="item" index="index">
                    INSERT INTO CPU_STATE (ID,HOST_NAME,USER_PER,SYS,IDLE,IOWAIT,IRQ,SOFT,CREATE_TIME)  VALUES
                    (#{item.id},#{item.hostname},#{item.userPer},#{item.sys},#{item.idle},#{item.iowait},#{item.irq},#{item.soft},#{item.createTime});
                </foreach>
                end;
            </when>
            <otherwise>
                INSERT INTO CPU_STATE (ID,HOST_NAME,USER_PER,SYS,IDLE,IOWAIT,IRQ,SOFT,CREATE_TIME)  VALUES
                <foreach collection="list" item="item" index="index" separator="," >
                    (#{item.id},#{item.hostname},#{item.userPer},#{item.sys},#{item.idle},#{item.iowait},#{item.irq},#{item.soft},#{item.createTime})
                </foreach>
            </otherwise>
        </choose>
     </insert>
    
    
      <select id="selectAllByParams" parameterType="map" resultMap="resultMap">
        SELECT
        <include refid="tableColumnList" />
        FROM CPU_STATE t
        <where>
            <include refid="queryByParams" />
        </where>
         ORDER BY CREATE_TIME ASC
    </select>
    
    <select id="selectByParams" parameterType="map" resultMap="resultMap">
        SELECT
        <include refid="tableColumnList" />
        FROM CPU_STATE
        <where>
            <include refid="queryByParams" />
        </where>
         ORDER BY CREATE_TIME DESC
    </select>
    
    
</mapper>