UPDATE 同步充电桩数据

This commit is contained in:
Guoqs
2026-01-05 13:37:18 +08:00
parent 3a83908302
commit 62f455fe70

View File

@@ -7,12 +7,14 @@ import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.JcppSyncRecord;
import com.jsowell.pile.domain.PileBasicInfo;
import com.jsowell.pile.domain.PileConnectorInfo;
import com.jsowell.pile.domain.PileModelInfo;
import com.jsowell.pile.jcpp.dto.sync.*;
import com.jsowell.pile.jcpp.service.IJcppAuthService;
import com.jsowell.pile.jcpp.service.IJcppPileSyncService;
import com.jsowell.pile.mapper.JcppSyncRecordMapper;
import com.jsowell.pile.service.PileBasicInfoService;
import com.jsowell.pile.service.PileConnectorInfoService;
import com.jsowell.pile.service.PileModelInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -48,6 +50,9 @@ public class JcppPileSyncServiceImpl implements IJcppPileSyncService {
@Autowired
private RestTemplate restTemplate;
@Autowired
private PileModelInfoService pileModelInfoService;
@Value("${jcpp.sync.api-url:http://localhost:8180/api/sync}")
private String jcppApiUrl;
@@ -94,6 +99,7 @@ public class JcppPileSyncServiceImpl implements IJcppPileSyncService {
log.info("全量同步完成: 充电桩 {}/{}, 充电枪 {}/{}",
response.getSuccessPiles(), response.getTotalPiles(),
response.getSuccessGuns(), response.getTotalGuns());
return response;
@@ -228,18 +234,35 @@ public class JcppPileSyncServiceImpl implements IJcppPileSyncService {
// 基本字段
dto.setPileCode(pile.getSn());
dto.setPileName(pile.getName());
dto.setProtocol(pile.getSoftwareProtocol());
String pileName = pile.getName();
// 如果名称为空,使用充电桩编号
if (StringUtils.isBlank(pileName)) {
pileName = pile.getSn();
}
dto.setPileName(pileName);
dto.setProtocol("yunkuaichongV150");
// 品牌、型号、制造商(可为空)
dto.setBrand("jsowell"); // Web 项目中没有这些字段
dto.setModel(null);
dto.setManufacturer("jsowell");
// 类型映射:1-运营桩 → OPERATION, 2-个人桩 → PERSONAL
String type = "OPERATION"; // 默认运营桩
if ("2".equals(pile.getBusinessType())) {
type = "PERSONAL";
// 类型映射:从 pile_model_info 表获取 speed_type
// 1-快充(DC直流) → DC, 2-慢充(AC交流) → AC
String type = "AC"; // 默认交流桩
if (pile.getModelId() != null) {
try {
PileModelInfo modelInfo = pileModelInfoService.selectPileModelInfoById(pile.getModelId());
if (modelInfo != null && StringUtils.isNotEmpty(modelInfo.getSpeedType())) {
if ("1".equals(modelInfo.getSpeedType())) {
type = "DC"; // 快充-直流
} else if ("2".equals(modelInfo.getSpeedType())) {
type = "AC"; // 慢充-交流
}
}
} catch (Exception e) {
log.warn("查询充电桩型号信息失败使用默认类型AC: pileSn={}, modelId={}", pile.getSn(), pile.getModelId(), e);
}
}
dto.setType(type);
@@ -274,7 +297,16 @@ public class JcppPileSyncServiceImpl implements IJcppPileSyncService {
// 基本字段
dto.setGunCode(gun.getPileConnectorCode());
dto.setGunName(gun.getName());
// 充电枪名称:如果为空,使用枪号生成默认名称
String gunName = gun.getName();
if (StringUtils.isEmpty(gunName)) {
String gunNo = extractGunNo(gun.getPileConnectorCode());
gunName = "充电枪" + gunNo;
log.warn("充电枪名称为空,使用默认名称: {} (gunCode: {})", gunName, gun.getPileConnectorCode());
}
dto.setGunName(gunName);
dto.setPileCode(gun.getPileSn());
// 提取枪号(最后 2 位)