package com.iformall.controller.market;

import com.iformall.annotation.SystemControllerLog;
import com.iformall.common.ResultData;
import com.iformall.controller.base.BaseController;
import com.iformall.domain.dto.MarkingCouponDataReportDto;
import com.iformall.service.MarkingDataReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by syf on 2018/8/29.
 */
@RestController
@RequestMapping("markingDataReport")
@Api(description = "营销报表接口")
public class MarkingDataReportController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MarkingDataReportService markingDataReportService;

    @ApiOperation("查询券数据")
    @GetMapping("/couponData")
    @SystemControllerLog(description = "券数据-查询券数据")
    public ResultData findCouponData() {
        logger.debug("[" + getIpAddr() + "] MarkingDataReportController::findCouponData");
        return new ResultData(markingDataReportService.getCouponData(getTenantId()));
    }

    @ApiOperation("查询券数据列表")
    @GetMapping("/couponDataList")
    @SystemControllerLog(description = "券数据-查询券数据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
    public ResultData findCouponDataList(@ModelAttribute MarkingCouponDataReportDto markingCouponDataReportDto, Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] MarkingDataReportController::findCouponDataList");
        return new ResultData(markingDataReportService.getCouponDataList(getTenantId(), markingCouponDataReportDto, pageNum, pageSize));
    }

    @ApiOperation("查询场景投放券数据")
    @GetMapping("/sceneData")
    @SystemControllerLog(description = "券数据-查询场景投放券数据")
    public ResultData findSceneData() {
        logger.debug("[" + getIpAddr() + "] MarkingDataReportController::findSceneData");
        return new ResultData(markingDataReportService.getSceneData(getTenantId()));
    }

    @ApiOperation("查询场景营销数据列表")
    @GetMapping("/sceneDataList")
    @SystemControllerLog(description = "券数据-查询场景营销数据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
    public ResultData findSceneDataList(@ModelAttribute MarkingCouponDataReportDto markingCouponDataReportDto, Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] MarkingDataReportController::findSceneDataList");
        return new ResultData(markingDataReportService.getSceneDataList(getTenantId(), markingCouponDataReportDto, pageNum, pageSize));
    }

    @ApiOperation("查询触达用户数数据")
    @GetMapping("/touchUsersData")
    @SystemControllerLog(description = "券数据-查询触达用户数数据")
    public ResultData touchUsersData() {
        logger.debug("[" + getIpAddr() + "] MarkingDataReportController::touchUsersData");
        return new ResultData(markingDataReportService.getTouchUsersReportData(getTenantId()));
    }

    @ApiOperation("查询触达用户数数据列表")
    @GetMapping("/touchUsersDataList")
    @SystemControllerLog(description = "券数据-查询触达用户数数据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
    public ResultData touchUsersDataList(@ModelAttribute MarkingCouponDataReportDto markingCouponDataReportDto, Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] MarkingDataReportController::touchUsersDataList");
        return new ResultData(markingDataReportService.getTouchUsersReportList(getTenantId(), markingCouponDataReportDto, pageNum, pageSize));
    }

    @ApiOperation("触达用户数数据导出")
    @GetMapping("/exportTouchUsersData")
    @SystemControllerLog(description = "券数据-触达用户数数据导出")
    public void exportTouchUsersData(@ModelAttribute MarkingCouponDataReportDto markingCouponDataReportDto, HttpServletRequest request, HttpServletResponse response) {
        markingCouponDataReportDto.setTenantId(getTenantId());
        markingDataReportService.exportTouchUsersData(request, response, markingCouponDataReportDto);
    }


}
