mirror of
https://github.com/ccmjga/zhilu-admin
synced 2026-03-14 05:33:42 +08:00
add ai delete
This commit is contained in:
@@ -5,6 +5,8 @@ import com.zl.mjga.dto.PageResponseDto;
|
||||
import com.zl.mjga.dto.ai.LlmQueryDto;
|
||||
import com.zl.mjga.dto.ai.LlmVm;
|
||||
import com.zl.mjga.exception.BusinessException;
|
||||
import com.zl.mjga.repository.DepartmentRepository;
|
||||
import com.zl.mjga.repository.UserRepository;
|
||||
import com.zl.mjga.service.AiChatService;
|
||||
import com.zl.mjga.service.EmbeddingService;
|
||||
import com.zl.mjga.service.LlmService;
|
||||
@@ -16,8 +18,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jooq.generated.mjga.enums.LlmCodeEnum;
|
||||
import org.jooq.generated.mjga.tables.pojos.AiLlmConfig;
|
||||
import org.jooq.generated.mjga.tables.pojos.Department;
|
||||
import org.jooq.generated.mjga.tables.pojos.User;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -34,6 +39,8 @@ public class AiController {
|
||||
private final AiChatService aiChatService;
|
||||
private final LlmService llmService;
|
||||
private final EmbeddingService embeddingService;
|
||||
private final UserRepository userRepository;
|
||||
private final DepartmentRepository departmentRepository;
|
||||
|
||||
@PostMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
public Flux<String> chat(Principal principal, @RequestBody String userMessage) {
|
||||
@@ -72,4 +79,27 @@ public class AiController {
|
||||
}
|
||||
return embeddingService.searchAction(message);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority(T(com.zl.mjga.model.urp.EPermission).WRITE_USER_ROLE_PERMISSION)")
|
||||
@DeleteMapping("/action/user")
|
||||
void deleteUser(@RequestParam String username, Principal principal) {
|
||||
if (StringUtils.equals(username, principal.getName())) {
|
||||
throw new BusinessException("不能删除当前登录用户");
|
||||
}
|
||||
User fetched = userRepository.fetchOneByUsername(username);
|
||||
if (fetched == null) {
|
||||
throw new BusinessException("该用户不存在");
|
||||
}
|
||||
userRepository.deleteByUsername(username);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority(T(com.zl.mjga.model.urp.EPermission).WRITE_USER_ROLE_PERMISSION)")
|
||||
@DeleteMapping("/action/department")
|
||||
void deleteDepartment(@RequestParam String name) {
|
||||
Department department = departmentRepository.fetchOneByName(name);
|
||||
if (department == null) {
|
||||
throw new BusinessException("该部门不存在");
|
||||
}
|
||||
departmentRepository.deleteByName(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class IdentityAccessController {
|
||||
return identityAccessService.queryUniqueUserWithRolePermission(userId);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority(T(com.zl.mjga.model.urp.EPermission).DELETE_USER_ROLE_PERMISSION)")
|
||||
@PreAuthorize("hasAuthority(T(com.zl.mjga.model.urp.EPermission).WRITE_USER_ROLE_PERMISSION)")
|
||||
@DeleteMapping("/user")
|
||||
void deleteUser(@RequestParam Long userId) {
|
||||
if (userId == 1) {
|
||||
|
||||
@@ -7,7 +7,9 @@ import lombok.Getter;
|
||||
@Getter
|
||||
public enum Actions {
|
||||
CREATE_USER("CREATE_USER", "创建用户"),
|
||||
CREATE_DEPARTMENT("CREATE_DEPARTMENT", "创建部门");
|
||||
CREATE_DEPARTMENT("CREATE_DEPARTMENT", "创建部门"),
|
||||
DELETE_USER("DELETE_USER", "删除用户"),
|
||||
DELETE_DEPARTMENT("DELETE_DEPARTMENT", "删除部门");
|
||||
public static final String INDEX_KEY = "action";
|
||||
private final String code;
|
||||
private final String content;
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.jooq.generated.mjga.tables.daos.DepartmentDao;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Repository
|
||||
public class DepartmentRepository extends DepartmentDao {
|
||||
@@ -95,4 +96,9 @@ public class DepartmentRepository extends DepartmentDao {
|
||||
.innerJoin(USER.department())
|
||||
.where(USER.ID.eq(userId));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteByName(String name) {
|
||||
ctx().deleteFrom(DEPARTMENT).where(DEPARTMENT.NAME.eq(name)).execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ public class LlmRepository extends AiLlmConfigDao {
|
||||
public Result<Record> pageFetchBy(PageRequestDto pageRequestDto, LlmQueryDto llmQueryDto) {
|
||||
return ctx()
|
||||
.select(
|
||||
AI_LLM_CONFIG.asterisk(),
|
||||
DSL.count().over().as("total_llm").convertFrom(Long::valueOf))
|
||||
AI_LLM_CONFIG.asterisk(), DSL.count().over().as("total_llm").convertFrom(Long::valueOf))
|
||||
.from(AI_LLM_CONFIG)
|
||||
.where(
|
||||
StringUtils.isNotEmpty(llmQueryDto.name())
|
||||
|
||||
@@ -35,7 +35,7 @@ public class EmbeddingService {
|
||||
EmbeddingSearchRequest embeddingSearchRequest =
|
||||
EmbeddingSearchRequest.builder()
|
||||
.queryEmbedding(zhipuEmbeddingModel.embed(message).content())
|
||||
.minScore(0.89)
|
||||
.minScore(0.89)
|
||||
.build();
|
||||
EmbeddingSearchResult<TextSegment> embeddingSearchResult =
|
||||
zhiPuEmbeddingStore.search(embeddingSearchRequest);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.zl.mjga.service;
|
||||
|
||||
import static org.jooq.generated.mjga.Tables.AI_LLM_CONFIG;
|
||||
|
||||
import com.zl.mjga.dto.PageRequestDto;
|
||||
import com.zl.mjga.dto.PageResponseDto;
|
||||
import com.zl.mjga.dto.ai.LlmQueryDto;
|
||||
@@ -18,8 +20,6 @@ import org.jooq.generated.mjga.tables.pojos.AiLlmConfig;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import static org.jooq.generated.mjga.Tables.AI_LLM_CONFIG;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@@ -44,11 +44,13 @@ public class LlmService {
|
||||
if (records.isEmpty()) {
|
||||
return PageResponseDto.empty();
|
||||
}
|
||||
List<LlmVm> llmVms = records.map((record) -> {
|
||||
LlmVm into = record.into(LlmVm.class);
|
||||
into.setType(record.get(AI_LLM_CONFIG.TYPE).getLiteral());
|
||||
return into;
|
||||
});
|
||||
List<LlmVm> llmVms =
|
||||
records.map(
|
||||
(record) -> {
|
||||
LlmVm into = record.into(LlmVm.class);
|
||||
into.setType(record.get(AI_LLM_CONFIG.TYPE).getLiteral());
|
||||
return into;
|
||||
});
|
||||
Long totalLlm = records.get(0).getValue("total_llm", Long.class);
|
||||
return new PageResponseDto<>(totalLlm, llmVms);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user