You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
4.7 KiB

2 years ago
  1. using Entity.Sugar;
  2. using Euro.Transfer.Base;
  3. using Newtonsoft.Json;
  4. using SqlSugar.Base;
  5. using System;
  6. using System.Collections.Generic;
  7. namespace Euro.Transfer.Jobs.BackRuns
  8. {
  9. public class Job : ServiceTask
  10. {
  11. /// <summary>
  12. /// 任务开始
  13. /// </summary>
  14. protected override void Start()
  15. {
  16. try
  17. {
  18. var sCurrDate = DateTime.Now.ToString("MM-dd");
  19. var sCurrTime = DateTime.Now.ToString("HH:mm");
  20. var sIsBackRuns = Common.ConfigGetValue("", "IsBackRuns");//是否執行
  21. if ((sCurrDate == "01-01") || sIsBackRuns == "true")
  22. {
  23. //运行中
  24. this.mIsRunning = true;
  25. //执行工作项
  26. this.Run();
  27. }
  28. }
  29. catch (Exception error)
  30. {
  31. //异常日志
  32. ServiceTools.WriteLog(Errorlog_Path + @"BackRuns\" + DateTime.Now.ToString("yyyyMMdd"), error.ToString(), true);
  33. }
  34. finally
  35. {
  36. //空闲
  37. this.mIsRunning = false;
  38. }
  39. }
  40. /// <summary>
  41. /// 任务停止
  42. /// </summary>
  43. protected override void Stop()
  44. {
  45. this.mIsRunning = false;
  46. }
  47. /// <summary>
  48. /// 执行請假設定默認設定
  49. /// </summary>
  50. protected void Run()
  51. {
  52. try
  53. {
  54. do
  55. {
  56. var db = SugarBase.GetIntance();
  57. var sCurrYear = DateTime.Now.ToString("yyyy");
  58. var sRegisterOrgID = Common.ConfigGetValue("", "RegisterOrgs");
  59. var saRegisterOrgs = sRegisterOrgID.Split(',');
  60. var saLeaveSet = new List<OTB_EIP_LeaveSet>();
  61. foreach (string org in saRegisterOrgs)
  62. {
  63. var saMembers = db.Queryable<OTB_SYS_Members>()
  64. .Where(t => t.OrgID == org && t.Effective == "Y" && t.ServiceCode != "API").ToList();
  65. var saArguments = db.Queryable<OTB_SYS_Arguments>()
  66. .Where(t => t.OrgID == org && t.Effective == "Y" && t.ArgumentClassID == "LeaveType").ToList();
  67. foreach (OTB_SYS_Members user in saMembers)
  68. {
  69. var iCount = db.Queryable<OTB_EIP_LeaveSet>().Count(t => t.OrgID == org && t.UserID == user.MemberID && t.TYear == sCurrYear);
  70. if (iCount == 0)
  71. {
  72. var oLeaveSet = new OTB_EIP_LeaveSet
  73. {
  74. Guid = Guid.NewGuid().ToString(),
  75. OrgID = org,
  76. UserID = user.MemberID,
  77. TYear = sCurrYear,
  78. CreateUser = nameof(Transfer),
  79. CreateDate = DateTime.Now
  80. };
  81. var dicSetInfo = new List<Dictionary<string, object>>();
  82. foreach (OTB_SYS_Arguments arg in saArguments)
  83. {
  84. var dicInfo = new Dictionary<string, object>
  85. {
  86. { "Id", arg.ArgumentID },
  87. { "Name", arg.ArgumentValue },
  88. { "PaymentHours", arg.Correlation ?? "" },
  89. { "UsedHours", "0" },
  90. { "RemainHours", arg.Correlation ?? "0" },
  91. { "Memo", arg.Memo }
  92. };
  93. dicSetInfo.Add(dicInfo);
  94. }
  95. oLeaveSet.SetInfo = JsonConvert.SerializeObject(dicSetInfo, Formatting.Indented);
  96. saLeaveSet.Add(oLeaveSet);
  97. }
  98. }
  99. }
  100. if (saLeaveSet.Count > 0)
  101. {
  102. var iRel = db.Insertable<OTB_EIP_LeaveSet>(saLeaveSet).ExecuteCommand();
  103. }
  104. } while (false);
  105. }
  106. catch (Exception error)
  107. {
  108. //写错误日志
  109. ServiceTools.WriteLog(Errorlog_Path + @"BackRuns\" + DateTime.Now.ToString("yyyyMMdd"), error.ToString(), true);
  110. }
  111. }
  112. }
  113. }