<?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.sckw.slope.detection.dao.mysql.KwsReportDataMapper">
  <resultMap id="BaseResultMap" type="com.sckw.slope.detection.model.dos.mysql.KwsReportData">
    <!--@mbg.generated-->
    <!--@Table kws_report_data-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="template_id" jdbcType="BIGINT" property="templateId" />
      <result column="company_id" jdbcType="VARCHAR" property="companyId" />
    <result column="project_id" jdbcType="BIGINT" property="projectId" />
    <result column="project_name" jdbcType="VARCHAR" property="projectName" />
    <result column="device_id" jdbcType="BIGINT" property="deviceId" />
    <result column="device_name" jdbcType="VARCHAR" property="deviceName" />
    <result column="sn_code" jdbcType="VARCHAR" property="snCode" />
    <result column="alias" jdbcType="VARCHAR" property="alias" />
    <result column="model_id" jdbcType="BIGINT" property="modelId" />
    <result column="model_name" jdbcType="VARCHAR" property="modelName" />
    <result column="device_type" jdbcType="VARCHAR" property="deviceType" />
    <result column="device_label" jdbcType="VARCHAR" property="deviceLabel" />
    <result column="lat" jdbcType="VARCHAR" property="lat" />
    <result column="lng" jdbcType="VARCHAR" property="lng" />
    <result column="alt" jdbcType="VARCHAR" property="alt" />
    <result column="alarm_type" jdbcType="INTEGER" property="alarmType" />
    <result column="alarm_title" jdbcType="VARCHAR" property="alarmTitle" />
    <result column="content" jdbcType="VARCHAR" property="content" />
    <result column="items" jdbcType="VARCHAR" property="items" />
    <result column="file_url" jdbcType="VARCHAR" property="fileUrl" />
    <result column="file_size"  property="fileSize" />
    <result column="alarm_time" jdbcType="TIMESTAMP" property="alarmTime" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, template_id, project_id, project_name, device_id, device_name, sn_code, `alias`, 
    model_id, model_name, device_type, device_label, lat, lng, alt, alarm_type, alarm_title, 
    content, items, alarm_time, create_time,company_id,file_url,file_size
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from kws_report_data
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--@mbg.generated-->
    delete from kws_report_data
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsReportData">
    <!--@mbg.generated-->
    insert into kws_report_data (id,mountain_id,company_id, template_id, project_id,
      project_name, file_size, file_url,create_time,del_flag
      )
    values (#{id,jdbcType=BIGINT}, #{mountainId,jdbcType=BIGINT}, #{companyId,jdbcType=BIGINT},
      #{templateId,jdbcType=VARCHAR}, #{projectId,jdbcType=BIGINT}, #{projectName,jdbcType=VARCHAR},
      #{fileSize,jdbcType=VARCHAR}, #{fileUrl,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{delFlag,jdbcType=BIGINT})
  </insert>
  <insert id="insertSelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsReportData">
    <!--@mbg.generated-->
    insert into kws_report_data
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="templateId != null">
        template_id,
      </if>
      <if test="projectId != null">
        project_id,
      </if>
      <if test="projectName != null">
        project_name,
      </if>
      <if test="deviceId != null">
        device_id,
      </if>
      <if test="deviceName != null">
        device_name,
      </if>
      <if test="snCode != null">
        sn_code,
      </if>
      <if test="alias != null">
        `alias`,
      </if>
      <if test="modelId != null">
        model_id,
      </if>
      <if test="modelName != null">
        model_name,
      </if>
      <if test="deviceType != null">
        device_type,
      </if>
      <if test="deviceLabel != null">
        device_label,
      </if>
      <if test="lat != null">
        lat,
      </if>
      <if test="lng != null">
        lng,
      </if>
      <if test="alt != null">
        alt,
      </if>
      <if test="alarmType != null">
        alarm_type,
      </if>
      <if test="alarmTitle != null">
        alarm_title,
      </if>
      <if test="content != null">
        content,
      </if>
      <if test="items != null">
        items,
      </if>
      <if test="alarmTime != null">
        alarm_time,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="templateId != null">
        #{templateId,jdbcType=BIGINT},
      </if>
      <if test="projectId != null">
        #{projectId,jdbcType=BIGINT},
      </if>
      <if test="projectName != null">
        #{projectName,jdbcType=VARCHAR},
      </if>
      <if test="deviceId != null">
        #{deviceId,jdbcType=BIGINT},
      </if>
      <if test="deviceName != null">
        #{deviceName,jdbcType=VARCHAR},
      </if>
      <if test="snCode != null">
        #{snCode,jdbcType=VARCHAR},
      </if>
      <if test="alias != null">
        #{alias,jdbcType=VARCHAR},
      </if>
      <if test="modelId != null">
        #{modelId,jdbcType=BIGINT},
      </if>
      <if test="modelName != null">
        #{modelName,jdbcType=VARCHAR},
      </if>
      <if test="deviceType != null">
        #{deviceType,jdbcType=VARCHAR},
      </if>
      <if test="deviceLabel != null">
        #{deviceLabel,jdbcType=VARCHAR},
      </if>
      <if test="lat != null">
        #{lat,jdbcType=VARCHAR},
      </if>
      <if test="lng != null">
        #{lng,jdbcType=VARCHAR},
      </if>
      <if test="alt != null">
        #{alt,jdbcType=VARCHAR},
      </if>
      <if test="alarmType != null">
        #{alarmType,jdbcType=INTEGER},
      </if>
      <if test="alarmTitle != null">
        #{alarmTitle,jdbcType=VARCHAR},
      </if>
      <if test="content != null">
        #{content,jdbcType=VARCHAR},
      </if>
      <if test="items != null">
        #{items,jdbcType=VARCHAR},
      </if>
      <if test="alarmTime != null">
        #{alarmTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsReportData">
    <!--@mbg.generated-->
    update kws_report_data
    <set>
      <if test="templateId != null">
        template_id = #{templateId,jdbcType=BIGINT},
      </if>
      <if test="projectId != null">
        project_id = #{projectId,jdbcType=BIGINT},
      </if>
      <if test="projectName != null">
        project_name = #{projectName,jdbcType=VARCHAR},
      </if>
      <if test="deviceId != null">
        device_id = #{deviceId,jdbcType=BIGINT},
      </if>
      <if test="deviceName != null">
        device_name = #{deviceName,jdbcType=VARCHAR},
      </if>
      <if test="snCode != null">
        sn_code = #{snCode,jdbcType=VARCHAR},
      </if>
      <if test="alias != null">
        `alias` = #{alias,jdbcType=VARCHAR},
      </if>
      <if test="modelId != null">
        model_id = #{modelId,jdbcType=BIGINT},
      </if>
      <if test="modelName != null">
        model_name = #{modelName,jdbcType=VARCHAR},
      </if>
      <if test="deviceType != null">
        device_type = #{deviceType,jdbcType=VARCHAR},
      </if>
      <if test="deviceLabel != null">
        device_label = #{deviceLabel,jdbcType=VARCHAR},
      </if>
      <if test="lat != null">
        lat = #{lat,jdbcType=VARCHAR},
      </if>
      <if test="lng != null">
        lng = #{lng,jdbcType=VARCHAR},
      </if>
      <if test="alt != null">
        alt = #{alt,jdbcType=VARCHAR},
      </if>
      <if test="alarmType != null">
        alarm_type = #{alarmType,jdbcType=INTEGER},
      </if>
      <if test="alarmTitle != null">
        alarm_title = #{alarmTitle,jdbcType=VARCHAR},
      </if>
      <if test="content != null">
        content = #{content,jdbcType=VARCHAR},
      </if>
      <if test="items != null">
        items = #{items,jdbcType=VARCHAR},
      </if>
      <if test="alarmTime != null">
        alarm_time = #{alarmTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsReportData">
    <!--@mbg.generated-->
    update kws_report_data
    set template_id = #{templateId,jdbcType=BIGINT},
      project_id = #{projectId,jdbcType=BIGINT},
      project_name = #{projectName,jdbcType=VARCHAR},
      device_id = #{deviceId,jdbcType=BIGINT},
      device_name = #{deviceName,jdbcType=VARCHAR},
      sn_code = #{snCode,jdbcType=VARCHAR},
      `alias` = #{alias,jdbcType=VARCHAR},
      model_id = #{modelId,jdbcType=BIGINT},
      model_name = #{modelName,jdbcType=VARCHAR},
      device_type = #{deviceType,jdbcType=VARCHAR},
      device_label = #{deviceLabel,jdbcType=VARCHAR},
      lat = #{lat,jdbcType=VARCHAR},
      lng = #{lng,jdbcType=VARCHAR},
      alt = #{alt,jdbcType=VARCHAR},
      alarm_type = #{alarmType,jdbcType=INTEGER},
      alarm_title = #{alarmTitle,jdbcType=VARCHAR},
      content = #{content,jdbcType=VARCHAR},
      items = #{items,jdbcType=VARCHAR},
      alarm_time = #{alarmTime,jdbcType=TIMESTAMP},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>

  <select id="selectDataAndTemplate" resultType="com.sckw.slope.detection.model.vo.ReportDetailVO">

    </select>

  <select id="selectListByReportNameAndProjectId" resultType="com.sckw.slope.detection.model.vo.ReportStatementVO">
      SELECT b.`name`       AS reportName,
             b.type         AS reportType,
             a.project_name AS projectName,
             a.project_id AS projectId,
             a.file_size    AS fileSize,
             a.create_time  AS createTime,
             a.id           as id
      FROM kws_report_data a
               LEFT JOIN kws_report_template b ON a.template_id = b.id
      WHERE a.mountain_id = b.mountain_id
        AND b.del_flag = 0
        and a.del_flag = 0
      <if test="query.projectId != null and query.projectId != ''">
          and a.project_id = #{query.projectId}
      </if>
      <if test="query.reportName != null and query.reportName != ''">
          and b.name like concat('%', #{query.reportName}
              , '%')
      </if>
      <if test="query.reportType != null and query.reportType != ''">
          and b.type = #{query.reportType}
      </if>
      <if test="query.startTime != null and query.startTime != ''">
          and a.create_time &gt;= #{query.startTime}
      </if>
      <if test="query.endTime != null and query.endTime != ''">
          and a.create_time &lt;= #{query.endTime}
      </if>
      <if test="mountainId != null and mountainId != ''">
          and a.mountain_id = #{mountainId}
      </if>
  </select>
</mapper>