package com.hzs.member.statis.controller.manager;

import com.hzs.common.core.constant.CacheConstants;
import com.hzs.common.core.enums.ETop30Type;
import com.hzs.common.core.service.RedisService;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.member.statis.param.DirectStatisticsTop30QueryParam;
import com.hzs.member.statis.service.IMemberStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 统计
 */
@Slf4j
@RequestMapping("/manage/member-statistics")
@RestController
public class BackMemberStatisticsController {

    @Resource
    private IMemberStatisticsService memberStatisticsService;

    @Resource
    private RedisService redisService;


    @GetMapping("/setShowPeople/{flag}")
    public AjaxResult setShowPeople(@PathVariable("flag") String flag) {
        redisService.setCacheObject(CacheConstants.TOP_30_ACTIVITY + ETop30Type.PEOPLE.getKey(), flag);
        return AjaxResult.success();
    }


    @GetMapping("/setShowAmount/{flag}")
    public AjaxResult setShowAmount(@PathVariable("flag") String flag) {
        redisService.setCacheObject(CacheConstants.TOP_30_ACTIVITY + ETop30Type.AMOUNT.getKey(), flag);
        return AjaxResult.success();
    }


    @GetMapping("/getShowPeople")
    public AjaxResult getShowPeople() {
        return AjaxResult.success("操作成功!", redisService.getCacheObject(CacheConstants.TOP_30_ACTIVITY + ETop30Type.PEOPLE.getKey()));
    }

    @GetMapping("/getShowAmount")
    public AjaxResult getShowAmount() {
        return AjaxResult.success("操作成功!", redisService.getCacheObject(CacheConstants.TOP_30_ACTIVITY + ETop30Type.AMOUNT.getKey()));
    }

    @PostMapping("/topPeople")
    public AjaxResult topPeople(@RequestBody DirectStatisticsTop30QueryParam param) {
        param.setFaker(false);
        return AjaxResult.success(memberStatisticsService.getDirectStatisticsNumberOfPeople(param));
    }

    @PostMapping("/topAmount")
    public AjaxResult topAmount(@RequestBody DirectStatisticsTop30QueryParam param) {
        param.setFaker(false);
        return AjaxResult.success(memberStatisticsService.getDirectStatisticsNumberOfAmount(param));
    }


}
