<?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.BStatTablePwxkProductsMapper">
  <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.BStatTablePwxkProducts">
    <!--@mbg.generated-->
    <!--@Table b_stat_table_pwxk_products-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="factory_id" jdbcType="VARCHAR" property="factoryId" />
    <result column="product_name" jdbcType="VARCHAR" property="productName" />
    <result column="unit" jdbcType="VARCHAR" property="unit" />
    <result column="production_capacity" jdbcType="VARCHAR" property="productionCapacity" />
    <result column="year_production_time" jdbcType="SMALLINT" property="yearProductionTime" />
    <result column="other_info" jdbcType="VARCHAR" property="otherInfo" />
    <result column="trade_secrets" jdbcType="VARCHAR" property="tradeSecrets" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, factory_id, product_name, unit, production_capacity, year_production_time, other_info, 
    trade_secrets
  </sql>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update b_stat_table_pwxk_products
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="factory_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.factoryId,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="product_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.productName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="unit = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.unit,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="production_capacity = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.productionCapacity,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="year_production_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.yearProductionTime,jdbcType=SMALLINT}
        </foreach>
      </trim>
      <trim prefix="other_info = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.otherInfo,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="trade_secrets = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.tradeSecrets,jdbcType=VARCHAR}
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=BIGINT}
    </foreach>
  </update>
  <update id="updateBatchSelective" parameterType="java.util.List">
    <!--@mbg.generated-->
    update b_stat_table_pwxk_products
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="factory_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.factoryId != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.factoryId,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="product_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.productName != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.productName,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="unit = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.unit != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.unit,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="production_capacity = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.productionCapacity != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.productionCapacity,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="year_production_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.yearProductionTime != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.yearProductionTime,jdbcType=SMALLINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="other_info = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.otherInfo != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.otherInfo,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="trade_secrets = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.tradeSecrets != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.tradeSecrets,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=BIGINT}
    </foreach>
  </update>
  <insert id="batchInsert" parameterType="map">
    <!--@mbg.generated-->
    insert into b_stat_table_pwxk_products
    (id, factory_id, product_name, unit, production_capacity, year_production_time, other_info, 
      trade_secrets)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.id,jdbcType=BIGINT}, #{item.factoryId,jdbcType=VARCHAR}, #{item.productName,jdbcType=VARCHAR}, 
        #{item.unit,jdbcType=VARCHAR}, #{item.productionCapacity,jdbcType=VARCHAR}, #{item.yearProductionTime,jdbcType=SMALLINT}, 
        #{item.otherInfo,jdbcType=VARCHAR}, #{item.tradeSecrets,jdbcType=VARCHAR})
    </foreach>
  </insert>

  <select id="selectListAndFactory" resultType="cn.cecep.talroad.vo.BStatTablePwxkProductsVo">
    SELECT
    bstpp.*,
    pf.factory_name,
    pf.poll_dis_license_code,
    pf.city_code,
    pf.city_name,
    pf.country_code,
    pf.country_name,
    pf.license_man_type,
    pf.usc_code,
    pf.ins_fram_code,
    pf.whether_local_park,
    pf.industrial_park_name,
    pf.industrial_park_code,
    pf.industry_permission_name,
    pf.river_basin
    FROM
    pc_factory pf
    LEFT JOIN b_stat_table_pwxk_products bstpp ON pf.ID = bstpp.factory_id
    <if test="productName != null and productName != ''">
      AND bstpp.product_name LIKE CONCAT ('%',#{productName,jdbcType=VARCHAR},'%')
    </if>
    <where>
      <if test="factoryIdList != null and factoryIdList.size() != 0">
        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>
</mapper>