123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- using Microsoft.EntityFrameworkCore;
- using Quartz;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using wispro.sp.entity;
- namespace wispro.sp.api.Job
- {
- public class UpdateJXDataFromIPEasyJob : IJob
- {
- public Task Execute(IJobExecutionContext context)
- {
- spDbContext spDb = new spDbContext();
- var lstItem = spDb.PerformanceItems.Where<PerformanceItem>(p =>
- (p.DoItem == "新申请" && (p.CaseCoefficient == null || p.CaseCoefficient == "") && p.CalMonth.Status == 0) ||
- (p.DoItem == "处理审查意见" && (p.CaseStage == "一通" || p.CaseStage == "二通") && (p.DoItemCoefficient == null || p.DoItemCoefficient == "") && p.CalMonth.Status == 0) ||
- ((p.DoItem == "Final Action") || (p.DoItem == "翻译校核") || (p.DoItem == "申復") || (p.DoItem == "口审评估") ||
- (p.DoItem == "欧洲案答辩") || (p.DoItem == "RCE") || (p.DoItem == "Non Final Action") || (p.DoItem == "Advisory Action") && (p.DoItemCoefficient == null || p.DoItemCoefficient =="") && p.CalMonth.Status == 0) ||
- (p.FinishedDate == null && p.CalMonth.Status == 0))
- .Include(p=>p.Reviewer)
- .Include(p=>p.CalMonth)
- .ToList<PerformanceItem>();
-
- if (lstItem != null)
- {
- int i = 0;
- foreach (var Item in lstItem)
- {
- if (Item.CaseNo == "PAIN2134921" || Item.CaseNo == "PAUS2010405" || Item.CaseNo == "PAUS2016667")
- {
- Console.WriteLine("");
- }
- System.Diagnostics.Debug.WriteLine($"{DateTime.Now}\t{++i}\t{Item.CaseNo}");
- int iTryCount = 0;
- TryAgain:
- try
- {
- iTryCount++;
- 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("Reviewer") && (Item.Reviewer ==null || Item.Reviewer.Name != retObj.Reviewer) && !string.IsNullOrEmpty(retObj.Reviewer))
- {
- string name = retObj.Reviewer;
- if (!string.IsNullOrEmpty(name))
- {
- var temReviewer = spDb.Staffs.Where<Staff>(s => s.Name == name).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 && !string.IsNullOrEmpty(retObj.CaseCoefficient))
- {
- if (!string.IsNullOrEmpty(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 (Item.FinishedDate.HasValue &&
- Item.FinishedDate.Value.ToString("yyyy-MM") != DateTime.Parse($"{Item.CalMonth.Year}-{Item.CalMonth.Month}-01").ToString("yyyy-MM"))
- {
- var ItemStaffs = spDb.ItemStaffs.Where(p => p.ItemId == Item.Id).ToList();
- foreach(var itemstaff in ItemStaffs)
- {
- spDb.Remove(itemstaff);
- }
- spDb.PerformanceItems.Remove(Item);
- spDb.SaveChanges();
- }
- else
- {
- if (spDb.Entry(Item).State != EntityState.Unchanged)
- {
- Utility.Utility.CalBasePoint(Item, spDb.BasePointRules.ToList());
- spDb.SaveChanges();
- }
- }
- }
- catch(Exception ex)
- {
- if(iTryCount <= 3)
- {
- goto TryAgain;
- }
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- }
- }
- }
- return Task.CompletedTask;
- }
- }
- }
|