diff --git a/fance-menghang-common/src/main/java/com/shiyi/internet/constants/RedisConstants.java b/fance-menghang-common/src/main/java/com/shiyi/internet/constants/RedisConstants.java new file mode 100644 index 0000000..6bfc6ff --- /dev/null +++ b/fance-menghang-common/src/main/java/com/shiyi/internet/constants/RedisConstants.java @@ -0,0 +1,29 @@ +package com.shiyi.internet.constants; + +/** + * @Description : Redis常量 + * @Author : YangHaoYu + * @Date: 2023-11-22 19:29 + */ +public class RedisConstants { + + /** + *实时信息 + */ + public static final String CURRENT_INFO = "current_info"; + + /** + * 当日警告数 + */ + public static final String CURRENT_DAY_FAULT = "current_day_fault"; + + /** + *当月警告数 + */ + public static final String CURRENT_MONTH_FAULT = "current_month_fault"; + + /** + * 车辆有关信息标识 + */ + public static final String VEHICLE_INFO_TOKEN = "vehicle_info_token"; +} diff --git a/fance-menghang-common/src/main/java/com/shiyi/internet/constants/VehicleConstant.java b/fance-menghang-common/src/main/java/com/shiyi/internet/constants/VehicleConstant.java new file mode 100644 index 0000000..e59ead6 --- /dev/null +++ b/fance-menghang-common/src/main/java/com/shiyi/internet/constants/VehicleConstant.java @@ -0,0 +1,28 @@ +package com.shiyi.internet.constants; + +/** + * @Description : + * @Author : YangHaoYu + * @Date: 2023-11-23 11:33 + */ +public class VehicleConstant { + /** + * 车辆启动 + */ + public static final Integer VEHICLE_START = 1; + + /** + * 车辆停止 + */ + public static final Integer VEHICLE_END = 0; + + /** + * 车辆状态更改队列 + */ + public static final String VEHICLE_STATUS_UPDATE_QUEUE = "vehicle_status_update_queue"; + + /** + * 车辆信息前缀 + */ + public static final String VEHICLE_INFO_MAP = "vehicle_info_map"; +} diff --git a/fance-menghang-common/src/main/java/com/shiyi/internet/domain/Car.java b/fance-menghang-common/src/main/java/com/shiyi/internet/domain/Car.java index 3b82f35..c28a465 100644 --- a/fance-menghang-common/src/main/java/com/shiyi/internet/domain/Car.java +++ b/fance-menghang-common/src/main/java/com/shiyi/internet/domain/Car.java @@ -27,7 +27,7 @@ public class Car extends BaseEntity { @ApiModelProperty("车辆ID") @TableId(value = "car_id", type = IdType.AUTO) - private Integer carId; + private String carId; @ApiModelProperty("车辆名称") @TableField("car_name") @@ -37,6 +37,14 @@ public class Car extends BaseEntity { @TableField("car_license") private String carLicense; + @ApiModelProperty("车辆vin") + @TableField("car_vin") + private String carVin; + + @ApiModelProperty("车辆状态") + @TableField("car_status") + private String car_status; + @ApiModelProperty("车辆类型") @TableField("type_id") private Integer typeId; diff --git a/fance-menghang-common/src/main/java/com/shiyi/internet/domain/VehicleMessage.java b/fance-menghang-common/src/main/java/com/shiyi/internet/domain/VehicleMessage.java new file mode 100644 index 0000000..e0d669b --- /dev/null +++ b/fance-menghang-common/src/main/java/com/shiyi/internet/domain/VehicleMessage.java @@ -0,0 +1,737 @@ +package com.shiyi.internet.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +/** + * @Description : 车辆实时数据 + * @Author : YangHaoYu + * @Date: 2023-11-22 19:58 + */ +@Data +@SuperBuilder +@AllArgsConstructor +@NoArgsConstructor +public class VehicleMessage { + /** + * 消息标识 + */ + private String identifier; + + /** + * VIN码 + */ + private String vin; + + /** + * 经度 + */ + private String longitude; + + /** + * 纬度 + */ + private String latitude; + + /** + * 车速 + */ + private String speed; + + /** + * 总里程 + */ + private String totalDistance; + + /** + * 总电压 + */ + private String totalVoltage; + + /** + * 总电流 + */ + private String jointCurrent; + + /** + * 绝缘电阻 + */ + private String insulationResistance; + + /** + * 档位 + */ + private String gears; + + /** + * 加速踏板行程值 + */ + private String acceleratorPedal; + + /** + * 制动踏板行程值 + */ + private String brakePedal; + + /** + * 燃料消耗率 + */ + private String fuelRate; + + /** + * 电机控制器温度 + */ + private String motorControllerTemperature; + + /** + * 电机转速 + */ + private String motorSpeed; + + /** + * 电机转矩 + */ + private String motorTorque; + + /** + * 电机温度 + */ + private String motorTemperature; + + /** + * 电机电压 + */ + private String motorVoltage; + + /** + * 电机电流 + */ + private String motorCurrent; + + /** + * 动力电池剩余电量SOC + */ + private String dumpEnergy; + + /** + * 当前状态允许的最大反馈功率 + */ + private String maximumFeedbackPower; + + /** + * 当前状态允许最大放电功率 + */ + private String maximumDischargePower; + + /** + * BMS自检计数器 + */ + private String selfCheckingCounter; + + /** + * 动力电池充放电电流 + */ + private String chargingAndDischargingCurrent; + + /** + * 动力电池负载端总电压V3 + */ + private String totalVoltageAtLoadEnd; + + /** + * 单次最大电压 + */ + private String maximumVoltage; + + /** + * 单体电池最低电压 + */ + private String lowestVoltageBattery; + + /** + * 单体电池最高温度 + */ + private String maximumTemperatureBattery; + + /** + * 单体电池最低温度 + */ + private String lowestTemperatureBattery; + + /** + * 动力电池可用容量 + */ + private String availableBatteryCapacity; + + /** + * 车辆状态 + */ + private Integer vehicleState; + + /** + * 充电状态 + */ + private Integer chargingState; + + /** + * 运行状态 + */ + private Integer runningStatus; + + /** + * SOC + */ + private Integer socStatus; + + /** + * 可充电储能装置工作状态 + */ + private Integer energyStorageDeviceState; + + /** + * 驱动电机状态 + */ + private Integer driveMotorCondition; + + /** + * 定位是否有效 + */ + private Integer positioningState; + + /** + * EAS 电子防窃系统状态 + */ + private Integer easStatus; + + /** + * PTC 传动系统状态 + */ + private Integer ptcStatus; + + /** + * EPS 蓄电池状态 + */ + private Integer epsStatus; + + /** + * ABS 防滑刹车系统状态 + */ + private Integer absStatus; + + /** + * MCU 微处理器状态 + */ + private Integer mcuStatus; + + /** + * 动力电池加热状态 + */ + private Integer batteryHeatingCondition; + + /** + * 动力电池当前状态 + */ + private Integer currentBatteryStatus; + + /** + * 动力电池保温状态 + */ + private Integer batteryInsulationStatus; + + /** + * DCDC 电力交换系统状态 + */ + private Integer dcdcStatus; + + /** + * CHG 充电机状态 + */ + private Integer chgStatus; + + /** + *时间 + */ + private Long time; + + public Long getTime() { + return time; + } + + public void setTime(Object time) { + if(time != null){ + this.time = Long.valueOf(time.toString()); + } + } + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(Object identifier) { + if(identifier != null) { + this.identifier = (String) identifier; + } + } + + public String getVin() { + return vin; + } + + public void setVin(Object vin) { + if(vin != null) { + this.vin = (String) vin; + } + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(Object longitude) { + if(longitude != null) { + this.longitude = (String) longitude; + } + } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(Object latitude) { + if(latitude != null) { + this.latitude = (String) latitude; + } + } + + public String getSpeed() { + return speed; + } + + public void setSpeed(Object speed) { + if(speed != null) { + this.speed = (String) speed; + } + } + + public String getTotalDistance() { + return totalDistance; + } + + public void setTotalDistance(Object totalDistance) { + if(totalDistance != null) { + this.totalDistance = (String) totalDistance; + } + } + + public String getTotalVoltage() { + return totalVoltage; + } + + public void setTotalVoltage(Object totalVoltage) { + if(totalVoltage != null) { + this.totalVoltage = (String) totalVoltage; + } + } + + public String getJointCurrent() { + return jointCurrent; + } + + public void setJointCurrent(Object jointCurrent) { + if(jointCurrent != null) { + this.jointCurrent = (String) jointCurrent; + } + } + + public String getInsulationResistance() { + return insulationResistance; + } + + public void setInsulationResistance(Object insulationResistance) { + if(insulationResistance != null) { + this.insulationResistance = (String) insulationResistance; + } + } + + public String getGears() { + return gears; + } + + public void setGears(Object gears) { + if(gears != null) { + this.gears = (String) gears; + } + } + + public String getAcceleratorPedal() { + return acceleratorPedal; + } + + public void setAcceleratorPedal(Object acceleratorPedal) { + if(acceleratorPedal != null) { + this.acceleratorPedal = (String) acceleratorPedal; + } + } + + public String getBrakePedal() { + return brakePedal; + } + + public void setBrakePedal(Object brakePedal) { + if(brakePedal != null) { + this.brakePedal = (String) brakePedal; + } + } + + public String getFuelRate() { + return fuelRate; + } + + public void setFuelRate(Object fuelRate) { + if(fuelRate != null) { + this.fuelRate = (String) fuelRate; + } + } + + public String getMotorControllerTemperature() { + return motorControllerTemperature; + } + + public void setMotorControllerTemperature(Object motorControllerTemperature) { + if(motorControllerTemperature != null) { + this.motorControllerTemperature = (String) motorControllerTemperature; + } + } + + public String getMotorSpeed() { + return motorSpeed; + } + + public void setMotorSpeed(Object motorSpeed) { + if(motorSpeed != null) { + this.motorSpeed = (String) motorSpeed; + } + } + + public String getMotorTorque() { + return motorTorque; + } + + public void setMotorTorque(Object motorTorque) { + if(motorTorque != null) { + this.motorTorque = (String) motorTorque; + } + } + + public String getMotorTemperature() { + return motorTemperature; + } + + public void setMotorTemperature(Object motorTemperature) { + if(motorTemperature != null) { + this.motorTemperature = (String) motorTemperature; + } + } + + public String getMotorVoltage() { + return motorVoltage; + } + + public void setMotorVoltage(Object motorVoltage) { + if(motorVoltage != null) { + this.motorVoltage = (String) motorVoltage; + } + } + + public String getMotorCurrent() { + return motorCurrent; + } + + public void setMotorCurrent(Object motorCurrent) { + if(motorCurrent != null) { + this.motorCurrent = (String) motorCurrent; + } + } + + public String getDumpEnergy() { + return dumpEnergy; + } + + public void setDumpEnergy(Object dumpEnergy) { + if(dumpEnergy != null) { + this.dumpEnergy = (String) dumpEnergy; + } + } + + public String getMaximumFeedbackPower() { + return maximumFeedbackPower; + } + + public void setMaximumFeedbackPower(Object maximumFeedbackPower) { + if(maximumFeedbackPower != null) { + this.maximumFeedbackPower = (String) maximumFeedbackPower; + } + } + + public String getMaximumDischargePower() { + return maximumDischargePower; + } + + public void setMaximumDischargePower(Object maximumDischargePower) { + if(maximumDischargePower != null) { + this.maximumDischargePower = (String) maximumDischargePower; + } + } + + public String getSelfCheckingCounter() { + return selfCheckingCounter; + } + + public void setSelfCheckingCounter(Object selfCheckingCounter) { + if(selfCheckingCounter != null) { + this.selfCheckingCounter = (String) selfCheckingCounter; + } + } + + public String getChargingAndDischargingCurrent() { + return chargingAndDischargingCurrent; + } + + public void setChargingAndDischargingCurrent(Object chargingAndDischargingCurrent) { + if(chargingAndDischargingCurrent != null) { + this.chargingAndDischargingCurrent = (String) chargingAndDischargingCurrent; + } + } + + public String getTotalVoltageAtLoadEnd() { + return totalVoltageAtLoadEnd; + } + + public void setTotalVoltageAtLoadEnd(Object totalVoltageAtLoadEnd) { + if(totalVoltageAtLoadEnd != null) { + this.totalVoltageAtLoadEnd = (String) totalVoltageAtLoadEnd; + } + } + + public String getMaximumVoltage() { + return maximumVoltage; + } + + public void setMaximumVoltage(Object maximumVoltage) { + if(maximumVoltage != null) { + this.maximumVoltage = (String) maximumVoltage; + } + } + + public String getLowestVoltageBattery() { + return lowestVoltageBattery; + } + + public void setLowestVoltageBattery(Object lowestVoltageBattery) { + if(lowestVoltageBattery != null) { + this.lowestVoltageBattery = (String) lowestVoltageBattery; + } + } + + public String getMaximumTemperatureBattery() { + return maximumTemperatureBattery; + } + + public void setMaximumTemperatureBattery(Object maximumTemperatureBattery) { + if(maximumTemperatureBattery != null) { + this.maximumTemperatureBattery = (String) maximumTemperatureBattery; + } + } + + public String getLowestTemperatureBattery() { + return lowestTemperatureBattery; + } + + public void setLowestTemperatureBattery(Object lowestTemperatureBattery) { + if(lowestTemperatureBattery != null) { + this.lowestTemperatureBattery = (String) lowestTemperatureBattery; + } + } + + public String getAvailableBatteryCapacity() { + return availableBatteryCapacity; + } + + public void setAvailableBatteryCapacity(Object availableBatteryCapacity) { + if(availableBatteryCapacity != null) { + this.availableBatteryCapacity = (String) availableBatteryCapacity; + } + } + + public Integer getVehicleState() { + return vehicleState; + } + + public void setVehicleState(Object vehicleState) { + if(vehicleState != null) { + this.vehicleState = Integer.valueOf(vehicleState.toString()); + } + } + + public Integer getChargingState() { + return chargingState; + } + + public void setChargingState(Object chargingState) { + if(chargingState != null) { + this.chargingState = Integer.valueOf(chargingState.toString()); + } + } + + public Integer getRunningStatus() { + return runningStatus; + } + + public void setRunningStatus(Object runningStatus) { + if(runningStatus != null){ + this.runningStatus = Integer.valueOf(runningStatus.toString()); + } + } + + public Integer getSocStatus() { + return socStatus; + } + + public void setSocStatus(Object socStatus) { + if(socStatus != null) { + this.socStatus = Integer.valueOf(socStatus.toString()); + } + } + + public Integer getEnergyStorageDeviceState() { + return energyStorageDeviceState; + } + + public void setEnergyStorageDeviceState(Object energyStorageDeviceState) { + if(energyStorageDeviceState != null){ + this.energyStorageDeviceState = Integer.valueOf(energyStorageDeviceState.toString()); + } + } + + public Integer getDriveMotorCondition() { + return driveMotorCondition; + } + + public void setDriveMotorCondition(Object driveMotorCondition) { + if(driveMotorCondition != null) { + this.driveMotorCondition = Integer.valueOf(driveMotorCondition.toString()); + } + } + + public Integer getPositioningState() { + return positioningState; + } + + public void setPositioningState(Object positioningState) { + if(positioningState != null) { + this.positioningState = Integer.valueOf(positioningState.toString()); + } + } + + public Integer getEasStatus() { + return easStatus; + } + + public void setEasStatus(Object easStatus) { + if(easStatus != null) { + this.easStatus = Integer.valueOf(easStatus.toString()); + } + } + + public Integer getPtcStatus() { + return ptcStatus; + } + + public void setPtcStatus(Object ptcStatus) { + if(ptcStatus != null) { + this.ptcStatus = Integer.valueOf(ptcStatus.toString()); + } + } + + public Integer getEpsStatus() { + return epsStatus; + } + + public void setEpsStatus(Object epsStatus) { + if(epsStatus != null) { + this.epsStatus = Integer.valueOf(epsStatus.toString()); + } + } + + public Integer getAbsStatus() { + return absStatus; + } + + public void setAbsStatus(Object absStatus) { + if(absStatus != null) { + this.absStatus = Integer.valueOf(absStatus.toString()); + } + } + + public Integer getMcuStatus() { + return mcuStatus; + } + + public void setMcuStatus(Object mcuStatus) { + if(mcuStatus != null) { + this.mcuStatus = Integer.valueOf(mcuStatus.toString()); + } + } + + public Integer getBatteryHeatingCondition() { + return batteryHeatingCondition; + } + + public void setBatteryHeatingCondition(Object batteryHeatingCondition) { + if(batteryHeatingCondition != null) { + this.batteryHeatingCondition = Integer.valueOf(batteryHeatingCondition.toString()); + } + } + + public Integer getCurrentBatteryStatus() { + return currentBatteryStatus; + } + + public void setCurrentBatteryStatus(Object currentBatteryStatus) { + if(currentBatteryStatus != null){ + this.currentBatteryStatus = Integer.valueOf(currentBatteryStatus.toString()); + } + } + + public Integer getBatteryInsulationStatus() { + return batteryInsulationStatus; + } + + public void setBatteryInsulationStatus(Object batteryInsulationStatus) { + if(batteryInsulationStatus != null){ + this.batteryInsulationStatus = Integer.valueOf(batteryInsulationStatus.toString()); + } + } + + public Integer getDcdcStatus() { + return dcdcStatus; + } + + public void setDcdcStatus(Object dcdcStatus) { + if(dcdcStatus != null) { + this.dcdcStatus = Integer.valueOf(dcdcStatus.toString()); + } + } + + public Integer getChgStatus() { + return chgStatus; + } + + public void setChgStatus(Object chgStatus) { + if(chgStatus != null) { + this.chgStatus = Integer.valueOf(chgStatus.toString()); + } + } +} diff --git a/fance-menghang-remote/src/main/java/com/shiyi/vehicle/feign/VehicleFeign.java b/fance-menghang-remote/src/main/java/com/shiyi/vehicle/feign/VehicleFeign.java new file mode 100644 index 0000000..29d6583 --- /dev/null +++ b/fance-menghang-remote/src/main/java/com/shiyi/vehicle/feign/VehicleFeign.java @@ -0,0 +1,12 @@ +package com.shiyi.vehicle.feign; + +import org.springframework.cloud.openfeign.FeignClient; + +/** + * @Description : 接口调用 + * @Author : YangHaoYu + * @Date: 2023-11-23 11:13 + */ +@FeignClient(name = "fate-fence") +public interface VehicleFeign { +} diff --git a/fance-menghang-service/src/main/java/com/shiyi/internet/controller/DrivingRecordController.java b/fance-menghang-service/src/main/java/com/shiyi/internet/controller/DrivingRecordController.java index aa757d9..3fdab30 100644 --- a/fance-menghang-service/src/main/java/com/shiyi/internet/controller/DrivingRecordController.java +++ b/fance-menghang-service/src/main/java/com/shiyi/internet/controller/DrivingRecordController.java @@ -39,7 +39,7 @@ public class DrivingRecordController extends BaseController { * @Updator: YHY * @Date 2023/11/21 14:38 */ - //@RequiresPermissions("record:record:list") + @RequiresPermissions("record:record:list") @GetMapping("/list") public Result> list(DrivingRecord drivingRecord){ log.info("功能名称:车辆行驶记录,请求URL:【{}】,请求方法:【{}】",request.getRequestURI(), @@ -55,8 +55,8 @@ public class DrivingRecordController extends BaseController { * @param response * @param drivingRecord */ - //@RequiresPermissions("record:record:export") - //@Log(title = "导出车辆行驶记录", businessType = BusinessType.EXPORT) + @RequiresPermissions("record:record:export") + @Log(title = "导出车辆行驶记录", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response ,DrivingRecord drivingRecord){ Result> list = drivingRecordService.listDriving(drivingRecord); //车辆行驶车辆对象 @@ -87,8 +87,8 @@ public class DrivingRecordController extends BaseController { * @param drivingRecord * @return */ - //@RequiresPermissions("record:record:insertDriving") - //@Log(title = "车辆行驶记录", businessType = BusinessType.INSERT) + @RequiresPermissions("record:record:insertDriving") + @Log(title = "车辆行驶记录", businessType = BusinessType.INSERT) @PostMapping("/insertDriving") public Result insertDriving(@RequestBody DrivingRecord drivingRecord){ log.info("功能名称:添加车辆行驶记录,请求URL:【{}】,请求防范:【{}】,请求参数:【{}】",request.getRequestURI(), @@ -105,8 +105,8 @@ public class DrivingRecordController extends BaseController { * @param drivingRecord * @return */ - //@RequiresPermissions("record:record:updateDrivingRecord") - //@Log(title = "修改车辆行驶记录", businessType = BusinessType.UPDATE) + @RequiresPermissions("record:record:updateDrivingRecord") + @Log(title = "修改车辆行驶记录", businessType = BusinessType.UPDATE) @PostMapping("/updateDrivingRecord") public Result updateDrivingRecord(@RequestBody DrivingRecord drivingRecord){ log.info("功能名称:修改车辆行驶记录,请求URL:【{}】,请求方法:【{}】,请求参数:【{】】",request.getRequestURI(), @@ -123,8 +123,8 @@ public class DrivingRecordController extends BaseController { * @param recordId * @return */ - //@RequiresPermissions("record:record:deleteDrivingRecord") - //@Log(title = "根据ID删除车辆行驶记录", businessType = BusinessType.DELETE) + @RequiresPermissions("record:record:deleteDrivingRecord") + @Log(title = "根据ID删除车辆行驶记录", businessType = BusinessType.DELETE) @PostMapping("/deleteDrivingRecord/{recordId}") public Result deleteDrivingRecord(@PathVariable Integer recordId){ log.info("功能名称:根据ID删除车辆行驶记录,请求URL:【{}】,请求方法:【{}】,请求参数:【{}】",request.getRequestURI(), diff --git a/fance-menghang-service/src/main/java/com/shiyi/internet/controller/VehicleController.java b/fance-menghang-service/src/main/java/com/shiyi/internet/controller/VehicleController.java index d9fa94d..4c3d5ec 100644 --- a/fance-menghang-service/src/main/java/com/shiyi/internet/controller/VehicleController.java +++ b/fance-menghang-service/src/main/java/com/shiyi/internet/controller/VehicleController.java @@ -5,8 +5,10 @@ import com.fate.common.core.domain.Result; import com.fate.common.core.utils.poi.ExcelUtil; import com.fate.common.core.web.controller.BaseController; import com.shiyi.internet.domain.Car; +import com.shiyi.internet.domain.VehicleMessage; import com.shiyi.internet.domain.response.ResponseCar; import com.shiyi.internet.service.VehicleService; +import io.swagger.models.auth.In; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -79,8 +81,7 @@ public class VehicleController extends BaseController { public Result addVehicl(@RequestBody Car car){ log.info("功能名称:添加车辆信息,请求URL:【{}】,请求方法:【{}】,请求参数:【{}】",request.getRequestURI(), request.getMethod(),car); - vehicleService.addVehicl(car); - Result result = Result.success(); + Result result = vehicleService.addVehicl(car); log.info("功能名称:添加车辆信息,请求URL:【{}】,请求方法:【{}】,响应结果:【{}】",request.getRequestURI(), request.getMethod(), JSONObject.toJSONString(result)); return result; @@ -105,6 +106,7 @@ public class VehicleController extends BaseController { return result; } + /** * @Description:修改车辆管理 No such property: code for class: Script1 @@ -137,4 +139,63 @@ public class VehicleController extends BaseController { ExcelUtil carExcelUtil = new ExcelUtil<>(ResponseCar.class); carExcelUtil.exportExcel(response,list.getData(),"车辆信息"); } + + + /** + * @Description:修改车辆状态 + No such property: code for class: Script1 + * @return: com.fate.common.core.domain.Result + * @Author: YHY + * @Updator: YHY + * @Date 2023/11/23 11:18 + */ + @PostMapping("/updateVehicleStatus/{vin}/{status}") + public Result updateVehicleStatus(@PathVariable("vin") String vin, @PathVariable("status")Integer status){ + log.info("功能名称:修改车辆状态,请求URL:【{}】,请求方法:【{}】,请求参数:【{}】",request.getRequestURI(), + request.getMethod(),vin,status); + Result result = vehicleService.updateVehicleStatus(vin,status); + log.info("功能名称:修改车辆状态,请求URL:【{}】,请求方法:【{}】,响应结果:【{}】",request.getRequestURI(), + request.getMethod(), JSONObject.toJSONString(result)); + return result; + } + + + /** + * @Description:查询所有在线车辆 + No such property: code for class: Script1 + * @return: com.fate.common.core.domain.Result> + * @Author: YHY + * @Updator: YHY + * @Date 2023/11/23 20:27 + */ + @GetMapping("onlineVehicle") + public Result> onlineVehicle(){ + log.info("功能名称:查询所有在线车辆,请求URL:【{}】,请求方法:【{}】",request.getRequestURI(), + request.getMethod()); + Result> result = vehicleService.onlineVehicle(); + log.info("功能名称:查询所有在线车辆,请求URL:【{}】,请求方法:【{}】,响应结果:【{}】",request.getRequestURI(), + request.getMethod(),JSONObject.toJSONString(result)); + return result; + } + + + /** + * @Description:统计数据 + No such property: code for class: Script1 + * @return: com.fate.common.core.domain.Result + * @Author: YHY + * @Updator: YHY + * @Date 2023/11/23 20:42 + */ + @GetMapping("/countData") + public Result countData(){ + log.info("功能名称:统计数据,请求URL:【{}】,请求方法:【{}】",request.getRequestURI(), + request.getMethod()); + Result result = vehicleService.countData(); + log.info("功能名称:统计数据,请求URL:【{}】,请求方法:【{}】,响应结果:【{}】",request.getRequestURI(), + request.getMethod(),JSONObject.toJSONString(result)); + return result; + } + + } diff --git a/fance-menghang-service/src/main/java/com/shiyi/internet/mapper/DrivingRecordMapper.java b/fance-menghang-service/src/main/java/com/shiyi/internet/mapper/DrivingRecordMapper.java index 5a4e0e2..76505d6 100644 --- a/fance-menghang-service/src/main/java/com/shiyi/internet/mapper/DrivingRecordMapper.java +++ b/fance-menghang-service/src/main/java/com/shiyi/internet/mapper/DrivingRecordMapper.java @@ -5,6 +5,7 @@ import com.shiyi.internet.domain.DrivingRecord; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.Date; import java.util.List; /** @@ -38,4 +39,8 @@ public interface DrivingRecordMapper extends BaseMapper { void deleteDrivingRecord(@Param("recordId") Integer recordId); + Integer selectLastId(@Param("carVin") String carVin); + + void endVehicle(@Param("id") Integer id, @Param("date") Date date, @Param("endKey") String endKey); + } diff --git a/fance-menghang-service/src/main/java/com/shiyi/internet/mapper/VehicleMapper.java b/fance-menghang-service/src/main/java/com/shiyi/internet/mapper/VehicleMapper.java index 61c0231..7e4c372 100644 --- a/fance-menghang-service/src/main/java/com/shiyi/internet/mapper/VehicleMapper.java +++ b/fance-menghang-service/src/main/java/com/shiyi/internet/mapper/VehicleMapper.java @@ -2,6 +2,7 @@ package com.shiyi.internet.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.shiyi.internet.domain.Car; +import com.shiyi.internet.domain.DrivingRecord; import com.shiyi.internet.domain.response.ResponseCar; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,9 +20,23 @@ public interface VehicleMapper extends BaseMapper { int deletVehiclById(@Param("carId") Integer carId); - void addVehicl(Car car); + int addVehicl(Car car); ResponseCar findVehiclById(@Param("carId") Integer carId); int updateVehicl(Car car); + + void updateVehicleStatus(@Param("carVin") String carVin, @Param("status") Integer status); + + Car getVehicleInfoByVin(@Param("vin") String vin); + + void insertRecord(DrivingRecord record); + + DrivingRecord selectLastByVin(@Param("carVin") String carVin); + + List getOnlineVehicleIds(); + + Integer getOnlineCount(); + + Integer getUnOnlineCount(); } diff --git a/fance-menghang-service/src/main/java/com/shiyi/internet/service/VehicleService.java b/fance-menghang-service/src/main/java/com/shiyi/internet/service/VehicleService.java index db11e7e..d79a636 100644 --- a/fance-menghang-service/src/main/java/com/shiyi/internet/service/VehicleService.java +++ b/fance-menghang-service/src/main/java/com/shiyi/internet/service/VehicleService.java @@ -3,6 +3,7 @@ package com.shiyi.internet.service; import com.baomidou.mybatisplus.extension.service.IService; import com.fate.common.core.domain.Result; import com.shiyi.internet.domain.Car; +import com.shiyi.internet.domain.VehicleMessage; import com.shiyi.internet.domain.response.ResponseCar; import java.util.List; @@ -18,9 +19,15 @@ public interface VehicleService extends IService { Result deletVehiclById(Integer carId); - void addVehicl(Car car); + Result addVehicl(Car car); ResponseCar findVehiclById(Integer carId); Result updateVehicl(Car car); + + Result updateVehicleStatus(String vin, Integer status); + + Result> onlineVehicle(); + + Result countData(); } diff --git a/fance-menghang-service/src/main/java/com/shiyi/internet/service/impl/VehicleServiceimpl.java b/fance-menghang-service/src/main/java/com/shiyi/internet/service/impl/VehicleServiceimpl.java index e176552..65872f1 100644 --- a/fance-menghang-service/src/main/java/com/shiyi/internet/service/impl/VehicleServiceimpl.java +++ b/fance-menghang-service/src/main/java/com/shiyi/internet/service/impl/VehicleServiceimpl.java @@ -2,26 +2,40 @@ package com.shiyi.internet.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fate.common.core.domain.Result; +import com.shiyi.internet.constants.RedisConstants; +import com.shiyi.internet.constants.VehicleConstant; import com.shiyi.internet.domain.Car; +import com.shiyi.internet.domain.DrivingRecord; +import com.shiyi.internet.domain.VehicleMessage; import com.shiyi.internet.domain.response.ResponseCar; -import com.shiyi.internet.mapper.FencingMapper; +import com.shiyi.internet.mapper.DrivingRecordMapper; import com.shiyi.internet.mapper.VehicleMapper; import com.shiyi.internet.service.VehicleService; +import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; +import java.util.Date; import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; /** * @Description : 车辆系统业务层 * @Author : YHY * @Date: 2023-11-19 21:24 */ +@Log4j2 @Service public class VehicleServiceimpl extends ServiceImpl implements VehicleService { @Autowired private VehicleMapper vehicleMapper; + @Autowired + private DrivingRecordMapper drivingRecordMapper; + + private RedisTemplate redisTemplate; @Override public Result> vehicleList() { @@ -36,9 +50,11 @@ public class VehicleServiceimpl extends ServiceImpl implement } @Override - public void addVehicl(Car car) { - - vehicleMapper.addVehicl(car); + public Result addVehicl(Car car) { + car.setCarId(UUID.randomUUID().toString().replaceAll("-","").toUpperCase()); + int i = vehicleMapper.addVehicl(car); + redisTemplate.opsForHash().put(VehicleConstant.VEHICLE_INFO_MAP,car.getCarVin(),vehicleMapper.getVehicleInfoByVin(car.getCarVin())); + return i>0?Result.success(200,"成功"):Result.error(500,"失败"); } @Override @@ -51,4 +67,56 @@ public class VehicleServiceimpl extends ServiceImpl implement int i = vehicleMapper.updateVehicl(car); return i>0?Result.success(200,"车辆信息已成功修改"):Result.error(500,"修改失败"); } + + @Override + public Result updateVehicleStatus(String carVin, Integer status) { + vehicleMapper.updateVehicleStatus(carVin,status); + if (status.equals(VehicleConstant.VEHICLE_START)){ + DrivingRecord drivingRecord = vehicleMapper.selectLastByVin(carVin); + if (drivingRecord == null){ + DrivingRecord record = new DrivingRecord(); + record.setCarVin(carVin); + record.setStartTime(new Date()); //开始时间 + record.setStartKey(String.valueOf(new Date().getTime())); //开始标识 + log.info("车辆启动:【{}】,时间:【{}】",carVin,new Date().getTime()); + vehicleMapper.insertRecord(record); + return Result.success(); + } + if (drivingRecord != null && drivingRecord.getStartTime() != null && drivingRecord.getEndTime() != null){ + DrivingRecord record = new DrivingRecord(); + record.setCarVin(carVin); + record.setStartTime(new Date()); //开始时间 + record.setStartKey(String.valueOf(new Date().getTime())); //开始标识 + log.info("车辆启动:【{}】,时间:【{}】",carVin,new Date().getTime()); + drivingRecordMapper.insertDriving(record); + } + return Result.success(); + }else { + Integer id =drivingRecordMapper.selectLastId(carVin); + String endKey = String.valueOf(new Date().getTime()); + log.info("车辆停止:【{}】,时间:【{}】",carVin,new Date().getTime()); + drivingRecordMapper.endVehicle(id,new Date(),endKey); + } + return Result.success(); + } + + @Override + public Result> onlineVehicle() { + List ids = vehicleMapper.getOnlineVehicleIds(); + List messages = ids.stream().map(id -> { + String vmString = redisTemplate.opsForValue().get(RedisConstants.CURRENT_INFO + ":" + id); + VehicleMessage message = new VehicleMessage(); + return message; + }).collect(Collectors.toList()); + return Result.success(messages); + } + + @Override + public Result countData() { //响应信息主体 + Integer day = Integer.valueOf(redisTemplate.opsForValue().get(RedisConstants.VEHICLE_INFO_TOKEN + RedisConstants.CURRENT_DAY_FAULT)); + Integer month = Integer.valueOf(redisTemplate.opsForValue().get(RedisConstants.VEHICLE_INFO_TOKEN + RedisConstants.CURRENT_MONTH_FAULT)); + Integer onlineCount = vehicleMapper.getOnlineCount(); + Integer unOnlineCount = vehicleMapper.getUnOnlineCount(); + return Result.success(day +":"+ month +":"+ onlineCount +":"+ unOnlineCount); + } } diff --git a/fance-menghang-service/src/main/resources/mapper/DrivingRecordMapper.xml b/fance-menghang-service/src/main/resources/mapper/DrivingRecordMapper.xml index 83dcb9b..4dfd3d4 100644 --- a/fance-menghang-service/src/main/resources/mapper/DrivingRecordMapper.xml +++ b/fance-menghang-service/src/main/resources/mapper/DrivingRecordMapper.xml @@ -33,17 +33,23 @@ start_key=#{startKey}, end_key=#{endKey} where record_id=#{recordId} - + + update driving_record set + end_time=#{date},end_key=#{endKey} + where record_id=#{id} + delete from car_record where record_id=#{recordId} - + diff --git a/fance-menghang-service/src/main/resources/mapper/VehicleMapper.xml b/fance-menghang-service/src/main/resources/mapper/VehicleMapper.xml index 94e13f4..380d986 100644 --- a/fance-menghang-service/src/main/resources/mapper/VehicleMapper.xml +++ b/fance-menghang-service/src/main/resources/mapper/VehicleMapper.xml @@ -20,6 +20,9 @@ #{batteryId}, #{carAddress}) + + insert into driving_record values (#{recordId},#{carVin},#{startTime},#{endTime},#{startKey},#{endKey}) + update t_car set car_name=#{carName}, @@ -30,6 +33,9 @@ battery_id=#{batteryId}, car_address=#{carAddress} where car_id=#{carId} + + update t_car set car_vin=#{},car_status=#{status} + delete from t_car where car_id=#{carId} @@ -43,4 +49,19 @@ t_battery ba on ca.battery_id=ba.battery_id left join t_fence fe on ca.fence_id=fe.fence_id where car_id=#{carId} + + + + +