package cn.com.oa.service.impl;

import cn.com.oa.common.constant.DataService;
import cn.com.oa.mapper.UserLoginMapper;
import cn.com.oa.model.Company;
import cn.com.oa.model.UserLogin;
import cn.com.oa.service.IUserLoginService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 */
@Service
public class UserLoginServiceImpl extends ServiceImpl<UserLoginMapper, UserLogin> implements IUserLoginService {

    @Override
    public Map<String, Object> getUserLoginCount() {
        Map constantData = DataService.getConstantData();
        Company company = (Company)constantData.get("company");
        LambdaQueryWrapper<UserLogin> queryWrapper = new LambdaQueryWrapper<>();
        LocalDate today = LocalDate.now();
        queryWrapper.apply("DATE(loginTime) = {0}", today.toString())
                .eq(UserLogin::getCompanyId,company.getUNIVERSALID());
        int countToday = baseMapper.selectCount(queryWrapper);
        Map<String,Object> userLoginCount = new HashMap<>();
        userLoginCount.put("countToday",countToday);
        return userLoginCount;
    }
}
