package com.ruoyi.web.controller.wocom;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
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.CustomerContactData;
import com.ruoyi.excel.wecom.service.ICustomerContactDataService;
import com.ruoyi.excel.wecom.vo.CustomerContactDataVO;
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/customerContact")
public class CustomerContactDataController extends BaseController {

    @Autowired
    private ICustomerContactDataService customerContactDataService;

    /**
     * 查询客户联系统计数据列表
     */
    @PreAuthorize("@ss.hasPermi('wecom:customerContact: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 = "userid", required = false) String userid) {
        startPage();
        List<CustomerContactData> list = customerContactDataService.selectCustomerContactDataList(startDate, endDate, userid);
        return getDataTable(list);
    }

    /**
     * 导出客户联系统计数据列表
     */
    @PreAuthorize("@ss.hasPermi('wecom:customerContact: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 = "userid", required = false) String userid) {
        List<CustomerContactDataVO> list = customerContactDataService.selectCustomerContactDataVOList(startDate, endDate, userid);
        ExcelUtil<CustomerContactDataVO> util = new ExcelUtil<>(CustomerContactDataVO.class);
        util.exportExcel(response, list, "客户联系统计数据");
    }

    /**
     * 获取客户联系统计数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('wecom:customerContact:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(customerContactDataService.selectCustomerContactDataById(id));
    }

    /**
     * 新增客户联系统计数据
     */
    @PreAuthorize("@ss.hasPermi('wecom:customerContact:add')")
    @Log(title = "客户联系统计数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerContactData customerContactData) {
        return toAjax(customerContactDataService.insertCustomerContactData(customerContactData));
    }

    /**
     * 修改客户联系统计数据
     */
    @PreAuthorize("@ss.hasPermi('wecom:customerContact:edit')")
    @Log(title = "客户联系统计数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerContactData customerContactData) {
        return toAjax(customerContactDataService.updateCustomerContactData(customerContactData));
    }

    /**
     * 删除客户联系统计数据
     */
    @PreAuthorize("@ss.hasPermi('wecom:customerContact:remove')")
    @Log(title = "客户联系统计数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(customerContactDataService.deleteCustomerContactDataByIds(ids));
    }
}
