ny
昨天 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package jnpf.base.controller;
 
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jnpf.base.ActionResult;
import jnpf.base.entity.AiChatEntity;
import jnpf.base.model.ai.AiChatVo;
import jnpf.base.model.ai.AiForm;
import jnpf.base.model.ai.AiHisVo;
import jnpf.base.model.ai.AiParam;
import jnpf.base.service.AiChatService;
import jnpf.constant.MsgCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
@Tag(name = "AI助手", description = "Aichat")
@RestController
@RequestMapping("/Aichat")
public class AiChatController {
    @Autowired
    private AiChatService aiChatService;
 
    //ai助手接口
    @Operation(summary = "发送对话")
    @Parameters({
            @Parameter(name = "param", description = "对话内容参数"),
    })
    @PostMapping("/send")
    public ActionResult send(@RequestBody AiParam param) {
        String content = aiChatService.send(param.getKeyword());
        return ActionResult.success(MsgCode.SU000.get(), content);
    }
 
    @Operation(summary = "ai会话列表")
    @GetMapping("/history/list")
    public ActionResult historyList() {
        List<AiChatVo> listVo = aiChatService.historyList();
        return ActionResult.success(listVo);
    }
 
    @Operation(summary = "ai会话记录")
    @Parameters({
            @Parameter(name = "id", description = "会话id"),
    })
    @GetMapping("/history/get/{id}")
    public ActionResult historyGet(@PathVariable("id") String id) {
        List<AiHisVo> listVo = aiChatService.historyGet(id);
        return ActionResult.success(listVo);
    }
 
    @Operation(summary = "保存历史记录")
    @Parameters({
            @Parameter(name = "form", description = "会话信息表单"),
    })
    @PostMapping("/history/save")
    public ActionResult historySave(@RequestBody AiForm form) {
        String chatId = aiChatService.historySave(form);
        return ActionResult.success(MsgCode.SU002.get(), chatId);
    }
 
    @Operation(summary = "删除ai会话")
    @Parameters({
            @Parameter(name = "form", description = "删除ai会话"),
    })
    @DeleteMapping("/history/delete/{id}")
    public ActionResult historyDelete(@PathVariable("id") String id) {
        AiChatEntity byId = aiChatService.getById(id);
        if (byId != null) {
            aiChatService.delete(id);
            return ActionResult.success(MsgCode.SU003.get());
        }
        return ActionResult.fail(MsgCode.FA003.get());
    }
}