<?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="jnpf.store.mapper.StoreUserMapper">

    <resultMap id="storeUserResultMap" type="jnpf.entity.StoreUserEntity">
        <id property="id" column="F_Id" jdbcType="VARCHAR"/>
        <result property="storeId" column="F_StoreId" jdbcType="VARCHAR"/>
        <result property="userId" column="F_UserId" jdbcType="VARCHAR"/>
        <result property="shiftsmarks" column="F_ShiftsMarks" jdbcType="INTEGER"/>
        <result property="creatoruserid" column="F_CreatorUserId" jdbcType="VARCHAR"/>
        <result property="creatortime" column="F_CreatorTime" jdbcType="TIMESTAMP"/>
        <result property="lastmodifyuserid" column="F_LastModifyUserId" jdbcType="VARCHAR"/>
        <result property="lastmodifytime" column="F_LastModifyTime" jdbcType="TIMESTAMP"/>
        <result property="deletemark" column="F_DeleteMark" jdbcType="INTEGER"/>
        <result property="deletetime" column="F_DeleteTime" jdbcType="TIMESTAMP"/>
        <result property="deleteuserid" column="F_DeleteUserId" jdbcType="VARCHAR"/>
        <result property="tenantid" column="F_TenantId" jdbcType="VARCHAR"/>
    </resultMap>

    <insert id="createStoreUser" parameterType="java.util.List">
        insert into ftb_store_user (F_Id, F_StoreId, F_UserId, F_ShiftsMarks, F_CreatorUserId,
        F_CreatorTime, F_LastModifyUserId, F_LastModifyTime, F_DeleteMark, F_DeleteTime, F_DeleteUserId, F_TenantId)
        values
        <foreach collection="list" item="storeUser" index="index" separator=",">
            (
            #{storeUser.id},
            #{storeUser.storeid},
            #{storeUser.userid},
            #{storeUser.shiftsmarks},
            #{storeUser.creatoruserid},
            #{storeUser.creatortime},
            #{storeUser.lastmodifyuserid},
            #{storeUser.lastmodifytime},
            #{storeUser.deletemark},
            #{storeUser.deletetime},
            #{storeUser.deleteuserid},
            #{storeUser.tenantid}
            )
        </foreach>
    </insert>

    <select id="getByStoreId" resultType="jnpf.entity.StoreUserEntity" >
        select F_Id as id, F_StoreId as storeId, F_UserId as userId, F_ShiftsMarks as shiftsmarks,F_PositionId as positionId,F_OrganizeId as organizeId,F_GradeId as gradeId,F_TargetType as targetType,F_TenantId as tenantId from ftb_store_user where F_StoreId = #{storeId}
    </select>
    <!-- 查询门店下的成员 -->
    <select id="getStoreUserList" resultType="java.lang.String">
        select F_UserId from base_userrelation where F_ObjectType = 'Organize' and F_ObjectId = (
            select F_OrganizeId from ftb_store where F_Id = #{storeId}
        )
    </select>
    <delete id="deleteByStoreId" >
        delete from ftb_store_user where F_StoreId = #{storeId}
    </delete>

    <select id="queryStoreUserInfo" resultType="jnpf.model.personnels.dto.staff.roster.SimpleStoreUserDto">
        select F_StoreName as storeName, b.F_UserId as userId, b.F_StoreId as storeId
        from ftb_store as a
                 left join ftb_store_user_relation as b on a.F_Id = b.F_StoreId
        where
        a.F_DeleteMark=0  and b.F_DeleteMark=0 and a.F_OrganizeId = #{orgId}
          and b.F_UserId = #{userId} limit 1

    </select>
</mapper>
