package com.ruoyi.controller;

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.cs.domain.CsCustomerFollow;
import com.ruoyi.cs.domain.template.CsCustomerFollowTemplate;
import com.ruoyi.cs.service.ICsCustomerFollowService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 回访客户记录Controller
 *
 * @author ruoyi
 * @date 2024-05-07
 */
@RestController
@RequestMapping("/cs/csCustomerFollow")
public class CsCustomerFollowController extends BaseController
{
    @Resource
    private ICsCustomerFollowService csCustomerFollowService;

    /**
     * 查询回访客户记录列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csCustomerFollow:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsCustomerFollow csCustomerFollow)
    {
        startPage();
        csCustomerFollow.setDelFlag("0");
        List<CsCustomerFollow> list = csCustomerFollowService.selectCsCustomerFollowList(csCustomerFollow);
        return getDataTable(list);
    }

    /**
     * 导出回访客户记录列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csCustomerFollow:export')")
    @Log(title = "回访客户记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsCustomerFollow csCustomerFollow)
    {
        csCustomerFollow.setDelFlag("0");
        List<CsCustomerFollow> list = csCustomerFollowService.selectCsCustomerFollowList(csCustomerFollow);
        ExcelUtil<CsCustomerFollow> util = new ExcelUtil<CsCustomerFollow>(CsCustomerFollow.class);
        util.exportExcel(response, list, "回访客户记录数据");
    }

    /**
     * 导出回访客户记录列表模板
     */
    @Log(title = "回访客户记录模板", businessType = BusinessType.EXPORT)
    @PostMapping("/exportTemplate")
    public void exportTemplate(HttpServletResponse response)
    {
        ExcelUtil<CsCustomerFollowTemplate> util = new ExcelUtil<CsCustomerFollowTemplate>(CsCustomerFollowTemplate.class);
        util.exportExcel(response, null, "回访客户记录数据模板");
    }

    /**
     * 获取回访客户记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csCustomerFollow:query')")
    @GetMapping(value = "/{customerFollowId}")
    public AjaxResult getInfo(@PathVariable("customerFollowId") String customerFollowId)
    {
        return AjaxResult.success(csCustomerFollowService.selectCsCustomerFollowByCustomerFollowId(customerFollowId));
    }

    /**
     * 新增回访客户记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csCustomerFollow:add')")
    @Log(title = "回访客户记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsCustomerFollow csCustomerFollow)
    {
        return toAjax(csCustomerFollowService.insertCsCustomerFollow(csCustomerFollow));
    }

    /**
     * 修改回访客户记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csCustomerFollow:edit')")
    @Log(title = "回访客户记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsCustomerFollow csCustomerFollow)
    {
        return toAjax(csCustomerFollowService.updateCsCustomerFollow(csCustomerFollow));
    }

    /**
     * 删除回访客户记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csCustomerFollow:remove')")
    @Log(title = "回访客户记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerFollowIds}")
    public AjaxResult remove(@PathVariable String[] customerFollowIds)
    {
        return toAjax(csCustomerFollowService.deleteCsCustomerFollowByCustomerFollowIds(customerFollowIds));
    }

    /**
     * 导入回访客户记录
     */
    @Log(title = "导入回访客户记录", businessType = BusinessType.IMPORT)
    @PostMapping("/importCsCustomerFollow")
    public AjaxResult importCsCustomerFollow(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<CsCustomerFollowTemplate> util = new ExcelUtil<CsCustomerFollowTemplate>(CsCustomerFollowTemplate.class);
        List<CsCustomerFollowTemplate> list = util.importExcel(file.getInputStream());
        String message = csCustomerFollowService.importCsCustomerFollow(list, updateSupport);
        return AjaxResult.success(message);
    }
}
