package cn.feast.coding.service.system;

import cn.feast.coding.mapper.system.UserRoleMapper;
import cn.feast.coding.model.generator.Page;
import cn.feast.coding.model.system.UserRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created By FeastCoding.
 */
@Service
public class UserRoleService {

    @Autowired
    private UserRoleMapper mapper;

    public Integer save(UserRole userRole) {
        return mapper.save(userRole);
    }

    public void update(UserRole userRole) {
        mapper.update(userRole);
    }

    public void deleteById(Integer id) {
        mapper.deleteById(id);
    }

    public int queryByCount(UserRole userRole) {
        return mapper.queryByCount(userRole);
    }

    public List<UserRole> queryByList(Page page, UserRole userRole) {
        String pageQueryCondition = " limit " + page.getStart() + " , " + page.getMaxRows();
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("userid", userRole.getUserid());
        paramsMap.put("pageQueryCondition", pageQueryCondition);
        return mapper.queryByList(paramsMap);
    }

    public List<UserRole> queryByUserRole(UserRole userRole) {
        return mapper.queryByUserRole(userRole);
    }

    public UserRole queryById(Integer id) {
        return mapper.queryById(id);
    }

    public void deleteByUser(Integer userid) {
        mapper.deleteByUser(userid);
    }

    public List<UserRole> queryByUser(Integer userid) {
        return mapper.queryByUser(userid);
    }
}
