<?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.ssm.manage.dao.SysStoreRoleDao">

    <resultMap type="com.ssm.manage.entity.SysStoreRole" id="SysStoreRoleMap">
        <result property="roleNum" column="role_num" jdbcType="VARCHAR"/>
        <result property="roleName" column="role_name" jdbcType="VARCHAR"/>
        <result property="state" column="state" jdbcType="INTEGER"/>
        <result property="founder" column="Founder" jdbcType="VARCHAR"/>
        <result property="founderDatetime" column="Founder_datetime" jdbcType="TIMESTAMP"/>
        <result property="modifyBy" column="modify_by" jdbcType="VARCHAR"/>
        <result property="modifyDatetime" column="modify_datetime" jdbcType="TIMESTAMP"/>
        <result property="storeId" column="store_id" jdbcType="INTEGER"/>
        <result property="storeNum" column="store_num" jdbcType="VARCHAR"/>
        <result property="storeName" column="store_name" jdbcType="VARCHAR"/>
        <result property="id" column="id" jdbcType="INTEGER"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="SysStoreRoleMap">
        select
          role_num, role_name, state, Founder, Founder_datetime, modify_by, modify_datetime, store_id, store_num, store_name, id
        from sys_store_role
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="SysStoreRoleMap">
        select
          role_num, role_name, state, Founder, Founder_datetime, modify_by, modify_datetime, store_id, store_num, store_name, id
        from sys_store_role
        <where>
            <if test="roleNum != null and roleNum != ''">
                and role_num = #{roleNum}
            </if>
            <if test="roleName != null and roleName != ''">
                and role_name = #{roleName}
            </if>
            <if test="state != null">
                and state = #{state}
            </if>
            <if test="founder != null and founder != ''">
                and Founder = #{founder}
            </if>
            <if test="founderDatetime != null">
                and Founder_datetime = #{founderDatetime}
            </if>
            <if test="modifyBy != null and modifyBy != ''">
                and modify_by = #{modifyBy}
            </if>
            <if test="modifyDatetime != null">
                and modify_datetime = #{modifyDatetime}
            </if>
            <if test="storeId != null">
                and store_id = #{storeId}
            </if>
            <if test="storeNum != null and storeNum != ''">
                and store_num = #{storeNum}
            </if>
            <if test="storeName != null and storeName != ''">
                and store_name = #{storeName}
            </if>
            <if test="id != null">
                and id = #{id}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from sys_store_role
        <where>
            <if test="roleNum != null and roleNum != ''">
                and role_num = #{roleNum}
            </if>
            <if test="roleName != null and roleName != ''">
                and role_name = #{roleName}
            </if>
            <if test="state != null">
                and state = #{state}
            </if>
            <if test="founder != null and founder != ''">
                and Founder = #{founder}
            </if>
            <if test="founderDatetime != null">
                and Founder_datetime = #{founderDatetime}
            </if>
            <if test="modifyBy != null and modifyBy != ''">
                and modify_by = #{modifyBy}
            </if>
            <if test="modifyDatetime != null">
                and modify_datetime = #{modifyDatetime}
            </if>
            <if test="storeId != null">
                and store_id = #{storeId}
            </if>
            <if test="storeNum != null and storeNum != ''">
                and store_num = #{storeNum}
            </if>
            <if test="storeName != null and storeName != ''">
                and store_name = #{storeName}
            </if>
            <if test="id != null">
                and id = #{id}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into sys_store_role(role_num, role_name, state, Founder, Founder_datetime, modify_by, modify_datetime, store_id, store_num, store_name)
        values (#{roleNum}, #{roleName}, #{state}, #{founder}, #{founderDatetime}, #{modifyBy}, #{modifyDatetime}, #{storeId}, #{storeNum}, #{storeName})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into sys_store_role(role_num, role_name, state, Founder, Founder_datetime, modify_by, modify_datetime, store_id, store_num, store_name)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.roleNum}, #{entity.roleName}, #{entity.state}, #{entity.founder}, #{entity.founderDatetime}, #{entity.modifyBy}, #{entity.modifyDatetime}, #{entity.storeId}, #{entity.storeNum}, #{entity.storeName})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into sys_store_role(role_num, role_name, state, Founder, Founder_datetime, modify_by, modify_datetime, store_id, store_num, store_name)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.roleNum}, #{entity.roleName}, #{entity.state}, #{entity.founder}, #{entity.founderDatetime}, #{entity.modifyBy}, #{entity.modifyDatetime}, #{entity.storeId}, #{entity.storeNum}, #{entity.storeName})
        </foreach>
        on duplicate key update
        role_num = values(role_num),
        role_name = values(role_name),
        state = values(state),
        Founder = values(Founder),
        Founder_datetime = values(Founder_datetime),
        modify_by = values(modify_by),
        modify_datetime = values(modify_datetime),
        store_id = values(store_id),
        store_num = values(store_num),
        store_name = values(store_name)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update sys_store_role
        <set>
            <if test="roleNum != null and roleNum != ''">
                role_num = #{roleNum},
            </if>
            <if test="roleName != null and roleName != ''">
                role_name = #{roleName},
            </if>
            <if test="state != null">
                state = #{state},
            </if>
            <if test="founder != null and founder != ''">
                Founder = #{founder},
            </if>
            <if test="founderDatetime != null">
                Founder_datetime = #{founderDatetime},
            </if>
            <if test="modifyBy != null and modifyBy != ''">
                modify_by = #{modifyBy},
            </if>
            <if test="modifyDatetime != null">
                modify_datetime = #{modifyDatetime},
            </if>
            <if test="storeId != null">
                store_id = #{storeId},
            </if>
            <if test="storeNum != null and storeNum != ''">
                store_num = #{storeNum},
            </if>
            <if test="storeName != null and storeName != ''">
                store_name = #{storeName},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from sys_store_role where id = #{id}
    </delete>

</mapper>

