|
@@ -0,0 +1,90 @@
|
|
|
+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.dto.CorrectionDto;
|
|
|
+import com.sd.business.entity.in.po.InOutStorageBom;
|
|
|
+import com.sd.business.service.bom.BomSpecService;
|
|
|
+import com.sd.business.service.inventory.InventoryService;
|
|
|
+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.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
+@SpringBootTest(classes = SdApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
|
|
+public class F1_SyncStorage {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InventoryService inventoryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BomSpecService bomSpecService;
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ @DSTransactional
|
|
|
+ @Test
|
|
|
+ public void test() {
|
|
|
+
|
|
|
+ DataListener<ExcelData> listener = new DataListener<>();
|
|
|
+
|
|
|
+ FileInputStream fileInputStream = new FileInputStream("E:\\9.25盘点.xlsx");
|
|
|
+
|
|
|
+ ExcelReaderBuilder read = EasyExcel.read(fileInputStream, ExcelData.class, listener);
|
|
|
+ read.sheet(0).doRead();
|
|
|
+ List<ExcelData> list = listener.getDataList();
|
|
|
+
|
|
|
+ List<String> codeList = list.stream().map(ExcelData::getCode).collect(Collectors.toList());
|
|
|
+ Map<String, Long> map = bomSpecService.mapKV(BomSpec::getCode, BaseIdPo::getId, q -> q.in(BomSpec::getCode, codeList));
|
|
|
+
|
|
|
+ List<InOutStorageBom> inOutStorageBomList = list.stream()
|
|
|
+ .map(item -> {
|
|
|
+ InOutStorageBom inOutStorageBom = new InOutStorageBom();
|
|
|
+ inOutStorageBom.setBomSpecId(map.get(item.getCode()));
|
|
|
+ inOutStorageBom.setQuantity(item.getQuantity());
|
|
|
+ return inOutStorageBom;
|
|
|
+ })
|
|
|
+ .filter(item -> Objects.nonNull(item.getBomSpecId()))
|
|
|
+ .filter(item -> Objects.nonNull(item.getQuantity()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ CorrectionDto correctionDto = new CorrectionDto();
|
|
|
+ correctionDto.setDepartmentId(0L);
|
|
|
+ correctionDto.setWarehouseId(1684037244354052098L);
|
|
|
+ correctionDto.setInOutStorageBomList(inOutStorageBomList);
|
|
|
+
|
|
|
+ inventoryService.correction(correctionDto);
|
|
|
+
|
|
|
+ System.out.println();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Getter
|
|
|
+ @Setter
|
|
|
+ public static final class ExcelData {
|
|
|
+
|
|
|
+ @ExcelProperty("品号")
|
|
|
+ private String code;
|
|
|
+
|
|
|
+ @ExcelProperty("现盘数量")
|
|
|
+ private BigDecimal quantity;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|