|
@@ -35,6 +35,7 @@ import com.ym.mec.util.excel.POIUtil;
|
|
|
import com.ym.mec.util.ini.IniFileUtil;
|
|
|
import com.ym.mec.util.upload.UploadUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang.math.NumberUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.PictureData;
|
|
@@ -47,7 +48,6 @@ import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Isolation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -1512,4 +1512,36 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
return new HashMap<>();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void copyGoods(Integer goodsId) {
|
|
|
+ List<GoodsSub> goodsSubs = goodsSubService.lambdaQuery().eq(GoodsSub::getGoodsId, goodsId).list();
|
|
|
+ Goods goods = goodsDao.get(goodsId);
|
|
|
+ if (goods == null) {
|
|
|
+ throw new BizException("商品不存在");
|
|
|
+ }
|
|
|
+ Date now = new Date();
|
|
|
+ if(goods.getName().contains("-副本")){
|
|
|
+ //截取副本后的数字
|
|
|
+ String copyNum = goods.getName().substring(goods.getName().lastIndexOf("-副本") + 3);
|
|
|
+ if(NumberUtils.isNumber(copyNum)){
|
|
|
+ goods.setName(goods.getName().replace("-副本"+copyNum,"")+"-副本"+(Integer.parseInt(copyNum)+1));
|
|
|
+ }else{
|
|
|
+ goods.setName(goods.getName()+"-副本1");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ goods.setId(null);
|
|
|
+ goods.setStatus(YesOrNoEnum.NO);
|
|
|
+ goods.setCreateTime(now);
|
|
|
+ goods.setUpdateTime(now);
|
|
|
+ goodsDao.insert(goods);
|
|
|
+ if(CollectionUtils.isNotEmpty(goodsSubs)){
|
|
|
+ List<GoodsSub> newGoodsSubs = goodsSubs.stream().peek(goodsSub -> {
|
|
|
+ goodsSub.setId(null);
|
|
|
+ goodsSub.setGoodsId(goods.getId());
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ goodsSubService.saveBatch(newGoodsSubs);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|