123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- using Microsoft.EntityFrameworkCore;
- using Quartz;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading;
- using System.Threading.Tasks;
- using wispro.sp.entity;
- namespace wispro.sp.api.Job
- {
- public class UpdateJXDataFromIPEasyJob : IJob
- {
- public void UpdateFromIPEasy(PerformanceItem Item,spDbContext spDb)
- {
- dynamic retObj = utility.IPEasyUtility.GetPerformanceRecord(Item.CaseNo, Item.DoItem, string.IsNullOrEmpty(Item.CaseStage) ? null : Item.CaseStage);
- IDictionary<String, Object> keyValuePairs = (IDictionary<String, Object>)retObj;
- if (keyValuePairs.ContainsKey("DoItemCoefficient") && Item.DoItemCoefficient != retObj.DoItemCoefficient)
- {
- Item.DoItemCoefficient = retObj.DoItemCoefficient;
- }
- //if (keyValuePairs.ContainsKey("DoItemMemo") && Item.DoItemMemo != retObj.DoItemMemo && !string.IsNullOrEmpty(retObj.DoItemMemo))
- //{
- // Item.DoItemMemo = retObj.DoItemMemo;
- //}
- //if (keyValuePairs.ContainsKey("DoItemState") && Item.DoItemState != retObj.DoItemState && !string.IsNullOrEmpty(retObj.DoItemState))
- //{
- // Item.DoItemState = retObj.DoItemState;
- //}
- //if (keyValuePairs.ContainsKey("CustomerLimitDate"))
- //{
- // if (!string.IsNullOrEmpty(retObj.CustomerLimitDate))
- // {
- // DateTime date = DateTime.Parse(retObj.CustomerLimitDate);
- // if (date != Item.CustomerLimitDate)
- // Item.CustomerLimitDate = date;
- // }
- //}
- //if (keyValuePairs.ContainsKey("EntrustingDate"))
- //{
- // if (!string.IsNullOrEmpty(retObj.EntrustingDate))
- // {
- // DateTime date = DateTime.Parse(retObj.EntrustingDate);
- // if (date != Item.EntrustingDate)
- // Item.EntrustingDate = date;
- // }
- //}
- //if (keyValuePairs.ContainsKey("FinalizationDate"))
- //{
- // if (!string.IsNullOrEmpty(retObj.FinalizationDate))
- // {
- // DateTime date = DateTime.Parse(retObj.FinalizationDate);
- // if (date != Item.FinalizationDate)
- // Item.FinalizationDate = date;
- // }
- //}
- //if (keyValuePairs.ContainsKey("FinishedDate"))
- //{
- // if (!string.IsNullOrEmpty(retObj.FinishedDate))
- // {
- // DateTime date = DateTime.Parse(retObj.FinishedDate);
- // if (date != Item.FinishedDate)
- // Item.FinishedDate = date;
- // }
- //}
- //if (keyValuePairs.ContainsKey("FirstDraftDate"))
- //{
- // if (!string.IsNullOrEmpty(retObj.FirstDraftDate))
- // {
- // DateTime date = DateTime.Parse(retObj.FirstDraftDate);
- // if (date != Item.FirstDraftDate)
- // Item.FirstDraftDate = date;
- // }
- //}
- //if (keyValuePairs.ContainsKey("InternalDate"))
- //{
- // if (!string.IsNullOrEmpty(retObj.InternalDate))
- // {
- // DateTime date = DateTime.Parse(retObj.InternalDate);
- // if (date != Item.InternalDate)
- // Item.InternalDate = date;
- // }
- //}
- //if (keyValuePairs.ContainsKey("ReturnDate"))
- //{
- // if (!string.IsNullOrEmpty(retObj.ReturnDate))
- // {
- // DateTime date = DateTime.Parse(retObj.ReturnDate);
- // if (date != Item.ReturnDate)
- // Item.ReturnDate = date;
- // }
- //}
- if (keyValuePairs.ContainsKey("WordCount"))
- {
- if (!string.IsNullOrEmpty(retObj.WordCount))
- {
- var wordCount = int.Parse(retObj.WordCount);
- if (wordCount != Item.WordCount)
- Item.WordCount = wordCount;
- }
- }
- if (keyValuePairs.ContainsKey("Reviewer") && (Item.Reviewer == null || Item.Reviewer.Name != retObj.Reviewer) && !string.IsNullOrEmpty(retObj.Reviewer))
- {
- string name = retObj.Reviewer;
- if (!string.IsNullOrEmpty(name))
- {
- string temName = name.Split('-')[0].Trim();
- if (!name.Contains("君龙"))
- {
- temName = name;
- }
- var temReviewer = spDb.Staffs.Where<Staff>(s => s.Name == temName).FirstOrDefault();
- if (temReviewer == null)
- {
- //Item.Reviewer = new Staff() { Name = retObj.Reviewer };
- }
- else
- {
- //Item.Reviewer = temReviewer;
- Item.ReviewerId = temReviewer.Id;
- }
- }
- }
- if (keyValuePairs.ContainsKey("ApplicationType") && Item.ApplicationType != retObj.ApplicationType && !string.IsNullOrEmpty(retObj.ApplicationType))
- {
- Item.ApplicationType = retObj.ApplicationType;
- }
- //if (keyValuePairs.ContainsKey("BusinessType") && Item.BusinessType != retObj.BusinessType && !string.IsNullOrEmpty(retObj.BusinessType))
- //{
- // Item.BusinessType = retObj.BusinessType;
- //}
- if (keyValuePairs.ContainsKey("CaseCoefficient") && Item.CaseCoefficient != retObj.CaseCoefficient)
- {
- Item.CaseCoefficient = retObj.CaseCoefficient;
- }
- //if (keyValuePairs.ContainsKey("CaseMemo") && Item.CaseMemo != retObj.CaseMemo && !string.IsNullOrEmpty(retObj.CaseMemo))
- //{
- // Item.CaseMemo = retObj.CaseMemo;
- //}
- //if (keyValuePairs.ContainsKey("CaseStage") && Item.CaseStage != retObj.CaseStage && !string.IsNullOrEmpty(retObj.CaseStage))
- //{
- // Item.CaseStage = retObj.CaseStage;
- //}
- //if (keyValuePairs.ContainsKey("CaseState") && Item.CaseState != retObj.CaseState && !string.IsNullOrEmpty(retObj.CaseState))
- //{
- // Item.CaseState = retObj.CaseState;
- //}
- if (keyValuePairs.ContainsKey("CaseType") && Item.CaseType != retObj.CaseType && !string.IsNullOrEmpty(retObj.CaseType))
- {
- Item.CaseType = retObj.CaseType;
- }
- if (spDb.Entry(Item).State != EntityState.Unchanged)
- {
- if (Item.AgentFeedbackMemo != "特殊点数申诉")
- {
- Utility.Utility.CalBasePoint(Item, spDb.BasePointRules.ToList());
- spDb.SaveChanges();
- new Controllers.PerformanceItemController(spDb, new Services.FileTaskCacheService()).RefreshBasePoint();
- }
- }
- }
- public void RefreshFromIPEasy(int type)
- {
- System.Threading.Thread t = new Thread(new ParameterizedThreadStart(RefreshFromIPEasy_BatchThread));
- t.Start(type);
- }
- /// <summary>
- /// 批量从IPEasy中更新数据
- /// </summary>
- /// <param name="type">
- /// 0:所有;
- /// 1:BasePoint为空记录;
- /// 2:新申请案件系数为空记录;
- /// 3:BasePoint为空记录 或者 新申请案件系数为空记录
- /// </param>
- /// <returns></returns>
- private void RefreshFromIPEasy_BatchThread(object type)
- {
- spDbContext spDb = new spDbContext();
- var Results = spDb.PerformanceItems.Include(p=>p.Customer).Where(p =>
- (p.AgentFeedbackMemo != "已算绩效" || p.AgentFeedbackMemo == null)
- && p.CalMonth.Status == 0
- && !p.CaseNo.StartsWith("J"));
- switch (type.ToString())
- {
- case "1":
- Results = Results.Where(p => p.BasePoint == null);
- break;
- case "2":
- Results = Results.Where(p => p.Type == "新申请" && p.CaseCoefficient == "");
- break;
- case "3":
- Results = Results.Where(p => p.BasePoint == null || (p.DoItem == "新申请" && p.CaseCoefficient == ""));
- break;
- }
- var listItems = Results.ToList();
- int i = 0;
- foreach (var Item in listItems)
- {
- int iTryCount = 0;
- TryAgain:
- try
- {
- iTryCount++;
- UpdateFromIPEasy(Item, spDb);
- Log($"{DateTime.Now}\t{++i}/{listItems.Count}\t{Item.CaseNo}");
- System.Diagnostics.Debug.WriteLine($"{DateTime.Now}\t{i}/{listItems.Count}\t{Item.CaseNo}");
- //}
- }
- catch (Exception ex)
- {
- if (iTryCount <= 3)
- {
- goto TryAgain;
- }
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- Log($"{DateTime.Now}\t{++i}/{listItems.Count}\t{Item.CaseNo}\t更新失败!");
- }
-
- }
- }
- public Task Execute(IJobExecutionContext context)
- {
- spDbContext spDb = new spDbContext();
- var lstItem = spDb.PerformanceItems.Where<PerformanceItem>(p =>
- ((p.AgentFeedbackMemo != "已算绩效" || p.AgentFeedbackMemo==null )
- && p.CalMonth.Status == 0 &&
- !p.CaseNo.StartsWith("J") &&
- (p.Type == null || (p.Type =="新申请" && string.IsNullOrEmpty(p.CaseCoefficient)))))
- .Include(p=>p.Reviewer)
- .Include(p=>p.CalMonth)
- .Include(p=>p.Customer)
- .ToList<PerformanceItem>();
-
- if (lstItem != null)
- {
- int i = 0;
- foreach (var Item in lstItem)
- {
-
- int iTryCount = 0;
- TryAgain:
- try
- {
- iTryCount++;
- UpdateFromIPEasy(Item, spDb);
- Log($"{DateTime.Now}\t{++i}/{lstItem.Count}\t{Item.CaseNo}");
- System.Diagnostics.Debug.WriteLine($"{DateTime.Now}\t{i}/{lstItem.Count}\t{Item.CaseNo}");
- //}
- }
- catch(Exception ex)
- {
- if(iTryCount <= 3)
- {
- goto TryAgain;
- }
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- Log($"{DateTime.Now}\t{++i}\t{Item.CaseNo}\r\n{ex.ToString()}");
- }
- }
- }
- return Task.CompletedTask;
- }
- private void Log(string strMessage)
- {
- StreamWriter sw = File.AppendText("c:\\temp\\log.txt");
- sw.WriteLine($"{strMessage}");
- sw.Flush();
- sw.Close();
- sw.Dispose();
- }
- }
- }
|