|
|
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Quartz;
using System.Data;
namespace ICSSoft.FromERP { /// <summary>
/// 用户
/// </summary>
public class ICSUser : IJob { private static object key = new object(); private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); public void Execute(IJobExecutionContext context) { try { lock (key) { log.Info("开始……………………………………………………………………"); Execute(); log.Info("结束……………………………………………………………………"); } } catch (Exception ex) { log.Error(ex.ToString()); } }
public void Execute() { try {
//string conERPStr = ICSHelper.GetERPConnectString();
string conStr = ICSHelper.GetConnectString(); string Namespace = this.GetType().Namespace; //string Class = this.GetType().Name;
DataTable dt = ICSHelper.GetERPDB(conStr); foreach (DataRow dr in dt.Rows) { string erpName = ICSHelper.GetConfigString()["ERPDB"]; string WorkPoint = dr["WorkPointCode"].ToString(); string Class = this.GetType().Name + WorkPoint; erpName = string.Format(erpName, WorkPoint);
#region SQL
string sql = @"select b.cPsn_Num AS UserCode,b.cPsn_Name AS UserName,b.cDept_num AS DepCode,c.cDepName AS DepName,
NEWID() AS ID,CASE WHEN b.rEmployState='10' THEN '1' ELSE '0' END AS StartFlag, b.dEnterUnitDate AS CreateDate, 'job' AS CreateUserCode, b.dLastDate AS ModifyUserCode, '' AS ModifyDate, GETDATE() AS MTIME ,'{0}' as F_Location INTO #TempUser from {1}.DBO.hr_hi_person b with (nolock) left join {1}.DBO.Department c with (nolock) on b.cDept_num=c.cDepCode --where ISNULL(b.dLastDate, b.dEnterUnitDate)>=DATEADD(DAY, -1, @LastTime) ORDER BY b.cPsn_Num";
sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempUser");
sql += @"--删除数据
--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'
SELECT a.F_Account INTO #tableSys_SRM_User FROM Sys_SRM_User a With(NoLock) LEFT JOIN {1}.dbo.[hr_hi_person] b With(NoLock) ON a.F_Account=b.cPsn_Num WHERE a.F_Location ='{0}' and b.cPsn_Num IS NULL and a.F_Account<>'admin'
DELETE Sys_SRM_User WHERE F_Location='{0}' and F_Account IN ( SELECT F_Account from #tableSys_SRM_User) ";
Dictionary<string, string> values = new Dictionary<string, string>(); values.Add("F_RealName", "a.UserName"); values.Add("F_CreatorTime", "a.CreateDate"); values.Add("F_CreatorUserId", "a.CreateUserCode"); values.Add("F_LastModifyUserId", "a.ModifyUserCode"); values.Add("F_LastModifyTime", "a.ModifyDate"); values.Add("F_DepartmentId", "a.DepCode"); //values.Add("DepName", "a.DepName");
values.Add("F_EnabledMark", "a.StartFlag"); //更新存在数据
sql += ICSHelper.UpdateSQL("b", values) + @" #TempUser a
INNER JOIN Sys_SRM_User b ON a.UserCode=b.F_RealName and a.F_Location=b.F_Location WHERE a.F_Location='" + WorkPoint + "' ";
values.Add("F_ID", "a.ID"); values.Add("F_Account", "a.UserCode"); //values.Add("UserPwd", "'NjMDK5c7vIs='");
values.Add("F_Location", "'" + WorkPoint + "'"); //插入新增数据
sql += ICSHelper.InsertSQL("Sys_SRM_User", values) + @" #TempUser a
LEFT JOIN Sys_SRM_User b ON a.UserCode=b.F_RealName and a.F_Location=b.F_Location WHERE b.F_ID IS NULL and a.F_Location='" + WorkPoint + @"' ";
sql += " DROP TABLE #TempUser" + " DROP TABLE #tableSys_SRM_User"; sql = string.Format(sql, WorkPoint, erpName); ICSHelper.ExecuteDate(conStr, sql); SRMUser.User(); #endregion
} } catch (Exception ex) { log.Error(ex.ToString()); } } } }
|