parent
e74fee8812
commit
f3e3f48422
@ -0,0 +1,26 @@
|
||||
package cn.teammodel.model.dto.ai;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
@Data
|
||||
public class CreateChatAppDto {
|
||||
@ApiModelProperty("应用图标")
|
||||
private String icon;
|
||||
|
||||
@ApiModelProperty("应用名称")
|
||||
@NotBlank(message = "请输入应用名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("应用描述")
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty("是否公开")
|
||||
private boolean publicApp = false;
|
||||
|
||||
@NotBlank(message = "请输入应用提示词")
|
||||
@ApiModelProperty("应用提示词")
|
||||
private String prompt;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package cn.teammodel.model.dto.ai;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
@Data
|
||||
public class UpdateChatAppDto {
|
||||
@ApiModelProperty("应用 id")
|
||||
@NotBlank(message = "请输入应用 id")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty("应用图标")
|
||||
private String icon;
|
||||
|
||||
@ApiModelProperty("应用名称")
|
||||
@NotBlank(message = "请输入应用名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("应用描述")
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty("是否公开")
|
||||
private boolean publicApp = false;
|
||||
|
||||
@NotBlank(message = "请输入应用提示词")
|
||||
@ApiModelProperty("应用提示词")
|
||||
private String prompt;
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package cn.teammodel.model.entity.ai;
|
||||
|
||||
import cn.teammodel.model.entity.BaseItem;
|
||||
import com.azure.spring.data.cosmos.core.mapping.Container;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 聊天应用(面具)
|
||||
* code: ChatApp
|
||||
* @author winter
|
||||
* @create 2024-01-23 11:08
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Container(containerName = "School")
|
||||
@Data
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class ChatApp extends BaseItem {
|
||||
/**
|
||||
* 租户 id ( public: 不允许修改 / telnet id)
|
||||
*/
|
||||
private String schoolId;
|
||||
/**
|
||||
* 图标
|
||||
*/
|
||||
private String icon;
|
||||
private String name;
|
||||
private String description;
|
||||
/**
|
||||
* 面具提示词
|
||||
*/
|
||||
private String prompt;
|
||||
private String creator;
|
||||
private String creatorId;
|
||||
private Long createTime;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package cn.teammodel.repository;
|
||||
|
||||
import cn.teammodel.model.entity.ai.ChatApp;
|
||||
import com.azure.spring.data.cosmos.repository.CosmosRepository;
|
||||
import com.azure.spring.data.cosmos.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author winter
|
||||
* @create 2023-11-28 17:39
|
||||
*/
|
||||
@Repository
|
||||
public interface ChatAppRepository extends CosmosRepository<ChatApp, String> {
|
||||
@Query("SELECT * FROM c WHERE c.code = 'ChatApp' AND (c.schoolId = @schoolId OR c.schoolId = 'public'))")
|
||||
List<ChatApp> findAllByCodeAndSchoolId(String schoolId);
|
||||
|
||||
@Query("SELECT c.id, c.schoolId, c.prompt FROM c WHERE c.code = 'ChatApp' AND c.id = @id")
|
||||
List<ChatApp> findByAppId(String id);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package cn.teammodel.service;
|
||||
|
||||
import cn.teammodel.common.IdRequest;
|
||||
import cn.teammodel.model.dto.ai.CreateChatAppDto;
|
||||
import cn.teammodel.model.dto.ai.UpdateChatAppDto;
|
||||
import cn.teammodel.model.entity.ai.ChatApp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author winter
|
||||
* @create 2024-01-23 11:19
|
||||
*/
|
||||
public interface ChatAppService {
|
||||
ChatApp createApp(CreateChatAppDto createChatAppDto);
|
||||
|
||||
ChatApp updateApp(UpdateChatAppDto updateChatAppDto);
|
||||
|
||||
void deleteApp(IdRequest idRequest);
|
||||
|
||||
List<ChatApp> listApp();
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package cn.teammodel.service.impl;
|
||||
|
||||
import cn.teammodel.common.ErrorCode;
|
||||
import cn.teammodel.common.IdRequest;
|
||||
import cn.teammodel.common.PK;
|
||||
import cn.teammodel.config.exception.ServiceException;
|
||||
import cn.teammodel.model.dto.ai.CreateChatAppDto;
|
||||
import cn.teammodel.model.dto.ai.UpdateChatAppDto;
|
||||
import cn.teammodel.model.entity.User;
|
||||
import cn.teammodel.model.entity.ai.ChatApp;
|
||||
import cn.teammodel.repository.ChatAppRepository;
|
||||
import cn.teammodel.security.utils.SecurityUtil;
|
||||
import cn.teammodel.service.ChatAppService;
|
||||
import cn.teammodel.utils.RepositoryUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author winter
|
||||
* @create 2024-01-23 11:19
|
||||
*/
|
||||
@Service
|
||||
public class ChatAppServiceImpl implements ChatAppService {
|
||||
@Resource
|
||||
private ChatAppRepository chatAppRepostitory;
|
||||
|
||||
@Override
|
||||
public ChatApp createApp(CreateChatAppDto createChatAppDto) {
|
||||
User user = SecurityUtil.getLoginUser();
|
||||
ChatApp newApp = new ChatApp();
|
||||
newApp.setName(createChatAppDto.getName());
|
||||
newApp.setIcon(createChatAppDto.getIcon());
|
||||
if (createChatAppDto.isPublicApp()) {
|
||||
newApp.setSchoolId("public");
|
||||
} else {
|
||||
newApp.setSchoolId(user.getSchoolId());
|
||||
}
|
||||
newApp.setDescription(createChatAppDto.getDescription());
|
||||
newApp.setPrompt(createChatAppDto.getPrompt());
|
||||
newApp.setCreator(user.getName());
|
||||
newApp.setCreatorId(user.getId());
|
||||
newApp.setCreateTime(Instant.now().toEpochMilli());
|
||||
newApp.setCode(PK.CHAT_APP);
|
||||
|
||||
return chatAppRepostitory.save(newApp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatApp updateApp(UpdateChatAppDto updateChatAppDto) {
|
||||
String id = updateChatAppDto.getId();
|
||||
String userId = SecurityUtil.getUserId();
|
||||
ChatApp chatApp = RepositoryUtil.findOne(chatAppRepostitory.findByAppId(id), "该应用不存在");
|
||||
if (!userId.equals(chatApp.getCreatorId())) {
|
||||
throw new ServiceException(ErrorCode.NO_AUTH_ERROR.getCode(), "您没有权限修改该应用");
|
||||
}
|
||||
chatApp.setIcon(updateChatAppDto.getIcon());
|
||||
chatApp.setName(updateChatAppDto.getName());
|
||||
chatApp.setDescription(updateChatAppDto.getDescription());
|
||||
chatApp.setPrompt(updateChatAppDto.getPrompt());
|
||||
return chatAppRepostitory.save(chatApp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteApp(IdRequest idRequest) {
|
||||
String appId = idRequest.getId();
|
||||
String userId = SecurityUtil.getUserId();
|
||||
ChatApp chatApp = RepositoryUtil.findOne(chatAppRepostitory.findByAppId(appId), "该应用不存在");
|
||||
if (userId.equals(chatApp.getCreatorId())) {
|
||||
chatAppRepostitory.deleteById(appId);
|
||||
} else {
|
||||
throw new ServiceException(ErrorCode.NO_AUTH_ERROR.getCode(), "您没有权限修改该应用");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChatApp> listApp() {
|
||||
User user = SecurityUtil.getLoginUser();
|
||||
String schoolId = user.getSchoolId();
|
||||
List<ChatApp> apps = chatAppRepostitory.findAllByCodeAndSchoolId(schoolId);
|
||||
return apps;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue