package com.ruoyi.web.controller.wocom;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.excel.wecom.domain.CustomerExportData;
import com.ruoyi.excel.wecom.service.ICustomerExportDataService;
import com.ruoyi.excel.wecom.vo.CustomerExportDataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 客户统计数据Controller
 */
@RestController
@RequestMapping("/wecom/customerExport")
public class CustomerExportDataController extends BaseController {

    @Autowired
    private ICustomerExportDataService customerExportDataService;

    /**
     * 查询客户统计数据列表
     */
    @PreAuthorize("@ss.hasPermi('wecom:customerExport:list')")
    @GetMapping("/list")
    public TableDataInfo list(
            @RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
            @RequestParam(value = "customerName", required = false) String customerName) {
        startPage();
        List<CustomerExportData> list = customerExportDataService.selectCustomerExportDataList(startDate, endDate, customerName);
        return getDataTable(list);
    }

    /**
     * 导出客户统计数据列表
     */
    @PreAuthorize("@ss.hasPermi('wecom:customerExport:export')")
    @Log(title = "客户统计数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,
                       @RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
                       @RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
                       @RequestParam(value = "customerName", required = false) String customerName) {
        List<CustomerExportDataVO> list = customerExportDataService.selectCustomerExportDataVOList(startDate, endDate, customerName);
        ExcelUtil<CustomerExportDataVO> util = new ExcelUtil<>(CustomerExportDataVO.class);
        util.exportExcel(response, list, "客户统计数据");
    }


}
