Commit 41f6cc6f authored by muhong's avatar muhong

新增 小程序收藏接口

parent fb1d9ead
...@@ -87,6 +87,7 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -87,6 +87,7 @@ public class FavoritesServiceImpl implements FavoritesService {
} }
page.setTotal(favoritesPage.getTotal()); page.setTotal(favoritesPage.getTotal());
page.setList(list); page.setList(list);
logger.info("【请求结束】分页查询收藏册列表成功");
return Result.success(page); return Result.success(page);
} catch (Exception e) { } catch (Exception e) {
logger.error("查询收藏册列表失败,原因:" + e.getMessage(), e); logger.error("查询收藏册列表失败,原因:" + e.getMessage(), e);
...@@ -112,6 +113,7 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -112,6 +113,7 @@ public class FavoritesServiceImpl implements FavoritesService {
vo.setCount(favoritesItemsRelationDao.countByFavoritesId(favorites.getId())); vo.setCount(favoritesItemsRelationDao.countByFavoritesId(favorites.getId()));
result.add(vo); result.add(vo);
} }
logger.info("【请求结束】查询收藏册列表成功");
return Result.success(result); return Result.success(result);
} catch (Exception e) { } catch (Exception e) {
logger.error("获取收藏册列表失败,原因:" + e.getMessage(), e); logger.error("获取收藏册列表失败,原因:" + e.getMessage(), e);
...@@ -139,6 +141,7 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -139,6 +141,7 @@ public class FavoritesServiceImpl implements FavoritesService {
favorites.setDeleted(false); favorites.setDeleted(false);
favorites.setSort(0); favorites.setSort(0);
favoritesDao.insert(favorites); favoritesDao.insert(favorites);
logger.info("【请求结束】新增收藏册成功");
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
logger.error("新增收藏册失败,原因:" + e.getMessage(), e); logger.error("新增收藏册失败,原因:" + e.getMessage(), e);
...@@ -165,11 +168,12 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -165,11 +168,12 @@ public class FavoritesServiceImpl implements FavoritesService {
favorites.setImages(dto.getImages()); favorites.setImages(dto.getImages());
favorites.setUpdateTime(new Date()); favorites.setUpdateTime(new Date());
favoritesDao.update(favorites); favoritesDao.update(favorites);
logger.info("【请求结束】修改收藏册成功");
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
logger.error("新增收藏册失败,原因:" + e.getMessage(), e); logger.error("修改收藏册失败,原因:" + e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return Result.failed("新增收藏册失败"); return Result.failed("修改收藏册失败");
} }
} }
...@@ -180,6 +184,7 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -180,6 +184,7 @@ public class FavoritesServiceImpl implements FavoritesService {
if (Objects.isNull(favorites)) { if (Objects.isNull(favorites)) {
return Result.failed("数据异常,记录不存在"); return Result.failed("数据异常,记录不存在");
} }
logger.info("【请求结束】查看收藏册详情成功");
return Result.success(favorites); return Result.success(favorites);
} catch (Exception e) { } catch (Exception e) {
logger.error("查看收藏册详情失败,原因:" + e.getMessage(), e); logger.error("查看收藏册详情失败,原因:" + e.getMessage(), e);
...@@ -220,6 +225,7 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -220,6 +225,7 @@ public class FavoritesServiceImpl implements FavoritesService {
} }
page.setTotal(favoritesItemsRelationDao.countByFavoritesId(dto.getId())); page.setTotal(favoritesItemsRelationDao.countByFavoritesId(dto.getId()));
page.setList(list); page.setList(list);
logger.info("【请求结束】查看收藏册的藏品列表成功");
return Result.success(page); return Result.success(page);
} catch (Exception e) { } catch (Exception e) {
logger.error("查看收藏册的藏品列表失败,原因:" + e.getMessage(), e); logger.error("查看收藏册的藏品列表失败,原因:" + e.getMessage(), e);
...@@ -238,6 +244,7 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -238,6 +244,7 @@ public class FavoritesServiceImpl implements FavoritesService {
// 删除收藏册 // 删除收藏册
favoritesDao.delete(dto.getId(), null); favoritesDao.delete(dto.getId(), null);
logger.info("【请求结束】删除收藏册成功");
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
logger.error("删除收藏册失败,原因:" + e.getMessage(), e); logger.error("删除收藏册失败,原因:" + e.getMessage(), e);
...@@ -272,6 +279,7 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -272,6 +279,7 @@ public class FavoritesServiceImpl implements FavoritesService {
// 删除收藏册 // 删除收藏册
favoritesDao.delete(null, dto.getIds()); favoritesDao.delete(null, dto.getIds());
logger.info("【请求结束】批量删除收藏册成功");
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
logger.error("批量删除收藏册失败,原因:" + e.getMessage(), e); logger.error("批量删除收藏册失败,原因:" + e.getMessage(), e);
...@@ -280,6 +288,29 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -280,6 +288,29 @@ public class FavoritesServiceImpl implements FavoritesService {
} }
} }
@Transactional
@Override
public Result addItem(ItemRequestDto dto) {
try {
Favorites favorites = favoritesDao.info(dto.getFavoritesId());
if (Objects.isNull(favorites)) {
Result.failed("数据异常,收藏册不存在");
}
FavoritesItemsRelation favoritesItemsRelation = new FavoritesItemsRelation();
favoritesItemsRelation.setUserId(favorites.getUserId());
favoritesItemsRelation.setFavoritesId(dto.getFavoritesId());
favoritesItemsRelation.setItemId(dto.getId());
favoritesItemsRelation.setAddTime(new Date());
favoritesItemsRelationDao.insert(favoritesItemsRelation);
logger.info("【请求结束】收藏藏品成功");
return Result.success();
} catch (Exception e) {
logger.error("收藏藏品失败,原因:" + e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return Result.failed("收藏藏品失败");
}
}
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public Result removeItem(ItemRequestDto dto) { public Result removeItem(ItemRequestDto dto) {
...@@ -298,6 +329,7 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -298,6 +329,7 @@ public class FavoritesServiceImpl implements FavoritesService {
// 删除收藏册和钱币的关联 // 删除收藏册和钱币的关联
favoritesItemsRelationDao.deleteByChosen(dto.getFavoritesId(), dto.getItemIds()); favoritesItemsRelationDao.deleteByChosen(dto.getFavoritesId(), dto.getItemIds());
logger.info("【请求结束】取消收藏成功");
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
logger.info("收藏册取消收藏失败,原因:" + e.getMessage(), e); logger.info("收藏册取消收藏失败,原因:" + e.getMessage(), e);
...@@ -326,6 +358,7 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -326,6 +358,7 @@ public class FavoritesServiceImpl implements FavoritesService {
if (CollectionUtils.isNotEmpty(list)) { if (CollectionUtils.isNotEmpty(list)) {
favoritesItemsRelationDao.batchInsert(list); favoritesItemsRelationDao.batchInsert(list);
} }
logger.info("【请求结束】移动藏品成功");
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
logger.error("移动藏品失败,原因:" + e.getMessage(), e); logger.error("移动藏品失败,原因:" + e.getMessage(), e);
......
...@@ -21,6 +21,7 @@ public interface FavoritesService { ...@@ -21,6 +21,7 @@ public interface FavoritesService {
Result delete(FavoritesRequestDto dto); Result delete(FavoritesRequestDto dto);
Result batchDelete(FavoritesRequestDto dto); Result batchDelete(FavoritesRequestDto dto);
Result addItem(ItemRequestDto dto);
Result removeItem(ItemRequestDto dto); Result removeItem(ItemRequestDto dto);
......
...@@ -207,6 +207,26 @@ public class WxFavoritesController { ...@@ -207,6 +207,26 @@ public class WxFavoritesController {
return favoritesService.batchDelete(dto); return favoritesService.batchDelete(dto);
} }
@ApiOperation(value = "收藏")
@PostMapping("/addItem")
public Result addItem(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data();
logger.info("【请求开始】收藏册收藏,请求参数,kl_data:{}", json);
String favoritesId = JsonUtils.getValueByPath(json, "favoritesId");
String id = JsonUtils.getValueByPath(json, "id");
if (StringUtils.isBlank(favoritesId)) {
return Result.failed("收藏册id不能为空");
}
if (StringUtils.isBlank(id)) {
return Result.failed("请选择藏品");
}
ItemRequestDto dto = new ItemRequestDto();
dto.setFavoritesId(Long.parseLong(favoritesId));
dto.setId(Long.parseLong(id));
return favoritesService.addItem(dto);
}
@ApiOperation(value = "取消收藏") @ApiOperation(value = "取消收藏")
@PostMapping("/removeItem") @PostMapping("/removeItem")
public Result removeItem(@RequestBody KlDataRequestDto klDataRequestDto) { public Result removeItem(@RequestBody KlDataRequestDto klDataRequestDto) {
......
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