Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
commit
504fec5011
|
|
@ -4,7 +4,6 @@ import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.bean.copier.CopyOptions;
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.ysk.cashier.cons.domain.TbConsInfo;
|
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.domain.TbProskuCon;
|
||||||
import cn.ysk.cashier.cons.repository.TbConsInfoRepository;
|
import cn.ysk.cashier.cons.repository.TbConsInfoRepository;
|
||||||
import cn.ysk.cashier.cons.service.dto.ProskuInfo;
|
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.dto.TbProskuConQueryCriteria;
|
||||||
import cn.ysk.cashier.cons.service.mapstruct.TbProskuConMapper;
|
import cn.ysk.cashier.cons.service.mapstruct.TbProskuConMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -168,6 +167,10 @@ public class TbProskuConServiceImpl implements TbProskuConService {
|
||||||
tbProskuConRepository.deleteAllByProductId(resources.getProductId());
|
tbProskuConRepository.deleteAllByProductId(resources.getProductId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
List<TbProskuConDto> cons = resources.getCons();
|
||||||
|
if(hasIdentical(cons)){
|
||||||
|
throw new BadRequestException("添加失败,对应耗材存在多条关系");
|
||||||
|
}
|
||||||
List<TbProskuCon> newCons = new ArrayList<>();
|
List<TbProskuCon> newCons = new ArrayList<>();
|
||||||
TbProduct product = tbProductRepository.getById(resources.getProductId());
|
TbProduct product = tbProductRepository.getById(resources.getProductId());
|
||||||
if (Objects.isNull(product)) {
|
if (Objects.isNull(product)) {
|
||||||
|
|
@ -196,6 +199,9 @@ public class TbProskuConServiceImpl implements TbProskuConService {
|
||||||
if (ObjectUtil.isNull(tbConsInfo) || ObjectUtil.isNull(tbConsInfo.getId())) {
|
if (ObjectUtil.isNull(tbConsInfo) || ObjectUtil.isNull(tbConsInfo.getId())) {
|
||||||
throw new BadRequestException("对应的耗材信息不存在");
|
throw new BadRequestException("对应的耗材信息不存在");
|
||||||
}
|
}
|
||||||
|
if (resource.getSurplusStock().compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
throw new BadRequestException("耗材"+ tbConsInfo.getConName() +"使用数量不可小于等于 0");
|
||||||
|
}
|
||||||
TbProductSku sku = null;
|
TbProductSku sku = null;
|
||||||
if (resource.getProductSkuId() != 0) {
|
if (resource.getProductSkuId() != 0) {
|
||||||
sku = tbProductSkuRepository.findById(resource.getProductSkuId()).orElseGet(TbProductSku::new);
|
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
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(TbProskuCon resources) throws Exception {
|
public void update(TbProskuCon resources) throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -253,9 +253,13 @@ public class TbProductServiceImpl implements TbProductService {
|
||||||
productNewVo.setLowPrice(product.getLowPrice().toString());
|
productNewVo.setLowPrice(product.getLowPrice().toString());
|
||||||
productNewVo.setStockNumber(Double.valueOf(product.getStockNumber()));
|
productNewVo.setStockNumber(Double.valueOf(product.getStockNumber()));
|
||||||
List<TbProductSku> tbProductSkus = tbProductSkuRepository.searchSku(product.getId().toString());
|
List<TbProductSku> tbProductSkus = tbProductSkuRepository.searchSku(product.getId().toString());
|
||||||
if (tbProductSkus.size() > 1) {
|
if ("sku".equals(product.getTypeEnum())){
|
||||||
|
if(tbProductSkus.size() > 1){
|
||||||
BigDecimal maxPrice = tbProductSkus.stream().map(TbProductSku::getSalePrice).max(BigDecimal::compareTo).get();
|
BigDecimal maxPrice = tbProductSkus.stream().map(TbProductSku::getSalePrice).max(BigDecimal::compareTo).get();
|
||||||
productNewVo.setLowPrice("¥" +productNewVo.getLowPrice() + "~¥" + maxPrice);
|
productNewVo.setLowPrice("¥" +productNewVo.getLowPrice() + "~¥" + maxPrice);
|
||||||
|
}else {
|
||||||
|
productNewVo.setLowPrice("¥" +productNewVo.getLowPrice());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ViewConSku viewConSku = new ViewConSku();
|
ViewConSku viewConSku = new ViewConSku();
|
||||||
viewConSku.setShopId(Integer.valueOf(product.getShopId()));
|
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);
|
products.add(productNewVo);
|
||||||
}
|
}
|
||||||
Map<String, Object> result = PageUtil.toPage(products, page.getTotalElements());
|
Map<String, Object> result = PageUtil.toPage(products, page.getTotalElements());
|
||||||
|
|
@ -433,10 +437,8 @@ public class TbProductServiceImpl implements TbProductService {
|
||||||
product.setStatus(1);
|
product.setStatus(1);
|
||||||
product.setCreatedAt(Instant.now().toEpochMilli());
|
product.setCreatedAt(Instant.now().toEpochMilli());
|
||||||
product.setUpdatedAt(Instant.now().toEpochMilli());
|
product.setUpdatedAt(Instant.now().toEpochMilli());
|
||||||
if ("sku".equals(resources.getTypeEnum())) {
|
List<BigDecimal> lowPrice = resources.getSkuList().stream().map(TbProductSku::getSalePrice).sorted().collect(Collectors.toList());
|
||||||
List<BigDecimal> collect = resources.getSkuList().stream().map(TbProductSku::getSalePrice).sorted().collect(Collectors.toList());
|
product.setLowPrice(lowPrice.get(0));
|
||||||
product.setLowPrice(collect.get(0));
|
|
||||||
}
|
|
||||||
if ("group".equals(resources.getTypeEnum())) {
|
if ("group".equals(resources.getTypeEnum())) {
|
||||||
//套餐内容
|
//套餐内容
|
||||||
if (!resources.getGroupSnap().isEmpty()) {
|
if (!resources.getGroupSnap().isEmpty()) {
|
||||||
|
|
@ -505,13 +507,13 @@ public class TbProductServiceImpl implements TbProductService {
|
||||||
StringBuilder description = new StringBuilder("商品" + source.getName());
|
StringBuilder description = new StringBuilder("商品" + source.getName());
|
||||||
//上架 库存开关 设为推荐
|
//上架 库存开关 设为推荐
|
||||||
if (resources.getIsHot().equals(source.getIsHot())) {
|
if (resources.getIsHot().equals(source.getIsHot())) {
|
||||||
description.append((resources.getIsHot() == 0 ? ",已取消" : ",已设为") + "推荐");
|
description.append(resources.getIsHot() == 0 ? ",已取消" : ",已设为").append("推荐");
|
||||||
}
|
}
|
||||||
if (resources.getIsGrounding().equals(source.getIsGrounding())) {
|
if (resources.getIsGrounding().equals(source.getIsGrounding())) {
|
||||||
description.append((resources.getIsGrounding() == 0 ? ",已取消" : ",已设为") + "上架");
|
description.append(resources.getIsGrounding() == 0 ? ",已取消" : ",已设为").append("上架");
|
||||||
}
|
}
|
||||||
if (resources.getIsStock().equals(source.getIsStock())) {
|
if (resources.getIsStock().equals(source.getIsStock())) {
|
||||||
description.append((resources.getIsStock() == 0 ? ",已关闭" : ",已打开") + "库存开关");
|
description.append(resources.getIsStock() == 0 ? ",已关闭" : ",已打开").append("库存开关");
|
||||||
}
|
}
|
||||||
TbProduct product = new TbProduct();
|
TbProduct product = new TbProduct();
|
||||||
//组装
|
//组装
|
||||||
|
|
@ -540,10 +542,8 @@ public class TbProductServiceImpl implements TbProductService {
|
||||||
product.setUpdatedAt(Instant.now().toEpochMilli());
|
product.setUpdatedAt(Instant.now().toEpochMilli());
|
||||||
product.setImages(resources.getImages().toString());
|
product.setImages(resources.getImages().toString());
|
||||||
product.setStockNumber(resources.getStockNumber().intValue());
|
product.setStockNumber(resources.getStockNumber().intValue());
|
||||||
if ("sku".equals(resources.getTypeEnum())) {
|
List<BigDecimal> lowPrices = resources.getSkuList().stream().map(TbProductSku::getSalePrice).sorted().collect(Collectors.toList());
|
||||||
List<BigDecimal> collect = resources.getSkuList().stream().map(TbProductSku::getSalePrice).sorted().collect(Collectors.toList());
|
product.setLowPrice(lowPrices.get(0));
|
||||||
product.setLowPrice(collect.get(0));
|
|
||||||
}
|
|
||||||
if ("group".equals(resources.getTypeEnum())) {
|
if ("group".equals(resources.getTypeEnum())) {
|
||||||
//套餐内容
|
//套餐内容
|
||||||
if (!resources.getGroupSnap().isEmpty()) {
|
if (!resources.getGroupSnap().isEmpty()) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue