资料管理界面新增查询编辑功能添加了确定所属知识库的功能,按钮管理界面的增删改查及界面按钮开关实时操作开启和关闭功能
正在显示
9 个修改的文件
包含
331 行增加
和
11 行删除
| 1 | +package org.jeecg.modules.airag.app.controller; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
| 4 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
| 5 | +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||
| 6 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 8 | +import lombok.extern.slf4j.Slf4j; | ||
| 9 | +import org.apache.shiro.authz.annotation.RequiresPermissions; | ||
| 10 | +import org.jeecg.common.api.vo.Result; | ||
| 11 | +import org.jeecg.common.aspect.annotation.AutoLog; | ||
| 12 | +import org.jeecg.common.system.base.controller.JeecgController; | ||
| 13 | +import org.jeecg.common.system.query.QueryGenerator; | ||
| 14 | +import org.jeecg.modules.airag.app.entity.AiragButton; | ||
| 15 | +import org.jeecg.modules.airag.app.service.IAiragButtonService; | ||
| 16 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 17 | +import org.springframework.web.bind.annotation.*; | ||
| 18 | +import org.springframework.web.servlet.ModelAndView; | ||
| 19 | + | ||
| 20 | +import javax.servlet.http.HttpServletRequest; | ||
| 21 | +import javax.servlet.http.HttpServletResponse; | ||
| 22 | +import java.util.Arrays; | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | +* @Description: 按钮表单 | ||
| 26 | +* @Author: jeecg-boot | ||
| 27 | +* @Date: 2025-06-05 | ||
| 28 | +* @Version: V1.0 | ||
| 29 | +*/ | ||
| 30 | +@Tag(name="按钮表单") | ||
| 31 | +@RestController | ||
| 32 | +@RequestMapping("/airagbutton/airagButton") | ||
| 33 | +@Slf4j | ||
| 34 | +public class AiragButtonController extends JeecgController<AiragButton, IAiragButtonService> { | ||
| 35 | + @Autowired | ||
| 36 | + private IAiragButtonService airagButtonService; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 分页列表查询 | ||
| 40 | + * | ||
| 41 | + * @param airagButton | ||
| 42 | + * @param pageNo | ||
| 43 | + * @param pageSize | ||
| 44 | + * @param req | ||
| 45 | + * @return | ||
| 46 | + */ | ||
| 47 | + //@AutoLog(value = "按钮表单-分页列表查询") | ||
| 48 | + @Operation(summary="按钮表单-分页列表查询") | ||
| 49 | + @GetMapping(value = "/list") | ||
| 50 | + public Result<IPage<AiragButton>> queryPageList(AiragButton airagButton, | ||
| 51 | + @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, | ||
| 52 | + @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, | ||
| 53 | + HttpServletRequest req) { | ||
| 54 | + QueryWrapper<AiragButton> queryWrapper = QueryGenerator.initQueryWrapper(airagButton, req.getParameterMap()); | ||
| 55 | + Page<AiragButton> page = new Page<AiragButton>(pageNo, pageSize); | ||
| 56 | + IPage<AiragButton> pageList = airagButtonService.page(page, queryWrapper); | ||
| 57 | +// pageList.setRecords(airagButtonService. findAll(airagButton)); | ||
| 58 | + return Result.OK(pageList); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * 添加 | ||
| 63 | + * | ||
| 64 | + * @param airagButton | ||
| 65 | + * @return | ||
| 66 | + */ | ||
| 67 | + @AutoLog(value = "按钮表单-添加") | ||
| 68 | + @Operation(summary="按钮表单-添加") | ||
| 69 | + @RequiresPermissions("airagbutton:airag_button:add") | ||
| 70 | + @PostMapping(value = "/add") | ||
| 71 | + public Result<String> add(@RequestBody AiragButton airagButton) { | ||
| 72 | + // 检查按钮开关是否为开启状态 | ||
| 73 | + if ("Y".equals(airagButton.getButtonSwitch())) { | ||
| 74 | + // 查询当前已开启的按钮数量 | ||
| 75 | + QueryWrapper<AiragButton> queryWrapper = new QueryWrapper<>(); | ||
| 76 | + queryWrapper.eq("button_switch", "Y"); | ||
| 77 | + long openedButtonCount = airagButtonService.count(queryWrapper); | ||
| 78 | + | ||
| 79 | + // 如果已开启的按钮数量超过或等于5个,则返回错误提示 | ||
| 80 | + if (openedButtonCount >= 5) { | ||
| 81 | + return Result.error("按钮超过五个,请先关闭一个按钮"); | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + airagButtonService.save(airagButton); | ||
| 85 | + return Result.OK("添加成功!"); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + /** | ||
| 89 | + * 编辑 | ||
| 90 | + * | ||
| 91 | + * @param airagButton | ||
| 92 | + * @return | ||
| 93 | + */ | ||
| 94 | + @AutoLog(value = "按钮表单-编辑") | ||
| 95 | + @Operation(summary="按钮表单-编辑") | ||
| 96 | + @RequiresPermissions("airagbutton:airag_button:edit") | ||
| 97 | + @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) | ||
| 98 | + public Result<String> edit(@RequestBody AiragButton airagButton) { | ||
| 99 | + // 检查按钮开关是否为开启状态 | ||
| 100 | + if ("Y".equals(airagButton.getButtonSwitch())) { | ||
| 101 | + // 查询当前已开启的按钮数量(排除自身) | ||
| 102 | + QueryWrapper<AiragButton> queryWrapper = new QueryWrapper<>(); | ||
| 103 | + queryWrapper.eq("button_switch", "Y") | ||
| 104 | + .ne("id", airagButton.getId()); // 排除当前正在编辑的按钮 | ||
| 105 | + long openedButtonCount = airagButtonService.count(queryWrapper); | ||
| 106 | + | ||
| 107 | + // 如果已开启的按钮数量超过或等于5个,则返回错误提示 | ||
| 108 | + if (openedButtonCount >= 5) { | ||
| 109 | + return Result.error("按钮超过五个,请先关闭一个按钮"); | ||
| 110 | + } | ||
| 111 | + } | ||
| 112 | + airagButtonService.updateById(airagButton); | ||
| 113 | + return Result.OK("编辑成功!"); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + /** | ||
| 117 | + * 通过id删除 | ||
| 118 | + * | ||
| 119 | + * @param id | ||
| 120 | + * @return | ||
| 121 | + */ | ||
| 122 | + @AutoLog(value = "按钮表单-通过id删除") | ||
| 123 | + @Operation(summary="按钮表单-通过id删除") | ||
| 124 | + @RequiresPermissions("airagbutton:airag_button:delete") | ||
| 125 | + @DeleteMapping(value = "/delete") | ||
| 126 | + public Result<String> delete(@RequestParam(name="id",required=true) String id) { | ||
| 127 | + airagButtonService.removeById(id); | ||
| 128 | + return Result.OK("删除成功!"); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * 批量删除 | ||
| 133 | + * | ||
| 134 | + * @param ids | ||
| 135 | + * @return | ||
| 136 | + */ | ||
| 137 | + @AutoLog(value = "按钮表单-批量删除") | ||
| 138 | + @Operation(summary="按钮表单-批量删除") | ||
| 139 | + @RequiresPermissions("airagbutton:airag_button:deleteBatch") | ||
| 140 | + @DeleteMapping(value = "/deleteBatch") | ||
| 141 | + public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) { | ||
| 142 | + this.airagButtonService.removeByIds(Arrays.asList(ids.split(","))); | ||
| 143 | + return Result.OK("批量删除成功!"); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + /** | ||
| 147 | + * 通过id查询 | ||
| 148 | + * | ||
| 149 | + * @param id | ||
| 150 | + * @return | ||
| 151 | + */ | ||
| 152 | + //@AutoLog(value = "按钮表单-通过id查询") | ||
| 153 | + @Operation(summary="按钮表单-通过id查询") | ||
| 154 | + @GetMapping(value = "/queryById") | ||
| 155 | + public Result<AiragButton> queryById(@RequestParam(name="id",required=true) String id) { | ||
| 156 | + AiragButton airagButton = airagButtonService.getById(id); | ||
| 157 | + if(airagButton==null) { | ||
| 158 | + return Result.error("未找到对应数据"); | ||
| 159 | + } | ||
| 160 | + return Result.OK(airagButton); | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + /** | ||
| 164 | + * 导出excel | ||
| 165 | + * | ||
| 166 | + * @param request | ||
| 167 | + * @param airagButton | ||
| 168 | + */ | ||
| 169 | + @RequiresPermissions("airagbutton:airag_button:exportXls") | ||
| 170 | + @RequestMapping(value = "/exportXls") | ||
| 171 | + public ModelAndView exportXls(HttpServletRequest request, AiragButton airagButton) { | ||
| 172 | + return super.exportXls(request, airagButton, AiragButton.class, "按钮表单"); | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + /** | ||
| 176 | + * 通过excel导入数据 | ||
| 177 | + * | ||
| 178 | + * @param request | ||
| 179 | + * @param response | ||
| 180 | + * @return | ||
| 181 | + */ | ||
| 182 | + @RequiresPermissions("airagbutton:airag_button:importExcel") | ||
| 183 | + @RequestMapping(value = "/importExcel", method = RequestMethod.POST) | ||
| 184 | + public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { | ||
| 185 | + return super.importExcel(request, response, AiragButton.class); | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | +} |
| 1 | +package org.jeecg.modules.airag.app.entity; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.annotation.IdType; | ||
| 4 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 6 | +import com.fasterxml.jackson.annotation.JsonFormat; | ||
| 7 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 8 | +import lombok.Data; | ||
| 9 | +import lombok.EqualsAndHashCode; | ||
| 10 | +import lombok.experimental.Accessors; | ||
| 11 | +import org.jeecgframework.poi.excel.annotation.Excel; | ||
| 12 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 13 | + | ||
| 14 | +import java.io.Serializable; | ||
| 15 | +import java.io.UnsupportedEncodingException; | ||
| 16 | +import java.util.Date; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * @Description: 按钮表单 | ||
| 20 | + * @Author: jeecg-boot | ||
| 21 | + * @Date: 2025-06-05 | ||
| 22 | + * @Version: V1.0 | ||
| 23 | + */ | ||
| 24 | +@Data | ||
| 25 | +@TableName("airag_button") | ||
| 26 | +@Accessors(chain = true) | ||
| 27 | +@EqualsAndHashCode(callSuper = false) | ||
| 28 | +@Schema(description="按钮表单") | ||
| 29 | +public class AiragButton implements Serializable { | ||
| 30 | + private static final long serialVersionUID = 1L; | ||
| 31 | + | ||
| 32 | + /**主键*/ | ||
| 33 | + @TableId(type = IdType.ASSIGN_ID) | ||
| 34 | + @Schema(description = "主键") | ||
| 35 | + private String id; | ||
| 36 | + /**创建人*/ | ||
| 37 | + @Schema(description = "创建人") | ||
| 38 | + private String createBy; | ||
| 39 | + /**创建日期*/ | ||
| 40 | + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") | ||
| 41 | + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") | ||
| 42 | + @Schema(description = "创建日期") | ||
| 43 | + private Date createTime; | ||
| 44 | + /**更新人*/ | ||
| 45 | + @Schema(description = "更新人") | ||
| 46 | + private String updateBy; | ||
| 47 | + /**更新日期*/ | ||
| 48 | + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") | ||
| 49 | + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") | ||
| 50 | + @Schema(description = "更新日期") | ||
| 51 | + private Date updateTime; | ||
| 52 | + /**所属部门*/ | ||
| 53 | + @Schema(description = "所属部门") | ||
| 54 | + private String sysOrgCode; | ||
| 55 | + /**按钮名称*/ | ||
| 56 | + @Excel(name = "按钮名称", width = 15) | ||
| 57 | + @Schema(description = "按钮名称") | ||
| 58 | + private String buttonName; | ||
| 59 | + | ||
| 60 | + | ||
| 61 | + private String buttonSwitch; | ||
| 62 | + | ||
| 63 | + /**按钮值*/ | ||
| 64 | + @Excel(name = "按钮值", width = 15) | ||
| 65 | + @Schema(description = "按钮值") | ||
| 66 | + private String buttonValues; | ||
| 67 | +} |
| 1 | +package org.jeecg.modules.airag.app.mapper; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
| 4 | +import io.lettuce.core.dynamic.annotation.Param; | ||
| 5 | +import org.jeecg.modules.airag.app.entity.AiragButton; | ||
| 6 | + | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * @Description: 按钮表单 | ||
| 11 | + * @Author: jeecg-boot | ||
| 12 | + * @Date: 2025-06-05 | ||
| 13 | + * @Version: V1.0 | ||
| 14 | + */ | ||
| 15 | +public interface AiragButtonMapper extends BaseMapper<AiragButton> { | ||
| 16 | +} |
| @@ -32,15 +32,19 @@ public class PgVectorMapper { | @@ -32,15 +32,19 @@ public class PgVectorMapper { | ||
| 32 | // 查询所有向量记录 | 32 | // 查询所有向量记录 |
| 33 | public List<Embeddings> findAll(Embeddings embeddings) { | 33 | public List<Embeddings> findAll(Embeddings embeddings) { |
| 34 | List<Embeddings> results = new ArrayList<>(); | 34 | List<Embeddings> results = new ArrayList<>(); |
| 35 | - String sql = "SELECT * FROM embeddings"; | 35 | + String sql = "SELECT * FROM embeddings WHERE 1 =1 "; |
| 36 | if (StringUtils.isNotBlank(embeddings.getId())){ | 36 | if (StringUtils.isNotBlank(embeddings.getId())){ |
| 37 | - sql += " WHERE embedding_id = '" + embeddings.getId() + "'"; | 37 | + sql += " and embedding_id = '" + embeddings.getId() + "'"; |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | - if(StringUtils.isNotBlank(embeddings.getText())){ | ||
| 41 | - sql += " where text = '" + embeddings.getText() + "'"; | 40 | + if (StringUtils.isNotBlank(embeddings.getKnowledgeId())){ |
| 41 | + sql += " and metadata ->> 'knowledgeId' = '" + embeddings.getKnowledgeId() + "'"; | ||
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | + if(StringUtils.isNotBlank(embeddings.getText())){ | ||
| 45 | + sql += " and text = '" + embeddings.getText() + "'"; | ||
| 46 | + } | ||
| 47 | + System.out.println("sql = " + sql); | ||
| 44 | try (Connection conn = getConnection(); | 48 | try (Connection conn = getConnection(); |
| 45 | PreparedStatement stmt = conn.prepareStatement(sql); | 49 | PreparedStatement stmt = conn.prepareStatement(sql); |
| 46 | ResultSet rs = stmt.executeQuery()) { | 50 | ResultSet rs = stmt.executeQuery()) { |
| @@ -111,18 +115,15 @@ public class PgVectorMapper { | @@ -111,18 +115,15 @@ public class PgVectorMapper { | ||
| 111 | 115 | ||
| 112 | // 更新向量记录 | 116 | // 更新向量记录 |
| 113 | public int update(Embeddings record) { | 117 | public int update(Embeddings record) { |
| 114 | - String sql = "UPDATE embeddings SET embedding = ?, metadata = ?, text = ?::jsonb WHERE embedding_id = ?"; | 118 | + String sql = "UPDATE embeddings SET embedding = ?, metadata = ?::jsonb, text = ? WHERE embedding_id = ?"; |
| 115 | 119 | ||
| 116 | try (Connection conn = getConnection(); | 120 | try (Connection conn = getConnection(); |
| 117 | PreparedStatement stmt = conn.prepareStatement(sql)) { | 121 | PreparedStatement stmt = conn.prepareStatement(sql)) { |
| 118 | 122 | ||
| 119 | JSONObject mataData = new JSONObject(); | 123 | JSONObject mataData = new JSONObject(); |
| 120 | - SnowflakeGenerator snowflakeGenerator = new SnowflakeGenerator(); | ||
| 121 | - String knowledgeId = String.valueOf(snowflakeGenerator.next()); | ||
| 122 | - mataData.put("knowledgeId", knowledgeId); // 使用前端传入的知识库ID | 124 | + mataData.put("knowledgeId", record.getKnowledgeId()); // 使用前端传入的知识库ID |
| 123 | mataData.put("docName", record.getDocName()); | 125 | mataData.put("docName", record.getDocName()); |
| 124 | - String docId = String.valueOf(snowflakeGenerator.next()); | ||
| 125 | - mataData.put("docId", docId); // 自动生成唯一文档ID | 126 | + mataData.put("docId", record.getDocId()); // 自动生成唯一文档ID |
| 126 | mataData.put("index", "0"); | 127 | mataData.put("index", "0"); |
| 127 | 128 | ||
| 128 | PGobject jsonObject = new PGobject(); | 129 | PGobject jsonObject = new PGobject(); |
| @@ -2,4 +2,6 @@ | @@ -2,4 +2,6 @@ | ||
| 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| 3 | <mapper namespace="org.jeecg.modules.airag.app.mapper.AiragAppMapper"> | 3 | <mapper namespace="org.jeecg.modules.airag.app.mapper.AiragAppMapper"> |
| 4 | 4 | ||
| 5 | + | ||
| 6 | + | ||
| 5 | </mapper> | 7 | </mapper> |
| 1 | +package org.jeecg.modules.airag.app.service; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.extension.service.IService; | ||
| 4 | +import org.jeecg.modules.airag.app.entity.AiragButton; | ||
| 5 | +import org.jeecg.modules.airag.app.entity.Embeddings; | ||
| 6 | + | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * @Description: 按钮表单 | ||
| 11 | + * @Author: jeecg-boot | ||
| 12 | + * @Date: 2025-06-05 | ||
| 13 | + * @Version: V1.0 | ||
| 14 | + */ | ||
| 15 | +public interface IAiragButtonService extends IService<AiragButton> { | ||
| 16 | + | ||
| 17 | +} |
| 1 | +package org.jeecg.modules.airag.app.service.impl; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||
| 4 | +import org.jeecg.modules.airag.app.entity.AiragButton; | ||
| 5 | +import org.jeecg.modules.airag.app.entity.Embeddings; | ||
| 6 | +import org.jeecg.modules.airag.app.mapper.AiragButtonMapper; | ||
| 7 | +import org.jeecg.modules.airag.app.mapper.PgVectorMapper; | ||
| 8 | +import org.jeecg.modules.airag.app.service.IAiragButtonService; | ||
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 10 | +import org.springframework.stereotype.Service; | ||
| 11 | + | ||
| 12 | +import java.util.List; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * @Description: 按钮表单 | ||
| 16 | + * @Author: jeecg-boot | ||
| 17 | + * @Date: 2025-06-05 | ||
| 18 | + * @Version: V1.0 | ||
| 19 | + */ | ||
| 20 | +@Service | ||
| 21 | +public class AiragButtonServiceImpl extends ServiceImpl<AiragButtonMapper, AiragButton> implements IAiragButtonService { | ||
| 22 | + | ||
| 23 | + | ||
| 24 | +} |
-
请 注册 或 登录 后发表评论