1. 初始化代码
parent
f662e3b1db
commit
159d00a852
@ -0,0 +1,40 @@
|
||||
package com.supervision.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.supervision.model.KgInfo;
|
||||
import com.supervision.qanything.dto.ChatResult;
|
||||
import com.supervision.service.KGService;
|
||||
import com.supervision.vo.kg.ChatReqVo;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/kg")
|
||||
@RequiredArgsConstructor
|
||||
public class KGController {
|
||||
|
||||
private final KGService kgService;
|
||||
@ApiOperation("问答对话")
|
||||
@PostMapping("/chat")
|
||||
public ChatResult chat(@RequestBody ChatReqVo chatReqVo) {
|
||||
|
||||
return kgService.chat(chatReqVo.getQuestion());
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("问答对话")
|
||||
@PostMapping("/hotKG")
|
||||
public IPage<KgInfo> hotKG() {
|
||||
|
||||
return kgService.hotKG(new Page<>(1,10));
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.supervision.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.supervision.model.KgInfo;
|
||||
import com.supervision.qanything.dto.ChatResult;
|
||||
|
||||
public interface KGService {
|
||||
ChatResult chat(String question);
|
||||
|
||||
IPage<KgInfo> hotKG(Page<KgInfo> page);
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.supervision.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.supervision.model.KgInfo;
|
||||
import com.supervision.qanything.QanythingService;
|
||||
import com.supervision.qanything.dto.ChatResult;
|
||||
import com.supervision.qanything.dto.ResultWrapper;
|
||||
import com.supervision.service.KGService;
|
||||
import com.supervision.service.KgInfoService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class KGServiceImpl implements KGService {
|
||||
|
||||
@Value("${youdao.qanthing.kbId}")
|
||||
private String kbId;
|
||||
|
||||
private final QanythingService qanythingService;
|
||||
|
||||
private final KgInfoService kgInfoService;
|
||||
|
||||
|
||||
@Override
|
||||
public ChatResult chat(String question) {
|
||||
Assert.notEmpty(question, "问题不能为空");
|
||||
|
||||
try {
|
||||
ResultWrapper<ChatResult> chat = qanythingService.chat(question, CollUtil.newArrayList(kbId));
|
||||
if (chat.isSuccess()){
|
||||
return chat.getResult();
|
||||
}
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<KgInfo> hotKG(Page<KgInfo> page) {
|
||||
|
||||
return kgInfoService.lambdaQuery().eq(KgInfo::getHotFlag,1).page(page);
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.supervision.vo.kg;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ChatReqVo {
|
||||
|
||||
private String question;
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.supervision.mapper;
|
||||
|
||||
import com.supervision.model.KgGuide;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【kg_guide(知识办事指南)】的数据库操作Mapper
|
||||
* @createDate 2024-04-15 17:40:13
|
||||
* @Entity com.supervision.model.KgGuide
|
||||
*/
|
||||
public interface KgGuideMapper extends BaseMapper<KgGuide> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.supervision.mapper;
|
||||
|
||||
import com.supervision.model.KgInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【kg_info(知识内容信息)】的数据库操作Mapper
|
||||
* @createDate 2024-04-15 17:40:13
|
||||
* @Entity com.supervision.model.KgInfo
|
||||
*/
|
||||
public interface KgInfoMapper extends BaseMapper<KgInfo> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,62 @@
|
||||
package com.supervision.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 知识办事指南
|
||||
* @TableName kg_guide
|
||||
*/
|
||||
@TableName(value ="kg_guide")
|
||||
@Data
|
||||
public class KgGuide implements Serializable {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 知识id
|
||||
*/
|
||||
private String kgId;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String titile;
|
||||
|
||||
/**
|
||||
* url地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
private String createUserId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
private String updateUserId;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.supervision.service;
|
||||
|
||||
import com.supervision.model.KgGuide;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【kg_guide(知识办事指南)】的数据库操作Service
|
||||
* @createDate 2024-04-15 17:40:13
|
||||
*/
|
||||
public interface KgGuideService extends IService<KgGuide> {
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.supervision.service;
|
||||
|
||||
import com.supervision.model.KgInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【kg_info(知识内容信息)】的数据库操作Service
|
||||
* @createDate 2024-04-15 17:40:13
|
||||
*/
|
||||
public interface KgInfoService extends IService<KgInfo> {
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.supervision.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.supervision.model.KgGuide;
|
||||
import com.supervision.service.KgGuideService;
|
||||
import com.supervision.mapper.KgGuideMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【kg_guide(知识办事指南)】的数据库操作Service实现
|
||||
* @createDate 2024-04-15 17:40:13
|
||||
*/
|
||||
@Service
|
||||
public class KgGuideServiceImpl extends ServiceImpl<KgGuideMapper, KgGuide>
|
||||
implements KgGuideService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.supervision.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.supervision.model.KgInfo;
|
||||
import com.supervision.service.KgInfoService;
|
||||
import com.supervision.mapper.KgInfoMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【kg_info(知识内容信息)】的数据库操作Service实现
|
||||
* @createDate 2024-04-15 17:40:13
|
||||
*/
|
||||
@Service
|
||||
public class KgInfoServiceImpl extends ServiceImpl<KgInfoMapper, KgInfo>
|
||||
implements KgInfoService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.supervision.mapper.KgGuideMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.supervision.model.KgGuide">
|
||||
<result property="id" column="id" jdbcType="VARCHAR"/>
|
||||
<result property="kgId" column="kg_id" jdbcType="VARCHAR"/>
|
||||
<result property="titile" column="titile" jdbcType="VARCHAR"/>
|
||||
<result property="url" column="url" jdbcType="VARCHAR"/>
|
||||
<result property="createUserId" column="create_user_id" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateUserId" column="update_user_id" jdbcType="VARCHAR"/>
|
||||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,kg_id,titile,
|
||||
url,create_user_id,create_time,
|
||||
update_user_id,update_time
|
||||
</sql>
|
||||
</mapper>
|
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.supervision.mapper.KgInfoMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.supervision.model.KgInfo">
|
||||
<result property="id" column="id" jdbcType="VARCHAR"/>
|
||||
<result property="title" column="title" jdbcType="VARCHAR"/>
|
||||
<result property="classify" column="classify" jdbcType="INTEGER"/>
|
||||
<result property="hotFlag" column="hot_flag" jdbcType="INTEGER"/>
|
||||
<result property="contentType" column="content_type" jdbcType="INTEGER"/>
|
||||
<result property="preUrl" column="pre_url" jdbcType="VARCHAR"/>
|
||||
<result property="content" column="content" jdbcType="VARCHAR"/>
|
||||
<result property="policyItem" column="policy_item" jdbcType="VARCHAR"/>
|
||||
<result property="createUserId" column="create_user_id" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateUserId" column="update_user_id" jdbcType="VARCHAR"/>
|
||||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,title,classify,
|
||||
content_type,hot_flag,pre_url,content,
|
||||
policy_item,create_user_id,create_time,
|
||||
update_user_id,update_time
|
||||
</sql>
|
||||
</mapper>
|
Loading…
Reference in New Issue