修复sku修改之后清除问题

This commit is contained in:
taozi
2022-09-11 17:38:42 +08:00
parent dc36bd5667
commit 44c706c11e
2 changed files with 13 additions and 3 deletions

View File

@ -45,7 +45,7 @@ public class YxStoreProductAttrResultServiceImpl extends BaseServiceImpl<StorePr
yxStoreProductAttrResult.setResult(JSON.toJSONString(map));
yxStoreProductAttrResult.setChangeTime(new Date());
Long count = this.count(Wrappers.<YxStoreProductAttrResult>lambdaQuery()
long count = this.count(Wrappers.<YxStoreProductAttrResult>lambdaQuery()
.eq(YxStoreProductAttrResult::getProductId,productId));
if(count > 0) {
this.remove(Wrappers.<YxStoreProductAttrResult>lambdaQuery()

View File

@ -29,6 +29,7 @@ import co.yixiang.modules.product.service.dto.ProductFormatDto;
import co.yixiang.modules.product.service.mapper.StoreProductAttrMapper;
import co.yixiang.modules.product.service.mapper.StoreProductAttrValueMapper;
import co.yixiang.modules.product.vo.YxStoreProductAttrQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -42,6 +43,7 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@ -101,14 +103,23 @@ public class YxStoreProductAttrServiceImpl extends BaseServiceImpl<StoreProductA
}
List<String> stringList = new ArrayList<>(productFormatDto.getDetail().values());
Collections.sort(stringList);
YxStoreProductAttrValue oldAttrValue = storeProductAttrValueService.getOne(new LambdaQueryWrapper<YxStoreProductAttrValue>()
.eq(YxStoreProductAttrValue::getSku, productFormatDto.getSku())
.eq(YxStoreProductAttrValue::getProductId, productId));
String unique = IdUtil.simpleUUID();
if (Objects.nonNull(oldAttrValue)) {
unique = oldAttrValue.getUnique();
}
YxStoreProductAttrValue yxStoreProductAttrValue = YxStoreProductAttrValue.builder()
.id(Objects.isNull(oldAttrValue) ? null : oldAttrValue.getId())
.productId(productId)
.sku(StrUtil.join(",",stringList))
.price(BigDecimal.valueOf(productFormatDto.getPrice()))
.cost(BigDecimal.valueOf(productFormatDto.getCost()))
.otPrice(BigDecimal.valueOf(productFormatDto.getOtPrice()))
.unique(IdUtil.simpleUUID())
.unique(unique)
.image(productFormatDto.getPic())
.barCode(productFormatDto.getBarCode())
.weight(BigDecimal.valueOf(productFormatDto.getWeight()))
@ -123,7 +134,6 @@ public class YxStoreProductAttrServiceImpl extends BaseServiceImpl<StoreProductA
.seckillStock(productFormatDto.getSeckillStock()==null?0:productFormatDto.getSeckillStock())
.build();
valueGroup.add(yxStoreProductAttrValue);
}