301 lines
9.6 KiB
C#
301 lines
9.6 KiB
C#
using LiangLiSystem.Services.Helpers;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Traffic.Data.ViewModels;
|
|
using Traffic.Service.Interfaces;
|
|
|
|
namespace Traffic.Api.Controllers
|
|
{
|
|
[Route("api/report")]
|
|
[Authorize]
|
|
[ApiController]
|
|
public class ReportController : ControllerBase
|
|
{
|
|
private readonly IFileService _fileService;
|
|
private readonly IReportService _service;
|
|
public ReportController(IFileService fileService, IReportService service)
|
|
{
|
|
_fileService = fileService;
|
|
_service = service;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得 API 資料顯示 的 TableName
|
|
/// </summary>
|
|
[HttpGet("tycg/tableName")]
|
|
public IActionResult GetTycgLog()
|
|
{
|
|
try
|
|
{
|
|
var data = _service.GetTycgTableName();
|
|
var result = new Response
|
|
{
|
|
Result = data
|
|
};
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 取得 API 資料顯示
|
|
/// </summary>
|
|
/// <param name="tycgTableName"></param>
|
|
/// <param name="searchModel"></param>
|
|
/// <param name="method"></param>
|
|
/// <returns></returns>
|
|
/// <remarks>需要給Table名稱
|
|
/// tycg_logases
|
|
/// tycg_logbigcarviolation
|
|
/// tycg_logchecked
|
|
/// tycg_logcrossroad
|
|
/// tycg_logmalfunctionhttp
|
|
/// tycg_logrejected
|
|
/// tycg_logtraffichttp
|
|
/// tycg_loguploaded</remarks>
|
|
[HttpGet("tycg")]
|
|
public IActionResult GetTycgLog(string tycgTableName, [FromQuery] SearchModelViewModel searchModel, string method = "0")
|
|
{
|
|
try
|
|
{
|
|
if (method == "1")
|
|
{
|
|
var data = _service.GetTycgLogAll(tycgTableName);
|
|
var url = _fileService.ExportGetTycgLog(tycgTableName, data);
|
|
return Ok(url);
|
|
}
|
|
else
|
|
{
|
|
SearchModel model = Util.GetSearchModel(searchModel);
|
|
var data = _service.GetTycgLog(tycgTableName, model);
|
|
|
|
var result = new Response
|
|
{
|
|
Result = data
|
|
};
|
|
return !string.IsNullOrWhiteSpace(tycgTableName) ? Ok(result) : BadRequest("請輸入 TableName");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 違規事件統計站店違規數統計表
|
|
/// </summary>
|
|
/// <param name="viewModel"></param>
|
|
/// <param name="method">0 : 查詢, 1:匯出</param>
|
|
/// <returns></returns>
|
|
[HttpPost("site/eventTypes")]
|
|
public IActionResult GetEvent(SiteAndEventTypeViewModel viewModel, string method = "0")
|
|
{
|
|
try
|
|
{
|
|
var data = _service.GetReportSiteEventTypes(viewModel.Sites, viewModel.EventTypes, viewModel.StartTime, viewModel.EndTime);
|
|
|
|
var result = new Response
|
|
{
|
|
Result = data
|
|
};
|
|
|
|
if (method == "1")
|
|
{
|
|
var start = viewModel.StartTime.Replace("undefined", "00:00:00");
|
|
var end = viewModel.EndTime.Replace("undefined", "23:59:59");
|
|
var url = _fileService.ExportGetSiteEvent(
|
|
Convert.ToDateTime(start).ToString("yyMMdd"),
|
|
Convert.ToDateTime(end).ToString("yyMMdd"),
|
|
data);
|
|
return Ok(url);
|
|
}
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 違規類型統計表 違規停車
|
|
/// </summary>
|
|
/// <param name="viewModel"></param>
|
|
/// <param name="method">0 : 查詢, 1:匯出</param>
|
|
/// <returns></returns>
|
|
[HttpPost("eventType/1")]
|
|
public IActionResult GetEventType1(ReportRequestViewModel viewModel, string method = "0")
|
|
{
|
|
try
|
|
{
|
|
var data = _service.GetEventType1(viewModel);
|
|
var result = new Response
|
|
{
|
|
Result = data
|
|
};
|
|
|
|
if (method == "1")
|
|
{
|
|
var url = _fileService.ExportGetEventType1(
|
|
Convert.ToDateTime(viewModel.StartDate).ToString("yyMMdd"),
|
|
Convert.ToDateTime(viewModel.EndDate).ToString("yyMMdd"),
|
|
data);
|
|
return Ok(url);
|
|
}
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 違規類型統計表 區間測速
|
|
/// </summary>
|
|
/// <param name="viewModel"></param>
|
|
/// <param name="method">0 : 查詢, 1:匯出</param>
|
|
/// <returns></returns>
|
|
[HttpPost("eventType/2")]
|
|
public IActionResult GetEventType2(ReportRequestViewModel viewModel, string method = "0")
|
|
{
|
|
try
|
|
{
|
|
var data = _service.GetEventType2(viewModel);
|
|
|
|
var result = new Response
|
|
{
|
|
Result = data
|
|
};
|
|
|
|
if (method == "1")
|
|
{
|
|
var url = _fileService.ExportGetEventType2(
|
|
Convert.ToDateTime(viewModel.StartDate).ToString("yyMMdd"),
|
|
Convert.ToDateTime(viewModel.EndDate).ToString("yyMMdd"),
|
|
data);
|
|
return Ok(url);
|
|
}
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 違規類型統計表 未依標線行駛_路口淨空_闖紅燈 未保持路口淨空
|
|
/// </summary>
|
|
/// <param name="viewModel"></param>
|
|
/// <param name="method">0 : 查詢, 1:匯出</param>
|
|
/// <returns></returns>
|
|
[HttpPost("eventType/34")]
|
|
public IActionResult GetEventType34(ReportRequestViewModel viewModel, string method = "0")
|
|
{
|
|
try
|
|
{
|
|
var data = _service.GetEventType34(viewModel);
|
|
|
|
var result = new Response
|
|
{
|
|
Result = data
|
|
};
|
|
|
|
if (method == "1")
|
|
{
|
|
var url = _fileService.ExportGetEventType34(
|
|
Convert.ToDateTime(viewModel.StartDate).ToString("yyMMdd"),
|
|
Convert.ToDateTime(viewModel.EndDate).ToString("yyMMdd"),
|
|
data);
|
|
return Ok(url);
|
|
}
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 違規類型統計表 大貨車禁行
|
|
/// </summary>
|
|
/// <param name="viewModel"></param>
|
|
/// <param name="method">0 : 查詢, 1:匯出</param>
|
|
/// <returns></returns>
|
|
[HttpPost("eventType/6")]
|
|
public IActionResult GetEventType6(ReportRequestViewModel viewModel, string method = "0")
|
|
{
|
|
try
|
|
{
|
|
var data = _service.GetEventType6(viewModel);
|
|
|
|
var result = new Response
|
|
{
|
|
Result = data
|
|
};
|
|
|
|
if (method == "1")
|
|
{
|
|
var url = _fileService.ExportGetEventType6(
|
|
Convert.ToDateTime(viewModel.StartDate).ToString("yyMMdd"),
|
|
Convert.ToDateTime(viewModel.EndDate).ToString("yyMMdd"),
|
|
data);
|
|
return Ok(url);
|
|
}
|
|
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 設備故障報表
|
|
/// </summary>
|
|
/// <param name="viewModel"></param>
|
|
/// <param name="method">0 : 查詢, 1:匯出</param>
|
|
/// <returns></returns>
|
|
[HttpPost("malfunction")]
|
|
public IActionResult GetMalfunction(ReportRequestViewModel viewModel, string method = "0")
|
|
{
|
|
try
|
|
{
|
|
var data = _service.GetMalfunction(viewModel);
|
|
|
|
var result = new Response
|
|
{
|
|
Result = data
|
|
};
|
|
|
|
if (method == "1")
|
|
{
|
|
var url = _fileService.ExportGetMalfunction(
|
|
Convert.ToDateTime(viewModel.StartDate).ToString("yyMMdd"),
|
|
Convert.ToDateTime(viewModel.EndDate).ToString("yyMMdd"),
|
|
data);
|
|
return Ok(url);
|
|
}
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
}
|
|
}
|