| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- <?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.inspur.idm.media.dao.RescueInfoDao">
- <sql id="data_auth">
- <choose>
- <when test="ccType == 'none'">
- and 1=2
- </when>
- <when test="ccType == 'estate'">
- <!-- 物业 estate -->
- and rescue_info.elevator_id in (select elevator_id from ele_info_usage where estate_company_id = #{ccId})
- </when>
- <when test="ccType == 'mainten'">
- <!-- 维保 mainten -->
- and rescue_info.elevator_id in (select elevator_id from ele_info_mainten where mainten_company_id = #{ccId})
- </when>
- <when test="ccType == 'insure'">
- <!-- 保险 insure -->
- and rescue_info.elevator_id in (select elevator_id from fault_insure_elevator where insure_id in (select insure_id from fault_insure where insure_company_id = #{ccId}))
- </when>
- <when test="ccType == 'quality'">
- <!-- 质监 quality 政府人员 -->
- and rescue_info.elevator_id in (select elevator_id from ele_info_basic where quality_company_id = #{ccId})
- </when>
- <when test="ccType == 'inspect'">
- <!-- 检验 inspect 电梯评估机构人员 -->
- and rescue_info.elevator_id in (select elevator_id from ele_info_basic where inspect_company_id = #{ccId})
- </when>
- <otherwise>
- <!--
- 安装 install install_company_id
- select elevator_id from ele_info_install where install_company_id = '';
- 验收单位 accept accept_company_id
- select elevator_id from ele_info_install where accept_company_id = '';
- 制造单位 manufact manufact_company_id
- select elevator_id from ele_info_manufact where manufact_company_id = '';
- -->
- </otherwise>
- </choose>
- </sql>
- <sql id="data_auth_by_user">
- <if test="limitUser != null">
- and rescue_info.elevator_id in (select elevator_id from pf_user_elevator where user_id = #{limitUser})
- </if>
- </sql>
- <select id="selectByQuery" parameterType="com.inspur.idm.media.vo.rescue.RescueInfoQuery" resultType="com.inspur.idm.media.vo.rescue.RescueInfoVO">
- select
- rescue_info.*,
- ele_info_basic.registration_code,ele_info_basic.elevator_name,ele_info_usage.estate_id,
- pf_auth_user.real_name rescueUserName,pf_auth_user.phone rescueUserPhone,
- ele_company.company_name rescueCompanyName
- from `rescue_info`
- left join ele_info_basic on rescue_info.elevator_id = ele_info_basic.elevator_id
- left join pf_auth_user on rescue_info.rescue_user = pf_auth_user.user_id
- left join ele_info_usage on rescue_info.elevator_id = ele_info_usage.elevator_id
- left join ele_company on rescue_info.rescue_company = ele_company.company_id
- <where>
- <if test="querySearch != null and querySearch != ''.toString()">
- and (ele_info_basic.elevator_name like concat('%',#{querySearch,jdbcType=VARCHAR},'%')
- or rescue_info.elevator_id like concat('%',#{querySearch,jdbcType=VARCHAR},'%')
- or rescue_info.rescue_id like concat('%',#{querySearch,jdbcType=VARCHAR},'%') )
- </if>
- <if test="elevatorId != null">
- and rescue_info.elevator_id = #{elevatorId,jdbcType=VARCHAR}
- </if>
- <if test="cityId != null">
- and ele_info_usage.city_id like concat(#{cityId,jdbcType=VARCHAR},'%')
- </if>
- <if test="estateId != null">
- and ele_info_usage.estate_id = #{estateId,jdbcType=VARCHAR}
- </if>
- <if test="elevatorId != null">
- and rescue_info.elevator_id = #{elevatorId}
- </if>
- <if test="estateIds != null and estateIds.length > 0">
- and ele_info_usage.estate_id in
- <foreach collection="estateIds" item="estateId" open="(" close=")" separator=",">
- #{estateId}
- </foreach>
- </if>
- <if test="rescueSource != null">
- and rescue_source = #{rescueSource,jdbcType=VARCHAR}
- </if>
- <if test="eventStatus != null">
- and event_status = #{eventStatus,jdbcType=INTEGER}
- </if>
- <if test="sendTimeStart != null">
- and date(send_time) >= #{sendTimeStart,jdbcType=VARCHAR}
- </if>
- <if test="sendTimeEnd != null">
- and date(send_time) <= #{sendTimeEnd,jdbcType=VARCHAR}
- </if>
- <if test="catchTimeStart != null">
- and date(catch_time) >= #{catchTimeStart,jdbcType=VARCHAR}
- </if>
- <if test="catchTimeEnd != null">
- and date(catch_time) <= #{catchTimeEnd,jdbcType=VARCHAR}
- </if>
- <if test="arrivalTimeStart != null">
- and date(arrival_time) >= #{arrivalTimeStart,jdbcType=VARCHAR}
- </if>
- <if test="arrivalTimeEnd != null">
- and date(arrival_time) <= #{arrivalTimeEnd,jdbcType=VARCHAR}
- </if>
- <if test="getoutTimeStart != null">
- and date(getout_time) >= #{getoutTimeStart,jdbcType=VARCHAR}
- </if>
- <if test="getoutTimeEnd != null">
- and date(getout_time) <= #{getoutTimeEnd,jdbcType=VARCHAR}
- </if>
- <if test="eventTimeStart != null">
- and date(event_time) >= #{eventTimeStart,jdbcType=VARCHAR}
- </if>
- <if test="eventTimeEnd != null">
- and date(event_time) <= #{eventTimeEnd,jdbcType=VARCHAR}
- </if>
- <if test="eventEndTimeStart != null">
- and date(event_end_time) >= #{eventEndTimeStart,jdbcType=VARCHAR}
- </if>
- <if test="eventEndTimeEnd != null">
- and date(event_end_time) <= #{eventEndTimeEnd,jdbcType=VARCHAR}
- </if>
- <if test="eventStatuses != null and eventStatuses.length > 0">
- and event_status in
- <foreach collection="eventStatuses" item="status" open="(" close=")" separator=",">
- #{status}
- </foreach>
- </if>
- <if test="arrivalTimeOut != null or outOfTrapTimeOut != null">
- and (
- <if test="arrivalTimeOut != null">
- (arrival_time is null and TIMESTAMPDIFF(MINUTE,event_time,sysdate()) >= #{arrivalTimeOut})
- or (arrival_time is not null and TIMESTAMPDIFF(MINUTE,event_time,arrival_time) >= #{arrivalTimeOut})
- </if>
- <if test="arrivalTimeOut != null and outOfTrapTimeOut != null">
- or
- </if>
- <if test="outOfTrapTimeOut != null">
- (getout_time is null and TIMESTAMPDIFF(MINUTE,event_time,sysdate()) >= #{outOfTrapTimeOut})
- or (getout_time is not null and TIMESTAMPDIFF(MINUTE,event_time,getout_time) >= #{outOfTrapTimeOut})
- </if>
- )
- </if>
- <include refid="data_auth_by_user"></include>
- </where>
- <choose>
- <when test="orderByClause == 'elevatorId'.toString()">
- order by rescue_info.elevator_id
- </when>
- <when test="orderByClause == 'elevatorName'.toString()">
- order by elevator_name
- </when>
- <when test="orderByClause == 'rerunTime'.toString()">
- order by rerun_time
- </when>
- <when test="orderByClause == 'eventTime'.toString()">
- order by event_time
- </when>
- <when test="orderByClause == 'arrivalTime'.toString()">
- order by arrival_time
- </when>
- <when test="orderByClause == 'getoutTime'.toString()">
- order by getout_time
- </when>
- <when test="orderByClause == 'elevatorIdDesc'.toString()">
- order by rescue_info.elevator_id desc
- </when>
- <when test="orderByClause == 'elevatorNameDesc'.toString()">
- order by elevator_name desc
- </when>
- <when test="orderByClause == 'rerunTimeDesc'.toString()">
- order by rerun_time desc
- </when>
- <when test="orderByClause == 'eventTimeDesc'.toString()">
- order by event_time desc
- </when>
- <when test="orderByClause == 'arrivalTimeDesc'.toString()">
- order by arrival_time desc
- </when>
- <when test="orderByClause == 'getoutTimeDesc'.toString()">
- order by getout_time desc
- </when>
- <otherwise>
- order by create_time desc
- </otherwise>
- </choose>
- <!-- <if test='orderByClause.contains("Desc")'> desc</if>-->
- <!-- ,rescue_id asc-->
- </select>
- <select id="selectMaxId" resultType="string">
- select rescue_id from `rescue_info`
- where rescue_id like concat(#{rescueId,jdbcType=VARCHAR},'%') order by LENGTH(rescue_id) desc,rescue_id desc limit 1
- </select>
- <select id="getTotalPersonNum" resultType="Integer">
- SELECT IFNULL(SUM(personal_num),0) FROM rescue_info
- <where>
- <if test="elevatorId != null">
- and elevator_id = #{elevatorId,jdbcType=VARCHAR}
- </if>
- <include refid="data_auth_by_user"></include>
- </where>
- </select>
- <select id="countByQuery" resultType="Integer">
- select count(0) from `rescue_info`
- <where>
- <if test="querySearch != null and querySearch != ''.toString()">
- and elevator_id = #{querySearch,jdbcType=VARCHAR}
- </if>
- <if test="eventStatus != null">
- and event_status = #{eventStatus,jdbcType=INTEGER}
- </if>
- <if test="arrivalTimeOut != null">
- and ((arrival_time is null and TIMESTAMPDIFF(MINUTE,event_time,sysdate()) >= #{arrivalTimeOut})
- or (arrival_time is not null and TIMESTAMPDIFF(MINUTE,event_time,arrival_time) >= #{arrivalTimeOut}))
- </if>
- <if test="outOfTrapTimeOut != null">
- and ((getout_time is null and TIMESTAMPDIFF(MINUTE,event_time,sysdate()) >= #{outOfTrapTimeOut})
- or (getout_time is not null and TIMESTAMPDIFF(MINUTE,event_time,getout_time) >= #{outOfTrapTimeOut}))
- </if>
- <if test="eventTimeStart != null">
- and date(event_time) = #{eventTimeStart,jdbcType=VARCHAR}
- </if>
- <include refid="data_auth_by_user"></include>
- </where>
- </select>
- <select id="getWaitRecordList" resultType="com.inspur.idm.media.vo.rescue.RescueInfoVO">
- select * from `rescue_info`
- <where>
- elevator_id = #{elevatorId,jdbcType=VARCHAR} and getout_time is not null and getout_time < now() and video_path is null and getout_time > timestampadd(day, -1, now())
- and event_time > timestampadd(day, -1, now())
- <!-- 先查24h以内的,太久远的不处理 -->
- </where>
- order by getout_time
- </select>
- <update id="updateRescueVideo">
- update `rescue_info`
- <set>
- <if test="videoPath != null">
- `video_path` = #{videoPath,jdbcType=VARCHAR},
- </if>
- <if test="imgPath != null">
- `img_path` = #{imgPath,jdbcType=VARCHAR}
- </if>
- </set>
- <where>
- rescue_id = #{rescueId,jdbcType=VARCHAR}
- </where>
- </update>
- <update id="updateTrapVideo">
- update `rescue_info`
- <set>
- <if test="trapVideoPath != null">
- `trap_video_path` = #{trapVideoPath,jdbcType=VARCHAR},
- </if>
- <if test="imgPath != null">
- `img_path` = #{imgPath,jdbcType=VARCHAR}
- </if>
- </set>
- <where>
- rescue_id = #{rescueId,jdbcType=VARCHAR}
- </where>
- </update>
- <update id="updateFaultId">
- update `rescue_info`
- <set>
- `fault_id` = #{faultId,jdbcType=VARCHAR}
- </set>
- <where>
- rescue_id = #{rescueId,jdbcType=VARCHAR}
- </where>
- </update>
- <select id="getLastTrapStatus" resultType="java.lang.Integer">
- select IFNULL(event_status, 0) from `rescue_info`
- <where>
- `elevator_id` = #{elevatorId,jdbcType=VARCHAR} and `create_time` >= timestampadd(day, -1, now())
- </where>
- order by create_time desc limit 1
- </select>
- <select id="selectInfoById" resultType="com.inspur.idm.media.po.rescue.RescueInfo">
- select * from `rescue_info`
- <where>
- rescue_id = #{rescueId,jdbcType=VARCHAR}
- </where>
- <include refid="data_auth_by_user"></include>
- </select>
- </mapper>
|