package ink.wgink.login.base.service.log.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.login.base.dao.log.ILoginLogDao;
import ink.wgink.login.base.pojo.dtos.log.LoginLogDTO;
import ink.wgink.login.base.service.log.ILoginLogService;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.SuccessResultList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: LoginLogServiceImpl
 * @Description: 登录日志
 * @Author: wanggeng
 * @Date: 2021/2/28 10:39 上午
 * @Version: 1.0
 */
@Service
public class LoginLogServiceImpl extends DefaultBaseService implements ILoginLogService {

    @Autowired
    private ILoginLogDao loginLogDao;

    @Override
    public void save(Map<String, Object> params) {
        loginLogDao.save(params);
    }

    @Override
    public Integer countDay(String day) {
        Map<String, Object> params = getHashMap(2);
        params.put("day", day);
        Integer count = loginLogDao.count(params);
        return count == null ? 0 : count;
    }

    @Override
    public SuccessResultList<List<LoginLogDTO>> listPage(ListPage page) {
        PageHelper.startPage(page.getPage(), page.getRows());
        List<LoginLogDTO> loginLoggerDTOs = loginLogDao.list(page.getParams());
        PageInfo<LoginLogDTO> pageInfo = new PageInfo<>(loginLoggerDTOs);
        return new SuccessResultList<>(loginLoggerDTOs, pageInfo.getPageNum(), pageInfo.getTotal());
    }
}
