liyg 2 years ago
parent
commit
80ba8d42a9

+ 17 - 1
src/main/java/com/steerinfo/dil/controller/WmshGridMaterialController.java

@@ -2,6 +2,7 @@ package com.steerinfo.dil.controller;
 
 import com.steerinfo.dil.service.IWmshGridMaterialService;
 import com.steerinfo.dil.util.ColumnDataUtil;
+import com.steerinfo.dil.util.DataChange;
 import com.steerinfo.dil.util.PageListAdd;
 import com.steerinfo.framework.controller.BaseRESTfulController;
 import com.steerinfo.framework.controller.RESTfulResult;
@@ -16,6 +17,7 @@ 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.List;
 import java.util.Map;
 
@@ -40,6 +42,7 @@ public class WmshGridMaterialController extends BaseRESTfulController {
     IWmshGridMaterialService wmshGridMaterialService;
     @Autowired
     ColumnDataUtil columnDataUtil;
+    private final SimpleDateFormat sdfDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
     /**
      * 展示下游港口港存库库存列表
@@ -163,11 +166,24 @@ public class WmshGridMaterialController extends BaseRESTfulController {
                                                         Integer pageNum,
                                                         Integer pageSize,
                                                         Integer apiId,
-                                                        String con){
+                                                        String con,
+                                            String activeName,
+                                            String startTime,
+                                            String endTime){
         if (con!=null&&!"".equals(con)){
             mapVal.put("con",con);
         }
+        if (activeName!=null&&!"".equals(activeName)){
+            mapVal.put("activeName",activeName);
+        }
+        if (startTime!=null&&!"".equals(startTime)){
+            mapVal.put("startTime",startTime);
+        }
+        if (endTime!=null&&!"".equals(endTime)){
+            mapVal.put("endTime",endTime);
+        }
         PageHelper.startPage(pageNum, pageSize);
+        DataChange.queryDataByDateTime(startTime, endTime, mapVal, sdfDateTime);//根据时间段查询数据
         //分页查询数据
         List<Map<String, Object>> columnList = wmshGridMaterialService.getUnLockPortStock(mapVal);
         PageListAdd data = columnDataUtil.tableColumnData(apiId, null, columnList);

+ 83 - 14
src/main/java/com/steerinfo/dil/util/DataChange.java

@@ -7,6 +7,7 @@ import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
 
 /**
  * @ author    :TXF
@@ -17,24 +18,45 @@ public class DataChange {
 
 
     /**
-     * 解析前端传来的日期字符串
+     * 时间转换类
+     * 处理了三种类型 yyyy-MM-dd HH:mm:ss  yyyy/MM/dd HH:mm:ss  时间戳类型(带毫秒数时间戳13位)
      * @param vueDate
      * @return
      */
     public static Date dataToDate(Object vueDate){
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-        Date parseDate = null;
-        if (vueDate != null){
+        if(vueDate instanceof Date){
+            return (Date) vueDate;
+        } else {
             try {
-                String date = (String) vueDate;
-                parseDate = sdf.parse(date);
-            } catch (ParseException e) {
-                e.printStackTrace();
+                String str = String.valueOf(vueDate);
+                if(judgeNumber(str) && str.length() == 13){
+                    return new Date(Long.parseLong(str));
+                }else if(str.contains("-")){
+                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                    return sdf.parse(str);
+                }else if(str.contains("/")){
+                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
+                    return sdf.parse(str);
+                }
+            }catch (Exception e){
+                System.out.println("时间解析错误!返回null");
+                return null;
             }
         }
-        return parseDate;
+        return null;
+    }
+
+    /**
+     * 判断是否纯数字(不带小数点)仅供上面方法使用
+     * @param str
+     * @return
+     */
+    public static boolean judgeNumber(String str){
+        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
+        return pattern.matcher(str).matches();
     }
 
+
     /**
      * 数据转换成BigDecimal
      * @param data
@@ -72,7 +94,7 @@ public class DataChange {
         if(date == null)
             return null;
         try{
-             changeDate = (Date) date;
+            changeDate = (Date) date;
         }catch (Exception e){
             e.printStackTrace();
         }
@@ -106,19 +128,18 @@ public class DataChange {
      * @param key
      */
     public static void dataTo2Number(List<Map<String, Object>> list, String ...key){
+        DecimalFormat df =  new DecimalFormat("0.00");
         //遍历List
         for (Map<String, Object> map : list) {
             for (String s : key) {
                 //修改数据为带两位小数
                 try {
-                    BigDecimal oldDate = (BigDecimal) map.get(s);
-                    DecimalFormat df =  new DecimalFormat("0.00");
+                    BigDecimal oldDate = dataToBigDecimal(map.get(s));
                     String resultDeduction = df.format(oldDate.doubleValue());
                     map.put(s, resultDeduction);
                 } catch (Exception e) {
                     System.out.println("原料扣减量数据有误");
                 }
-
             }
         }
     }
@@ -167,7 +188,7 @@ public class DataChange {
     }
 
     /**
-     * 根据时间段查询数据
+     * 根据时间段查询数据 支持只选择单个时间
      * @Author TXF
      * @Date 2022/1/10 23:21
      * @param startTime
@@ -188,4 +209,52 @@ public class DataChange {
             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");
+    }
 }

+ 10 - 0
src/main/resources/com/steerinfo/dil/mapper/WmshGridMaterialMapper.xml

@@ -524,6 +524,16 @@
            and (instr(RM.MATERIAL_NAME , #{con}) > 0 or instr( TLT.RESULT_WAGON_NO, #{con}) > 0 or
                 instr(DB.RESULT_FOREIGN_SHIP_NAME,#{con}) > 0 or instr( RP.PORT_NAME,#{con}) > 0)
         </if>
+        <if test="activeName!=null and activeName=='second'">
+           and TWR.RESULT_POUND_NO is null
+        </if>
+        <if test="oneDate != null">
+            and to_date(#{oneDate}, 'yyyy-mm-dd hh24:mi:ss') &lt;= WOR.INSERT_TIME
+        </if>
+        <if test="startDate != null">
+            and to_date(#{startDate}, 'yyyy-mm-dd hh24:mi:ss') &lt;= WOR.INSERT_TIME
+            and to_date(#{endDate}, 'yyyy-mm-dd hh24:mi:ss') >= WOR.INSERT_TIME
+        </if>
         Order By  WOR.RESULT_NUMBER desc
     </select>
 </mapper>