Explorar el Código

feat:库存查询接口

luobo hace 5 días
padre
commit
f6b0ae1f0a

+ 47 - 0
easydo-mes/src/main/java/easydo/technology/controller/WarehouseMaterialController.java

@@ -0,0 +1,47 @@
+package easydo.technology.controller;
+
+import easydo.technology.service.WarehouseMaterialService;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/warehouseMaterial")
+public class WarehouseMaterialController {
+
+    @Resource
+    private WarehouseMaterialService warehouseMaterialService;
+
+    @PostMapping(value = "/getPage")
+    public Object getPage(@RequestBody(required = false) Map<String, Object> map) {
+        try {
+            if (map == null) {
+                map = new HashMap<>();
+            }
+            Map<String, Object> page = warehouseMaterialService.getPage(map);
+            return new ResponseEntity<>(page, HttpStatus.OK);
+        } catch (Exception e) {
+            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @PostMapping(value = "/getList")
+    public Object getList(@RequestBody(required = false) Map<String, Object> map) {
+        try {
+            if (map == null) {
+                map = new HashMap<>();
+            }
+            Object list = warehouseMaterialService.getList(map);
+            return new ResponseEntity<>(list, HttpStatus.OK);
+        } catch (Exception e) {
+            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+}

+ 10 - 0
easydo-mes/src/main/java/easydo/technology/service/WarehouseMaterialService.java

@@ -0,0 +1,10 @@
+package easydo.technology.service;
+
+import java.util.Map;
+
+public interface WarehouseMaterialService {
+
+    Map<String, Object> getPage(Map<String, Object> map) throws Exception;
+
+    Object getList(Map<String, Object> map) throws Exception;
+}

+ 90 - 0
easydo-mes/src/main/java/easydo/technology/service/impl/WarehouseMaterialServiceImpl.java

@@ -0,0 +1,90 @@
+package easydo.technology.service.impl;
+
+import easydo.technology.components.JdbcClient;
+import easydo.technology.model.ProductMaterial;
+import easydo.technology.model.WarehouseMaterial;
+import easydo.technology.service.WarehouseMaterialService;
+import easydo.technology.utils.MapUtil;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+@Service
+public class WarehouseMaterialServiceImpl implements WarehouseMaterialService {
+
+    @Resource
+    private JdbcClient jdbcClient;
+
+    @Resource
+    private DataSource dataSource;
+
+    @Override
+    public Map<String, Object> getPage(Map<String, Object> map) throws Exception {
+        Connection connection = dataSource.getConnection();
+        try {
+            Map<String, Object> page = jdbcClient.getJdbcPage(map, WarehouseMaterial.class, connection);
+            List<WarehouseMaterial> records = MapUtil.mapToList(page, WarehouseMaterial.class, "records");
+            List<Map<String, Object>> resultRecords = buildMaterialRecords(records, connection);
+            page.put("records", resultRecords);
+            return page;
+        } finally {
+            connection.close();
+        }
+    }
+
+    @Override
+    public Object getList(Map<String, Object> map) throws Exception {
+        Connection connection = dataSource.getConnection();
+        try {
+            List<WarehouseMaterial> list = jdbcClient.getJdbcList(map, WarehouseMaterial.class, connection);
+            return buildMaterialRecords(list, connection);
+        } finally {
+            connection.close();
+        }
+    }
+
+    private List<Map<String, Object>> buildMaterialRecords(List<WarehouseMaterial> records, Connection connection) throws Exception {
+        List<Map<String, Object>> resultRecords = new ArrayList<>();
+        if (records == null || records.isEmpty()) {
+            return resultRecords;
+        }
+
+        Set<String> materialCodes = new HashSet<>();
+        for (WarehouseMaterial record : records) {
+            if (record.getMaterialCode() != null && !record.getMaterialCode().trim().isEmpty()) {
+                materialCodes.add(record.getMaterialCode());
+            }
+        }
+
+        Map<String, ProductMaterial> materialMap = new HashMap<>();
+        if (!materialCodes.isEmpty()) {
+            Map<String, Object> materialMapParam = new HashMap<>();
+            materialMapParam.put("code_in", new ArrayList<>(materialCodes));
+            List<ProductMaterial> materials = jdbcClient.getJdbcList(materialMapParam, ProductMaterial.class, connection);
+            if (materials != null) {
+                for (ProductMaterial material : materials) {
+                    materialMap.put(material.getCode(), material);
+                }
+            }
+        }
+
+        for (WarehouseMaterial record : records) {
+            Map<String, Object> recordMap = MapUtil.objectToMap(record);
+            ProductMaterial material = materialMap.get(record.getMaterialCode());
+            recordMap.put("specification", material != null ? material.getSpecification() : "");
+            recordMap.put("materialName", material != null ? material.getName() : "");
+            recordMap.put("unit", material != null ? material.getUnit() : "");
+            resultRecords.add(recordMap);
+        }
+
+        return resultRecords;
+    }
+}