This commit is contained in:
2024-11-29 15:51:56 +08:00
parent 2830d1d948
commit 217a6ed82a

View File

@@ -53,6 +53,7 @@ import java.util.stream.Stream;
*/ */
@Slf4j @Slf4j
@Service @Service
@Transactional
public class TbShopSyncInfoServiceImpl extends ServiceImpl<TbShopSyncInfoMapper, TbShopSyncInfo> implements TbShopSyncInfoService { public class TbShopSyncInfoServiceImpl extends ServiceImpl<TbShopSyncInfoMapper, TbShopSyncInfo> implements TbShopSyncInfoService {
@@ -208,7 +209,6 @@ public class TbShopSyncInfoServiceImpl extends ServiceImpl<TbShopSyncInfoMapper,
} }
} }
@Transactional(rollbackFor = Exception.class)
@Override @Override
public void clear(TbShopSyncInfo tbShopSyncInfo) { public void clear(TbShopSyncInfo tbShopSyncInfo) {
unitRepository.clearShopUnit(tbShopSyncInfo.getPointShopId().toString()); unitRepository.clearShopUnit(tbShopSyncInfo.getPointShopId().toString());
@@ -298,21 +298,31 @@ public class TbShopSyncInfoServiceImpl extends ServiceImpl<TbShopSyncInfoMapper,
public CompletableFuture<Map<Integer, Integer>> syncProduct(Integer sourceShopId, Integer pointShopId, Map<Integer, Integer> units, public CompletableFuture<Map<Integer, Integer>> syncProduct(Integer sourceShopId, Integer pointShopId, Map<Integer, Integer> units,
Map<Integer, Integer> specs, Map<Integer, Integer> cateGorys) { Map<Integer, Integer> specs, Map<Integer, Integer> cateGorys) {
CompletableFuture<Map<Integer, Integer>> future = new CompletableFuture<>(); CompletableFuture<Map<Integer, Integer>> future = new CompletableFuture<>();
String cateGory = "";
if(CollectionUtil.isNotEmpty(cateGorys)){
cateGory = cateGorys.get(cateGorys.keySet().stream().findFirst()).toString();
}
Map<Integer, Integer> proMap = new HashMap<>(); Map<Integer, Integer> proMap = new HashMap<>();
List<TbProduct> products = productRepository.findByShopId(sourceShopId.toString()); List<TbProduct> products = productRepository.findByShopId(sourceShopId.toString());
if(CollectionUtil.isNotEmpty(products)){ if(CollectionUtil.isNotEmpty(products)){
products.forEach(tbProduct -> { for (TbProduct tbProduct : products) {
Integer sourceSpecId = tbProduct.getId(); Integer sourceSpecId = tbProduct.getId();
tbProduct.setId(null); tbProduct.setId(null);
tbProduct.setShopId(pointShopId.toString()); tbProduct.setShopId(pointShopId.toString());
tbProduct.setCategoryId(StringUtils.isNotBlank(tbProduct.getCategoryId()) ? cateGorys.get(Integer.valueOf(tbProduct.getCategoryId())).toString() : ""); if(cateGorys.containsKey(Integer.valueOf(tbProduct.getCategoryId()))){
tbProduct.setCategoryId(StringUtils.isNotBlank(tbProduct.getCategoryId()) ? cateGorys.get(Integer.valueOf(tbProduct.getCategoryId())).toString() : "");
}else {
tbProduct.setCategoryId(cateGory);
}
tbProduct.setSpecId(tbProduct.getSpecId() != null ? specs.get(tbProduct.getSpecId()) : null); tbProduct.setSpecId(tbProduct.getSpecId() != null ? specs.get(tbProduct.getSpecId()) : null);
tbProduct.setUnitId(tbProduct.getUnitId() != null ? units.get(tbProduct.getUnitId()) : null); tbProduct.setUnitId(tbProduct.getUnitId() != null ? units.get(tbProduct.getUnitId()) : null);
tbProduct.setStockNumber(0); tbProduct.setStockNumber(0);
productRepository.save(tbProduct); productRepository.save(tbProduct);
proMap.put(sourceSpecId, tbProduct.getId()); proMap.put(sourceSpecId, tbProduct.getId());
}); }
} }
future.complete(proMap); future.complete(proMap);
return future; return future;