package com.fdkanfang.service.backend.impl;

import com.fdkanfang.common.model.PageDto;
import com.fdkanfang.dao.backend.IBaseMapper;
import com.fdkanfang.dao.backend.UserMapper;
import com.fdkanfang.domain.backend.UserEntity;
import com.fdkanfang.domain.response.UserResponse;
import com.fdkanfang.service.BaseMapperServiceImpl;
import com.fdkanfang.service.backend.UserService2;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * Created by owen on 2020/3/11 0011 16:16
 */
@Service
public class UserServiceImpl2 extends BaseMapperServiceImpl<UserEntity, Long> implements UserService2 {

    @Autowired
    private UserMapper entityMapper;

    @Override
    public IBaseMapper<UserEntity, Long> getBaseMapper() {
        return this.entityMapper;
    }

    @Override
    public List<UserResponse> findAllBySearchKey(PageDto param) {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        return entityMapper.findAllBySearchKey(param.getSearchKey());
    }

    @Override
    public UserEntity findByUserName(String userName) {
        return entityMapper.findByUserName(userName);
    }

    @Override
    public void deleteUserRoleByUserId(Long id) {
        entityMapper.deleteUserRoleByUserId(id);
    }

    @Override
    public void saveUserRole(Long userId, Long roleId) {
        entityMapper.saveUserRole(userId, roleId);
    }

    @Override
    public Set<String> findRoleByUserId(Long userId) {
        return entityMapper.findRoleByUserId(userId);
    }

    @Override
    public UserEntity findByPhone(String phone) {
        return entityMapper.findByPhone(phone);
    }

    @Override
    public Set<Integer> findRoleIdByUserId(Long id) {
        return entityMapper.findRoleIdByUserId(id);
    }
}
