<?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.KwsReportTemplateMapper">
    <resultMap id="BaseResultMap" type="com.sckw.slope.detection.model.dos.mysql.KwsReportTemplate">
        <!--@mbg.generated-->
        <!--@Table kws_report_template-->
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="type" jdbcType="INTEGER" property="type"/>
        <result column="company_id" jdbcType="VARCHAR" property="companyId"/>
        <result column="mountain_id" jdbcType="VARCHAR" property="mountainId"/>
        <result column="project_id" jdbcType="VARCHAR" property="projectId"/>
        <result column="part_names" jdbcType="VARCHAR" property="partNames"/>
        <result column="tabulation_time" jdbcType="VARCHAR" property="tabulationTime"/>
        <result column="intergration_names" jdbcType="VARCHAR" property="intergrationNames"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
        <result column="create_by" jdbcType="BIGINT" property="createBy"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
    </resultMap>
    <sql id="Base_Column_List">
        <!--@mbg.generated-->
        id,
        `name`,
        `type`,
        part_names,
        project_id,
        intergration_names,
        `status`,
        create_by,
        create_time,
        update_by,
        update_time,
        del_flag,
        company_id,
        mountain_id,
        tabulation_time
    </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        <!--@mbg.generated-->
        select
        <include refid="Base_Column_List"/>
        from kws_report_template
        where id = #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        <!--@mbg.generated-->
        delete
        from kws_report_template
        where id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insertSelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsReportTemplate">
        <!--@mbg.generated-->
        insert into kws_report_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                `name`,
            </if>
            <if test="type != null">
                `type`,
            </if>
            <if test="partNames != null">
                part_names,
            </if>
            <if test="intergrationNames != null">
                intergration_names,
            </if>
            <if test="status != null">
                `status`,
            </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="delFlag != null">
                del_flag,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=BIGINT},
            </if>
            <if test="name != null">
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="type != null">
                #{type,jdbcType=INTEGER},
            </if>
            <if test="partNames != null">
                #{partNames,jdbcType=VARCHAR},
            </if>
            <if test="intergrationNames != null">
                #{intergrationNames,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                #{status,jdbcType=TINYINT},
            </if>
            <if test="createBy != null">
                #{createBy,jdbcType=BIGINT},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateBy != null">
                #{updateBy,jdbcType=BIGINT},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="delFlag != null">
                #{delFlag,jdbcType=TINYINT},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsReportTemplate">
        <!--@mbg.generated-->
        update kws_report_template
        <set>
            <if test="name != null">
                `name` = #{name,jdbcType=VARCHAR},
            </if>
            <if test="type != null">
                `type` = #{type,jdbcType=INTEGER},
            </if>
            <if test="partNames != null">
                part_names = #{partNames,jdbcType=VARCHAR},
            </if>
            <if test="intergrationNames != null">
                intergration_names = #{intergrationNames,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                `status` = #{status,jdbcType=TINYINT},
            </if>
            <if test="createBy != null">
                create_by = #{createBy,jdbcType=BIGINT},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateBy != null">
                update_by = #{updateBy,jdbcType=BIGINT},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="delFlag != null">
                del_flag = #{delFlag,jdbcType=TINYINT},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsReportTemplate">
        <!--@mbg.generated-->
        update kws_report_template
        set `name`             = #{name,jdbcType=VARCHAR},
            `type`             = #{type,jdbcType=INTEGER},
            part_names         = #{partNames,jdbcType=VARCHAR},
            intergration_names = #{intergrationNames,jdbcType=VARCHAR},
            `status`           = #{status,jdbcType=TINYINT},
            create_by          = #{createBy,jdbcType=BIGINT},
            create_time        = #{createTime,jdbcType=TIMESTAMP},
            update_by          = #{updateBy,jdbcType=BIGINT},
            update_time        = #{updateTime,jdbcType=TIMESTAMP},
            del_flag           = #{delFlag,jdbcType=TINYINT}
        where id = #{id,jdbcType=BIGINT}
    </update>

    <select id="selectListByReportNameAndProjectIdAndCompany"
            resultType="com.sckw.slope.detection.model.vo.ReportStatementVO">
        SELECT STATUS,
               `name`          AS reportName,
               type            AS reportType,
               project_id      AS projectId,
               tabulation_time AS tabulationTime,
               create_time     AS createTime,
               id              as id
        FROM kws_report_template
        WHERE del_flag = 0
        <if test="query.projectId != null and query.projectId != ''">
            and project_id = #{query.projectId}
        </if>
        <if test="companyId != null and companyId != ''">
            and mountain_id = #{companyId,jdbcType=VARCHAR}
        </if>
        <if test="query.name != null and query.name != ''">
            and name like concat('%', #{query.name}
            , '%')
        </if>
        <if test="query.type != null and query.type != ''">
            and type =#{query.type}
        </if>
    </select>

    <select id="selectListByReportNameAndProjectId" resultType="com.sckw.slope.detection.model.vo.ReportStatementVO">
    </select>

    <select id="selectDataAndTemplate" resultType="com.sckw.slope.detection.model.vo.ReportDetailVO">
        SELECT a.id,
               a.part_names         AS partNames,
               a.intergration_names AS intergrationNames,
               a.type               AS type,
               a.`status`           AS STATUS,
               b.NAME               AS NAME,

        FROM kws_report_template a
                 LEFT JOIN kws_report_data b ON a.id = b.template_id
        WHERE id = #{id,jdbcType=BIGINT}
    </select>

    <select id="selectDeviceByProjectId" resultType="com.sckw.slope.detection.model.vo.DeviceVo">
        select DISTINCT d.id,d.sn_code,d.name from kws_device_reference as r
            inner join kws_device as d on r.device_id=d.id
            inner join kws_project_device as p on p.device_id=d.id
        where p.del_flag=0 and d.del_flag=0 and r.del_flag=0
        and project_id=#{projectId}
        <if test="list != null">
            and r.item in
            <foreach collection="list" index="index" separator="," open="(" close=")" item="list">
                #{list}
            </foreach>
        </if>
    </select>
</mapper>