IcsFromERPJob
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.

117 lines
5.4 KiB

4 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Quartz;
  6. using System.Data;
  7. namespace ICSSoft.FromERP
  8. {
  9. /// <summary>
  10. /// 部门
  11. /// </summary>
  12. public class ICSDepartment : IJob
  13. {
  14. private static object key = new object();
  15. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  16. public void Execute(IJobExecutionContext context)
  17. {
  18. try
  19. {
  20. lock (key)
  21. {
  22. log.Info("开始……………………………………………………………………");
  23. Execute();
  24. log.Info("结束……………………………………………………………………");
  25. }
  26. }
  27. catch (Exception ex)
  28. {
  29. log.Error(ex.ToString());
  30. }
  31. }
  32. public void Execute()
  33. {
  34. try
  35. {
  36. //string conERPStr = ICSHelper.GetERPConnectString();
  37. string conStr = ICSHelper.GetConnectString();
  38. string Namespace = this.GetType().Namespace;
  39. //string Class = this.GetType().Name;
  40. DataTable dt = ICSHelper.GetERPDB(conStr);
  41. foreach (DataRow dr in dt.Rows)
  42. {
  43. string erpName = ICSHelper.GetConfigString()["ERPDB"];
  44. string WorkPoint = dr["WorkPointCode"].ToString();
  45. string Class = this.GetType().Name + WorkPoint;
  46. erpName = string.Format(erpName, WorkPoint);
  47. #region SQL
  48. string sql = @"select cDepCode as DepCode,cDepName as DepName,cDepFullName as UserName,iDepGrade,
  49. NEWID() AS ID,bDepEnd,
  50. dDepBeginDate AS CreateDate,
  51. 'job' AS CreateUserCode,
  52. dModifyDate AS ModifyUserCode,
  53. '' AS ModifyDate,
  54. GETDATE() AS MTIME
  55. , '{0}' as WorkPoint
  56. INTO #TempUser
  57. from
  58. --{1}.DBO.hr_hi_person b with (nolock)
  59. --left join
  60. {1}.DBO.Department
  61. --c with (nolock) on b.cDept_num=c.cDepCode
  62. --where ISNULL(b.dLastDate, b.dEnterUnitDate)>=DATEADD(DAY, -1, @LastTime)
  63. ORDER BY cDepCode";
  64. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempUser");
  65. sql += @"--删除数据
  66. -- DELETE ICSDepartment WHERE DepCode NOT IN (SELECT DepCode FROM {1}.dbo.[Department])
  67. SELECT a.DepCode INTO #tableICSDepartment
  68. FROM ICSDepartment a With(NoLock)
  69. LEFT JOIN {1}.dbo.[Department] b With(NoLock) ON a.DepCode=b.cDepCode
  70. WHERE a.WorkPoint='{0}' and b.cDepCode IS NULL
  71. DELETE ICSDepartment
  72. WHERE WorkPoint='{0}' and DepCode IN ( SELECT DepCode from #tableICSDepartment)
  73. ";
  74. Dictionary<string, string> values = new Dictionary<string, string>();
  75. values.Add("DepCode", "a.DepCode");
  76. values.Add("DepName", "a.DepName");
  77. values.Add("DepFullName", "a.UserName");
  78. values.Add("DepGrade", "a.iDepGrade");
  79. values.Add("DepEnd", "a.bDepEnd");
  80. values.Add("WorkPoint", "'" + WorkPoint + "'");
  81. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");//操作人
  82. values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
  83. values.Add("MTIME", "a.MTIME");//操作时间
  84. //values.Add("PODetailID", ""); //自定义栏位
  85. //更新存在数据
  86. sql += ICSHelper.UpdateSQL("b", values)
  87. + @" #TempUser a
  88. INNER JOIN ICSDepartment b ON a.DepCode=b.DepCode and a.WorkPoint=b.WorkPoint
  89. WHERE a.WorkPoint='" + WorkPoint + "' ";
  90. //values.Add("WorkPointCode", "'" + WorkPoint + "'");
  91. //插入新增数据
  92. sql += ICSHelper.InsertSQL("ICSDepartment", values)
  93. + @" #TempUser a
  94. LEFT JOIN ICSDepartment b ON a.DepCode=b.DepCode and a.WorkPoint=b.WorkPoint
  95. WHERE b.ID IS NULL and a.WorkPoint='" + WorkPoint + "' ";
  96. sql += " DROP TABLE #TempUser " +
  97. " DROP TABLE #tableICSDepartment";
  98. sql = string.Format(sql, WorkPoint, erpName);
  99. ICSHelper.ExecuteDate(conStr, sql);
  100. #endregion
  101. }
  102. }
  103. catch (Exception ex)
  104. {
  105. log.Error(ex.ToString());
  106. }
  107. }
  108. }
  109. }