package com.elink.esua.epdc.modules.analysis.controller;

import com.elink.esua.epdc.common.token.dto.TokenDto;
import com.elink.esua.epdc.common.token.dto.WorkUserAuthorizationDTO;
import com.elink.esua.epdc.common.token.dto.WorkUserLoginDTO;
import com.elink.esua.epdc.commons.tools.annotation.LoginUser;
import com.elink.esua.epdc.commons.tools.utils.Result;
import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils;
import com.elink.esua.epdc.dto.form.EpdcWorkAppUserMaTokenFormDTO;
import com.elink.esua.epdc.dto.user.form.MemberRankFormDTO;
import com.elink.esua.epdc.dto.user.form.UserSortRankFormDTO;
import com.elink.esua.epdc.dto.user.form.UserCountDTO;
import com.elink.esua.epdc.dto.user.result.OldMemberRankResultDTO;
import com.elink.esua.epdc.dto.user.result.UserSortRankResultDTO;
import com.elink.esua.epdc.dto.user.result.YoungMemberRankResultDTO;
import com.elink.esua.epdc.modules.analysis.service.AnalysisUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 移动端接口-数据分析模块(项目)
 * @Author LPF
 * @Date 2019/11/18 13:32
 */
@RestController
@RequestMapping("analysis/user")
public class ApiAnalysisUserController {

    @Autowired
    private AnalysisUserService analysisUserService;


    /**
     * 测试demo

     * @Return: com.elink.esua.epdc.commons.tools.utils.Result<>
     * @Author: lipengfei
     * @Date: 2019/11/19 16:34
     */
    @GetMapping("test")
    public Result test(@LoginUser TokenDto tokenDto) {
        return analysisUserService.test();
    }

    /**
     *
     * 数据分析端-用户登录
     *
     * @params [formDto]
     * @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.common.token.dto.WorkUserAuthorizationDTO>
     * @author liuchuang
     * @since 2020/2/12 10:57
     */
    @PostMapping("login")
    public Result<WorkUserAuthorizationDTO> login(@RequestBody WorkUserLoginDTO formDto) {
        ValidatorUtils.validateEntity(formDto);
        return analysisUserService.login(formDto);
    }

    /**
     *
     * 数据分析端-获取token
     *
     * @params [formDto]
     * @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.common.token.dto.WorkUserAuthorizationDTO>
     * @author liuchuang
     * @since 2020/2/12 10:58
     */
    @GetMapping("getToken")
    public Result<WorkUserAuthorizationDTO> getMaToken(EpdcWorkAppUserMaTokenFormDTO formDto) {
        ValidatorUtils.validateEntity(formDto);
        return analysisUserService.getMaToken(formDto);
    }

    @GetMapping("/partyMemberOldSort")
    public Result<List<OldMemberRankResultDTO>> listOldMemberRankByDeptId(MemberRankFormDTO formDto) {
        return analysisUserService.listOldMemberRankByDeptId(formDto);
    }
    @GetMapping("/partyMemberYoungSort")
    public Result<List<YoungMemberRankResultDTO>> listYoungMemberRankByDeptId(MemberRankFormDTO formDto) {
        return analysisUserService.listYoungMemberRankByDeptId(formDto);
    }

    /**
     *用户数据统计
     *
     * @author wangtong
     * @date 2020/2/11 11:32
     * @param formDto
     * @return com.elink.esua.epdc.commons.tools.utils.Result
     */
    @GetMapping("/getUserStatistics")
    public Result getUserStatistics(UserCountDTO formDto) {
        return analysisUserService.getUserStatistics(formDto);
    }

    /**
     *网格开通状况
     *
     * @author wangtong
     * @date 2020/2/11 14:22
     * @param formDto
     * @return com.elink.esua.epdc.commons.tools.utils.Result
     */
    @GetMapping("/getGridStatistics")
    public Result getGridStatistics(UserCountDTO formDto) {
        return analysisUserService.getGridStatistics(formDto);
    }
    @GetMapping("/userRegisterSort")
    public Result<List<UserSortRankResultDTO>> userRegisterSort(UserSortRankFormDTO formDto) {
        return analysisUserService.userRegisterSort(formDto);
    }
}
