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


import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.util.ExcelUtil;
import com.tmerclub.cloud.flow.dto.FlowAnalysisDTO;
import com.tmerclub.cloud.flow.service.UserVisitAnalysisService;
import com.tmerclub.cloud.flow.vo.FlowUserAnalysisVO;
import com.tmerclub.cloud.flow.vo.UserAnalysisDataExcelVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
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.RestController;

import java.util.List;

/**
 * 流量分析—用户访问数据
 *
 * @author YXF
 * @date 2021-05-21 15:25:19
 */
@RestController("platformUserVisitAnalysisController")
@RequestMapping("/p/userVisitAnalysis")
@Tag(name = "platform-用户访问统计")
public class UserVisitAnalysisController {

    @Autowired
    private UserVisitAnalysisService userVisitAnalysisService;

    @GetMapping("/getUserAnalysisData")
    @Operation(summary = "获取访客分析数据", description = "获取访客分析数据")
    public ServerResponseEntity<FlowUserAnalysisVO> getUserAnalysisData(FlowAnalysisDTO flowAnalysisDTO) {
        FlowUserAnalysisVO flowUserAnalysisVO = userVisitAnalysisService.getUserAnalysisData(flowAnalysisDTO);
        return ServerResponseEntity.success(flowUserAnalysisVO);
    }

    @GetMapping("/userAnalysisDataExport")
    @Operation(summary = "导出excel", description = "导出会员分析数据-地图")
    public ServerResponseEntity<Void> userAnalysisDataExport(HttpServletResponse response, FlowAnalysisDTO flowAnalysisDTO) {
        List<UserAnalysisDataExcelVO> list = userVisitAnalysisService.listUserAnalysisDataExcel(flowAnalysisDTO);
        ExcelUtil.soleExcel(response, list, UserAnalysisDataExcelVO.EXCEL_NAME, UserAnalysisDataExcelVO.MERGE_ROW_INDEX, UserAnalysisDataExcelVO.MERGE_COLUMN_INDEX, UserAnalysisDataExcelVO.class);
        return ServerResponseEntity.success();
    }

}
