ソースを参照

修改活动关联

silent 4 年 前
コミット
3b261e6ae9

+ 1 - 19
src/main/java/org/springblade/sing/active/controller/ActiveHelpRecordController.java

@@ -18,7 +18,6 @@ package org.springblade.sing.active.controller;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -34,13 +33,10 @@ import org.springblade.sing.active.service.IActiveHelpRecordService;
 import org.springblade.sing.active.service.IActiveProductRecordService;
 import org.springblade.sing.active.vo.ActiveHelpRecordVO;
 import org.springblade.sing.active.wrapper.ActiveHelpRecordWrapper;
-import org.springblade.sing.goods.entity.ActiveIdAndGoodsId;
-import org.springblade.sing.goods.service.IActiveIdAndGoodsIdService;
 import org.springblade.sing.goods.service.IHelpGoodsService;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
-import java.util.List;
 
 /**
  * 活动助力记录 控制器
@@ -57,7 +53,6 @@ public class ActiveHelpRecordController extends BladeController {
 	private final IActiveHelpRecordService activeHelpRecordService;
 	private final IActiveProductRecordService activeProductRecordService;
 	private final IHelpGoodsService helpGoodsService;
-	private final IActiveIdAndGoodsIdService activeIdAndGoodsIdService;
 
 	/**
 	 * 详情
@@ -138,19 +133,6 @@ public class ActiveHelpRecordController extends BladeController {
 	@ApiOperationSupport(order = 7)
 	@ApiOperation(value = "逻辑删除", notes = "传入ids")
 	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
-		List<Long> longs = Func.toLongList(ids);
-		for (Long aLong : longs) {
-			deletePointGoodsAndActiveId(aLong);
-		}
-		return R.status(activeHelpRecordService.deleteLogic(longs));
-	}
-
-	/**
-	 * 删除积分商品的活动
-	 * @param activeId
-	 */
-	private boolean deletePointGoodsAndActiveId(Long activeId){
-		return activeIdAndGoodsIdService.remove(Wrappers.<ActiveIdAndGoodsId>lambdaUpdate()
-			.eq(ActiveIdAndGoodsId::getActiveId,activeId));
+		return R.status(activeHelpRecordService.deleteLogic(Func.toLongList(ids)));
 	}
 }

+ 21 - 1
src/main/java/org/springblade/sing/active/controller/ActiveRecordController.java

@@ -19,6 +19,7 @@ package org.springblade.sing.active.controller;
 import cn.hutool.core.lang.Assert;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -34,10 +35,14 @@ import org.springblade.sing.active.entity.ActiveRecord;
 import org.springblade.sing.active.service.IActiveRecordService;
 import org.springblade.sing.active.vo.ActiveRecordVO;
 import org.springblade.sing.active.wrapper.ActiveRecordWrapper;
+import org.springblade.sing.goods.entity.ActiveIdAndGoodsId;
+import org.springblade.sing.goods.service.IActiveIdAndGoodsIdService;
 import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
+import java.util.List;
 
 /**
  * 活动记录 控制器
@@ -52,6 +57,7 @@ import javax.validation.Valid;
 public class ActiveRecordController extends BladeController {
 
 	private final IActiveRecordService activeRecordService;
+	private final IActiveIdAndGoodsIdService activeIdAndGoodsIdService;
 
 	/**
 	 * 详情
@@ -133,7 +139,21 @@ public class ActiveRecordController extends BladeController {
 	@PostMapping("/remove")
 	@ApiOperationSupport(order = 7)
 	@ApiOperation(value = "逻辑删除", notes = "传入ids")
+	@Transactional
 	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
-		return R.status(activeRecordService.deleteLogic(Func.toLongList(ids)));
+		List<Long> longs = Func.toLongList(ids);
+		for (Long aLong : longs) {
+			deletePointGoodsAndActiveId(aLong);
+		}
+		return R.status(activeRecordService.deleteLogic(longs));
+	}
+
+	/**
+	 * 删除积分商品的活动
+	 * @param activeId
+	 */
+	private boolean deletePointGoodsAndActiveId(Long activeId){
+		return activeIdAndGoodsIdService.remove(Wrappers.<ActiveIdAndGoodsId>lambdaUpdate()
+			.eq(ActiveIdAndGoodsId::getActiveId,activeId));
 	}
 }

+ 57 - 16
src/main/java/org/springblade/sing/goods/controller/ActiveIdAndGoodsIdController.java

@@ -16,25 +16,30 @@
  */
 package org.springblade.sing.goods.controller;
 
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
-import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import lombok.AllArgsConstructor;
-import javax.validation.Valid;
-
+import org.apache.commons.lang3.StringUtils;
+import org.springblade.core.boot.ctrl.BladeController;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
-import org.springframework.web.bind.annotation.*;
-import org.springframework.web.bind.annotation.RequestParam;
-import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springblade.sing.active.entity.ActiveRecord;
 import org.springblade.sing.goods.entity.ActiveIdAndGoodsId;
+import org.springblade.sing.goods.service.IActiveIdAndGoodsIdService;
 import org.springblade.sing.goods.vo.ActiveIdAndGoodsIdVO;
 import org.springblade.sing.goods.wrapper.ActiveIdAndGoodsIdWrapper;
-import org.springblade.sing.goods.service.IActiveIdAndGoodsIdService;
-import org.springblade.core.boot.ctrl.BladeController;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  *  控制器
@@ -62,7 +67,7 @@ public class ActiveIdAndGoodsIdController extends BladeController {
 	}
 
 	/**
-	 * 分页 
+	 * 分页
 	 */
 	@GetMapping("/list")
 	@ApiOperationSupport(order = 2)
@@ -74,7 +79,7 @@ public class ActiveIdAndGoodsIdController extends BladeController {
 
 
 	/**
-	 * 自定义分页 
+	 * 自定义分页
 	 */
 	@GetMapping("/page")
 	@ApiOperationSupport(order = 3)
@@ -85,7 +90,7 @@ public class ActiveIdAndGoodsIdController extends BladeController {
 	}
 
 	/**
-	 * 新增 
+	 * 新增
 	 */
 	@PostMapping("/save")
 	@ApiOperationSupport(order = 4)
@@ -95,7 +100,7 @@ public class ActiveIdAndGoodsIdController extends BladeController {
 	}
 
 	/**
-	 * 修改 
+	 * 修改
 	 */
 	@PostMapping("/update")
 	@ApiOperationSupport(order = 5)
@@ -105,7 +110,7 @@ public class ActiveIdAndGoodsIdController extends BladeController {
 	}
 
 	/**
-	 * 新增或修改 
+	 * 新增或修改
 	 */
 	@PostMapping("/submit")
 	@ApiOperationSupport(order = 6)
@@ -114,9 +119,9 @@ public class ActiveIdAndGoodsIdController extends BladeController {
 		return R.status(activeIdAndGoodsIdService.saveOrUpdate(activeIdAndGoodsId));
 	}
 
-	
+
 	/**
-	 * 删除 
+	 * 删除
 	 */
 	@PostMapping("/remove")
 	@ApiOperationSupport(order = 7)
@@ -125,5 +130,41 @@ public class ActiveIdAndGoodsIdController extends BladeController {
 		return R.status(activeIdAndGoodsIdService.deleteLogic(Func.toLongList(ids)));
 	}
 
-	
+	/**
+	 * 更新活动与积分商品的关系
+	 */
+	@PostMapping("/updateActiveAndPointGoods")
+	@ApiOperationSupport(order = 8)
+	@ApiOperation(value = "更新活动与积分商品的关系", notes = "传入ids")
+	public R updateActiveAndPointGoods(@ApiParam(value = "主键id", required = true) @RequestParam Long id,
+									   @ApiParam(value = "主键ids", required = true) @RequestParam String ids,
+									   @ApiParam(value = "类型", required = true) @RequestParam String type) {
+		List<Long> longs = Func.toLongList(ids);
+		List<ActiveIdAndGoodsId> collect = longs.stream().map(eleId -> new ActiveIdAndGoodsId() {{
+			if(StringUtils.equals(type, ActiveRecord.class.getSimpleName())){
+				setActiveId(id);
+				setGoodsId(eleId);
+			}else{
+				setGoodsId(id);
+				setActiveId(eleId);
+			}
+		}}).collect(Collectors.toList());
+		return R.status(deletePointGoodsAndActiveId(id, type) && activeIdAndGoodsIdService.saveBatch(collect));
+	}
+
+	/**
+	 * 删除积分商品的活动关联
+	 * @param id
+	 * @param type
+	 * @return
+	 */
+	private boolean deletePointGoodsAndActiveId(Long id,String type){
+		LambdaUpdateWrapper<ActiveIdAndGoodsId> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
+		if(StringUtils.equals(type, ActiveRecord.class.getSimpleName())){
+			lambdaUpdateWrapper.eq(ActiveIdAndGoodsId::getActiveId, id);
+		}else{
+			lambdaUpdateWrapper.eq(ActiveIdAndGoodsId::getGoodsId, id);
+		}
+		return activeIdAndGoodsIdService.remove(lambdaUpdateWrapper);
+	}
 }

+ 1 - 18
src/main/java/org/springblade/sing/goods/controller/PointGoodsController.java

@@ -40,9 +40,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
-import java.util.Arrays;
 import java.util.List;
-import java.util.stream.Collectors;
 
 /**
  * 积分商城 控制器
@@ -122,8 +120,7 @@ public class PointGoodsController extends BladeController {
 	@ApiOperation(value = "新增或修改", notes = "传入pointGoods")
 	@Transactional
 	public R submit(@Valid @RequestBody PointGoods pointGoods) {
-		return R.status(updatePointGoodsAndActiveId(pointGoods.getActiveId(),pointGoods.getId())
-			&& pointGoodsService.saveOrUpdate(pointGoods));
+		return R.status(pointGoodsService.saveOrUpdate(pointGoods));
 	}
 
 
@@ -151,20 +148,6 @@ public class PointGoodsController extends BladeController {
 		return R.data(loginUser);
 	}
 
-	/**
-	 * 修改积分商品的活动ID
-	 * @param activeIds
-	 * @param goodsId
-	 */
-	private boolean updatePointGoodsAndActiveId(String activeIds,Long goodsId){
-		//先删除原有的,再添加新的
-		return deletePointGoodsAndActiveId(goodsId)
-			&& activeIdAndGoodsIdService.saveBatch(Arrays.stream(activeIds.split(",")).map(activeId -> new ActiveIdAndGoodsId() {{
-			setActiveId(Long.valueOf(activeId));
-			setGoodsId(goodsId);
-		}}).collect(Collectors.toList()));
-	}
-
 	/**
 	 * 删除积分商品的活动
 	 * @param goodsId