108 lines
4.4 KiB
C#
108 lines
4.4 KiB
C#
using FrontendWebApi.Models;
|
||
using iTextSharp.text;
|
||
using Microsoft.AspNetCore.Http;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.AspNetCore.Mvc.Filters;
|
||
using Microsoft.Extensions.Logging;
|
||
using Newtonsoft.Json;
|
||
using NPOI.HPSF;
|
||
using NPOI.HSSF.UserModel;
|
||
using NPOI.SS.Formula.Functions;
|
||
using NPOI.SS.UserModel;
|
||
using NPOI.XSSF.UserModel;
|
||
using NPOI.Util;
|
||
using Org.BouncyCastle.Crypto.Agreement.JPake;
|
||
using Repository.BackendRepository.Interface;
|
||
using Repository.FrontendRepository.Interface;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Drawing.Drawing2D;
|
||
using System.Drawing.Imaging;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Threading.Tasks;
|
||
using Image = System.Drawing.Image;
|
||
using System.IdentityModel.Tokens.Jwt;
|
||
using System.Net;
|
||
|
||
namespace FrontendWebApi.ApiControllers
|
||
{
|
||
//[Route("api/[controller]")]
|
||
//[ApiController]
|
||
public class OperationLogController : MyBaseApiController<OperationLogController>
|
||
{
|
||
private readonly IBackendRepository backendRepository;
|
||
private string operationFileSaveAsPath = "";
|
||
|
||
public OperationLogController(IBackendRepository backendRepository)
|
||
{
|
||
this.backendRepository = backendRepository;
|
||
operationFileSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "operation");
|
||
}
|
||
|
||
|
||
[HttpPost]
|
||
[Route("api/OperationLog/GetList")]
|
||
public async Task<ActionResult<ApiResult<List<OperationLogOutput>>>> GetList([FromBody] PageResult<OperationLogInput> pageResult)
|
||
{
|
||
|
||
ApiResult<List<OperationLogOutput>> apiResult = new ApiResult<List<OperationLogOutput>>(jwt_str);
|
||
if (!jwtlife)
|
||
{
|
||
apiResult.Code = "5000";
|
||
return BadRequest(apiResult);
|
||
}
|
||
try
|
||
{
|
||
// 取得資料
|
||
var logList = await backendRepository.GetAllAsync<OperationLogOutput>($@"
|
||
select ui.full_name as 'user_name' ,ol.* from operation_log ol
|
||
LEFT JOIN userinfo ui on ui.userinfo_guid COLLATE utf8mb4_unicode_ci = ol.user_guid
|
||
WHERE ol.operation_type = @operation_type AND ol.building_tag = @building_tag AND
|
||
ol.created_at >= @start_time AND ol.created_at <= @end_time
|
||
LIMIT @pageSize OFFSET @skip ",
|
||
new {
|
||
pageSize = pageResult.pageSize ,
|
||
skip = (pageResult.currentPage - 1) * pageResult.pageSize,
|
||
operation_type = pageResult.data?.operation_type,
|
||
building_tag = pageResult.data?.building_tag,
|
||
start_time = pageResult.data?.start_time,
|
||
end_time = pageResult.data?.end_time,
|
||
});
|
||
|
||
// 設定呈現紀錄內容
|
||
foreach (var log in logList) {
|
||
if (log.parameter == null) {
|
||
continue;
|
||
}
|
||
switch (log.operation_type) {
|
||
case 1:
|
||
var chaName = JsonConvert.DeserializeObject<ChangeName>(log.parameter);
|
||
if (chaName == null) continue;
|
||
log.content = chaName.TagName + ":" + chaName.ChangeN;
|
||
break;
|
||
case 2:
|
||
var schedule = JsonConvert.DeserializeObject<SaveSchedule>(log.parameter);
|
||
if (schedule == null) continue;
|
||
log.content = "編號:"+schedule.light_schedule_guid + "\n" +
|
||
"名稱:" + schedule.full_name + "\n" +
|
||
"修改內容:" + string.Join("、",schedule.changeNames);
|
||
break;
|
||
}
|
||
}
|
||
apiResult.Code = "0000";
|
||
apiResult.Data = logList;
|
||
|
||
}
|
||
catch (Exception exception)
|
||
{
|
||
apiResult.Code = "9999";
|
||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||
return Ok(apiResult);
|
||
}
|
||
return Ok(apiResult);
|
||
|
||
}
|
||
}
|
||
}
|