2022-11-04 09:41:50 +08:00
|
|
|
|
using FrontendWebApi.Models;
|
2022-11-05 11:26:34 +08:00
|
|
|
|
using iTextSharp.text;
|
2022-11-04 09:41:50 +08:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2022-11-05 11:26:34 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
2022-11-04 09:41:50 +08:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Newtonsoft.Json;
|
2022-11-05 11:26:34 +08:00
|
|
|
|
using NPOI.HPSF;
|
2022-11-17 10:28:47 +08:00
|
|
|
|
using NPOI.HSSF.UserModel;
|
2022-11-05 11:26:34 +08:00
|
|
|
|
using NPOI.SS.Formula.Functions;
|
2022-11-04 09:41:50 +08:00
|
|
|
|
using NPOI.SS.UserModel;
|
|
|
|
|
using NPOI.XSSF.UserModel;
|
2022-11-17 10:28:47 +08:00
|
|
|
|
using NPOI.Util;
|
2022-11-05 11:26:34 +08:00
|
|
|
|
using Org.BouncyCastle.Crypto.Agreement.JPake;
|
2022-11-04 09:41:50 +08:00
|
|
|
|
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;
|
2022-11-17 10:28:47 +08:00
|
|
|
|
using System.Drawing.Imaging;
|
2022-11-04 09:41:50 +08:00
|
|
|
|
using System.IO;
|
2022-11-05 11:26:34 +08:00
|
|
|
|
using System.Linq;
|
2022-11-04 09:41:50 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2022-11-17 10:28:47 +08:00
|
|
|
|
using Image = System.Drawing.Image;
|
2022-12-14 11:57:40 +08:00
|
|
|
|
using System.IdentityModel.Tokens.Jwt;
|
|
|
|
|
using System.Net;
|
2022-11-04 09:41:50 +08:00
|
|
|
|
|
|
|
|
|
namespace FrontendWebApi.ApiControllers
|
|
|
|
|
{
|
2022-11-05 11:26:34 +08:00
|
|
|
|
//[Route("api/[controller]")]
|
|
|
|
|
//[ApiController]
|
2023-05-30 18:29:51 +08:00
|
|
|
|
public class OperationLogController : MyBaseApiController<OperationLogController>
|
2022-11-04 09:41:50 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly IBackendRepository backendRepository;
|
|
|
|
|
private string operationFileSaveAsPath = "";
|
|
|
|
|
|
2023-05-30 18:29:51 +08:00
|
|
|
|
public OperationLogController(IBackendRepository backendRepository)
|
2022-11-04 09:41:50 +08:00
|
|
|
|
{
|
|
|
|
|
this.backendRepository = backendRepository;
|
|
|
|
|
operationFileSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "operation");
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-11 17:38:17 +08:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-05-30 18:29:51 +08:00
|
|
|
|
[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;
|
2022-11-04 09:41:50 +08:00
|
|
|
|
}
|
2023-05-30 18:29:51 +08:00
|
|
|
|
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-04 09:41:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-12 11:25:46 +08:00
|
|
|
|
apiResult.Code = "0000";
|
2023-05-30 18:29:51 +08:00
|
|
|
|
apiResult.Data = logList;
|
2022-11-12 11:25:46 +08:00
|
|
|
|
|
2023-02-24 14:16:03 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
apiResult.Code = "9999";
|
2022-12-14 11:57:40 +08:00
|
|
|
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
2023-05-30 18:29:51 +08:00
|
|
|
|
return Ok(apiResult);
|
2022-12-14 11:57:40 +08:00
|
|
|
|
}
|
2023-05-30 18:29:51 +08:00
|
|
|
|
return Ok(apiResult);
|
2022-12-14 11:57:40 +08:00
|
|
|
|
|
|
|
|
|
}
|
2022-11-04 09:41:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|