
package com.tmerclub.cloud.flow.controller.supplier;

import com.tmerclub.cloud.api.product.dto.ProdEffectDTO;
import com.tmerclub.cloud.api.product.vo.ProdEffectRespVO;
import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.i18n.I18nMessage;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.security.AuthUserContext;
import com.tmerclub.cloud.flow.service.ProductAnalyseService;
import com.tmerclub.cloud.flow.vo.ShopFlowInfoVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chiley
 * @date 2022/6/23 16:03
 */

@RestController("supplierProductAnalyseController")
@RequestMapping("/s/productAnalyse")
@Tag(name = "supplier-商品分析")
public class ProductAnalyseController {

    @Autowired
    private ProductAnalyseService productAnalyseService;

    @GetMapping("/getProductEffect")
    @Operation(summary = "获取商家端商品洞察数据", description = "获取商品洞察数据")
    public ServerResponseEntity<PageVO<ProdEffectRespVO>> getProductEffect(@Valid PageDTO pageDTO, ProdEffectDTO prodEffectDTO) {
        prodEffectDTO.setShopId(AuthUserContext.get().getTenantId());
        prodEffectDTO.setLang(I18nMessage.getLang());
        return ServerResponseEntity.success(productAnalyseService.getProductEffect(pageDTO, prodEffectDTO));
    }

    @GetMapping("/getShopProductFlowInfo")
    @Operation(summary = "获取供应商店铺流量信息和近30天的商品访问流量排行榜", description = "获取店铺商品浏览量、新老访客数量和近30天的商品访问流量排行榜")
    @Parameters({
            @Parameter(name = "dayCount", description = "天数（几天内的排行榜）"),
            @Parameter(name = "limit", description = "排行榜条数")})
    public ServerResponseEntity<ShopFlowInfoVO> getShopProductFlowInfo(@RequestParam(value = "dayCount", defaultValue = "30") Integer dayCount,
                                                                              @RequestParam(value = "limit", defaultValue = "5") Integer limit){
        return ServerResponseEntity.success(productAnalyseService.getSupplierFlowInfoAndProdRankIng(dayCount, limit));
    }
}
