UpdateJXDataFromIPEasyJob.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. using Microsoft.Data.SqlClient;
  2. using Microsoft.EntityFrameworkCore;
  3. using Newtonsoft.Json.Schema;
  4. using Quartz;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Diagnostics;
  9. using System.Dynamic;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Net.Http;
  13. using System.Net.Http.Json;
  14. using System.Text.Json;
  15. using System.Threading;
  16. using System.Threading.Tasks;
  17. using wispro.sp.entity;
  18. using wispro.sp.utility;
  19. namespace wispro.sp.api.Job
  20. {
  21. public class UpdateJXDataFromIPEasyJob : IJob
  22. {
  23. public dynamic GetItemFromIPEasyDB(PerformanceItem Item, spDbContext spDb)
  24. {
  25. return wispro.sp.utility.IPEasyUtility.GetPerformanceRecord(Item.CaseNo, Item.DoItem,Item.CaseStage);
  26. #region 从维德系统服务上的API获取数据
  27. //HttpClient http = new HttpClient();
  28. ////http.GetFromJsonAsync($"{ConfigHelper.GetSectionValue("IPEasySetting:ipEeasyApi")}/api/ipEasy/GetItemFromIPEasyDB?CaseNo={Item.CaseNo}&DoItem={Item.DoItem}").Wait();
  29. //var response = http.GetFromJsonAsync<Object>($"{ConfigHelper.GetSectionValue("IPEasySetting:ipEeasyApi")}/api/ipEasy/GetItemFromIPEasyDB?CaseNo={Item.CaseNo}&DoItem={Item.DoItem}").Result;
  30. //dynamic retItem = new ExpandoObject();
  31. //JsonElement json = ((System.Text.Json.JsonElement)response);
  32. //retItem.CaseNo = json.GetProperty("CaseNo").GetString();
  33. //retItem.ApplicationType = json.GetProperty("ApplicationType").GetString();
  34. //retItem.BusinessType = json.GetProperty("BusinessType").GetString();
  35. //retItem.DoItem = json.GetProperty("DoItem").GetString();
  36. //retItem.CaseStage = json.GetProperty("CaseStage").GetString();
  37. //retItem.CaseCoefficient = json.GetProperty("CaseCoefficient").GetString();
  38. //retItem.DoItemCoefficient = json.GetProperty("DoItemCoefficient").GetString();
  39. //retItem.DoPersons = json.GetProperty("DoPersons").GetString();
  40. //retItem.Reviewer = json.GetProperty("Reviewer").GetString();
  41. //retItem.CustomerName = json.GetProperty("CustomerName").GetString();
  42. //retItem.FinishedDate = json.GetProperty("FinishedDate").GetString();
  43. //retItem.WordCount = json.GetProperty("WordCount").GetString();
  44. //retItem.ReturnDate = json.GetProperty("ReturnDate").GetString();
  45. //retItem.CaseType = json.GetProperty("CaseType").GetString();
  46. //retItem.CaseState = json.GetProperty("CaseState").GetString();
  47. //retItem.DoItemMemo = json.GetProperty("DoItemMemo").GetString();
  48. //retItem.DoItemState = json.GetProperty("DoItemState").GetString();
  49. //retItem.CaseName = json.GetProperty("CaseName").GetString();
  50. //retItem.EntrustingDate = json.GetProperty("EntrustingDate").GetString();
  51. //retItem.CustomerLimitDate = json.GetProperty("CustomerLimitDate").GetString();
  52. //retItem.InternalDate = json.GetProperty("InternalDate").GetString();
  53. //retItem.FirstDraftDate = json.GetProperty("FirstDraftDate").GetString();
  54. //retItem.CaseMemo = json.GetProperty("CaseMemo").GetString();
  55. //retItem.FinalizationDate = json.GetProperty("FinalizationDate").GetString();
  56. //return retItem;
  57. #endregion
  58. #region old code 直接从数据库中获取数据
  59. //dynamic retItem = new ExpandoObject();
  60. //var dt = new DataTable();
  61. //using (var conn = new SqlConnection(ConfigHelper.GetSectionValue("IPEasySetting:ConnectionStrings")))
  62. //{
  63. // try
  64. // {
  65. // conn.Open();
  66. // string strSql = @"SELECT distinct p_case_info.case_volume as case_volume,
  67. // i_apply_type.apply_type_zh_cn as apply_type_zh_cn,
  68. // i_business_type.business_type_zh_cn as business_type_zh_cn,
  69. // i_ctrl_proc.ctrl_proc_zh_cn as ctrl_proc_zh_cn,
  70. // (select case_status_zh_cn from i_case_status where case_status_id=p_proc_info.review_stage) as review_stage,
  71. // i_case_coefficient.case_coefficient_zh_cn as case_coefficient,
  72. // i_proc_coefficient.proc_coefficient_zh_cn as proc_coefficient,
  73. // (select proc_coefficient_zh_cn from p_proc_info pr
  74. // left join i_proc_coefficient pc on pc.proc_coefficient_id=pr.proc_coefficient_id
  75. // where case_id=p_case_info.case_id and ctrl_proc_id='8b96378e-05a0-4a8d-b3d1-39af92fddaf5'
  76. // and pr.seq=
  77. // (select max(seq) from p_proc_info pr where case_id=p_case_info.case_id
  78. // and ctrl_proc_id='8b96378e-05a0-4a8d-b3d1-39af92fddaf5'and seq<p_proc_info.seq)
  79. // ) as oa_proc_coefficient,
  80. // (STUFF((SELECT ',' + u.cn_name from p_proc_pic_list as pl
  81. // inner join s_user_info as u on u.user_id = pl.pic_id
  82. // inner join p_proc_info pr1 on pr1.proc_id=pl.obj_id
  83. // where case_id=p_case_info.case_id and
  84. // ctrl_proc_id='8b96378e-05a0-4a8d-b3d1-39af92fddaf5'
  85. // and pr1.seq=(
  86. // select max(seq) from p_proc_info pr2 where case_id=p_case_info.case_id
  87. // and ctrl_proc_id='8b96378e-05a0-4a8d-b3d1-39af92fddaf5'
  88. // and seq<p_proc_info.seq) FOR XML PATH('') ),1,1,''))
  89. // as oa_pic_list,
  90. // STUFF((SELECT ',' + ur.rank_zh_cn from p_proc_pic_list as pl
  91. // inner join s_user_info as u on u.user_id = pl.pic_id
  92. // left join i_user_rank ur on ur.rank_id=u.rank_id
  93. // where pl.obj_id = p_proc_info.proc_id FOR XML PATH('') ),1,1,'') as user_rank,
  94. // STUFF((SELECT ',' + u.cn_name from p_proc_pic_list as pl
  95. // inner join s_user_info as u on u.user_id = pl.pic_id
  96. // where pl.obj_id = p_proc_info.proc_id FOR XML PATH('') ),1,1,'') as pic,
  97. // STUFF((SELECT ',' + u.cn_name from p_revise_user_list as pl
  98. // inner join s_user_info as u on u.user_id = pl.revise_user_id
  99. // where pl.obj_id = p_proc_info.proc_id FOR XML PATH('') ),1,1,'') as reviser,
  100. // c_customer.customer_name as customer_name,
  101. // STUFF((SELECT ',' + a.applicant_name_cn from p_applicant_list as al
  102. // inner join i_applicant as a on a.applicant_id = al.applicant_id
  103. // where al.obj_id = p_case_info.case_id order by al.seq FOR XML PATH('') ),1,1,'') as applicants,
  104. // p_proc_info.finish_date as finish_date,
  105. // p_proc_info.finish_doc_date as finish_doc_date,
  106. // p_proc_info.back_date as back_date,
  107. // i_case_type.case_type_zh_cn as case_type_zh_cn,
  108. // i_case_status.case_status_zh_cn as case_status_zh_cn,
  109. // p_proc_info.proc_note as proc_note,
  110. // (select proc_status_zh_cn from i_proc_status where proc_status_id=p_proc_info.proc_status_id) as proc_status_zh_cn,
  111. // p_case_info.case_name as case_name,
  112. // p_case_info.charge_date as charge_date,
  113. // p_proc_info.cus_due_date as cus_due_date,
  114. // p_proc_info.int_due_date as int_due_date,
  115. // p_proc_info.first_doc_date as first_doc_date,
  116. // p_case_info.remark as case_remark,
  117. // p_proc_info.translate_count as translate_count,
  118. // STUFF((SELECT ',' + ui.cn_name from p_sales_list as sl
  119. // inner join dbo.s_user_info as ui on ui.user_id = sl.sales_user_id
  120. // where sl.obj_id = p_case_info.case_id AND sl.is_enabled=1 order by sl.seq FOR XML PATH('') ),1,1,'') as sales,
  121. // i_country.country_zh_cn as country_zh_cn
  122. // from p_case_info
  123. // inner join p_case_advance_info with(nolock) on p_case_info.case_id=p_case_advance_info.case_id
  124. // inner join i_apply_type with(nolock) on i_apply_type.apply_type_id=p_case_info.apply_type_id
  125. // inner join i_case_type with(nolock) on i_case_type.case_type_id=p_case_info.case_type_id
  126. // inner join i_country with(nolock) on i_country.country_id=p_case_info.country_id
  127. // inner join i_case_status with(nolock) on i_case_status.case_status_id=p_case_info.case_status_id
  128. // inner join c_customer with(nolock) on c_customer.customer_id=p_case_info.customer_id
  129. // left join i_case_coefficient on i_case_coefficient.case_coefficient_id=p_case_info.case_coefficient_id
  130. // inner join p_proc_info with(nolock) on p_case_info.case_id=p_proc_info.case_id
  131. // inner join i_ctrl_proc with(nolock) on p_proc_info.ctrl_proc_id=i_ctrl_proc.ctrl_proc_id
  132. // inner join i_business_type on i_business_type.business_type_id = p_case_info.business_type_id
  133. // left join p_proc_pic_list with(nolock) on p_proc_pic_list.obj_id=p_proc_info.proc_id
  134. // left join s_user_info with(nolock) on s_user_info.user_id=p_proc_pic_list.pic_id
  135. // left join i_proc_coefficient on i_proc_coefficient.proc_coefficient_id=p_proc_info.proc_coefficient_id
  136. // where
  137. // p_case_info.is_enabled=1 and
  138. // p_proc_info.is_enabled=1 and
  139. // s_user_info.dept_id not in ('60e09ee0-fcc7-446f-badc-af9973079fee','34d0e351-71dc-418f-9b6b-bcb67af62fed','599cbe0c-044e-4ffc-9411-96dd9019d8a6') and
  140. // (p_case_info.case_type_id='31D1A147-2931-43B5-94AE-B72B1525BA8A') AND
  141. // i_ctrl_proc.ctrl_proc_zh_cn=@DoItem and
  142. // p_case_info.case_volume =@CaseNo";
  143. // //if (!string.IsNullOrEmpty(Item.CaseStage))
  144. // //{
  145. // // strSql = $"select * from ({strSql}) as t where review_stage=@CaseStage";
  146. // //}
  147. // using (var cmd = conn.CreateCommand())
  148. // {
  149. // cmd.CommandText = strSql;
  150. // cmd.CommandType = CommandType.Text;
  151. // cmd.Parameters.Add(new SqlParameter("DoItem", Item.DoItem.Trim()));
  152. // cmd.Parameters.Add(new SqlParameter("CaseNo", Item.CaseNo.Trim()));
  153. // //if (!string.IsNullOrEmpty(Item.CaseStage))
  154. // //{
  155. // // cmd.Parameters.Add(new SqlParameter("CaseStage", Item.CaseStage));
  156. // //}
  157. // using (var reader = cmd.ExecuteReader())
  158. // {
  159. // dt.Load(reader);
  160. // if (dt.Rows.Count > 1)
  161. // {
  162. // bool bRet = false;
  163. // foreach (DataRow row in dt.Rows)
  164. // {
  165. // retItem.FinishedDate = row["finish_date"].ToString();
  166. // DateTime temDate = DateTime.Now;
  167. // DateTime.TryParse(retItem.FinishedDate,out temDate);
  168. // if ((Item.FinishedDate.HasValue && Item.FinishedDate.Value == temDate) ||
  169. // (!string.IsNullOrEmpty(Item.CaseStage) && Item.CaseStage == row["review_stage"].ToString()))
  170. // {
  171. // GetItemData(retItem, row);
  172. // bRet = true;
  173. // break;
  174. // }
  175. // }
  176. // if (!bRet)
  177. // {
  178. // DataRow row = dt.Rows[0];
  179. // GetItemData(retItem, row);
  180. // }
  181. // }
  182. // else
  183. // {
  184. // if (dt.Rows.Count > 0)
  185. // {
  186. // DataRow row = dt.Rows[0];
  187. // GetItemData(retItem, row);
  188. // }
  189. // }
  190. // }
  191. // }
  192. // }
  193. // catch (Exception ex)
  194. // {
  195. // // error handling
  196. // throw;
  197. // }
  198. // finally
  199. // {
  200. // conn.Close();
  201. // }
  202. //}
  203. //return retItem;
  204. #endregion
  205. }
  206. private static void GetItemData(dynamic retItem, DataRow row)
  207. {
  208. retItem.CaseNo = row["case_volume"].ToString();
  209. retItem.ApplicationType = row["apply_type_zh_cn"].ToString();
  210. retItem.BusinessType = row["business_type_zh_cn"].ToString();
  211. retItem.DoItem = row["ctrl_proc_zh_cn"].ToString(); ;
  212. retItem.CaseStage = row["review_stage"].ToString();
  213. retItem.CaseCoefficient = row["case_coefficient"].ToString();
  214. retItem.DoItemCoefficient = row["proc_coefficient"].ToString();
  215. retItem.DoPersons = row["pic"].ToString();
  216. retItem.Reviewer = row["reviser"].ToString();
  217. retItem.CustomerName = row["customer_name"].ToString();
  218. retItem.FinishedDate = row["finish_date"].ToString();
  219. retItem.WordCount = row["translate_count"].ToString();
  220. retItem.ReturnDate = row["back_date"].ToString();
  221. retItem.CaseType = row["case_type_zh_cn"].ToString();
  222. retItem.CaseState = row["case_status_zh_cn"].ToString();
  223. retItem.DoItemState = row["proc_status_zh_cn"].ToString();
  224. retItem.DoItemMemo = row["proc_note"].ToString();
  225. retItem.CaseName = row["case_name"].ToString();
  226. retItem.EntrustingDate = row["charge_date"].ToString();
  227. retItem.CustomerLimitDate = row["cus_due_date"].ToString();
  228. retItem.InternalDate = row["int_due_date"].ToString();
  229. retItem.FirstDraftDate = row["first_doc_date"].ToString();
  230. retItem.CaseMemo = row["case_remark"].ToString();
  231. retItem.FinalizationDate = row["finish_doc_date"].ToString();
  232. }
  233. public void UpdateFromIPEasy(PerformanceItem Item,spDbContext spDb)
  234. {
  235. List<string> caseNos = new List<string>()
  236. {
  237. "AHK2211737",
  238. "PAHK2211739",
  239. "PACN2120893-TS",
  240. "PAKR2117244",
  241. "PAIN2117242",
  242. "PAEPO1912286",
  243. "PAUS2116581-转所",
  244. "PATW2111942",
  245. "PACN2024870-TS客户自行递交",
  246. "PAUS2010428",
  247. "PAEPO2111073",
  248. "PAUS1915675",
  249. "PAUS2111071",
  250. "PAAU2210170",
  251. "PAUS2010164",
  252. "PACN1914374",
  253. "PAUS2210315",
  254. "PAUS2016669-结案",
  255. "PAEPO1510129",
  256. "PAUS2016669-结案",
  257. "PACN2026619-TS",
  258. "PACN2123589-TS",
  259. "PACN2125458"
  260. };
  261. if (caseNos.Contains(Item.CaseNo))
  262. {
  263. System.Diagnostics.Debug.WriteLine("");
  264. }
  265. dynamic retObj = GetItemFromIPEasyDB(Item, spDb); //utility.IPEasyUtility.GetPerformanceRecord(Item.CaseNo, Item.DoItem, string.IsNullOrEmpty(Item.CaseStage) ? null : Item.CaseStage);
  266. var appealAJXS = spDb.AppealTypes.FirstOrDefault(p => p.Name.Contains("案件系数"));
  267. var appealCLSXXS = spDb.AppealTypes.FirstOrDefault(p => p.Name.Contains("处理事项系数"));
  268. var caseXS = (spDb.AppealRecords.FirstOrDefault(p => p.ItemId == Item.Id && p.TypeId == appealAJXS.Id && p.State == 1) == null);
  269. var doItemXS = (spDb.AppealRecords.FirstOrDefault(p => p.ItemId == Item.Id && p.TypeId == appealCLSXXS.Id && p.State == 1) == null);
  270. IDictionary<String, Object> keyValuePairs = (IDictionary<String, Object>)retObj;
  271. if (keyValuePairs.ContainsKey("DoItemCoefficient") && Item.DoItemCoefficient != retObj.DoItemCoefficient && doItemXS)
  272. {
  273. Item.DoItemCoefficient = retObj.DoItemCoefficient;
  274. }
  275. if (keyValuePairs.ContainsKey("WordCount"))
  276. {
  277. if (!string.IsNullOrEmpty(retObj.WordCount))
  278. {
  279. var wordCount = int.Parse(retObj.WordCount);
  280. if (wordCount != Item.WordCount)
  281. Item.WordCount = wordCount;
  282. }
  283. }
  284. if (keyValuePairs.ContainsKey("Reviewer") && (Item.Reviewer == null || Item.Reviewer.Name != retObj.Reviewer) && !string.IsNullOrEmpty(retObj.Reviewer))
  285. {
  286. string name = retObj.Reviewer;
  287. if (!string.IsNullOrEmpty(name))
  288. {
  289. string temName = name.Split('-')[0].Trim();
  290. if (!name.Contains("君龙"))
  291. {
  292. temName = name;
  293. }
  294. var temReviewer = spDb.Staffs.Where<Staff>(s => s.Name == temName).FirstOrDefault();
  295. if (temReviewer == null)
  296. {
  297. //Item.Reviewer = new Staff() { Name = retObj.Reviewer };
  298. }
  299. else
  300. {
  301. //Item.Reviewer = temReviewer;
  302. Item.ReviewerId = temReviewer.Id;
  303. }
  304. }
  305. }
  306. if (keyValuePairs.ContainsKey("ExternalHandler") && (Item.ExternalHandler == null || Item.ExternalHandler.Name != retObj.ExternalHandler) && !string.IsNullOrEmpty(retObj.ExternalHandler))
  307. {
  308. string name = retObj.ExternalHandler;
  309. if (!string.IsNullOrEmpty(name))
  310. {
  311. string temName = name.Split('-')[0].Trim();
  312. if (!name.Contains("君龙"))
  313. {
  314. temName = name;
  315. }
  316. var temExternalHandler = spDb.Staffs.Where<Staff>(s => s.Name == temName).FirstOrDefault();
  317. if (temExternalHandler == null)
  318. {
  319. //Item.Reviewer = new Staff() { Name = retObj.Reviewer };
  320. }
  321. else
  322. {
  323. //Item.Reviewer = temReviewer;
  324. Item.ExternalHandlerId = temExternalHandler.Id;
  325. }
  326. }
  327. }
  328. if (keyValuePairs.ContainsKey("ApplicationType") && Item.ApplicationType != retObj.ApplicationType && !string.IsNullOrEmpty(retObj.ApplicationType))
  329. {
  330. Item.ApplicationType = retObj.ApplicationType;
  331. }
  332. if (keyValuePairs.ContainsKey("CaseCoefficient") && Item.CaseCoefficient != retObj.CaseCoefficient && caseXS)
  333. {
  334. if(!(retObj.CaseCoefficient == null && string.IsNullOrEmpty(Item.CaseCoefficient)))
  335. Item.CaseCoefficient = retObj.CaseCoefficient;
  336. }
  337. if (keyValuePairs.ContainsKey("CaseType") && Item.CaseType != retObj.CaseType && !string.IsNullOrEmpty(retObj.CaseType))
  338. {
  339. Item.CaseType = retObj.CaseType;
  340. }
  341. if (keyValuePairs.ContainsKey("CaseStage") && Item.CaseStage != retObj.CaseStage && !string.IsNullOrEmpty(retObj.CaseStage))
  342. {
  343. Item.CaseStage = retObj.CaseStage;
  344. }
  345. if (spDb.Entry(Item).State != EntityState.Unchanged)
  346. {
  347. if (Item.AgentFeedbackMemo != "特殊点数申诉")
  348. {
  349. new Controllers.PerformanceItemController(spDb, new Services.FileTaskCacheService()).RefreshPoint(Item);
  350. }
  351. }
  352. }
  353. public void RefreshFromIPEasy(int type)
  354. {
  355. System.Threading.Thread t = new Thread(new ParameterizedThreadStart(RefreshFromIPEasy_BatchThread));
  356. t.Start(type);
  357. }
  358. /// <summary>
  359. /// 批量从IPEasy中更新数据
  360. /// </summary>
  361. /// <param name="type">
  362. /// 0:所有;
  363. /// 1:BasePoint为空记录;
  364. /// 2:新申请案件系数为空记录;
  365. /// 3:BasePoint为空记录 或者 新申请案件系数为空记录
  366. /// </param>
  367. /// <returns></returns>
  368. private void RefreshFromIPEasy_BatchThread(object type)
  369. {
  370. spDbContext spDb = new spDbContext();
  371. var Results = spDb.PerformanceItems.Include(p=>p.Customer).Where(p =>
  372. (p.AgentFeedbackMemo != "已算绩效" || p.AgentFeedbackMemo == null)
  373. && p.CalMonth.Status == 0
  374. && !p.CaseNo.StartsWith("J"));
  375. switch (type.ToString())
  376. {
  377. case "1":
  378. Results = Results.Where(p => p.BasePoint == null);
  379. break;
  380. case "2":
  381. Results = Results.Where(p => p.Type == "新申请" && p.CaseCoefficient == "");
  382. break;
  383. case "3":
  384. Results = Results.Where(p => p.BasePoint == null || (p.DoItem == "新申请" && p.CaseCoefficient == ""));
  385. break;
  386. }
  387. var listItems = Results.ToList();
  388. int i = 0;
  389. foreach (var Item in listItems)
  390. {
  391. int iTryCount = 0;
  392. TryAgain:
  393. try
  394. {
  395. iTryCount++;
  396. UpdateFromIPEasy(Item, spDb);
  397. Log($"{DateTime.Now}\t{++i}/{listItems.Count}\t{Item.CaseNo}");
  398. System.Diagnostics.Debug.WriteLine($"{DateTime.Now}\t{i}/{listItems.Count}\t{Item.CaseNo}");
  399. //}
  400. }
  401. catch (Exception ex)
  402. {
  403. if (iTryCount <= 3)
  404. {
  405. goto TryAgain;
  406. }
  407. System.Diagnostics.Debug.WriteLine(ex.ToString());
  408. Log($"{DateTime.Now}\t{++i}/{listItems.Count}\t{Item.CaseNo}\t更新失败!");
  409. }
  410. }
  411. }
  412. public Task Execute(IJobExecutionContext context)
  413. {
  414. spDbContext spDb = new spDbContext();
  415. int lastUpdate = getInt();
  416. var lstItem = spDb.PerformanceItems.Where<PerformanceItem>(p =>
  417. ((p.AgentFeedbackMemo != "已算绩效" || p.AgentFeedbackMemo==null )
  418. && p.CalMonth.Status == 0 &&
  419. !p.CaseNo.StartsWith("J")))
  420. .Include(p=>p.Reviewer)
  421. .Include(p=>p.CalMonth)
  422. .Include(p=>p.Customer)
  423. .Include(p=>p.ItemStaffs).ThenInclude(p=>p.DoPerson)
  424. .ToList<PerformanceItem>();
  425. if (lstItem != null)
  426. {
  427. int i = 0;
  428. foreach (var Item in lstItem)
  429. {
  430. if (i < lastUpdate)
  431. {
  432. i++;
  433. continue;
  434. }
  435. System.Threading.Thread.Sleep(100);
  436. int iTryCount = 0;
  437. TryAgain:
  438. try
  439. {
  440. iTryCount++;
  441. UpdateFromIPEasy(Item, spDb);
  442. Log($"{DateTime.Now}\t{++i}/{lstItem.Count}\t{Item.CaseNo}");
  443. //System.Diagnostics.Debug.WriteLine($"{DateTime.Now}\t{i}/{lstItem.Count}\t{Item.CaseNo}");
  444. //}
  445. save(i);
  446. }
  447. catch(Exception ex)
  448. {
  449. if(iTryCount <= 3)
  450. {
  451. goto TryAgain;
  452. }
  453. //System.Diagnostics.Debug.WriteLine(ex.ToString());
  454. Log($"{DateTime.Now}\t{++i}\t{Item.CaseNo}\r\n{ex.ToString()}");
  455. }
  456. }
  457. }
  458. try
  459. {
  460. System.IO.File.Delete(updateFilePath);
  461. }
  462. catch { }
  463. return Task.CompletedTask;
  464. }
  465. private void Log(string strMessage)
  466. {
  467. StreamWriter sw = File.AppendText("c:\\temp\\log.txt");
  468. sw.WriteLine($"{strMessage}");
  469. sw.Flush();
  470. sw.Close();
  471. sw.Dispose();
  472. }
  473. #region 添加一个记录更新绩效记录的进度文件,用于解决重新启动更新数据时重新从第一条开始导致更新时间漫长的问题
  474. string updateFilePath = "c:\\temp\\update.txt";
  475. private int getInt()
  476. {
  477. try
  478. {
  479. string sw = File.ReadAllText(updateFilePath);
  480. return int.Parse(sw);
  481. }
  482. catch
  483. {
  484. return 0;
  485. }
  486. }
  487. private void save(int i)
  488. {
  489. try
  490. {
  491. StreamWriter sw = File.CreateText(updateFilePath);
  492. sw.Write(i);
  493. sw.Flush();
  494. sw.Close();
  495. sw.Dispose();
  496. }
  497. catch { }
  498. }
  499. #endregion
  500. }
  501. }