package com.fs.crm.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.crm.domain.CrmEvent;
import com.fs.crm.service.ICrmEventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 代办事项Controller
 *
 * @author fs
 * @date 2022-12-21
 */
@RestController
@RequestMapping("/crm/event")
public class CrmEventController extends BaseController
{
    @Autowired
    private ICrmEventService crmEventService;

    /**
     * 查询代办事项列表
     */
    @PreAuthorize("@ss.hasPermi('crm:event:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmEvent crmEvent)
    {
        startPage();
        List<CrmEvent> list = crmEventService.selectCrmEventList(crmEvent);
        return getDataTable(list);
    }

    /**
     * 导出代办事项列表
     */
    @PreAuthorize("@ss.hasPermi('crm:event:export')")
    @Log(title = "代办事项", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmEvent crmEvent)
    {
        List<CrmEvent> list = crmEventService.selectCrmEventList(crmEvent);
        ExcelUtil<CrmEvent> util = new ExcelUtil<CrmEvent>(CrmEvent.class);
        return util.exportExcel(list, "event");
    }

    /**
     * 获取代办事项详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:event:query')")
    @GetMapping(value = "/{eventId}")
    public AjaxResult getInfo(@PathVariable("eventId") Long eventId)
    {
        return AjaxResult.success(crmEventService.selectCrmEventById(eventId));
    }

    /**
     * 新增代办事项
     */
    @PreAuthorize("@ss.hasPermi('crm:event:add')")
    @Log(title = "代办事项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmEvent crmEvent)
    {
        return toAjax(crmEventService.insertCrmEvent(crmEvent));
    }

    /**
     * 修改代办事项
     */
    @PreAuthorize("@ss.hasPermi('crm:event:edit')")
    @Log(title = "代办事项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmEvent crmEvent)
    {
        return toAjax(crmEventService.updateCrmEvent(crmEvent));
    }

    /**
     * 删除代办事项
     */
    @PreAuthorize("@ss.hasPermi('crm:event:remove')")
    @Log(title = "代办事项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{eventIds}")
    public AjaxResult remove(@PathVariable Long[] eventIds)
    {
        return toAjax(crmEventService.deleteCrmEventByIds(eventIds));
    }
}
