package org.linlinjava.jz.db.service;

import com.github.pagehelper.PageHelper;
import org.linlinjava.jz.db.dao.SysUserRestMapper;
import org.linlinjava.jz.db.domain.SysUserRest;
import org.linlinjava.jz.db.domain.SysUserRestExample;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * 客服休息时间统计
 */
@Service
public class JzSysUserRestService {

    private final SysUserRest.Column[] result = new SysUserRest.Column[]{SysUserRest.Column.id, SysUserRest.Column.userId, SysUserRest.Column.type, SysUserRest.Column.duration};
    @Resource
    private SysUserRestMapper restMapper;

    public SysUserRest findUserRest(Integer id) {
        return restMapper.selectByPrimaryKey(id);
    }

    public List<SysUserRest> querySelective(Integer page, Integer limit, String sort, String order) {
        SysUserRestExample example = new SysUserRestExample();
        SysUserRestExample.Criteria criteria = example.createCriteria();

        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }

        PageHelper.startPage(page, limit);
        return restMapper.selectByExampleSelective(example);
    }


    public int updateById(SysUserRest admin) {
        return restMapper.updateByPrimaryKeySelective(admin);
    }


    public void add(SysUserRest admin) {
        restMapper.insertSelective(admin);
    }

    public SysUserRest findById(Integer id) {
        return restMapper.selectByPrimaryKeySelective(id, result);
    }

    public List<SysUserRest> all() {
        SysUserRestExample example = new SysUserRestExample();
        return restMapper.selectByExampleSelective(example, result);
    }
}
