<?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.house365.ws.dao.mapper.PlatRuleMapper">

    <resultMap id="infoMap" type="com.house365.beans.entity.PlatRuleEntity">
        <result property="id" column="id"/>
        <result property="platGroupName" column="platGroupName"/>
        <result property="salesGroupName" column="salesGroupName"/>
        <result property="platGroupIds" column="platGroupIds"/>
        <result property="salesGroupIds" column="salesGroupIds"/>
        <result property="createTime" column="createTime"/>
        <result property="createrId" column="createrId"/>
        <result property="createrName" column="createrName"/>
    </resultMap>

    <select id="getPlatRuleList" resultMap="infoMap" parameterType="map">
        SELECT id,platGroupName,salesGroupName,platGroupIds,salesGroupIds,createrName,createTime,createrId
        FROM plat_rule
        where cityCode = #{cityCode}
        limit #{startNum},#{pageSize}
    </select>

    <select id="countPlatRule" resultType="Integer" parameterType="map">
        SELECT count(*)
        FROM plat_rule
        where cityCode = #{cityCode}
    </select>

    <select id="getRuleById" resultMap="infoMap" parameterType="String">
        SELECT id,platGroupName,salesGroupName,platGroupIds,salesGroupIds,createrName,createTime,createrId
        FROM plat_rule
        where id = #{ruleId}
    </select>

    <select id="queryDeptList" resultMap="infoMap" parameterType="Integer">
        select ur.deptId,pr.platGroupIds,pr.salesGroupIds
        from user ur, plat_rule pr
        where ur.deptId=pr.platGroupIds
        and ur.id=#{userId}
    </select>

    <delete id="delRule" parameterType="String">
        delete from plat_rule where id =#{ruleId}
    </delete>

    <insert id="saveRule" parameterType="com.house365.beans.entity.PlatRuleEntity">
            INSERT INTO
            plat_rule (
                platGroupIds,
                salesGroupIds,
                platGroupName,
                salesGroupName,
                createrId,
                createrName,
                createTime,
                updateTime,
                cityCode
                )
            VALUES (
                #{platGroupIds},
                #{salesGroupIds},
                #{platGroupName},
                #{salesGroupName},
                #{createrId},
                #{createrName},
                #{createTime},
                #{updateTime},
                #{cityCode}
            )
    </insert>

    <update id="modifyRule" parameterType="com.house365.beans.entity.PlatRuleEntity">
            update plat_rule set platGroupIds =#{platGroupIds},salesGroupIds =#{salesGroupIds},platGroupName =#{platGroupName},salesGroupName =#{salesGroupName},updateTime =#{updateTime}
            where id=#{id}
    </update>

</mapper>