<?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.BStatTablePwxkRawMaterialMapper">
  <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.BStatTablePwxkRawMaterial">
    <!--@mbg.generated-->
    <!--@Table b_stat_table_pwxk_raw_material-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="factory_id" jdbcType="VARCHAR" property="factoryId" />
    <result column="raw_material_class" jdbcType="VARCHAR" property="rawMaterialClass" />
    <result column="raw_material_type" jdbcType="VARCHAR" property="rawMaterialType" />
    <result column="raw_material_name" jdbcType="VARCHAR" property="rawMaterialName" />
    <result column="year_max_used" jdbcType="NUMERIC" property="yearMaxUsed" />
    <result column="year_plan_used" jdbcType="NUMERIC" property="yearPlanUsed" />
    <result column="unit" jdbcType="VARCHAR" property="unit" />
    <result column="sulfur_ratio" jdbcType="NUMERIC" property="sulfurRatio" />
    <result column="poisonous_component" jdbcType="VARCHAR" property="poisonousComponent" />
    <result column="extra" jdbcType="VARCHAR" property="extra" />
    <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, raw_material_class, raw_material_type, raw_material_name, year_max_used, 
    year_plan_used, unit, sulfur_ratio, poisonous_component, extra, other_info, trade_secrets
  </sql>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update b_stat_table_pwxk_raw_material
    <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="raw_material_class = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.rawMaterialClass,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="raw_material_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.rawMaterialType,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="raw_material_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.rawMaterialName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="year_max_used = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.yearMaxUsed,jdbcType=NUMERIC}
        </foreach>
      </trim>
      <trim prefix="year_plan_used = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.yearPlanUsed,jdbcType=NUMERIC}
        </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="sulfur_ratio = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.sulfurRatio,jdbcType=NUMERIC}
        </foreach>
      </trim>
      <trim prefix="poisonous_component = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.poisonousComponent,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="extra = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.extra,jdbcType=VARCHAR}
        </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_raw_material
    <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="raw_material_class = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.rawMaterialClass != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.rawMaterialClass,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="raw_material_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.rawMaterialType != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.rawMaterialType,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="raw_material_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.rawMaterialName != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.rawMaterialName,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="year_max_used = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.yearMaxUsed != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.yearMaxUsed,jdbcType=NUMERIC}
          </if>
        </foreach>
      </trim>
      <trim prefix="year_plan_used = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.yearPlanUsed != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.yearPlanUsed,jdbcType=NUMERIC}
          </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="sulfur_ratio = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.sulfurRatio != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.sulfurRatio,jdbcType=NUMERIC}
          </if>
        </foreach>
      </trim>
      <trim prefix="poisonous_component = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.poisonousComponent != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.poisonousComponent,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="extra = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.extra != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.extra,jdbcType=VARCHAR}
          </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_raw_material
    (id, factory_id, raw_material_class, raw_material_type, raw_material_name, year_max_used, 
      year_plan_used, unit, sulfur_ratio, poisonous_component, extra, other_info, trade_secrets
      )
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.id,jdbcType=BIGINT}, #{item.factoryId,jdbcType=VARCHAR}, #{item.rawMaterialClass,jdbcType=VARCHAR}, 
        #{item.rawMaterialType,jdbcType=VARCHAR}, #{item.rawMaterialName,jdbcType=VARCHAR}, 
        #{item.yearMaxUsed,jdbcType=NUMERIC}, #{item.yearPlanUsed,jdbcType=NUMERIC}, #{item.unit,jdbcType=VARCHAR}, 
        #{item.sulfurRatio,jdbcType=NUMERIC}, #{item.poisonousComponent,jdbcType=VARCHAR}, 
        #{item.extra,jdbcType=VARCHAR}, #{item.otherInfo,jdbcType=VARCHAR}, #{item.tradeSecrets,jdbcType=VARCHAR}
        )
    </foreach>
  </insert>

  <select id="selectListAndFactory" resultType="cn.cecep.talroad.vo.BStatTablePwxkRawMaterialVo">
    SELECT
    bstprm.*,
    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_raw_material bstprm ON pf.ID = bstprm.factory_id
    <if test="rawMaterialClass != null and rawMaterialClass != ''">
      AND bstprm.raw_material_class LIKE CONCAT ('%',#{rawMaterialClass,jdbcType=VARCHAR},'%')
    </if>
    <if test="rawMaterialType != null and rawMaterialType != ''">
      AND bstprm.raw_material_type LIKE CONCAT ('%',#{rawMaterialType,jdbcType=VARCHAR},'%')
    </if>
    <if test="rawMaterialName != null and rawMaterialName != ''">
      AND bstprm.raw_material_name LIKE CONCAT ('%',#{rawMaterialName,jdbcType=VARCHAR},'%')
    </if>
    <where>
      <if test="factoryIdList != null and factoryIdList.size() != 0">
        pf.id
        <foreach close=")" collection="factoryIdList" item="item" open=" IN (" separator=",">
          #{item,jdbcType=VARCHAR}
        </foreach>
      </if>

    </where>
    ORDER BY pf.order_num, pf.id
    </select>
</mapper>