package com.ruoyi.web.controller.tool;

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

import com.ruoyi.system.domain.crm.TCustomer;
import com.ruoyi.system.service.crm.ITCustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * crmController
 * 
 * @author ruoyi
 * @date 2023-11-28
 */
@Api(tags = "CRM系统接口")
@RestController
@RequestMapping("/system/customer")
public class TCustomerController extends BaseController
{
    @Autowired
    private ITCustomerService tCustomerService;

    /**
     * 查询crm列表
     */
    @ApiOperation(value = "获取客户列表")
    @PreAuthorize("@ss.hasPermi('system:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCustomer tCustomer)
    {
        startPage();
        List<TCustomer> list = tCustomerService.selectTCustomerList(tCustomer);
        return getDataTable(list);
    }

    /**
     * 导出crm列表
     */
    @ApiOperation(value = "导出客户列表")
    @PreAuthorize("@ss.hasPermi('system:customer:export')")
    @Log(title = "crm", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCustomer tCustomer)
    {
        List<TCustomer> list = tCustomerService.selectTCustomerList(tCustomer);
        ExcelUtil<TCustomer> util = new ExcelUtil<TCustomer>(TCustomer.class);
        util.exportExcel(response, list, "crm数据");
    }

    /**
     * 获取crm详细信息
     */
    @ApiOperation(value = "获取crm详细信息")
    @PreAuthorize("@ss.hasPermi('system:customer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tCustomerService.selectTCustomerById(id));
    }

    /**
     * 新增crm
     */
    @ApiOperation(value = "新增crm")
    @PreAuthorize("@ss.hasPermi('system:customer:add')")
    @Log(title = "crm", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCustomer tCustomer)
    {
        tCustomer.setCreateBy(getUsername());
        return toAjax(tCustomerService.insertTCustomer(tCustomer));
    }

    /**
     * 修改crm
     */
    @ApiOperation(value = "修改crm")
    @PreAuthorize("@ss.hasPermi('system:customer:edit')")
    @Log(title = "crm", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCustomer tCustomer)
    {
        return toAjax(tCustomerService.updateTCustomer(tCustomer));
    }

    /**
     * 删除crm
     */
    @ApiOperation(value = "删除crm")
    @PreAuthorize("@ss.hasPermi('system:customer:remove')")
    @Log(title = "crm", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tCustomerService.deleteTCustomerByIds(ids));
    }
}