<?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.BStatTablePwxkWaterLifeInMapper">
  <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.BStatTablePwxkWaterLifeIn">
    <!--@mbg.generated-->
    <!--@Table b_stat_table_pwxk_water_life_in-->
    <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="water_range_east" jdbcType="VARCHAR" property="waterRangeEast" />
    <result column="water_range_west" jdbcType="VARCHAR" property="waterRangeWest" />
    <result column="water_range_south" jdbcType="VARCHAR" property="waterRangeSouth" />
    <result column="water_range_north" jdbcType="VARCHAR" property="waterRangeNorth" />
    <result column="population_number" jdbcType="INTEGER" property="populationNumber" />
    <result column="service_country_code" jdbcType="VARCHAR" property="serviceCountryCode" />
    <result column="inflow_water_volume" jdbcType="VARCHAR" property="inflowWaterVolume" />
    <result column="pipe_properties" jdbcType="VARCHAR" property="pipeProperties" />
    <result column="pipe_unit" jdbcType="VARCHAR" property="pipeUnit" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, factory_id, treatment_plant_name, service_provider, treatment_plant_type, belong_to_water_treatment_facilities, 
    water_range_east, water_range_west, water_range_south, water_range_north, population_number, 
    service_country_code, inflow_water_volume, pipe_properties, pipe_unit, remarks
  </sql>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update b_stat_table_pwxk_water_life_in
    <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="water_range_east = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.waterRangeEast,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="water_range_west = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.waterRangeWest,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="water_range_south = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.waterRangeSouth,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="water_range_north = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.waterRangeNorth,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="population_number = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.populationNumber,jdbcType=INTEGER}
        </foreach>
      </trim>
      <trim prefix="service_country_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.serviceCountryCode,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="inflow_water_volume = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.inflowWaterVolume,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="pipe_properties = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.pipeProperties,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="pipe_unit = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.pipeUnit,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="remarks = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.remarks,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_life_in
    <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="water_range_east = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.waterRangeEast != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.waterRangeEast,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="water_range_west = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.waterRangeWest != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.waterRangeWest,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="water_range_south = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.waterRangeSouth != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.waterRangeSouth,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="water_range_north = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.waterRangeNorth != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.waterRangeNorth,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="population_number = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.populationNumber != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.populationNumber,jdbcType=INTEGER}
          </if>
        </foreach>
      </trim>
      <trim prefix="service_country_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.serviceCountryCode != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.serviceCountryCode,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="inflow_water_volume = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.inflowWaterVolume != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.inflowWaterVolume,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="pipe_properties = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.pipeProperties != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.pipeProperties,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="pipe_unit = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.pipeUnit != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.pipeUnit,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="remarks = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.remarks != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.remarks,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_life_in
    (id, factory_id, treatment_plant_name, service_provider, treatment_plant_type, belong_to_water_treatment_facilities, 
      water_range_east, water_range_west, water_range_south, water_range_north, population_number, 
      service_country_code, inflow_water_volume, pipe_properties, pipe_unit, remarks)
    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.waterRangeEast,jdbcType=VARCHAR}, 
        #{item.waterRangeWest,jdbcType=VARCHAR}, #{item.waterRangeSouth,jdbcType=VARCHAR}, 
        #{item.waterRangeNorth,jdbcType=VARCHAR}, #{item.populationNumber,jdbcType=INTEGER}, 
        #{item.serviceCountryCode,jdbcType=VARCHAR}, #{item.inflowWaterVolume,jdbcType=VARCHAR}, 
        #{item.pipeProperties,jdbcType=VARCHAR}, #{item.pipeUnit,jdbcType=VARCHAR}, #{item.remarks,jdbcType=VARCHAR}
        )
    </foreach>
  </insert>

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