sendmail 에 프로젝트업데이트하지 않은 대상 메일 발송 기능 추가 (월)

This commit is contained in:
ChiKyun Kim
2025-08-05 11:40:49 +09:00
parent 81f91f0897
commit d23771039b
4 changed files with 287 additions and 19 deletions

View File

@@ -88,6 +88,25 @@ namespace Console_SendMail
} }
} }
public static string GetUserEmail(string gcode, string uid)
{
if (string.IsNullOrEmpty(gcode) || string.IsNullOrEmpty(uid)) return string.Empty;
var slq = "select isnull(email,'') from vGroupUser" +
$" where gcode = '{gcode}'" +
$" and id = '{uid}'";
try
{
return ExecuteScalar(slq);
}
catch
{
return string.Empty;
}
}
public static string GetUserTel(string gcode, string uid) public static string GetUserTel(string gcode, string uid)
{ {
var slq = "select isnull(tel,'') from vGroupUser" + var slq = "select isnull(tel,'') from vGroupUser" +

View File

@@ -13,6 +13,7 @@ namespace Console_SendMail
static DateTime ChkMakeAutoTime = DateTime.Now.AddDays(-1); static DateTime ChkMakeAutoTime = DateTime.Now.AddDays(-1);
static DateTime ChkSendMailTime = DateTime.Now.AddDays(-1); static DateTime ChkSendMailTime = DateTime.Now.AddDays(-1);
static DateTime ChkMakeSchDayWeekTime = DateTime.Now.AddDays(-1); static DateTime ChkMakeSchDayWeekTime = DateTime.Now.AddDays(-1);
static DateTime ChkMakePrjUpdateWeekTime = DateTime.Now.AddDays(-1);
static DateTime ChkMakeSchDay = DateTime.Now.AddDays(-1); static DateTime ChkMakeSchDay = DateTime.Now.AddDays(-1);
static DateTime ChkNoSchedule = DateTime.Now.AddDays(-1); static DateTime ChkNoSchedule = DateTime.Now.AddDays(-1);
static DateTime ChkJobreportDay = DateTime.Now.AddDays(-1); static DateTime ChkJobreportDay = DateTime.Now.AddDays(-1);
@@ -66,7 +67,7 @@ namespace Console_SendMail
static void Main(string[] args) static void Main(string[] args)
{ {
Console.WriteLine("mail start"); Console.WriteLine($"mail start ver 2508051140");
while (true) while (true)
{ {
@@ -88,6 +89,16 @@ namespace Console_SendMail
finally { ChkMakeAutoTime = DateTime.Now; } finally { ChkMakeAutoTime = DateTime.Now; }
} }
//프로젝트업데이트알림
var tsPrjUpdateweek = DateTime.Now - ChkMakePrjUpdateWeekTime;
if (tsPrjUpdateweek.TotalMinutes > 30 && DateTime.Now.DayOfWeek == DayOfWeek.Monday && DateTime.Now.Hour >= 10 && DateTime.Now.Hour <= 18)
{
try { Mail_MakeUpdateRequireProject(); }
catch { }
finally { ChkMakePrjUpdateWeekTime = DateTime.Now; }
}
///스케쥴 기한 알림(주) ///스케쥴 기한 알림(주)
var tsScheDayweek = DateTime.Now - ChkMakeSchDayWeekTime; var tsScheDayweek = DateTime.Now - ChkMakeSchDayWeekTime;
if (tsScheDayweek.TotalMinutes > 30 && DateTime.Now.DayOfWeek == DayOfWeek.Monday && DateTime.Now.Hour >= 10 && DateTime.Now.Hour <= 18) if (tsScheDayweek.TotalMinutes > 30 && DateTime.Now.DayOfWeek == DayOfWeek.Monday && DateTime.Now.Hour >= 10 && DateTime.Now.Hour <= 18)
@@ -98,6 +109,7 @@ namespace Console_SendMail
finally { ChkMakeSchDayWeekTime = DateTime.Now; } finally { ChkMakeSchDayWeekTime = DateTime.Now; }
} }
///스케쥴 기한 알림(일) ///스케쥴 기한 알림(일)
var tsScheDay = DateTime.Now - ChkMakeSchDay; var tsScheDay = DateTime.Now - ChkMakeSchDay;
if (tsScheDay.TotalMinutes > 30 && DateTime.Now.DayOfWeek != DayOfWeek.Saturday && if (tsScheDay.TotalMinutes > 30 && DateTime.Now.DayOfWeek != DayOfWeek.Saturday &&

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 // 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
// 기본값으로 할 수 있습니다. // 기본값으로 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("25.06.16.1530")] [assembly: AssemblyVersion("25.08.05.1130")]
[assembly: AssemblyFileVersion("25.06.16.1530")] [assembly: AssemblyFileVersion("25.08.05.1130")]

View File

@@ -4,6 +4,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -779,6 +781,7 @@ namespace Console_SendMail
taMailPrjSche.Dispose(); taMailPrjSche.Dispose();
} }
/// <summary> /// <summary>
/// 스케쥴기한임박알림(주) /// 스케쥴기한임박알림(주)
/// </summary> /// </summary>
@@ -823,8 +826,8 @@ namespace Console_SendMail
if (Existweek) return; if (Existweek) return;
//대상 사용자 목록을 추출한다 //대상 사용자 목록을 추출한다
var users = new DSMail.vMailingProjectScheduleDataTable(); var datas = new DSMail.vMailingProjectScheduleDataTable();
taMailPrjSche.Fill(users, vGcode); taMailPrjSche.Fill(datas, vGcode);
//var users = db.vMailingProjectSchedule.ToList();// .vJobReportForUser.Where(t => t.gcode == Pub.vGcode).GroupBy(t => t.id); //var users = db.vMailingProjectSchedule.ToList();// .vJobReportForUser.Where(t => t.gcode == Pub.vGcode).GroupBy(t => t.id);
//Console.WriteLine($"[{vGcode}] {users.Count} 명의 데이터가 확인 되었습니다");// (); //Console.WriteLine($"[{vGcode}] {users.Count} 명의 데이터가 확인 되었습니다");// ();
@@ -840,7 +843,7 @@ namespace Console_SendMail
body.AppendLine("<td>스케쥴</td>"); body.AppendLine("<td>스케쥴</td>");
body.AppendLine("</tr>"); body.AppendLine("</tr>");
var gp = users.GroupBy(t => t.idx); var gp = datas.GroupBy(t => t.idx);
foreach (var row in gp) foreach (var row in gp)
{ {
var prc = row.Sum(t => t.progress) / row.Count(); var prc = row.Sum(t => t.progress) / row.Count();
@@ -970,6 +973,240 @@ namespace Console_SendMail
taMailPrjSche.Dispose(); taMailPrjSche.Dispose();
} }
/// <summary>
/// 프로젝트업데이트요청(주)
/// </summary>
public static void Mail_MakeUpdateRequireProject()
{
var taForm = new DSMailTableAdapters.MailFormTableAdapter();
var taMailData = new DSMailTableAdapters.MailDataTableAdapter();
//var taMailPrjSche = new DSMailTableAdapters.vMailingProjectScheduleTableAdapter();
var vCate = "PN";
try
{
Console.WriteLine("프로젝트업데이트요청(주) 미 작성자 추출 작업을 시작 합니다");
var gcodelist = DatabaseManager.getGroupListWithoutGcode("gcode", "MailForm", "gcode is not null and gcode <> 'DEV'");
//var db = new EEEntities();
//기준일자는 오늘부터 -15일이다
//var sd = DateTime.Now.AddDays(-15);
//var ed = DateTime.Now;
//var str_sd = sd.ToShortDateString();
//var str_ed = ed.ToShortDateString();
var str_dt = DateTime.Now.ToShortDateString();
var sql = "select (select isnull(max(pdate),'') from ProjectsHistory where pidx = Projects.idx) as LastHistory," +
" idx,status,name,sdate,ddate,orderno as CR,crdue,dbo.getUserName(isnull(championid,usermanager)) as NameChampion," +
" dbo.getUserName(isnull(designid,usermain)) as NameDesign,dbo.getUserName(isnull(epanelid,userhw2)) as NameEPanel," +
" dbo.getUserName(isnull(softwareid,usersub)) as NameSoftware,championid as IdChampion,designid as IdDesign," +
" epanelid as IdEPanel,softwareid as IdSoftware " +
" from Projects where gcode = @gcode and status = '진행'" +
$" and pdate >= '{DateTime.Now.AddYears(-3).ToShortDateString()}'";
var cs = Properties.Settings.Default.cs;
var cn = new System.Data.SqlClient.SqlConnection(cs);
var cmd = new SqlCommand(sql, cn);
cmd.Parameters.Add("gcode", System.Data.SqlDbType.VarChar);
cn.Open();
//대상 그룹코드를 모두 확인한다
foreach (var vGcode in gcodelist)
{
//메일기능이 꺼져있다면 처리하지 않는다.
var usemail = DatabaseManager.GetGroupEnableMail(vGcode);
if (usemail == false) continue;
//메일양식이 지정되어있는지 체크
var MailJD = taForm.GetData(vGcode, vCate).FirstOrDefault();
if (MailJD == null) continue;
if (MailJD.exceptmail == null) MailJD.exceptmail = string.Empty;
if (MailJD.exceptmailcc == null) MailJD.exceptmailcc = string.Empty;
if (string.IsNullOrEmpty(MailJD.subject) || string.IsNullOrEmpty(MailJD.tolist)) continue;
//오늘날짜로 데이터가 등록되어있느지 확인한다.
var Existweek = taMailData.GetData(vGcode, str_dt, vCate).Where(t => t.tolist.Equals("chikyun.kim@amkor.co.kr") == false && t.wuid.Equals("debug") == false).Any();
if (Existweek) return;
cmd.Parameters[0].Value = vGcode;
//메일데이터 생성
var body = new System.Text.StringBuilder();
body.AppendLine("<table border='1' cellspacing='1' cellpadding='1' style='text-align:center;'>");
body.AppendLine("<tr>");
body.AppendLine("<td>idx</td>");
body.AppendLine("<td>Project</td>");
body.AppendLine("<td>LastUpdate</td>");
body.AppendLine("<td>Champion</td>");
body.AppendLine("<td>Design</td>");
body.AppendLine("<td>EPanel</td>");
body.AppendLine("<td>Software</td>");
body.AppendLine("<td>Start</td>");
body.AppendLine("<td>Due</td>");
body.AppendLine("</tr>");
var gp = cmd.ExecuteReader();
List<string> emaillist = new List<string>();
while (gp.Read())
{
var lasthistory = gp[0]?.ToString() ?? string.Empty;
var prjidx = gp["idx"]?.ToString() ?? string.Empty;
var prjname = gp["name"]?.ToString() ?? string.Empty;
var prjstart = gp["sdate"]?.ToString() ?? string.Empty;
var prjend = gp["ddate"]?.ToString() ?? string.Empty;
var NameChampion = gp["NameChampion"]?.ToString() ?? string.Empty;
var NameDesign = gp["NameDesign"]?.ToString() ?? string.Empty;
var NameEPanel = gp["NameEPanel"]?.ToString() ?? string.Empty;
var NameSoftware = gp["NameSoftware"]?.ToString() ?? string.Empty;
var IdChampion = gp["IdChampion"]?.ToString() ?? string.Empty;
var IdDesign = gp["IdDesign"]?.ToString() ?? string.Empty;
var IdEPanel = gp["IdEPanel"]?.ToString() ?? string.Empty;
var IdSoftware = gp["IdSoftware"]?.ToString() ?? string.Empty;
if (string.IsNullOrEmpty(lasthistory) == false)
{
//일주일 전이라면 넘어간다.
if (DateTime.TryParse(lasthistory, out DateTime lastindate))
{
if (lastindate >= DateTime.Now.AddDays(-7)) continue;
}
}
//담당자의 메일주소를 취합해야한다.
var email_champion = DatabaseManager.GetUserEmail(vGcode, IdChampion);
var email_design = DatabaseManager.GetUserEmail(vGcode, IdDesign);
var email_epanel = DatabaseManager.GetUserEmail(vGcode, IdEPanel);
var email_software = DatabaseManager.GetUserEmail(vGcode, IdSoftware);
if (string.IsNullOrEmpty(email_champion) ==false && emaillist.Contains(email_champion) == false) emaillist.Add(email_champion);
if (string.IsNullOrEmpty(email_design) == false && emaillist.Contains(email_design) == false) emaillist.Add(email_design);
if (string.IsNullOrEmpty(email_epanel) == false && emaillist.Contains(email_epanel) == false) emaillist.Add(email_epanel);
if (string.IsNullOrEmpty(email_software) == false && emaillist.Contains(email_software) == false) emaillist.Add(email_software);
body.AppendLine($"<tr>");
body.AppendLine($"<td>{prjidx}</td>");
body.AppendLine($"<td>{prjname}</td>");
body.AppendLine($"<td>{lasthistory}</td>");
body.AppendLine($"<td>{NameChampion}</td>");
body.AppendLine($"<td>{NameDesign}</td>");
body.AppendLine($"<td>{NameEPanel}</td>");
body.AppendLine($"<td>{NameSoftware}</td>");
body.AppendLine($"<td>{prjstart}</td>");
body.AppendLine($"<td>{prjend}</td>");
body.AppendLine("</tr>");
}
body.AppendLine("</table>");
//일별경고(월요일제외)
var mail_subject = MailJD.subject;//.Replace("{담당자}", userinfo.name).Replace("{사번}", userinfo.id);
var mail_to = MailJD.tolist;
if (emaillist.Any() && mail_to.Contains("{")) mail_to = mail_to.Replace("{담당자}", string.Join(";", emaillist));
var mail_cc = string.Empty; //
if (MailJD.cc != null) mail_cc = MailJD.cc;//.Replace("{담당자}", userinfo.email);
if (emaillist.Any() && mail_cc.Contains("{")) mail_cc = mail_cc.Replace("{담당자}", string.Join(";", emaillist));
var mail_bcc = string.Empty;
if (MailJD.bcc != null) mail_bcc = MailJD.bcc;//.Replace("{담당자}", userinfo.email);
if (emaillist.Any() && mail_bcc.Contains("{")) mail_bcc = mail_bcc.Replace("{담당자}", string.Join(";", emaillist));
var mail_body = MailJD.body;//.Replace("{담당자}", userinfo.name);
//mail_body = mail_body.Replace("{사번}", userinfo.id);
//메일본문을 생성해서 진행해야함
var mail_content = mail_body;
if (mail_content.Contains("{data}"))
mail_content = mail_content.Replace("{data}", body.ToString());
else
mail_content += "<br />" + body.ToString();
//메일데이터를 생성한다.
//mail_to = "chikyun.kim@amkor.co.kr";
//mail_bcc = string.Empty;
//mail_cc = string.Empty;
mail_to = MailSort(mail_to, MailJD.exceptmail);
if (string.IsNullOrEmpty(mail_to) == false)
{
using (var dt = new DSMail.MailDataDataTable())
{
var newdr = dt.NewMailDataRow();
newdr.gcode = vGcode;
newdr.cate = vCate;
newdr.subject = mail_subject;
newdr.fromlist = "eetgw@amkor.co.kr";
newdr.tolist = mail_to;// MailSort(mail_to, MailJD.exceptmail);
newdr.bcc = mail_bcc;
newdr.cc = MailSort(mail_cc, MailJD.exceptmailcc);
newdr.pdate = DateTime.Now.ToShortDateString();
newdr.body = mail_content;
newdr.wuid = "dev";// "dev";
newdr.wdate = DateTime.Now;
if (System.Diagnostics.Debugger.IsAttached)
{
newdr.tolist = "chikyun.kim@amkor.co.kr";
newdr.bcc = string.Empty;
newdr.cc = string.Empty;
newdr.wuid = "debug";
}
newdr.EndEdit();
dt.AddMailDataRow(newdr);
var cnt = taMailData.Update(dt);// db.SaveChanges();
Console.WriteLine($"[{vGcode}] 메일 전송 완료(프로젝트업데이트)");
}
}
}
cmd.Dispose();
cn.Close();
cn.Dispose();
}
catch (Exception ex)
{
using (var dt = new DSMail.MailDataDataTable())
{
var newdr = dt.NewMailDataRow();
newdr.gcode = "EET1P";
newdr.cate = "ER";
newdr.subject = "[ERROR] 프로젝트업데이트(주) 메일작성 실패";
newdr.fromlist = "chikyun.kim@amkor.co.kr";
newdr.tolist = "chikyun.kim@amkor.co.kr";
newdr.bcc = string.Empty;
newdr.cc = string.Empty;
newdr.pdate = DateTime.Now.ToShortDateString();
newdr.body = ex.Message;
newdr.wuid = "dev";// "dev";
newdr.wdate = DateTime.Now;
if (System.Diagnostics.Debugger.IsAttached)
{
newdr.tolist = "chikyun.kim@amkor.co.kr";
newdr.bcc = string.Empty;
newdr.cc = string.Empty;
newdr.wuid = "debug";
}
newdr.EndEdit();
dt.AddMailDataRow(newdr);
var cnt = taMailData.Update(dt);
}
}
finally
{
ChkMakeSchDayWeekTime = DateTime.Now;
}
taForm.Dispose();
taMailData.Dispose();
}
/// <summary> /// <summary>
/// 전송되지 않은 메일을 확인하고 그것을 전송한다 /// 전송되지 않은 메일을 확인하고 그것을 전송한다
/// </summary> /// </summary>
@@ -1099,7 +1336,7 @@ namespace Console_SendMail
} }
catch (Exception eX) catch (Exception eX)
{ {
Console.WriteLine("[sendmail] : "+ eX.Message); Console.WriteLine("[sendmail] : " + eX.Message);
sendMsg = eX.Message; sendMsg = eX.Message;
msgupdate = true; msgupdate = true;
} }