PowerOffAlarmMapper.xml 6.29 KB
<?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="cn.com.glsx.dj.reports.mapper.PowerOffAlarmMapper">
  	<resultMap id="BaseResultMap" type="cn.com.glsx.dj.reports.model.PowerOffAlarm">
	    <id column="id" jdbcType="INTEGER" property="id" />
	    <result column="sn" jdbcType="VARCHAR" property="sn" />
	    <result column="type" jdbcType="INTEGER" property="type" />
	    <result column="restore_times" jdbcType="INTEGER" property="restoreTimes" />
	    <result column="alarm_times" jdbcType="INTEGER" property="alarmTimes" />
	    <result column="max_duration" jdbcType="DECIMAL" property="maxDuration" />
	    <result column="min_duration" jdbcType="DECIMAL" property="minDuration" />
	    <result column="avg_duration" jdbcType="DECIMAL" property="avgDuration" />
	    <result column="alarm_time" jdbcType="TIMESTAMP" property="alarmTime" />
	    <result column="voltage" jdbcType="DECIMAL" property="voltage" />
	    <result column="alarm_place" jdbcType="VARCHAR" property="alarmPlace" />
	    <result column="lng" jdbcType="VARCHAR" property="lng" />
	    <result column="lat" jdbcType="VARCHAR" property="lat" />
	    <result column="merchant_id" jdbcType="INTEGER" property="merchantId" />
	    <result column="created_by" jdbcType="VARCHAR" property="createdBy" />
	    <result column="created_date" jdbcType="TIMESTAMP" property="createdDate" />
	    <result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
	    <result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate" />
	    <result column="deleted_flag" jdbcType="CHAR" property="deletedFlag" />
  	</resultMap>
  
  	<resultMap id="BaseResultDTOMap" type="cn.com.glsx.dj.reports.dto.PowerOffAlarmDTO" extends="BaseResultMap">
	    
  	</resultMap>
  
  	<resultMap id="BaseResultVOMap" type="cn.com.glsx.dj.reports.vo.PowerOffAlarmVO">
	    <id column="id" jdbcType="INTEGER" property="id" />
	    <result column="sn" jdbcType="VARCHAR" property="sn" />
	    <result column="alarm_place" jdbcType="VARCHAR" property="alarmPlace" />
		<result column="alarm_time" jdbcType="VARCHAR" property="alarmTime" />
		<result column="activeDate" jdbcType="VARCHAR" property="activeDate" />
		<result column="stand_no" jdbcType="VARCHAR" property="standNo" />
		<result column="name" jdbcType="VARCHAR" property="name" />
		<result column="is_active" jdbcType="VARCHAR" property="activeFlag" />
		<result column="vehicle_status" jdbcType="VARCHAR" property="vehicleStatus" />
		<result column="shopName" jdbcType="VARCHAR" property="shopName" />
  	</resultMap>
  
  	<sql id="Base_Column_List">
    	id, sn, type, restore_times, alarm_times, max_duration, min_duration, avg_duration, 
    	alarm_time, voltage, alarm_place, lng, lat, merchant_id, created_by, created_date, 
    	updated_by, updated_date, deleted_flag
  	</sql>
  
  	<sql id="baseWhereClause" >
    	<where>
			<if test="record.id != null">
				and id = #{record.id,jdbcType=INTEGER}
			</if>
			<if test="record.sn != null and record.sn !=''">
				and sn = #{record.sn,jdbcType=VARCHAR}
			</if>
			<if test="record.createdDate != null and record.createdDate !=''">
				and created_date = #{record.createdDate,jdbcType=TIMESTAMP}
			</if>
			<if test="record.updatedDate != null and record.updatedDate !=''">
				and updated_date = #{record.updatedDate,jdbcType=TIMESTAMP}
			</if>
			<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
	            and merchant_id in
	            <foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
		            #{merchantId}
		        </foreach>
			</if>
			and deleted_flag = 'N'
    	</where>
  	</sql>
  
  	<select id="listBasic" parameterType="cn.com.glsx.dj.reports.dto.PowerOffAlarmDTO" resultMap="BaseResultDTOMap">
  		select <include refid="Base_Column_List"></include> 
  		from dj_power_off_alarm 
  		<include refid="baseWhereClause"/>
  	</select>
  
  	<select id="powerOffReportsList" parameterType="cn.com.glsx.dj.reports.dto.PowerOffAlarmDTO" resultMap="BaseResultVOMap">
  		SELECT 
      	poa.id,
      	poa.alarm_place ,
      	DATE_FORMAT(poa.alarm_time,'%Y-%m-%d %H:%i:%s') AS alarm_time,
      	d.sn,
      	DATE_FORMAT(d.active_date,'%Y-%m-%d %H:%i:%s') AS activeDate,
      	iv.stand_no,
      	iv.name,
      	d.is_active,
      	m.merchant_name AS shopName
      	FROM
      	dj_insure_device d LEFT JOIN dj_power_off_alarm poa ON d.sn = poa.sn
		INNER JOIN dj_insure_vehicle iv ON d.vehicle_id=iv.id
		LEFT JOIN dj_system_merchant m ON iv.merchant_id=m.merchant_id
		LEFT JOIN dj_insure_order o on o.vehicle_id=iv.id
		WHERE poa.type=1
		AND iv.deleted_flag='N'
		AND d.deleted_flag='N'
		AND o.insurance_status=1
		AND o.name NOT LIKE '%\_'
		<if test="record.sn != null and record.sn !=''">
			and d.sn LIKE CONCAT('%',#{record.sn,jdbcType=VARCHAR},'%')
		</if>
		<if test="record.name != null and record.name !=''">
			and iv.name LIKE CONCAT('%',#{record.name,jdbcType=VARCHAR},'%')
		</if>
		<if test="record.shopName != null and record.shopName !=''">
			and m.merchant_name LIKE CONCAT('%',#{record.shopName,jdbcType=VARCHAR},'%')
		</if>
		<if test="record.standNo != null and record.standNo !=''">
			and iv.stand_no LIKE CONCAT('%',#{record.standNo,jdbcType=VARCHAR},'%')
		</if>
		<if test="record.alarmPlace != null and record.alarmPlace !=''">
			and poa.alarm_place LIKE CONCAT('%',#{record.alarmPlace,jdbcType=VARCHAR},'%')
		</if>
       	<if test="record.warnStartTime1 != null and record.warnStartTime2!=null and record.warnStartTime1 !='' and record.warnStartTime2 !=''">
           	and poa.alarm_time between #{record.warnStartTime1,jdbcType=VARCHAR} and #{record.warnStartTime2,jdbcType=VARCHAR}
       	</if>
       	<if test="record.activeDate1 != null and record.activeDate2!=null and record.activeDate1 !='' and record.activeDate2 !=''">
           	and d.active_date between #{record.activeDate1,jdbcType=VARCHAR} and #{record.activeDate2,jdbcType=VARCHAR}
       	</if>
		<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
	        and iv.merchant_id in
	        <foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
	        	#{merchantId}
	        </foreach>
		</if>
  		ORDER BY poa.alarm_time DESC
  	</select>
  
</mapper>