feat(): 新增获取车辆实时数据接口

dev
面包骑士 2024-10-10 20:31:33 +08:00
parent 7b309dc9ac
commit f34d4acc1f
6 changed files with 155 additions and 1 deletions

View File

@ -12,7 +12,7 @@ public class WebMvcSaaSConfig implements WebMvcConfigurer {
/**
*
*/
public static final String[] EXCLUDE_URLS = {"/user/info", "/login", "/logout", "/refresh"};
public static final String[] EXCLUDE_URLS = {"/user/info", "/login", "/logout", "/refresh", "/realTime/getCarRealTime"};
@Override
public void addInterceptors (InterceptorRegistry registry) {

View File

@ -0,0 +1,28 @@
package com.muyu.openbusiness.domain;
import lombok.*;
import lombok.experimental.SuperBuilder;
/**
*
*
* @Author:
* @Name: SysCarData
* @Description:
* @CreatedDate: 2024/10/10 7:35
* @FilePath: com.muyu.openbusiness.domain
*/
@Data
@Setter
@Getter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class SysCarData <T> {
private String key;
private String label;
private T value;
private String type;
}

View File

@ -53,6 +53,9 @@ public class SysCarMessage implements Serializable {
@Excel(name = "报文分类")
private String messageType;
/* 报文数据类型*/
private String messageClass;
@Override
public String toString() {

View File

@ -0,0 +1,32 @@
package com.muyu.openbusiness.controller;
import com.muyu.common.core.domain.Result;
import com.muyu.openbusiness.domain.SysCarData;
import com.muyu.openbusiness.service.SysCarRealTimeService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
/**
*
*
* @Author:
* @Name: SysCarRealTimeController
* @Description:
* @CreatedDate: 2024/10/10 7:16
* @FilePath: com.muyu.openbusiness.controller
*/
@RestController
@RequestMapping("/realTime")
public class SysCarRealTimeController {
@Resource
private SysCarRealTimeService service;
@GetMapping("/getCarRealTime")
public Result<HashMap<String, String>> getCarRealTime(@RequestParam("vin") String vin) {
return Result.success(service.getCarRealTime(vin));
}
}

View File

@ -0,0 +1,21 @@
package com.muyu.openbusiness.service;
import com.muyu.openbusiness.domain.SysCarData;
import java.util.HashMap;
import java.util.List;
/**
*
*
* @Author:
* @Name: SysCarRealTime
* @Description:
* @CreatedDate: 2024/10/10 7:37
* @FilePath: com.muyu.openbusiness.service
*/
public interface SysCarRealTimeService{
HashMap<String, String> getCarRealTime(String vin);
}

View File

@ -0,0 +1,70 @@
package com.muyu.openbusiness.service.impl;
import javax.annotation.Resource;
import com.muyu.common.redis.service.RedisService;
import com.muyu.openbusiness.domain.SysCarData;
import com.muyu.openbusiness.service.SysCarRealTimeService;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
*
*
* @Author:
* @Name: SysCarRealTime
* @Description:
* @CreatedDate: 2024/10/10 7:37
* @FilePath: com.muyu.openbusiness.service.impl
*/
@Slf4j
@Service
public class SysCarRealTimeServiceImpl implements SysCarRealTimeService {
@Resource
private RedisService redisService;
private static final HashMap<String, Class<?> > typeMap = new HashMap<>();
static {
typeMap.put("int", Integer.class);
typeMap.put("double", Double.class);
typeMap.put("long", Long.class);
typeMap.put("string", String.class);
}
@Override
public HashMap<String, String> getCarRealTime(String vin) {
HashMap<String, String> map = new HashMap<>();
for (String key : redisService.keys(vin+":*")) {
map.put(key.replace(vin + ":",""), classConversion(redisService.getCacheObject(key)));
}
return map;
}
/**
*
* @param str
* @return
*/
private String classConversion(String str) {
try {
double d = Double.parseDouble(str);
str = Double.toString(d);
String[] split = str.split(".");
if (split.length>1 && split[1].equals("0")) {
str = String.valueOf(Integer.parseInt(str));
}
return str;
} catch (NumberFormatException e) {
return str;
}
}
}