TSafeEquipmentStandingBookMapper.xml 8.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?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.TSafeEquipmentStandingBookMapper">

    <resultMap type="TSafeEquipmentStandingBook" id="TSafeEquipmentStandingBookResult">
        <result property="safeEquipmentId"    column="safe_equipment_id"    />
        <result property="userName"    column="user_name"    />
        <result property="userNo"    column="user_no"    />
        <result property="userAddress"    column="user_address"    />
        <result property="idCard"    column="id_card"    />
        <result property="linkMobile"    column="link_mobile"    />
        <result property="equipmentType"    column="equipment_type"    />
        <result property="installTime"    column="install_time"    />
        <result property="brandName"    column="brand_name"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
        <result property="userType"    column="user_type"    />
24 25
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="enterpriseName"    column="enterpriseName"    />
26 27 28
    </resultMap>

    <sql id="selectTSafeEquipmentStandingBookVo">
29 30 31 32
        select book.safe_equipment_id, book.user_name, book.user_no, book.user_address, book.id_card, book.link_mobile,
               book.equipment_type, book.install_time, book.brand_name, book.create_by, book.create_time, book.update_by,
               book.update_time, book.is_del, book.remarks,book.user_type,book.enterprise_id,info.enterprise_name as enterpriseName
        from t_safe_equipment_standing_book book left join t_enterprise_info info on book.enterprise_id = info.enterprise_id
33 34 35 36
    </sql>

    <select id="selectTSafeEquipmentStandingBookList" parameterType="TSafeEquipmentStandingBookForm" resultMap="TSafeEquipmentStandingBookResult">
        <include refid="selectTSafeEquipmentStandingBookVo"/>
37 38 39 40 41 42 43
        <where>  book.is_del = '0'
            <if test="userName != null  and userName != ''"> and book.user_name like concat('%', #{userName}, '%')</if>
            <if test="linkMobile != null  and linkMobile != ''"> and book.link_mobile like concat('%', #{linkMobile}, '%')</if>
            <if test="equipmentType != null  and equipmentType != ''"> and book.equipment_type like concat('%', #{equipmentType}, '%')</if>
            <if test="installTimeStart != null "> and book.install_time &gt;= #{installTimeStart}</if>
            <if test="installTimeEnd != null "> and book.install_time &lt;= #{installTimeEnd}</if>
            <if test="enterpriseId != null and enterpriseId != '' "> and book.enterprise_id = #{enterpriseId}</if>
44
        </where>
45
        order by book.create_time desc
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
    </select>

    <select id="selectTSafeEquipmentStandingBookById" parameterType="Long" resultMap="TSafeEquipmentStandingBookResult">
        <include refid="selectTSafeEquipmentStandingBookVo"/>
        where safe_equipment_id = #{safeEquipmentId}
    </select>

    <insert id="insertTSafeEquipmentStandingBook" parameterType="TSafeEquipmentStandingBook" useGeneratedKeys="true" keyProperty="safeEquipmentId">
        insert into t_safe_equipment_standing_book
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userName != null">user_name,</if>
            <if test="userNo != null">user_no,</if>
            <if test="userAddress != null">user_address,</if>
            <if test="idCard != null">id_card,</if>
            <if test="linkMobile != null">link_mobile,</if>
            <if test="installTime != null">install_time,</if>
            <if test="equipmentType != null">equipment_type,</if>
            <if test="brandName != null">brand_name,</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>
            <if test="isDel != null">is_del,</if>
            <if test="remarks != null">remarks,</if>
            <if test="userType != null">user_type,</if>
71
            <if test="enterpriseId != null">enterprise_id,</if>
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userName != null">#{userName},</if>
            <if test="userNo != null">#{userNo},</if>
            <if test="userAddress != null">#{userAddress},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="linkMobile != null">#{linkMobile},</if>
            <if test="installTime != null">#{installTime},</if>
            <if test="equipmentType != null">#{equipmentType},</if>
            <if test="brandName != null">#{brandName},</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>
            <if test="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="userType != null">#{userType},</if>
89
            <if test="enterpriseId != null">#{enterpriseId},</if>
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
         </trim>
    </insert>

    <update id="updateTSafeEquipmentStandingBook" parameterType="TSafeEquipmentStandingBook">
        update t_safe_equipment_standing_book
        <trim prefix="SET" suffixOverrides=",">
            <if test="userName != null">user_name = #{userName},</if>
            <if test="userNo != null">user_no = #{userNo},</if>
            <if test="userAddress != null">user_address = #{userAddress},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="linkMobile != null">link_mobile = #{linkMobile},</if>
            <if test="installTime != null">install_time = #{installTime},</if>
            <if test="equipmentType != null">equipment_type = #{equipmentType},</if>
            <if test="brandName != null">brand_name = #{brandName},</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>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="userType != null">user_type = #{userType},</if>
111
            <if test="enterpriseId != null">enterprise_id = #{enterpriseId},</if>
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
        </trim>
        where safe_equipment_id = #{safeEquipmentId}
    </update>

    <delete id="deleteTSafeEquipmentStandingBookById" parameterType="Long">
        delete from t_safe_equipment_standing_book where safe_equipment_id = #{safeEquipmentId}
    </delete>

    <delete id="deleteTSafeEquipmentStandingBookByIds" parameterType="String">
        delete from t_safe_equipment_standing_book where safe_equipment_id in
        <foreach item="safeEquipmentId" collection="array" open="(" separator="," close=")">
            #{safeEquipmentId}
        </foreach>
    </delete>
    <select id="selectCountByYears" resultType="java.util.HashMap">
        SELECT d.`years`, COUNT(w.`safe_equipment_id`) AS `count`
            FROM(
              SELECT DATE_FORMAT((CURDATE()), '%Y') AS `years`
                UNION SELECT DATE_FORMAT((CURDATE() - INTERVAL 1 YEAR), '%Y') AS `years`
                UNION SELECT DATE_FORMAT((CURDATE() - INTERVAL 2 YEAR), '%Y') AS `years`
                UNION SELECT DATE_FORMAT((CURDATE() - INTERVAL 3 YEAR), '%Y') AS `years`
                UNION SELECT DATE_FORMAT((CURDATE() - INTERVAL 4 YEAR), '%Y') AS `years`
                )d
                LEFT JOIN t_safe_equipment_standing_book w
                ON DATE_FORMAT(w.create_time, '%Y')=d.`years` AND w.`is_del` =0
                GROUP BY years
    </select>
    <select id="selectCountByUserType" resultType="java.util.HashMap">
        SELECT  IFNULL(SUM(IF(user_type=1,1,0)),0) AS cheng,
            IFNULL(SUM(IF(user_type=2,1,0)),0) AS zhen,
            IFNULL(SUM(IF(user_type=3,1,0)),0) AS danwei
        FROM t_safe_equipment_standing_book
        WHERE is_del = 0
    </select>
</mapper>