Commit 8a9b0f75 authored by alex yao's avatar alex yao

fix: 修复 Agent应用上架应用广场后,应用收藏计数。

parent 3fb7c06e
......@@ -23,100 +23,111 @@ import org.springframework.util.Assert;
@Component
public class BizAgentApplicationMallRestImpl implements BizAgentApplicationMallRest {
@Resource
private AgentApplicationMallService agentApplicationMallService;
@Resource
private AgentApplicationMallService agentApplicationMallService;
@Resource
private BizMemberAgentApplicationCollectService bizMemberAgentApplicationCollectService;
@Resource
private BizMemberAgentApplicationCollectService bizMemberAgentApplicationCollectService;
@Resource
private BizAgentApplicationPublishService bizAgentApplicationPublishService;
@Resource
private BizAgentApplicationPublishService bizAgentApplicationPublishService;
@Resource
@Resource
private BizAgentApplicationMallService bizAgentApplicationMallService;
@Override
public void publishAgentToMall(BizAgentApplicationMallDto dto) throws Exception {
Assert.notNull(dto);
Assert.notNull(dto.getAgentPublishId());
Assert.notNull(dto.getAgentType());
Assert.notNull(dto.getIsCopy());
BizAgentApplicationPublishEntity publishEntity = bizAgentApplicationPublishService.get(dto.getAgentPublishId());
if(publishEntity == null){
throw new BusinessException("应用未发布");
}
dto.setIsSale(CommonConstant.IsDeleted.Y);
// 判断当前应用之前是否上架了
BizAgentApplicationMallEntity mallEntity = bizAgentApplicationMallService.getByAgentPublishId(dto.getAgentPublishId());
if(mallEntity != null){
mallEntity.setIsSale(CommonConstant.IsDeleted.Y);
mallEntity.setAgentType(dto.getAgentType());
mallEntity.setIsCopy(dto.getIsCopy());
// 如果上架过,则update操作
bizAgentApplicationMallService.update(mallEntity);
}else{
// 如果没上架过,则save操作
// 把应用存入应用市场表中
bizAgentApplicationMallService.save(BizAgentApplicationMallConvert.dtoToEntity(dto));
}
}
public BizAgentApplicationMallDto getById(java.lang.Integer id) throws Exception{
Assert.notNull(id);
return BizAgentApplicationMallConvert.entityToDto(bizAgentApplicationMallService.get(id));
}
@Override
public List<BizAgentApplicationMallDto> getListByExample(BizAgentApplicationMallDto example, PagingInfo pagingInfo) throws Exception {
return null;
}
public List<BizAgentApplicationMallDto> getList(PagingInfo pagingInfo) throws Exception{
List<BizAgentApplicationMallDto> resultList = new ArrayList<>();
List<BizAgentApplicationMallEntity> byExample = bizAgentApplicationMallService.findByExample(pagingInfo);
for(BizAgentApplicationMallEntity entity : byExample){
BizAgentApplicationMallDto mallDto = BizAgentApplicationMallConvert.entityToDto(entity);
// 如果应用上架了
if(CommonConstant.IsDeleted.Y.equals(mallDto.getIsSale())){
// 设置当前用户是否收藏了
if(mallDto.getBaseInfo() != null){
BizMemberAgentApplicationCollectEntity collect = bizMemberAgentApplicationCollectService.getByAgentId(mallDto.getBaseInfo().getAgentId());
if(collect != null){
mallDto.setIsCollect(collect.getIsCollect());
}else {
mallDto.setIsCollect(CommonConstant.IsDeleted.N);
}
}
resultList.add(mallDto);
}
}
return resultList;
}
public BizAgentApplicationMallDto update(BizAgentApplicationMallDto dto) throws Exception{
Assert.notNull(dto);
BizAgentApplicationMallEntity entity = BizAgentApplicationMallConvert.dtoToEntity(dto);
return BizAgentApplicationMallConvert.entityToDto(bizAgentApplicationMallService.update(entity));
}
public void deletedById(java.lang.Integer id) throws Exception{
Assert.notNull(id);
bizAgentApplicationMallService.deletedById(id);
}
@Override
public void collectOrCancelAgentInMall(Integer id) throws Exception {
Assert.notNull(id);
agentApplicationMallService.collectOrCancelAgentInMall(id);
}
@Override
public void unSaleAgentInMall(Integer agentPublishId) throws Exception {
Assert.notNull(agentPublishId);
BizAgentApplicationMallEntity mallEntity = bizAgentApplicationMallService.getByAgentPublishId(agentPublishId);
mallEntity.setIsSale(CommonConstant.IsDeleted.N);
bizAgentApplicationMallService.update(mallEntity);
}
@Override
public void publishAgentToMall(BizAgentApplicationMallDto dto) throws Exception {
Assert.notNull(dto);
Assert.notNull(dto.getAgentPublishId());
Assert.notNull(dto.getAgentType());
Assert.notNull(dto.getIsCopy());
BizAgentApplicationPublishEntity publishEntity = bizAgentApplicationPublishService.get(dto.getAgentPublishId());
if (publishEntity == null) {
throw new BusinessException("应用未发布");
}
dto.setIsSale(CommonConstant.IsDeleted.Y);
// 判断当前应用之前是否上架了
BizAgentApplicationMallEntity mallEntity = bizAgentApplicationMallService.getByAgentPublishId(dto.getAgentPublishId());
// 查询当前应用的收藏情况
BizMemberAgentApplicationCollectEntity collectEntity = new BizMemberAgentApplicationCollectEntity();
collectEntity.setAgentId(publishEntity.getAgentId());
collectEntity.setIsCollect(CommonConstant.YOrN.Y);
collectEntity.setIsDeleted(CommonConstant.IsDeleted.N);
List<BizMemberAgentApplicationCollectEntity> collectEntities = bizMemberAgentApplicationCollectService.findByExample(collectEntity, null);
if (mallEntity != null) {
mallEntity.setIsSale(CommonConstant.IsDeleted.Y);
mallEntity.setAgentType(dto.getAgentType());
mallEntity.setIsCopy(dto.getIsCopy());
mallEntity.setCollectNumber(collectEntities.size());
// 如果上架过,则update操作
bizAgentApplicationMallService.update(mallEntity);
} else {
// 如果没上架过,则save操作
// 把应用存入应用市场表中
mallEntity.setCollectNumber(collectEntities.size());
bizAgentApplicationMallService.save(BizAgentApplicationMallConvert.dtoToEntity(dto));
}
}
public BizAgentApplicationMallDto getById(java.lang.Integer id) throws Exception {
Assert.notNull(id);
return BizAgentApplicationMallConvert.entityToDto(bizAgentApplicationMallService.get(id));
}
@Override
public List<BizAgentApplicationMallDto> getListByExample(BizAgentApplicationMallDto example, PagingInfo pagingInfo) throws Exception {
return null;
}
public List<BizAgentApplicationMallDto> getList(PagingInfo pagingInfo) throws Exception {
List<BizAgentApplicationMallDto> resultList = new ArrayList<>();
List<BizAgentApplicationMallEntity> byExample = bizAgentApplicationMallService.findByExample(pagingInfo);
for (BizAgentApplicationMallEntity entity : byExample) {
BizAgentApplicationMallDto mallDto = BizAgentApplicationMallConvert.entityToDto(entity);
// 如果应用上架了
if (CommonConstant.IsDeleted.Y.equals(mallDto.getIsSale())) {
// 设置当前用户是否收藏了
if (mallDto.getBaseInfo() != null) {
BizMemberAgentApplicationCollectEntity collect = bizMemberAgentApplicationCollectService.getByAgentId(mallDto.getBaseInfo().getAgentId());
if (collect != null) {
mallDto.setIsCollect(collect.getIsCollect());
} else {
mallDto.setIsCollect(CommonConstant.IsDeleted.N);
}
}
resultList.add(mallDto);
}
}
return resultList;
}
public BizAgentApplicationMallDto update(BizAgentApplicationMallDto dto) throws Exception {
Assert.notNull(dto);
BizAgentApplicationMallEntity entity = BizAgentApplicationMallConvert.dtoToEntity(dto);
return BizAgentApplicationMallConvert.entityToDto(bizAgentApplicationMallService.update(entity));
}
public void deletedById(java.lang.Integer id) throws Exception {
Assert.notNull(id);
bizAgentApplicationMallService.deletedById(id);
}
@Override
public void collectOrCancelAgentInMall(Integer id) throws Exception {
Assert.notNull(id);
agentApplicationMallService.collectOrCancelAgentInMall(id);
}
@Override
public void unSaleAgentInMall(Integer agentPublishId) throws Exception {
Assert.notNull(agentPublishId);
BizAgentApplicationMallEntity mallEntity = bizAgentApplicationMallService.getByAgentPublishId(agentPublishId);
mallEntity.setIsSale(CommonConstant.IsDeleted.N);
bizAgentApplicationMallService.update(mallEntity);
}
}
\ No newline at end of file
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