package com.sptg.statistics.biz.service.impl;

import com.baomidou.mybatisplus.enums.SqlLike;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.sptg.statistics.api.dto.AppMemberLoginRecordsDto;
import com.sptg.statistics.api.entity.AppMemberLoginRecords;
import com.sptg.statistics.biz.mapper.AppMemberLoginRecordsMapper;
import com.sptg.statistics.biz.service.AppMemberLoginRecordsServiceInterface;
import org.springframework.stereotype.Service;

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

/**
 * title: AppMemberLoginRecordsServiceImpl
 * package: com.sptg.statistics.biz.security.impl
 * description: 会员登录记录-服务层实现类
 *
 *                
 *                
 */
@Service
public class AppMemberLoginRecordsServiceImpl extends ServiceImpl<AppMemberLoginRecordsMapper, AppMemberLoginRecords> implements AppMemberLoginRecordsServiceInterface {

    @Override
    public List<Map<String, Object>> getMemberLoginCountList(AppMemberLoginRecordsDto dto) {
        EntityWrapper<AppMemberLoginRecords> wrapper=new EntityWrapper<>();
        //按日查询
        String sqlSelect="SUM(CASE WHEN i_login_type = 0 THEN 1 ELSE 0 END) AS smallCount," +
                "SUM(CASE WHEN i_login_type = 1 THEN 1 ELSE 0 END) AS appCount,DATE_FORMAT(t_login_date,'%H') AS indexDate";
        wrapper.setSqlSelect(sqlSelect);
        wrapper.where("DATE_FORMAT(t_login_date,'%Y-%m-%d')=DATE_FORMAT(NOW(),'%Y-%m-%d')");
        //权限
        wrapper.like("s_org_position", dto.getOrgPosition(), SqlLike.RIGHT);
        //分组
        wrapper.groupBy("indexDate");
        return this.selectMaps(wrapper);
    }
}
