Commit 0cd9e782 authored by alex yao's avatar alex yao

style: 创建/更新应用 删除应用

parent 9da0d28a
......@@ -10,17 +10,31 @@ import java.util.List;
public interface AgentApplicationInfoService {
/**
* 创建/更新应用
*/
BizAgentApplicationInfoEntity saveOrUpdate(BizAgentApplicationInfoEntity entity) throws Exception;
/**
* 更新并发布应用
*/
boolean updateAndPublish(BizAgentApplicationInfoEntity entity) throws Exception;
/**
* 删除Agent应用
*
* @param agentId 应用ID
*/
boolean deletedAgentApplication(String agentId) throws Exception;
/**
* 应用预览
*/
String callAgentApplication(String identifier, String largeModel, String[] unitIds, String agentSystem,
Integer[] knowledgeIds, Integer communicationTurn, Float topP, Float temperature,
List<Message> messages, List<Tool> tools, HttpServletResponse httpServletResponse) throws Exception;
/**
* 应用下架
*
......@@ -78,15 +92,15 @@ public interface AgentApplicationInfoService {
/**
* 收藏/取消收藏应用广场中的应用
*
* @param id 应用广场的应用id
* @param id 应用广场的应用id
* @param agentId Agent应用id
* */
*/
void collectOrCancelAgentInMall(Integer id, String agentId) throws Exception;
/**
* 收藏/取消收藏个人空间中的应用
*
* @param agentId Agent应用id
* */
*/
void collectOrCancelAgentInPerson(String agentId) throws Exception;
}
......@@ -4,6 +4,7 @@ import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService;
import cn.com.poc.agent_application.constant.AgentApplicationConstants;
import cn.com.poc.agent_application.constant.AgentApplicationDialoguesRecordConstants;
import cn.com.poc.agent_application.constant.AgentApplicationGCConfigConstants;
import cn.com.poc.agent_application.convert.AgentApplicationInfoConvert;
import cn.com.poc.agent_application.entity.*;
import cn.com.poc.agent_application.query.DialogsIdsQueryByAgentIdQueryItem;
import cn.com.poc.agent_application.service.*;
......@@ -42,6 +43,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
......@@ -95,6 +97,19 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
@Resource
private RedisService redisService;
@Override
public BizAgentApplicationInfoEntity saveOrUpdate(BizAgentApplicationInfoEntity entity) throws Exception {
// 如果存在agentId,则判断变量结构是否有变化,如果有变化,则删除redis中的数据
if (StringUtils.isNotBlank(entity.getAgentId())) {
String contentKey = SetValueMemoryConstants.REDIS_PREFIX + entity.getAgentId() + ":" + entity.getMemberId();
redisService.del(contentKey);
}
// 保存或更新
return StringUtils.isEmpty(entity.getAgentId()) ?
bizAgentApplicationInfoService.save(entity) : bizAgentApplicationInfoService.update(entity);
}
@Override
public boolean updateAndPublish(BizAgentApplicationInfoEntity bizAgentApplicationInfoEntity) throws Exception {
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
......@@ -126,6 +141,21 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
return true;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean deletedAgentApplication(String agentId) throws Exception {
bizAgentApplicationInfoService.deletedByAgentId(agentId);
// 删除应用
BizAgentApplicationPublishEntity publishEntity = bizAgentApplicationPublishService.getByAgentId(agentId);
if (publishEntity != null) {
// 删除应用市场表中的应用
bizAgentApplicationMallService.deletedByAgentPublishId(publishEntity.getId());
// 删除发布表中的应用
bizAgentApplicationPublishService.deleteByAgentId(agentId);
}
return true;
}
@Override
public String callAgentApplication(String identifier, String largeModel, String[] unitIds, String agentSystem, Integer[] kdIds, Integer communicationTurn, Float topP, Float temperature, List<Message> messages, List<Tool> tools, HttpServletResponse httpServletResponse) throws Exception {
logger.info("--------- Call Agent Application large model:{},unitIds:{},agentSystem:{},knowledgeIds:{}" + " communicationTurn:{},topP:{},messages:{}--------------", largeModel, unitIds, agentSystem, kdIds, communicationTurn, topP, messages);
......
......@@ -76,6 +76,7 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
return AgentApplicationInfoConvert.entityToDto(bizAgentApplicationInfoEntity);
}
@Override
public List<AgentApplicationInfoDto> getListByMember(AgentApplicationInfoSearchDto dto, PagingInfo pagingInfo) throws Exception {
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
Long userId = userBaseEntity.getUserId();
......@@ -99,7 +100,7 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
// 如果符合条件,则把值加入
if (collect != null && collect.getIsCollect().equals(dto.getIsCollect())) {
infoDto.setIsCollect(collect.getIsCollect());
} else if ((collect == null && CommonConstant.IsDeleted.N.equals(dto.getIsCollect()))) {
} else if (collect == null && CommonConstant.IsDeleted.N.equals(dto.getIsCollect())) {
infoDto.setIsCollect(CommonConstant.IsDeleted.N);
} else {
// 如果不符合条件,则continue
......@@ -140,25 +141,23 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
}
@Override
public AgentApplicationInfoDto saveOrUpdate(AgentApplicationInfoDto dto) throws Exception {
Assert.notNull(dto);
Assert.notNull(dto.getBaseInfo());
Assert.notNull(dto.getCommConfig());
Assert.notNull(dto.getCommModelConfig());
Assert.notNull(dto.getKnowledgeConfig());
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
if (userBaseEntity == null) {
throw new I18nMessageException("exception/user.does.not.exist");
}
Long userId = userBaseEntity.getUserId();
dto.getBaseInfo().setMemberId(userId.intValue());
BizAgentApplicationInfoEntity entity = AgentApplicationInfoConvert.dtoToEntity(dto);
// 如果存在agentId,则判断变量结构是否有变化,如果有变化,则删除redis中的数据
if (StringUtils.isNotBlank(entity.getAgentId())) {
String contentKey = SetValueMemoryConstants.REDIS_PREFIX + dto.getBaseInfo().getAgentId() + ":" + BlContext.getCurrentUserNotException().getUserId().toString();
redisService.del(contentKey);
}
return AgentApplicationInfoConvert.entityToDto(StringUtils.isEmpty(entity.getAgentId()) ?
bizAgentApplicationInfoService.save(entity) : bizAgentApplicationInfoService.update(entity));
return AgentApplicationInfoConvert.entityToDto(agentApplicationInfoService.saveOrUpdate(entity));
}
......@@ -186,15 +185,7 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
@Override
public void delete(String agentId) throws Exception {
Assert.notNull(agentId);
bizAgentApplicationInfoService.deletedByAgentId(agentId);
// 删除应用
BizAgentApplicationPublishEntity publishEntity = bizAgentApplicationPublishService.getByAgentId(agentId);
if (publishEntity != null) {
// 删除应用市场表中的应用
bizAgentApplicationMallService.deletedByAgentPublishId(publishEntity.getId());
// 删除发布表中的应用
bizAgentApplicationPublishService.deleteByAgentId(agentId);
}
agentApplicationInfoService.deletedAgentApplication(agentId);
}
@Override
......@@ -319,12 +310,12 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
}
@Override
public List<String> createFeaturedQuestions(AgentApplicationGCDto dto) throws Exception {
public List<String> createFeaturedQuestions(AgentApplicationGCDto dto){
return agentApplicationInfoService.createFeaturedQuestions(dto.getAgentTitle(), dto.getAgentDesc());
}
@Override
public String createPreamble(AgentApplicationGCDto dto) throws Exception {
public String createPreamble(AgentApplicationGCDto dto){
return agentApplicationInfoService.createPreamble(dto.getAgentTitle(), dto.getAgentDesc(), dto.getAgentSystem());
}
......@@ -335,7 +326,7 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
}
@Override
public AgentApplicationGCDto createAgentTitleAndDesc(AgentApplicationGCDto dto) throws Exception {
public AgentApplicationGCDto createAgentTitleAndDesc(AgentApplicationGCDto dto) {
Assert.notNull(dto.getInput());
CreateAgentTitleAndDescEntity entity = agentApplicationInfoService.createAgentTitleAndDesc(dto.getInput());
if (null == entity) {
......@@ -383,7 +374,7 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
}
@Override
public List<AgentLongMemoryDto> getLongMemoryList(String agentId) throws Exception {
public List<AgentLongMemoryDto> getLongMemoryList(String agentId){
Assert.notNull(agentId);
List<AgentLongMemoryDto> result = new ArrayList<>();
String contentKey = SetLongMemoryConstants.REDIS_PREFIX + agentId + ":" + BlContext.getCurrentUserNotException().getUserId().toString();
......@@ -400,7 +391,7 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
}
@Override
public void deleteLongMemoryByKey(String agentId, String timestamp) throws Exception {
public void deleteLongMemoryByKey(String agentId, String timestamp) {
Assert.notNull(agentId);
Assert.notNull(timestamp);
String contentKey = SetLongMemoryConstants.REDIS_PREFIX + agentId + ":" + BlContext.getCurrentUserNotException().getUserId().toString();
......@@ -408,7 +399,7 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
}
@Override
public void deleteLongMemory(String agentId) throws Exception {
public void deleteLongMemory(String agentId){
Assert.notNull(agentId);
String contentKey = SetLongMemoryConstants.REDIS_PREFIX + agentId + ":" + BlContext.getCurrentUserNotException().getUserId().toString();
redisService.del(contentKey);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment