|
|
@@ -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);
|
|
|
+ }
|
|
|
}
|