package com.fs.company.controller.crm;

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.domain.R;
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.CrmCustomerPropertyTemplate;
import com.fs.crm.service.ICrmCustomerPropertyTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "客户属性标签模板管理")
@RestController
@RequestMapping("/crm/customerPropertyTemplate")
public class CrmCustomerPropertyTemplateController extends BaseController {

    @Autowired
    private ICrmCustomerPropertyTemplateService crmCustomerPropertyTemplateService;

    @ApiOperation("查询客户属性标签模板列表")
    @PreAuthorize("@ss.hasPermi('crm:customer:query')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCustomerPropertyTemplate crmCustomerPropertyTemplate) {
        startPage();
        List<CrmCustomerPropertyTemplate> list = crmCustomerPropertyTemplateService.selectCrmCustomerPropertyTemplateList(crmCustomerPropertyTemplate);
        return getDataTable(list);
    }

    @ApiOperation("查询客户属性标签模板详情")
    @PreAuthorize("@ss.hasPermi('crm:customer:query')")
    @GetMapping("/{id}")
    public R getInfo(@PathVariable("id") Long id) {
        CrmCustomerPropertyTemplate template = crmCustomerPropertyTemplateService.selectCrmCustomerPropertyTemplateById(id);
        return R.ok().put("data", template);
    }

    @ApiOperation("添加客户属性标签模板")
    @PreAuthorize("@ss.hasPermi('crm:customer:edit')")
    @Log(title = "客户属性标签模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmCustomerPropertyTemplate crmCustomerPropertyTemplate) {
        return toAjax(crmCustomerPropertyTemplateService.insertCrmCustomerPropertyTemplate(crmCustomerPropertyTemplate));
    }

    @ApiOperation("修改客户属性标签模板")
    @PreAuthorize("@ss.hasPermi('crm:customer:edit')")
    @Log(title = "客户属性标签模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCustomerPropertyTemplate crmCustomerPropertyTemplate) {
        return toAjax(crmCustomerPropertyTemplateService.updateCrmCustomerPropertyTemplate(crmCustomerPropertyTemplate));
    }

    @ApiOperation("删除客户属性标签模板")
    @PreAuthorize("@ss.hasPermi('crm:customer:edit')")
    @Log(title = "客户属性标签模板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(crmCustomerPropertyTemplateService.deleteCrmCustomerPropertyTemplateByIds(ids));
    }

    @ApiOperation("导出客户属性标签模板")
    @PreAuthorize("@ss.hasPermi('crm:customer:export')")
    @Log(title = "客户属性标签模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmCustomerPropertyTemplate crmCustomerPropertyTemplate) {
        List<CrmCustomerPropertyTemplate> list = crmCustomerPropertyTemplateService.selectCrmCustomerPropertyTemplateList(crmCustomerPropertyTemplate);
        ExcelUtil<CrmCustomerPropertyTemplate> util = new ExcelUtil<CrmCustomerPropertyTemplate>(CrmCustomerPropertyTemplate.class);
        return util.exportExcel(list, "客户属性标签模板数据");
    }
}
