同步充电桩数据

This commit is contained in:
Guoqs
2025-12-31 16:38:27 +08:00
parent ee7a3425d0
commit 193470ffb4
5 changed files with 253 additions and 43 deletions

View File

@@ -1,5 +1,6 @@
package com.jsowell.web.controller.jcpp;
import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.annotation.Log;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.core.domain.AjaxResult;
@@ -12,7 +13,6 @@ import com.jsowell.pile.mapper.JcppSyncRecordMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -26,8 +26,9 @@ import java.util.List;
*
* @author jsowell
*/
@Slf4j
// @Slf4j
@Api(tags = "JCPP 充电桩同步")
@Anonymous
@RestController
@RequestMapping("/jcpp/sync")
public class JcppPileSyncController extends BaseController {
@@ -47,11 +48,11 @@ public class JcppPileSyncController extends BaseController {
@PostMapping("/full")
public AjaxResult syncFull() {
try {
log.info("开始执行全量同步");
logger.info("开始执行全量同步");
JcppSyncResponse response = jcppPileSyncService.syncAllPiles();
return AjaxResult.success("全量同步完成", response);
} catch (Exception e) {
log.error("全量同步失败", e);
logger.error("全量同步失败", e);
return AjaxResult.error("全量同步失败: " + e.getMessage());
}
}
@@ -69,11 +70,11 @@ public class JcppPileSyncController extends BaseController {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
Date lastSyncTime) {
try {
log.info("开始执行增量同步,上次同步时间: {}", lastSyncTime);
logger.info("开始执行增量同步,上次同步时间: {}", lastSyncTime);
JcppSyncResponse response = jcppPileSyncService.syncIncrementalPiles(lastSyncTime);
return AjaxResult.success("增量同步完成", response);
} catch (Exception e) {
log.error("增量同步失败", e);
logger.error("增量同步失败", e);
return AjaxResult.error("增量同步失败: " + e.getMessage());
}
}
@@ -89,7 +90,7 @@ public class JcppPileSyncController extends BaseController {
@ApiParam("充电桩编号")
@PathVariable String pileSn) {
try {
log.info("开始同步单个充电桩: {}", pileSn);
logger.info("开始同步单个充电桩: {}", pileSn);
boolean success = jcppPileSyncService.syncSinglePile(pileSn);
if (success) {
return AjaxResult.success("同步成功");
@@ -97,7 +98,7 @@ public class JcppPileSyncController extends BaseController {
return AjaxResult.error("同步失败");
}
} catch (Exception e) {
log.error("同步单个充电桩失败: {}", pileSn, e);
logger.error("同步单个充电桩失败: {}", pileSn, e);
return AjaxResult.error("同步失败: " + e.getMessage());
}
}

View File

@@ -14,7 +14,7 @@ jcpp:
queue-prefix: jcpp.uplink.partition
sync:
# JCPP 同步接口地址
api-url: http://localhost:8080/api/sync
api-url: http://localhost:8180/api/sync
# 批量同步大小
batch-size: 100
# 超时时间(毫秒)
@@ -23,6 +23,11 @@ jcpp:
auto-sync-enabled: false
# 自动同步间隔(分钟)
auto-sync-interval: 30
auth:
# JCPP 认证用户名
username: sanbing
# JCPP 认证密码
password: password123
# 数据源配置
spring: