diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java index c953032..13d3710 100644 --- a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java +++ b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java @@ -51,4 +51,7 @@ public interface RemoteVehicleService { @GetMapping("/findByVIN/{vin}") public Result> findByVIN(@PathVariable("vin") String vin); + @GetMapping("onOrOutLineByVIN") + public Integer onOrOutLineByVIN(@RequestParam("params") String params); + } diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/factory/RemoteVehicleFallbackFactory.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/factory/RemoteVehicleFallbackFactory.java index 8084062..d630f15 100644 --- a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/factory/RemoteVehicleFallbackFactory.java +++ b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/factory/RemoteVehicleFallbackFactory.java @@ -51,6 +51,12 @@ public class RemoteVehicleFallbackFactory implements FallbackFactory { Integer addVehicle(VehicleMiddle vehicleMiddle); List vehicleAll(); + + Integer onOrOutLineByVIN(@Param("vin") String vin, @Param("status") Integer status); } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/VehicleService.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/VehicleService.java index 954fe8b..f692152 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/VehicleService.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/VehicleService.java @@ -37,4 +37,6 @@ public interface VehicleService extends IService { List vehicleAll(); + Integer onOrOutLineByVIN(String vin,Integer status); + } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleServiceImpl.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleServiceImpl.java index 1ee5a95..92971e0 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleServiceImpl.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleServiceImpl.java @@ -97,7 +97,7 @@ public class VehicleServiceImpl extends ServiceImpl impl **/ @Override public String deleteById(Long vehicleId) { - String result = ""; + String result; UpdateWrapper updateWrapper = new UpdateWrapper<>(); @@ -125,7 +125,7 @@ public class VehicleServiceImpl extends ServiceImpl impl **/ @Override public String editById(VehicleEditParams editParams) { - String result = ""; + String result; if ((editParams.getLogoIds() == null || editParams.getLogoIds().isEmpty())) { result = "未选择电子围栏"; @@ -180,7 +180,7 @@ public class VehicleServiceImpl extends ServiceImpl impl **/ @Override public String insert(VehicleInsertParams insertParams) { - String result = ""; + String result; if ((insertParams.getLogoIds() == null || insertParams.getLogoIds().isEmpty())) { result = "未选择电子围栏"; @@ -249,14 +249,13 @@ public class VehicleServiceImpl extends ServiceImpl impl **/ @Override public List getBindLogoById(Long vehicleId) { - List logoIds = vehicleAndLogoService.getBindLogoById(vehicleId); - return logoIds; + return vehicleAndLogoService.getBindLogoById(vehicleId); } /* * @param userId: - * @return List + * @return List * @author 付凡芮 * @description 根据登入人id查询管理车辆 * @@ -282,6 +281,14 @@ public class VehicleServiceImpl extends ServiceImpl impl return vehicleMapper.vehicleAll(); } + + //通过vin修改车辆上下线的状态 + @Override + public Integer onOrOutLineByVIN(String vin, Integer status) { + + return vehicleMapper.onOrOutLineByVIN(vin, status); + } + @Override public List findByVIN(String vin) { diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/time/Timer.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/time/Timer.java new file mode 100644 index 0000000..1ed0c20 --- /dev/null +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/time/Timer.java @@ -0,0 +1,62 @@ +package com.couplet.business.time; + +import com.couplet.business.server.service.VehicleService; +import com.couplet.common.domain.Vehicle; +import com.couplet.common.domain.request.VehicleListParams; +import com.couplet.common.redis.service.RedisService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * @ProjectName: five-groups-couplet + * @Author: LiuYunHu + * @CreateTime: 2024/4/4 + * @Description: 车辆定时器 + */ +@Component +@Slf4j +public class Timer { + //redis + @Autowired + private RedisService redis; + //查询车辆列表 + @Autowired + private VehicleService vehicleService; + + + //判断车辆是否下线 + @Scheduled(cron = "* * * * * *") + public void outLine() { + log.info("定时器启动"); + + //先查询车辆列表 + List list = vehicleService.list(new VehicleListParams(null, null, null, null)); + + list.forEach(vehicle -> { + + //只针对已经上线的车辆 + if (redis.hasKey(vehicle.getVin())) { + + //如果vin的缓存 时间还剩一秒,则判断为已经下线 + if (redis.getExpire(vehicle.getVin()) <= 3) { + log.info(vehicle.getVin() + "的车辆已经下线"); + + //执行修改下线状态的方法 + Integer i = vehicleService.onOrOutLineByVIN(vehicle.getVin(), 0); + + if (0 == 1) { + log.error("下线状态修改失败"); + } + + log.info("下线状态修改成功"); + } + } + + + }); + } +} diff --git a/couplet-modules/couplet-business/src/main/resources/bootstrap.yml b/couplet-modules/couplet-business/src/main/resources/bootstrap.yml index cf4e9b6..dd7da4f 100644 --- a/couplet-modules/couplet-business/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-business/src/main/resources/bootstrap.yml @@ -16,9 +16,11 @@ spring: discovery: # 服务注册地址 server-addr: 121.89.211.230:8848 + namespace: 172469 config: # 配置中心地址 server-addr: 121.89.211.230:8848 + namespace: 172469 # 配置文件格式 file-extension: yml # 共享配置 diff --git a/couplet-modules/couplet-business/src/main/resources/mapper/business/VehicleMapper.xml b/couplet-modules/couplet-business/src/main/resources/mapper/business/VehicleMapper.xml index 4eb95a7..718b615 100644 --- a/couplet-modules/couplet-business/src/main/resources/mapper/business/VehicleMapper.xml +++ b/couplet-modules/couplet-business/src/main/resources/mapper/business/VehicleMapper.xml @@ -6,35 +6,32 @@ - SELECT - m.middle_id, - m.user_id, - m.vehicle_id, - m.del_flag, - v.vehicle_type, - v.motor_manufacturer, - v.battery_manufacturer, - v.motor_number, - v.battery_number, - v.vin, - v.vehicle_state, - t.vehicle_type_name - FROM - `couplet_middle` m - LEFT JOIN couplet_vehicle v ON m.vehicle_id = v.vehicle_id - LEFT JOIN couplet_vehicle_type t ON v.vehicle_id = t.vehicle_type_id + SELECT m.middle_id, + m.user_id, + m.vehicle_id, + m.del_flag, + v.vehicle_type, + v.motor_manufacturer, + v.battery_manufacturer, + v.motor_number, + v.battery_number, + v.vin, + v.vehicle_state, + t.vehicle_type_name + FROM `couplet_middle` m + LEFT JOIN couplet_vehicle v ON m.vehicle_id = v.vehicle_id + LEFT JOIN couplet_vehicle_type t ON v.vehicle_id = t.vehicle_type_id WHERE m.del_flag = 0 - select - v.vehicle_id, - v.motor_manufacturer, - v.battery_manufacturer, - v.motor_number, - v.battery_number, - v.vin, - v.vehicle_state, - t.vehicle_type_name + select v.vehicle_id, + v.motor_manufacturer, + v.battery_manufacturer, + v.motor_number, + v.battery_number, + v.vin, + v.vehicle_state, + t.vehicle_type_name from couplet_vehicle v left join couplet_vehicle_type t on v.vehicle_type = t.vehicle_type_id where v.isdelete = 0 @@ -45,6 +42,15 @@ (#{userId}, #{vehicleId}, 0) + + + + UPDATE `couplet-cloud`.`couplet_vehicle` + SET `vehicle_state` = #{status} + WHERE `vin` = #{vin}; + + + update couplet_middle set del_flag = '2' @@ -53,9 +59,9 @@