<?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.TotalCheckCompanyDAO">
    <sql id="Base_Column_List">
    id_,
    company_id,
    normal_day,
    total_check_num,
    total_abnormal_num,
    del_flag,
    create_by,
    create_time,
    update_by,
    update_time,
    abnormal_time
</sql>
    <resultMap id="TotalCheckCompanyMap" type="com.jpsoft.shinestar.modules.base.entity.TotalCheckCompany">
        <id property="id" column="id_"/>
        <result property="companyId" column="company_id"/>
        <result property="normalDay" column="normal_day" />
        <result property="totalCheckNum" column="total_check_num" />
        <result property="totalAbnormalNum" column="total_abnormal_num"/>
        <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"/>
        <result property="abnormalTime" column="abnormal_time"/>
    </resultMap>
    <select id="get" parameterType="long" resultMap="TotalCheckCompanyMap">
            select * from base_total_check_company where id_=#{0} and del_flag = false
    </select>

    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.TotalCheckCompany">
        insert into base_total_check_company
        (company_id,normal_day,total_check_num,total_abnormal_num,del_flag,
        create_by,create_time,update_by,update_time,abnormal_time)
        values
        (
        #{companyId,jdbcType=VARCHAR}
        ,#{normalDay,jdbcType=NUMERIC}
        ,#{totalCheckNum,jdbcType=NUMERIC}
        ,#{totalAbnormalNum,jdbcType=NUMERIC}
        ,#{delFlag,jdbcType= NUMERIC }
        ,#{createBy,jdbcType=VARCHAR}
        ,#{createTime,jdbcType= TIMESTAMP }
        ,#{updateBy,jdbcType=VARCHAR}
        ,#{updateTime,jdbcType= TIMESTAMP }
        ,#{abnormalTime,jdbcType= TIMESTAMP }
        )
    </insert>
    <update id="update" parameterType = "com.jpsoft.shinestar.modules.base.entity.TotalCheckCompany">
        update base_total_check_company
        <set>
            <if test="companyId!=null">
                company_id=#{companyId,jdbcType=VARCHAR},
            </if>
            <if test="normalDay!=null">
                normal_day=#{normalDay,jdbcType=NUMERIC},
            </if>
            <if test="totalCheckNum!=null">
                total_check_num=#{totalCheckNum,jdbcType=NUMERIC},
            </if>

            <if test="totalAbnormalNum!=null">
                total_abnormal_num=#{totalAbnormalNum,jdbcType=NUMERIC},
            </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>
            <if test="abnormalTime !=null">
                abnormal_time=#{abnormalTime,jdbcType= TIMESTAMP },
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="findMinNormalDay" resultType="Integer">
        select min(normal_day) from base_total_check_company where del_flag = false
    </select>

    <select id="findMinNormalDayByCompanyList" resultType="Integer">
        select min(normal_day) from base_total_check_company where company_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">   #{item.id}
        </foreach>
        and del_flag = 0

    </select>

    <select id="getTotalAbnormalNum" resultType="Integer">
        select sum(total_abnormal_num) from  base_total_check_company where del_flag = 0
    </select>

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

    <select id="findByCompanyId" parameterType="String" resultMap="TotalCheckCompanyMap">
        select * from base_total_check_company where company_id = #{id} and del_flag = 0 limit 1
    </select>

<!--auto generated by MybatisCodeHelper on 2020-03-28-->
    <select id="getTotalCheckNum" resultType="Integer">
        select sum(total_check_num) from base_total_check_company where del_flag =0
        <if test="list!=null">
            and
            company_id in
            <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
                #{item.id}
            </foreach>
        </if>
    </select>

<!--auto generated by MybatisCodeHelper on 2020-04-04-->
    <select id="findAll" resultMap="TotalCheckCompanyMap">
        select
        <include refid="Base_Column_List"/>
        from base_total_check_company where del_flag = 0
    </select>

    <select id="findMaxAbnormalTimeByCompanyList" resultType="Date">
        <![CDATA[
        select max(abnormal_time) from base_total_check_company
        where del_flag = 0
        ]]>
        <foreach collection="list" index="index" item="item" open="and company_id in(" separator="," close=")">   #{item.id}
        </foreach>

    </select>

    <select id="findMaxNormalDayByCompanyList" resultType="Integer">
        <![CDATA[
        select max(normal_day) from base_total_check_company
        where del_flag = 0
        ]]>
        <foreach collection="list" index="index" item="item" open="and company_id in(" separator="," close=")">   #{item.id}
        </foreach>
    </select>
</mapper>
