Commit ca7193c3 authored by shiyu's avatar shiyu

Merge remote-tracking branch 'origin/master'

parents 2ab4481d 6866f3b6
......@@ -82,4 +82,13 @@ public interface FavoritesDao {
* @return
*/
Favorites defaultFavorites(Long userId);
/**
* 更新时间
*
* @param id
* @param ids
* @return
*/
int updateTime(Long id, List<Long> ids);
}
......@@ -40,6 +40,15 @@ public interface FootPrintDao {
*/
int delete(List<Long> ids);
/**
* 删除记录
*
* @param userId
* @param itemId
* @return
*/
int deleteByUserIdItemId(Long userId, Long itemId);
/**
* 通过用户id和藏品id获取对应的记录
*
......
......@@ -49,7 +49,7 @@ public class FavoritesDaoImpl implements FavoritesDao {
FavoritesExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId);
criteria.andDeletedEqualTo(false);
example.orderBy("sort desc,add_time desc");
example.orderBy("sort desc,update_time desc");
return favoritesMapper.selectByExampleWithBLOBs(example);
}
......@@ -98,4 +98,15 @@ public class FavoritesDaoImpl implements FavoritesDao {
criteria.andSortEqualTo(1);
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);
}
}
......@@ -9,6 +9,7 @@ import com.wwdz.ch.db.mapper.FootprintMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
......@@ -33,6 +34,13 @@ public class FootPrintDaoImpl implements FootPrintDao {
FootprintExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId);
criteria.andDeletedEqualTo(false);
// 现在
Date now = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(now);
calendar.add(Calendar.MONTH, -1);
Date month = calendar.getTime();
criteria.andUpdateTimeGreaterThan(month);
example.orderBy("update_time desc");
PageHelper.startPage(page, size);
List<Footprint> list = footprintMapper.selectByExample(example);
......@@ -59,6 +67,18 @@ public class FootPrintDaoImpl implements FootPrintDao {
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
public Footprint selectByUserIdItem(Long userId, Long itemId) {
FootprintExample example = new FootprintExample();
......
......@@ -355,6 +355,9 @@ public class FavoritesServiceImpl implements FavoritesService {
favoritesItemsRelation.setItemId(dto.getId());
favoritesItemsRelation.setAddTime(new Date());
favoritesItemsRelationDao.insert(favoritesItemsRelation);
// 更新收藏册操作时间
favoritesDao.updateTime(dto.getFavoritesId(), null);
logger.info("【请求结束】收藏藏品成功");
return Result.success();
} catch (Exception e) {
......@@ -384,6 +387,9 @@ public class FavoritesServiceImpl implements FavoritesService {
// 删除收藏册和钱币的关联
favoritesItemsRelationDao.deleteByChosen(dto.getFavoritesId(), dto.getItemIds());
// 更新收藏册操作时间
favoritesDao.updateTime(dto.getFavoritesId(), null);
logger.info("【请求结束】取消收藏成功");
return Result.success();
} catch (Exception e) {
......@@ -418,6 +424,12 @@ public class FavoritesServiceImpl implements FavoritesService {
if (CollectionUtils.isNotEmpty(list)) {
favoritesItemsRelationDao.batchInsert(list);
}
// 更新收藏册操作时间
List<Long> favoritesIds = new ArrayList<>();
favoritesIds.add(dto.getBeforeFavoritesId());
favoritesIds.add(dto.getAfterFavoritesId());
favoritesDao.updateTime(null, favoritesIds);
logger.info("【请求结束】移动藏品成功");
return Result.success();
} catch (Exception e) {
......
......@@ -96,16 +96,16 @@ public class FootPrintServiceImpl implements FootPrintService {
itemResponseVo.setHomePageImage(getImage(item));
// 设置日期类型
if (footprint.getAddTime().compareTo(today) >= 0) {
if (footprint.getUpdateTime().compareTo(today) >= 0) {
itemResponseVo.setTimeType(1);
}
if (footprint.getAddTime().compareTo(yesterday) >= 0 && footprint.getAddTime().compareTo(today) < 0) {
if (footprint.getUpdateTime().compareTo(yesterday) >= 0 && footprint.getUpdateTime().compareTo(today) < 0) {
itemResponseVo.setTimeType(2);
}
if (footprint.getAddTime().compareTo(week) >= 0 && footprint.getAddTime().compareTo(yesterday) < 0) {
if (footprint.getUpdateTime().compareTo(week) >= 0 && footprint.getUpdateTime().compareTo(yesterday) < 0) {
itemResponseVo.setTimeType(3);
}
if (footprint.getAddTime().compareTo(month) >= 0 && footprint.getAddTime().compareTo(week) < 0) {
if (footprint.getUpdateTime().compareTo(month) >= 0 && footprint.getUpdateTime().compareTo(week) < 0) {
itemResponseVo.setTimeType(4);
}
......@@ -197,6 +197,9 @@ public class FootPrintServiceImpl implements FootPrintService {
String countString = "";
// 设置收藏数
long count = favoritesItemsRelationDao.countByItemId(itemId);
if (count <= 0) {
return "0";
}
if (sourceType.equals(CommonEnum.SourceTypeEnum.USER_UPLOAD.getCode())) {
count --;
}
......
......@@ -205,6 +205,9 @@ public class ItemServiceImpl implements ItemService {
favoritesItemsRelation.setAddTime(now);
favoritesItemsRelationDao.insert(favoritesItemsRelation);
// 更新收藏册操作时间
favoritesDao.updateTime(dto.getFavoritesId(), null);
Map<String, Object> map = new HashMap<>();
map.put("id", item.getId());
return Result.success(map);
......@@ -223,9 +226,20 @@ public class ItemServiceImpl implements ItemService {
if (Objects.nonNull(dto.getType()) && dto.getType().equals(1)) {
if (Objects.nonNull(dto.getUserId()) && !dto.getUserId().equals(0L)) {
// 如果当前用户已收藏该藏品,则删除收藏关联
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(), "该藏品已经被移除");
}
ItemResponseVo itemResponseVo = new ItemResponseVo();
......@@ -335,6 +349,9 @@ public class ItemServiceImpl implements ItemService {
favoritesItemsRelation.setAddTime(new Date());
favoritesItemsRelationDao.insert(favoritesItemsRelation);
// 更新收藏册操作时间
favoritesDao.updateTime(favorites.getId(), null);
// 查询收藏数
String collectCount = getCollectCount(item.getId(), item.getSourceType());
......@@ -363,6 +380,12 @@ public class ItemServiceImpl implements ItemService {
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());
......@@ -399,6 +422,15 @@ public class ItemServiceImpl implements ItemService {
item.setUpdateTime(now);
itemDao.update(item);
// 更新收藏册
List<Long> favoritesIds = new ArrayList<>();
FavoritesItemsRelation beforeRelation = favoritesItemsRelationDao.selectByUserIdItemId(dto.getUserId(), dto.getId());
if (Objects.nonNull(beforeRelation) && !beforeRelation.getFavoritesId().equals(dto.getFavoritesId())) {
// 更新操作时间
favoritesIds.add(beforeRelation.getFavoritesId());
favoritesIds.add(dto.getFavoritesId());
favoritesDao.updateTime(null, favoritesIds);
// 删除原来藏品和收藏册关联
favoritesItemsRelationDao.deleteByUserIdItemId(dto.getUserId(), dto.getId());
......@@ -409,6 +441,7 @@ public class ItemServiceImpl implements ItemService {
favoritesItemsRelation.setItemId(item.getId());
favoritesItemsRelation.setAddTime(now);
favoritesItemsRelationDao.insert(favoritesItemsRelation);
}
Map<String, Object> map = new HashMap<>();
map.put("id", dto.getId());
......
......@@ -46,7 +46,7 @@ public class WxFootprintController {
public Result delete(@RequestBody FootPrintRequestDto dto) {
logger.info("【请求开始】用户足迹删除,请求参数:{}", JSON.toJSONString(dto));
if (CollectionUtils.isEmpty(dto.getIds())) {
return Result.failed("收藏册id不能为空");
return Result.failed("请选择藏品");
}
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