|
|
|
|
@ -3,14 +3,19 @@ package org.springblade.modules.business.service.impl.supplies; |
|
|
|
|
import com.aliyun.oss.ServiceException; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import org.springblade.core.mp.base.BaseEntity; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springblade.core.tool.utils.BeanUtil; |
|
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.supplies.Goods; |
|
|
|
|
import org.springblade.modules.business.excel.supplies.GoodsExcel; |
|
|
|
|
import org.springblade.modules.business.mapper.GoodsMapper; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.supplies.GoodsDetail; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.supplies.WareHouse; |
|
|
|
|
import org.springblade.modules.business.service.supplies.IGoodsDetailService; |
|
|
|
|
import org.springblade.modules.business.service.supplies.IGoodsService; |
|
|
|
|
import org.springblade.modules.business.pojo.vo.supplies.GoodsVO; |
|
|
|
|
import org.springblade.modules.business.service.supplies.IWareHouseService; |
|
|
|
|
@ -30,6 +35,7 @@ import java.util.List; |
|
|
|
|
public class GoodsServiceImpl extends BaseServiceImpl<GoodsMapper, Goods> implements IGoodsService { |
|
|
|
|
|
|
|
|
|
private final IWareHouseService wareHouseService; |
|
|
|
|
private final IGoodsDetailService goodsDetailService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public IPage<GoodsVO> selectGoodsPage(IPage<GoodsVO> page, GoodsVO goods) { |
|
|
|
|
@ -48,13 +54,18 @@ public class GoodsServiceImpl extends BaseServiceImpl<GoodsMapper, Goods> implem |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void importGoods(List<GoodsExcel> data, Boolean isCovered) { |
|
|
|
|
List<Goods> list = new ArrayList<>(); |
|
|
|
|
List<Goods> insertList = new ArrayList<>(); |
|
|
|
|
List<Goods> updateList = new ArrayList<>(); |
|
|
|
|
List<GoodsDetail> insertDetailList = new ArrayList<>(); |
|
|
|
|
// 获取仓库数据
|
|
|
|
|
List<WareHouse> wareHouses = wareHouseService.list(); |
|
|
|
|
// 遍历保存
|
|
|
|
|
data.forEach(goodsExcel -> { |
|
|
|
|
Goods goods = BeanUtil.copyProperties(goodsExcel, Goods.class); |
|
|
|
|
if (goods != null) { |
|
|
|
|
if (StringUtils.isEmpty(goods.getInventoryId())) { |
|
|
|
|
throw new ServiceException("物品【" + goods.getName() + "】未填写库存ID,请修改后再上传!"); |
|
|
|
|
} |
|
|
|
|
// 查询符合仓库名称的数据,没有则抛异常
|
|
|
|
|
List<WareHouse> houseList = wareHouses.stream().filter(wareHouse -> wareHouse.getName().equals(goods.getWarehouseName())).toList(); |
|
|
|
|
if (CollectionUtil.isEmpty(houseList)) { |
|
|
|
|
@ -63,14 +74,33 @@ public class GoodsServiceImpl extends BaseServiceImpl<GoodsMapper, Goods> implem |
|
|
|
|
goods.setWarehouseId(houseList.get(0).getId()); |
|
|
|
|
// 是否已停产
|
|
|
|
|
goods.setDeactivate("是".equals(goodsExcel.getDeactivate()) ? 1 : 0); |
|
|
|
|
list.add(goods); |
|
|
|
|
//根据inventoryId查询是否已存在
|
|
|
|
|
Goods oldGoods = baseMapper.selectOne(Wrappers.lambdaQuery(Goods.class).eq(Goods::getInventoryId,goods.getInventoryId()).eq(BaseEntity::getIsDeleted,0)); |
|
|
|
|
if(oldGoods != null){ |
|
|
|
|
goods.setId(oldGoods.getId()); |
|
|
|
|
goods.setNum(goods.getNum() + oldGoods.getNum()); |
|
|
|
|
goods.setAllEnterNum(goods.getNum() + oldGoods.getAllEnterNum()); |
|
|
|
|
updateList.add(goods); |
|
|
|
|
}else{ |
|
|
|
|
goods.setAllEnterNum(goods.getNum()); |
|
|
|
|
insertList.add(goods); |
|
|
|
|
} |
|
|
|
|
GoodsDetail goodsDetail = BeanUtil.copyProperties(goods,GoodsDetail.class); |
|
|
|
|
goodsDetail.setId(null); |
|
|
|
|
goodsDetail.setEnterNum(goods.getNum()); |
|
|
|
|
insertDetailList.add(goodsDetail); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
if (isCovered) { |
|
|
|
|
this.saveOrUpdateBatch(list); |
|
|
|
|
} else { |
|
|
|
|
this.saveBatch(list); |
|
|
|
|
if(CollectionUtil.isNotEmpty(updateList)){ |
|
|
|
|
this.updateBatchById(updateList); |
|
|
|
|
} |
|
|
|
|
if(CollectionUtil.isNotEmpty(insertList)){ |
|
|
|
|
this.saveBatch(insertList); |
|
|
|
|
} |
|
|
|
|
if(CollectionUtil.isNotEmpty(insertDetailList)){ |
|
|
|
|
goodsDetailService.saveBatch(insertDetailList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|