package com.fs.his.controller;

import java.util.List;

import com.fs.aiChat.domain.DoctorAiChatMsg;
import com.fs.aiChat.domain.DoctorAiChatSession;
import com.fs.aiChat.vo.DoctorAiVO;
import com.fs.common.core.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.his.service.IHisDoctorAiChatMsgService;
import com.fs.his.service.IHisDoctorAiChatSessionService;
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.common.utils.poi.ExcelUtil;

import javax.annotation.Resource;

/**
 * 对话关系Controller
 *
 * @author fs
 * @date 2024-12-30
 */
@RestController
@RequestMapping("doctorChat/session")
public class HisDoctorAiChatSessionController extends BaseController
{
    @Resource
    private IHisDoctorAiChatSessionService doctorAiChatSessionService;

    @Resource
    private IHisDoctorAiChatMsgService chatMsgService;

    /**
     * 查询会话列表
     */
    @PreAuthorize("@ss.hasPermi('chat:chatSession:list')")
    @GetMapping("/list")
    public TableDataInfo list(DoctorAiChatSession param)
    {
        startPage();
        List<DoctorAiChatSession> doctorAiChatSessions = doctorAiChatSessionService.selectDoctorAiChatSessionList(param);
        return getDataTable(doctorAiChatSessions);
    }
    /**
     * 获取会话详细信息
     */
    @PreAuthorize("@ss.hasPermi('chat:chatSession:query')")
    @GetMapping(value = "/{sessionId}")
    public R getInfo(@PathVariable("sessionId") Long sessionId)
    {
        DoctorAiChatSession doctorAiChatSession = doctorAiChatSessionService.selectChatSessionCVOBySessionId(sessionId);
        DoctorAiVO doctorAiVO = new DoctorAiVO();
        doctorAiVO.setDoctorId(doctorAiChatSession.getDoctorId());
        List<DoctorAiChatMsg> list = doctorAiChatSessionService.selectDoctorAiChatSessionListByUser(doctorAiVO);
        return R.ok().put("data",doctorAiChatSession).put("list",list);
    }
    /**
     * 导出对话关系列表
     */
    @Log(title = "对话关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DoctorAiChatSession doctorAiChatSession)
    {
        List<DoctorAiChatSession> list = doctorAiChatSessionService.selectDoctorAiChatSessionList(doctorAiChatSession);
        ExcelUtil<DoctorAiChatSession> util = new ExcelUtil<DoctorAiChatSession>(DoctorAiChatSession.class);
        return util.exportExcel(list, "对话关系数据");
    }


    /**
     * 新增对话关系
     */
    @Log(title = "对话关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DoctorAiChatSession doctorAiChatSession)
    {
        return toAjax(doctorAiChatSessionService.insertDoctorAiChatSession(doctorAiChatSession));
    }

    /**
     * 修改对话关系
     */
    @Log(title = "对话关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DoctorAiChatSession doctorAiChatSession)
    {
        return toAjax(doctorAiChatSessionService.updateDoctorAiChatSession(doctorAiChatSession));
    }

    /**
     * 删除对话关系
     */
    @PreAuthorize("@ss.hasPermi('shop:session:remove')")
    @Log(title = "对话关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sessionIds}")
    public AjaxResult remove(@PathVariable Long[] sessionIds)
    {
        return toAjax(doctorAiChatSessionService.deleteDoctorAiChatSessionBySessionIds(sessionIds));
    }
}
