Commit ad1fa2f3 authored by muhong's avatar muhong

修改 小程序藏品列表

parent c5b761a4
...@@ -49,7 +49,7 @@ public class FavoritesDaoImpl implements FavoritesDao { ...@@ -49,7 +49,7 @@ public class FavoritesDaoImpl implements FavoritesDao {
FavoritesExample.Criteria criteria = example.createCriteria(); FavoritesExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId); criteria.andUserIdEqualTo(userId);
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
example.orderBy("add_time desc"); example.orderBy("sort desc,add_time desc");
return favoritesMapper.selectByExampleWithBLOBs(example); return favoritesMapper.selectByExampleWithBLOBs(example);
} }
...@@ -59,7 +59,7 @@ public class FavoritesDaoImpl implements FavoritesDao { ...@@ -59,7 +59,7 @@ public class FavoritesDaoImpl implements FavoritesDao {
FavoritesExample.Criteria criteria = example.createCriteria(); FavoritesExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId); criteria.andUserIdEqualTo(userId);
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
example.orderBy("add_time desc"); example.orderBy("sort desc,add_time desc");
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
List<Favorites> list = favoritesMapper.selectByExampleWithBLOBs(example); List<Favorites> list = favoritesMapper.selectByExampleWithBLOBs(example);
return new PageInfo<>(list); return new PageInfo<>(list);
......
...@@ -284,6 +284,10 @@ public class ItemServiceImpl implements ItemService { ...@@ -284,6 +284,10 @@ public class ItemServiceImpl implements ItemService {
if (dto.getUserId().equals(0L)) { if (dto.getUserId().equals(0L)) {
return Result.failed("您尚未登录,请先登录"); return Result.failed("您尚未登录,请先登录");
} }
Item item = itemDao.findDetails(dto.getId());
if (Objects.isNull(item)) {
return Result.failed("数据异常,藏品不存在");
}
// 判断是否收藏过 // 判断是否收藏过
if (favoritesItemsRelationDao.isCollected(dto.getUserId(), dto.getId())) { if (favoritesItemsRelationDao.isCollected(dto.getUserId(), dto.getId())) {
return Result.failed("您已经收藏过该藏品"); return Result.failed("您已经收藏过该藏品");
...@@ -302,8 +306,21 @@ public class ItemServiceImpl implements ItemService { ...@@ -302,8 +306,21 @@ public class ItemServiceImpl implements ItemService {
favoritesItemsRelation.setAddTime(new Date()); favoritesItemsRelation.setAddTime(new Date());
favoritesItemsRelationDao.insert(favoritesItemsRelation); favoritesItemsRelationDao.insert(favoritesItemsRelation);
// 查询收藏数
long count = favoritesItemsRelationDao.countByItemId(dto.getId());
if (item.getSourceType().equals(CommonEnum.SourceTypeEnum.USER_UPLOAD.getCode())) {
count --;
}
String collectCount = "0";
if (count < 1000) {
collectCount = String.valueOf(count);
} else {
collectCount = String.format("%.1f", (double) count / 1000) + "k";
}
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("favoritesId", favorites.getId()); map.put("favoritesId", favorites.getId());
map.put("collectCount", collectCount);
return Result.success(map); return Result.success(map);
} catch (Exception e) { } catch (Exception e) {
logger.error("首页收藏失败,原因:" + e.getMessage(), e); logger.error("首页收藏失败,原因:" + e.getMessage(), e);
...@@ -318,13 +335,32 @@ public class ItemServiceImpl implements ItemService { ...@@ -318,13 +335,32 @@ public class ItemServiceImpl implements ItemService {
if (dto.getUserId().equals(0L)) { if (dto.getUserId().equals(0L)) {
return Result.failed("您尚未登录,请先登录"); return Result.failed("您尚未登录,请先登录");
} }
Item item = itemDao.findDetails(dto.getId());
if (Objects.isNull(item)) {
return Result.failed("数据异常,藏品不存在");
}
if (userItemsRelationDao.isExisted(dto.getUserId(), dto.getId())) { if (userItemsRelationDao.isExisted(dto.getUserId(), dto.getId())) {
return Result.failed("自己发布的藏品不能取消收藏"); return Result.failed("自己发布的藏品不能取消收藏");
} }
// 删除藏品和收藏册关联 // 删除藏品和收藏册关联
favoritesItemsRelationDao.deleteByUserIdItemId(dto.getUserId(), dto.getId()); favoritesItemsRelationDao.deleteByUserIdItemId(dto.getUserId(), dto.getId());
return Result.success();
// 查询收藏数
long count = favoritesItemsRelationDao.countByItemId(dto.getId());
if (item.getSourceType().equals(CommonEnum.SourceTypeEnum.USER_UPLOAD.getCode())) {
count --;
}
String collectCount = "0";
if (count < 1000) {
collectCount = String.valueOf(count);
} else {
collectCount = String.format("%.1f", (double) count / 1000) + "k";
}
Map<String, Object> map = new HashMap<>();
map.put("collectCount", collectCount);
return Result.success(map);
} catch (Exception e) { } catch (Exception e) {
logger.error("首页取消收藏失败,原因:" + e.getMessage(), e); logger.error("首页取消收藏失败,原因:" + e.getMessage(), e);
return Result.failed("首页取消收藏失败"); return Result.failed("首页取消收藏失败");
......
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