纽威
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.

120 lines
5.4 KiB

  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 ICSUser : 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 b.cPsn_Num AS UserCode,b.cPsn_Name AS UserName,b.cDept_num AS DepCode,c.cDepName AS DepName,
  49. NEWID() AS ID,CASE WHEN b.rEmployState='10' THEN '1' ELSE '0' END AS StartFlag,
  50. b.dEnterUnitDate AS CreateDate,
  51. 'job' AS CreateUserCode,
  52. b.dLastDate AS ModifyUserCode,
  53. '' AS ModifyDate,
  54. GETDATE() AS MTIME
  55. ,'{0}' as F_Location
  56. INTO #TempUser
  57. from {1}.DBO.hr_hi_person b with (nolock)
  58. left join {1}.DBO.Department c with (nolock) on b.cDept_num=c.cDepCode
  59. --where ISNULL(b.dLastDate, b.dEnterUnitDate)>=DATEADD(DAY, -1, @LastTime)
  60. ORDER BY b.cPsn_Num";
  61. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempUser");
  62. sql += @"--删除数据
  63. --DELETE Sys_SRM_User where F_Account NOT IN (SELECT cPsn_Num FROM {1}.dbo.[hr_hi_person])and Sys_SRM_User.F_Account<>'admin'
  64. SELECT a.F_Account INTO #tableSys_SRM_User
  65. FROM Sys_SRM_User a With(NoLock)
  66. LEFT JOIN {1}.dbo.[hr_hi_person] b With(NoLock) ON a.F_Account=b.cPsn_Num
  67. WHERE a.F_Location ='{0}' and b.cPsn_Num IS NULL and a.F_Account<>'admin'
  68. DELETE Sys_SRM_User
  69. WHERE F_Location='{0}' and F_Account IN ( SELECT F_Account from #tableSys_SRM_User)
  70. ";
  71. Dictionary<string, string> values = new Dictionary<string, string>();
  72. values.Add("F_RealName", "a.UserName");
  73. values.Add("F_CreatorTime", "a.CreateDate");
  74. values.Add("F_CreatorUserId", "a.CreateUserCode");
  75. values.Add("F_LastModifyUserId", "a.ModifyUserCode");
  76. values.Add("F_LastModifyTime", "a.ModifyDate");
  77. values.Add("F_DepartmentId", "a.DepCode");
  78. //values.Add("DepName", "a.DepName");
  79. values.Add("F_EnabledMark", "a.StartFlag");
  80. //更新存在数据
  81. sql += ICSHelper.UpdateSQL("b", values)
  82. + @" #TempUser a
  83. INNER JOIN Sys_SRM_User b ON a.UserCode=b.F_RealName and a.F_Location=b.F_Location
  84. WHERE a.F_Location='" + WorkPoint + "' ";
  85. values.Add("F_ID", "a.ID");
  86. values.Add("F_Account", "a.UserCode");
  87. //values.Add("UserPwd", "'NjMDK5c7vIs='");
  88. values.Add("F_Location", "'" + WorkPoint + "'");
  89. //插入新增数据
  90. sql += ICSHelper.InsertSQL("Sys_SRM_User", values)
  91. + @" #TempUser a
  92. LEFT JOIN Sys_SRM_User b ON a.UserCode=b.F_RealName and a.F_Location=b.F_Location
  93. WHERE b.F_ID IS NULL and a.F_Location='" + WorkPoint + @"'
  94. ";
  95. sql += " DROP TABLE #TempUser" +
  96. " DROP TABLE #tableSys_SRM_User";
  97. sql = string.Format(sql, WorkPoint, erpName);
  98. ICSHelper.ExecuteDate(conStr, sql);
  99. SRMUser.User();
  100. #endregion
  101. }
  102. }
  103. catch (Exception ex)
  104. {
  105. log.Error(ex.ToString());
  106. }
  107. }
  108. }
  109. }