This commit is contained in:
wangw 2024-11-29 15:51:56 +08:00
parent 2830d1d948
commit 217a6ed82a
1 changed files with 14 additions and 4 deletions

View File

@ -53,6 +53,7 @@ import java.util.stream.Stream;
*/
@Slf4j
@Service
@Transactional
public class TbShopSyncInfoServiceImpl extends ServiceImpl<TbShopSyncInfoMapper, TbShopSyncInfo> implements TbShopSyncInfoService {
@ -208,7 +209,6 @@ public class TbShopSyncInfoServiceImpl extends ServiceImpl<TbShopSyncInfoMapper,
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public void clear(TbShopSyncInfo tbShopSyncInfo) {
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,
Map<Integer, Integer> specs, Map<Integer, Integer> cateGorys) {
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<>();
List<TbProduct> products = productRepository.findByShopId(sourceShopId.toString());
if(CollectionUtil.isNotEmpty(products)){
products.forEach(tbProduct -> {
for (TbProduct tbProduct : products) {
Integer sourceSpecId = tbProduct.getId();
tbProduct.setId(null);
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.setUnitId(tbProduct.getUnitId() != null ? units.get(tbProduct.getUnitId()) : null);
tbProduct.setStockNumber(0);
productRepository.save(tbProduct);
proMap.put(sourceSpecId, tbProduct.getId());
});
}
}
future.complete(proMap);
return future;