123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- 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));
- /// <summary>
- /// 레포트 추가
- /// </summary>
- /// <param name="policyTid"></param>
- /// <param name="fileName"></param>
- /// <param name="filePath"></param>
- /// <param name="workType"></param>
- /// <param name="isFail"></param>
- /// <returns></returns>
- 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;
- }
- }
- /// <summary>
- /// 백업 레포트 추가
- /// </summary>
- /// <param name="policyTid"></param>
- /// <param name="fileName"></param>
- /// <param name="filePath"></param>
- /// <param name="isFail"></param>
- /// <returns></returns>
- public int AddBackupReport(int policyTid, string fileName, string filePath, bool isFail)
- {
- return AddReport(policyTid, fileName, filePath, "BACKUP", isFail);
- }
- /// <summary>
- /// 복구 레포트 추가
- /// </summary>
- /// <param name="policyTid"></param>
- /// <param name="fileName"></param>
- /// <param name="filePath"></param>
- /// <param name="isFail"></param>
- /// <returns></returns>
- public int AddRestoreReport(int policyTid, string fileName, string filePath, bool isFail)
- {
- return AddReport(policyTid, fileName, filePath, "RESTORE", isFail);
- }
- /// <summary>
- /// 재시도 레포트 추가
- /// </summary>
- /// <param name="policyTid"></param>
- /// <param name="fileName"></param>
- /// <param name="filePath"></param>
- /// <param name="isFail"></param>
- /// <returns></returns>
- public int AddRetryReport(int policyTid, string fileName, string filePath, bool isFail)
- {
- return AddReport(policyTid, fileName, filePath, "RETRY", isFail);
- }
- /// <summary>
- /// 레포트 조회
- /// </summary>
- /// <returns></returns>
- public List<Report> 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<Report>(sql, new { UserTid = userTid }).ToList();
- }
- }
- catch (Exception e)
- {
- log.Error(e);
- return new List<Report>();
- }
- }
- /// <summary>
- /// 일일 레포트 조회
- /// </summary>
- /// <returns></returns>
- public List<Report> 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<Report>(sql, new { UserTid = userTid, MinDate = $"{start} 00:00:00", MaxDate = $"{end} 23:59:59" }).ToList();
- }
- }
- catch (Exception e)
- {
- log.Error(e);
- return new List<Report>();
- }
- }
- }
- }
|