From b348a4182490d9a153f0373d1cebd2b9e6211608 Mon Sep 17 00:00:00 2001
From: leo <10200039@qq.com>
Date: Sat, 13 May 2023 21:36:01 +0800
Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=AF=BC=E5=87=BA=E4=BF=AE?=
=?UTF-8?q?=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/OperateLogController.cs | 34 ++++++++++++++++++
FactorySystemBll/OperateLogBll.cs | 35 +++++++++++++++++++
2 files changed, 69 insertions(+)
diff --git a/FactorySystemApi/Controllers/OperateLogController.cs b/FactorySystemApi/Controllers/OperateLogController.cs
index 7ca9653..a12f61e 100644
--- a/FactorySystemApi/Controllers/OperateLogController.cs
+++ b/FactorySystemApi/Controllers/OperateLogController.cs
@@ -1,4 +1,7 @@
+using System;
using System.Collections.Generic;
+using System.Data;
+using System.IO;
using System.Web.Http;
using FactorySystemBll;
using FactorySystemCommon;
@@ -87,5 +90,36 @@ namespace FactorySystemApi.Controllers
}, apiResult, Request);
}
+ ///
+ /// 导出操作日志
+ ///
+ [HttpPost]
+ public ApiResult DownloadLogs(Dictionary inParams)
+ {
+ ApiResult apiResult = new ApiResult();
+
+ return ExceptionHelper.TryReturnException(() =>
+ {
+ string basePath = AppDomain.CurrentDomain.BaseDirectory.Trim('\\');
+ string savePath = basePath + string.Format("\\File\\Temp\\logs\\");
+ string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
+
+ int limit = inParams.ContainsKey("limit") ? int.Parse(inParams["limit"].ToString()) : 1000;
+ if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath);
+
+ CreateExeclFileLogs(fileName, savePath, limit);
+ string url = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, "") + savePath.Replace(basePath, "").Replace("\\", "/") + fileName;
+ apiResult.Data = url;
+
+ }, apiResult, Request);
+ }
+
+ private void CreateExeclFileLogs(string fName, string savePath, int limit)
+ {
+ DataTable dataList = new DataTable();
+
+ dataList = OperateLogBll.GetLogs(limit);
+ NPOIHelper.ExportDTtoExcel(dataList, "Sheet1", savePath + fName);
+ }
}
}
diff --git a/FactorySystemBll/OperateLogBll.cs b/FactorySystemBll/OperateLogBll.cs
index 4f98f4e..3823524 100644
--- a/FactorySystemBll/OperateLogBll.cs
+++ b/FactorySystemBll/OperateLogBll.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Data;
using System.Xml.Linq;
using FactorySystemCommon;
using FactorySystemModel.ResponseModel;
@@ -83,5 +84,39 @@ namespace FactorySystemBll
}).ExecuteCommand();
}
+ public static DataTable GetLogs(int limit)
+ {
+ SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
+ string strSql = @"
+ select TOP(" + limit + @")
+ CONVERT(varchar(100), a.FAddDate, 120) as '操作时间',
+ b.FName as '操作人',
+ CASE a.FModule
+ when 1 THEN '待办事项'
+ WHEN 2 THEN '协同路线'
+ WHEN 3 THEN '物料路线'
+ WHEN 4 THEN '试验号变更'
+ WHEN 5 THEN '清单管理'
+ WHEN 6 THEN '系统设置'
+ ELSE ''
+ END AS '模块',
+ a.FTeamID as '协同ID',
+ c.FName as '来源类型',
+ LEFT(a.FDesc, 100) as '操作描述'
+ from
+ TFS_OperateLog a
+ left join TUser b on
+ a.FAddUser = b.FID
+ left join TBasicCode c on
+ a.FType = c.FCode
+ WHERE c.FType = 33
+ ORDER by
+ a.FAddDate desc
+ ";
+
+ DataTable data = db.Ado.GetDataTable(strSql);
+ return data;
+ }
+
}
}