using log4net; using System; using System.Configuration; using System.Data.SqlClient; using Dapper; using System.Windows; using Agent.Models; using System.Linq; using System.Collections.Generic; namespace Agent.Services { class ReportService { private static readonly ILog log = LogManager.GetLogger(typeof(ReportService)); /// /// 레포트 추가 /// /// /// /// /// /// /// private int AddReport(int policyTid, string fileName, string filePath, string workType, bool isFail) { try { var userTid = Application.Current.Properties["user_tid"]; using (var con = new SqlConnection(App._myConnection)) { con.Open(); var sql = $@" INSERT INTO [di_report] ([user_tid] ,[policy_tid] ,[name] ,[path] ,[work_type] ,[create_date] ,[is_fail] ,[sys_plant_cd] ) VALUES (@UserTid ,@PolicyTid ,@Name ,@Path ,@WorkType ,GETDATE() ,@IsFail ,@sysPlantCd ) "; var data = new { UserTid = userTid, PolicyTid = policyTid, Name = fileName, Path = filePath, WorkType = workType, IsFail = isFail, sysPlantCd = App._sysPlantCd }; return con.Execute(sql, data); } } catch (Exception e) { log.Error(e); return 0; } } /// /// 백업 레포트 추가 /// /// /// /// /// /// public int AddBackupReport(int policyTid, string fileName, string filePath, bool isFail) { return AddReport(policyTid, fileName, filePath, "BACKUP", isFail); } /// /// 복구 레포트 추가 /// /// /// /// /// /// public int AddRestoreReport(int policyTid, string fileName, string filePath, bool isFail) { return AddReport(policyTid, fileName, filePath, "RESTORE", isFail); } /// /// 재시도 레포트 추가 /// /// /// /// /// /// public int AddRetryReport(int policyTid, string fileName, string filePath, bool isFail) { return AddReport(policyTid, fileName, filePath, "RETRY", isFail); } /// /// 레포트 조회 /// /// public List GetReports() { try { var userTid = Application.Current.Properties["user_tid"]; using (var con = new SqlConnection(App._myConnection)) { con.Open(); var sql = @" SELECT [tid] ,[user_tid] ,[policy_tid] ,[name] ,[path] ,dbo.FN_WORK_TYPE_NM([work_type]) AS [work_type] ,[create_date] ,[is_fail] FROM [di_report] WHERE user_tid = @UserTid ORDER BY [create_date] DESC "; return con.Query(sql, new { UserTid = userTid }).ToList(); } } catch (Exception e) { log.Error(e); return new List(); } } /// /// 일일 레포트 조회 /// /// public List GetDailyReports(string start, string end) { try { var userTid = Application.Current.Properties["user_tid"]; using (var con = new SqlConnection(App._myConnection)) { con.Open(); var sql = @" SELECT [tid] ,[user_tid] ,[policy_tid] ,[name] ,[path] ,dbo.FN_WORK_TYPE_NM([work_type]) AS [work_type] ,[create_date] ,[is_fail] FROM [di_report] WHERE 1=1 AND user_tid = @UserTid AND ([create_date] >= @MinDate AND [create_date] <= @MaxDate) ORDER BY [create_date] DESC "; return con.Query(sql, new { UserTid = userTid, MinDate = $"{start} 00:00:00", MaxDate = $"{end} 23:59:59" }).ToList(); } } catch (Exception e) { log.Error(e); return new List(); } } } }