ibms-dome/FrontendWebApi/ApiControllers/OperationController.cs

108 lines
4.4 KiB
C#
Raw Normal View History

using FrontendWebApi.Models;
2022-11-05 11:26:34 +08:00
using iTextSharp.text;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
2022-11-05 11:26:34 +08:00
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
2022-11-05 11:26:34 +08:00
using NPOI.HPSF;
using NPOI.HSSF.UserModel;
2022-11-05 11:26:34 +08:00
using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using NPOI.Util;
2022-11-05 11:26:34 +08:00
using Org.BouncyCastle.Crypto.Agreement.JPake;
using Repository.BackendRepository.Interface;
using Repository.FrontendRepository.Interface;
using System;
using System.Collections.Generic;
2022-11-05 11:26:34 +08:00
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
2022-11-05 11:26:34 +08:00
using System.Linq;
using System.Threading.Tasks;
using Image = System.Drawing.Image;
2022-12-14 11:57:40 +08:00
using System.IdentityModel.Tokens.Jwt;
using System.Net;
namespace FrontendWebApi.ApiControllers
{
2022-11-05 11:26:34 +08:00
//[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");
}
2022-11-11 17:38:17 +08:00
[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;
}
}
2022-11-12 11:25:46 +08:00
apiResult.Code = "0000";
apiResult.Data = logList;
2022-11-12 11:25:46 +08:00
}
catch (Exception exception)
{
apiResult.Code = "9999";
2022-12-14 11:57:40 +08:00
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
return Ok(apiResult);
2022-12-14 11:57:40 +08:00
}
return Ok(apiResult);
2022-12-14 11:57:40 +08:00
}
}
}