|
|
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Quartz;
using System.Data;
namespace ICSSoft.FromERP { /// <summary>
/// 部门
/// </summary>
public class ICSDepartment : 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 cDepCode as DepCode,cDepName as DepName,cDepFullName as UserName,iDepGrade,
NEWID() AS ID,bDepEnd, dDepBeginDate AS CreateDate, 'job' AS CreateUserCode, dModifyDate AS ModifyUserCode, '' AS ModifyDate, GETDATE() AS MTIME , '{0}' as WorkPoint 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 cDepCode";
sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempUser");
sql += @"--删除数据
-- DELETE ICSDepartment WHERE DepCode NOT IN (SELECT DepCode FROM {1}.dbo.[Department]) SELECT a.DepCode INTO #tableICSDepartment FROM ICSDepartment a With(NoLock) LEFT JOIN {1}.dbo.[Department] b With(NoLock) ON a.DepCode=b.cDepCode WHERE a.WorkPoint='{0}' and b.cDepCode IS NULL
DELETE ICSDepartment WHERE WorkPoint='{0}' and DepCode IN ( SELECT DepCode from #tableICSDepartment)
";
Dictionary<string, string> values = new Dictionary<string, string>(); values.Add("DepCode", "a.DepCode"); values.Add("DepName", "a.DepName"); values.Add("DepFullName", "a.UserName"); values.Add("DepGrade", "a.iDepGrade"); values.Add("DepEnd", "a.bDepEnd"); values.Add("WorkPoint", "'" + WorkPoint + "'"); values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");//操作人
values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
values.Add("MTIME", "a.MTIME");//操作时间
//values.Add("PODetailID", ""); //自定义栏位
//更新存在数据
sql += ICSHelper.UpdateSQL("b", values) + @" #TempUser a
INNER JOIN ICSDepartment b ON a.DepCode=b.DepCode and a.WorkPoint=b.WorkPoint WHERE a.WorkPoint='" + WorkPoint + "' ";
//values.Add("WorkPointCode", "'" + WorkPoint + "'");
//插入新增数据
sql += ICSHelper.InsertSQL("ICSDepartment", values) + @" #TempUser a
LEFT JOIN ICSDepartment b ON a.DepCode=b.DepCode and a.WorkPoint=b.WorkPoint WHERE b.ID IS NULL and a.WorkPoint='" + WorkPoint + "' ";
sql += " DROP TABLE #TempUser " + " DROP TABLE #tableICSDepartment"; sql = string.Format(sql, WorkPoint, erpName); ICSHelper.ExecuteDate(conStr, sql); #endregion
} } catch (Exception ex) { log.Error(ex.ToString()); } } } }
|