|
|
@@ -16,6 +16,7 @@
|
|
|
*/
|
|
|
package org.springblade.sing.goods.controller;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
@@ -24,6 +25,7 @@ import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springblade.core.boot.ctrl.BladeController;
|
|
|
import org.springblade.core.mp.support.Condition;
|
|
|
@@ -42,7 +44,7 @@ import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
- * 控制器
|
|
|
+ * 控制器
|
|
|
*
|
|
|
* @author BladeX
|
|
|
* @since 2021-12-10
|
|
|
@@ -72,8 +74,10 @@ public class ActiveIdAndGoodsIdController extends BladeController {
|
|
|
@GetMapping("/list")
|
|
|
@ApiOperationSupport(order = 2)
|
|
|
@ApiOperation(value = "分页", notes = "传入activeIdAndGoodsId")
|
|
|
- public R<IPage<ActiveIdAndGoodsIdVO>> list(ActiveIdAndGoodsId activeIdAndGoodsId, Query query) {
|
|
|
- IPage<ActiveIdAndGoodsId> pages = activeIdAndGoodsIdService.page(Condition.getPage(query), Condition.getQueryWrapper(activeIdAndGoodsId));
|
|
|
+ public R<IPage<ActiveIdAndGoodsIdVO>> list(ActiveIdAndGoodsId activeIdAndGoodsId, Query query, String ids) {
|
|
|
+ QueryWrapper<ActiveIdAndGoodsId> queryWrapper = Condition.getQueryWrapper(activeIdAndGoodsId);
|
|
|
+ queryWrapper.lambda().in(ObjectUtils.isNotEmpty(activeIdAndGoodsId.getActiveId()), ActiveIdAndGoodsId::getGoodsId, Func.toLongList(ids));
|
|
|
+ IPage<ActiveIdAndGoodsId> pages = activeIdAndGoodsIdService.page(Condition.getPage(query), queryWrapper);
|
|
|
return R.data(ActiveIdAndGoodsIdWrapper.build().pageVO(pages));
|
|
|
}
|
|
|
|
|
|
@@ -138,35 +142,37 @@ public class ActiveIdAndGoodsIdController extends BladeController {
|
|
|
@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 = "删除ids", required = true) @RequestParam String delIds,
|
|
|
@ApiParam(value = "类型", required = true) @RequestParam String type) {
|
|
|
List<Long> longs = Func.toLongList(ids);
|
|
|
- List<ActiveIdAndGoodsId> collect = longs.stream().filter(eleId->{
|
|
|
- return !Long.valueOf(0L).equals(eleId);
|
|
|
- }).map(eleId -> new ActiveIdAndGoodsId() {{
|
|
|
- if(StringUtils.equals(type, ActiveRecord.class.getSimpleName())){
|
|
|
+ List<ActiveIdAndGoodsId> collect = longs.stream().filter(eleId ->
|
|
|
+ !Long.valueOf(0L).equals(eleId)).map(eleId -> new ActiveIdAndGoodsId() {{
|
|
|
+ if (StringUtils.equals(type, ActiveRecord.class.getSimpleName())) {
|
|
|
setActiveId(id);
|
|
|
setGoodsId(eleId);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
setGoodsId(id);
|
|
|
setActiveId(eleId);
|
|
|
}
|
|
|
}}).collect(Collectors.toList());
|
|
|
- deletePointGoodsAndActiveId(id, type);
|
|
|
+ deletePointGoodsAndActiveId(id, type, Func.toLongList(delIds));
|
|
|
return R.status(activeIdAndGoodsIdService.saveBatch(collect));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除积分商品的活动关联
|
|
|
+ *
|
|
|
* @param id
|
|
|
* @param type
|
|
|
+ * @param delIds
|
|
|
* @return
|
|
|
*/
|
|
|
- private boolean deletePointGoodsAndActiveId(Long id,String type){
|
|
|
+ private boolean deletePointGoodsAndActiveId(Long id, String type, List<Long> delIds) {
|
|
|
LambdaUpdateWrapper<ActiveIdAndGoodsId> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
|
- if(StringUtils.equals(type, ActiveRecord.class.getSimpleName())){
|
|
|
- lambdaUpdateWrapper.eq(ActiveIdAndGoodsId::getActiveId, id);
|
|
|
- }else{
|
|
|
- lambdaUpdateWrapper.eq(ActiveIdAndGoodsId::getGoodsId, id);
|
|
|
+ if (StringUtils.equals(type, ActiveRecord.class.getSimpleName())) {
|
|
|
+ lambdaUpdateWrapper.eq(ActiveIdAndGoodsId::getActiveId, id).in(ActiveIdAndGoodsId::getGoodsId, delIds);
|
|
|
+ } else {
|
|
|
+ lambdaUpdateWrapper.eq(ActiveIdAndGoodsId::getGoodsId, id).in(ActiveIdAndGoodsId::getActiveId, delIds);
|
|
|
}
|
|
|
return activeIdAndGoodsIdService.remove(lambdaUpdateWrapper);
|
|
|
}
|