feat: 补充 chatApp 字段

11111
winter 11 months ago
parent 118fc413d3
commit d5ad605b35

@ -0,0 +1,46 @@
package cn.teammodel.common;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author winter
* @create 2024-02-01 15:30
*/
public enum ChatAppScopeEnum {
PUBLIC("public", "公共"),
SCHOOL("school", "学校"),
PRIVATE("private", "私人");
private final String code;
private final String name;
public static List<String> codes() {
return Arrays.stream(values()).map(ChatAppScopeEnum::getCode).collect(Collectors.toList());
}
/**
* name code
*/
public static String getCodeByName(String name) {
ChatAppScopeEnum chatAppScopeEnum = Arrays.stream(values()).filter(item -> item.getName().equals(name)).findFirst().orElse(null);
String res = null;
if (chatAppScopeEnum != null) {
res = chatAppScopeEnum.getCode();
}
return res;
}
ChatAppScopeEnum(String code, String name) {
this.code = code;
this.name = name;
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
}

@ -2,10 +2,7 @@ package cn.teammodel.controller.frontend;
import cn.teammodel.common.IdRequest; import cn.teammodel.common.IdRequest;
import cn.teammodel.common.R; import cn.teammodel.common.R;
import cn.teammodel.model.dto.ai.ChatCompletionReqDto; import cn.teammodel.model.dto.ai.*;
import cn.teammodel.model.dto.ai.CreateChatAppDto;
import cn.teammodel.model.dto.ai.UpdateChatAppDto;
import cn.teammodel.model.dto.ai.UpdateSessionDto;
import cn.teammodel.model.entity.ai.ChatApp; import cn.teammodel.model.entity.ai.ChatApp;
import cn.teammodel.model.entity.ai.ChatSession; import cn.teammodel.model.entity.ai.ChatSession;
import cn.teammodel.service.ChatAppService; import cn.teammodel.service.ChatAppService;
@ -106,10 +103,10 @@ public class AiController {
return R.success(session); return R.success(session);
} }
@GetMapping("app/list") @PostMapping("app/list")
@ApiOperation("查询聊天应用列表") @ApiOperation("查询聊天应用列表")
public R<List<ChatApp>> listApp() { public R<List<ChatApp>> listApp(@RequestBody @Valid SearchAppDto searchAppDto) {
List<ChatApp> chatApps = chatAppService.listApp(); List<ChatApp> chatApps = chatAppService.listApp(searchAppDto);
return R.success(chatApps); return R.success(chatApps);
} }

@ -13,13 +13,17 @@ public class CreateChatAppDto {
@ApiModelProperty("应用名称") @ApiModelProperty("应用名称")
@NotBlank(message = "请输入应用名称") @NotBlank(message = "请输入应用名称")
private String name; private String name;
private String lang;
private String bizType;
@ApiModelProperty("应用域")
@NotBlank(message = "请输入应用域")
private String scope;
private String itemType;;
private String period;
private String subject;
@ApiModelProperty("应用描述") @ApiModelProperty("应用描述")
private String description; private String description;
@ApiModelProperty("是否公开")
private boolean publicApp = false;
@NotBlank(message = "请输入应用提示词") @NotBlank(message = "请输入应用提示词")
@ApiModelProperty("应用提示词") @ApiModelProperty("应用提示词")
private String prompt; private String prompt;

@ -0,0 +1,20 @@
package cn.teammodel.model.dto.ai;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* @author winter
* @create 2024-02-01 15:40
*/
@Data
public class SearchAppDto {
@NotBlank(message = "scope不能为空")
private String scope;
private String bizType;
private String lang;
private String itemType;;
private String period;
private String subject;
}

@ -17,13 +17,17 @@ public class UpdateChatAppDto {
@ApiModelProperty("应用名称") @ApiModelProperty("应用名称")
@NotBlank(message = "请输入应用名称") @NotBlank(message = "请输入应用名称")
private String name; private String name;
private String lang;
private String bizType;
@ApiModelProperty("应用域")
@NotBlank(message = "请输入应用域")
private String scope;
private String itemType;;
private String period;
private String subject;
@ApiModelProperty("应用描述") @ApiModelProperty("应用描述")
private String description; private String description;
@ApiModelProperty("是否公开")
private boolean publicApp = false;
@NotBlank(message = "请输入应用提示词") @NotBlank(message = "请输入应用提示词")
@ApiModelProperty("应用提示词") @ApiModelProperty("应用提示词")
private String prompt; private String prompt;

@ -18,7 +18,7 @@ import lombok.EqualsAndHashCode;
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class ChatApp extends BaseItem { public class ChatApp extends BaseItem {
/** /**
* id ( public: / telnet id) * id (telnet id)
*/ */
private String schoolId; private String schoolId;
/** /**
@ -26,6 +26,24 @@ public class ChatApp extends BaseItem {
*/ */
private String icon; private String icon;
private String name; private String name;
private String bizType;
private String scope;
/**
*
*/
private String lang;
/**
*
*/
private String itemType;
/**
*
*/
private String period;
/**
*
*/
private String subject;
private String description; private String description;
/** /**
* *

@ -13,8 +13,23 @@ import java.util.List;
*/ */
@Repository @Repository
public interface ChatAppRepository extends CosmosRepository<ChatApp, String> { public interface ChatAppRepository extends CosmosRepository<ChatApp, String> {
@Query("SELECT * FROM c WHERE c.code = 'ChatApp' AND (c.schoolId = @schoolId OR c.schoolId = 'public')") @Query("SELECT * FROM c WHERE c.code = 'ChatApp' " +
List<ChatApp> findAllByCodeAndSchoolId(String schoolId); "AND (IS_NULL(@scope) or c.scope = @scope) " +
"AND (IS_NULL(@schoolId) or c.schoolId = @schoolId) " +
"AND (IS_NULL(@creatorId) or c.creatorId = @creatorId) " +
"AND (IS_NULL(@bizType) or c.bizType = @bizType) " +
"AND (IS_NULL(@lang) or c.lang = @lang) " +
"AND (IS_NULL(@itemType) or c.itemType = @itemType) " +
"AND (IS_NULL(@period) or c.period = @period) " +
"AND (IS_NULL(@subject) or c.subject = @subject)")
List<ChatApp> findAllByConditon(String scope,
String schoolId,
String creatorId,
String bizType,
String lang,
String itemType,
String period,
String subject);
@Query("SELECT c.id, c.schoolId, c.prompt FROM c WHERE c.code = 'ChatApp' AND c.id = @id") @Query("SELECT c.id, c.schoolId, c.prompt FROM c WHERE c.code = 'ChatApp' AND c.id = @id")
List<ChatApp> findByAppId(String id); List<ChatApp> findByAppId(String id);

@ -2,6 +2,7 @@ package cn.teammodel.service;
import cn.teammodel.common.IdRequest; import cn.teammodel.common.IdRequest;
import cn.teammodel.model.dto.ai.CreateChatAppDto; import cn.teammodel.model.dto.ai.CreateChatAppDto;
import cn.teammodel.model.dto.ai.SearchAppDto;
import cn.teammodel.model.dto.ai.UpdateChatAppDto; import cn.teammodel.model.dto.ai.UpdateChatAppDto;
import cn.teammodel.model.entity.ai.ChatApp; import cn.teammodel.model.entity.ai.ChatApp;
@ -18,5 +19,5 @@ public interface ChatAppService {
void deleteApp(IdRequest idRequest); void deleteApp(IdRequest idRequest);
List<ChatApp> listApp(); List<ChatApp> listApp(SearchAppDto searchAppDto);
} }

@ -1,10 +1,12 @@
package cn.teammodel.service.impl; package cn.teammodel.service.impl;
import cn.teammodel.common.ChatAppScopeEnum;
import cn.teammodel.common.ErrorCode; import cn.teammodel.common.ErrorCode;
import cn.teammodel.common.IdRequest; import cn.teammodel.common.IdRequest;
import cn.teammodel.common.PK; import cn.teammodel.common.PK;
import cn.teammodel.config.exception.ServiceException; import cn.teammodel.config.exception.ServiceException;
import cn.teammodel.model.dto.ai.CreateChatAppDto; import cn.teammodel.model.dto.ai.CreateChatAppDto;
import cn.teammodel.model.dto.ai.SearchAppDto;
import cn.teammodel.model.dto.ai.UpdateChatAppDto; import cn.teammodel.model.dto.ai.UpdateChatAppDto;
import cn.teammodel.model.entity.User; import cn.teammodel.model.entity.User;
import cn.teammodel.model.entity.ai.ChatApp; import cn.teammodel.model.entity.ai.ChatApp;
@ -12,6 +14,8 @@ import cn.teammodel.repository.ChatAppRepository;
import cn.teammodel.security.utils.SecurityUtil; import cn.teammodel.security.utils.SecurityUtil;
import cn.teammodel.service.ChatAppService; import cn.teammodel.service.ChatAppService;
import cn.teammodel.utils.RepositoryUtil; import cn.teammodel.utils.RepositoryUtil;
import cn.teammodel.utils.StrUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -30,17 +34,14 @@ public class ChatAppServiceImpl implements ChatAppService {
@Override @Override
public ChatApp createApp(CreateChatAppDto createChatAppDto) { public ChatApp createApp(CreateChatAppDto createChatAppDto) {
User user = SecurityUtil.getLoginUser(); User user = SecurityUtil.getLoginUser();
ChatApp newApp = new ChatApp(); String scope = createChatAppDto.getScope();
newApp.setName(createChatAppDto.getName()); if (!ChatAppScopeEnum.codes().contains(scope)) {
newApp.setIcon(createChatAppDto.getIcon()); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "scope参数不合法");
if (createChatAppDto.isPublicApp()) {
newApp.setSchoolId("public");
} else {
newApp.setSchoolId(user.getSchoolId());
} }
newApp.setDescription(createChatAppDto.getDescription()); ChatApp newApp = new ChatApp();
newApp.setPrompt(createChatAppDto.getPrompt()); BeanUtils.copyProperties(createChatAppDto, newApp);
newApp.setCreator(user.getName()); newApp.setCreator(user.getName());
newApp.setSchoolId(user.getSchoolId());
newApp.setCreatorId(user.getId()); newApp.setCreatorId(user.getId());
newApp.setCreateTime(Instant.now().toEpochMilli()); newApp.setCreateTime(Instant.now().toEpochMilli());
newApp.setCode(PK.CHAT_APP); newApp.setCode(PK.CHAT_APP);
@ -56,10 +57,7 @@ public class ChatAppServiceImpl implements ChatAppService {
if (!userId.equals(chatApp.getCreatorId())) { if (!userId.equals(chatApp.getCreatorId())) {
throw new ServiceException(ErrorCode.NO_AUTH_ERROR.getCode(), "您没有权限修改该应用"); throw new ServiceException(ErrorCode.NO_AUTH_ERROR.getCode(), "您没有权限修改该应用");
} }
chatApp.setIcon(updateChatAppDto.getIcon()); BeanUtils.copyProperties(updateChatAppDto, chatApp);
chatApp.setName(updateChatAppDto.getName());
chatApp.setDescription(updateChatAppDto.getDescription());
chatApp.setPrompt(updateChatAppDto.getPrompt());
return chatAppRepostitory.save(chatApp); return chatAppRepostitory.save(chatApp);
} }
@ -76,10 +74,28 @@ public class ChatAppServiceImpl implements ChatAppService {
} }
@Override @Override
public List<ChatApp> listApp() { public List<ChatApp> listApp(SearchAppDto searchAppDto) {
String scope = StrUtil.blankToNull(searchAppDto.getScope());
String bizType = StrUtil.blankToNull(searchAppDto.getBizType());
String lang = StrUtil.blankToNull(searchAppDto.getLang());
String itemType = StrUtil.blankToNull(searchAppDto.getItemType());
String period = StrUtil.blankToNull(searchAppDto.getPeriod());
String subject = StrUtil.blankToNull(searchAppDto.getSubject());
if (!ChatAppScopeEnum.codes().contains(scope)) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "scope参数不合法");
}
User user = SecurityUtil.getLoginUser(); User user = SecurityUtil.getLoginUser();
String schoolId = user.getSchoolId(); String schoolId = null;
List<ChatApp> apps = chatAppRepostitory.findAllByCodeAndSchoolId(schoolId); String creatorId = null;
if (scope.equals(ChatAppScopeEnum.PRIVATE.getCode())) {
creatorId = user.getId();
} else if (scope.equals(ChatAppScopeEnum.SCHOOL.getCode())) {
schoolId = user.getSchoolId();
}
List<ChatApp> apps = chatAppRepostitory.findAllByConditon(scope, schoolId, creatorId, bizType, lang, itemType, period, subject);
return apps; return apps;
} }
} }

@ -0,0 +1,13 @@
package cn.teammodel.utils;
import org.apache.commons.lang3.StringUtils;
/**
* @author winter
* @create 2024-02-01 16:18
*/
public class StrUtil {
public static String blankToNull(String str) {
return StringUtils.isBlank(str) ? null : str;
}
}
Loading…
Cancel
Save