package ink.wgink.login.base.controller.api.count;

import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.exceptions.ParamsException;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.login.base.service.count.ICountService;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResultData;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: CountController
 * @Description: 统计
 * @Author: wanggeng
 * @Date: 2021/2/28 9:35 上午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "统计")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/count")
public class CountController extends DefaultBaseController {

    @Autowired
    private ICountService countService;

    @ApiOperation(value = "统计新增用户数量统计（按周统计）", notes = "统计新增用户数量统计（按周统计）接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("count-new-user-by-week")
    public SuccessResultData<Map<String, Object>> countNewUserByWeek() {
        Map<String, Object> params = getParams();
        return new SuccessResultData<>(countService.countNewUserByWeek(params));
    }

    @ApiOperation(value = "统计用户数量", notes = "统计用户数量接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("count-user")
    public SuccessResultData<Map<String, Object>> countUser() {
        Map<String, Object> params = getParams();
        return new SuccessResultData<>(countService.countUser(params));
    }

    @ApiOperation(value = "系统登录量统计", notes = "系统登录量统计接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("count-login")
    public SuccessResultData<Map<String, Object>> countLogin() {
        Map<String, Object> params = getParams();
        return new SuccessResultData<>(countService.countLogin(params));
    }

    @ApiOperation(value = "系统登录量统计（按展示天数）", notes = "系统登录量统计（按展示天数）接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "days", value = "展示天数", paramType = "path"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("count-login-for-days/{days}")
    public SuccessResultData<Map<String, Object>> countLoginForDays(@PathVariable("days") Integer days) {
        if (days < 1) {
            throw new ParamsException("天数格式错误");
        }
        return new SuccessResultData<>(countService.countLoginForDays(days));
    }

    @ApiOperation(value = "统计机构数量", notes = "统计机构数量接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("count-department")
    public SuccessResultData<Integer> countDepartment() {
        return new SuccessResultData<>(countService.countDepartment());
    }

    @ApiOperation(value = "统计角色数量", notes = "统计角色数量接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("count-role")
    public SuccessResultData<Integer> countRole() {
        return new SuccessResultData<>(countService.countRole());
    }

    @ApiOperation(value = "统计职位数量", notes = "统计职位数量接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("count-position")
    public SuccessResultData<Integer> countPosition() {
        return new SuccessResultData<>(countService.countPosition());
    }

    @ApiOperation(value = "统计用户类型比例", notes = "统计用户类型比例接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("count-user-type-proportion")
    public SuccessResultData<List<Map<String, Object>>> countUserTypeProportion() {
        return new SuccessResultData<>(countService.countUserTypeProportion());
    }

    @ApiOperation(value = "统计用户状态比例", notes = "统计用户状态比例接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("count-user-state-proportion")
    public SuccessResultData<List<Map<String, Object>>> countUserStateProportion() {
        return new SuccessResultData<>(countService.countUserStateProportion());
    }

}
