ソースを参照

Merge branch 'master' of https://git.steerinfo.com/DAL-DAZHOU1/DAL-TMS-TRAIN-API

liyg 2 年 前
コミット
fe3aebcffa

+ 13 - 6
src/main/java/com/steerinfo/dil/controller/TmstrainMeasureCommissionController.java

@@ -3,6 +3,7 @@ package com.steerinfo.dil.controller;
 import com.steerinfo.dil.service.ITmstrainMeasureCommissionService;
 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;
@@ -12,6 +13,7 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.text.SimpleDateFormat;
 import java.util.List;
 import java.util.Map;
 
@@ -38,6 +40,9 @@ public class TmstrainMeasureCommissionController extends BaseRESTfulController {
     @Autowired
     ColumnDataUtil columnDataUtil;
 
+    private final SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
+
+    private final SimpleDateFormat sdfDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
     @ApiOperation(value = "查询待计量的计量委托并展示")
     @ApiImplicitParams({
@@ -54,9 +59,10 @@ public class TmstrainMeasureCommissionController extends BaseRESTfulController {
             String endTime,
             String con) {
         mapValue.put("resultType",resultType);
-        mapValue.put("startTime",startTime);
-        mapValue.put("endTime",endTime);
-        mapValue.put("con",con);
+        DataChange.queryDataByDateTime(startTime, endTime, mapValue, sdfDateTime);//根据时间段查询数据
+        if(con!=null&&!"null".equals(con)&&!"".equals(con)) {
+            mapValue.put("con", con);
+        }
         //不分页筛选数据
         PageHelper.startPage(pageNum, pageSize);
         //分页数据
@@ -80,9 +86,10 @@ public class TmstrainMeasureCommissionController extends BaseRESTfulController {
             String endTime,
             String con) {
         mapValue.put("resultType",resultType);
-        mapValue.put("startTime",startTime);
-        mapValue.put("endTime",endTime);
-        mapValue.put("con",con);
+        DataChange.queryDataByDateTime(startTime, endTime, mapValue, sdfDateTime);//根据时间段查询数据
+        if(con!=null&&!"null".equals(con)&&!"".equals(con)) {
+            mapValue.put("con", con);
+        }
         //不分页筛选数据
         PageHelper.startPage(pageNum, pageSize);
         //分页数据

+ 126 - 27
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
@@ -42,20 +64,20 @@ public class DataChange {
      */
     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);
@@ -69,8 +91,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();
         }
@@ -104,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("原料扣减量数据有误");
+                }
             }
         }
     }
@@ -154,8 +182,79 @@ public class DataChange {
                         ? "0000" + id : id < 100000
                         ? "000" + id : id < 1000000
                         ? "00" + id : id < 10000000
-                        ? "0" + id : id
+                        ? "0" + id : id.toString()
         );
         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");
+    }
 }

+ 27 - 8
src/main/resources/com/steerinfo/dil/mapper/TmstrainMeasureCommissionMapper.xml

@@ -430,12 +430,13 @@
                  or RS.SUPPLIER_NAME like concat('%',concat(#{con},'%'))
                )
              </if>
-             <if test="startTime!=null">
-             and TLR.RESULT_LOADING_DATE >= #{startTime}
-             </if>
-             <if test="endTime!=null">
-             and #{endTime} >= TLR.RESULT_LOADING_DATE
-             </if>
+      <if test="oneDate != null">
+          and to_date(#{oneDate}, 'yyyy-mm-dd hh24:mi:ss') &lt;=  TLR.INSERT_TIME
+      </if>
+      <if test="startDate != null">
+          and to_date(#{startDate}, 'yyyy-mm-dd hh24:mi:ss') &lt;=  TLR.INSERT_TIME
+          and to_date(#{endDate}, 'yyyy-mm-dd hh24:mi:ss') >=  TLR.INSERT_TIME
+      </if>
          )
     <include refid="orderBy"></include>
     <if test="orderField == null  ">
@@ -484,11 +485,29 @@
            left join TMSTRAIN_WAGON_UNLOAD_RESULT TWUR
                      on (TLR.PURCHASE_ORDER_RAIL_PLAN_ID=TWUR.PURCHASE_ORDER_RAIL_PLAN_ID and  TLR.RESULT_WAGON_NO=TWUR.RESULT_WAGON_NO)
     where TLR.DELETED = 0
-      and TLR.RESULT_TYPE = 3
+      and TLR.RESULT_TYPE = #{resultType}
       and TLR.SEND_REQUEST = 2
       and APO.PURCHASE_ORDER_NO IS NOT NULL
       AND TWR.RESULT_POUND_NO IS NOT NULL
-
+      <if test="con!=null and con!=''.toString()">
+          and (
+          APO.PURCHASE_ORDER_NO like concat('%',concat(#{con},'%'))
+          or TLR.RESULT_WAGON_NO like concat('%',concat(#{con},'%'))
+          or TLR.RESULT_CLASS like concat('%',concat(#{con},'%'))
+          or DB.RESULT_FOREIGN_SHIP_NAME like concat('%',concat(#{con},'%'))
+          or RM.MATERIAL_NAME like concat('%',concat(#{con},'%'))
+          or RAS.ARRIVAL_NAME like concat('%',concat(#{con},'%'))
+          or RAS2.ARRIVAL_NAME like concat('%',concat(#{con},'%'))
+          or RS.SUPPLIER_NAME like concat('%',concat(#{con},'%'))
+          )
+      </if>
+      <if test="oneDate != null">
+          and to_date(#{oneDate}, 'yyyy-mm-dd hh24:mi:ss') &lt;= TWR.UPDATE_TIME
+      </if>
+      <if test="startDate != null">
+          and to_date(#{startDate}, 'yyyy-mm-dd hh24:mi:ss') &lt;= TWR.UPDATE_TIME
+          and to_date(#{endDate}, 'yyyy-mm-dd hh24:mi:ss') >= TWR.UPDATE_TIME
+      </if>
   </select>
 
     <sql id="orderBy">