package com.xinyilu.web.controller.applogmanagestatistics;

import com.xinyilu.common.core.controller.BaseController;
import com.xinyilu.common.core.domain.AjaxResult;
import com.xinyilu.common.core.page.TableDataInfo;
import com.xinyilu.system.domain.dto.AppLogManageStatisticsDTO;
import com.xinyilu.system.domain.vo.applogmanagestatistics.AppLogManageStatisticsVO;
import com.xinyilu.system.service.applogmanagestatistics.AppLogManageStatisticsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @Description PC端家长小程序登录日志统计控制器
 * @Author 纪寒
 * @Date 2023-04-14 13:57:08
 * @Version 1.0
 */
@RestController
@RequestMapping("/system/appLogManage")
public class AppLogManageStatisticsController extends BaseController {

    @Resource
    private AppLogManageStatisticsService appLogManageStatisticsService;

    /**
     * 小程序访问日志统计
     *
     * @param logManageStatistics 检索条件
     * @return 统计结果
     */
//    @PreAuthorize("@ss.hasPermi('system:appLogManage:appletVisitRecord')")
    @PostMapping("/appletVisitRecord")
    public TableDataInfo appletVisitRecord(AppLogManageStatisticsDTO logManageStatistics) {
        startPage();
        List<AppLogManageStatisticsVO> appLogManageStatisticsList = appLogManageStatisticsService.appletVisitRecord(logManageStatistics);
        return getDataTable(appLogManageStatisticsList);
    }

    /**
     * 小程序日志-按个人统计
     *
     * @param logManageStatistics 检索条件
     * @return 统计结果
     */
//    @PreAuthorize("@ss.hasPermi('system:appLogManage:appletPersonCount')")
    @GetMapping("/appletPersonCount")
    public TableDataInfo appletPersonCount(AppLogManageStatisticsDTO logManageStatistics) {
        return appLogManageStatisticsService.appletPersonCount(logManageStatistics);
    }

    /**
     * 小程序访问日志-按园所统计
     *
     * @param logManageStatistics 检索条件
     * @return 统计结果
     */
//    @PreAuthorize("@ss.hasPermi('system:appLogManage:appletKindergartenCount')")
    @GetMapping("/appletKindergartenCount")
    public TableDataInfo appletKindergartenCount(AppLogManageStatisticsDTO logManageStatistics) {
        return appLogManageStatisticsService.appletKindergartenCount(logManageStatistics);
    }


    /**
     * 查看家长所属的孩子、班级、以及幼儿园的信息
     *
     * @param parentInfoId 家长id
     * @return 统计结果
     */
    @GetMapping("/getParentAndStudentInfo")
    public AjaxResult getParentAndStudentInfo(Long parentInfoId) {
        if (Objects.isNull(parentInfoId)) {
            return AjaxResult.error("家长id不能为空！");
        }
        return appLogManageStatisticsService.getParentAndStudentInfo(parentInfoId);
    }

    /**
     * 按区县统计
     */
//    @PreAuthorize("@ss.hasPermi('system:appLogManage:countyStatistic')")
    @PostMapping("/countyStatistic")
    public TableDataInfo selectCountyStatistic(AppLogManageStatisticsDTO appLogManageStatistic) {
        return appLogManageStatisticsService.selectCountyStatistic(appLogManageStatistic);
    }

    /**
     * 家长打卡统计
     */
//    @PreAuthorize("@ss.hasPermi('system:appLogManage:clockStatistics')")
    @PostMapping("/clockStatistics")
    public TableDataInfo selectClockStatistics(AppLogManageStatisticsDTO appLogManageStatistic) {
        startPage();
        List<AppLogManageStatisticsVO> list = appLogManageStatisticsService.selectClockStatistics(appLogManageStatistic);
        return getDataTable(list);
    }

    /**
     * 家长打卡日历展示
     */
    @PostMapping("/calendarStatistics")
    public AjaxResult selectCalendarStatistics(AppLogManageStatisticsDTO appLogManageStatistic) {
        if (Objects.isNull(appLogManageStatistic) || Objects.isNull(appLogManageStatistic.getStartDate()) || Objects.isNull(appLogManageStatistic.getParentInfoId())) {
            return AjaxResult.error("家长信息为空！");
        }
        return AjaxResult.success(appLogManageStatisticsService.selectCalendarStatistics(appLogManageStatistic));
    }
}
