Commit 3fb7c06e authored by alex yao's avatar alex yao

fix: 修复 Agent应用收藏计数问题

parent 6e1cc5e4
......@@ -719,6 +719,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
collectEntity.setAgentId(agentId);
collectEntity.setMemberId(userBaseEntity.getUserId().intValue());
List<BizMemberAgentApplicationCollectEntity> collectEntities = bizMemberAgentApplicationCollectService.findByExample(collectEntity, new PagingInfo());
Integer isCollect = 0;
if (collectEntities.isEmpty() || CommonConstant.IsDeleted.N.equals(collectEntities.get(0).getIsCollect())) { //如果没被收藏
// 收藏该应用
// 说明从来没收藏过
......@@ -733,10 +734,26 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
collectEntities.get(0).setIsCollect(CommonConstant.IsDeleted.Y);
bizMemberAgentApplicationCollectService.update(collectEntities.get(0));
}
isCollect = 1;
} else {
// 取消收藏该应用
collectEntities.get(0).setIsCollect(CommonConstant.IsDeleted.N);
bizMemberAgentApplicationCollectService.update(collectEntities.get(0));
isCollect = -1;
}
BizAgentApplicationPublishEntity publishEntity = bizAgentApplicationPublishService.getByAgentId(agentId);
if (publishEntity == null) {
logger.warn("应用尚未发布,agentId:{}", agentId);
return;
}
Integer id = publishEntity.getId();
BizAgentApplicationMallEntity mallEntity = bizAgentApplicationMallService.getByAgentPublishId(id);
if (mallEntity == null) {
logger.warn("应用尚未上架,agentId:{}", agentId);
return;
}
mallEntity.setCollectNumber(mallEntity.getCollectNumber() + isCollect);
bizAgentApplicationMallService.update(mallEntity);
}
}
......@@ -13,11 +13,13 @@ import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.utils.BlContext;
import cn.com.poc.support.security.oauth.entity.UserBaseEntity;
import cn.com.yict.framemax.core.exception.BusinessException;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
@Service
public class AgentApplicationMallServiceImpl implements AgentApplicationMallService {
......@@ -41,33 +43,40 @@ public class AgentApplicationMallServiceImpl implements AgentApplicationMallServ
}
BizAgentApplicationMallEntity mallEntity = bizAgentApplicationMallService.get(id);
if(mallEntity == null){
if (mallEntity == null) {
throw new BusinessException("应用不存在");
}
BizAgentApplicationPublishEntity publishEntity = bizAgentApplicationPublishService.get(mallEntity.getAgentPublishId());
if(publishEntity == null){
if (publishEntity == null) {
throw new BusinessException("应用未发布");
}
// 先判断当前应用被收藏了吗
BizMemberAgentApplicationCollectEntity collectEntity = bizMemberAgentApplicationCollectService.getByAgentId(publishEntity.getAgentId());
if(collectEntity == null || CommonConstant.IsDeleted.N.equals(collectEntity.getIsCollect())){ //如果没被收藏
BizMemberAgentApplicationCollectEntity bizMemberAgentApplicationCollectEntity = new BizMemberAgentApplicationCollectEntity();
bizMemberAgentApplicationCollectEntity.setMemberId(userBaseEntity.getUserId().intValue());
bizMemberAgentApplicationCollectEntity.setAgentId(publishEntity.getAgentId());
bizMemberAgentApplicationCollectEntity.setIsDeleted(CommonConstant.IsDeleted.N);
List<BizMemberAgentApplicationCollectEntity> collectEntities = bizMemberAgentApplicationCollectService.findByExample(bizMemberAgentApplicationCollectEntity, null);
if (CollectionUtils.isEmpty(collectEntities) || CommonConstant.IsDeleted.N.equals(collectEntities.get(0).getIsCollect())) { //如果没被收藏
// 收藏该应用
// 说明从来没收藏过
if(collectEntity == null){
if (CollectionUtils.isEmpty(collectEntities)) {
// 在用户收藏表中添加数据
BizMemberAgentApplicationCollectEntity entity = new BizMemberAgentApplicationCollectEntity();
entity.setIsCollect(CommonConstant.IsDeleted.Y);
entity.setMemberId(userBaseEntity.getUserId().intValue());
entity.setAgentId(publishEntity.getAgentId());
bizMemberAgentApplicationCollectService.save(entity);
}else{ // 说明之前收藏过,则只需要做个修改
} else { // 说明之前收藏过,则只需要做个修改
BizMemberAgentApplicationCollectEntity collectEntity = collectEntities.get(0);
collectEntity.setIsCollect(CommonConstant.IsDeleted.Y);
bizMemberAgentApplicationCollectService.update(collectEntity);
}
// 在应用广场的应用中 添加收藏数
mallEntity.setCollectNumber(mallEntity.getCollectNumber() + 1);
}else {
} else {
BizMemberAgentApplicationCollectEntity collectEntity = collectEntities.get(0);
// 取消收藏该应用
collectEntity.setIsCollect(CommonConstant.IsDeleted.N);
bizMemberAgentApplicationCollectService.update(collectEntity);
......
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