|
@@ -6,11 +6,15 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import io.swagger.annotations.*;
|
|
import io.swagger.annotations.*;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.poi.util.StringUtil;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import shop.alien.entity.result.R;
|
|
import shop.alien.entity.result.R;
|
|
|
|
+import shop.alien.entity.second.SecondGoods;
|
|
import shop.alien.entity.store.LifeCollect;
|
|
import shop.alien.entity.store.LifeCollect;
|
|
import shop.alien.entity.store.vo.StoreInfoVo;
|
|
import shop.alien.entity.store.vo.StoreInfoVo;
|
|
|
|
+import shop.alien.mapper.second.SecondGoodsMapper;
|
|
import shop.alien.store.config.GaoDeMapUtil;
|
|
import shop.alien.store.config.GaoDeMapUtil;
|
|
import shop.alien.mapper.LifeCollectMapper;
|
|
import shop.alien.mapper.LifeCollectMapper;
|
|
import shop.alien.mapper.StoreInfoMapper;
|
|
import shop.alien.mapper.StoreInfoMapper;
|
|
@@ -35,6 +39,8 @@ public class LifeCollectController {
|
|
|
|
|
|
private final LifeCollectMapper lifeCollectMapper;
|
|
private final LifeCollectMapper lifeCollectMapper;
|
|
|
|
|
|
|
|
+ private final SecondGoodsMapper secondGoodsMapper;
|
|
|
|
+
|
|
private final StoreInfoMapper storeInfoMapper;
|
|
private final StoreInfoMapper storeInfoMapper;
|
|
|
|
|
|
private final GaoDeMapUtil gaoDeMapUtil;
|
|
private final GaoDeMapUtil gaoDeMapUtil;
|
|
@@ -92,6 +98,13 @@ public class LifeCollectController {
|
|
log.info("LifeCollectController.addCollect?lifeCollect={}", lifeCollect.toString());
|
|
log.info("LifeCollectController.addCollect?lifeCollect={}", lifeCollect.toString());
|
|
lifeCollect.setCreatedTime(new Date());
|
|
lifeCollect.setCreatedTime(new Date());
|
|
int num = lifeCollectMapper.insert(lifeCollect);
|
|
int num = lifeCollectMapper.insert(lifeCollect);
|
|
|
|
+ // 二手商品收藏数量+1
|
|
|
|
+ if (StringUtil.isBlank(lifeCollect.getBusinessType()) && lifeCollect.getBusinessType().equals(1)) {
|
|
|
|
+ LambdaUpdateWrapper<SecondGoods> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
+ lambdaUpdateWrapper.eq(SecondGoods::getId, lifeCollect.getBusinessId());
|
|
|
|
+ lambdaUpdateWrapper.setSql("collect_count = collect_count + 1");
|
|
|
|
+ secondGoodsMapper.update(null, lambdaUpdateWrapper);
|
|
|
|
+ }
|
|
if (num == 0) {
|
|
if (num == 0) {
|
|
return R.fail("收藏失败");
|
|
return R.fail("收藏失败");
|
|
}
|
|
}
|
|
@@ -103,13 +116,33 @@ public class LifeCollectController {
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户id", dataType = "String", paramType = "query"),
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户id", dataType = "String", paramType = "query"),
|
|
@ApiImplicitParam(name = "storeId", value = "storeId", dataType = "String", paramType = "query")})
|
|
@ApiImplicitParam(name = "storeId", value = "storeId", dataType = "String", paramType = "query")})
|
|
@PostMapping("cancelCollect")
|
|
@PostMapping("cancelCollect")
|
|
- public R<Boolean> cancelCollect(@RequestParam String userId, @RequestParam String storeId) {
|
|
|
|
|
|
+ public R<Boolean> cancelCollect(
|
|
|
|
+ @RequestParam(value = "userId", required = false) String userId,
|
|
|
|
+ @RequestParam(value = "storeId", required = false) String storeId,
|
|
|
|
+ @RequestParam(value = "businessId", required = false) String businessId,
|
|
|
|
+ @RequestParam(value = "businessType", required = false) String businessType) {
|
|
log.info("LifeCollectController.cancelCollect?userId={},storeId={}", userId, storeId);
|
|
log.info("LifeCollectController.cancelCollect?userId={},storeId={}", userId, storeId);
|
|
LambdaUpdateWrapper<LifeCollect> wrapper = new LambdaUpdateWrapper<>();
|
|
LambdaUpdateWrapper<LifeCollect> wrapper = new LambdaUpdateWrapper<>();
|
|
wrapper.eq(LifeCollect::getUserId, userId);
|
|
wrapper.eq(LifeCollect::getUserId, userId);
|
|
- wrapper.eq(LifeCollect::getStoreId, storeId);
|
|
|
|
|
|
+ if (StringUtil.isBlank(businessType) && businessType.equals(1)) {
|
|
|
|
+ wrapper.eq(LifeCollect::getBusinessId, businessId);
|
|
|
|
+ wrapper.eq(LifeCollect::getBusinessType, businessType);
|
|
|
|
+ } else {
|
|
|
|
+ wrapper.eq(LifeCollect::getStoreId, storeId);
|
|
|
|
+ }
|
|
wrapper.set(LifeCollect::getDeleteFlag, 1);
|
|
wrapper.set(LifeCollect::getDeleteFlag, 1);
|
|
int num = lifeCollectMapper.update(null, wrapper);
|
|
int num = lifeCollectMapper.update(null, wrapper);
|
|
|
|
+ // 二手交易收藏数量-1
|
|
|
|
+ if (StringUtil.isBlank(businessType) && businessType.equals(1)) {
|
|
|
|
+ // 创建LambdaUpdateWrapper实例用于构建更新条件
|
|
|
|
+ LambdaUpdateWrapper<SecondGoods> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
+ // 设置更新条件:根据商品ID匹配且收藏数大于0
|
|
|
|
+ lambdaUpdateWrapper.eq(SecondGoods::getId, businessId).gt(SecondGoods::getCollectCount, 0);
|
|
|
|
+ // 执行SQL语句将收藏数减1
|
|
|
|
+ lambdaUpdateWrapper.setSql("collect_count = collect_count - 1");
|
|
|
|
+ secondGoodsMapper.update(null, lambdaUpdateWrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
if (num == 0) {
|
|
if (num == 0) {
|
|
return R.fail("取消收藏失败");
|
|
return R.fail("取消收藏失败");
|
|
}
|
|
}
|