<?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.BStatTablePwxkProductionFacilitiesMapper">
  <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.BStatTablePwxkProductionFacilities">
    <!--@mbg.generated-->
    <!--@Table b_stat_table_pwxk_production_facilities-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="factory_id" jdbcType="VARCHAR" property="factoryId" />
    <result column="production_line_type" jdbcType="VARCHAR" property="productionLineType" />
    <result column="production_line_code" jdbcType="VARCHAR" property="productionLineCode" />
    <result column="production_unit_name" jdbcType="VARCHAR" property="productionUnitName" />
    <result column="craft_name" jdbcType="SMALLINT" property="craftName" />
    <result column="facility_name" jdbcType="VARCHAR" property="facilityName" />
    <result column="trade_secrets" jdbcType="VARCHAR" property="tradeSecrets" />
    <result column="production_facility_code" jdbcType="VARCHAR" property="productionFacilityCode" />
    <result column="other_facility_info" jdbcType="VARCHAR" property="otherFacilityInfo" />
    <result column="other_craft_info" jdbcType="VARCHAR" property="otherCraftInfo" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, factory_id, production_line_type, production_line_code, production_unit_name, 
    craft_name, facility_name, trade_secrets, production_facility_code, other_facility_info, 
    other_craft_info
  </sql>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update b_stat_table_pwxk_production_facilities
    <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="production_line_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.productionLineType,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="production_line_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.productionLineCode,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="production_unit_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.productionUnitName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="craft_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.craftName,jdbcType=SMALLINT}
        </foreach>
      </trim>
      <trim prefix="facility_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.facilityName,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="production_facility_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.productionFacilityCode,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="other_facility_info = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.otherFacilityInfo,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="other_craft_info = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.otherCraftInfo,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_production_facilities
    <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="production_line_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.productionLineType != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.productionLineType,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="production_line_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.productionLineCode != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.productionLineCode,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="production_unit_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.productionUnitName != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.productionUnitName,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="craft_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.craftName != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.craftName,jdbcType=SMALLINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="facility_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.facilityName != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.facilityName,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="production_facility_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.productionFacilityCode != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.productionFacilityCode,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="other_facility_info = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.otherFacilityInfo != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.otherFacilityInfo,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="other_craft_info = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.otherCraftInfo != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.otherCraftInfo,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_production_facilities
    (id, factory_id, production_line_type, production_line_code, production_unit_name, 
      craft_name, facility_name, trade_secrets, production_facility_code, other_facility_info, 
      other_craft_info)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.id,jdbcType=BIGINT}, #{item.factoryId,jdbcType=VARCHAR}, #{item.productionLineType,jdbcType=VARCHAR}, 
        #{item.productionLineCode,jdbcType=VARCHAR}, #{item.productionUnitName,jdbcType=VARCHAR}, 
        #{item.craftName,jdbcType=SMALLINT}, #{item.facilityName,jdbcType=VARCHAR}, #{item.tradeSecrets,jdbcType=VARCHAR}, 
        #{item.productionFacilityCode,jdbcType=VARCHAR}, #{item.otherFacilityInfo,jdbcType=VARCHAR}, 
        #{item.otherCraftInfo,jdbcType=VARCHAR})
    </foreach>
  </insert>
  <resultMap id="BaseResultVoMap" type="cn.cecep.talroad.vo.BStatTablePwxkProductionFacilitiesVo">
    <!--@mbg.generated-->

    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="production_line_type" jdbcType="VARCHAR" property="productionLineType" />
    <result column="production_line_code" jdbcType="VARCHAR" property="productionLineCode" />
    <result column="production_unit_name" jdbcType="VARCHAR" property="productionUnitName" />
    <result column="craft_name" jdbcType="SMALLINT" property="craftName" />
    <result column="facility_name" jdbcType="VARCHAR" property="facilityName" />
    <result column="trade_secrets" jdbcType="VARCHAR" property="tradeSecrets" />
    <result column="production_facility_code" jdbcType="VARCHAR" property="productionFacilityCode" />
    <result column="other_facility_info" jdbcType="VARCHAR" property="otherFacilityInfo" />
    <result column="other_craft_info" jdbcType="VARCHAR" property="otherCraftInfo" />
    <result column="factory_name" jdbcType="VARCHAR" property="factoryName" />
    <result column="poll_dis_license_code" jdbcType="VARCHAR" property="pollDisLicenseCode" />
    <result column="country_name" jdbcType="VARCHAR" property="countryName" />
    <result column="license_man_type" jdbcType="VARCHAR" property="licenseManType" />
    <result column="industrial_park_name" jdbcType="VARCHAR" property="industrialParkName" />
    <result column="industrial_park_code" jdbcType="VARCHAR" property="industrialParkCode" />
    <result column="industry_permission_name" jdbcType="VARCHAR" property="industryPermissionName" />
    <result column="river_basin" jdbcType="VARCHAR" property="riverBasin" />
    <collection property="params" ofType="cn.cecep.talroad.domain.BStatTablePwxkProductionFacilitiesParams">
      <id column="bId" jdbcType="VARCHAR" property="id" />
      <result column="params_name" jdbcType="VARCHAR" property="paramsName" />
      <result column="params_unit" jdbcType="VARCHAR" property="paramsUnit" />
      <result column="design_values" jdbcType="VARCHAR" property="designValues" />
      <result column="other_params_info" jdbcType="VARCHAR" property="otherParamsInfo" />
    </collection>
  </resultMap>
  <select id="selectListAndFactory" resultMap="BaseResultVoMap">
    SELECT
    production_line_type, production_line_code, production_unit_name,
    craft_name, facility_name, trade_secrets, production_facility_code, other_facility_info,
    other_craft_info,
    b.id AS bId,
    b.params_name,
    b.params_unit,
    b.design_values,
    b.other_params_info,
    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
    RIGHT JOIN b_stat_table_pwxk_production_facilities bstpwiit  ON pf.ID = bstpwiit.factory_id
    <if test="productionUnitName != null and productionUnitName != ''">
      AND bstpwiit.production_unit_name LIKE CONCAT ('%',#{productionUnitName,jdbcType=VARCHAR},'%')
    </if>
    <if test="craftName != null and craftName != ''">
      AND bstpwiit.craft_name LIKE CONCAT ('%',#{craftName,jdbcType=VARCHAR},'%')
    </if>
    <if test="facilityName != null and facilityName != ''">
      AND bstpwiit.facility_name LIKE CONCAT ('%',#{facilityName,jdbcType=VARCHAR},'%')
    </if>
    <if test="productionLineType != null and productionLineType != ''">
      AND bstpwiit.production_line_type = #{productionLineType,jdbcType=VARCHAR}
    </if>
    LEFT JOIN b_stat_table_pwxk_production_facilities_params b ON b.facilities_id=bstpwiit.id
    <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>