纽威

134 lines
6.5 KiB

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