package cn.pluss.platform.merchant;

import cn.pluss.platform.entity.StaffPermission;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;

/**
 * <p>
 * 员工权限表 服务类
 * </p>
 *
 * @author Djh
 * @since 2021-06-11
 */
public interface StaffPermissionService extends IService<StaffPermission> {

    /**
     * 获取一个员工权限信息
     * @param userId            用户id
     * @param merchantCode      商户编号
     * @return  组装好的信息
     */
    default StaffPermission getEntity(Long userId, String merchantCode) {
        StaffPermission staffPermission = new StaffPermission();
        staffPermission.setUserId(userId);
        staffPermission.setMerchantCode(merchantCode);

        StaffPermission existData = getOne(new QueryWrapper<>(staffPermission));
        return existData == null? staffPermission : existData;
    }

    /**
     * 移除指定员工权限信息
     * @param userId        员工账号id
     * @param merchantCode  商户编码
     */
    default void remove(Long userId, String merchantCode) {
        QueryWrapper<StaffPermission> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId", userId);
        queryWrapper.eq("merchantCode", merchantCode);
        remove(queryWrapper);
    }
}
