package com.ssm.manage.service.impl;

import com.github.pagehelper.PageInfo;
import com.ssm.core.service.impl.BaseServiceImpl;
import com.ssm.manage.dao.SsmSysRoleUserDao;
import com.ssm.manage.entity.SmsException;
import com.ssm.manage.entity.SysRoleUser;
import com.ssm.manage.query.RoleUserRequest;
import com.ssm.manage.query.UserRequest;
import com.ssm.manage.service.SsmSysRoleUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SsmSysRoleUserServiceImpl extends BaseServiceImpl<SysRoleUser> implements SsmSysRoleUserService {
    @Autowired
    private SsmSysRoleUserDao dao;

    @Override
    public SsmSysRoleUserDao getDao() {
        return dao;
    }

    @Override
    public int addRoleUser(RoleUserRequest roleUserRequest) throws SmsException {
        return dao.addRoleUser(roleUserRequest);
    }

    @Override
    public PageInfo<SysRoleUser> rolePage(RoleUserRequest roleUserRequest) {
        return dao.rolePage(roleUserRequest);
    }

    @Override
    public List<SysRoleUser> roleUserList(RoleUserRequest roleUserRequest) {
        SysRoleUser sysRoleUser = new SysRoleUser();
        if (roleUserRequest.getUserId() != null) {
            sysRoleUser.setUserId(roleUserRequest.getUserId());
        }
        if (roleUserRequest.getRoleId() != null) {
            sysRoleUser.setRoleId(roleUserRequest.getRoleId());
        }
        return dao.select(sysRoleUser);
    }
}
