Commit 8f0580b4 authored by muhong's avatar muhong

修改 足迹和收藏册

parent b707a6f9
...@@ -82,4 +82,13 @@ public interface FavoritesDao { ...@@ -82,4 +82,13 @@ public interface FavoritesDao {
* @return * @return
*/ */
Favorites defaultFavorites(Long userId); Favorites defaultFavorites(Long userId);
/**
* 更新时间
*
* @param id
* @param ids
* @return
*/
int updateTime(Long id, List<Long> ids);
} }
...@@ -40,6 +40,15 @@ public interface FootPrintDao { ...@@ -40,6 +40,15 @@ public interface FootPrintDao {
*/ */
int delete(List<Long> ids); int delete(List<Long> ids);
/**
* 删除记录
*
* @param userId
* @param itemId
* @return
*/
int deleteByUserIdItemId(Long userId, Long itemId);
/** /**
* 通过用户id和藏品id获取对应的记录 * 通过用户id和藏品id获取对应的记录
* *
......
...@@ -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("sort desc,add_time desc"); example.orderBy("sort desc,update_time desc");
return favoritesMapper.selectByExampleWithBLOBs(example); return favoritesMapper.selectByExampleWithBLOBs(example);
} }
...@@ -98,4 +98,15 @@ public class FavoritesDaoImpl implements FavoritesDao { ...@@ -98,4 +98,15 @@ public class FavoritesDaoImpl implements FavoritesDao {
criteria.andSortEqualTo(1); criteria.andSortEqualTo(1);
return favoritesMapper.selectOneByExample(example); return favoritesMapper.selectOneByExample(example);
} }
@Override
public int updateTime(Long id, List<Long> ids) {
FavoritesExample example = new FavoritesExample();
FavoritesExample.Criteria criteria = example.createCriteria();
JdbcHelper.ifPresent(id, criteria::andIdEqualTo);
JdbcHelper.ifPresent(ids, criteria::andIdIn);
Favorites favorites = new Favorites();
favorites.setUpdateTime(new Date());
return favoritesMapper.updateByExampleSelective(favorites, example);
}
} }
...@@ -59,6 +59,18 @@ public class FootPrintDaoImpl implements FootPrintDao { ...@@ -59,6 +59,18 @@ public class FootPrintDaoImpl implements FootPrintDao {
return footprintMapper.updateByExampleSelective(footprint, example); return footprintMapper.updateByExampleSelective(footprint, example);
} }
@Override
public int deleteByUserIdItemId(Long userId, Long itemId) {
FootprintExample example = new FootprintExample();
FootprintExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId);
criteria.andItemIdEqualTo(itemId);
Footprint footprint = new Footprint();
footprint.setDeleted(true);
footprint.setUpdateTime(new Date());
return footprintMapper.updateByExampleSelective(footprint, example);
}
@Override @Override
public Footprint selectByUserIdItem(Long userId, Long itemId) { public Footprint selectByUserIdItem(Long userId, Long itemId) {
FootprintExample example = new FootprintExample(); FootprintExample example = new FootprintExample();
......
...@@ -355,6 +355,9 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -355,6 +355,9 @@ public class FavoritesServiceImpl implements FavoritesService {
favoritesItemsRelation.setItemId(dto.getId()); favoritesItemsRelation.setItemId(dto.getId());
favoritesItemsRelation.setAddTime(new Date()); favoritesItemsRelation.setAddTime(new Date());
favoritesItemsRelationDao.insert(favoritesItemsRelation); favoritesItemsRelationDao.insert(favoritesItemsRelation);
// 更新收藏册操作时间
favoritesDao.updateTime(dto.getFavoritesId(), null);
logger.info("【请求结束】收藏藏品成功"); logger.info("【请求结束】收藏藏品成功");
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
...@@ -384,6 +387,9 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -384,6 +387,9 @@ public class FavoritesServiceImpl implements FavoritesService {
// 删除收藏册和钱币的关联 // 删除收藏册和钱币的关联
favoritesItemsRelationDao.deleteByChosen(dto.getFavoritesId(), dto.getItemIds()); favoritesItemsRelationDao.deleteByChosen(dto.getFavoritesId(), dto.getItemIds());
// 更新收藏册操作时间
favoritesDao.updateTime(dto.getFavoritesId(), null);
logger.info("【请求结束】取消收藏成功"); logger.info("【请求结束】取消收藏成功");
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
...@@ -418,6 +424,12 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -418,6 +424,12 @@ public class FavoritesServiceImpl implements FavoritesService {
if (CollectionUtils.isNotEmpty(list)) { if (CollectionUtils.isNotEmpty(list)) {
favoritesItemsRelationDao.batchInsert(list); favoritesItemsRelationDao.batchInsert(list);
} }
// 更新收藏册操作时间
List<Long> favoritesIds = new ArrayList<>();
favoritesIds.add(dto.getBeforeFavoritesId());
favoritesIds.add(dto.getAfterFavoritesId());
favoritesDao.updateTime(null, favoritesIds);
logger.info("【请求结束】移动藏品成功"); logger.info("【请求结束】移动藏品成功");
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
......
...@@ -197,6 +197,9 @@ public class FootPrintServiceImpl implements FootPrintService { ...@@ -197,6 +197,9 @@ public class FootPrintServiceImpl implements FootPrintService {
String countString = ""; String countString = "";
// 设置收藏数 // 设置收藏数
long count = favoritesItemsRelationDao.countByItemId(itemId); long count = favoritesItemsRelationDao.countByItemId(itemId);
if (count <= 0) {
return "0";
}
if (sourceType.equals(CommonEnum.SourceTypeEnum.USER_UPLOAD.getCode())) { if (sourceType.equals(CommonEnum.SourceTypeEnum.USER_UPLOAD.getCode())) {
count --; count --;
} }
......
...@@ -205,6 +205,9 @@ public class ItemServiceImpl implements ItemService { ...@@ -205,6 +205,9 @@ public class ItemServiceImpl implements ItemService {
favoritesItemsRelation.setAddTime(now); favoritesItemsRelation.setAddTime(now);
favoritesItemsRelationDao.insert(favoritesItemsRelation); favoritesItemsRelationDao.insert(favoritesItemsRelation);
// 更新收藏册操作时间
favoritesDao.updateTime(dto.getFavoritesId(), null);
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("id", item.getId()); map.put("id", item.getId());
return Result.success(map); return Result.success(map);
...@@ -223,7 +226,18 @@ public class ItemServiceImpl implements ItemService { ...@@ -223,7 +226,18 @@ public class ItemServiceImpl implements ItemService {
if (Objects.nonNull(dto.getType()) && dto.getType().equals(1)) { if (Objects.nonNull(dto.getType()) && dto.getType().equals(1)) {
if (Objects.nonNull(dto.getUserId()) && !dto.getUserId().equals(0L)) { if (Objects.nonNull(dto.getUserId()) && !dto.getUserId().equals(0L)) {
// 如果当前用户已收藏该藏品,则删除收藏关联 // 如果当前用户已收藏该藏品,则删除收藏关联
favoritesItemsRelationDao.deleteByUserIdItemId(dto.getUserId(), dto.getId()); FavoritesItemsRelation favoritesItemsRelation = favoritesItemsRelationDao.selectByUserIdItemId(dto.getUserId(), dto.getId());
if (Objects.nonNull(favoritesItemsRelation)) {
// 更新收藏册操作时间
favoritesDao.updateTime(favoritesItemsRelation.getFavoritesId(), null);
favoritesItemsRelationDao.deleteByUserIdItemId(dto.getUserId(), dto.getId());
}
}
}
if (Objects.nonNull(dto.getType()) && dto.getType().equals(2)) {
if (Objects.nonNull(dto.getUserId()) && !dto.getUserId().equals(0L)) {
// 删除用户足迹
footPrintDao.deleteByUserIdItemId(dto.getUserId(), dto.getId());
} }
} }
return Result.failed(ResultCode.INVALID_DATA.getCode(), "该藏品已经被移除"); return Result.failed(ResultCode.INVALID_DATA.getCode(), "该藏品已经被移除");
...@@ -335,6 +349,9 @@ public class ItemServiceImpl implements ItemService { ...@@ -335,6 +349,9 @@ public class ItemServiceImpl implements ItemService {
favoritesItemsRelation.setAddTime(new Date()); favoritesItemsRelation.setAddTime(new Date());
favoritesItemsRelationDao.insert(favoritesItemsRelation); favoritesItemsRelationDao.insert(favoritesItemsRelation);
// 更新收藏册操作时间
favoritesDao.updateTime(favorites.getId(), null);
// 查询收藏数 // 查询收藏数
String collectCount = getCollectCount(item.getId(), item.getSourceType()); String collectCount = getCollectCount(item.getId(), item.getSourceType());
...@@ -363,6 +380,12 @@ public class ItemServiceImpl implements ItemService { ...@@ -363,6 +380,12 @@ public class ItemServiceImpl implements ItemService {
return Result.failed("自己发布的藏品不能取消收藏"); return Result.failed("自己发布的藏品不能取消收藏");
} }
// 更新收藏册操作时间
FavoritesItemsRelation favoritesItemsRelation = favoritesItemsRelationDao.selectByUserIdItemId(dto.getUserId(), dto.getId());
if (Objects.nonNull(favoritesItemsRelation)) {
favoritesDao.updateTime(favoritesItemsRelation.getFavoritesId(), null);
}
// 删除藏品和收藏册关联 // 删除藏品和收藏册关联
favoritesItemsRelationDao.deleteByUserIdItemId(dto.getUserId(), dto.getId()); favoritesItemsRelationDao.deleteByUserIdItemId(dto.getUserId(), dto.getId());
...@@ -399,16 +422,26 @@ public class ItemServiceImpl implements ItemService { ...@@ -399,16 +422,26 @@ public class ItemServiceImpl implements ItemService {
item.setUpdateTime(now); item.setUpdateTime(now);
itemDao.update(item); itemDao.update(item);
// 删除原来藏品和收藏册关联 // 更新收藏册
favoritesItemsRelationDao.deleteByUserIdItemId(dto.getUserId(), dto.getId()); List<Long> favoritesIds = new ArrayList<>();
FavoritesItemsRelation beforeRelation = favoritesItemsRelationDao.selectByUserIdItemId(dto.getUserId(), dto.getId());
// 新增藏品和收藏册关联 if (Objects.nonNull(beforeRelation) && !beforeRelation.getFavoritesId().equals(dto.getFavoritesId())) {
FavoritesItemsRelation favoritesItemsRelation = new FavoritesItemsRelation(); // 更新操作时间
favoritesItemsRelation.setUserId(dto.getUserId()); favoritesIds.add(beforeRelation.getFavoritesId());
favoritesItemsRelation.setFavoritesId(dto.getFavoritesId()); favoritesIds.add(dto.getFavoritesId());
favoritesItemsRelation.setItemId(item.getId()); favoritesDao.updateTime(null, favoritesIds);
favoritesItemsRelation.setAddTime(now);
favoritesItemsRelationDao.insert(favoritesItemsRelation); // 删除原来藏品和收藏册关联
favoritesItemsRelationDao.deleteByUserIdItemId(dto.getUserId(), dto.getId());
// 新增藏品和收藏册关联
FavoritesItemsRelation favoritesItemsRelation = new FavoritesItemsRelation();
favoritesItemsRelation.setUserId(dto.getUserId());
favoritesItemsRelation.setFavoritesId(dto.getFavoritesId());
favoritesItemsRelation.setItemId(item.getId());
favoritesItemsRelation.setAddTime(now);
favoritesItemsRelationDao.insert(favoritesItemsRelation);
}
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("id", dto.getId()); map.put("id", dto.getId());
......
...@@ -46,7 +46,7 @@ public class WxFootprintController { ...@@ -46,7 +46,7 @@ public class WxFootprintController {
public Result delete(@RequestBody FootPrintRequestDto dto) { public Result delete(@RequestBody FootPrintRequestDto dto) {
logger.info("【请求开始】用户足迹删除,请求参数:{}", JSON.toJSONString(dto)); logger.info("【请求开始】用户足迹删除,请求参数:{}", JSON.toJSONString(dto));
if (CollectionUtils.isEmpty(dto.getIds())) { if (CollectionUtils.isEmpty(dto.getIds())) {
return Result.failed("收藏册id不能为空"); return Result.failed("请选择藏品");
} }
return footPrintService.delete(dto); return footPrintService.delete(dto);
} }
......
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