!10 修复分类参数修改索引属性后没有同步到商品参数问题

Merge pull request !10 from OceansDeep/feature/pg
This commit is contained in:
OceansDeep 2021-06-24 01:21:39 +00:00 committed by Gitee
commit cf1c138fe8
3 changed files with 50 additions and 2 deletions

View File

@ -23,6 +23,21 @@ public interface GoodsParamsService extends IService<GoodsParams> {
*/ */
void addParams(List<GoodsParams> paramList, String goodsId); void addParams(List<GoodsParams> paramList, String goodsId);
/**
* 更新商品参数是否索引
*
* @param paramId 参数id
* @param isIndex 是否索引
*/
void updateParametersIsIndex(String paramId, Integer isIndex);
/**
* 根据参数id删除已经设置的商品参数
*
* @param paramId 参数id
*/
void deleteByParamId(String paramId);
/** /**
* 获取商品关联参数 * 获取商品关联参数
* *

View File

@ -10,9 +10,10 @@ import cn.lili.modules.goods.service.CategoryParameterGroupService;
import cn.lili.modules.goods.service.GoodsParamsService; import cn.lili.modules.goods.service.GoodsParamsService;
import cn.lili.modules.goods.service.ParametersService; import cn.lili.modules.goods.service.ParametersService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -60,6 +61,30 @@ public class GoodsParamsServiceImpl extends ServiceImpl<GoodsParamsMapper, Goods
} }
} }
/**
* 更新商品参数是否索引
*
* @param paramId 参数id
* @param isIndex 是否索引
*/
@Override
public void updateParametersIsIndex(String paramId, Integer isIndex) {
LambdaUpdateWrapper<GoodsParams> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(GoodsParams::getParamId, paramId);
updateWrapper.set(GoodsParams::getIsIndex, isIndex);
this.update(updateWrapper);
}
/**
* 根据参数id删除已经设置的商品参数
*
* @param paramId 参数id
*/
@Override
public void deleteByParamId(String paramId) {
this.remove(new QueryWrapper<GoodsParams>().eq("param_id", paramId));
}
@Override @Override
public List<GoodsParams> getGoodsParamsByGoodsId(String goodsId) { public List<GoodsParams> getGoodsParamsByGoodsId(String goodsId) {
return this.list(new LambdaQueryWrapper<GoodsParams>().eq(GoodsParams::getGoodsId, goodsId)); return this.list(new LambdaQueryWrapper<GoodsParams>().eq(GoodsParams::getGoodsId, goodsId));

View File

@ -1,10 +1,11 @@
package cn.lili.controller.goods; package cn.lili.controller.goods;
import cn.lili.common.enums.ResultCode; import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.enums.ResultUtil; import cn.lili.common.enums.ResultUtil;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.vo.ResultMessage; import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.goods.entity.dos.Parameters; import cn.lili.modules.goods.entity.dos.Parameters;
import cn.lili.modules.goods.service.GoodsParamsService;
import cn.lili.modules.goods.service.ParametersService; import cn.lili.modules.goods.service.ParametersService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
@ -28,6 +29,9 @@ public class ParameterManagerController {
@Autowired @Autowired
private ParametersService parametersService; private ParametersService parametersService;
@Autowired
private GoodsParamsService goodsParamsService;
@ApiOperation(value = "添加参数") @ApiOperation(value = "添加参数")
@PostMapping @PostMapping
public ResultMessage<Parameters> save(@Valid Parameters parameters) { public ResultMessage<Parameters> save(@Valid Parameters parameters) {
@ -44,6 +48,9 @@ public class ParameterManagerController {
public ResultMessage<Parameters> update(@Valid Parameters parameters) { public ResultMessage<Parameters> update(@Valid Parameters parameters) {
if (parametersService.updateById(parameters)) { if (parametersService.updateById(parameters)) {
if (parameters.getIsIndex() != null) {
goodsParamsService.updateParametersIsIndex(parameters.getId(), parameters.getIsIndex());
}
return ResultUtil.data(parameters); return ResultUtil.data(parameters);
} }
throw new ServiceException(ResultCode.PARAMETER_UPDATE_ERROR); throw new ServiceException(ResultCode.PARAMETER_UPDATE_ERROR);
@ -54,6 +61,7 @@ public class ParameterManagerController {
@DeleteMapping(value = "/{id}") @DeleteMapping(value = "/{id}")
public ResultMessage<Object> delById(@PathVariable String id) { public ResultMessage<Object> delById(@PathVariable String id) {
parametersService.removeById(id); parametersService.removeById(id);
goodsParamsService.deleteByParamId(id);
return ResultUtil.success(); return ResultUtil.success();
} }