<?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.ho.user.mapper.PermStationRelationMapper">

    <resultMap id="BaseResultMap" type="com.ho.user.api.entity.PermStationRelation">
            <id property="id" column="id" jdbcType="INTEGER"/>
            <result property="permissionId" column="permission_id" jdbcType="INTEGER"/>
            <result property="stationId" column="station_id" jdbcType="INTEGER"/>
            <result property="stationName" column="station_name"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,permission_id,station_id,station_name,
        create_time
    </sql>

    <insert id="insertSelective">
        insert into perm_station_relation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="permissionId != null">
                permission_id,
            </if>
            <if test="stationId != null">
                station_id,
            </if>
            <if test="stationName != null">
                station_name,
            </if>
            <if test="createTime != null">
                create_time
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="permissionId != null">
                #{permissionId},
            </if>
            <if test="stationId != null">
                #{stationId},
            </if>
            <if test="stationName != null">
                #{stationName},
            </if>
            <if test="createTime != null">
                #{createTime}
            </if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective">
        update perm_station_relation
        <set>
            <if test="permissionId != null">
                permission_id = #{permissionId},
            </if>
            <if test="stationId != null">
                station_id = #{stationId},
            </if>
            <if test="stationName != null">
                station_name = #{stationName},
            </if>
            <if test="createTime != null">
                create_time = #{createTime}
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>

    <update id="updateByPrimaryKey">
        update perm_station_relation
        set permission_id = #{permissionId},
            station_id = #{stationId},
            station_name = #{stationName},
            create_time = #{createTime}
        where id = #{id,jdbcType=INTEGER}
    </update>

    <delete id="deleteByPrimaryKey">
        delete from perm_station_relation
        where id = #{id}
    </delete>








<!--      <insert id="batchUserRole" parameterType="com.ho.user.entity.SysUserRole">
          INSERT INTO perm_station_relation (
          id,
          role_id,
          user_id,
          create_time
          )
          VALUES
          <foreach item="item" collection="list" index="index" separator=",">
              (
              #{item.id},
              #{item.roleId},
              #{item.userId},
              #{item.createTime}
              )
          </foreach>
      </insert>-->






      <delete id="removeByUserIds">
          delete
          from perm_station_relation
          where  permission_id  in
          <foreach collection="list" open="(" close=")" separator="," item="item">
              #{item}
          </foreach>
      </delete>

    <delete id="deleteBatch">
        delete
        from perm_station_relation
        <where>
            <if test="ids != null and ids.size !=0">
                and id in
                <foreach collection="ids" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
    </delete>

    <delete id="deleteBatchStationId">
        delete
        from perm_station_relation
        <where>
            <if test="ids != null and ids.size !=0">
                and station_id in
                <foreach collection="ids" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
    </delete>

    <select id="selectByStationId" resultType="com.ho.user.api.entity.PermStationRelation">
        select
        <include refid="Base_Column_List"></include>
        from perm_station_relation
        where station_id = #{stationId}
    </select>

    <select id="selectByPermissionId" resultType="com.ho.user.api.entity.PermStationRelation">
        select
        <include refid="Base_Column_List"></include>
        from perm_station_relation
        where permission_id = #{permissionId}
    </select>

    <select id="selectAll" resultType="com.ho.user.api.entity.PermStationRelation">
        select
        <include refid="Base_Column_List"></include>
        from perm_station_relation
        <where>
            <if test="vo.stationName != null and record.name != ''">
                and station_name LIKE concat('%',#{vo.stationName},'%')
            </if>
        </where>

    </select>

</mapper>
