<?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.BStatTablePwxkWaterTreatmentLineMapper">
  <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.BStatTablePwxkWaterTreatmentLine">
    <!--@mbg.generated-->
    <!--@Table b_stat_table_pwxk_water_treatment_line-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="factory_id" jdbcType="VARCHAR" property="factoryId" />
    <result column="treatment_plant_name" jdbcType="VARCHAR" property="treatmentPlantName" />
    <result column="service_provider" jdbcType="VARCHAR" property="serviceProvider" />
    <result column="treatment_plant_type" jdbcType="VARCHAR" property="treatmentPlantType" />
    <result column="belong_to_water_treatment_facilities" jdbcType="VARCHAR" property="belongToWaterTreatmentFacilities" />
    <result column="line_type" jdbcType="VARCHAR" property="lineType" />
    <result column="line_name" jdbcType="VARCHAR" property="lineName" />
    <result column="processing_capacity" jdbcType="VARCHAR" property="processingCapacity" />
    <result column="year_run_time" jdbcType="SMALLINT" property="yearRunTime" />
    <result column="outside_water_type" jdbcType="VARCHAR" property="outsideWaterType" />
    <result column="other_info" jdbcType="VARCHAR" property="otherInfo" />
    <result column="process_unit" jdbcType="VARCHAR" property="processUnit" />
    <result column="pollution_control_facilities_type" jdbcType="VARCHAR" property="pollutionControlFacilitiesType" />
    <result column="pollution_control_facilities_code" jdbcType="VARCHAR" property="pollutionControlFacilitiesCode" />
    <result column="workable_technology" jdbcType="VARCHAR" property="workableTechnology" />
    <result column="trade_secrets" jdbcType="VARCHAR" property="tradeSecrets" />
    <result column="pollution_control_facilities_other" jdbcType="VARCHAR" property="pollutionControlFacilitiesOther" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, factory_id, treatment_plant_name, service_provider, treatment_plant_type, belong_to_water_treatment_facilities, 
    line_type, line_name, processing_capacity, year_run_time, outside_water_type, other_info, 
    process_unit, pollution_control_facilities_type, pollution_control_facilities_code, 
    workable_technology, trade_secrets, pollution_control_facilities_other
  </sql>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update b_stat_table_pwxk_water_treatment_line
    <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="treatment_plant_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.treatmentPlantName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="service_provider = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.serviceProvider,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="treatment_plant_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.treatmentPlantType,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="belong_to_water_treatment_facilities = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.belongToWaterTreatmentFacilities,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="line_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.lineType,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="line_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.lineName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="processing_capacity = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.processingCapacity,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="year_run_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.yearRunTime,jdbcType=SMALLINT}
        </foreach>
      </trim>
      <trim prefix="outside_water_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.outsideWaterType,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="process_unit = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.processUnit,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="pollution_control_facilities_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.pollutionControlFacilitiesType,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="pollution_control_facilities_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.pollutionControlFacilitiesCode,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="workable_technology = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.workableTechnology,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 prefix="pollution_control_facilities_other = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.pollutionControlFacilitiesOther,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_water_treatment_line
    <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="treatment_plant_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.treatmentPlantName != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.treatmentPlantName,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="service_provider = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.serviceProvider != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.serviceProvider,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="treatment_plant_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.treatmentPlantType != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.treatmentPlantType,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="belong_to_water_treatment_facilities = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.belongToWaterTreatmentFacilities != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.belongToWaterTreatmentFacilities,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="line_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.lineType != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.lineType,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="line_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.lineName != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.lineName,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="processing_capacity = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.processingCapacity != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.processingCapacity,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="year_run_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.yearRunTime != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.yearRunTime,jdbcType=SMALLINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="outside_water_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.outsideWaterType != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.outsideWaterType,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="process_unit = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.processUnit != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.processUnit,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="pollution_control_facilities_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.pollutionControlFacilitiesType != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.pollutionControlFacilitiesType,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="pollution_control_facilities_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.pollutionControlFacilitiesCode != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.pollutionControlFacilitiesCode,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="workable_technology = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.workableTechnology != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.workableTechnology,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 prefix="pollution_control_facilities_other = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.pollutionControlFacilitiesOther != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.pollutionControlFacilitiesOther,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_water_treatment_line
    (id, factory_id, treatment_plant_name, service_provider, treatment_plant_type, belong_to_water_treatment_facilities, 
      line_type, line_name, processing_capacity, year_run_time, outside_water_type, other_info, 
      process_unit, pollution_control_facilities_type, pollution_control_facilities_code, 
      workable_technology, trade_secrets, pollution_control_facilities_other)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.id,jdbcType=BIGINT}, #{item.factoryId,jdbcType=VARCHAR}, #{item.treatmentPlantName,jdbcType=VARCHAR}, 
        #{item.serviceProvider,jdbcType=VARCHAR}, #{item.treatmentPlantType,jdbcType=VARCHAR}, 
        #{item.belongToWaterTreatmentFacilities,jdbcType=VARCHAR}, #{item.lineType,jdbcType=VARCHAR}, 
        #{item.lineName,jdbcType=VARCHAR}, #{item.processingCapacity,jdbcType=VARCHAR}, 
        #{item.yearRunTime,jdbcType=SMALLINT}, #{item.outsideWaterType,jdbcType=VARCHAR}, 
        #{item.otherInfo,jdbcType=VARCHAR}, #{item.processUnit,jdbcType=VARCHAR}, #{item.pollutionControlFacilitiesType,jdbcType=VARCHAR}, 
        #{item.pollutionControlFacilitiesCode,jdbcType=VARCHAR}, #{item.workableTechnology,jdbcType=VARCHAR}, 
        #{item.tradeSecrets,jdbcType=VARCHAR}, #{item.pollutionControlFacilitiesOther,jdbcType=VARCHAR}
        )
    </foreach>
  </insert>

  <select id="selectListAndFactory" resultType="cn.cecep.talroad.vo.BStatTablePwxkWaterTreatmentLineVo">
    SELECT
      bstpwtl.*,
      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_water_treatment_line bstpwtl  ON pf.ID = bstpwtl.factory_id
          <if test="treatmentPlantName != null and treatmentPlantName.trim()!=''">
          AND bstpwtl.treatment_plant_name LIKE CONCAT('%',#{treatmentPlantName},'%')
        </if>
          <if test="serviceProvider != null and serviceProvider.trim()!=''">
            AND bstpwtl.service_provider LIKE CONCAT('%',#{serviceProvider},'%')
          </if>
          <if test="belongToWaterTreatmentFacilities != null and belongToWaterTreatmentFacilities.trim()!=''">
            AND bstpwtl.belong_to_water_treatment_facilities = #{serviceProvider}
          </if>
          <if test="serviceCountryCode != null and serviceCountryCode.trim()!=''">
            AND bstpwtl.service_country_code = #{serviceCountryCode}
          </if>
          <if test="treatmentPlantTypes != null and treatmentPlantTypes.size() != 0">
            AND bstpwtl.treatment_plant_type
            <foreach collection="treatmentPlantTypes" close=")" open=" IN (" separator="," item="item">
              #{item,jdbcType=VARCHAR}
            </foreach>
          </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>