package com.hzs.report.order.controller.manage;

import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.core.utils.poi.ExcelUtil;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.report.order.param.OrderCountryAchieveParam;
import com.hzs.report.order.service.IOrderReportService;
import com.hzs.report.order.vo.OrderCountryAchieveVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * @Description: 订单报表控制器
 * @Author: jiang chao
 * @Time: 2024/11/20 17:24
 * @Classname: SaOrderController
 * @PackageName: com.hzs.report.order.controller
 */
@RestController
@RequestMapping("/manager/activation")
public class OrderReportController extends BaseController {

    @Autowired
    private IOrderReportService iOrderReportService;

    /**
     * 查询业绩国家来源
     *
     * @param param 查询入参
     * @return
     */
    @GetMapping("/country-achieve")
    public TableDataInfo countryAchieve(@Valid OrderCountryAchieveParam param) {
        if (null != param.getStartDate()) {
            param.setStartDate(DateUtils.getStartTime(param.getStartDate()));
        }
        if (null != param.getEndDate()) {
            param.setEndDate(DateUtils.getEndTime(param.getEndDate()));
        }

        startPage();
        return getDataTable(iOrderReportService.listCountryAchieve(param));
    }

    /**
     * 查询业绩国家来源
     *
     * @param param 查询入参
     * @return
     */
    @PostMapping("/country-achieve-export")
    public void countryAchieveExport(@Valid OrderCountryAchieveParam param, HttpServletResponse response) {
        if (null != param.getStartDate()) {
            param.setStartDate(DateUtils.getStartTime(param.getStartDate()));
        }
        if (null != param.getEndDate()) {
            param.setEndDate(DateUtils.getEndTime(param.getEndDate()));
        }

        List<OrderCountryAchieveVO> resultList = iOrderReportService.listCountryAchieve(param);

        ExcelUtil<OrderCountryAchieveVO> util = new ExcelUtil<>(OrderCountryAchieveVO.class);
        util.exportExcel(response, resultList, "业绩国家来源");
    }


}
