Browse Source

2.14收发存

zhouzh 3 years ago
parent
commit
f7aaf2f6b1

+ 2 - 2
src/main/java/com/steerinfo/dil/controller/WmsInboundResultController.java

@@ -197,7 +197,7 @@ public class WmsInboundResultController extends BaseRESTfulController {
                 for (int i=0;i<mapList.size();i++) {
 
                     Map<String, Object> item = mapList.get(i);
-                    //获取物资大类id
+/*                    //获取物资大类id
                     BigDecimal materialSteelId = DataChange.dataToBigDecimal(item.get("materialId"));
                     BigDecimal materialId = wmspSendReceiveService.getMaterialId(materialSteelId);
                     Map<String,Object> map4 = new HashMap<>();
@@ -205,7 +205,7 @@ public class WmsInboundResultController extends BaseRESTfulController {
                     map4.put("warehouseId",3);
                     wmspSendReceiveService.addInBoundSendReceive(map4);
                     wmspSendReceiveService.addThisdayInventorySendReceive(map4);
-                    //获得高线库
+                    //获得高线库*/
                     HashMap<String, Object> map3 = new HashMap<>();
                     map3.put("warehouseId",3);
                     BigDecimal houseGrid=rmsPwarehouseGridService.getGridId(map3);;

+ 25 - 24
src/main/java/com/steerinfo/dil/controller/WmspSendReceiveController.java

@@ -4,6 +4,7 @@ import com.steerinfo.dil.feign.ESFeign;
 import com.steerinfo.dil.service.impl.WmspSendReceiveServiceImpl;
 import com.steerinfo.dil.util.BaseRESTfulController;
 import com.steerinfo.dil.util.ColumnDataUtil;
+import com.steerinfo.dil.util.DataChange;
 import com.steerinfo.dil.util.PageListAdd;
 import com.steerinfo.framework.controller.RESTfulResult;
 import com.steerinfo.framework.service.pagehelper.PageHelper;
@@ -11,11 +12,13 @@ import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
 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 java.text.SimpleDateFormat;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -38,6 +41,10 @@ public class WmspSendReceiveController extends BaseRESTfulController {
     @Autowired
     WmspSendReceiveServiceImpl iWmspSendReceiveService;
 
+    private final SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
+
+    private final SimpleDateFormat sdfDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
     @PostMapping("/getSendReceive")
     @ApiOperation(value = "展示收发存报表信息")
     @ApiImplicitParams({
@@ -47,32 +54,19 @@ public class WmspSendReceiveController extends BaseRESTfulController {
                                            Integer apiId,
                                            Integer pageNum,
                                            Integer pageSize,
-                                           String  con
+                                           String  con,
+                                           String startTime,
+                                           String endTime
                                         ){
-        if(con != null){
-            if(!"undefined".equals(con)){
-                String index = "get_wms_SendReceive";
-                return success(esFeign.getConResult(mapValue,index,apiId,pageNum,pageSize,con));
-            }
-        }
-        List<Map<String,Object>>sendReceiveList = null;
-        if(mapValue.size() == 0){
-            //将查询结果存入索引中
-            sendReceiveList = iWmspSendReceiveService.getWmspSendReceiveService(mapValue);
-            Map<String, Object> sendReceiveMap = new HashMap<>();
-            //添加索引
-            sendReceiveMap.put("index","get_wms_SendReceive");
-            //添加ID
-            sendReceiveMap.put("indexId","sendReceivetId");
-            sendReceiveList.add(sendReceiveMap);
-            //新建索引
-            esFeign.insertIndex(sendReceiveList);
-            //删除
-            sendReceiveList.remove(sendReceiveList.size() -1);
+        if (con!=null&&!con.equals("undefined")){
+            mapValue.put("con","%"+con+"%");
         }
-        if(sendReceiveList == null) {
-            sendReceiveList =iWmspSendReceiveService.getWmspSendReceiveService(mapValue);
+        if(mapValue == null){
+            mapValue =new HashMap<>();
         }
+        DataChange.queryDataByDateTime(startTime, endTime, mapValue, sdfDateTime);//根据时间段查询数据
+        List<Map<String,Object>> sendReceiveList = iWmspSendReceiveService.getWmspSendReceiveService(mapValue);
+
         /*分页*/
         PageHelper.startPage(pageNum, pageSize);
         List<Map<String,Object>> columnList = iWmspSendReceiveService.getWmspSendReceiveService(mapValue);
@@ -80,8 +74,15 @@ public class WmspSendReceiveController extends BaseRESTfulController {
         return success(pageList);
     }
 
-    //初始化收发层
+   /* //初始化收发层
+    @PostMapping("addSendReceive")
+    public RESTfulResult addSendReceive(){
+        int result = iWmspSendReceiveService.addSendReceive();
+        return success(result);
+    }*/
+
     @PostMapping("addSendReceive")
+    @Scheduled(cron =  "0 0 0 * * ? ")
     public RESTfulResult addSendReceive(){
         int result = iWmspSendReceiveService.addSendReceive();
         return success(result);

+ 4 - 0
src/main/java/com/steerinfo/dil/mapper/WmspSendReceiveMapper.java

@@ -34,4 +34,8 @@ public interface WmspSendReceiveMapper extends IBaseMapper<WmspSendReceive, BigD
     BigDecimal getMaterialId(BigDecimal materialSteelId);
     //实时更改库存
     int updateSendReceiveThisdayInventory(Map<String,Object> map);
+    //统计前一天的入库总数
+    BigDecimal countSndReceiveThisdayInbound(Map<String, Object> map2);
+    //统计前一天的出库总数
+    BigDecimal countSendReceiveThisdayOutbound(Map<String, Object> map2);
 }

+ 2 - 3
src/main/java/com/steerinfo/dil/service/impl/WmspOutboundResultServiceImpl.java

@@ -12,7 +12,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -248,7 +247,7 @@ public class WmspOutboundResultServiceImpl  implements IWmspOutboundResultServic
 
             for(Map<String,Object> map:listMap) {
                 BigDecimal materialSteelId = DataChange.dataToBigDecimal(map.get("materialId"));
-                if(materialSteelId == null){
+         /*       if(materialSteelId == null){
                     return -1;
                 }
                 //根据物资钢材id查询仓库id和物资大类id
@@ -257,7 +256,7 @@ public class WmspOutboundResultServiceImpl  implements IWmspOutboundResultServic
                 map1.put("materialId",materialId);
                 map1.put("warehouseId",3);
                 wmspSendReceiveService.addOutBoundSendReceive(map1);
-                wmspSendReceiveService.addThisdayInventorySendReceive(map1);
+                wmspSendReceiveService.addThisdayInventorySendReceive(map1);*/
                 //将这些物资钢材id进行逻辑删除
                 i += wmspGridMaterialMapper.updateByMaterialId(materialSteelId);
             }

+ 62 - 2
src/main/java/com/steerinfo/dil/service/impl/WmspSendReceiveServiceImpl.java

@@ -8,7 +8,6 @@ import com.steerinfo.dil.model.WmspSendReceive;
 import com.steerinfo.dil.service.IWmspSendReceiveService;
 import com.steerinfo.dil.util.DataChange;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
@@ -52,7 +51,7 @@ public class WmspSendReceiveServiceImpl implements IWmspSendReceiveService {
         return wmspSendReceiveMapper.getMaterialId(materialSteelId);
     }
 
-    @Override
+   /* @Override
     //针对每一个仓库中的每一个物资类型新增一个收发层(初始化收发层)
     @Scheduled(cron =  "0 0 0 * * ? ")
     public int addSendReceive() {
@@ -131,8 +130,14 @@ public class WmspSendReceiveServiceImpl implements IWmspSendReceiveService {
         BigDecimal warehouseId = DataChange.dataToBigDecimal(map.get("warehouseId"));
         //今天入库
        BigDecimal sendReceiveThisdayInbound = wmspSendReceiveMapper.selectSendReceiveThisdayInbound(map);
+       if(sendReceiveThisdayInbound == null){
+           sendReceiveThisdayInbound = new BigDecimal(0);
+       }
        //今天出库
         BigDecimal sendReceiveThisdayOutbound = wmspSendReceiveMapper.selectSendReceiveThisdayOutbound(map);
+       if(sendReceiveThisdayOutbound == null){
+           sendReceiveThisdayOutbound = new BigDecimal(0);
+       }
        // 昨天库存
         BigDecimal sendReceiveLastdayInventory = wmspSendReceiveMapper.getSendReceiveLastdayInventory(map);
         if(sendReceiveLastdayInventory == null){
@@ -148,4 +153,59 @@ public class WmspSendReceiveServiceImpl implements IWmspSendReceiveService {
         return wmspSendReceiveMapper.updateSendReceiveThisdayInventory(map1);
 
     }
+*/
+    //零点生成前一天的入库、出库、库存
+    public int addSendReceive(){
+        WmspSendReceive wmspSendReceive = new WmspSendReceive();
+        int i = 0;
+        //高线库,一棒库,二棒库,配送库
+        List<Map<String, Object>> mapList = rmsWarehouseMapper.getWarehouseName();
+        //遍历四个仓库
+        for(Map<String,Object> map:mapList){
+            BigDecimal warehouseId = DataChange.dataToBigDecimal(map.get("id"));
+            //查询去重实时库存中的物资id
+            List<Map<String,Object>> materialIdList = wmspGridMaterialMapper.getMaterialId(warehouseId);
+            for(Map<String,Object> map1:materialIdList) {
+                //收发层主键自增
+                BigDecimal sendReceiveId = wmspSendReceiveMapper.getSendReceiveId();
+                wmspSendReceive.setSendReceiveId(sendReceiveId);
+                //仓库id
+                wmspSendReceive.setWarehouseId(warehouseId);
+                //收发层日期
+                wmspSendReceive.setSendReceiveDate(new Date());
+                //物资id
+                BigDecimal materialId = DataChange.dataToBigDecimal(map1.get("materialId"));
+                wmspSendReceive.setMaterialId(materialId);
+
+                Map<String,Object> map2 = new HashMap<>();
+                map2.put("warehouseId",warehouseId);
+                map2.put("materialId",materialId);
+                //统计前一天的入库总数
+                BigDecimal sendReceiveThisdayInbound = wmspSendReceiveMapper.countSndReceiveThisdayInbound(map2);
+                wmspSendReceive.setSendReceiveThisdayInbound(sendReceiveThisdayInbound);
+                //统计前一天的出库总数
+                BigDecimal sendReceiveThisdayOutbound = wmspSendReceiveMapper.countSendReceiveThisdayOutbound(map2);
+                wmspSendReceive.setSendReceiveThisdayOutbound(sendReceiveThisdayOutbound);
+                //昨天库存
+                BigDecimal sendReceiveLastdayInventory = wmspSendReceiveMapper.getSendReceiveLastdayInventory(map2);
+                if(sendReceiveLastdayInventory == null){
+                    wmspSendReceive.setSendReceiveLastdayInventory(new BigDecimal(0));
+                }else{
+                    wmspSendReceive.setSendReceiveLastdayInventory(sendReceiveLastdayInventory);
+                }
+                BigDecimal sendReceiveLastdayInventory1 = wmspSendReceive.getSendReceiveLastdayInventory();
+                //今天库存
+                BigDecimal sendReceiveThisdayInventory = new BigDecimal(sendReceiveLastdayInventory1.intValue()
+                                +sendReceiveThisdayInbound.intValue()-sendReceiveThisdayOutbound.intValue());
+
+                wmspSendReceive.setSendReceiveThisdayInventory(sendReceiveThisdayInventory);
+                wmspSendReceive.setInsertUsername("admin");
+                wmspSendReceive.setInsertTime(new Date());
+                wmspSendReceive.setDeleted(new BigDecimal(1));
+                i+=wmspSendReceiveMapper.insertSelective(wmspSendReceive);
+            }
+        }
+        return i;
+    }
+
 }

+ 96 - 19
src/main/java/com/steerinfo/dil/util/DataChange.java

@@ -40,23 +40,22 @@ public class DataChange {
      * @param data
      * @return
      */
-    public static BigDecimal
-    dataToBigDecimal(Object data){
+    public static BigDecimal dataToBigDecimal(Object data){
         if (data != null){
-            if(data instanceof String){
-                String data1 = (String) data;
-                return new BigDecimal(data1);
-            }
-            if(data instanceof Integer){
-                Integer data2 = (Integer) data;
-                return new BigDecimal(data2);
-            }
-            if(data instanceof Double){
-                Double data3 = (Double) data;
-                return new BigDecimal(data3);
-            }
             if(data instanceof BigDecimal){
                 return (BigDecimal) data;
+            }else{
+                String str = String.valueOf(data);
+                BigDecimal decimal = null;
+                if(!"".equals(str)){
+                    try {
+                        decimal = new BigDecimal(str);
+                    } catch (Exception e) {
+                        System.out.println(data + ":数据解析失败!返回0");
+                        return new BigDecimal(0);
+                    }
+                }
+                return decimal;
             }
         }
         return new BigDecimal(0);
@@ -70,8 +69,10 @@ public class DataChange {
     public static String dateToDayDate(Object date){
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         Date changeDate = null;
+        if(date == null)
+            return null;
         try{
-            changeDate = (Date) date;
+             changeDate = (Date) date;
         }catch (Exception e){
             e.printStackTrace();
         }
@@ -109,10 +110,15 @@ public class DataChange {
         for (Map<String, Object> map : list) {
             for (String s : key) {
                 //修改数据为带两位小数
-                BigDecimal oldDate = (BigDecimal) map.get(s);
-                DecimalFormat df =  new DecimalFormat("0.00");
-                String resultDeduction = df.format(oldDate.doubleValue());
-                map.put(s, resultDeduction);
+                try {
+                    BigDecimal oldDate = (BigDecimal) map.get(s);
+                    DecimalFormat df =  new DecimalFormat("0.00");
+                    String resultDeduction = df.format(oldDate.doubleValue());
+                    map.put(s, resultDeduction);
+                } catch (Exception e) {
+                    System.out.println("原料扣减量数据有误");
+                }
+
             }
         }
     }
@@ -159,4 +165,75 @@ public class DataChange {
         );
         return sb.toString();
     }
+
+    /**
+     * 根据时间段查询数据 支持只选择单个时间
+     * @Author TXF
+     * @Date 2022/1/10 23:21
+     * @param startTime
+     * @param endTime
+     * @param map
+     * @param sdf
+     * @return
+     **/
+    public static void queryDataByDate(String startTime, String endTime, Map<String, Object> map, SimpleDateFormat sdf){
+        if (startTime != null && !"null".equals(startTime) && endTime != null && !"null".equals(endTime)) {
+            map.put("startDate", sdf.format(new Date(Long.parseLong(startTime))));
+            map.put("endDate", sdf.format(new Date(Long.parseLong(endTime) + 86400000)));
+        } else if (startTime != null && !"null".equals(startTime)) {
+            map.put("oneDate", sdf.format(new Date(Long.parseLong(startTime))));
+        } else if (endTime != null && !"null".equals(endTime)) {
+            map.put("oneDate", sdf.format(new Date(Long.parseLong(endTime))));
+        } else {
+            map.put("oneDate", sdf.format(new Date()));
+        }
+    }
+
+    /**
+     * 只支持两个时间查询
+     * @Author TXF
+     * @Date 2022/1/15 9:08
+     * @param startTime
+     * @param endTime
+     * @param sdf
+     * @return
+     **/
+    public static void queryDataByDateTime(String startTime, String endTime, Map<String, Object> map,SimpleDateFormat sdf){
+        SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
+        if (startTime != null && !"null".equals(startTime) && endTime != null && !"null".equals(endTime)) {
+            map.put("startDate", sdf.format(new Date(Long.parseLong(startTime))));
+            map.put("endDate", sdf.format(new Date(Long.parseLong(endTime))));
+        }
+        //如果开始时间和结束时间有且只有一个为空 则只查那天的数据
+        else if((startTime != null && !"null".equals(startTime)) || (endTime != null && !"null".equals(endTime))){
+            if(startTime != null && !"null".equals(startTime)){
+                queryDataByTwoDateSon(map, startTime, sdfDate);
+            }
+            if(endTime != null && !"null".equals(endTime)){
+                queryDataByTwoDateSon(map, endTime, sdfDate);
+            }
+        }else {
+            //如果两者时间都为空,则查询当天数据
+            String nowDate = sdfDate.format(new Date());
+            map.put("oneDate", nowDate + " 00:00:00");
+        }
+    }
+
+    /**
+     * 上面方法的儿子方法 如果只传入了一个时间 则查询那天的数据
+     * @Author TXF
+     * @Date 2022/1/17 16:17
+     * @param map
+     * @param time
+     * @param sdfDate
+     * @return
+     **/
+    private static void queryDataByTwoDateSon(Map<String, Object> map, String time, SimpleDateFormat sdfDate){
+        Date date1 = new Date(Long.parseLong(time));
+        Date date2 = new Date(Long.parseLong(time) + 86400000);
+        String dayStartTime = sdfDate.format(date1);
+        String dayEndTime = sdfDate.format(date2);
+        map.put("startDate", dayStartTime + " 00:00:00");
+        map.put("endDate", dayEndTime + " 00:00:00");
+    }
 }

+ 62 - 1
src/main/resources/com/steerinfo/dil/mapper/WmspSendReceiveMapper.xml

@@ -450,13 +450,17 @@
   <!-- 请将自己写的代码放在此标签之下,方便以后粘贴复制。-->
 
   <select id="selectWmspSendReceive" resultType="java.util.LinkedHashMap">
+    select * from (
     select
     rw.warehouse_name "warehouse_name",
     rm.material_name "material_name",
+    rm.material_specification "material_specification",
+    rm.material_model "material_model",
     wsr.send_receive_lastday_inventory "send_receive_lastday_inventory" ,
     wsr.send_receive_thisday_inbound "send_receive_thisday_inbound",
     wsr.send_receive_thisday_outbound "send_receive_thisday_outbound",
-    wsr.send_receive_thisday_inventory "send_receive_thisday_inventory"
+    wsr.send_receive_thisday_inventory "send_receive_thisday_inventory",
+    wsr.send_receive_date "send_receive_date"
     from wmsp_send_receive wsr
     join RMS_MATERIAL rm
     on rm.material_id=wsr.material_id
@@ -464,6 +468,17 @@
     on rmt.material_type_id=rm.material_type_id
     join rms_warehouse rw
     on rw.warehouse_id=wsr.warehouse_id
+
+   <where>
+    <if test="oneDate != null">
+      and to_date(#{oneDate}, 'yyyy-mm-dd hh24:mi:ss') &lt;= wsr.INSERT_TIME
+    </if>
+    <if test="startDate != null">
+      and to_date(#{startDate}, 'yyyy-mm-dd hh24:mi:ss') &lt;= wsr.INSERT_TIME
+      and to_date(#{endDate}, 'yyyy-mm-dd hh24:mi:ss') >= wsr.INSERT_TIME
+    </if>
+   </where>
+    )
     <where>
       <if test="warehouse_name != null">
         and "warehouse_name" in
@@ -477,6 +492,18 @@
           #{item}
         </foreach>
       </if>
+      <if test="material_specification != null">
+        and "material_specification" in
+        <foreach collection="material_specification" item="item" open="(" separator="," close=")">
+          #{item}
+        </foreach>
+      </if>
+      <if test="material_model != null">
+        and "material_model" in
+        <foreach collection="material_model" item="item" open="(" separator="," close=")">
+          #{item}
+        </foreach>
+      </if>
       <if test="send_receive_lastday_inventory != null">
         and "send_receive_lastday_inventory" in
         <foreach collection="send_receive_lastday_inventory" item="item" open="(" separator="," close=")">
@@ -501,6 +528,12 @@
           #{item}
         </foreach>
       </if>
+      <if test="send_receive_date != null">
+        and "send_receive_date" in
+        <foreach collection="send_receive_date" item="item" open="(" separator="," close=")">
+          #{item}
+        </foreach>
+      </if>
     </where>
     <include refid="orderBy"></include>
   </select>
@@ -536,12 +569,14 @@
     select wsr.SEND_RECEIVE_THISDAY_INBOUND
     from WMSP_SEND_RECEIVE wsr
     where wsr.MATERIAL_ID = #{materialId} and wsr.WAREHOUSE_ID = #{warehouseId}
+     and trunc(wsr.INSERT_TIME) = trunc(sysdate-1)
   </select>
 
   <select id="selectSendReceiveThisdayOutbound" parameterType="java.util.Map" resultType="java.math.BigDecimal">
     select wsr.SEND_RECEIVE_THISDAY_OUTBOUND
     from WMSP_SEND_RECEIVE wsr
     where wsr.MATERIAL_ID = #{materialId} and wsr.WAREHOUSE_ID = #{warehouseId}
+    and trunc(wsr.INSERT_TIME) = trunc(sysdate-1)
   </select>
 
   <select id="getMaterialId" parameterType="java.math.BigDecimal" resultType="java.math.BigDecimal">
@@ -557,4 +592,30 @@
     set wsr.SEND_RECEIVE_THISDAY_INVENTORY = #{sendReceiveThisdayInventory}
     where wsr.MATERIAL_ID = #{materialId} and wsr.WAREHOUSE_ID = #{warehouseId}
   </update>
+
+  <select id="countSndReceiveThisdayInbound" parameterType="java.util.Map" resultType="java.math.BigDecimal">
+    select count(*) from WMSP_INBOUND_RESULT wir
+    left join RMS_MATERIAL_STEEL rms
+    on rms.MATERIAL_STEEL_ID = wir.MATERIAL_ID
+    left join RMS_MATERIAL rm
+    on rm.MATERIAL_ID =rms.MATERIAL_ID
+    left join RMS_PWAREHOUSE_GRID rpg
+    on rpg.GRID_ID = wir.GRID_ID
+    where rm.MATERIAL_ID = #{materialId} and
+    rpg.WAREHOUSE_ID = #{warehouseId} and
+    trunc(wir.INSERT_TIME) = trunc(sysdate-1)
+  </select>
+
+  <select id="countSendReceiveThisdayOutbound" parameterType="java.util.Map" resultType="java.math.BigDecimal">
+    select count(*) from WMSP_GRID_MATERIAL wgm
+     left join RMS_MATERIAL_STEEL rms
+    on rms.MATERIAL_STEEL_ID = wgm.MATERIAL_ID
+    left join RMS_MATERIAL rm
+    on rm.MATERIAL_ID =rms.MATERIAL_ID
+    left join RMS_PWAREHOUSE_GRID rpg
+    on rpg.GRID_ID = wgm.GRID_ID
+    where  rm.MATERIAL_ID = #{materialId} and
+    rpg.WAREHOUSE_ID = #{warehouseId} and
+    trunc(wgm.UPDATE_TIME) = trunc(sysdate-1)
+  </select>
 </mapper>