<?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.jpsoft.shinestar.modules.base.dao.CheckNumCompanyDAO">


    <sql id="Base_Column_List">
    id_,
    company_id,
    check_num,
    normal_num,
    abnormal_num,
    record_time,
    del_flag,
    create_by,
    create_time,
    update_by,
    update_time
</sql>
    <resultMap id="CheckNumCompanyMap" type="com.jpsoft.shinestar.modules.base.entity.CheckNumCompany">
        <id property="id" column="id_"/>
        <result property="companyId" column="company_id"/>
        <result property="checkNum" column="check_num" />
        <result property="normalNum" column="normal_num" />
        <result property="abnormalNum" column="abnormal_num"/>
        <result property="recordTime" column="record_time"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <select id="get" parameterType="long" resultMap="CheckNumCompanyMap">
        select *  from base_check_num_company where id_=#{0}
    </select>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.CheckNumCompany">
    insert into base_check_num_company
    (company_id,check_num,normal_num,abnormal_num,record_time,del_flag,
    create_by,create_time,update_by,update_time)
    values
    (
    #{companyId,jdbcType=VARCHAR}
    ,#{checkNum,jdbcType=NUMERIC}
    ,#{normalNum,jdbcType=NUMERIC}
    ,#{abnormalNum,jdbcType=NUMERIC}
    ,#{recordTime,jdbcType=VARCHAR}
    ,#{delFlag,jdbcType= NUMERIC }
    ,#{createBy,jdbcType=VARCHAR}
    ,#{createTime,jdbcType= TIMESTAMP }
    ,#{updateBy,jdbcType=VARCHAR}
    ,#{updateTime,jdbcType= TIMESTAMP }
    )
</insert>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.CheckNumCompany">
        update base_check_num_company
        <set>
            <if test="companyId!=null">
                company_id=#{companyId,jdbcType=VARCHAR},
            </if>
            <if test="checkNum!=null">
                check_num=#{checkNum,jdbcType=NUMERIC},
            </if>
            <if test="normalNum!=null">
                normal_num=#{normalNum,jdbcType=NUMERIC},
            </if>

            <if test="abnormalNum!=null">
                abnormal_num=#{abnormalNum,jdbcType=NUMERIC},
            </if>
            <if test="recordTime!=null">
                record_time=#{recordTime,jdbcType=VARCHAR},
            </if>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </if>
            <if test="createBy!=null">
                create_by=#{createBy,jdbcType=VARCHAR},
            </if>
            <if test="createTime!=null">
                create_time=#{createTime,jdbcType= TIMESTAMP },
            </if>
            <if test="updateBy!=null">
                update_by=#{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="updateTime!=null">
                update_time=#{updateTime,jdbcType= TIMESTAMP },
            </if>
        </set>
        where id_=#{id}
    </update>
    <delete id="delete" parameterType="long">
        delete from base_check_num_company where id_=#{id,jdbcType=NUMERIC}
    </delete>
    <select id="list" resultMap="CheckNumCompanyMap">
        select * from base_check_num_company where del_flag = 0
    </select>
    <select id="search" resultMap="CheckNumCompanyMap"></select>

<!--auto generated by MybatisCodeHelper on 2020-03-27-->
    <select id="findByCompanyIdAndRecordTime" resultMap="CheckNumCompanyMap">
        select
        <include refid="Base_Column_List"/>
        from base_check_num_company
        where company_id=#{companyId} and record_time=#{recordTime} and del_flag = false limit 1
    </select>
    <select id="getDayCheckNum" parameterType="String" resultType="Integer">
        select sum(check_num) from  base_check_num_company where del_flag = 0
        <if test="recordTime!=null">
           and record_time = #{recordTime}
        </if>
    </select>

    <select id="getDayCheckNumByCompanyList"  resultType="Integer">
        select sum(check_num) from  base_check_num_company where del_flag = 0
        and
        company_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">   #{item.id}
        </foreach>

        <if test="recordTime!=null">
            and record_time = #{recordTime}
        </if>
    </select>


    <select id="findByRecordTime" parameterType="String" resultMap="CheckNumCompanyMap">
        select
        *
        from base_check_num_company
        where record_time=#{recordTime} and del_flag = 0
    </select>

    <select id="getDayNormalNumByCompanyList" resultType="Integer">
        select sum(normal_num) from  base_check_num_company where del_flag = 0
        <if test="recordTime!=null">
            and record_time = #{recordTime}
        </if>

        <if test="list!=null">
            and
            company_id in
            <foreach collection="list" index="index" item="item" open="(" separator="," close=")">   #{item.id}
            </foreach>
        </if>
    </select>

    <select id="getDayAbnormalNumByCompanyList" resultType="Integer">
        select sum(abnormal_num) from  base_check_num_company where del_flag = 0
        <if test="recordTime!=null">
            and record_time = #{recordTime}
        </if>

        <if test="list!=null">
            and
            company_id in
            <foreach collection="list" index="index" item="item" open="(" separator="," close=")">   #{item.id}
            </foreach>
        </if>
    </select>
</mapper>
