Răsfoiți Sursa

1、车辆规矩相关接口

zk 2 ani în urmă
părinte
comite
adb4bf82d3

+ 408 - 0
sckw-common/sckw-common-core/src/main/java/com/sckw/core/utils/DateUtils.java

@@ -0,0 +1,408 @@
+package com.sckw.core.utils;
+
+import cn.hutool.core.date.DateUtil;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.*;
+
+/**
+ * 日期处理
+ * @author
+ */
+public class DateUtils extends DateUtil {
+    /**
+     * 时间格式(yyyy-MM-dd)
+     */
+    public final static String DATE_PATTERN = "yyyy-MM-dd";
+    /**
+     * 时间格式(yyyy-MM-dd HH:mm:ss)
+     */
+    public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
+
+    public static String FORMAT2 = "yyyy-MM-dd HH:mm:ss";
+
+    public static String FORMAT3 = "yyyyMMddHHmmss";
+
+    public static String FORMAT4 = "yyMMddHHmmss";
+
+    public static String FORMAT5 = "yyMMddHHmmssSSS";
+
+    public static String FORMAT6 = "yyyyMMdd";
+
+    public static String FORMAT7 = "yyyy-MM-dd HH:mm";
+
+    public static String FORMAT8 = "yyMMdd";
+
+    public static String FORMAT9 = "yyyy/MM/dd";
+
+    public static String FORMAT10 = "yyyy-MM";
+
+    public static int THIRTEEN = 13;
+
+    /**
+     * 获取时间
+     *
+     * @return 返回当前时间
+     */
+    public static Date getDate() {
+        return new Date();
+    }
+
+    public static String getCurrentTime() {
+        Date day = new Date();
+        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        System.out.println(df.format(day));
+        return df.format(day);
+    }
+
+    public static String getCurrentTime(String format) {
+        Date day = new Date();
+        SimpleDateFormat df = new SimpleDateFormat(format);
+        System.out.println(df.format(day));
+        return df.format(day);
+    }
+
+    /**
+     * 获取时间
+     *
+     * @param timeStamp 时间戳
+     * @return Date
+     */
+    public static Date getDate(Long timeStamp) {
+        if (timeStamp == null || timeStamp <= 0) {
+            return null;
+        }
+        return new Date(timeStamp);
+    }
+
+    /**
+     * 日期格式化 日期格式为:yyyy-MM-dd
+     *
+     * @param date 日期
+     * @return 返回yyyy-MM-dd格式日期
+     */
+    public static String format(Date date) {
+        return format(date, DATE_PATTERN);
+    }
+
+    /**
+     * 日期格式化 日期格式为:yyyy-MM-dd
+     *
+     * @param date    日期
+     * @param pattern 格式,如:DateUtils.DATE_TIME_PATTERN
+     * @return 返回yyyy-MM-dd格式日期
+     */
+    public static String format(Date date, String pattern) {
+        if (date != null) {
+            SimpleDateFormat df = new SimpleDateFormat(pattern);
+            return df.format(date);
+        }
+        return null;
+    }
+
+    /**
+     * @param date
+     * @return String    返回类型
+     * @Title: getYear
+     * @Description: TODO(获取YYYY格式)
+     */
+    public static String getYear(Date date) {
+        return format(date, "yyyy");
+    }
+
+    /**
+     * @param date
+     * @return String    返回类型
+     * @Title: getMonth
+     * @Description: 获取月(获取MM格式)
+     */
+    public static String getMonth(Date date) {
+        return format(date, "MM");
+    }
+
+    /**
+     * @param date
+     * @return String    返回类型
+     * @Title: getTheDay
+     * @Description: 获取日期的天(dd格式)
+     */
+    public static String getTheDay(Date date) {
+        return format(date, "dd");
+    }
+
+    /**
+     * 方法描述:将时间转换为制定格式的日期时间字符串
+     * @param date
+     * @return
+     */
+    public static String dateToString(Date date, String pattern) {
+        SimpleDateFormat df;
+        String returnValue = "";
+
+        if (date != null) {
+            df = new SimpleDateFormat(pattern);
+            returnValue = df.format(date);
+        }
+        return (returnValue);
+    }
+
+    /**
+     * @param beginDateStr
+     * @param endDateStr
+     * @return long    返回类型
+     * @Title: getDaySub
+     * @Description: TODO(功能描述 : 时间相减得到天数)
+     */
+    public static long getDaySub(String beginDateStr, String endDateStr) {
+        long day = 0;
+        SimpleDateFormat format = new SimpleDateFormat(
+                "yyyy-MM-dd");
+        Date beginDate = null;
+        Date endDate = null;
+
+        try {
+            beginDate = format.parse(beginDateStr);
+            endDate = format.parse(endDateStr);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        day = (endDate.getTime() - beginDate.getTime()) / (24 * 60 * 60 * 1000);
+        // System.out.println("相隔的天数="+day);
+
+        return day;
+    }
+
+    /**
+     * 10位13位时间戳转String 格式(2018-10-15 16:03:27) 日期
+     *
+     * @param timestamp
+     * @param simpleDateFormatType 时间戳类型("yyyy-MM-dd HH:mm:ss")
+     * @return
+     */
+    public static String numberDateFormat(String timestamp, String simpleDateFormatType) {
+        SimpleDateFormat sdf = new SimpleDateFormat(simpleDateFormatType);//要转换的时间格式
+        String date = null;
+        if (timestamp.length() == THIRTEEN) {
+            date = sdf.format(Long.parseLong(timestamp));
+        } else {
+            date = sdf.format(Long.parseLong(timestamp) * 1000);
+        }
+        return date;
+    }
+
+    /**
+     * 10位13位时间戳转Date
+     *
+     * @param timestamp            参数时间戳
+     * @param simpleDateFormatType 时间戳类型("yyyy-MM-dd HH:mm:ss")
+     * @return
+     */
+    public static Date numberDateFormatToDate(String timestamp, String simpleDateFormatType) {
+        SimpleDateFormat sdf = new SimpleDateFormat(simpleDateFormatType);//要转换的时间格式
+        Date date = null;
+        try {
+            if (timestamp.length() == THIRTEEN) {
+                date = sdf.parse(sdf.format(Long.parseLong(timestamp)));
+            } else {
+                date = sdf.parse(sdf.format(Long.parseLong(timestamp) * 1000));
+            }
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return date;
+    }
+
+    /**
+     * Date转10位13位时间戳
+     *
+     * @param date 参数date
+     * @param n    需要转换成几位时间戳
+     * @return
+     */
+    public static String numberDateFormatToDate(Date date, int n) {
+        String result = null;
+        if (n == THIRTEEN) {
+            result = String.valueOf(date.getTime());
+        } else {
+            result = String.valueOf(date.getTime() / 1000);
+        }
+        return result;
+    }
+
+    /**
+     * @Author:Bernie
+     * @Params: seconds 秒数
+     * @Description: 通过秒数转换为时分秒
+     * @Date: 2019/7/18 0018 16:46
+     */
+    public static String getTimeBySecond(long seconds) {
+        long days = seconds / 86400;//转换天数
+        seconds = seconds % 86400;//剩余秒数
+        long hours = seconds / 3600;//转换小时数
+        seconds = seconds % 3600;//剩余秒数
+        long minutes = seconds / 60;//转换分钟
+        seconds = seconds % 60;//剩余秒数
+        if (0 < days) {
+            return days + "天," + hours + "小时," + minutes + "分," + seconds + "秒";
+        } else {
+            return (hours == 0 ? "00" : (hours >= 10 ? hours : "0" + hours)) + ":" + (minutes == 0 ? "00" : (minutes >= 10 ? minutes : "0" + minutes)) + ":" + (seconds == 0 ? "00" : (seconds >= 10 ? seconds : "0" + seconds)) + "秒";
+        }
+
+    }
+
+    /**
+     * @return java.lang.String
+     * @Description 转换iso格式
+     * @Author CHENJUN
+     * @Date 2020/7/10 14:49
+     * @params [isoDate]
+     */
+    public static long getDateFromISO(String isoDate) {
+        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+//        DateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        try {
+            return sdf.parse(isoDate).getTime();
+        } catch (ParseException e) {
+            e.printStackTrace();
+            return 0;
+        }
+    }
+
+    public static long getDateFromDate(String date) {
+        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+//        DateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        try {
+            return sdf.parse(date).getTime();
+        } catch (ParseException e) {
+            e.printStackTrace();
+            return 0;
+        }
+    }
+
+    public static int getDifference(String start, String end) {
+        SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd");
+        /*天数差*/
+        Date fromDate1 = null, toDate1 = null;
+        try {
+            fromDate1 = simpleFormat.parse(start);
+            toDate1 = simpleFormat.parse(end);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        long from1 = fromDate1.getTime();
+        long to1 = toDate1.getTime();
+        int days = (int) ((to1 - from1) / (1000 * 60 * 60 * 24));
+        System.out.println("两个时间之间的天数差为:" + days);
+        return days;
+    }
+
+    /**
+     * @return 以小数格式显示的小时
+     * @Description 将毫秒转换成以小数格式显示的小时
+     * @Author SuiYingying
+     * @Date 2021/12/24 14:49
+     * @params time 毫秒格式的时间
+     */
+    public static String getHoursForLong(Long time) {
+        float newTime;
+        time = time / 1000;
+        newTime = (float) time % (1000 * 60 * 60 * 24) / (1000 * 60 * 60);
+        newTime = newTime * 1000;
+        return String.format("%.5f", newTime);
+    }
+
+
+    public static void main(String[] ager) throws InterruptedException {
+
+    }
+
+    /**
+     * ltf 获取
+     * 获取指定日期所在周的周一
+     * @param date
+     * @return
+     */
+    public static Date getFirstDayOfWeek(Date date) {
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+        if (c.get(Calendar.DAY_OF_WEEK) == 1) {
+            c.add(Calendar.DAY_OF_MONTH, -1);
+        }
+        c.add(Calendar.DATE, c.getFirstDayOfWeek() - c.get(Calendar.DAY_OF_WEEK) + 1);
+        return c.getTime();
+    }
+    /**
+     * 获取startDate日期后month月的日期
+     * @param startDate 开始日期
+     * @param month  几个月后
+     * @author wenzhang
+     * @return
+     */
+    public static Date getMonthDate(Date startDate, int month){
+        LocalDateTime localDateTime = startDate.toInstant()
+                .atZone(ZoneId.systemDefault() )
+                .toLocalDateTime().plusMonths(month);
+        Date date = Date.from(localDateTime.atZone( ZoneId.systemDefault()).toInstant());
+        return date;
+    }
+
+    /**
+     *
+     * @param days
+     * @author wenzhang
+     * @return
+     */
+    public static Date getDateAdd(int days){
+        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.DAY_OF_MONTH, days);
+        return c.getTime();
+
+    }
+
+    /**
+     * 计算两个日期的月数
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    public static int getMonthSpace(String startDate, String endDate) throws Exception {
+        int monthCount = 0;
+        Calendar startCalendar = Calendar.getInstance();
+        Calendar endCalendar = Calendar.getInstance();
+        startCalendar.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(startDate));
+        endCalendar.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(endDate));
+
+        int year = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR);
+        int month = endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH);
+        int day = Math.abs(endCalendar.get(Calendar.DATE) - startCalendar.get(Calendar.DATE));
+
+        if (year == 0 && month == 0){
+            startCalendar.set(Calendar.DATE, 1);
+            endCalendar.set(Calendar.DATE, 1);
+            endCalendar.roll(Calendar.DATE, -1);
+            if (day == (endCalendar.get(Calendar.DATE) - startCalendar.get(Calendar.DATE))) {
+                monthCount = 1;// 两日期间满一个月
+            } else {
+                monthCount = 0;// 两日期间不足一个月
+            }
+        } else if (year != 0 && month == 0) {// 年份不同月份相同
+            if (startCalendar.get(Calendar.DATE) < endCalendar.get(Calendar.DATE)) {// 两日期间的天数,小于等于当月
+                monthCount = 1;
+            }
+            monthCount += year * 12 + month;
+        } else {
+            if (startCalendar.get(Calendar.DATE) >= endCalendar.get(Calendar.DATE)) {// 起始日期DATE 大于等于结束日期DATE
+                monthCount = year * 12 + month;
+            } else {
+                monthCount = year * 12 + month + 1;
+            }
+        }
+
+        return monthCount;
+    }
+
+}

+ 77 - 4
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/controller/KwfTruckController.java

@@ -1,5 +1,6 @@
 package com.sckw.fleet.controller;
 
+import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageHelper;
@@ -7,6 +8,8 @@ import com.github.pagehelper.PageInfo;
 import com.sckw.core.exception.SystemException;
 import com.sckw.core.model.page.PageHelperUtil;
 import com.sckw.core.model.page.PageResult;
+import com.sckw.core.utils.CollectionUtils;
+import com.sckw.core.utils.DateUtils;
 import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.core.web.response.HttpResult;
@@ -20,12 +23,9 @@ import com.sckw.fleet.service.KwfTruckService;
 import jakarta.servlet.http.HttpServletResponse;
 import jakarta.validation.Valid;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @author zk
@@ -233,4 +233,77 @@ public class KwfTruckController {
         return truckService.transportLicenseEdit(params);
     }
 
+    /**
+     * @param params {truckNo 車牌號}
+     * @description 车辆查询(业务关联+归属车辆)
+     * @author zk
+     * @date 2023/7/26
+     **/
+    @PostMapping("/findTruck")
+    public HttpResult findTruck(@RequestBody Map params) {
+        params.put("entId", LoginUserHolder.getEntId());
+        List<KwfTruckVo> trucks = truckService.findPage(params);
+
+        List data = new ArrayList();
+        for (KwfTruckVo truck:trucks) {
+            data.add(new HashMap(){{put("truckNo", truck.getTruckNo());
+                put("entId", truck.getEntId()); put("firmName",
+                        truck.getFirmName()); put("businessStatus", truck.getStatusName());
+                        put("runStatus", 0);}});
+        }
+
+        return HttpResult.ok(data);
+    }
+
+    /**
+     * @param truckNos 車牌號集
+     * @description 车辆查询GPS(业务关联 + 归属车辆)
+     * @author zk
+     * @date 2023/7/26
+     **/
+    @PostMapping("/findTruckGps")
+    public HttpResult findTruckGps(@RequestBody List<String> truckNos) {
+        if (CollectionUtils.isEmpty(truckNos)) {
+            return HttpResult.ok();
+        }
+
+        List data = new ArrayList();
+        for (String truckNo:truckNos) {
+            data.add(new HashMap(){{
+                put("truckNo", truckNo);
+                put("speed", new Random().nextInt(100));
+                put("lng", "30."+new Random().nextInt(1000000));
+                put("lat", "103."+new Random().nextInt(1000000));
+                put("gpsTime", DateUtils.getCurrentTime());}});
+        }
+        return HttpResult.ok(data);
+    }
+
+    /**
+     * @param params {truckNos 車牌號集, startTime 開始實際, endTime 結束時間}
+     * @description 车辆查询GPS(通过车牌号查询)
+     * @author zk
+     * @date 2023/7/26
+     **/
+    @PostMapping("/findGpsByTruckNo")
+    public HttpResult findGpsByTruckNo(@RequestBody @Valid GpsByTruckNoDto params) {
+        Long hours = (params.getEndTime().getTime() - params.getStartTime().getTime()) /1000/60;
+        List data = new ArrayList();
+        data.add(new HashMap(){{put("truckNo", params.getTruckNo()); put("speed", 95.0);
+            put("lng", "30.60513"); put("lat", "104.05079");
+            put("gpsTime", DateUtils.format(params.getStartTime(), DateUtils.DATE_TIME_PATTERN));}});
+        for (long i=0; i<hours; i++) {
+            data.add(new HashMap(){{
+                put("truckNo", params.getTruckNo());
+                put("speed", new Random().nextInt(100));
+                put("lng", "30."+new Random().nextInt(1000000));
+                put("lat", "103."+new Random().nextInt(1000000));
+                put("gpsTime", DateUtils.getCurrentTime());}});
+        }
+        data.add(new HashMap(){{put("truckNo", params.getTruckNo()); put("speed", 95.0);
+            put("lng", "29.524931"); put("lat", "103.734587");
+            put("gpsTime", DateUtils.format(params.getEndTime(), DateUtils.DATE_TIME_PATTERN));}});
+        return HttpResult.ok(data);
+    }
+
 }

+ 39 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/model/dto/GpsByTruckNoDto.java

@@ -0,0 +1,39 @@
+package com.sckw.fleet.model.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+import java.util.Date;
+
+/**
+ * @author zk
+ * @desc TODO
+ * @date 2023/7/26 0026
+ */
+@Data
+public class GpsByTruckNoDto {
+
+    /**
+     *車牌號集
+     */
+    @NotBlank(message = "车牌号不能为空!")
+    private String truckNo;
+
+    /**
+     *開始實際
+     */
+    @NotNull(message = "开始时间不能为空!")
+    @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date startTime;
+
+    /**
+     *結束時間
+     */
+    @NotNull(message = "结束时间不能为空!")
+    @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date endTime;
+}

+ 22 - 0
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/controller/KwtWaybillOrderController.java

@@ -140,6 +140,28 @@ public class KwtWaybillOrderController {
         return waybillOrderService.refuseSendCar(params);
     }
 
+    /**
+     * @param params {}
+     * @description 确认出车
+     * @author zk
+     * @date 2023/7/26
+     **/
+    @PostMapping("/confirmDeparture")
+    public HttpResult confirmDeparture(@RequestBody @Valid ConfirmRefuseSendCarDto params){
+        return waybillOrderService.confirmSendCar(params);
+    }
+
+    /**
+     * @param params {}
+     * @description 拒绝出车
+     * @author zk
+     * @date 2023/7/26
+     **/
+    @PostMapping("/confirmDeparture")
+    public HttpResult refuseDeparture(@RequestBody @Valid ConfirmRefuseSendCarDto params){
+        return waybillOrderService.refuseSendCar(params);
+    }
+
 
 
     //取消派车(未接单前)