Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
SongZhang 2024-10-10 16:58:01 +08:00
commit 504fec5011
2 changed files with 33 additions and 17 deletions

View File

@ -4,7 +4,6 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.util.ObjectUtil;
import cn.ysk.cashier.cons.domain.TbConsInfo;
import cn.ysk.cashier.cons.domain.TbConsSuppFlow;
import cn.ysk.cashier.cons.domain.TbProskuCon;
import cn.ysk.cashier.cons.repository.TbConsInfoRepository;
import cn.ysk.cashier.cons.service.dto.ProskuInfo;
@ -22,13 +21,13 @@ import cn.ysk.cashier.cons.service.dto.TbProskuConDto;
import cn.ysk.cashier.cons.service.dto.TbProskuConQueryCriteria;
import cn.ysk.cashier.cons.service.mapstruct.TbProskuConMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.*;
import java.io.IOException;
@ -168,6 +167,10 @@ public class TbProskuConServiceImpl implements TbProskuConService {
tbProskuConRepository.deleteAllByProductId(resources.getProductId());
return;
}
List<TbProskuConDto> cons = resources.getCons();
if(hasIdentical(cons)){
throw new BadRequestException("添加失败,对应耗材存在多条关系");
}
List<TbProskuCon> newCons = new ArrayList<>();
TbProduct product = tbProductRepository.getById(resources.getProductId());
if (Objects.isNull(product)) {
@ -196,6 +199,9 @@ public class TbProskuConServiceImpl implements TbProskuConService {
if (ObjectUtil.isNull(tbConsInfo) || ObjectUtil.isNull(tbConsInfo.getId())) {
throw new BadRequestException("对应的耗材信息不存在");
}
if (resource.getSurplusStock().compareTo(BigDecimal.ZERO) <= 0) {
throw new BadRequestException("耗材"+ tbConsInfo.getConName() +"使用数量不可小于等于 0");
}
TbProductSku sku = null;
if (resource.getProductSkuId() != 0) {
sku = tbProductSkuRepository.findById(resource.getProductSkuId()).orElseGet(TbProductSku::new);
@ -226,6 +232,16 @@ public class TbProskuConServiceImpl implements TbProskuConService {
}
}
public static boolean hasIdentical(List<TbProskuConDto> cons) {
List<List<TbProskuConDto>> groupedByAllFields = cons.stream()
.collect(Collectors.groupingBy(item -> item.getProductSkuId() + "-" + item.getConInfoId() + "-" + item.getShopId() + "-" + item.getProductId()))
.values().stream()
.filter(group -> group.size() > 1)
.collect(Collectors.toList());
return!groupedByAllFields.isEmpty();
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(TbProskuCon resources) throws Exception {

View File

@ -253,9 +253,13 @@ public class TbProductServiceImpl implements TbProductService {
productNewVo.setLowPrice(product.getLowPrice().toString());
productNewVo.setStockNumber(Double.valueOf(product.getStockNumber()));
List<TbProductSku> tbProductSkus = tbProductSkuRepository.searchSku(product.getId().toString());
if (tbProductSkus.size() > 1) {
BigDecimal maxPrice = tbProductSkus.stream().map(TbProductSku::getSalePrice).max(BigDecimal::compareTo).get();
productNewVo.setLowPrice("" +productNewVo.getLowPrice() + "~¥" + maxPrice);
if ("sku".equals(product.getTypeEnum())){
if(tbProductSkus.size() > 1){
BigDecimal maxPrice = tbProductSkus.stream().map(TbProductSku::getSalePrice).max(BigDecimal::compareTo).get();
productNewVo.setLowPrice("" +productNewVo.getLowPrice() + "~¥" + maxPrice);
}else {
productNewVo.setLowPrice("" +productNewVo.getLowPrice());
}
}
ViewConSku viewConSku = new ViewConSku();
viewConSku.setShopId(Integer.valueOf(product.getShopId()));
@ -273,7 +277,7 @@ public class TbProductServiceImpl implements TbProductService {
}
}
}
productNewVo.setConInfos(CollectionUtils.isEmpty(skuCons)?Arrays.asList():skuCons);
productNewVo.setConInfos(CollectionUtils.isEmpty(skuCons)? Collections.emptyList() :skuCons);
products.add(productNewVo);
}
Map<String, Object> result = PageUtil.toPage(products, page.getTotalElements());
@ -433,10 +437,8 @@ public class TbProductServiceImpl implements TbProductService {
product.setStatus(1);
product.setCreatedAt(Instant.now().toEpochMilli());
product.setUpdatedAt(Instant.now().toEpochMilli());
if ("sku".equals(resources.getTypeEnum())) {
List<BigDecimal> collect = resources.getSkuList().stream().map(TbProductSku::getSalePrice).sorted().collect(Collectors.toList());
product.setLowPrice(collect.get(0));
}
List<BigDecimal> lowPrice = resources.getSkuList().stream().map(TbProductSku::getSalePrice).sorted().collect(Collectors.toList());
product.setLowPrice(lowPrice.get(0));
if ("group".equals(resources.getTypeEnum())) {
//套餐内容
if (!resources.getGroupSnap().isEmpty()) {
@ -505,13 +507,13 @@ public class TbProductServiceImpl implements TbProductService {
StringBuilder description = new StringBuilder("商品" + source.getName());
//上架 库存开关 设为推荐
if (resources.getIsHot().equals(source.getIsHot())) {
description.append((resources.getIsHot() == 0 ? ",已取消" : ",已设为") + "推荐");
description.append(resources.getIsHot() == 0 ? ",已取消" : ",已设为").append("推荐");
}
if (resources.getIsGrounding().equals(source.getIsGrounding())) {
description.append((resources.getIsGrounding() == 0 ? ",已取消" : ",已设为") + "上架");
description.append(resources.getIsGrounding() == 0 ? ",已取消" : ",已设为").append("上架");
}
if (resources.getIsStock().equals(source.getIsStock())) {
description.append((resources.getIsStock() == 0 ? ",已关闭" : ",已打开") + "库存开关");
description.append(resources.getIsStock() == 0 ? ",已关闭" : ",已打开").append("库存开关");
}
TbProduct product = new TbProduct();
//组装
@ -540,10 +542,8 @@ public class TbProductServiceImpl implements TbProductService {
product.setUpdatedAt(Instant.now().toEpochMilli());
product.setImages(resources.getImages().toString());
product.setStockNumber(resources.getStockNumber().intValue());
if ("sku".equals(resources.getTypeEnum())) {
List<BigDecimal> collect = resources.getSkuList().stream().map(TbProductSku::getSalePrice).sorted().collect(Collectors.toList());
product.setLowPrice(collect.get(0));
}
List<BigDecimal> lowPrices = resources.getSkuList().stream().map(TbProductSku::getSalePrice).sorted().collect(Collectors.toList());
product.setLowPrice(lowPrices.get(0));
if ("group".equals(resources.getTypeEnum())) {
//套餐内容
if (!resources.getGroupSnap().isEmpty()) {