<?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.ho.business.mapper.ColCountMapper">

    <sql id="Base_Column_List">
        id
        ,station_id,device_type,col,col_name,`offset`,count_method,count_flag,create_time,update_time,identify_num
    </sql>

    <insert id="insertColCount" parameterType="com.ho.business.entity.ColCount">
        insert into col_count
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stationId != null">station_id,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="col != null">col,</if>
            <if test="colName != null">col_name,</if>
            <if test="offset != null">`offset`,</if>
            <if test="countMethod != null">count_method,</if>
            <if test="countFlag != null">count_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="identifyNum != null">identify_num,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stationId != null">#{stationId},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="col != null">#{col},</if>
            <if test="colName != null">#{colName},</if>
            <if test="offset != null">#{offset},</if>
            <if test="countMethod != null">#{countMethod},</if>
            <if test="countFlag != null">#{countFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="identifyNum != null">#{identifyNum},</if>
        </trim>
    </insert>

    <insert id="insertList" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
        insert into col_count (station_id,device_type,col,col_name,`offset`,count_method,count_flag,create_time)
        values
        <foreach item="item" collection="list" index="index" separator=",">
            (
            #{item.stationId},#{item.deviceType},#{item.col},
            #{item.colName},#{item.offset},#{item.countMethod},#{item.countFlag},now()
            )
        </foreach>

    </insert>

    <update id="updateById" parameterType="com.ho.business.entity.ColCount">
        update col_count
        <set>
            <if test="deviceType != null">device_type = #{deviceType},</if>
            <if test="col != null">col = #{col},</if>
            <if test="colName != null">col_name = #{colName},</if>
            <if test="offset != null">`offset` = #{offset},</if>
            <if test="countMethod != null">count_method = #{countMethod},</if>
            <if test="countFlag != null">count_flag = #{countFlag},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="identifyNum != null">identify_num = #{identifyNum},</if>
        </set>
        where id = #{id}
    </update>

    <select id="selectByParam" resultType="com.ho.business.vo.resp.colCount.ColCountResp">
        SELECT
        <include refid="Base_Column_List"/>
        FROM col_count
        <where>
            <if test="stationId != null">and station_id = #{stationId}</if>
            <if test="deviceType != null">and device_type = #{deviceType}</if>
            <if test="col != null">and col = #{col}</if>
            <if test="colName != null">and col_name = #{colName}</if>
            <if test="name !=null ">and (col_name like concat('%',#{name},'%') or col like concat('%',#{name},'%')) </if>
            <if test="offset != null">and `offset` = #{offset}</if>
            <if test="countMethod != null">and count_method = #{countMethod}</if>
            <if test="countFlag != null">and count_flag = #{countFlag}</if>
            <if test="ids != null and ids.size() != 0">
                and station_id in
                <foreach collection="ids" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
            <if test="cols != null and cols.size() != 0">
                and col in
                <foreach collection="cols" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <delete id="deleteByList">
        delete
        from col_count
        <where>
            <if test="ids != null and ids.size() != 0">
                and id in
                <foreach collection="ids" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
    </delete>

    <delete id="deleteStationId">
        delete
        from col_count
        where station_id = #{stationId}
    </delete>
</mapper>
