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.CrmCustomerProperty;
import com.fs.crm.service.ICrmCustomerPropertyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/crm/customerProperty")
public class CrmCustomerPropertyController extends BaseController {

    @Autowired
    private ICrmCustomerPropertyService crmCustomerPropertyService;

    @PreAuthorize("@ss.hasPermi('crm:customerProperty:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCustomerProperty crmCustomerProperty) {
        startPage();
        List<CrmCustomerProperty> list = crmCustomerPropertyService.selectCrmCustomerPropertyList(crmCustomerProperty);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('crm:customerProperty:export')")
    @Log(title = "客户属性标签", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmCustomerProperty crmCustomerProperty) {
        List<CrmCustomerProperty> list = crmCustomerPropertyService.selectCrmCustomerPropertyList(crmCustomerProperty);
        ExcelUtil<CrmCustomerProperty> util = new ExcelUtil<CrmCustomerProperty>(CrmCustomerProperty.class);
        return util.exportExcel(list, "客户属性标签数据");
    }

    @PreAuthorize("@ss.hasPermi('crm:customerProperty:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(crmCustomerPropertyService.selectCrmCustomerPropertyById(id));
    }

    @PreAuthorize("@ss.hasPermi('crm:customerProperty:add')")
    @Log(title = "客户属性标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmCustomerProperty crmCustomerProperty) {
        return toAjax(crmCustomerPropertyService.insertCrmCustomerProperty(crmCustomerProperty));
    }

    @PreAuthorize("@ss.hasPermi('crm:customerProperty:edit')")
    @Log(title = "客户属性标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCustomerProperty crmCustomerProperty) {
        return toAjax(crmCustomerPropertyService.updateCrmCustomerProperty(crmCustomerProperty));
    }

    @PreAuthorize("@ss.hasPermi('crm:customerProperty:remove')")
    @Log(title = "客户属性标签", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(crmCustomerPropertyService.deleteCrmCustomerPropertyByIds(ids));
    }
}
