package com.ruoyi.web.controller.ss;

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

import com.ruoyi.common.core.domain.ValidGroup;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.ss.customerService.domain.CustomerService;
import com.ruoyi.ss.customerService.domain.CustomerServiceVO;
import com.ruoyi.ss.customerService.domain.CustomerServiceQuery;
import com.ruoyi.ss.customerService.service.CustomerServiceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客服Controller
 *
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/ss/customerService")
public class CustomerServiceController extends BaseController
{
    @Autowired
    private CustomerServiceService customerServiceService;

    /**
     * 查询客服列表
     */
    @PreAuthorize("@ss.hasPermi('ss:customerService:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerServiceQuery query)
    {
        startPage();
        startOrderBy();
        List<CustomerServiceVO> list = customerServiceService.selectCustomerServiceList(query);
        return getDataTable(list);
    }

    /**
     * 导出客服列表
     */
    @PreAuthorize("@ss.hasPermi('ss:customerService:export')")
    @Log(title = "客服", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerServiceQuery query)
    {
        List<CustomerServiceVO> list = customerServiceService.selectCustomerServiceList(query);
        ExcelUtil<CustomerServiceVO> util = new ExcelUtil<CustomerServiceVO>(CustomerServiceVO.class);
        util.exportExcel(response, list, "客服数据");
    }

    /**
     * 获取客服详细信息
     */
    @PreAuthorize("@ss.hasPermi('ss:customerService:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(customerServiceService.selectCustomerServiceById(id));
    }

    /**
     * 新增客服
     */
    @PreAuthorize("@ss.hasPermi('ss:customerService:add')")
    @Log(title = "客服", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) CustomerService customerService)
    {
        return toAjax(customerServiceService.insertCustomerService(customerService));
    }

    /**
     * 修改客服
     */
    @PreAuthorize("@ss.hasPermi('ss:customerService:edit')")
    @Log(title = "客服", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class) CustomerService customerService)
    {
        return toAjax(customerServiceService.updateCustomerService(customerService));
    }

    /**
     * 删除客服
     */
    @PreAuthorize("@ss.hasPermi('ss:customerService:remove')")
    @Log(title = "客服", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(customerServiceService.deleteCustomerServiceByIds(ids));
    }
}
