zx 2 years ago
parent
commit
ae1f648b29

+ 7 - 1
src/main/java/com/steerinfo/dil/controller/TmsshipLoadShipResultController.java

@@ -8,6 +8,7 @@ import com.steerinfo.dil.model.TmsshipShipLocation;
 import com.steerinfo.dil.service.ITmsshipLoadShipResultService;
 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;
@@ -21,6 +22,7 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.math.BigDecimal;
 
@@ -47,6 +49,7 @@ public class TmsshipLoadShipResultController extends BaseRESTfulController {
     ColumnDataUtil columnDataUtil;
     @Autowired
     ESFeign esFeign;
+    private final SimpleDateFormat sdfDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
     /**
      * 新增装船作业(附带新增装船卸船)
      * @param map
@@ -148,7 +151,10 @@ public class TmsshipLoadShipResultController extends BaseRESTfulController {
                                          Integer pageSize,
                                          Integer apiId,
                                          Integer status,
-                                         String con){
+                                         String con,
+                                         String startTime,
+                                         String endTime){
+        DataChange.queryDataByDateTime(startTime, endTime, mapVal, sdfDateTime);//根据时间段查询数据
         //判断状态值是否为空
         if (status!=null){
             mapVal.put("status",status);

+ 14 - 14
src/main/java/com/steerinfo/dil/controller/TmsshipShipLocationController.java

@@ -145,20 +145,20 @@ public class TmsshipShipLocationController extends BaseRESTfulController {
         if (con!=null&&!"".equals(con)){
             mapVal.put("con",con);
         }
-//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-//        //通过时间查询数据
-//        Object dayTime = mapVal.get("dayTime");
-//        Date date;
-//        String timeFormat;
-//        if(dayTime != null){
-//
-//             date = new Date((long) dayTime);
-//             timeFormat = sdf.format(date);
-//        }else {
-//             date = new Date();
-//            timeFormat = sdf.format(date);
-//        }
-//        mapVal.put("dayTime", timeFormat);
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        //通过时间查询数据
+        Object dayTime = mapVal.get("dayTime");
+        Date date;
+        String timeFormat;
+        if(dayTime != null){
+
+             date = new Date((long) dayTime);
+             timeFormat = sdf.format(date);
+        }else {
+             date = new Date();
+            timeFormat = sdf.format(date);
+        }
+        mapVal.put("dayTime", timeFormat);
         List<Map<String, Object>> columnList = tmsshipShipLocationService.selectShipLocationList(mapVal);
         return success(columnList);
     }

+ 129 - 28
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,46 +18,66 @@ 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
      * @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);
@@ -91,7 +112,12 @@ public class DataChange {
             for (String s : key) {
                 //从map中取 date的值 并转换成字符串类型的日期
                 String stringDate = dateToDayDate(map.get(s));
-                map.put(s, stringDate);
+                if(stringDate.length() == 0){
+                    break;
+                }else {
+                    //修改map中的值
+                    map.put(s, stringDate);
+                }
             }
         }
     }
@@ -102,14 +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) {
                 //修改数据为带两位小数
-                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 = dataToBigDecimal(map.get(s));
+                    String resultDeduction = df.format(oldDate.doubleValue());
+                    map.put(s, resultDeduction);
+                } catch (Exception e) {
+                    System.out.println("原料扣减量数据有误");
+                }
             }
         }
     }
@@ -156,4 +186,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");
+    }
 }

+ 2 - 0
src/main/resources/com/steerinfo/dil/mapper/OmsshipShipmentInstructionsMapper.xml

@@ -576,6 +576,8 @@
         ADA.ATTORNEY_CONTACT_TELEPHONE "shipperContactNumber",
         adn.RESULT_NUMBER_OF_LOANS "numberOfLoans",
         RPO2.PORT_NAME "arriveName",
+        -- 承运单位 carrierNaming 万州港
+        RPO2.PORT_ALL_NAME "carrierNaming",
         osi.INSTRUCTION_TIME "instructionTime",
         osi.INSTRUCTIONS_TOTAL_TONNAGE "instruct",
         osi.INSTRUCTIONS_STATUS  "instructions",

+ 5 - 0
src/main/resources/com/steerinfo/dil/mapper/TmsshipLoadShipResultMapper.xml

@@ -602,6 +602,7 @@
             order by "insertTime" desc
         </if>
     </sql>
+<!-- 查询装船作业-->
     <select id="selectLoadShipList" resultType="java.util.Map">
         SELECT * FROM(
         SELECT DISTINCT ttr.ORDER_ID as "orderId",
@@ -659,6 +660,10 @@
         WHERE tlsr.DELETED = 0 AND  adn.DELETED=0 AND ada.DELETED=0
         <if test="con != null" >
             and dbi.INFACTORY_SHIP_NAME || rm.MATERIAL_NAME || db.RESULT_FOREIGN_SHIP_NAME like #{con}
+        </if>
+        <if test="startDate != null">
+            and to_date(#{startDate}, 'yyyy-mm-dd hh24:mi:ss') &lt;=  tlsr.RESULT_LOAD_SHIP_DATE
+            and to_date(#{endDate}, 'yyyy-mm-dd hh24:mi:ss') >=  tlsr.RESULT_LOAD_SHIP_DATE
         </if>
             )
         <where>

+ 5 - 0
src/main/resources/com/steerinfo/dil/mapper/TmsshipShipLocationMapper.xml

@@ -458,6 +458,8 @@
       order by "insertTime" desc
     </if>
   </sql>
+  
+<!--查询位置作业-->
   <select id="selectShipLocationList" parameterType="map" resultType="java.util.Map">
     SELECT DISTINCT
       ttr.ORDER_ID                     as "orderId",
@@ -502,6 +504,9 @@
   <if test="con!=null">
     and  (instr(rc.CAPACITY_NUMBER,#{con}) > 0 or instr(rm.MATERIAL_NAME,#{con}) > 0 or   instr(db.RESULT_FOREIGN_SHIP_NAME,#{con}) > 0  )
   </if>
+  <if test="dayTime!=null">
+  and  tsl.LOCATION_ROUTE_TIME = #{dayTime}
+  </if>
   </select>
 
   <select id="selectShipLocation" parameterType="DECIMAL" resultType="java.util.Map">