ImportReportJob.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. using DynamicExpresso;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using Quartz;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Configuration;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. using wispro.sp.entity;
  11. using wispro.sp.utility;
  12. namespace wispro.sp.api.Job
  13. {
  14. public class ImportReportJob : Quartz.IJob
  15. {
  16. /// <summary>
  17. /// 不需要计算绩效的处理事项
  18. /// </summary>
  19. private string[] InValidDoItem = new string[]
  20. {
  21. "案件异常-催缴年费",
  22. "案件异常-视为放弃取得专利权",
  23. "办理登记手续",
  24. "办理登记手续-确认客户是否委托",
  25. "代理所变更",
  26. "绘图",
  27. "技术确认",
  28. "缴年费",
  29. "请求保密审查",
  30. "请求费减",
  31. "请求实审",
  32. "取得申请号",
  33. "取得证书",
  34. "取得专利权评价报告",
  35. "确认官方审查状况",
  36. "询问放弃或复审",
  37. "知识点总结",
  38. "专利权人发明人申请人信息变更",
  39. "专利挖掘与布局",
  40. "我方文号前缀带J",
  41. "开卷",
  42. "请求提前公开",
  43. "取得国际检索报告",
  44. "委外检索",
  45. "中止程序",
  46. "终止",
  47. "案件异常-视为撤回",
  48. "进入国家阶段提醒",
  49. "请求恢复权利",
  50. "请求优先权",
  51. "取得【无效宣告请求审查决定】",
  52. "撤回",
  53. "请求退款",
  54. "确认是否委托申请与类型",
  55. "专利交易",
  56. "专利权评价报告",
  57. "专利权人发明人申请人信息变更+代理所变更"
  58. };
  59. spDbContext spDb = new spDbContext();
  60. public Task Execute(IJobExecutionContext context)
  61. {
  62. CalMonth calMonth = new CalMonth()
  63. {
  64. Year = DateTime.Now.AddMonths(-1).Year,
  65. Month = DateTime.Now.AddMonths(-1).Month,
  66. Status = 0
  67. };
  68. var temCalMonth = spDb.CalMonths.Where<CalMonth>(x => x.Year == calMonth.Year && x.Month == calMonth.Month).FirstOrDefault();
  69. if (temCalMonth != null)
  70. {
  71. var iCount = spDb.PerformanceItems.Where<PerformanceItem>(p => p.CalMonthId == temCalMonth.Id).Count<PerformanceItem>();
  72. if (iCount > 0)
  73. {
  74. return Task.CompletedTask;
  75. }
  76. calMonth = temCalMonth;
  77. }
  78. else
  79. {
  80. spDb.CalMonths.Add(calMonth);
  81. spDb.SaveChanges();
  82. }
  83. //每月绩效统计--发客户超过一个月未完成案件
  84. DownloadReport( "每月绩效统计--发客户超过一个月未完成案件", calMonth,false);
  85. //每月绩效统计--上个月递交完成案件
  86. DownloadReport("每月绩效统计--上个月递交完成案件", calMonth, true);
  87. //每月绩效统计--中国一次OA授权表
  88. DownloadReport("每月绩效统计--中国一次OA授权表", calMonth, true,true);
  89. //专案数据
  90. DownloadProject(calMonth);
  91. var lstStaff = spDb.Staffs.Where<Staff>(s=>s.ItemStaffs.Where<ItemStaff>(p=>p.Item.CalMonthId == calMonth.Id).Count<ItemStaff>()>0);
  92. foreach (var staff in lstStaff.ToList<Staff>())
  93. {
  94. string strSubject = $"{calMonth.Year}年{calMonth.Month}月绩效数据确认通知";
  95. string strBody = $"<html><body>{staff.Name},您好!<br/></br/>&nbsp;&nbsp;&nbsp;&nbsp;<div>{calMonth.Year}年{calMonth.Month}月绩效数据已生成,请在{DateTime.Now.AddDays(4).ToString("yyyy年MM月dd日")}之前确认完成!</div></body></html>";
  96. string strTo = "luocaiyang@wispro-china.com";
  97. _ = QuartzUtil.AddMailJob(strSubject, strBody, staff.Name, strTo);
  98. }
  99. return Task.CompletedTask;
  100. }
  101. private void DownloadReport(string ReportName,CalMonth calMonth,bool isModifyDate,bool isFirstOA=false)
  102. {
  103. string strFileSavePath = utility.ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  104. int tryCount = 0;
  105. tryAgain:
  106. try
  107. {
  108. wispro.sp.utility.IPEasyUtility.DownloadReport(ReportName, isModifyDate);
  109. }
  110. catch {
  111. tryCount++;
  112. if (tryCount < 5)
  113. {
  114. goto tryAgain;
  115. }
  116. }
  117. System.Threading.Thread.Sleep(5000);
  118. string filename = $"{ReportName.Trim()}.xlsx";
  119. string strFilePath = System.IO.Path.Combine(strFileSavePath, filename);
  120. string strFinalPath = System.IO.Path.Combine(strFileSavePath, $"{calMonth.Year}{calMonth.Month}-{filename}");
  121. InputPerformanceItem(strFilePath, true, false, 1, calMonth, isFirstOA);
  122. System.IO.File.Move(strFilePath, strFinalPath);
  123. }
  124. private void DownloadProject(CalMonth calMonth)
  125. {
  126. string strFileSavePath = utility.ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  127. int tryCount = 0;
  128. string[] ReportNames =new string[] { "每月绩效统计--专案进度跟踪~S卷", "每月绩效统计--专案开卷报表~S卷" };
  129. List<PerformanceItem> pfItems = new List<PerformanceItem>();
  130. foreach (var ReportName in ReportNames)
  131. {
  132. tryAgain:
  133. try
  134. {
  135. wispro.sp.utility.IPEasyUtility.DownloadReport(ReportName, false);
  136. }
  137. catch
  138. {
  139. tryCount++;
  140. if (tryCount < 5)
  141. {
  142. goto tryAgain;
  143. }
  144. }
  145. System.Threading.Thread.Sleep(5000);
  146. string filename = $"{ReportName.Trim().Replace("~","_")}.xlsx";
  147. string strFilePath = System.IO.Path.Combine(strFileSavePath, filename);
  148. string strFinalPath = System.IO.Path.Combine(strFileSavePath, $"{calMonth.Year}{calMonth.Month}-{filename}");
  149. var Items = GetProjectItem(strFilePath, calMonth, ReportName.Contains("专案开卷报表"));
  150. foreach(var item in Items)
  151. {
  152. var temObj = pfItems.FirstOrDefault<PerformanceItem>(s => s.CaseNo == item.CaseNo);
  153. if(temObj == null)
  154. {
  155. item.Type = "专案";
  156. pfItems.Add(item);
  157. }
  158. }
  159. System.IO.File.Move(strFilePath, strFinalPath);
  160. }
  161. List<BasePointRule> rules = spDb.BasePointRules.ToList<BasePointRule>();
  162. foreach (var item in pfItems)
  163. {
  164. SavePerformanceItem(item, rules);
  165. }
  166. }
  167. private List<PerformanceItem> GetProjectItem(string strPath,CalMonth calMonth,bool isOpenSheet)
  168. {
  169. DataTable dt = NPOIExcel.ExcelToDataTable(strPath, true, true, 1);
  170. #region 删除重复行
  171. DataTable temdt = new DataTable();
  172. foreach (DataColumn col in dt.Columns)
  173. {
  174. DataColumn temCol = new DataColumn();
  175. temCol.ColumnName = col.ColumnName;
  176. temCol.DataType = col.DataType;
  177. temCol.Caption = col.Caption;
  178. temdt.Columns.Add(temCol);
  179. }
  180. new ExcelHelper().MerageDataTable(temdt, dt);
  181. #endregion
  182. List<PerformanceItem> Items = new List<PerformanceItem>();
  183. int iRow = 0;
  184. foreach (DataRow row in temdt.Rows)
  185. {
  186. string strDebug = $"{++iRow}\t{row["我方文号"]}";
  187. PerformanceItem item = null;
  188. if (!isOpenSheet)
  189. {
  190. item = Row2Item_2(row, calMonth);
  191. }
  192. else
  193. {
  194. item = Row2Item_3(row, calMonth);
  195. }
  196. if (item != null)
  197. {
  198. Items.Add(item);
  199. }
  200. }
  201. return Items;
  202. }
  203. private Task InputPerformanceItem(string strExcelFile, bool isColumnName, bool ignorHideRows = false, int ColumnNameRow = 0, CalMonth calMonth = null, bool isFirstOAFile = false)
  204. {
  205. DataTable dt = NPOIExcel.ExcelToDataTable(strExcelFile, isColumnName, ignorHideRows, ColumnNameRow);
  206. #region 删除重复行
  207. DataTable temdt = new DataTable();
  208. foreach (DataColumn col in dt.Columns)
  209. {
  210. DataColumn temCol = new DataColumn();
  211. temCol.ColumnName = col.ColumnName;
  212. temCol.DataType = col.DataType;
  213. temCol.Caption = col.Caption;
  214. temdt.Columns.Add(temCol);
  215. }
  216. new ExcelHelper().MerageDataTable(temdt, dt);
  217. #endregion
  218. List<BasePointRule> rules = spDb.BasePointRules.ToList<BasePointRule>();
  219. int iRow = 0;
  220. foreach (DataRow row in temdt.Rows)
  221. {
  222. string strDebug = $"{++iRow}\t{row["我方文号"]}";
  223. PerformanceItem item = null;
  224. if (isFirstOAFile)
  225. {
  226. item = Row2Item_1(row, calMonth);
  227. }
  228. else
  229. {
  230. item = Row2Item(row, calMonth);
  231. }
  232. if (item != null)
  233. {
  234. if (!InValidDoItem.Contains(item.DoItem))
  235. {
  236. SavePerformanceItem(item,rules);
  237. strDebug = $"{strDebug}\t保存成功";
  238. }
  239. else
  240. {
  241. strDebug = $"{strDebug}\t无效处理事项";
  242. }
  243. }
  244. else
  245. {
  246. strDebug = $"{strDebug}\t转换Item为Null";
  247. }
  248. System.Diagnostics.Debug.WriteLine(strDebug);
  249. }
  250. return Task.CompletedTask;
  251. }
  252. private Task SavePerformanceItem(PerformanceItem item,List<BasePointRule> rules)
  253. {
  254. try
  255. {
  256. Utility.Utility.CalBasePoint(item, rules);
  257. new Controllers.PerformanceItemController(spDb).New(item);
  258. }
  259. catch (Exception ex)
  260. {
  261. System.Diagnostics.Debug.WriteLine(ex.Message);
  262. }
  263. return Task.CompletedTask;
  264. }
  265. private PerformanceItem Row2Item_3(DataRow row, CalMonth calMonth)
  266. {
  267. PerformanceItem item = new PerformanceItem();
  268. item.CaseNo = row["我方文号"].ToString().Trim();
  269. item.CaseName = row["案件名称"].ToString().Trim();
  270. item.CaseType = row["案件类型"].ToString().Trim();
  271. item.BusinessType = row["业务类型"].ToString().Trim();
  272. item.Customer = new Customer();
  273. item.Customer.Name = row["客户名称"].ToString().Trim();
  274. item.CaseState = row["案件状态"].ToString().Trim();
  275. DateTime temDate = new DateTime();
  276. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  277. {
  278. item.EntrustingDate = temDate;
  279. }
  280. string strHandler = "";
  281. if (row.Table.Columns.Contains("处理人"))
  282. {
  283. strHandler = row["处理人"].ToString().Trim();
  284. }
  285. else
  286. {
  287. if (row.Table.Columns.Contains("案件处理人"))
  288. {
  289. strHandler = row["案件处理人"].ToString().Trim();
  290. }
  291. }
  292. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  293. item.ItemStaffs = new List<ItemStaff>();
  294. foreach (string name in temHandlers)
  295. {
  296. ItemStaff itemStaff = new ItemStaff();
  297. int? iTem = GetStaff(name);
  298. if ((iTem != null))
  299. {
  300. //itemStaff.Item = item;
  301. itemStaff.DoPersonId = iTem.Value;
  302. item.ItemStaffs.Add(itemStaff);
  303. }
  304. else
  305. {
  306. itemStaff.DoPerson = new Staff()
  307. {
  308. Name = name,
  309. Account = name,
  310. Password = "12345678",
  311. IsCalPerformsnce = false,
  312. Status = "正式员工",
  313. StaffGradeId = 4
  314. };
  315. item.ItemStaffs.Add(itemStaff);
  316. }
  317. }
  318. if (item.ItemStaffs.Count == 0)
  319. {
  320. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  321. }
  322. if (row.Table.Columns.Contains("核稿人"))
  323. {
  324. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  325. }
  326. else
  327. {
  328. if (row.Table.Columns.Contains("案件核稿人"))
  329. {
  330. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  331. }
  332. }
  333. return item;
  334. }
  335. private PerformanceItem Row2Item_2(DataRow row, CalMonth calMonth)
  336. {
  337. PerformanceItem item = new PerformanceItem();
  338. item.CaseNo = row["我方文号"].ToString().Trim();
  339. item.CaseName= row["案件名称"].ToString().Trim();
  340. item.CaseType = row["案件类型"].ToString().Trim();
  341. item.BusinessType= row["业务类型"].ToString().Trim();
  342. item.Customer = new Customer();
  343. item.Customer.Name = row["客户名称"].ToString().Trim();
  344. item.CaseState = row["案件状态"].ToString().Trim();
  345. item.DoItem = row["处理事项"].ToString().Trim();
  346. DateTime temDate = new DateTime();
  347. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  348. {
  349. item.InternalDate = temDate;
  350. }
  351. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  352. {
  353. item.CustomerLimitDate = temDate;
  354. }
  355. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  356. {
  357. item.FirstDraftDate = temDate;
  358. }
  359. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  360. {
  361. item.FinalizationDate = temDate;
  362. }
  363. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  364. {
  365. item.EntrustingDate = temDate;
  366. }
  367. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  368. {
  369. item.FinishedDate = temDate;
  370. }
  371. item.DoItemState = row["处理状态"].ToString().Trim();
  372. string strHandler = "";
  373. if (row.Table.Columns.Contains("处理人"))
  374. {
  375. strHandler = row["处理人"].ToString().Trim();
  376. }
  377. else
  378. {
  379. if (row.Table.Columns.Contains("案件处理人"))
  380. {
  381. strHandler = row["案件处理人"].ToString().Trim();
  382. }
  383. }
  384. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  385. item.ItemStaffs = new List<ItemStaff>();
  386. foreach (string name in temHandlers)
  387. {
  388. ItemStaff itemStaff = new ItemStaff();
  389. int? iTem = GetStaff(name);
  390. if ((iTem != null))
  391. {
  392. //itemStaff.Item = item;
  393. itemStaff.DoPersonId = iTem.Value;
  394. item.ItemStaffs.Add(itemStaff);
  395. }
  396. else
  397. {
  398. itemStaff.DoPerson = new Staff()
  399. {
  400. Name = name,
  401. Account = name,
  402. Password = "12345678",
  403. IsCalPerformsnce = false,
  404. Status = "正式员工",
  405. StaffGradeId = 4
  406. };
  407. item.ItemStaffs.Add(itemStaff);
  408. }
  409. }
  410. if (item.ItemStaffs.Count == 0)
  411. {
  412. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  413. }
  414. if (row.Table.Columns.Contains("核稿人"))
  415. {
  416. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  417. }
  418. else
  419. {
  420. if (row.Table.Columns.Contains("案件核稿人"))
  421. {
  422. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  423. }
  424. }
  425. return item;
  426. }
  427. private PerformanceItem Row2Item_1(DataRow row, CalMonth calMonth)
  428. {
  429. PerformanceItem item = new PerformanceItem();
  430. item.ApplicationType = row["申请类型"].ToString().Trim();
  431. if (item.ApplicationType != "发明")
  432. {
  433. return null;
  434. }
  435. if (item.CaseNo.StartsWith("S"))
  436. {
  437. return null;
  438. }
  439. item.CaseNo = row["我方文号"].ToString().Trim();
  440. if (calMonth != null)
  441. {
  442. item.CalMonth = calMonth;
  443. }
  444. else
  445. {
  446. if (row.Table.Columns.Contains("绩效核算月份"))
  447. {
  448. string strjxyf = row["绩效核算月份"].ToString().Trim();
  449. string[] temYFs = strjxyf.Split(new char[] { '.' });
  450. item.CalMonth = new CalMonth();
  451. item.CalMonth.Year = int.Parse(temYFs[0]);
  452. item.CalMonth.Month = int.Parse(temYFs[1]);
  453. item.CalMonth.Status = 4;
  454. }
  455. else
  456. {
  457. item.CalMonth = new CalMonth();
  458. item.Status = 0;
  459. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  460. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  461. }
  462. }
  463. item.ApplicationType = row["申请类型"].ToString().Trim();
  464. item.BusinessType = "普通新申请"; // row["业务类型"].ToString().Trim();
  465. item.AgentFeedbackMemo = "发明一次OA授权"; //row["备注(填表注意事项)"].ToString().Trim();
  466. item.DoItem = "发明一次OA授权"; //row["处理事项"].ToString().Trim();
  467. string strHandler = "";
  468. if (row.Table.Columns.Contains("处理人"))
  469. {
  470. strHandler = row["处理人"].ToString().Trim();
  471. }
  472. else
  473. {
  474. if (row.Table.Columns.Contains("案件处理人"))
  475. {
  476. strHandler = row["案件处理人"].ToString().Trim();
  477. }
  478. }
  479. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  480. item.ItemStaffs = new List<ItemStaff>();
  481. foreach (string name in temHandlers)
  482. {
  483. ItemStaff itemStaff = new ItemStaff();
  484. int? iTem = GetStaff(name);
  485. if ((iTem != null))
  486. {
  487. //itemStaff.Item = item;
  488. itemStaff.DoPersonId = iTem.Value;
  489. item.ItemStaffs.Add(itemStaff);
  490. }
  491. else
  492. {
  493. itemStaff.DoPerson = new Staff()
  494. {
  495. Name = name,
  496. Account = name,
  497. Password = "12345678",
  498. IsCalPerformsnce = false,
  499. Status = "正式员工",
  500. StaffGradeId = 4
  501. };
  502. item.ItemStaffs.Add(itemStaff);
  503. }
  504. }
  505. if (item.ItemStaffs.Count == 0)
  506. {
  507. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  508. }
  509. if (row.Table.Columns.Contains("核稿人"))
  510. {
  511. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  512. }
  513. else
  514. {
  515. if (row.Table.Columns.Contains("案件核稿人"))
  516. {
  517. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  518. }
  519. }
  520. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  521. item.ApplicationName = row["申请人"].ToString().Trim();
  522. item.CaseName = row["案件名称"].ToString().Trim();
  523. //案件备注
  524. item.CaseMemo = $"发文日期:{row["发文日期"].ToString().Trim()}\r\n客户文号:{row["客户文号"].ToString().Trim()}\r\n上传日期:{row["上传日期"].ToString().Trim()}\r\n文件描述:{row["文件描述"].ToString().Trim()}";
  525. return item;
  526. }
  527. private PerformanceItem Row2Item(DataRow row, CalMonth calMonth)
  528. {
  529. PerformanceItem item = new PerformanceItem();
  530. item.CaseNo = row["我方文号"].ToString().Trim();
  531. if (item.CaseNo.StartsWith("S"))
  532. {
  533. return null;
  534. }
  535. if (calMonth != null)
  536. {
  537. item.CalMonth = calMonth;
  538. }
  539. else
  540. {
  541. if (row.Table.Columns.Contains("绩效核算月份"))
  542. {
  543. string strjxyf = row["绩效核算月份"].ToString().Trim();
  544. string[] temYFs = strjxyf.Split(new char[] { '.' });
  545. item.CalMonth = new CalMonth();
  546. item.CalMonth.Year = int.Parse(temYFs[0]);
  547. item.CalMonth.Month = int.Parse(temYFs[1]);
  548. item.CalMonth.Status = 4;
  549. }
  550. else
  551. {
  552. item.CalMonth = new CalMonth();
  553. item.Status = 0;
  554. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  555. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  556. }
  557. }
  558. item.ApplicationType = row["申请类型"].ToString().Trim();
  559. item.BusinessType = row["业务类型"].ToString().Trim();
  560. if (row.Table.Columns.Contains("备注(填表注意事项)"))
  561. item.AgentFeedbackMemo = row["备注(填表注意事项)"].ToString().Trim();
  562. item.DoItem = row["处理事项"].ToString().Trim();
  563. item.CaseStage = row["案件阶段"].ToString().Trim();
  564. item.CaseCoefficient = row["案件系数"].ToString().Trim();
  565. item.DoItemCoefficient = row["处理事项系数"].ToString().Trim();
  566. item.PreOastaffId = GetStaff(row["前一次OA处理人"].ToString().Trim());
  567. string strHandler = "";
  568. if (row.Table.Columns.Contains("处理人"))
  569. {
  570. strHandler = row["处理人"].ToString().Trim();
  571. }
  572. else
  573. {
  574. if (row.Table.Columns.Contains("案件处理人"))
  575. {
  576. strHandler = row["案件处理人"].ToString().Trim();
  577. }
  578. }
  579. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  580. item.ItemStaffs = new List<ItemStaff>();
  581. foreach (string name in temHandlers)
  582. {
  583. ItemStaff itemStaff = new ItemStaff();
  584. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  585. int? iTem = GetStaff(temName);
  586. if ((iTem != null))
  587. {
  588. //itemStaff.Item = item;
  589. itemStaff.DoPersonId = iTem.Value;
  590. item.ItemStaffs.Add(itemStaff);
  591. }
  592. else
  593. {
  594. itemStaff.DoPerson = new Staff()
  595. {
  596. Name = temName,
  597. Account = temName,
  598. Password = "12345678",
  599. IsCalPerformsnce = false,
  600. Status = "已离职",
  601. StaffGradeId = 4
  602. };
  603. item.ItemStaffs.Add(itemStaff);
  604. }
  605. }
  606. if (item.ItemStaffs.Count == 0)
  607. {
  608. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  609. }
  610. if (row.Table.Columns.Contains("核稿人"))
  611. {
  612. if (!string.IsNullOrEmpty(row["核稿人"].ToString().Trim()))
  613. {
  614. string temName = row["核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  615. item.ReviewerId = GetStaff(temName);
  616. }
  617. }
  618. else
  619. {
  620. if (row.Table.Columns.Contains("案件核稿人"))
  621. {
  622. if (!string.IsNullOrEmpty(row["案件核稿人"].ToString().Trim()))
  623. {
  624. string temName = row["案件核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  625. item.ReviewerId = GetStaff(temName);
  626. }
  627. }
  628. }
  629. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  630. item.ApplicationName = row["申请人"].ToString().Trim();
  631. DateTime temDate = new DateTime();
  632. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  633. {
  634. item.FinishedDate = temDate;
  635. }
  636. //定稿日
  637. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  638. {
  639. item.FinalizationDate = temDate;
  640. }
  641. //返稿日
  642. if (DateTime.TryParse(row["返稿日"].ToString().Trim(), out temDate))
  643. {
  644. item.ReturnDate = temDate;
  645. }
  646. //案件类型
  647. item.CaseType = row["案件类型"].ToString().Trim();
  648. //案件状态
  649. item.CaseState = row["案件状态"].ToString().Trim();
  650. //处理事项备注
  651. item.DoItemMemo = row["处理事项备注"].ToString().Trim();
  652. //处理状态
  653. item.DoItemState = row["处理状态"].ToString().Trim();
  654. //案件名称
  655. item.CaseName = row["案件名称"].ToString().Trim();
  656. //委案日期
  657. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  658. {
  659. item.EntrustingDate = temDate;
  660. }
  661. //客户期限
  662. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  663. {
  664. item.CustomerLimitDate = temDate;
  665. }
  666. //内部期限
  667. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  668. {
  669. item.InternalDate = temDate;
  670. }
  671. //初稿日
  672. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  673. {
  674. item.FirstDraftDate = temDate;
  675. }
  676. //备注(发文严重超期是否属客观原因,若为否,请填写原因)
  677. if (row.Table.Columns.Contains("备注(发文严重超期是否属客观原因,若为否,请填写原因)"))
  678. {
  679. item.OverDueMemo = row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"].ToString().Trim();
  680. }
  681. //案件备注
  682. item.CaseMemo = row["案件备注"].ToString().Trim();
  683. return item;
  684. }
  685. private int? GetStaff(string v)
  686. {
  687. var staff = spDb.Staffs.Where<Staff>(s => s.Name == v).FirstOrDefault();
  688. if(staff != null)
  689. {
  690. return staff.Id;
  691. }
  692. return null;
  693. }
  694. }
  695. }