提交 ae7a425a 作者: 925993793@qq.com

自定义专题智能体接口补充改造

上级 d8c1a3f8
package com.zzsn.event.external.controller;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzsn.event.constant.Result;
import com.zzsn.event.entity.Subject;
import com.zzsn.event.external.entity.ExternalSubjectInfoSourceMap;
import com.zzsn.event.external.service.ExternalSubjectInfoSourceMapService;
import com.zzsn.event.external.vo.SubjectInfoVO;
import com.zzsn.event.external.vo.SubjectVO;
import com.zzsn.event.service.CommonService;
import com.zzsn.event.service.SubjectSimpleService;
import com.zzsn.event.util.HttpUtil;
import com.zzsn.event.util.LLMUtil;
import com.zzsn.event.vo.FileDataVO;
import com.zzsn.event.vo.SubjectDetailVO;
import com.zzsn.event.vo.SubjectSimpleVO;
import com.zzsn.event.xxljob.service.IXxlJobInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
/**
* @author lkg
* @date 2025/8/12
*/
@RestController
@RequestMapping("/external")
public class ExternalController {
@Autowired
private SubjectSimpleService subjectSimpleService;
@Autowired
private IXxlJobInfoService xxlJobInfoService;
@Autowired
private ExternalSubjectInfoSourceMapService externalSubjectInfoSourceMapService;
@Autowired
private CommonService commonService;
/**
* 创建专题
*
* @param subjectVO 参数
* @author lkg
* @date 2025/1/9
*/
@PostMapping("/createSubject")
public Result<?> createSubject(@RequestBody SubjectVO subjectVO) {
subjectVO.setDataScope("1");
SubjectSimpleVO subjectSimpleVO = new SubjectSimpleVO();
BeanUtils.copyProperties(subjectVO, subjectSimpleVO);
Subject subject = subjectSimpleService.createSubject(subjectSimpleVO);
String subjectId = subject.getId();
CompletableFuture.runAsync(() -> {
//插入xxlJob
xxlJobInfoService.subjectInsert(subject);
});
return Result.OK();
}
/**
* 编辑专题
*
* @param subjectVO 参数
* @author lkg
* @date 2025/1/9
*/
@PostMapping("/updateSubject")
public Result<?> updateSubject(@RequestBody SubjectVO subjectVO) {
String subjectId = subjectVO.getId();
subjectVO.setDataScope("1");
SubjectSimpleVO subjectSimpleVO = new SubjectSimpleVO();
BeanUtils.copyProperties(subjectVO, subjectSimpleVO);
subjectSimpleService.editSubject(subjectSimpleVO);
return Result.OK();
}
/**
* 采集词推荐
*
* @param remark 专题描述
* @author lkg
* @date 2025/8/12
*/
@GetMapping("/crawlerWordRecommend")
public Result<?> crawlerWordRecommend(@RequestParam String remark) {
return Result.OK(LLMUtil.crawlerWord(remark));
}
/**
* 绑定信息源分页列表
*
* @param subjectId 专题id
* @param pageNo 页码
* @param pageSize 每页返回条数
* @author lkg
* @date 2025/8/12
*/
@GetMapping("/bindSourcePageList")
public Result<?> bindSourceList(@RequestParam String subjectId,
@RequestParam(defaultValue = "1") Integer pageNo,
@RequestParam(defaultValue = "10") Integer pageSize) {
Page<ExternalSubjectInfoSourceMap> page = new Page<>(pageNo, pageSize);
LambdaQueryWrapper<ExternalSubjectInfoSourceMap> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(ExternalSubjectInfoSourceMap::getSubjectId, subjectId)
.eq(ExternalSubjectInfoSourceMap::getType, 1);
Page<ExternalSubjectInfoSourceMap> list = externalSubjectInfoSourceMapService.page(page, queryWrapper);
return Result.OK(list);
}
/**
* 下载导入信息源
*
* @author lkg
* @date 2024/06/21
*/
@GetMapping("/downloadInfoSourceTemplate")
public void downloadResearchTemplate(HttpServletResponse response) {
String filePath = "subjectDataImport/导入信息源模板.xlsx";
commonService.downloadTemplate(response, filePath);
}
/**
* 批量导入绑定得信息源
*
* @author lkg
* @date 2025/8/12
*/
@PostMapping("/importInfoSource")
public Result<?> importInfoSource(HttpServletRequest request) {
String subjectId = request.getParameter("subjectId");
if (StringUtils.isBlank(subjectId)) {
return Result.FAIL(500, "专题id不能为空");
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
if (fileMap.size() < 1) {
return Result.FAIL(500, "请上传excel文件");
}
MultipartFile multipartFile = fileMap.get(new ArrayList<>(fileMap.keySet()).get(0));
int index = multipartFile.getOriginalFilename().lastIndexOf(".");
String fileSuffix = multipartFile.getOriginalFilename().substring(index + 1);
if ("xls".equals(fileSuffix) || "xlsx".equals(fileSuffix)) {
try {
ExcelReader reader = ExcelUtil.getReader(multipartFile.getInputStream());
Map<String, String> header = new HashMap<>();
header.put("信息源名称", "infoSourceName");
header.put("信息源地址", "infoSourceUrl");
reader.setHeaderAlias(header);
List<ExternalSubjectInfoSourceMap> infoSourceList = reader.read(0, 1, ExternalSubjectInfoSourceMap.class);
infoSourceList.forEach(infoSource -> infoSource.setSubjectId(subjectId));
externalSubjectInfoSourceMapService.saveBatch(infoSourceList);
} catch (IOException e) {
e.printStackTrace();
}
} else {
return Result.FAIL(500, "不支持的文件类型");
}
return Result.OK();
}
/**
* 绑定信息源
*
* @param externalSubjectInfoSourceMap 参数
* @author lkg
* @date 2025/8/12
*/
@PostMapping("/bindSource")
public Result<?> bindSource(@RequestBody ExternalSubjectInfoSourceMap externalSubjectInfoSourceMap) {
externalSubjectInfoSourceMap.setType(1);
externalSubjectInfoSourceMapService.save(externalSubjectInfoSourceMap);
return Result.OK();
}
/**
* 解绑信息源
*
* @param ids id集合
* @author lkg
* @date 2025/8/12
*/
@GetMapping("/unBindSource")
public Result<?> bindSource(@RequestParam List<String> ids) {
externalSubjectInfoSourceMapService.removeByIds(ids);
return Result.OK();
}
/**
* 专题详情
*
* @param subjectId 专题id
* @author lkg
* @date 2025/1/9
*/
@GetMapping("/queryInfo")
public Result<?> queryInfo(@RequestParam String subjectId) {
SubjectInfoVO subjectInfoVO = new SubjectInfoVO();
SubjectDetailVO subjectDetailVO = subjectSimpleService.queryInfo(subjectId);
BeanUtils.copyProperties(subjectDetailVO, subjectInfoVO);
LambdaQueryWrapper<ExternalSubjectInfoSourceMap> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(ExternalSubjectInfoSourceMap::getSubjectId, subjectId)
.eq(ExternalSubjectInfoSourceMap::getType, 1);
subjectInfoVO.setInfoSourceList(externalSubjectInfoSourceMapService.list(queryWrapper));
return Result.OK(subjectInfoVO);
}
/**
* 配置信息推送给采集
*
* @param subjectId 专题id
* @author lkg
* @date 2025/8/12
*/
@GetMapping("/pushToCaiji")
public Result<?> pushToCaiji(@RequestParam String subjectId) {
SubjectInfoVO subjectInfoVO = new SubjectInfoVO();
SubjectDetailVO subjectDetailVO = subjectSimpleService.queryInfo(subjectId);
BeanUtils.copyProperties(subjectDetailVO, subjectInfoVO);
LambdaQueryWrapper<ExternalSubjectInfoSourceMap> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(ExternalSubjectInfoSourceMap::getSubjectId, subjectId)
.eq(ExternalSubjectInfoSourceMap::getType, 1);
subjectInfoVO.setInfoSourceList(externalSubjectInfoSourceMapService.list(queryWrapper));
try {
HttpUtil.doPost("http://192.168.1.135:9000/put_keyword", JSONObject.from(subjectInfoVO), 30000);
} catch (IOException e) {
e.printStackTrace();
}
return Result.OK();
}
}
package com.zzsn.event.external.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
@Data
@TableName("external_subject_info_source_map")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class ExternalSubjectInfoSourceMap implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**
* 信息源地址
*/
private String subjectId;
/**
* 信息源id
*/
private String infoSourceUrl;
/**
* 信息源名称
*/
private String infoSourceName;
/**
* 专题描述
*/
private String description;
/**
* 1-信息源;2-专题描述
*/
private Integer type;
/**
* 创建人
*/
private String createBy;
/**
* 创建日期
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**
* 更新人
*/
private String updateBy;
/**
* 更新日期
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}
package com.zzsn.event.external.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.event.external.entity.ExternalSubjectInfoSourceMap;
import org.apache.ibatis.annotations.Mapper;
/**
*
*
* @author lkg
* @date 2025/8/12
*/
@Mapper
public interface ExternalSubjectInfoSourceMapMapper extends BaseMapper<ExternalSubjectInfoSourceMap> {
}
package com.zzsn.event.external.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.event.external.entity.ExternalSubjectInfoSourceMap;
/**
*
*
* @author lkg
* @date 2025/8/12
*/
public interface ExternalSubjectInfoSourceMapService extends IService<ExternalSubjectInfoSourceMap> {
}
package com.zzsn.event.external.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.event.external.entity.ExternalSubjectInfoSourceMap;
import com.zzsn.event.external.mapper.ExternalSubjectInfoSourceMapMapper;
import com.zzsn.event.external.service.ExternalSubjectInfoSourceMapService;
import org.springframework.stereotype.Service;
/**
*
*
* @author lkg
* @date 2025/8/12
*/
@Service
public class ExternalSubjectInfoSourceMapServiceImpl extends ServiceImpl<ExternalSubjectInfoSourceMapMapper, ExternalSubjectInfoSourceMap>
implements ExternalSubjectInfoSourceMapService {
}
package com.zzsn.event.external.vo;
import com.zzsn.event.external.entity.ExternalSubjectInfoSourceMap;
import com.zzsn.event.vo.SubjectDetailVO;
import lombok.Data;
import java.util.List;
/**
* 专题详情信息(包含样例文章)
*
* @author lkg
* @date 2025/1/8
*/
@Data
public class SubjectInfoVO extends SubjectDetailVO {
List<ExternalSubjectInfoSourceMap> infoSourceList;
}
package com.zzsn.event.external.vo;
import com.zzsn.event.external.entity.ExternalSubjectInfoSourceMap;
import com.zzsn.event.vo.SubjectSimpleVO;
import lombok.Data;
import java.util.List;
/**
* 简化流程后的入参对象-研究中心
*
* @author lkg
* @date 2025/1/9
*/
@Data
public class SubjectVO extends SubjectSimpleVO {
List<ExternalSubjectInfoSourceMap> infoSourceList;
}
...@@ -21,7 +21,8 @@ public class LLMUtil { ...@@ -21,7 +21,8 @@ public class LLMUtil {
final static String ChatGlm4_URL = "https://open.bigmodel.cn/api/paas/v4/chat/completions"; final static String ChatGlm4_URL = "https://open.bigmodel.cn/api/paas/v4/chat/completions";
final static String API_KEY = "2eb40c7bb8e4d22b389cd9ada5a8d6cc.bAbE6g6y71TeC0on"; //final static String API_KEY = "2eb40c7bb8e4d22b389cd9ada5a8d6cc.bAbE6g6y71TeC0on";
final static String API_KEY = "c5a53bd5f95a4e37a8997deb5d0c6031.orXyRRPNvZiqRaxF";
/** /**
* LLM-推荐关键词 * LLM-推荐关键词
...@@ -63,8 +64,58 @@ public class LLMUtil { ...@@ -63,8 +64,58 @@ public class LLMUtil {
return list; return list;
} }
public static String crawlerWord(String remark) {
String result = null;
String prompt = "你是一个专业信息采集助手,根据用户提供的专题描述,精准提取核心实体和主题,生成符合以下规则的关键词表达式:\n" +
"1. 用 `+` 表示 **与** 关系(必须同时出现)\n" +
"2. 用 `|` 表示 **或** 关系(任一出现即可)\n" +
"3. +两端的关键词组用 `()` 框选\n" +
"4. 关键词必须直接来自描述或合理扩展的同义/关联词\n" +
"5. 输出仅含表达式,无额外解释\n" +
"6.+号使用不超过2个\n" +
"7.不要把时间提取进表达式\n" +
"\n" +
"\n" +
"### 示例\n" +
"专题描述:\"星动纪元、云深处科技分别完成近5亿元融资,用于人形机器人研发与量产\" \n" +
"输出:`(星动纪元|云深处科技)+(融资|量产)`";
JSONObject params = new JSONObject();
List<JSONObject> messages = new ArrayList<>();
JSONObject systemMap = new JSONObject();
systemMap.put("role", "system");
systemMap.put("content", prompt);
messages.add(systemMap);
JSONObject message = new JSONObject();
message.put("content", remark);
message.put("role", "user");
messages.add(message);
params.put("messages", messages);
params.put("model", "glm-4-plus");
JSONObject responseFormat = new JSONObject();
responseFormat.put("type", "json_object");
params.put("response_format", responseFormat);
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("Authorization", "Bearer " + API_KEY);
String response = null;
try {
response = HttpUtil.doPostWithHeader(ChatGlm4_URL, params, 30000, headers);
JSONObject jsonObject = JSON.parseObject(response);
JSONArray choices = jsonObject.getJSONArray("choices");
JSONObject choice = choices.getJSONObject(0);
result = choice.getJSONObject("message").getString("content");
} catch (Exception e) {
log.info("大模型-{},调用异常:{}","glm-4-plus",e.getMessage());
log.info("返回结果:{}",response);
}
return result;
}
public static void main(String[] args) { public static void main(String[] args) {
List<String> list = wordRecommend("人工智能|汽车"); //List<String> list = wordRecommend("人工智能|汽车");
System.out.println(JSON.toJSONString(list)); //System.out.println(JSON.toJSONString(list));
String s = crawlerWord("2025年7月23日,东北大学6名学生在内蒙古中国黄金集团内蒙古矿业有限公司乌努格吐山铜钼矿选矿厂参观学习过程中不幸遇难。事故原因初步查明为浮选槽上方格栅板脱落。涉事公司已停产整顿,企业负责人及相关人员配合调查。内蒙古自治区政府成立调查组提级调查,事件善后工作正在进行中。");
System.out.println(s);
} }
} }
package com.zzsn.event.vo; package com.zzsn.event.vo;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.zzsn.event.entity.arrange.ClbModelArrange; import com.zzsn.event.entity.arrange.ClbModelArrange;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
...@@ -118,6 +120,9 @@ public class SubjectPage { ...@@ -118,6 +120,9 @@ public class SubjectPage {
private String sysOrgCode; private String sysOrgCode;
/**专题类型(1-普通专题;3-嵌套专题)*/ /**专题类型(1-普通专题;3-嵌套专题)*/
private Integer subjectType; private Integer subjectType;
/**数据范围(是否是全库) - 采集库全库-1,企业库全库-2,政策库全库-3*/
@TableField(updateStrategy = FieldStrategy.IGNORED) // 忽略更新策略
private String dataScope;
/**信息源数量*/ /**信息源数量*/
private Integer infoSourceNum; private Integer infoSourceNum;
......
...@@ -40,4 +40,6 @@ public class SubjectSimpleVO { ...@@ -40,4 +40,6 @@ public class SubjectSimpleVO {
private String environment; private String environment;
public String subjectTypeName; public String subjectTypeName;
/**数据范围(是否是全库) - 采集库全库-1,企业库全库-2,政策库全库-3*/
private String dataScope;
} }
...@@ -177,3 +177,5 @@ infoSource: ...@@ -177,3 +177,5 @@ infoSource:
waitInfoRemove: http://1.95.79.85:8823/baseSourceInfo/api/infoSource/waitInfoRemove waitInfoRemove: http://1.95.79.85:8823/baseSourceInfo/api/infoSource/waitInfoRemove
columnListByWait: http://1.95.79.85:8823/baseSourceInfo/api/infoSource/columnListByWait columnListByWait: http://1.95.79.85:8823/baseSourceInfo/api/infoSource/columnListByWait
columnDetail: http://1.95.79.85:8823/baseSourceInfo/api/infoSource/columnDetail columnDetail: http://1.95.79.85:8823/baseSourceInfo/api/infoSource/columnDetail
ai-article:
thematicColumnConfig-url: http://1.95.77.159:10089/reportManage/thematicInformationColumn/column/getThematicColumnConfig
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论