|
@@ -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;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|