<?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.analysis.SRaPollManTypeChangeMapper">
  <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.analysis.SRaPollManTypeChange">
    <!--@mbg.generated-->
    <!--@Table s_ra_poll_man_type_change-->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="factory_id" jdbcType="VARCHAR" property="factoryId" />
    <result column="last_license_time" jdbcType="DATE" property="lastLicenseTime" />
    <result column="last_license_man_type" jdbcType="VARCHAR" property="lastLicenseManType" />
    <result column="now_license_time" jdbcType="DATE" property="nowLicenseTime" />
    <result column="now_license_man_type" jdbcType="VARCHAR" property="nowLicenseManType" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, factory_id, last_license_time, last_license_man_type, now_license_time, now_license_man_type, 
    create_time, update_time
  </sql>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update s_ra_poll_man_type_change
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="factory_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=VARCHAR} then #{item.factoryId,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="last_license_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=VARCHAR} then #{item.lastLicenseTime,jdbcType=DATE}
        </foreach>
      </trim>
      <trim prefix="last_license_man_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=VARCHAR} then #{item.lastLicenseManType,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="now_license_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=VARCHAR} then #{item.nowLicenseTime,jdbcType=DATE}
        </foreach>
      </trim>
      <trim prefix="now_license_man_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=VARCHAR} then #{item.nowLicenseManType,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="create_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="update_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=VARCHAR} then #{item.updateTime,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=VARCHAR}
    </foreach>
  </update>
  <update id="updateBatchSelective" parameterType="java.util.List">
    <!--@mbg.generated-->
    update s_ra_poll_man_type_change
    <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=VARCHAR} then #{item.factoryId,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="last_license_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.lastLicenseTime != null">
            when id = #{item.id,jdbcType=VARCHAR} then #{item.lastLicenseTime,jdbcType=DATE}
          </if>
        </foreach>
      </trim>
      <trim prefix="last_license_man_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.lastLicenseManType != null">
            when id = #{item.id,jdbcType=VARCHAR} then #{item.lastLicenseManType,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="now_license_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.nowLicenseTime != null">
            when id = #{item.id,jdbcType=VARCHAR} then #{item.nowLicenseTime,jdbcType=DATE}
          </if>
        </foreach>
      </trim>
      <trim prefix="now_license_man_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.nowLicenseManType != null">
            when id = #{item.id,jdbcType=VARCHAR} then #{item.nowLicenseManType,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="create_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.createTime != null">
            when id = #{item.id,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
      <trim prefix="update_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.updateTime != null">
            when id = #{item.id,jdbcType=VARCHAR} then #{item.updateTime,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=VARCHAR}
    </foreach>
  </update>
  <insert id="batchInsert" parameterType="map">
    <!--@mbg.generated-->
    insert into s_ra_poll_man_type_change
    (id, factory_id, last_license_time, last_license_man_type, now_license_time, now_license_man_type, 
      create_time, update_time)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.id,jdbcType=VARCHAR}, #{item.factoryId,jdbcType=VARCHAR}, #{item.lastLicenseTime,jdbcType=DATE}, 
        #{item.lastLicenseManType,jdbcType=VARCHAR}, #{item.nowLicenseTime,jdbcType=DATE}, 
        #{item.nowLicenseManType,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}, 
        #{item.updateTime,jdbcType=TIMESTAMP})
    </foreach>
  </insert>

  <select id="selectListInfo" resultType="cn.cecep.talroad.vo.analysis.SRaPollManTypeChangeVo">
    SELECT
      srpmtc.last_license_time,
      srpmtc.last_license_man_type,
      srpmtc.now_license_time,
      srpmtc.now_license_man_type,
      pf.factory_name,
      pf.country_name,
      pf.industry_permission_name
    FROM
      s_ra_poll_man_type_change srpmtc
    LEFT JOIN pc_factory pf ON pf.ID = srpmtc.factory_id
    <where>
      <if test="query.factoryName != null and query.factoryName.trim() != ''">
        AND pf.factory_name LIKE CONCAT('%',#{query.factoryName,jdbcType=VARCHAR},'%')
      </if>

      <if test="query.industryPermissionName != null and query.industryPermissionName.trim() != ''">
        AND pf.industry_permission_name LIKE CONCAT('%',#{query.industryPermissionName,jdbcType=VARCHAR},'%')
      </if>

      <if test="query.countryName != null and query.countryName.trim() != ''">
        AND pf.country_name LIKE CONCAT('%',#{query.countryName,jdbcType=VARCHAR},'%')
      </if>
      <if test="query.countryName != null and query.countryName.trim() != ''">
        AND pf.country_name LIKE CONCAT('%',#{query.countryName,jdbcType=VARCHAR},'%')
      </if>
      <if test="query.countryCode != null and query.countryCode.trim() != ''">
        AND pf.country_name = #{query.countryCode,jdbcType=VARCHAR}
      </if>
    </where>
    </select>

  <select id="selectIndustryPermissionNameList" resultType="java.lang.String">
    SELECT
      pf.industry_permission_name
    FROM
        pc_factory pf
    <where>
    <if test="industryPermissionName != null and industryPermissionName.trim() != ''">
      AND pf.industry_permission_name LIKE CONCAT('%',#{industryPermissionName,jdbcType=VARCHAR},'%')
    </if>
    </where>
    GROUP BY pf.industry_permission_name
  </select>
</mapper>