TSafeEquipment.xml 10.5 KB
Newer Older
Rensq's avatar
Rensq committed
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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
<?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.testor.ddd.safetyControl.infrastructure.repository.equipment.dao.TSafeEquipmentDao">
    <!-- 开启二级缓存 -->
    <!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap"
               type="com.testor.ddd.safetyControl.infrastructure.repository.equipment.entity.TSafeEquipmentDO">
        <id column="id" property="id"/>
        <id column="org_id" property="orgId"/>
        <id column="sys_type_id" property="sysTypeId"/>
        <id column="equipment_type_id" property="equipmentTypeId"/>
        <id column="name" property="name"/>
        <id column="code" property="code"/>
        <id column="specification" property="specification"/>
        <id column="space_id" property="spaceId"/>
        <id column="space_area_id" property="spaceAreaId"/>
        <id column="manufacturer" property="manufacturer"/>
        <id column="des" property="des"/>
        <id column="validity_date" property="validityDate"/>
        <id column="is_special" property="isSpecial"/>
        <id column="img_url" property="imgUrl"/>
    </resultMap>

    <sql id="select_base_column">
        se.id, se.org_id orgId, se.sys_type_id sysTypeId, se.equipment_type_id equipmentTypeId, se.name, se.code,
        se.specification, se.space_id spaceId, se.space_area_id spaceAreaId, se.manufacturer, se.des, se.validity_date validityDate, se.is_special isSpecial,se.img_url imgUrl,
        se.status, se.remarks, se.create_by createBy, se.create_date createDate,
        se.update_by as updateBy, se.update_date updateDate
    </sql>

    <sql id="common_where_if">
        <if test="query.id!=null and query.id!=''">
            and se.id=#{query.id}
        </if>
        <if test="query.orgId!=null and query.orgId!=''">
            and se.org_id=#{query.orgId}
        </if>
        <if test="query.sysTypeId!='' and query.sysTypeId!=null">
            and se.sys_type_id=#{query.sysTypeId}
        </if>
        <if test="query.equipmentTypeId!='' and query.equipmentTypeId!=null">
            and se.equipment_type_id=#{query.equipmentTypeId}
        </if>
        <if test="query.spaceAreaId!='' and query.spaceAreaId!=null">
            and se.space_area_id=#{query.spaceAreaId}
        </if>
        <if test="query.spaceId!='' and query.spaceId!=null">
            and se.space_id=#{query.spaceId}
        </if>
        <if test="query.name!='' and query.name!=null">
            and se.name like concat('%',#{query.name},'%')
        </if>
        <if test="query.code!='' and query.code!=null">
            and se.code=#{query.code}
        </if>
        <if test="query.manufacturer!='' and query.manufacturer!=null">
            and se.manufacturer=#{query.manufacturer}
        </if>
        <if test="query.specification!='' and query.specification!=null">
            and se.specification=#{query.specification}
        </if>
        <if test="query.des!='' and query.des!=null">
            and se.des like concat('%',#{query.des},'%')
        </if>
        <if test="query.validityDate!='' and query.validityDate!=null">
            and se.validity_date=#{query.validityDate}
        </if>
        <if test="query.isSpecial!='' and query.isSpecial!=null">
            and se.is_special=#{query.isSpecial}
        </if>
    </sql>

    <select id="listPage" resultType="com.testor.ddd.safetyControl.interfaces.model.vo.equipment.TSafeEquipmentVO"
            parameterType="com.testor.ddd.safetyControl.interfaces.model.dto.equipment.TSafeEquipmentDTOParam">
        select   st.name as sysTypeName,
        et.name as equipmentTypeName,
        so.org_name as orgName,
        <include refid="select_base_column" />
        from t_safe_equipment se
        left join t_safe_equipment_type st on st.id = se.sys_type_id
        left join t_safe_equipment_type et on se.equipment_type_id = et.id
        left join t_sys_org so on so.org_id = se.org_id
        <where>
            se.status = '0'
            <include refid="common_where_if"></include>
            <if test="query.condOrgIdList!=null and query.condOrgIdList.size>0">
                and se.org_id in
                <foreach collection="query.condOrgIdList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="query.condSysTypeIdList!=null and query.condSysTypeIdList.size>0">
                and pss.sys_type_id in
                <foreach collection="query.condSysTypeIdList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="query.condEquipmentTypeIdList!=null and query.condEquipmentTypeIdList.size>0">
                and se.equipment_type_id in
                <foreach collection="query.condEquipmentTypeIdList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="query.validityStartDate!=null">
                and se.validity_date >= #{query.validityStartDate}
            </if>
            <if test="query.validityEndDate!=null">
                and #{query.validityEndDate} >= se.validity_date
            </if>
        </where>
        <if test="query.orderBy!='' and query.orderBy!=null and query.orderType!='' and query.orderType!=null" >
            order by ${query.orderBy} ${query.orderType}
        </if>
    </select>

    <select id="findDetailById" resultType="com.testor.ddd.safetyControl.interfaces.model.vo.equipment.TSafeEquipmentVO">
        select   st.name as sysTypeName,
        et.name as equipmentTypeName,
        so.org_name as orgName,
        ss.name as spaceAreaName,
        pss.name as spaceName,
        <include refid="select_base_column" />
        from t_safe_equipment se
        left join t_safe_equipment_type st on st.id = se.sys_type_id
        left join t_safe_equipment_type et on se.equipment_type_id = et.id
        left join t_sys_org so on so.org_id = se.org_id
        left join t_safe_space ss on ss.id = se.space_area_id
        left join t_safe_space pss on pss.id = se.space_id
        <where>
            se.status = '0' and se.id=#{id}
        </where>
    </select>

    <select id="listForRisk" resultType="com.testor.ddd.safetyControl.interfaces.model.vo.equipment.TSafeEquipmentVO"
            parameterType="com.testor.ddd.safetyControl.interfaces.model.dto.equipment.TSafeEquipmentDTOParam">
        select   st.name as sysTypeName,
        et.name as equipmentTypeName,
        ss.name as spaceAreaName,
        pss.name as spaceName,
        ptss.name as spaceTypeName,
        ptss.id as spaceTypeId,
        <include refid="select_base_column" />
        from t_safe_equipment se
        left join t_safe_equipment_type st on st.id = se.sys_type_id
        left join t_safe_equipment_type et on se.equipment_type_id = et.id
        left join t_safe_space ss on ss.id = se.space_area_id
        left join t_safe_space pss on pss.id = se.space_id
        left join t_safe_space_type ptss on ptss.id = pss.space_type_id
        <where>
            se.status = '0'
            <include refid="common_where_if"></include>
            <if test="query.condOrgIdList!=null and query.condOrgIdList.size>0">
                and se.org_id in
                <foreach collection="query.condOrgIdList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="query.condSysTypeIdList!=null and query.condSysTypeIdList.size>0">
                and pss.sys_type_id in
                <foreach collection="query.condSysTypeIdList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="query.condEquipmentTypeIdList!=null and query.condEquipmentTypeIdList.size>0">
                and se.equipment_type_id in
                <foreach collection="query.condEquipmentTypeIdList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="query.validityStartDate!='' and query.validityStartDate!=null">
                and se.validity_date > #{query.validityStartDate}
            </if>
            <if test="query.validityEndDate!='' and query.validityEndDate!=null">
                and se.validity_date=#{query.validityEndDate}
            </if>
        </where>
    </select>

    <select id="countEquipment" resultType="java.lang.Integer"
            parameterType="com.testor.ddd.safetyControl.interfaces.model.dto.equipment.TSafeEquipmentDTO">
        select count(se.id)
        from t_safe_equipment se
        left join t_partner_type st on st.id = se.sys_type_id
        left join t_partner_type et on se.equipment_type_id = et.id
        left join t_sys_org so on so.org_id = se.org_id
        <where>
            se.status = '0'
            <include refid="common_where_if"></include>
            <if test="query.condOrgIdList!=null and query.condOrgIdList.size>0">
                and se.org_id in
                <foreach collection="query.condOrgIdList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="query.condSysTypeIdList!=null and query.condSysTypeIdList.size>0">
                and pss.sys_type_id in
                <foreach collection="query.condSysTypeIdList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="query.condEquipmentTypeIdList!=null and query.condEquipmentTypeIdList.size>0">
                and se.equipment_type_id in
                <foreach collection="query.condEquipmentTypeIdList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="query.validityStartDate!=null">
                and se.validity_date >= #{query.validityStartDate}
            </if>
            <if test="query.validityEndDate!=null">
                and  #{query.validityEndDate} >= se.validity_date
            </if>
        </where>
    </select>

    <update id="replaceCode">
        update t_safe_equipment
        set code = replace(code,#{oldCode}, #{newCode})
        where status = '0' and (sys_type_id = #{typeId}  or equipment_type_id=#{typeId})
    </update>
</mapper>