package com.fs.chat.controller;

import java.util.List;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.chat.domain.ChatUser;
import com.fs.chat.service.IChatUserService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 客户Controller
 * 
 * @author fs
 * @date 2024-05-11
 */
@RestController
@RequestMapping("/chat/chatUser")
public class ChatUserController extends BaseController
{
    @Autowired
    private IChatUserService chatUserService;

    /**
     * 查询客户列表
     */
    @PreAuthorize("@ss.hasPermi('chat:chatUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChatUser chatUser)
    {
        startPage();
        List<ChatUser> list = chatUserService.selectChatUserList(chatUser);
        return getDataTable(list);
    }

    /**
     * 导出客户列表
     */
    @PreAuthorize("@ss.hasPermi('chat:chatUser:export')")
    @Log(title = "客户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ChatUser chatUser)
    {
        List<ChatUser> list = chatUserService.selectChatUserList(chatUser);
        ExcelUtil<ChatUser> util = new ExcelUtil<ChatUser>(ChatUser.class);
        return util.exportExcel(list, "客户数据");
    }

    /**
     * 获取客户详细信息
     */
    @PreAuthorize("@ss.hasPermi('chat:chatUser:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(chatUserService.selectChatUserByUserId(userId));
    }

    /**
     * 新增客户
     */
    @PreAuthorize("@ss.hasPermi('chat:chatUser:add')")
    @Log(title = "客户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChatUser chatUser)
    {
        return toAjax(chatUserService.insertChatUser(chatUser));
    }

    /**
     * 修改客户
     */
    @PreAuthorize("@ss.hasPermi('chat:chatUser:edit')")
    @Log(title = "客户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChatUser chatUser)
    {
        return toAjax(chatUserService.updateChatUser(chatUser));
    }

    /**
     * 删除客户
     */
    @PreAuthorize("@ss.hasPermi('chat:chatUser:remove')")
    @Log(title = "客户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(chatUserService.deleteChatUserByUserIds(userIds));
    }
}
