|
@@ -155,20 +155,38 @@ public class GoodsSnManagerImpl extends BaseServiceImpl<GoodsSnMapper, GoodsSnDO
|
|
|
|
|
|
@Override
|
|
|
public void createSnCode(GoodsSnDTO goodsDTO) {
|
|
|
- ProductDO byId = productManager.getById(goodsDTO.getProductId());
|
|
|
- if (ObjectUtil.isNull(byId)) {
|
|
|
- throw new ServiceException("sku不存在");
|
|
|
- }
|
|
|
- List<GoodsSnDO> list = new ArrayList<>();
|
|
|
- for (Integer num = goodsDTO.getNum(); num > 0; num--) {
|
|
|
- GoodsSnDO aDo = new GoodsSnDO();
|
|
|
- aDo.setGoodsId(byId.getGoodsId());
|
|
|
- aDo.setSku(byId.getSku());
|
|
|
- aDo.setProductId(goodsDTO.getProductId());
|
|
|
- aDo.setSnCode(byId.getSku().substring(0,3) + DateUtil.format(LocalDateTime.now(), "yyyyMMdd") + String.format("%04d", num));
|
|
|
- list.add(aDo);
|
|
|
+ synchronized (GoodsSnManagerImpl.class){
|
|
|
+ ProductDO byId = productManager.getById(goodsDTO.getProductId());
|
|
|
+ if (ObjectUtil.isNull(byId)) {
|
|
|
+ throw new ServiceException("sku不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ long count = count(new LambdaQueryWrapper<GoodsSnDO>().eq(GoodsSnDO::getProductId, goodsDTO.getProductId()));
|
|
|
+
|
|
|
+ List<GoodsSnDO> list = new ArrayList<>();
|
|
|
+ for(long num=count+1;num<=count+goodsDTO.getNum();num++) {
|
|
|
+ GoodsSnDO aDo = new GoodsSnDO();
|
|
|
+ aDo.setGoodsId(byId.getGoodsId());
|
|
|
+ aDo.setSku(byId.getSku());
|
|
|
+ aDo.setProductId(goodsDTO.getProductId());
|
|
|
+ aDo.setSnCode(byId.getSku().substring(0,3) + DateUtil.format(LocalDateTime.now(), "yyyyMMdd") + String.format("%04d", num));
|
|
|
+ list.add(aDo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// for (Integer num = goodsDTO.getNum(); num > 0; num--) {
|
|
|
+// GoodsSnDO aDo = new GoodsSnDO();
|
|
|
+// aDo.setGoodsId(byId.getGoodsId());
|
|
|
+// aDo.setSku(byId.getSku());
|
|
|
+// aDo.setProductId(goodsDTO.getProductId());
|
|
|
+// aDo.setSnCode(byId.getSku().substring(0,3) + DateUtil.format(LocalDateTime.now(), "yyyyMMdd") + String.format("%04d", num));
|
|
|
+// list.add(aDo);
|
|
|
+// }
|
|
|
+
|
|
|
+ saveBatch(list);
|
|
|
}
|
|
|
- saveBatch(list);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|