Commit 679a1eca authored by muhong's avatar muhong

修改 小程序收藏

parent e5d19519
...@@ -10,12 +10,9 @@ public interface FavoritesDao { ...@@ -10,12 +10,9 @@ public interface FavoritesDao {
int delete(Long id); int delete(Long id);
int update(Favorites record); int update(Favorites record);
Favorites info(Long id); Favorites info(Long id);
List<Favorites> listByUserId(Long userId); List<Favorites> listByUserId(Long userId);
PageInfo<Favorites> pageByUserId(Long userId, int page, int size); PageInfo<Favorites> pageByUserId(Long userId, int page, int size);
boolean isExisted(Long id, Long userId, String title); boolean isExisted(Long id, Long userId, String title);
int delete(Long id, List<Long> ids); int delete(Long id, List<Long> ids);
Favorites defaultFavorites(Long userId);
} }
...@@ -89,4 +89,13 @@ public class FavoritesDaoImpl implements FavoritesDao { ...@@ -89,4 +89,13 @@ public class FavoritesDaoImpl implements FavoritesDao {
favorites.setUpdateTime(new Date()); favorites.setUpdateTime(new Date());
return favoritesMapper.updateByExampleSelective(favorites, example); return favoritesMapper.updateByExampleSelective(favorites, example);
} }
@Override
public Favorites defaultFavorites(Long userId) {
FavoritesExample example = new FavoritesExample();
FavoritesExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId);
criteria.andSortEqualTo(1);
return favoritesMapper.selectOneByExample(example);
}
} }
...@@ -2,6 +2,7 @@ package com.wwdz.ch.db.impl; ...@@ -2,6 +2,7 @@ package com.wwdz.ch.db.impl;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.wwdz.ch.db.domain.Favorites;
import com.wwdz.ch.db.mapper.FavoritesItemsRelationMapper; import com.wwdz.ch.db.mapper.FavoritesItemsRelationMapper;
import com.wwdz.ch.db.domain.FavoritesItemsRelation; import com.wwdz.ch.db.domain.FavoritesItemsRelation;
import com.wwdz.ch.db.domain.FavoritesItemsRelationExample; import com.wwdz.ch.db.domain.FavoritesItemsRelationExample;
......
...@@ -359,6 +359,10 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -359,6 +359,10 @@ public class FavoritesServiceImpl implements FavoritesService {
@Override @Override
public Result moveItem(ItemRequestDto dto) { public Result moveItem(ItemRequestDto dto) {
try { try {
Favorites favorites = favoritesDao.info(dto.getAfterFavoritesId());
if (Objects.isNull(favorites)) {
return Result.failed("数据异常,目标收藏册不存在");
}
// 删除原收藏册和藏品关联记录 // 删除原收藏册和藏品关联记录
favoritesItemsRelationDao.deleteByChosen(dto.getBeforeFavoritesId(), dto.getItemIds()); favoritesItemsRelationDao.deleteByChosen(dto.getBeforeFavoritesId(), dto.getItemIds());
...@@ -368,6 +372,7 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -368,6 +372,7 @@ public class FavoritesServiceImpl implements FavoritesService {
for (Long itemId : dto.getItemIds()) { for (Long itemId : dto.getItemIds()) {
FavoritesItemsRelation record = new FavoritesItemsRelation(); FavoritesItemsRelation record = new FavoritesItemsRelation();
record.setFavoritesId(dto.getAfterFavoritesId()); record.setFavoritesId(dto.getAfterFavoritesId());
record.setUserId(favorites.getUserId());
record.setItemId(itemId); record.setItemId(itemId);
record.setAddTime(now); record.setAddTime(now);
list.add(record); list.add(record);
......
...@@ -3,14 +3,8 @@ package com.wwdz.ch.wx.impl; ...@@ -3,14 +3,8 @@ package com.wwdz.ch.wx.impl;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.wwdz.ch.core.consts.CommonEnum; import com.wwdz.ch.core.consts.CommonEnum;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dao.CategoryDao; import com.wwdz.ch.db.dao.*;
import com.wwdz.ch.db.dao.FavoritesItemsRelationDao; import com.wwdz.ch.db.domain.*;
import com.wwdz.ch.db.dao.ItemDao;
import com.wwdz.ch.db.dao.UserItemsRelationDao;
import com.wwdz.ch.db.domain.Category;
import com.wwdz.ch.db.domain.FavoritesItemsRelation;
import com.wwdz.ch.db.domain.Item;
import com.wwdz.ch.db.domain.UserItemsRelation;
import com.wwdz.ch.db.dto.request.CoinRequestDto; import com.wwdz.ch.db.dto.request.CoinRequestDto;
import com.wwdz.ch.wx.entity.request.ItemRequestDto; import com.wwdz.ch.wx.entity.request.ItemRequestDto;
import com.wwdz.ch.wx.entity.vo.AgentTranceResponseVo; import com.wwdz.ch.wx.entity.vo.AgentTranceResponseVo;
...@@ -37,6 +31,10 @@ public class ItemServiceImpl implements ItemService { ...@@ -37,6 +31,10 @@ public class ItemServiceImpl implements ItemService {
private FavoritesItemsRelationDao favoritesItemsRelationDao; private FavoritesItemsRelationDao favoritesItemsRelationDao;
@Autowired @Autowired
private CategoryDao categoryDao; private CategoryDao categoryDao;
@Autowired
private FootPrintDao footPrintDao;
@Autowired
private FavoritesDao favoritesDao;
@Override @Override
...@@ -66,6 +64,7 @@ public class ItemServiceImpl implements ItemService { ...@@ -66,6 +64,7 @@ public class ItemServiceImpl implements ItemService {
vo.setIsCollected(0); vo.setIsCollected(0);
if (!dto.getUserId().equals(0L)) { if (!dto.getUserId().equals(0L)) {
vo.setIsCollected(favoritesItemsRelationDao.isCollected(dto.getUserId(), item.getId()) ? 1 : 0); vo.setIsCollected(favoritesItemsRelationDao.isCollected(dto.getUserId(), item.getId()) ? 1 : 0);
vo.setIsMine(userItemsRelationDao.isExisted(dto.getUserId(), item.getId()) ? 1 : 0);
} }
long count = favoritesItemsRelationDao.countByItemId(item.getId()); long count = favoritesItemsRelationDao.countByItemId(item.getId());
if (item.getSourceType().equals(CommonEnum.SourceTypeEnum.USER_UPLOAD.getCode())) { if (item.getSourceType().equals(CommonEnum.SourceTypeEnum.USER_UPLOAD.getCode())) {
...@@ -73,7 +72,6 @@ public class ItemServiceImpl implements ItemService { ...@@ -73,7 +72,6 @@ public class ItemServiceImpl implements ItemService {
} }
vo.setCollectCount(count); vo.setCollectCount(count);
vo.setSourceType(item.getSourceType()); vo.setSourceType(item.getSourceType());
vo.setIsMine(0);
AgentTranceResponseVo agentTranceResponseVo = new AgentTranceResponseVo(); AgentTranceResponseVo agentTranceResponseVo = new AgentTranceResponseVo();
agentTranceResponseVo.setAgentTraceInfo_(""); agentTranceResponseVo.setAgentTraceInfo_("");
...@@ -170,6 +168,16 @@ public class ItemServiceImpl implements ItemService { ...@@ -170,6 +168,16 @@ public class ItemServiceImpl implements ItemService {
itemResponseVo.setIsCollected(0); itemResponseVo.setIsCollected(0);
} }
itemResponseVo.setIsMine(userItemsRelationDao.isExisted(dto.getUserId(), item.getId()) ? 1 : 0); itemResponseVo.setIsMine(userItemsRelationDao.isExisted(dto.getUserId(), item.getId()) ? 1 : 0);
// 添加用户足迹
Footprint footprint = new Footprint();
footprint.setUserId(dto.getUserId());
footprint.setItemId(item.getId());
Date now = new Date();
footprint.setAddTime(now);
footprint.setUpdateTime(now);
footprint.setDeleted(false);
footPrintDao.insert(footprint);
} }
logger.info("【请求结束】查看藏品详情成功"); logger.info("【请求结束】查看藏品详情成功");
return Result.success(itemResponseVo); return Result.success(itemResponseVo);
...@@ -183,36 +191,48 @@ public class ItemServiceImpl implements ItemService { ...@@ -183,36 +191,48 @@ public class ItemServiceImpl implements ItemService {
@Override @Override
public Result collect(ItemRequestDto dto) { public Result collect(ItemRequestDto dto) {
try { try {
Item item = itemDao.findDetails(dto.getId()); if (dto.getUserId().equals(0L)) {
if (null == item.getId()) { return Result.failed("您尚未登录,请先登录");
return Result.failed("数据异常,该藏品不存在"); }
// 查找默认收藏册
Favorites favorites = favoritesDao.defaultFavorites(dto.getUserId());
if (Objects.isNull(favorites)) {
return Result.failed("数据异常,查询不到用户的默认收藏册");
} }
item.setName(dto.getName());
item.setCid(dto.getCid());
item.setImages(dto.getImages());
item.setPrice(Long.parseLong(dto.getPrice()) / 100);
item.setDetail(dto.getDetail());
Date now = new Date();
item.setUpdateTime(now);
item.setSourceType(CommonEnum.SourceTypeEnum.USER_UPLOAD.getCode());
item.setIsDeleted(false);
itemDao.update(item);
// 删除藏品和原收藏册关联
List<Long> itemIds = new ArrayList<>();
itemIds.add(item.getId());
favoritesItemsRelationDao.deleteByChosen(dto.getBeforeFavoritesId(), itemIds);
// 新增藏品和新收藏册关联 // 新增藏品和新收藏册关联
FavoritesItemsRelation favoritesItemsRelation = new FavoritesItemsRelation(); FavoritesItemsRelation favoritesItemsRelation = new FavoritesItemsRelation();
favoritesItemsRelation.setUserId(dto.getUserId()); favoritesItemsRelation.setUserId(dto.getUserId());
favoritesItemsRelation.setFavoritesId(dto.getAfterFavoritesId()); favoritesItemsRelation.setFavoritesId(favorites.getId());
favoritesItemsRelation.setItemId(item.getId()); favoritesItemsRelation.setItemId(dto.getId());
favoritesItemsRelationDao.insert(favoritesItemsRelation); favoritesItemsRelationDao.insert(favoritesItemsRelation);
Map<String, Object> map = new HashMap<>();
map.put("favoritesId", favorites.getId());
return Result.success(map);
} catch (Exception e) {
logger.error("首页收藏失败,原因:" + e.getMessage(), e);
return Result.failed("首页收藏失败");
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public Result cancel(ItemRequestDto dto) {
try {
if (dto.getUserId().equals(0L)) {
return Result.failed("您尚未登录,请先登录");
}
if (userItemsRelationDao.isExisted(dto.getUserId(), dto.getId())) {
return Result.failed("操作失败,无法取消收藏");
}
// 删除藏品和收藏册关联
favoritesItemsRelationDao.deleteByUserIdItemId(dto.getUserId(), dto.getId());
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
logger.error("修改藏品失败,原因:" + e.getMessage(), e); logger.error("首页取消收藏失败,原因:" + e.getMessage(), e);
return Result.failed("修改藏品失败"); return Result.failed("首页取消收藏失败");
} }
} }
......
...@@ -30,10 +30,7 @@ public class LoginInterceptor implements HandlerInterceptor { ...@@ -30,10 +30,7 @@ public class LoginInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
logger.info("-------------进入拦截器"); logger.info("-------------进入拦截器");
logger.info("请求头名称:" + JSON.toJSONString(request.getHeaderNames())); logger.info("请求头名称:" + JSON.toJSONString(request.getHeaderNames()));
String token = request.getHeader("kl_token"); String token = request.getHeader("Authorization");
if (StringUtils.isBlank(token)) {
token = request.getHeader("kltoken");
}
logger.info("token的值是:" + token); logger.info("token的值是:" + token);
if (StringUtils.isBlank(token)) { if (StringUtils.isBlank(token)) {
return true; return true;
......
...@@ -14,5 +14,7 @@ public interface ItemService { ...@@ -14,5 +14,7 @@ public interface ItemService {
Result collect(ItemRequestDto dto); Result collect(ItemRequestDto dto);
Result cancel(ItemRequestDto dto);
Result update(ItemRequestDto dto); Result update(ItemRequestDto dto);
} }
...@@ -151,7 +151,7 @@ public class WxItemController { ...@@ -151,7 +151,7 @@ public class WxItemController {
String userId = JsonUtils.getValueByPath(json, "userId"); String userId = JsonUtils.getValueByPath(json, "userId");
String id = JsonUtils.getValueByPath(json, "id"); String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(id)) { if (StringUtils.isBlank(id)) {
return Result.failed("当前页不能为空"); return Result.failed("藏品id不能为空");
} }
ItemRequestDto dto = new ItemRequestDto(); ItemRequestDto dto = new ItemRequestDto();
...@@ -162,4 +162,44 @@ public class WxItemController { ...@@ -162,4 +162,44 @@ public class WxItemController {
dto.setId(Long.parseLong(id)); dto.setId(Long.parseLong(id));
return itemService.info(dto); return itemService.info(dto);
} }
@ApiOperation(value = "收藏")
@PostMapping("/collect")
public Result collect(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data();
logger.info("【请求开始】首页收藏,请求参数,kl_data:{}", json);
String userId = JsonUtils.getValueByPath(json, "userId");
String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(id)) {
return Result.failed("藏品id不能为空");
}
ItemRequestDto dto = new ItemRequestDto();
dto.setUserId(0L);
if (StringUtils.isNotBlank(userId)) {
dto.setUserId(Long.parseLong(userId));
}
dto.setId(Long.parseLong(id));
return itemService.collect(dto);
}
@ApiOperation(value = "取消收藏")
@PostMapping("/cancel")
public Result cancel(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data();
logger.info("【请求开始】首页取消收藏,请求参数,kl_data:{}", json);
String userId = JsonUtils.getValueByPath(json, "userId");
String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(id)) {
return Result.failed("藏品id不能为空");
}
ItemRequestDto dto = new ItemRequestDto();
dto.setUserId(0L);
if (StringUtils.isNotBlank(userId)) {
dto.setUserId(Long.parseLong(userId));
}
dto.setId(Long.parseLong(id));
return itemService.cancel(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