<?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.BStatTablePwxkWaterTreatmentInAskMapper">
  <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.BStatTablePwxkWaterTreatmentInAsk">
    <!--@mbg.generated-->
    <!--@Table b_stat_table_pwxk_water_treatment_in_ask-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="factory_id" jdbcType="VARCHAR" property="factoryId" />
    <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="outlet_code" jdbcType="VARCHAR" property="outletCode" />
    <result column="outlet_name" jdbcType="VARCHAR" property="outletName" />
    <result column="monitoring_content" jdbcType="VARCHAR" property="monitoringContent" />
    <result column="pollutant_name" jdbcType="VARCHAR" property="pollutantName" />
    <result column="monitoring_type" jdbcType="VARCHAR" property="monitoringType" />
    <result column="networking" jdbcType="SMALLINT" property="networking" />
    <result column="auto_monitor_name" jdbcType="VARCHAR" property="autoMonitorName" />
    <result column="monitor_address" jdbcType="VARCHAR" property="monitorAddress" />
    <result column="meet_requirement" jdbcType="SMALLINT" property="meetRequirement" />
    <result column="manual_monitoring_method_number" jdbcType="VARCHAR" property="manualMonitoringMethodNumber" />
    <result column="manual_monitoring_total" jdbcType="VARCHAR" property="manualMonitoringTotal" />
    <result column="manual_test_method" jdbcType="VARCHAR" property="manualTestMethod" />
    <result column="other" jdbcType="VARCHAR" property="other" />
    <result column="treatment_plant_name" jdbcType="VARCHAR" property="treatmentPlantName" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, factory_id, service_provider, treatment_plant_type, belong_to_water_treatment_facilities, 
    outlet_code, outlet_name, monitoring_content, pollutant_name, monitoring_type, networking, 
    auto_monitor_name, monitor_address, meet_requirement, manual_monitoring_method_number, 
    manual_monitoring_total, manual_test_method, other, treatment_plant_name
  </sql>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update b_stat_table_pwxk_water_treatment_in_ask
    <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="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="outlet_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.outletCode,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="outlet_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.outletName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="monitoring_content = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.monitoringContent,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="pollutant_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.pollutantName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="monitoring_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.monitoringType,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="networking = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.networking,jdbcType=SMALLINT}
        </foreach>
      </trim>
      <trim prefix="auto_monitor_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.autoMonitorName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="monitor_address = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.monitorAddress,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="meet_requirement = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.meetRequirement,jdbcType=SMALLINT}
        </foreach>
      </trim>
      <trim prefix="manual_monitoring_method_number = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.manualMonitoringMethodNumber,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="manual_monitoring_total = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.manualMonitoringTotal,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="manual_test_method = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.manualTestMethod,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="other = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.other,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>
    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_in_ask
    <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="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="outlet_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.outletCode != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.outletCode,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="outlet_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.outletName != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.outletName,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="monitoring_content = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.monitoringContent != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.monitoringContent,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="pollutant_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.pollutantName != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.pollutantName,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="monitoring_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.monitoringType != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.monitoringType,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="networking = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.networking != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.networking,jdbcType=SMALLINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="auto_monitor_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.autoMonitorName != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.autoMonitorName,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="monitor_address = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.monitorAddress != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.monitorAddress,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="meet_requirement = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.meetRequirement != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.meetRequirement,jdbcType=SMALLINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="manual_monitoring_method_number = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.manualMonitoringMethodNumber != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.manualMonitoringMethodNumber,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="manual_monitoring_total = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.manualMonitoringTotal != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.manualMonitoringTotal,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="manual_test_method = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.manualTestMethod != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.manualTestMethod,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="other = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.other != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.other,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>
    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_in_ask
    (id, factory_id, service_provider, treatment_plant_type, belong_to_water_treatment_facilities, 
      outlet_code, outlet_name, monitoring_content, pollutant_name, monitoring_type, 
      networking, auto_monitor_name, monitor_address, meet_requirement, manual_monitoring_method_number, 
      manual_monitoring_total, manual_test_method, other, treatment_plant_name)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.id,jdbcType=BIGINT}, #{item.factoryId,jdbcType=VARCHAR}, #{item.serviceProvider,jdbcType=VARCHAR}, 
        #{item.treatmentPlantType,jdbcType=VARCHAR}, #{item.belongToWaterTreatmentFacilities,jdbcType=VARCHAR}, 
        #{item.outletCode,jdbcType=VARCHAR}, #{item.outletName,jdbcType=VARCHAR}, #{item.monitoringContent,jdbcType=VARCHAR}, 
        #{item.pollutantName,jdbcType=VARCHAR}, #{item.monitoringType,jdbcType=VARCHAR}, 
        #{item.networking,jdbcType=SMALLINT}, #{item.autoMonitorName,jdbcType=VARCHAR}, 
        #{item.monitorAddress,jdbcType=VARCHAR}, #{item.meetRequirement,jdbcType=SMALLINT}, 
        #{item.manualMonitoringMethodNumber,jdbcType=VARCHAR}, #{item.manualMonitoringTotal,jdbcType=VARCHAR}, 
        #{item.manualTestMethod,jdbcType=VARCHAR}, #{item.other,jdbcType=VARCHAR}, #{item.treatmentPlantName,jdbcType=VARCHAR}
        )
    </foreach>
  </insert>

  <select id="selectListAndFactory" resultType="cn.cecep.talroad.vo.BStatTablePwxkWaterTreatmentInAskVo">
    SELECT
    bstpwtia.*,
    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_in_ask bstpwtia ON pf.ID = bstpwtia.factory_id
        <if test="treatmentPlantName != null and treatmentPlantName.trim()!=''">
        AND bstpwtia.treatment_plant_name LIKE CONCAT('%',#{treatmentPlantName},'%')
        </if>
        <if test="serviceProvider != null and serviceProvider.trim()!=''">
          AND bstpwtia.service_provider LIKE CONCAT('%',#{serviceProvider},'%')
        </if>
        <if test="belongToWaterTreatmentFacilities != null and belongToWaterTreatmentFacilities.trim()!=''">
          AND bstpwtia.belong_to_water_treatment_facilities = #{serviceProvider}
        </if>
        <if test="serviceCountryCode != null and serviceCountryCode.trim()!=''">
          AND bstpwtia.service_country_code = #{serviceCountryCode}
        </if>
        <if test="treatmentPlantTypes != null and treatmentPlantTypes.size() != 0">
          AND bstpwtia.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>