|
@@ -0,0 +1,124 @@
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.annotation.ExcelProperty;
|
|
|
+import com.alibaba.excel.read.builder.ExcelReaderBuilder;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
+import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
+import com.sd.SdApplication;
|
|
|
+import com.sd.business.entity.bom.po.BomSpec;
|
|
|
+import com.sd.business.entity.in.po.InOutStorageDetails;
|
|
|
+import com.sd.business.entity.inventory.po.Inventory;
|
|
|
+import com.sd.business.entity.warehouse.po.Warehouse;
|
|
|
+import com.sd.business.service.bom.BomSpecService;
|
|
|
+import com.sd.business.service.in.InOutStorageDetailsService;
|
|
|
+import com.sd.business.service.inventory.InventoryService;
|
|
|
+import com.sd.business.service.warehouse.WarehouseService;
|
|
|
+import com.sd.framework.util.excel.listener.DataListener;
|
|
|
+import lombok.Getter;
|
|
|
+import lombok.Setter;
|
|
|
+import lombok.SneakyThrows;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
+
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
+@SpringBootTest(classes = SdApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
|
|
+public class C1_SyncInventoryTest {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WarehouseService warehouseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BomSpecService bomSpecService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InventoryService inventoryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InOutStorageDetailsService inOutStorageDetailsService;
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ @DSTransactional
|
|
|
+ @Test
|
|
|
+ public void test() {
|
|
|
+
|
|
|
+ DataListener<ExcelData> listener = new DataListener<>();
|
|
|
+
|
|
|
+ FileInputStream fileInputStream = new FileInputStream("E:\\库存表.xlsx");
|
|
|
+
|
|
|
+ ExcelReaderBuilder read = EasyExcel.read(fileInputStream, ExcelData.class, listener);
|
|
|
+ read.sheet(0).doRead();
|
|
|
+ List<ExcelData> list = listener.getDataList();
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Long> warehouseMap = warehouseService.mapKV(Warehouse::getName, BaseIdPo::getId, null);
|
|
|
+ Map<String, Long> bomSpecMap = bomSpecService.mapKV(BomSpec::getCode, BaseIdPo::getId, null);
|
|
|
+
|
|
|
+ List<Inventory> inventorieList = new ArrayList<>();
|
|
|
+ List<InOutStorageDetails> inOutStorageDetailsList = new ArrayList<>();
|
|
|
+ for (ExcelData excelData : list) {
|
|
|
+ String code = excelData.getCode();
|
|
|
+ Long bomSpecId = bomSpecMap.get(code);
|
|
|
+ if (bomSpecId == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String storageName = excelData.getStorageName();
|
|
|
+ if (storageName.equals("废料仓")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long warehouseId = warehouseMap.get(storageName);
|
|
|
+ if (warehouseId == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Inventory inventory = new Inventory();
|
|
|
+ inventory.setQuantity(excelData.getQuantity());
|
|
|
+ inventory.setBomSpecId(bomSpecId);
|
|
|
+ inventory.setDepartmentId(0L);
|
|
|
+ inventory.setWarehouseId(warehouseId);
|
|
|
+ inventory.setBalanceUnitPrice(excelData.getBalanceUnitPrice());
|
|
|
+ inventorieList.add(inventory);
|
|
|
+
|
|
|
+
|
|
|
+ InOutStorageDetails inOutStorageDetails = new InOutStorageDetails();
|
|
|
+ inOutStorageDetails.setQuantity(excelData.getQuantity());
|
|
|
+ inOutStorageDetails.setBomSpecId(bomSpecId);
|
|
|
+ inOutStorageDetails.setDepartmentId(0L);
|
|
|
+ inOutStorageDetails.setWarehouseId(warehouseId);
|
|
|
+ inOutStorageDetails.setInUnitPrice(excelData.getBalanceUnitPrice());
|
|
|
+ inOutStorageDetailsList.add(inOutStorageDetails);
|
|
|
+ }
|
|
|
+
|
|
|
+ inventoryService.saveBatch(inventorieList);
|
|
|
+ inOutStorageDetailsService.saveBatch(inOutStorageDetailsList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Getter
|
|
|
+ @Setter
|
|
|
+ public static final class ExcelData {
|
|
|
+
|
|
|
+ @ExcelProperty("品号")
|
|
|
+ private String code;
|
|
|
+
|
|
|
+ @ExcelProperty("仓库名称")
|
|
|
+ private String storageName;
|
|
|
+
|
|
|
+ @ExcelProperty("结存单价")
|
|
|
+ private BigDecimal balanceUnitPrice;
|
|
|
+
|
|
|
+ @ExcelProperty("库存数量")
|
|
|
+ private BigDecimal quantity;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|