同步充电桩数据

This commit is contained in:
Guoqs
2025-12-30 15:59:34 +08:00
parent 3f42441869
commit ee7a3425d0
38 changed files with 4663 additions and 131 deletions

View File

@@ -0,0 +1,129 @@
package com.jsowell.web.controller.jcpp;
import com.jsowell.common.annotation.Log;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.core.domain.AjaxResult;
import com.jsowell.common.core.page.TableDataInfo;
import com.jsowell.common.enums.BusinessType;
import com.jsowell.pile.domain.JcppSyncRecord;
import com.jsowell.pile.jcpp.dto.sync.JcppSyncResponse;
import com.jsowell.pile.jcpp.service.IJcppPileSyncService;
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;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
/**
* JCPP 充电桩同步控制器
*
* @author jsowell
*/
@Slf4j
@Api(tags = "JCPP 充电桩同步")
@RestController
@RequestMapping("/jcpp/sync")
public class JcppPileSyncController extends BaseController {
@Autowired
private IJcppPileSyncService jcppPileSyncService;
@Autowired
private JcppSyncRecordMapper jcppSyncRecordMapper;
/**
* 全量同步充电桩数据
*/
@ApiOperation("全量同步充电桩数据")
@PreAuthorize("@ss.hasPermi('jcpp:sync:full')")
@Log(title = "JCPP 充电桩同步", businessType = BusinessType.OTHER)
@PostMapping("/full")
public AjaxResult syncFull() {
try {
log.info("开始执行全量同步");
JcppSyncResponse response = jcppPileSyncService.syncAllPiles();
return AjaxResult.success("全量同步完成", response);
} catch (Exception e) {
log.error("全量同步失败", e);
return AjaxResult.error("全量同步失败: " + e.getMessage());
}
}
/**
* 增量同步充电桩数据
*/
@ApiOperation("增量同步充电桩数据")
@PreAuthorize("@ss.hasPermi('jcpp:sync:incremental')")
@Log(title = "JCPP 充电桩同步", businessType = BusinessType.OTHER)
@PostMapping("/incremental")
public AjaxResult syncIncremental(
@ApiParam("上次同步时间可选格式yyyy-MM-dd HH:mm:ss")
@RequestParam(required = false)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
Date lastSyncTime) {
try {
log.info("开始执行增量同步,上次同步时间: {}", lastSyncTime);
JcppSyncResponse response = jcppPileSyncService.syncIncrementalPiles(lastSyncTime);
return AjaxResult.success("增量同步完成", response);
} catch (Exception e) {
log.error("增量同步失败", e);
return AjaxResult.error("增量同步失败: " + e.getMessage());
}
}
/**
* 同步单个充电桩
*/
@ApiOperation("同步单个充电桩")
@PreAuthorize("@ss.hasPermi('jcpp:sync:single')")
@Log(title = "JCPP 充电桩同步", businessType = BusinessType.OTHER)
@PostMapping("/pile/{pileSn}")
public AjaxResult syncSinglePile(
@ApiParam("充电桩编号")
@PathVariable String pileSn) {
try {
log.info("开始同步单个充电桩: {}", pileSn);
boolean success = jcppPileSyncService.syncSinglePile(pileSn);
if (success) {
return AjaxResult.success("同步成功");
} else {
return AjaxResult.error("同步失败");
}
} catch (Exception e) {
log.error("同步单个充电桩失败: {}", pileSn, e);
return AjaxResult.error("同步失败: " + e.getMessage());
}
}
/**
* 查询同步记录列表
*/
@ApiOperation("查询同步记录列表")
@PreAuthorize("@ss.hasPermi('jcpp:sync:list')")
@GetMapping("/records")
public TableDataInfo getSyncRecords(JcppSyncRecord jcppSyncRecord) {
startPage();
List<JcppSyncRecord> list = jcppSyncRecordMapper.selectJcppSyncRecordList(jcppSyncRecord);
return getDataTable(list);
}
/**
* 查询同步记录详情
*/
@ApiOperation("查询同步记录详情")
@PreAuthorize("@ss.hasPermi('jcpp:sync:query')")
@GetMapping("/records/{id}")
public AjaxResult getSyncRecordDetail(
@ApiParam("同步记录ID")
@PathVariable Long id) {
JcppSyncRecord record = jcppSyncRecordMapper.selectJcppSyncRecordById(id);
return AjaxResult.success(record);
}
}