运营区车辆列表(仓库外

This commit is contained in:
attiya 2025-06-05 12:01:10 +08:00
parent 84b882fd46
commit 8ceb589d37
4 changed files with 236 additions and 91 deletions

View File

@ -42,6 +42,11 @@ public class ResEbikeInfoRegionDto {
*/
private Character state;
/**
* 电动车状态名称
*/
private String stateName;
/**
* 电动车编码
*/
@ -127,4 +132,9 @@ public class ResEbikeInfoRegionDto {
*/
private String latestTimestamp;
/**
* 间隔时间
*/
private Integer intervalTime;
}

View File

@ -19,6 +19,7 @@ import com.cdzy.ebikemaintenance.service.EbikeBikeOrderService;
import com.cdzy.ebikemaintenance.utils.GeoCodingUtil;
import com.cdzy.ebikemaintenance.utils.MinioUtil;
import com.cdzy.ebikemaintenance.utils.RedisUtil;
import com.cdzy.ebikemaintenance.utils.TimeUtils;
import com.ebike.feign.clients.OperateFeignClient;
import com.ebike.feign.clients.StaffFeignClient;
import com.ebike.feign.model.res.ReqEcuSnDto;
@ -62,8 +63,7 @@ import static com.cdzy.ebikemaintenance.model.pojo.table.EbikeBikeOrderTableDef.
import static com.cdzy.ebikemaintenance.model.pojo.table.EbikeCarStatusInfoTableDef.EBIKE_CAR_STATUS_INFO;
import static com.cdzy.ebikemaintenance.model.pojo.table.EbikeDispatchRecordsTableDef.EBIKE_DISPATCH_RECORDS;
import static com.cdzy.ebikemaintenance.model.pojo.table.EbikeEcuInfoTableDef.EBIKE_ECU_INFO;
import static com.mybatisflex.core.query.QueryMethods.max;
import static com.mybatisflex.core.query.QueryMethods.select;
import static com.mybatisflex.core.query.QueryMethods.*;
/**
* 车辆基本信息 服务层实现
@ -270,7 +270,7 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
QueryWrapper queryWrapper = QueryWrapper.create();
queryWrapper.select(Arrays.stream(EBIKE_BIKE_INFO.DEFAULT_COLUMNS).toList());
queryWrapper.select(
QueryMethods.case_()
case_()
.when(EBIKE_CAR_STATUS_INFO.NAMEYW.isNull()).then(EBIKE_CAR_STATUS_INFO.NAMEYY)
.else_(EBIKE_CAR_STATUS_INFO.NAMEYW)
.end().as("state_name")
@ -381,7 +381,7 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
query.select(EBIKE_BIKE_INFO.BIKE_ID, EBIKE_BIKE_INFO.BIKE_NUMBER, EBIKE_BIKE_INFO.BIKE_MODEL);
query.select(EBIKE_BIKE_INFO.BIKE_CODE, EBIKE_BIKE_INFO.STATE, new QueryColumn("CHECKIN_TEMP", "enter_time"));
query.select(
QueryMethods.case_()
case_()
.when(EBIKE_CAR_STATUS_INFO.NAMEYW.isNull()).then(EBIKE_CAR_STATUS_INFO.NAMEYY)
.else_(EBIKE_CAR_STATUS_INFO.NAMEYW)
.end().as("state_name")
@ -1333,10 +1333,10 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
query.select(EBIKE_BIKE_INFO.BIKE_ID, EBIKE_BIKE_INFO.BIKE_NUMBER, EBIKE_BIKE_INFO.BIKE_MODEL);
query.select(EBIKE_BIKE_INFO.BIKE_CODE, EBIKE_BIKE_INFO.STATE, new QueryColumn("CHECKIN_TEMP", "enter_time"));
query.select(
QueryMethods.case_()
case_()
.when(EBIKE_DISPATCH_RECORDS.BIKE_CODE.isNotNull())
.then("投放中")
.else_(QueryMethods.case_()
.else_(case_()
.when(EBIKE_CAR_STATUS_INFO.NAMEYW.isNull()).then(EBIKE_CAR_STATUS_INFO.NAMEYY)
.else_(EBIKE_CAR_STATUS_INFO.NAMEYY)
.end())
@ -1543,7 +1543,10 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
return List.of();
}
QueryWrapper query = QueryWrapper.create()
.select(EBIKE_BIKE_INFO.ALL_COLUMNS,EBIKE_ECU_INFO.ECU_SN)
.select(EBIKE_BIKE_INFO.ALL_COLUMNS,case_(EBIKE_BIKE_INFO.STATE)
.when("2").then("待使用")
.when("3").then("骑行中")
.when("4").then("待维修").end().as(ResEbikeInfoRegionDto::getStateName),EBIKE_ECU_INFO.ECU_SN)
.leftJoin(EBIKE_ECU_INFO).on(EBIKE_BIKE_INFO.ECU_ID.eq(EBIKE_ECU_INFO.ECU_ID))
.where(EBIKE_BIKE_INFO.STATE.in(new String[]{"2", "3", "4"}))
.where(EBIKE_BIKE_INFO.IS_IN_WAREHOUSE.eq("0"))
@ -1565,7 +1568,11 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
resEbikeInfoRegionDto.setLatitude(resGPSDto.getLatitude());
resEbikeInfoRegionDto.setLongitude(resGPSDto.getLongitude());
resEbikeInfoRegionDto.setSoc(resGPSDto.getSoc());
resEbikeInfoRegionDto.setLatestTimestamp(String.valueOf(resGPSDto.getLatestTimestamp()));
Number latestTimestamp = resGPSDto.getLatestTimestamp();
if (latestTimestamp != null) {
resEbikeInfoRegionDto.setLatestTimestamp(String.valueOf(latestTimestamp));
resEbikeInfoRegionDto.setIntervalTime(TimeUtils.hoursSince(latestTimestamp.longValue()));
}
resEbikeInfoRegionDto.setInOperation(resGPSDto.getInOperation());
resEbikeInfoRegionDto.setInParking(resGPSDto.getInParking());
});

View File

@ -1,83 +0,0 @@
package com.cdzy.ebikemaintenance.test;
import com.mybatisflex.codegen.Generator;
import com.mybatisflex.codegen.config.GlobalConfig;
import com.zaxxer.hikari.HikariDataSource;
public class Tese {
private static String path="D://20250220/共享单车/java/ebike_maintenance";
private static String mapperPath="D://20250220/共享单车/java/ebike_maintenance/resources/mapper";
private static String Strpackage="com.cdzy.ebikeseversetest";
private static String tables="ebike_ecu_info";
public static void main(String[] args) {
//配置数据源
HikariDataSource dataSource = new HikariDataSource();
dataSource.setJdbcUrl("jdbc:mysql://192.168.2.226:3306/ebike_maintenance?characterEncoding=utf-8");
dataSource.setUsername("root");
dataSource.setPassword("970529");
//生成全库的
GlobalConfig globalConfig = createGlobalConfigUseStyle1();
//单表的
// GlobalConfig globalConfig = createGlobalConfigUseStyle2();
Generator generator = new Generator(dataSource, globalConfig);
//生成代码
generator.generate();
}
public static GlobalConfig createGlobalConfigUseStyle1() {
// 创建配置内容
GlobalConfig globalConfig = new GlobalConfig();
// 设置项目源目录和基础包
globalConfig.getPackageConfig()
.setSourceDir(path)
.setBasePackage(Strpackage);
// 启用生成 entity并启用 Lombok
globalConfig.setEntityGenerateEnable(true);
globalConfig.setEntityWithLombok(true);
// 设置项目的JDK版本
globalConfig.setEntityJdkVersion(17);
// 启用生成 mapperservicecontroller
globalConfig.enableEntity();
globalConfig.enableMapper();
globalConfig.enableService();
globalConfig.enableServiceImpl();
globalConfig.enableController();
globalConfig.enableMapperXml();
globalConfig.setMapperXmlPath(mapperPath);
// 配置 Mapper XML 生成路径和文件名
globalConfig.getMapperXmlConfig()
.setFilePrefix("") // 设置合适的前缀
.setFileSuffix("Mapper"); // 确保设置正确的后缀名
return globalConfig;
}
public static GlobalConfig createGlobalConfigUseStyle2() {
// 创建配置内容
GlobalConfig globalConfig = new GlobalConfig();
// 设置项目源目录和基础包
globalConfig.getPackageConfig()
.setSourceDir(path)
.setBasePackage(Strpackage);
// 启用生成 entity并启用 Lombok
globalConfig.setEntityGenerateEnable(true);
globalConfig.setEntityWithLombok(true);
// 设置项目的JDK版本
globalConfig.setEntityJdkVersion(17);
// 启用生成 mapperservicecontroller
globalConfig.enableEntity();
globalConfig.enableMapper();
globalConfig.enableService();
globalConfig.enableServiceImpl();
globalConfig.enableController();
globalConfig.enableMapperXml();
globalConfig.setMapperXmlPath(mapperPath);
// 配置 Mapper XML 生成路径和文件名
globalConfig.getMapperXmlConfig()
.setFilePrefix("") // 设置合适的前缀
.setFileSuffix("Mapper"); // 确保设置正确的后缀名
//设置表前缀和只生成哪些表
// globalConfig.setTablePrefix("tb_");
globalConfig.setGenerateTable(tables);
// 返回配置
return globalConfig;
}
}

View File

@ -0,0 +1,211 @@
package com.cdzy.ebikemaintenance.utils;
import java.time.*;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* @author attiya
* @since 2025-04-17
*/
public class TimeUtils {
// 禁止实例化
private TimeUtils() {
throw new AssertionError("Cannot instantiate utility class");
}
// region 时间比较
/**
* 判断时间1是否在时间2之后
*/
public static boolean isAfter(LocalDateTime time1, LocalDateTime time2) {
Objects.requireNonNull(time1, "time1 must not be null");
Objects.requireNonNull(time2, "time2 must not be null");
return time1.isAfter(time2);
}
/**
* 判断时间1是否在时间2之前
*/
public static boolean isBefore(LocalDateTime time1, LocalDateTime time2) {
Objects.requireNonNull(time1, "time1 must not be null");
Objects.requireNonNull(time2, "time2 must not be null");
return time1.isBefore(time2);
}
/**
* 判断两个时间是否相等
*/
public static boolean isEqual(LocalDateTime time1, LocalDateTime time2) {
Objects.requireNonNull(time1, "time1 must not be null");
Objects.requireNonNull(time2, "time2 must not be null");
return time1.equals(time2);
}
// endregion
// region 时间差计算
/**
* 计算两个时间之间的天数差
*/
public static long betweenDays(LocalDateTime start, LocalDateTime end) {
Objects.requireNonNull(start, "start time must not be null");
Objects.requireNonNull(end, "end time must not be null");
return ChronoUnit.DAYS.between(start, end);
}
/**
* 计算两个时间之间的小时差
*/
public static long betweenHours(LocalDateTime start, LocalDateTime end) {
Objects.requireNonNull(start, "start time must not be null");
Objects.requireNonNull(end, "end time must not be null");
return ChronoUnit.HOURS.between(start, end);
}
/**
* 计算两个时间之间的分钟差
*/
public static long betweenMinutes(LocalDateTime start, LocalDateTime end) {
Objects.requireNonNull(start, "开始时间不能为空");
Objects.requireNonNull(end, "结束时间不能为空");
return ChronoUnit.MINUTES.between(start, end);
}
/**
* 计算两个时间之间的分钟差
*/
public static long betweenMinutes(LocalTime start, LocalTime end) {
Objects.requireNonNull(start, "开始时间不能为空");
Objects.requireNonNull(end, "结束时间不能为空");
return ChronoUnit.MINUTES.between(start, end);
}
/**
* 计算两个时间之间的秒数差
*/
public static long betweenSeconds(LocalDateTime start, LocalDateTime end) {
Objects.requireNonNull(start, "开始时间不能为空");
Objects.requireNonNull(end, "结束时间不能为空");
return ChronoUnit.SECONDS.between(start, end);
}
// endregion
// region 时间加减
/**
* 增加指定时间量
* @param time 原始时间
* @param amount 时间量正数为加负数为减
* @param unit 时间单位
* @return 计算后的新时间
*/
public static LocalDateTime plus(LocalDateTime time, long amount, ChronoUnit unit) {
Objects.requireNonNull(time, "time must not be null");
return time.plus(amount, unit);
}
/**
* 减少指定时间量
* @param time 原始时间
* @param amount 时间量正数为减负数为加
* @param unit 时间单位
* @return 计算后的新时间
*/
public static LocalDateTime minus(LocalDateTime time, long amount, ChronoUnit unit) {
Objects.requireNonNull(time, "time must not be null");
return time.minus(amount, unit);
}
// endregion
// region 快捷操作
/**
* 获取当前时间
*/
public static LocalDateTime now() {
return LocalDateTime.now();
}
/**
* 转换为指定时区的时间默认系统时区
*/
public static ZonedDateTime toZonedDateTime(LocalDateTime time, ZoneId zoneId) {
Objects.requireNonNull(time, "time must not be null");
return time.atZone(zoneId != null ? zoneId : ZoneId.systemDefault());
}
/**
* 获取星期几的数字字符串表示ISO-8601 标准周一=1 周日=7
* @param dateTime 目标时间
* @return 1-7 的整数
*/
public static String getDayOfWeekNumber(LocalDateTime dateTime) {
return String.valueOf(dateTime.getDayOfWeek().getValue());
}
/**
* 判断两个时间是否跨天
* @param time1 时间1
* @param time2 时间2
* @return true=跨天 | false=未跨天
*/
public static boolean isCrossDay(LocalDateTime time1, LocalDateTime time2) {
return !time1.toLocalDate().equals(time2.toLocalDate());
}
/**
* 计算两个时间的自然日间隔天数忽略时间部分
* @param start 开始时间
* @param end 结束时间
* @return 间隔自然日天数end >= start 返回正数反之返回负数
*/
public static long daysBetween(LocalDateTime start, LocalDateTime end) {
return ChronoUnit.DAYS.between(
start.toLocalDate(),
end.toLocalDate()
);
}
/**
* 判断目标时间是否在时间范围内支持跨天时间
* @param target 要检查的时间
* @param start 开始时间
* @param end 结束时间
* @return 是否在时间范围内
*/
public static boolean isTimeWithinRange(LocalTime target,
LocalTime start,
LocalTime end) {
// 处理跨天时间的情况 22:00 - 02:00
if (start.isAfter(end)) {
return !target.isBefore(start) || !target.isAfter(end);
}
// 普通时间范围判断
return !target.isBefore(start) && !target.isAfter(end);
}
/**
* 计算时间戳到当前时间的小时间隔整数
* @param timestamp 毫秒时间戳
* @return 间隔小时数向下取整
*/
public static int hoursSince(long timestamp) {
long now = System.currentTimeMillis();
return (int) Duration.between(
Instant.ofEpochMilli(timestamp),
Instant.ofEpochMilli(now)
).toHours();
}
}