feature: process the compare of driver
This commit is contained in:
@@ -24,7 +24,7 @@ public class StartupCompareRunner implements ApplicationRunner {
|
|||||||
// compareService.compare(5, "vehicle");
|
// compareService.compare(5, "vehicle");
|
||||||
// compareService.compare(5, "device");
|
// compareService.compare(5, "device");
|
||||||
// compareService.compare(5, "business");
|
// compareService.compare(5, "business");
|
||||||
// compareService.compare(5, "driver");
|
compareService.compare(5, "driver");
|
||||||
// compareService.compare(5, "vehicle_device");
|
// compareService.compare(5, "vehicle_device");
|
||||||
// compareService.compare(5, "driver_vehicle");
|
// compareService.compare(5, "driver_vehicle");
|
||||||
// compareService.compare(5, "business_driver");
|
// compareService.compare(5, "business_driver");
|
||||||
|
@@ -0,0 +1,24 @@
|
|||||||
|
package com.ctgu.pro_eld_mqtt_compare.response;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName DriverConvertDTO
|
||||||
|
* @Author Alex2
|
||||||
|
* @Date 2025/7/23 9:59
|
||||||
|
**/
|
||||||
|
@Data
|
||||||
|
public class DriverConvertDTO {
|
||||||
|
private Integer id;
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
private String phone;
|
||||||
|
private String firstName;
|
||||||
|
private String lastName;
|
||||||
|
private String contactEmail;
|
||||||
|
private String contactPhone;
|
||||||
|
private String contactPhoneCountry;
|
||||||
|
private Integer isDelete;
|
||||||
|
private Integer customerId;
|
||||||
|
}
|
@@ -1,5 +1,6 @@
|
|||||||
package com.ctgu.pro_eld_mqtt_compare.response;
|
package com.ctgu.pro_eld_mqtt_compare.response;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,11 +9,30 @@ import lombok.Data;
|
|||||||
* @Date 2025/7/4 15:19
|
* @Date 2025/7/4 15:19
|
||||||
**/
|
**/
|
||||||
@Data
|
@Data
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class DriverDTO {
|
public class DriverDTO {
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private String name;
|
private String name;
|
||||||
private String email;
|
private String email;
|
||||||
private String phone;
|
private String phone;
|
||||||
|
private Content content;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public static class Content {
|
||||||
|
private String firstName;
|
||||||
|
private String lastName;
|
||||||
|
private String contactEmail;
|
||||||
|
private ContactPhone contactPhone;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public static class ContactPhone {
|
||||||
|
private String value;
|
||||||
|
private String country;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Integer isDelete;
|
private Integer isDelete;
|
||||||
private Integer customerId;
|
private Integer customerId;
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,8 @@ package com.ctgu.pro_eld_mqtt_compare.service;
|
|||||||
import com.ctgu.pro_eld_mqtt_compare.api.ApiService;
|
import com.ctgu.pro_eld_mqtt_compare.api.ApiService;
|
||||||
import com.ctgu.pro_eld_mqtt_compare.request.GetInfoVO;
|
import com.ctgu.pro_eld_mqtt_compare.request.GetInfoVO;
|
||||||
import com.ctgu.pro_eld_mqtt_compare.request.PublishMQTTVO;
|
import com.ctgu.pro_eld_mqtt_compare.request.PublishMQTTVO;
|
||||||
|
import com.ctgu.pro_eld_mqtt_compare.response.DriverConvertDTO;
|
||||||
|
import com.ctgu.pro_eld_mqtt_compare.response.DriverDTO;
|
||||||
import com.ctgu.pro_eld_mqtt_compare.utils.TAG;
|
import com.ctgu.pro_eld_mqtt_compare.utils.TAG;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
@@ -44,14 +46,20 @@ public class CompareService {
|
|||||||
CompareService.apiService = apiService;
|
CompareService.apiService = apiService;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成 value 组合
|
/**
|
||||||
|
* @Author: Alex
|
||||||
|
* @Description: 生成 value 组合
|
||||||
|
*/
|
||||||
private static String getValue(Map<String, Object> item, List<String> fieldNames) {
|
private static String getValue(Map<String, Object> item, List<String> fieldNames) {
|
||||||
return fieldNames.stream()
|
return fieldNames.stream()
|
||||||
.map(field -> String.valueOf(item.get(field)))
|
.map(field -> String.valueOf(item.get(field)))
|
||||||
.collect(Collectors.joining("-"));
|
.collect(Collectors.joining("-"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取 value 字段
|
/**
|
||||||
|
* @Author: Alex
|
||||||
|
* @Description: 获取 value 字段
|
||||||
|
*/
|
||||||
private static List<String> getValueField(String tableName) {
|
private static List<String> getValueField(String tableName) {
|
||||||
List<String> valueFields = KEY_FIELDS.get(tableName);
|
List<String> valueFields = KEY_FIELDS.get(tableName);
|
||||||
if (valueFields == null) {
|
if (valueFields == null) {
|
||||||
@@ -60,22 +68,94 @@ public class CompareService {
|
|||||||
return valueFields;
|
return valueFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 比较
|
/**
|
||||||
|
* @Author: Alex
|
||||||
|
* @Description: 根据表名分发到 driver 或 common 处理
|
||||||
|
*/
|
||||||
public PublishMQTTVO compare(Integer customerId, String tableName) throws JsonProcessingException {
|
public PublishMQTTVO compare(Integer customerId, String tableName) throws JsonProcessingException {
|
||||||
// Pakistan API
|
if ("driver".equalsIgnoreCase(tableName)) {
|
||||||
GetInfoVO driverVehicle = new GetInfoVO(customerId, tableName);
|
return compareDriver(customerId, tableName);
|
||||||
List<Object> postResultList = apiService.getInfoPakistan(driverVehicle).block();
|
} else {
|
||||||
List<Map<String, Object>> pakistanList = mapper.convertValue(postResultList, new TypeReference<List<Map<String, Object>>>() {
|
return compareCommon(customerId, tableName);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Pro API
|
/**
|
||||||
|
* @Author: Alex
|
||||||
|
* @Description: 处理 driver 表
|
||||||
|
*/
|
||||||
|
public PublishMQTTVO compareDriver(Integer customerId, String tableName) throws JsonProcessingException {
|
||||||
|
// Pakistan 数据
|
||||||
|
GetInfoVO getInfoVO = new GetInfoVO(customerId, tableName);
|
||||||
|
List<Object> postResultList = apiService.getInfoPakistan(getInfoVO).block();
|
||||||
|
List<DriverConvertDTO> pakistanDTOs = compareDriverTable(postResultList); // driver表特有的数据类型转换
|
||||||
|
List<Map<String, Object>> pakistanList = mapper.convertValue(pakistanDTOs, new TypeReference<List<Map<String, Object>>>() {});
|
||||||
|
|
||||||
|
// Pro 数据
|
||||||
List<Object> getResultList = apiService.getInfoPro(customerId, tableName).block();
|
List<Object> getResultList = apiService.getInfoPro(customerId, tableName).block();
|
||||||
String json2 = mapper.writeValueAsString(getResultList);
|
List<DriverConvertDTO> proDTOs = compareDriverTable(getResultList); // driver表特有的数据类型转换
|
||||||
List<Map<String, Object>> proList = mapper.readValue(json2, new TypeReference<List<Map<String, Object>>>() {
|
List<Map<String, Object>> proList = mapper.convertValue(proDTOs, new TypeReference<List<Map<String, Object>>>() {});
|
||||||
});
|
|
||||||
return compareList(customerId, tableName, pakistanList, proList);
|
return compareList(customerId, tableName, pakistanList, proList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: Alex
|
||||||
|
* @Description: 处理通用表(如 vehicle、device 等)
|
||||||
|
*/
|
||||||
|
public PublishMQTTVO compareCommon(Integer customerId, String tableName) throws JsonProcessingException {
|
||||||
|
// Pakistan 数据
|
||||||
|
GetInfoVO getInfoVO = new GetInfoVO(customerId, tableName);
|
||||||
|
List<Object> postResultList = apiService.getInfoPakistan(getInfoVO).block();
|
||||||
|
List<Map<String, Object>> pakistanList = mapper.convertValue(postResultList, new TypeReference<List<Map<String, Object>>>() {});
|
||||||
|
|
||||||
|
// Pro 数据
|
||||||
|
List<Object> getResultList = apiService.getInfoPro(customerId, tableName).block();
|
||||||
|
String json = mapper.writeValueAsString(getResultList);
|
||||||
|
List<Map<String, Object>> proList = mapper.readValue(json, new TypeReference<List<Map<String, Object>>>() {});
|
||||||
|
|
||||||
|
return compareList(customerId, tableName, pakistanList, proList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: Alex
|
||||||
|
* @Description: 将 DriverDTO 列表转换为扁平结构 DriverConvertDTO 列表
|
||||||
|
*/
|
||||||
|
public List<DriverConvertDTO> compareDriverTable(List<Object> list) {
|
||||||
|
List<DriverConvertDTO> driverConvertDTOS = new ArrayList<>();
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
|
if (list != null) {
|
||||||
|
for (Object obj : list) {
|
||||||
|
DriverDTO driverDTO = mapper.convertValue(obj, DriverDTO.class);
|
||||||
|
|
||||||
|
DriverConvertDTO dto = new DriverConvertDTO();
|
||||||
|
dto.setId(driverDTO.getId());
|
||||||
|
dto.setName(driverDTO.getName());
|
||||||
|
dto.setEmail(driverDTO.getEmail());
|
||||||
|
dto.setPhone(driverDTO.getPhone());
|
||||||
|
dto.setCustomerId(driverDTO.getCustomerId());
|
||||||
|
dto.setIsDelete(driverDTO.getIsDelete());
|
||||||
|
|
||||||
|
if (driverDTO.getContent() != null) {
|
||||||
|
dto.setFirstName(driverDTO.getContent().getFirstName());
|
||||||
|
dto.setLastName(driverDTO.getContent().getLastName());
|
||||||
|
dto.setContactEmail(driverDTO.getContent().getContactEmail());
|
||||||
|
|
||||||
|
if (driverDTO.getContent().getContactPhone() != null) {
|
||||||
|
dto.setContactPhone(driverDTO.getContent().getContactPhone().getValue());
|
||||||
|
dto.setContactPhoneCountry(driverDTO.getContent().getContactPhone().getCountry());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
driverConvertDTOS.add(dto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("driverConvertDTOS : {}", driverConvertDTOS);
|
||||||
|
return driverConvertDTOS;
|
||||||
|
}
|
||||||
|
|
||||||
// 比较列表
|
// 比较列表
|
||||||
// public void compareList(Integer customerId, String tableName, List<Map<String, Object>> pakistanList, List<Map<String, Object>> proList) {
|
// public void compareList(Integer customerId, String tableName, List<Map<String, Object>> pakistanList, List<Map<String, Object>> proList) {
|
||||||
// List<String> valueFields = getValueField(tableName);
|
// List<String> valueFields = getValueField(tableName);
|
||||||
@@ -102,6 +182,10 @@ public class CompareService {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: Alex
|
||||||
|
* @Description: 比较两侧数据
|
||||||
|
*/
|
||||||
public PublishMQTTVO compareList(Integer customerId, String tableName, List<Map<String, Object>> pakistanList, List<Map<String, Object>> proList) {
|
public PublishMQTTVO compareList(Integer customerId, String tableName, List<Map<String, Object>> pakistanList, List<Map<String, Object>> proList) {
|
||||||
List<String> valueFields = getValueField(tableName);
|
List<String> valueFields = getValueField(tableName);
|
||||||
|
|
||||||
|
@@ -20,8 +20,8 @@ public abstract class TAG {
|
|||||||
public static final List<String> VEHICLE_FIELDS = Arrays.asList("id", "name", "isDelete", "customerId");
|
public static final List<String> VEHICLE_FIELDS = Arrays.asList("id", "name", "isDelete", "customerId");
|
||||||
public static final List<String> DEVICE_FIELDS = Arrays.asList("id", "userPackageId", "isDelete", "synTime", "customerId");
|
public static final List<String> DEVICE_FIELDS = Arrays.asList("id", "userPackageId", "isDelete", "synTime", "customerId");
|
||||||
public static final List<String> BUSINESS_FIELDS = Arrays.asList("id", "name", "isDelete", "customerId");
|
public static final List<String> BUSINESS_FIELDS = Arrays.asList("id", "name", "isDelete", "customerId");
|
||||||
public static final List<String> DRIVER_FIELDS = Arrays.asList("id", "name", "isDelete", "email", "phone", "customerId");
|
public static final List<String> DRIVER_FIELDS = Arrays.asList("id", "name", "firstName","lastName","contactEmail", "contactPhone", "contactPhoneCountry", "isDelete", "email", "phone", "customerId");
|
||||||
public static final List<String> VEHICLE_DEVICE_FIELDS = Arrays.asList("id", "vehicleId", "deviceId", "isDelete", "customerId");
|
public static final List<String> VEHICLE_DEVICE_FIELDS = Arrays.asList("id", "vehicleId", "deviceId", "isDelete", "customerId");
|
||||||
public static final List<String> DRIVER_VEHICLE_FIELDS = Arrays.asList("id", "driverId", "vehicleId", "isDelete", "customerId");
|
public static final List<String> DRIVER_VEHICLE_FIELDS = Arrays.asList("id", "driverId", "vehicleId", "isDelete", "customerId");
|
||||||
public static final List<String> BUSINESS_DRIVER_FIELDS = Arrays.asList("id", "businessId", "driverId", "isDelete", "customerId");
|
public static final List<String> BUSINESS_DRIVER_FIELDS = Arrays.asList("id", "businessId", "driverId", "isDelete", "customerId");
|
||||||
}
|
}
|
Reference in New Issue
Block a user