Browse Source

问题修改

xiaochen 2 years atrás
parent
commit
380ed3a652

+ 25 - 3
src/main/java/com/tld/controller/QueryListController.java

@@ -3,10 +3,9 @@ package com.tld.controller;
 import com.tld.model.Inventory;
 import com.tld.service.QueryListService;
 import lombok.RequiredArgsConstructor;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.Map;
 
 /**
@@ -40,5 +39,28 @@ public class QueryListController {
     public Map<String, Object> reserveWarning(String wllbCode, int page, int limit){
         return queryListService.reserveWarning(wllbCode, page, limit);
     }
+
+
+    /**
+     * 查询库存信息
+     * @param inventory 参数
+     * @return 返回结果
+     */
+    @GetMapping("storageLocation")
+    public Map<String, Object> storageLocation(Inventory inventory){
+        return queryListService.storageLocation(inventory);
+    }
+
+    /**
+     * 导出查询库存信息
+     * @param inventory 参数
+     * @return 返回结果
+     */
+    @GetMapping("exportStorageLocation")
+    public void exportStorageLocation(Inventory inventory,HttpServletResponse response){
+        queryListService.exportStorageLocation(inventory,response);
+    }
+
+
 }
 

+ 6 - 0
src/main/java/com/tld/mapper/QueryListMapper.java

@@ -2,6 +2,7 @@ package com.tld.mapper;
 
 import com.tld.model.Inventory;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 import java.util.Map;
@@ -13,4 +14,9 @@ public interface QueryListMapper {
     Map<String, Object> reserveWarning(Map<String, Object> map);
 
     List<Map<String, Object>> getMaterial(String wllbCode);
+
+    List<Map<String, Object>> storageLocation(Inventory inventory);
+
+    List<Map<String, Object>> getStorageLocation(Inventory inventory);
+
 }

+ 6 - 0
src/main/java/com/tld/service/QueryListService.java

@@ -2,10 +2,16 @@ package com.tld.service;
 
 import com.tld.model.Inventory;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.Map;
 
 public interface QueryListService {
     Map<String, Object> dullGoods(Inventory inventory);
 
     Map<String, Object> reserveWarning(String wllbCode, int page, int limit);
+
+    Map<String, Object> storageLocation(Inventory inventory);
+
+    void exportStorageLocation(Inventory inventory, HttpServletResponse response);
+
 }

+ 47 - 4
src/main/java/com/tld/service/impl/QueryListServiceImpl.java

@@ -2,6 +2,7 @@ package com.tld.service.impl;
 
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.tld.excel.ExcelUtils;
 import com.tld.mapper.QueryListMapper;
 import com.tld.model.Inventory;
 import com.tld.model.Notice;
@@ -9,10 +10,9 @@ import com.tld.service.QueryListService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
+import javax.servlet.http.HttpServletResponse;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 @Service
 @RequiredArgsConstructor
@@ -62,4 +62,47 @@ public class QueryListServiceImpl implements QueryListService {
         }
         return map;
     }
+
+    @Override
+    public Map<String, Object> storageLocation(Inventory inventory) {
+        Map<String, Object> map = new HashMap<>();
+        try{
+            PageHelper.startPage(inventory.getPage(), inventory.getLimit());
+            PageInfo<Map<String, Object>> list = new PageInfo<>(queryListMapper.storageLocation(inventory));
+            map.put("data", list);
+            map.put("msg", "200");
+        } catch (Exception e){
+            e.printStackTrace();
+            map.put("msg", "500");
+            map.put("errMsg", "服务器请求异常,请稍后再试");
+        }
+        return map;
+    }
+
+    @Override
+    public void exportStorageLocation(Inventory inventory, HttpServletResponse response) {
+        try{
+            //导出数据汇总
+            List<List<Object>> sheetDataList = new ArrayList<>();
+            //表头数据
+            List<Object> head = Arrays.asList("物料code", "物料名称", "库位名称", "数量");
+            //查询数据
+            PageHelper.startPage(inventory.getPage(), inventory.getLimit());
+            PageInfo<Map<String, Object>> list = new PageInfo<>(queryListMapper.getStorageLocation(inventory));
+            sheetDataList.add(head);
+            for(Map<String, Object> userMap : list.getList()){
+                List<Object> listSheet = new ArrayList<>();
+                for(String key: userMap.keySet()){
+                    listSheet.add(userMap.get(key));
+                }
+                sheetDataList.add(listSheet);
+            }
+            //当前时间
+            Date time = new Date();
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMddHHmmss");
+            ExcelUtils.export(response, "入库流水数据导出" + sdf.format(time), sheetDataList);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
 }

+ 53 - 0
src/main/resources/mapper/QueryListMappeer.xml

@@ -50,4 +50,57 @@
         LEFT JOIN tld_material b ON a.material_id = b.tld_id
         WHERE material_id = #{tldId}
     </select>
+    <!-- 查询库位信息 -->
+    <select id="storageLocation" resultType="java.util.Map">
+        SELECT
+            a.storage_location_code as storageLocationCode,
+            a.material_id as materialId,
+            sum( a.amount ) AS sum,
+            b.storage_location_name as storageLocationName ,
+            b.warehouse_where as warehouseWhere,
+            b.storage_location_type as storageLocationType,
+            b.storage_location_capacity as storageLocationCapacity,
+            b.is_not_disable as isNotDisable,
+            b.create_time as createTime,
+            b.is_product as isProduct,
+            c.name as name,
+            c.code as code
+        FROM
+            tld_inventory a
+            LEFT JOIN tld_storage_location b ON a.storage_location_code = b.storage_location_code
+            LEFT JOIN tld_material c ON a.material_id = c.tld_id
+        <trim prefix="WHERE" prefixOverrides="and |or">
+            <if test="storageLocationCode != null and storageLocationCode != ''">
+                and a.storage_location_code = #{storageLocationCode}
+            </if>
+            <if test="materialId != null and materialId != ''">
+                and a.material_id = #{materialId}
+            </if>
+        </trim>
+        GROUP BY
+            a.storage_location_code,
+            a.material_id
+    </select>
+    <select id="getStorageLocation" resultType="java.util.LinkedHashMap">
+        SELECT
+            c.code as code,
+            c.name as name,
+            b.storage_location_name as storageLocationName ,
+            sum( a.amount ) AS sum
+        FROM
+            tld_inventory a
+            LEFT JOIN tld_storage_location b ON a.storage_location_code = b.storage_location_code
+            LEFT JOIN tld_material c ON a.material_id = c.tld_id
+        <trim prefix="WHERE" prefixOverrides="and |or">
+            <if test="storageLocationCode != null and storageLocationCode != ''">
+                and a.storage_location_code = #{storageLocationCode}
+            </if>
+            <if test="materialId != null and materialId != ''">
+                and a.material_id = #{materialId}
+            </if>
+        </trim>
+        GROUP BY
+        a.storage_location_code,
+        a.material_id
+    </select>
 </mapper>

+ 1 - 1
src/main/resources/mapper/StorageLocationMapper.xml

@@ -114,7 +114,7 @@
                 and id = #{id}
             </if>
         </trim>
-        order by a.id desc
+        order by id desc
     </select>
     <!-- 查询编号是否存在 -->
     <select id="getStorageCount" resultType="int">