车辆实时数据

master
Yang Haoyu 2023-11-23 22:38:14 +08:00
parent e931b2e6c0
commit 8deed8739c
13 changed files with 1017 additions and 20 deletions

View File

@ -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";
}

View File

@ -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";
}

View File

@ -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;

View File

@ -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());
}
}
}

View File

@ -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 {
}

View File

@ -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>> 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<DrivingRecord>> 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(),

View File

@ -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<ResponseCar> 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<java.util.List<com.shiyi.internet.domain.VehicleMessage>>
* @Author: YHY
* @Updator: YHY
* @Date 2023/11/23 20:27
*/
@GetMapping("onlineVehicle")
public Result<List<VehicleMessage>> onlineVehicle(){
log.info("功能名称查询所有在线车辆请求URL【{}】,请求方法:【{}】",request.getRequestURI(),
request.getMethod());
Result<List<VehicleMessage>> 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<java.lang.String>
* @Author: YHY
* @Updator: YHY
* @Date 2023/11/23 20:42
*/
@GetMapping("/countData")
public Result<String> countData(){
log.info("功能名称统计数据请求URL【{}】,请求方法:【{}】",request.getRequestURI(),
request.getMethod());
Result<String> result = vehicleService.countData();
log.info("功能名称统计数据请求URL【{}】,请求方法:【{}】,响应结果:【{}】",request.getRequestURI(),
request.getMethod(),JSONObject.toJSONString(result));
return result;
}
}

View File

@ -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<DrivingRecord> {
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);
}

View File

@ -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<Car> {
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<String> getOnlineVehicleIds();
Integer getOnlineCount();
Integer getUnOnlineCount();
}

View File

@ -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<Car> {
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<List<VehicleMessage>> onlineVehicle();
Result<String> countData();
}

View File

@ -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<VehicleMapper,Car> implements VehicleService {
@Autowired
private VehicleMapper vehicleMapper;
@Autowired
private DrivingRecordMapper drivingRecordMapper;
private RedisTemplate<String,String> redisTemplate;
@Override
public Result<List<ResponseCar>> vehicleList() {
@ -36,9 +50,11 @@ public class VehicleServiceimpl extends ServiceImpl<VehicleMapper,Car> 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<VehicleMapper,Car> 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<List<VehicleMessage>> onlineVehicle() {
List<String> ids = vehicleMapper.getOnlineVehicleIds();
List<VehicleMessage> 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<String> 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);
}
}

View File

@ -33,17 +33,23 @@
start_key=#{startKey},
end_key=#{endKey} where record_id=#{recordId}
</update>
<update id="endVehicle">
update driving_record set
end_time=#{date},end_key=#{endKey}
where record_id=#{id}
</update>
<delete id="deleteDrivingRecord">
delete from car_record where record_id=#{recordId}
</delete>
<select id="listDriving" resultType="com.shiyi.internet.domain.DrivingRecord">
select * from car_record
</select>
<select id="fingCarRecordById" resultType="com.shiyi.internet.domain.DrivingRecord">
select * from car_record where record_id=#{recordId}
</select>
<select id="selectLastId" resultType="java.lang.Integer">
select max(recordId) from driving_record where car_vin = #{carVin}
</select>
</mapper>

View File

@ -20,6 +20,9 @@
#{batteryId},
#{carAddress})
</insert>
<insert id="insertRecord">
insert into driving_record values (#{recordId},#{carVin},#{startTime},#{endTime},#{startKey},#{endKey})
</insert>
<update id="updateVehicl">
update t_car set
car_name=#{carName},
@ -30,6 +33,9 @@
battery_id=#{batteryId},
car_address=#{carAddress} where car_id=#{carId}
</update>
<update id="updateVehicleStatus">
update t_car set car_vin=#{},car_status=#{status}
</update>
<delete id="deletVehiclById">
delete from t_car where car_id=#{carId}
</delete>
@ -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}
</select>
<select id="getVehicleInfoByVin" resultType="com.shiyi.internet.domain.Car">
select * from t_car where vin=#{vin}
</select>
<select id="selectLastByVin" resultType="com.shiyi.internet.domain.DrivingRecord">
select * from driving_record dr left join (select max(recordId) id from friving_record where car_vin=#{carVin}) l on dr.record_id=l.record_id
</select>
<select id="getOnlineVehicleIds" resultType="java.lang.String">
select car_vin from t_car where car_status=1
</select>
<select id="getOnlineCount" resultType="java.lang.Integer">
select count(*) from t_car where car_status=1
</select>
<select id="getUnOnlineCount" resultType="java.lang.Integer">
select count(*) from t_car
</select>
</mapper>