<?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="com.xhpc.activity.mapper.XhpcWorkStationMapper">
  <resultMap id="BaseResultMap" type="com.xhpc.activity.domain.XhpcWorkStationDomain">
    <id column="work_station_id" jdbcType="BIGINT" property="workStationId" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="operator_id" jdbcType="BIGINT" property="operatorId" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="construction_site" jdbcType="SMALLINT" property="constructionSite" />
    <result column="service_facilities" jdbcType="VARCHAR" property="serviceFacilities" />
    <result column="periphery_facilities" jdbcType="VARCHAR" property="peripheryFacilities" />
    <result column="address" jdbcType="VARCHAR" property="address" />
    <result column="detailed_address" jdbcType="VARCHAR" property="detailedAddress" />
    <result column="longitude" jdbcType="VARCHAR" property="longitude" />
    <result column="latitude" jdbcType="VARCHAR" property="latitude" />
    <result column="parking_instructions" jdbcType="VARCHAR" property="parkingInstructions" />
    <result column="serial_number" jdbcType="VARCHAR" property="serialNumber" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="del_flag" jdbcType="INTEGER" property="delFlag" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="business_instructions" jdbcType="VARCHAR" property="businessInstructions" />
    <result column="reminder_instructions" jdbcType="VARCHAR" property="reminderInstructions" />
    <result column="img_id" jdbcType="VARCHAR" property="imgId" />
    <result column="station_type" jdbcType="SMALLINT" property="stationType" />
    <result column="service_tel" jdbcType="VARCHAR" property="serviceTel" />
    <result column="park_nums" jdbcType="INTEGER" property="parkNums" />
    <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
  </resultMap>
  <sql id="Base_Column_List">
    work_station_id, `name`, operator_id, `type`, construction_site, service_facilities, 
    periphery_facilities, address, detailed_address, longitude, latitude, parking_instructions, 
    serial_number, `status`, del_flag, create_time, create_by, update_time, update_by, 
    remark, business_instructions, reminder_instructions, img_id, station_type, service_tel, 
    park_nums, tenant_id
  </sql>

  <select id="selectListByParams" resultType="com.xhpc.activity.domain.XhpcWorkStationDomain">
    select
    <include refid="Base_Column_List" />
    from xhpc_work_station
    <where>
      <if test="params.name != null and params.name !=''">
        and name like concat('%', #{params.name}, '%')
      </if>
      <if test="params.tenantId!=null and params.tenantId!=''">
        and tenant_id = #{params.tenantId}
      </if>
        <if test="params.status != null">
          and status=#{params.status}
        </if>
        <if test="params.delFlag!=null">
          and del_flag=#{params.delFlag}
        </if>
    </where>

  </select>


  <select id="selectMapListByParams" resultType="map">
    select
        concat('S_', work_station_id) as 'id',
      name as 'name',
      type as 'type',
      address as 'address',
      serial_number as 'serialNumber'
    from xhpc_work_station
    <where>
      <if test="params.name != null and params.name !=''">
        and name like concat('%', #{params.name}, '%')
      </if>
      <if test="params.tenantId!=null and params.tenantId!=''">
        and tenant_id = #{params.tenantId}
      </if>
      <if test="params.status != null">
        and status=#{params.status}
      </if>
      <if test="params.delFlag!=null">
        and del_flag=#{params.delFlag}
      </if>
    </where>
  </select>


  <select id="selectByName" resultType="com.xhpc.activity.domain.XhpcWorkStationDomain">
    select
    <include refid="Base_Column_List" />
    from xhpc_work_station
    where name like concat('%', #{stationName}, '%')
  </select>

  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from xhpc_work_station
    where work_station_id = #{workStationId,jdbcType=BIGINT}
  </select>

  <update id="deleteByPrimaryKey" parameterType="java.lang.Long">
    update xhpc_work_station set del_flag=2
    where work_station_id = #{workStationId,jdbcType=BIGINT}
  </update>
  <insert id="insert" keyColumn="work_station_id" keyProperty="workStationId" parameterType="com.xhpc.activity.domain.XhpcWorkStationDomain" useGeneratedKeys="true">
    insert into xhpc_work_station (`name`, operator_id, `type`, 
      construction_site, service_facilities, periphery_facilities, 
      address, detailed_address, longitude, 
      latitude, parking_instructions, serial_number, 
      `status`, del_flag, create_time, 
      create_by, update_time, update_by, 
      remark, business_instructions, reminder_instructions, 
      img_id, station_type, service_tel, 
      park_nums, tenant_id)
    values (#{name,jdbcType=VARCHAR}, #{operatorId,jdbcType=BIGINT}, #{type,jdbcType=INTEGER}, 
      #{constructionSite,jdbcType=SMALLINT}, #{serviceFacilities,jdbcType=VARCHAR}, #{peripheryFacilities,jdbcType=VARCHAR}, 
      #{address,jdbcType=VARCHAR}, #{detailedAddress,jdbcType=VARCHAR}, #{longitude,jdbcType=VARCHAR}, 
      #{latitude,jdbcType=VARCHAR}, #{parkingInstructions,jdbcType=VARCHAR}, #{serialNumber,jdbcType=VARCHAR}, 
      #{status,jdbcType=INTEGER}, 0, sysdate(),
      #{createBy,jdbcType=VARCHAR}, sysdate(), #{updateBy,jdbcType=VARCHAR},
      #{remark,jdbcType=VARCHAR}, #{businessInstructions,jdbcType=VARCHAR}, #{reminderInstructions,jdbcType=VARCHAR}, 
      #{imgId,jdbcType=VARCHAR}, #{stationType,jdbcType=SMALLINT}, #{serviceTel,jdbcType=VARCHAR}, 
      #{parkNums,jdbcType=INTEGER}, #{tenantId,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" keyColumn="work_station_id" keyProperty="workStationId" parameterType="com.xhpc.activity.domain.XhpcWorkStationDomain" useGeneratedKeys="true">
    insert into xhpc_work_station
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="name != null">
        `name`,
      </if>
      <if test="operatorId != null">
        operator_id,
      </if>
      <if test="type != null">
        `type`,
      </if>
      <if test="constructionSite != null">
        construction_site,
      </if>
      <if test="serviceFacilities != null">
        service_facilities,
      </if>
      <if test="peripheryFacilities != null">
        periphery_facilities,
      </if>
      <if test="address != null">
        address,
      </if>
      <if test="detailedAddress != null">
        detailed_address,
      </if>
      <if test="longitude != null">
        longitude,
      </if>
      <if test="latitude != null">
        latitude,
      </if>
      <if test="parkingInstructions != null">
        parking_instructions,
      </if>
      <if test="serialNumber != null">
        serial_number,
      </if>
      <if test="status != null">
        `status`,
      </if>
        del_flag,
        create_time,
      <if test="createBy != null">
        create_by,
      </if>
        update_time,
      <if test="updateBy != null">
        update_by,
      </if>
      <if test="remark != null">
        remark,
      </if>
      <if test="businessInstructions != null">
        business_instructions,
      </if>
      <if test="reminderInstructions != null">
        reminder_instructions,
      </if>
      <if test="imgId != null">
        img_id,
      </if>
      <if test="stationType != null">
        station_type,
      </if>
      <if test="serviceTel != null">
        service_tel,
      </if>
      <if test="parkNums != null">
        park_nums,
      </if>
      <if test="tenantId != null">
        tenant_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="operatorId != null">
        #{operatorId,jdbcType=BIGINT},
      </if>
      <if test="type != null">
        #{type,jdbcType=INTEGER},
      </if>
      <if test="constructionSite != null">
        #{constructionSite,jdbcType=SMALLINT},
      </if>
      <if test="serviceFacilities != null">
        #{serviceFacilities,jdbcType=VARCHAR},
      </if>
      <if test="peripheryFacilities != null">
        #{peripheryFacilities,jdbcType=VARCHAR},
      </if>
      <if test="address != null">
        #{address,jdbcType=VARCHAR},
      </if>
      <if test="detailedAddress != null">
        #{detailedAddress,jdbcType=VARCHAR},
      </if>
      <if test="longitude != null">
        #{longitude,jdbcType=VARCHAR},
      </if>
      <if test="latitude != null">
        #{latitude,jdbcType=VARCHAR},
      </if>
      <if test="parkingInstructions != null">
        #{parkingInstructions,jdbcType=VARCHAR},
      </if>
      <if test="serialNumber != null">
        #{serialNumber,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
        0,
        sysdate(),
      <if test="createBy != null">
        #{createBy,jdbcType=VARCHAR},
      </if>
        sysdate(),
      <if test="updateBy != null">
        #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="remark != null">
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="businessInstructions != null">
        #{businessInstructions,jdbcType=VARCHAR},
      </if>
      <if test="reminderInstructions != null">
        #{reminderInstructions,jdbcType=VARCHAR},
      </if>
      <if test="imgId != null">
        #{imgId,jdbcType=VARCHAR},
      </if>
      <if test="stationType != null">
        #{stationType,jdbcType=SMALLINT},
      </if>
      <if test="serviceTel != null">
        #{serviceTel,jdbcType=VARCHAR},
      </if>
      <if test="parkNums != null">
        #{parkNums,jdbcType=INTEGER},
      </if>
      <if test="tenantId != null">
        #{tenantId,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

    <update id="updateByPrimaryKeySelective" parameterType="com.xhpc.activity.domain.XhpcWorkStationDomain">
    update xhpc_work_station
    <set>
      <if test="name != null">
        `name` = #{name,jdbcType=VARCHAR},
      </if>
      <if test="operatorId != null">
        operator_id = #{operatorId,jdbcType=BIGINT},
      </if>
      <if test="type != null">
        `type` = #{type,jdbcType=INTEGER},
      </if>
      <if test="constructionSite != null">
        construction_site = #{constructionSite,jdbcType=SMALLINT},
      </if>
      <if test="serviceFacilities != null">
        service_facilities = #{serviceFacilities,jdbcType=VARCHAR},
      </if>
      <if test="peripheryFacilities != null">
        periphery_facilities = #{peripheryFacilities,jdbcType=VARCHAR},
      </if>
      <if test="address != null">
        address = #{address,jdbcType=VARCHAR},
      </if>
      <if test="detailedAddress != null">
        detailed_address = #{detailedAddress,jdbcType=VARCHAR},
      </if>
      <if test="longitude != null">
        longitude = #{longitude,jdbcType=VARCHAR},
      </if>
      <if test="latitude != null">
        latitude = #{latitude,jdbcType=VARCHAR},
      </if>
      <if test="parkingInstructions != null">
        parking_instructions = #{parkingInstructions,jdbcType=VARCHAR},
      </if>
      <if test="serialNumber != null">
        serial_number = #{serialNumber,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        `status` = #{status,jdbcType=INTEGER},
      </if>
        update_time = sysdate(),
      <if test="updateBy != null">
        update_by = #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="remark != null">
        remark = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="businessInstructions != null">
        business_instructions = #{businessInstructions,jdbcType=VARCHAR},
      </if>
      <if test="reminderInstructions != null">
        reminder_instructions = #{reminderInstructions,jdbcType=VARCHAR},
      </if>
      <if test="imgId != null">
        img_id = #{imgId,jdbcType=VARCHAR},
      </if>
      <if test="stationType != null">
        station_type = #{stationType,jdbcType=SMALLINT},
      </if>
      <if test="serviceTel != null">
        service_tel = #{serviceTel,jdbcType=VARCHAR},
      </if>
      <if test="parkNums != null">
        park_nums = #{parkNums,jdbcType=INTEGER},
      </if>
      <if test="tenantId != null">
        tenant_id = #{tenantId,jdbcType=VARCHAR},
      </if>
    </set>
    where work_station_id = #{workStationId,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.xhpc.activity.domain.XhpcWorkStationDomain">
    update xhpc_work_station
    set `name` = #{name,jdbcType=VARCHAR},
      operator_id = #{operatorId,jdbcType=BIGINT},
      `type` = #{type,jdbcType=INTEGER},
      construction_site = #{constructionSite,jdbcType=SMALLINT},
      service_facilities = #{serviceFacilities,jdbcType=VARCHAR},
      periphery_facilities = #{peripheryFacilities,jdbcType=VARCHAR},
      address = #{address,jdbcType=VARCHAR},
      detailed_address = #{detailedAddress,jdbcType=VARCHAR},
      longitude = #{longitude,jdbcType=VARCHAR},
      latitude = #{latitude,jdbcType=VARCHAR},
      parking_instructions = #{parkingInstructions,jdbcType=VARCHAR},
      serial_number = #{serialNumber,jdbcType=VARCHAR},
      `status` = #{status,jdbcType=INTEGER},
      update_time = sysdate(),
      update_by = #{updateBy,jdbcType=VARCHAR},
      remark = #{remark,jdbcType=VARCHAR},
      business_instructions = #{businessInstructions,jdbcType=VARCHAR},
      reminder_instructions = #{reminderInstructions,jdbcType=VARCHAR},
      img_id = #{imgId,jdbcType=VARCHAR},
      station_type = #{stationType,jdbcType=SMALLINT},
      service_tel = #{serviceTel,jdbcType=VARCHAR},
      park_nums = #{parkNums,jdbcType=INTEGER},
      tenant_id = #{tenantId,jdbcType=VARCHAR}
    where work_station_id = #{workStationId,jdbcType=BIGINT}
  </update>


  <insert id="insertBatch">
    insert into xhpc_work_station (work_station_id, `name`, operator_id, `type`,
                                   construction_site, service_facilities, periphery_facilities,
                                   address, detailed_address, longitude,
                                   latitude, parking_instructions, serial_number,
                                   `status`, del_flag, create_time,
                                   create_by, update_time, update_by,
                                   remark, business_instructions, reminder_instructions,
                                   img_id, station_type, service_tel,
                                   park_nums, tenant_id)
    values
           <foreach collection="domainList" open="(" item="domain" index="index" separator="," close=")">
             (#{domain.workStationId}, #{domain.name}, #{domain.operatorId}, #{domain.type},
             #{domain.constructionSite}, #{domain.serviceFacilities}, #{domain.peripheryFacilities},
             #{domain.address}, #{domain.detailedAddress}, #{domain.longitude},
             #{domain.latitude}, #{domain.parkingInstructions}, #{domain.serialNumber},
             #{domain.status}, 0, sysdate(),
             #{domain.createBy}, sysdate(), #{domain.updateBy},
             #{domain.remark}, #{domain.businessInstructions}, #{domain.reminderInstructions},
             #{domain.imgId}, #{domain.stationType}, #{domain.serviceTel},
             #{domain.parkNums}, #{domain.tenantId})
           </foreach>

  </insert>


  <select id="selectBySerialNumbers" resultType="com.xhpc.activity.domain.XhpcWorkStationDomain">
    select
    <include refid="Base_Column_List" />
    from xhpc_work_station
    where find_in_set(serial_number, #{serialNumbers})
  </select>

  <select id="selectBySerialNumber" resultType="com.xhpc.activity.domain.XhpcWorkStationDomain">
    select
    <include refid="Base_Column_List" />
    from xhpc_work_station
    where serial_number=#{serialNumber}
  </select>


</mapper>