Commit c5cf65cf authored by wanglianghe's avatar wanglianghe

价格更新fix

parent 39857ba5
......@@ -59,6 +59,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.TimeUnit;
......@@ -586,7 +587,7 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
Map<Long, List<ProductPriceStepDO>> dbStepMap = dbStepList.stream()
.collect(Collectors.groupingBy(ProductPriceStepDO::getProductPriceId));
List<ProductPriceStepDO> insertList = new ArrayList<>();
List<ProductPriceStepDO> insertList1 = new ArrayList<>();
List<ProductPriceStepDO> updateList = new ArrayList<>();
for (Long productPriceId : productPriceIdList) {
String transportType = priceTransportTypeMap.get(productPriceId);
......@@ -599,13 +600,11 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
dbItem.setId(null);
dbItem.setProductPriceId(productPriceId);
initBasePrice(dbItem, transportType);
insertList.add(dbItem);
insertList1.add(dbItem);
}
} else {
//更新
for (ProductPriceStepDO stepItem : stepList) {
if(stepItem.getTransportPrice() == null && stepItem.getClearancePrice() == null
&& stepItem.getAllPrice() == null) continue;
boolean update = false;
for (ProductPriceStepDO dbStepItem : dbPriceStepList) {
if(!stepItem.getPriceType().equals(dbStepItem.getPriceType())) continue;
......@@ -616,6 +615,11 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
}
//更新
update = true;
dbStepItem.setSpecialList(stepItem.getSpecialList());
dbStepItem.setPackagingList(stepItem.getPackagingList());
updateList.add(dbStepItem);
if(stepItem.getTransportPrice() == null && stepItem.getClearancePrice() == null
&& stepItem.getAllPrice() == null) continue;
if(stepItem.getTransportPrice() != null) {
dbStepItem.setTransportPrice(stepItem.getTransportPrice());
}
......@@ -649,9 +653,6 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
if(stepItem.getRankNum() != null) {
dbStepItem.setRankNum(stepItem.getRankNum());
}
dbStepItem.setSpecialList(stepItem.getSpecialList());
dbStepItem.setPackagingList(stepItem.getPackagingList());
updateList.add(dbStepItem);
break;
}
if(!update) {
......@@ -659,13 +660,13 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
dbItem.setId(null);
dbItem.setProductPriceId(productPriceId);
initBasePrice(dbItem, transportType);
insertList.add(dbItem);
insertList1.add(dbItem);
}
}
}
}
if(CollectionUtil.isNotEmpty(insertList)) {
productPriceStepMapper.insertBatchSomeColumn(insertList);
if(CollectionUtil.isNotEmpty(insertList1)) {
productPriceStepMapper.insertBatchSomeColumn(insertList1);
}
if(CollectionUtil.isNotEmpty(updateList)) {
productPriceStepMapper.updateBatch(updateList);
......@@ -685,8 +686,9 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
}
}
insertList.addAll(updateList);
List<ProductPriceStepSpecialDO> allUpdateStepSpecialList = insertList.stream()
insertList1.addAll(updateList);
List<ProductPriceStepSpecialDO> allUpdateStepSpecialList = insertList1.stream()
.filter(step -> CollectionUtil.isNotEmpty(step.getSpecialList()))
.flatMap(step -> step.getSpecialList().stream())
.filter(stepSpecialDO -> stepSpecialDO.getTransportPrice() != null
|| stepSpecialDO.getClearancePrice() != null
......@@ -710,7 +712,7 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
List<ProductPriceStepSpecialDO> specialInsertList = new ArrayList<>();
List<ProductPriceStepSpecialDO> specialUpdateList = new ArrayList<>();
for (ProductPriceStepDO stepDO : insertList) {
for (ProductPriceStepDO stepDO : insertList1) {
String transportType = priceTransportTypeMap.get(stepDO.getProductPriceId());
List<ProductPriceStepSpecialDO> productPriceStepSpecialDOS = stepDO.getSpecialList();
//过滤掉价格为空的数据
......@@ -778,7 +780,7 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
productPriceStepSpecialMapper.updateBatch(specialUpdateList);
}
List<ProductPriceStepPackagingDO> stepPackagingList = stepList.stream()
List<ProductPriceStepPackagingDO> stepPackagingList = insertList1.stream()
.map(ProductPriceStepDO::getPackagingList)
.filter(CollectionUtil::isNotEmpty)
.flatMap(List::stream)
......@@ -804,7 +806,9 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
List<ProductPriceStepPackagingDO> packagingInsertList = new ArrayList<>();
List<ProductPriceStepPackagingDO> packagingUpdateList = new ArrayList<>();
for (ProductPriceStepDO priceStepDO : insertList) {
List<ProductPriceStepPackagingDO> packagingDeleteListList = new ArrayList<>();
for (ProductPriceStepDO priceStepDO : insertList1) {
List<ProductPriceStepPackagingDO> productPriceStepPackagingDOS = priceStepDO.getPackagingList();
if(CollectionUtil.isNotEmpty(productPriceStepPackagingDOS)) {
productPriceStepPackagingDOS = productPriceStepPackagingDOS.stream()
......@@ -826,26 +830,36 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
}
} else {
for (int i = 0; i < productPriceStepPackagingDOS.size(); i++) {
boolean update = false;
ProductPriceStepPackagingDO m = productPriceStepPackagingDOS.get(i);
for (ProductPriceStepPackagingDO dbStepPacking : dbStepPackagingList) {
update = checkPackageEquals(m, dbStepPacking);
if(update) {
dbStepPacking.setPackagingPrice(m.getPackagingPrice());
dbStepPacking.setPackagingPriceUnit(m.getPackagingPriceUnit());
dbStepPacking.setPackagingVolumeUnit(m.getPackagingVolumeUnit());
packagingUpdateList.add(dbStepPacking);
break;
}
}
if(!update) {
ProductPriceStepPackagingDO dbItem = ObjectUtil.clone(m);
ProductPriceStepPackagingDO item = productPriceStepPackagingDOS.get(i);
String addPricePackagingTypes = item.getPackagingTypes();
if(StringUtils.isBlank(addPricePackagingTypes)) continue;
Long addPricePackagingPriceUnit = item.getPackagingPriceUnit();
if(addPricePackagingPriceUnit == null) continue;
Long addPricePackagingVolumeUnit = item.getPackagingVolumeUnit();
if(addPricePackagingVolumeUnit == null) continue;
Set<String> addPriceTypeSets = new HashSet<>(Arrays.asList(addPricePackagingTypes.split(",")));
//新增BC
ProductPriceStepPackagingDO dbItem = ObjectUtil.clone(item);
dbItem.setId(null);
dbItem.setProductPriceId(priceStepDO.getProductPriceId());
dbItem.setProductPriceStepId(priceStepDO.getId());
dbItem.setRankNum(i + 1);
dbItem.setDeleted(false);
packagingInsertList.add(dbItem);
if(!batchUpdate) continue;
for (ProductPriceStepPackagingDO dbStepPacking : dbStepPackagingList) {
Set<String> dbPriceTypeSets = new HashSet<>(Arrays.asList(dbStepPacking.getPackagingTypes().split(",")));
dbPriceTypeSets.removeAll(addPriceTypeSets);
if(dbPriceTypeSets.isEmpty()) {
packagingDeleteListList.add(dbStepPacking);
} else {
dbStepPacking.setPackagingTypes(Joiner.on(",").join(dbPriceTypeSets));
dbStepPacking.setPackagingPriceUnit(item.getPackagingPriceUnit());
dbStepPacking.setPackagingVolumeUnit(item.getPackagingVolumeUnit());
packagingUpdateList.add(dbStepPacking);
}
}
}
}
......@@ -858,6 +872,12 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
if(CollectionUtil.isNotEmpty(packagingUpdateList)) {
productPriceStepPackagingMapper.updateBatch(packagingUpdateList);
}
if(CollectionUtil.isNotEmpty(packagingDeleteListList)) {
List<Long> dIdList = packagingDeleteListList.stream()
.map(BasePackagingPrice::getId)
.collect(toList());
productPriceStepPackagingMapper.deleteBatchIds(dIdList);
}
if(!batchUpdate) {
List<Long> updateIdList = packagingUpdateList.stream()
.map(ProductPriceStepPackagingDO::getId)
......@@ -1019,6 +1039,7 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
List<ProductPricePackagingDO> insertList = new ArrayList<>();
List<ProductPricePackagingDO> updateList = new ArrayList<>();
List<ProductPricePackagingDO> deleteList = new ArrayList<>();
Collection<Integer> priceTypes = packagingDOList.stream()
.map(ProductPricePackagingDO::getPriceType)
......@@ -1050,29 +1071,38 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
//更新
int i = 0;
for (ProductPricePackagingDO item : packagingDOList) {
boolean exist = false;
String addPricePackagingTypes = item.getPackagingTypes();
if(StringUtils.isBlank(addPricePackagingTypes)) continue;
Long addPricePackagingPriceUnit = item.getPackagingPriceUnit();
if(addPricePackagingPriceUnit == null) continue;
Long addPricePackagingVolumeUnit = item.getPackagingVolumeUnit();
if(addPricePackagingVolumeUnit == null) continue;
i++;
Set<String> addPriceTypeSets = new HashSet<>(Arrays.asList(addPricePackagingTypes.split(",")));
ProductPricePackagingDO dbItem = ObjectUtil.clone(item);
dbItem.setId(null);
dbItem.setRankNum(i + 1);
dbItem.setProductPriceId(productPriceId);
initBasePackagingPrice(dbItem, transportType);
insertList.add(dbItem);
if(!batchUpdate) continue;
for (ProductPricePackagingDO dbPackagingItem : dbPackagingDOList) {
boolean stepPackagingUpdate = checkPackageEquals(item, dbPackagingItem);
if(stepPackagingUpdate) {
exist = true;
dbPackagingItem.setPackagingPrice(item.getPackagingPrice());
if(!item.getPriceType().equals(dbPackagingItem.getPriceType())) continue;
Set<String> dbPriceTypeSets = new HashSet<>(Arrays.asList(dbPackagingItem.getPackagingTypes().split(",")));
dbPriceTypeSets.removeAll(addPriceTypeSets);
if(dbPriceTypeSets.isEmpty()) {
deleteList.add(dbPackagingItem);
} else {
dbPackagingItem.setPackagingTypes(Joiner.on(",").join(dbPriceTypeSets));
dbPackagingItem.setPackagingPriceUnit(item.getPackagingPriceUnit());
dbPackagingItem.setPackagingVolumeUnit(item.getPackagingVolumeUnit());
if(item.getPriceType() != null) {
dbPackagingItem.setPriceType(item.getPriceType());
}
updateList.add(dbPackagingItem);
break;
}
}
if(!exist) {
ProductPricePackagingDO dbItem = ObjectUtil.clone(item);
dbItem.setId(null);
dbItem.setRankNum(i + 1);
dbItem.setProductPriceId(productPriceId);
initBasePackagingPrice(dbItem, transportType);
insertList.add(dbItem);
}
}
}
......@@ -1084,6 +1114,12 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
if(CollectionUtil.isNotEmpty(updateList)) {
productPricePackagingMapper.updateBatch(updateList);
}
if(CollectionUtil.isNotEmpty(deleteList)) {
List<Long> dIdList = deleteList.stream()
.map(BasePackagingPrice::getId)
.collect(toList());
productPricePackagingMapper.deleteBatchIds(dIdList);
}
if(!batchUpdate) {
List<Long> dbIdList = dbPackagingList.stream()
......@@ -2646,7 +2682,7 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
for (ProductPricePackagingDO addPricePackaging : packagingList) {
Integer priceType = addPricePackaging.getPriceType();
if(priceType == null) continue;
boolean update = checkPackageAddPrice(addPricePackaging, dbPackaging);
boolean update = checkPackageAddPrice(addPricePackaging, dbPackaging) && priceType.equals(dbPackaging.getPriceType());
if(update) {
BigDecimal price = dbPackaging.getPackagingPrice();
price = price.add(addPricePackaging.getPackagingPrice());
......@@ -2816,11 +2852,11 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
private void checkStepPrice(List<ProductPriceStepDO> priceStepList, PriceTypeEnum priceTypeEnum) {
if (CollectionUtil.isNotEmpty(priceStepList)) {
priceStepList = priceStepList.stream()
.filter(t -> t.getTransportPrice() != null ||
t.getClearancePrice() != null ||
t.getAllPrice() != null)
.collect(Collectors.toList());
// priceStepList = priceStepList.stream()
// .filter(t -> t.getTransportPrice() != null ||
// t.getClearancePrice() != null ||
// t.getAllPrice() != null)
// .collect(Collectors.toList());
for (ProductPriceStepDO item : priceStepList) {
if (item.getRankNum() == null) {
......@@ -2828,31 +2864,31 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
}
item.setPriceType(priceTypeEnum.getPriceType());
}
switch (priceTypeEnum) {
case FREIGHT:
for (ProductPriceStepDO item : priceStepList) {
if (item.getTransportPrice() == null) {
throw new ServiceException(500, "价格不能为空");
}
}
break;
case CLEARANCE:
for (ProductPriceStepDO item : priceStepList) {
if (item.getClearancePrice() == null) {
throw new ServiceException(500, "价格不能为空");
}
}
break;
case FULL_PRICE:
for (ProductPriceStepDO item : priceStepList) {
if (item.getAllPrice() == null) {
throw new ServiceException(500, "价格不能为空");
}
}
break;
}
// switch (priceTypeEnum) {
// case FREIGHT:
// for (ProductPriceStepDO item : priceStepList) {
// if (item.getTransportPrice() == null) {
// throw new ServiceException(500, "价格不能为空");
// }
// }
// break;
//
// case CLEARANCE:
// for (ProductPriceStepDO item : priceStepList) {
// if (item.getClearancePrice() == null) {
// throw new ServiceException(500, "价格不能为空");
// }
// }
// break;
//
// case FULL_PRICE:
// for (ProductPriceStepDO item : priceStepList) {
// if (item.getAllPrice() == null) {
// throw new ServiceException(500, "价格不能为空");
// }
// }
// break;
// }
}
}
......@@ -2868,21 +2904,27 @@ public class ProductPriceServiceImpl extends AbstractService<ProductPriceMapper,
ProductPriceStepDO stepDO = priceStepList.get(0);
switch (priceTypeEnum) {
case FREIGHT:
if(stepDO.getTransportPrice() != null) {
productPrice.setTransportPrice(stepDO.getTransportPrice());
productPrice.setTransportPriceUnit(stepDO.getTransportPriceUnit());
productPrice.setTransportVolumeUnit(stepDO.getTransportVolumeUnit());
}
break;
case CLEARANCE:
if(stepDO.getClearancePrice() != null) {
productPrice.setClearancePrice(stepDO.getClearancePrice());
productPrice.setClearancePriceUnit(stepDO.getClearancePriceUnit());
productPrice.setClearanceVolumeUnit(stepDO.getClearanceVolumeUnit());
}
break;
case FULL_PRICE:
if(stepDO.getAllPrice() != null) {
productPrice.setAllPrice(stepDO.getAllPrice());
productPrice.setAllPriceUnit(stepDO.getAllPriceUnit());
productPrice.setAllVolumeUnit(stepDO.getAllVolumeUnit());
}
break;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment