<?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="cn.cecep.talroad.mapper.BStatTableZxbgJbxxInfoMapper">

    <resultMap type="cn.cecep.talroad.domain.BStatTableZxbgJbxxInfo" id="BStatTableZxbgJbxxInfoResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="zxbgType"    column="zxbg_type"    />
        <result property="zxbgPeriod"    column="zxbg_period"    />
        <result property="zxbgRecord"    column="zxbg_record"    />
        <result property="zxbgProPress"    column="zxbg_pro_press"    />
        <result property="zxbgName"    column="zxbg_name"    />
        <result property="zxbgParam"    column="zxbg_param"    />
        <result property="zxbgUnit"    column="zxbg_unit"    />
        <result property="zxbgNum"    column="zxbg_num"    />
        <result property="zsbgRemark"    column="zsbg_remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="isDelete"    column="is_delete"    />
    </resultMap>


    <sql id="selectBStatTableZxbgJbxxInfoVo">
        select id, factory_id, zxbg_type, zxbg_period, zxbg_record, zxbg_pro_press, zxbg_name, zxbg_param, zxbg_unit, zxbg_num, zsbg_remark, create_time, is_delete from b_stat_table_zxbg_jbxx_info
    </sql>

    <select id="selectBStatTableZxbgJbxxInfoList" parameterType="cn.cecep.talroad.domain.BStatTableZxbgJbxxInfo" resultMap="BStatTableZxbgJbxxInfoResult">
        <include refid="selectBStatTableZxbgJbxxInfoVo"/>
        <where>
            <if test="factoryId != null  and factoryId != ''"> and factory_id = #{factoryId}</if>
            <if test="zxbgType != null  and zxbgType != ''"> and zxbg_type = #{zxbgType}</if>
            <if test="zxbgPeriod != null  and zxbgPeriod != ''"> and zxbg_period = #{zxbgPeriod}</if>
            <if test="zxbgRecord != null  and zxbgRecord != ''"> and zxbg_record = #{zxbgRecord}</if>
            <if test="zxbgProPress != null  and zxbgProPress != ''"> and zxbg_pro_press = #{zxbgProPress}</if>
            <if test="zxbgName != null  and zxbgName != ''"> and zxbg_name like concat('%', #{zxbgName}, '%')</if>
            <if test="zxbgParam != null  and zxbgParam != ''"> and zxbg_param = #{zxbgParam}</if>
            <if test="zxbgUnit != null  and zxbgUnit != ''"> and zxbg_unit = #{zxbgUnit}</if>
            <if test="zxbgNum != null "> and zxbg_num = #{zxbgNum}</if>
            <if test="zsbgRemark != null  and zsbgRemark != ''"> and zsbg_remark = #{zsbgRemark}</if>
            <if test="isDelete != null  and isDelete != ''"> and is_delete = #{isDelete}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultType="cn.cecep.talroad.domain.BStatTableZxbgJbxxInfo">
        SELECT
        zxbg.*,
        pf.factory_name,
        pf.country_name,
        pf.license_man_type,
        pf.poll_dis_license_code,
        pf.industrial_park_name,
        pf.industrial_park_code,
        pf.industry_permission_name,
        pf.river_basin
        FROM
        (select * from b_stat_table_zxbg_jbxx_info
        <where>
            <if test="zxbgType != null  and zxbgType != ''"> and zxbg_type = #{zxbgType}</if>
            <if test="zxbgPeriod != null  and zxbgPeriod != ''"> and zxbg_period  like concat('%', #{zxbgPeriod}, '%')</if>
            <if test="zxbgRecord != null  and zxbgRecord != ''"> and zxbg_record like concat('%', #{zxbgRecord}, '%')</if>
            <if test="zxbgName != null  and zxbgName != ''"> and zxbg_name like concat('%', #{zxbgName}, '%')</if>
            <if test="zxbgParam != null  and zxbgParam != ''"> and zxbg_param like concat('%', #{zxbgParam}, '%')</if>
        </where>
        ) zxbg
        right JOIN pc_factory pf ON pf.ID = zxbg.factory_id
        <where>
            <if test="factoryIdList != null and factoryIdList.size() != 0">
                and pf.id
                <foreach collection="factoryIdList" close=")" open=" IN (" separator="," item="item">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
        ORDER BY pf.order_num, pf.id
    </select>
    <select id="selectCountByPeriodAndPeriod" resultType="java.lang.Integer">
        SELECT count(1)
        FROM b_stat_table_zxbg_jbxx_info
        WHERE zxbg_type = #{type,jdbcType=VARCHAR}
        AND zxbg_period = #{period,jdbcType=VARCHAR}
        AND zxbg_record IN
        <foreach collection="records" separator="," item="item" close=")" open="(">
            #{item,jdbcType=VARCHAR}
        </foreach>
        AND is_delete = '0'
        AND  COALESCE(zsbg_remark, '') != '停产'
    </select>
    <select id="selectByPeriodAndPeriod" resultType="cn.cecep.talroad.domain.BStatTableZxbgJbxxInfo">
        SELECT id,factory_id, zxbg_record, zxbg_name, zxbg_param, zxbg_num, zsbg_remark
        FROM b_stat_table_zxbg_jbxx_info
        WHERE zxbg_type = #{type,jdbcType=VARCHAR}
        AND zxbg_period = #{period,jdbcType=VARCHAR}
        AND zxbg_record IN
        <foreach collection="records" separator="," item="item" close=")" open="(">
            #{item,jdbcType=VARCHAR}
        </foreach>
        AND is_delete = '0'
        AND  COALESCE(zsbg_remark, '') != '停产'
    </select>
</mapper>
