TStaningBookMapper.xml 13.6 KB
Newer Older
耿迪迪's avatar
耿迪迪 committed
1 2 3 4 5
<?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.zehong.system.mapper.TStaningBookMapper">
6

耿迪迪's avatar
耿迪迪 committed
7 8 9 10 11 12
    <resultMap type="TStaningBook" id="TStaningBookResult">
        <result property="bookId"    column="book_id"    />
        <result property="troubleName"    column="trouble_name"    />
        <result property="troubleType"    column="trouble_type"    />
        <result property="troubleLevel"    column="trouble_level"    />
        <result property="measures"    column="measures"    />
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
        <result property="troubleHarm"    column="trouble_harm"    />
        <result property="escalation"    column="escalation"    />
        <result property="escalationName"    column="escalationName"    />
        <result property="findTime"    column="find_time"    />
        <result property="picture"    column="picture"    />
        <result property="enclosure"    column="enclosure"    />
        <result property="proposal"    column="proposal"    />
        <result property="rectificationTerm"    column="rectification_term"    />
        <result property="investmentCost"    column="investment_cost"    />
        <result property="investmentMaterial"    column="investment_material"    />
        <result property="rectification"    column="rectification"    />
        <result property="rectificationName"    column="rectificationName"    />
        <result property="rectificationPictrue"    column="rectification_pictrue"    />
        <result property="rectificationText"    column="rectification_text"    />
        <result property="rectificationTime"    column="rectification_time"    />
        <result property="remarks"    column="remarks"    />
耿迪迪's avatar
耿迪迪 committed
29
        <result property="finishDay"    column="finish_day"    />
30 31
        <result property="inspectPictrue"    column="inspect_pictrue"    />
        <result property="inspectTime"    column="inspect_time"    />
耿迪迪's avatar
耿迪迪 committed
32 33
        <result property="inspectResult"    column="inspect_result"    />
        <result property="personLiable"    column="person_liable"    />
34 35
        <result property="personLiableName"    column="personLiableName"    />
        <result property="state"    column="state"    />
耿迪迪's avatar
耿迪迪 committed
36 37 38 39
        <result property="deptId"    column="dept_id"    />
        <result property="workId"    column="work_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
40
        <result property="createId" column="create_id" />
耿迪迪's avatar
耿迪迪 committed
41
        <result property="isDel"    column="is_del"    />
42
        <result property="deptName"    column="deptName"    />
43 44 45
        <result property="troubleLevelName"    column="troubleLevelName"    />
        <result property="troubleTypeName"    column="troubleTypeName"    />
        <result property="stateName"    column="stateName"    />
耿迪迪's avatar
耿迪迪 committed
46 47 48
    </resultMap>

    <sql id="selectTStaningBookVo">
49
        select book_id, trouble_name, trouble_type, trouble_level, measures, trouble_harm, escalation, find_time, picture, enclosure, proposal,rectification_term, investment_cost, investment_material, rectification, rectification_pictrue, rectification_text, rectification_time, remarks, finish_day, inspect_pictrue, inspect_time, inspect_result, person_liable, state, dept_id, work_id, create_time, create_by, is_del from t_staning_book
耿迪迪's avatar
耿迪迪 committed
50 51 52
    </sql>

    <select id="selectTStaningBookList" parameterType="TStaningBook" resultMap="TStaningBookResult">
53
        SELECT b.*,s1.staff_name AS escalationName,
54 55
        s2.`staff_name` AS rectificationName,
        s3.`staff_name` AS personLiableName ,
56 57 58 59
        d.`dept_name` AS deptName,
        (select dict_label from sys_dict_data where dict_type='t_trouble_type' and dict_value=b.trouble_type) troubleTypeName,
        (select dict_label from sys_dict_data where dict_type='t_trouble_level' and dict_value=b.trouble_level) troubleLevelName,
        (case state when '0' then '待整改' when '1' then '待复查' when '2' then '已闭环' end) stateName
60
        FROM t_staning_book b
61 62 63
        LEFT JOIN sys_user s1 ON b.`escalation` = s1.`user_id`
        LEFT JOIN sys_user s2 ON b.`rectification` = s2.`user_id`
        LEFT JOIN sys_user s3 ON b.`person_liable` = s3.`user_id`
64 65
        LEFT JOIN sys_dept d ON d.`dept_id` = b.`dept_id`
        <where>
66

67
            <if test="userId != null and userId != 0"> and (b.escalation=#{userId}||b.rectification = #{userId}||b.create_id = #{userId} ) </if>
68 69 70 71
            <if test="troubleName != null  and troubleName != ''"> and b.trouble_name like concat('%', #{troubleName}, '%')</if>
            <if test="findTime != null "> and b.find_time &gt; #{findTime}</if>
            <if test="rectificationTime != null "> and b.find_time &lt; #{rectificationTime}</if>
            <if test="state != null "> and b.state = #{state}</if>
耿迪迪's avatar
耿迪迪 committed
72 73
        </where>
    </select>
74

耿迪迪's avatar
耿迪迪 committed
75 76 77 78
    <select id="selectTStaningBookById" parameterType="Long" resultMap="TStaningBookResult">
        <include refid="selectTStaningBookVo"/>
        where book_id = #{bookId}
    </select>
79

耿迪迪's avatar
耿迪迪 committed
80 81 82 83 84 85 86
    <insert id="insertTStaningBook" parameterType="TStaningBook" useGeneratedKeys="true" keyProperty="bookId">
        insert into t_staning_book
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="troubleName != null">trouble_name,</if>
            <if test="troubleType != null">trouble_type,</if>
            <if test="troubleLevel != null">trouble_level,</if>
            <if test="measures != null">measures,</if>
87 88 89 90 91 92 93 94 95 96 97 98 99 100
            <if test="troubleHarm != null">trouble_harm,</if>
            <if test="escalation != null">escalation,</if>
            <if test="findTime != null">find_time,</if>
            <if test="picture != null">picture,</if>
            <if test="enclosure != null">enclosure,</if>
            <if test="proposal != null">proposal,</if>
            <if test="rectificationTerm != null">rectification_term,</if>
            <if test="investmentCost != null">investment_cost,</if>
            <if test="investmentMaterial != null">investment_material,</if>
            <if test="rectification != null">rectification,</if>
            <if test="rectificationPictrue != null">rectification_pictrue,</if>
            <if test="rectificationText != null">rectification_text,</if>
            <if test="rectificationTime != null">rectification_time,</if>
            <if test="remarks != null">remarks,</if>
耿迪迪's avatar
耿迪迪 committed
101
            <if test="finishDay != null">finish_day,</if>
102 103
            <if test="inspectPictrue != null">inspect_pictrue,</if>
            <if test="inspectTime != null">inspect_time,</if>
耿迪迪's avatar
耿迪迪 committed
104 105
            <if test="inspectResult != null">inspect_result,</if>
            <if test="personLiable != null">person_liable,</if>
106
            <if test="state != null">state,</if>
耿迪迪's avatar
耿迪迪 committed
107 108 109 110
            <if test="deptId != null">dept_id,</if>
            <if test="workId != null">work_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
111
            <if test="createId != null">create_id,</if>
耿迪迪's avatar
耿迪迪 committed
112 113 114 115 116 117 118
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="troubleName != null">#{troubleName},</if>
            <if test="troubleType != null">#{troubleType},</if>
            <if test="troubleLevel != null">#{troubleLevel},</if>
            <if test="measures != null">#{measures},</if>
119 120 121 122 123 124 125 126 127 128 129 130 131 132
            <if test="troubleHarm != null">#{troubleHarm},</if>
            <if test="escalation != null">#{escalation},</if>
            <if test="findTime != null">#{findTime},</if>
            <if test="picture != null">#{picture},</if>
            <if test="enclosure != null">#{enclosure},</if>
            <if test="proposal != null">#{proposal},</if>
            <if test="rectificationTerm != null">#{rectificationTerm},</if>
            <if test="investmentCost != null">#{investmentCost},</if>
            <if test="investmentMaterial != null">#{investmentMaterial},</if>
            <if test="rectification != null">#{rectification},</if>
            <if test="rectificationPictrue != null">#{rectificationPictrue},</if>
            <if test="rectificationText != null">#{rectificationText},</if>
            <if test="rectificationTime != null">#{rectificationTime},</if>
            <if test="remarks != null">#{remarks},</if>
耿迪迪's avatar
耿迪迪 committed
133
            <if test="finishDay != null">#{finishDay},</if>
134 135
            <if test="inspectPictrue != null">#{inspectPictrue},</if>
            <if test="inspectTime != null">#{inspectTime},</if>
耿迪迪's avatar
耿迪迪 committed
136 137
            <if test="inspectResult != null">#{inspectResult},</if>
            <if test="personLiable != null">#{personLiable},</if>
138
            <if test="state != null">#{state},</if>
耿迪迪's avatar
耿迪迪 committed
139 140 141 142
            <if test="deptId != null">#{deptId},</if>
            <if test="workId != null">#{workId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
143
            <if test="createId != null">#{createId},</if>
耿迪迪's avatar
耿迪迪 committed
144 145 146 147 148 149 150 151 152 153 154
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateTStaningBook" parameterType="TStaningBook">
        update t_staning_book
        <trim prefix="SET" suffixOverrides=",">
            <if test="troubleName != null">trouble_name = #{troubleName},</if>
            <if test="troubleType != null">trouble_type = #{troubleType},</if>
            <if test="troubleLevel != null">trouble_level = #{troubleLevel},</if>
            <if test="measures != null">measures = #{measures},</if>
155 156 157 158 159 160 161 162 163 164 165 166 167 168
            <if test="troubleHarm != null">trouble_harm = #{troubleHarm},</if>
            <if test="escalation != null">escalation = #{escalation},</if>
            <if test="findTime != null">find_time = #{findTime},</if>
            <if test="picture != null">picture = #{picture},</if>
            <if test="enclosure != null">enclosure = #{enclosure},</if>
            <if test="proposal != null">proposal = #{proposal},</if>
            <if test="rectificationTerm != null">rectification_term = #{rectificationTerm},</if>
            <if test="investmentCost != null">investment_cost = #{investmentCost},</if>
            <if test="investmentMaterial != null">investment_material = #{investmentMaterial},</if>
            <if test="rectification != null">rectification = #{rectification},</if>
            <if test="rectificationPictrue != null">rectification_pictrue = #{rectificationPictrue},</if>
            <if test="rectificationText != null">rectification_text = #{rectificationText},</if>
            <if test="rectificationTime != null">rectification_time = #{rectificationTime},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
耿迪迪's avatar
耿迪迪 committed
169
            <if test="finishDay != null">finish_day = #{finishDay},</if>
170 171
            <if test="inspectPictrue != null">inspect_pictrue = #{inspectPictrue},</if>
            <if test="inspectTime != null">inspect_time = #{inspectTime},</if>
耿迪迪's avatar
耿迪迪 committed
172 173
            <if test="inspectResult != null">inspect_result = #{inspectResult},</if>
            <if test="personLiable != null">person_liable = #{personLiable},</if>
174
            <if test="state != null">state = #{state},</if>
耿迪迪's avatar
耿迪迪 committed
175 176 177 178
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="workId != null">work_id = #{workId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
179
            <if test="createId != null">create_id = #{createId},</if>
耿迪迪's avatar
耿迪迪 committed
180 181 182 183 184 185 186 187 188 189
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where book_id = #{bookId}
    </update>

    <delete id="deleteTStaningBookById" parameterType="Long">
        delete from t_staning_book where book_id = #{bookId}
    </delete>

    <delete id="deleteTStaningBookByIds" parameterType="String">
190
        delete from t_staning_book where book_id in
耿迪迪's avatar
耿迪迪 committed
191 192 193 194
        <foreach item="bookId" collection="array" open="(" separator="," close=")">
            #{bookId}
        </foreach>
    </delete>
lizhichao's avatar
lizhichao committed
195
    <select id="statics" parameterType="String" resultType="Map">
196
        select count(1) faxian,sum(case state when '2' then 1 else 0 end )as zhenggai from t_staning_book where is_del=0
lizhichao's avatar
lizhichao committed
197 198 199 200 201 202 203 204 205 206
        <if test="type=='day'">
            and DATE_SUB(now(), INTERVAL 1 DAY) &lt; date(find_time)
        </if>
        <if test="type=='month'">
            and DATE_SUB(now(), INTERVAL 30 DAY) &lt; date(find_time)
        </if>
        <if test="type=='year'">
            and DATE_SUB(now(), INTERVAL 365 DAY) &lt; date(find_time)
        </if>
    </select>
耿迪迪's avatar
耿迪迪 committed
207 208 209

    <select id="hiddenBarStat" resultType="HiddenStatVO">
        SELECT
210
            IFNULL(DATE_FORMAT(find_time,'%Y-%m'),0) AS month,
耿迪迪's avatar
耿迪迪 committed
211 212 213 214 215 216 217 218 219 220 221 222
            IFNULL(count(1),0) hiddenCount,
            IFNULL(sum(CASE state WHEN '2' THEN 1 ELSE 0 END),0) AS rectifiedCount
        FROM
            t_staning_book
        WHERE
            is_del = 0
        <if test="beginTime != null and endTime != null">
            AND find_time BETWEEN #{ beginTime } AND #{ endTime }
        </if>
        <if test="troubleLevel != null and troubleLevel != ''">
            AND trouble_level = #{troubleLevel}
        </if>
223
        GROUP BY DATE_FORMAT(find_time,'%Y-%m')
耿迪迪's avatar
耿迪迪 committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
    </select>

    <select id="hiddenPieStat" resultType="java.util.Map">
        SELECT
          IFNULL(sum(CASE state WHEN '2' THEN 1 ELSE 0 END),0) AS rectifiedCount,
          IFNULL(sum(IF(IFNULL(state,'-1') != '2',1,0)),0) AS stayRectifiedCount
        FROM
            t_staning_book
        WHERE
            is_del = 0
        <if test="beginTime != null and endTime != null">
            AND find_time BETWEEN #{ beginTime } AND #{ endTime }
        </if>
        <if test="troubleLevel != null and troubleLevel != ''">
            AND trouble_level = #{troubleLevel}
        </if>
    </select>
241
</mapper>