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

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

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