wanshenmean
8 天以前 559bb7b4be83575cc5fedee98484647243c96f89
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using Microsoft.AspNetCore.Mvc;
using WIDESEAWCS_S7Simulator.Application;
 
namespace WIDESEAWCS_S7Simulator.Server.Controllers;
 
[ApiController]
[Route("api/[controller]")]
public class SyncController : ControllerBase
{
    private readonly InstanceSyncService _syncService;
    private readonly ILogger<SyncController> _logger;
 
    public SyncController(InstanceSyncService syncService, ILogger<SyncController> logger)
    {
        _syncService = syncService;
        _logger = logger;
    }
 
    /// <summary>
    /// 手动触发实例同步
    /// </summary>
    [HttpPost("SyncInstances")]
    public async Task<IActionResult> SyncInstances()
    {
        try
        {
            _logger.LogInformation("收到手动同步请求");
            await _syncService.SyncInstancesAsync();
            return Ok(new { message = "同步完成", lastSyncTime = _syncService.LastSyncTime });
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "手动同步失败");
            return StatusCode(500, new { message = "同步失败", error = ex.Message });
        }
    }
 
    /// <summary>
    /// 获取上次同步时间
    /// </summary>
    [HttpGet("LastSyncTime")]
    public IActionResult GetLastSyncTime()
    {
        return Ok(new { lastSyncTime = _syncService.LastSyncTime });
    }
}