package shop.alien.store.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.vo.LifeGroupBuyCountDateVo;
import shop.alien.entity.store.vo.LifeGroupBuyCountVo;
import shop.alien.store.service.LifeGroupBuyCountService;

import java.util.List;

/**
 * 团购统计
 */
@Api(tags = {"团购统计"})
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/groupBuyCount")
@RequiredArgsConstructor
public class LifeGroupBuyCountController {

    private final LifeGroupBuyCountService lifeGroupBuyCountService;

    @ApiOperation("插入团购统计")
    @PostMapping("/insertGroupBuyCount")
    public R insertGroupBuyCount(@RequestParam(value = "storeId") Integer storeId,@RequestParam(value = "groupId") Integer groupId,@RequestParam(value = "userId") Integer userId,@RequestParam(value = "countType") String countType) {
        log.info("LifeGroupBuyCountController.insertGroupBuyCount?storeId={},groupId={},userId={},countType={}", storeId,groupId,userId,countType);
        try {
            lifeGroupBuyCountService.insertGroupBuyCount(storeId, groupId, userId, countType);
            return R.success("成功");
        }catch (Exception e){
            log.error("LifeGroupBuyCountController.insertGroupBuyCount?storeId={},groupId={},userId={},countType={}", storeId,groupId,userId,countType,e);
            return R.fail("失败");
        }
    }

    @ApiOperation("团购统计-经营数据")
    @ApiImplicitParams({@ApiImplicitParam(name = "storeId", value = "门店id", dataType = "String", paramType = "query", required = true)})
    @GetMapping("/getJysj")
    private R getJysj(@RequestParam(value = "storeId") String storeId) {
        log.info("LifeGroupBuyCountController.getJysj?storeId={}", storeId);
        return R.data(lifeGroupBuyCountService.getJysj(storeId));
    }

    @ApiOperation("团购统计-商品核心指标趋势")
    @ApiImplicitParams({@ApiImplicitParam(name = "storeId", value = "门店id", dataType = "String", paramType = "query", required = true)})
    @GetMapping("/getSphxzb")
    private R<List<LifeGroupBuyCountDateVo>> getSphxzb(@RequestParam(value = "storeId") String storeId) {
        log.info("LifeGroupBuyCountController.getSphxzb?storeId={}", storeId);
        return R.data(lifeGroupBuyCountService.getSphxzb(storeId));
    }

    @ApiOperation("团购统计-单品指标排名")
    @ApiImplicitParams({@ApiImplicitParam(name = "storeId", value = "门店id", dataType = "String", paramType = "query", required = true)})
    @GetMapping("/getDpzbpm")
    private R<List<LifeGroupBuyCountDateVo>> getDpzbpm(@RequestParam(value = "storeId") String storeId) {
        log.info("LifeGroupBuyCountController.getDpzbpm?storeId={}", storeId);
        return R.data(lifeGroupBuyCountService.getDpzbpm(storeId));
    }

    /*@ApiOperation("团购统计-测试")
    @GetMapping("/test")
    private R test() {
        lifeGroupBuyCountService.test();
        return R.success("成功");
    }*/
}
