ImportReportJob.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  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. item.CalMonth = calMonth;
  199. item.CalMonthId = calMonth.Id;
  200. Items.Add(item);
  201. }
  202. }
  203. return Items;
  204. }
  205. private Task InputPerformanceItem(string strExcelFile, bool isColumnName, bool ignorHideRows = false, int ColumnNameRow = 0, CalMonth calMonth = null, bool isFirstOAFile = false)
  206. {
  207. DataTable dt = NPOIExcel.ExcelToDataTable(strExcelFile, isColumnName, ignorHideRows, ColumnNameRow);
  208. #region 删除重复行
  209. DataTable temdt = new DataTable();
  210. foreach (DataColumn col in dt.Columns)
  211. {
  212. DataColumn temCol = new DataColumn();
  213. temCol.ColumnName = col.ColumnName;
  214. temCol.DataType = col.DataType;
  215. temCol.Caption = col.Caption;
  216. temdt.Columns.Add(temCol);
  217. }
  218. new ExcelHelper().MerageDataTable(temdt, dt);
  219. #endregion
  220. List<BasePointRule> rules = spDb.BasePointRules.ToList<BasePointRule>();
  221. int iRow = 0;
  222. foreach (DataRow row in temdt.Rows)
  223. {
  224. string strDebug = $"{++iRow}\t{row["我方文号"]}";
  225. PerformanceItem item = null;
  226. if (isFirstOAFile)
  227. {
  228. item = Row2Item_1(row, calMonth);
  229. }
  230. else
  231. {
  232. item = Row2Item(row, calMonth);
  233. }
  234. if (item != null)
  235. {
  236. if (!InValidDoItem.Contains(item.DoItem))
  237. {
  238. SavePerformanceItem(item,rules);
  239. strDebug = $"{strDebug}\t保存成功";
  240. }
  241. else
  242. {
  243. strDebug = $"{strDebug}\t无效处理事项";
  244. }
  245. }
  246. else
  247. {
  248. strDebug = $"{strDebug}\t转换Item为Null";
  249. }
  250. System.Diagnostics.Debug.WriteLine(strDebug);
  251. }
  252. return Task.CompletedTask;
  253. }
  254. private Task SavePerformanceItem(PerformanceItem item,List<BasePointRule> rules)
  255. {
  256. try
  257. {
  258. Utility.Utility.CalBasePoint(item, rules);
  259. var ret= new Controllers.PerformanceItemController(spDb).New(item);
  260. if (ret.Success == false)
  261. {
  262. System.Diagnostics.Debug.WriteLine(ret.ErrorMessage);
  263. }
  264. }
  265. catch (Exception ex)
  266. {
  267. System.Diagnostics.Debug.WriteLine(ex.Message);
  268. }
  269. return Task.CompletedTask;
  270. }
  271. private PerformanceItem Row2Item_3(DataRow row, CalMonth calMonth)
  272. {
  273. PerformanceItem item = new PerformanceItem();
  274. item.CaseNo = row["我方文号"].ToString().Trim();
  275. item.CaseName = row["案件名称"].ToString().Trim();
  276. item.CaseType = row["案件类型"].ToString().Trim();
  277. item.BusinessType = row["业务类型"].ToString().Trim();
  278. item.Customer = new Customer();
  279. item.Customer.Name = row["客户名称"].ToString().Trim();
  280. item.CaseState = row["案件状态"].ToString().Trim();
  281. DateTime temDate = new DateTime();
  282. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  283. {
  284. item.EntrustingDate = temDate;
  285. }
  286. string strHandler = "";
  287. if (row.Table.Columns.Contains("处理人"))
  288. {
  289. strHandler = row["处理人"].ToString().Trim();
  290. }
  291. else
  292. {
  293. if (row.Table.Columns.Contains("案件处理人"))
  294. {
  295. strHandler = row["案件处理人"].ToString().Trim();
  296. }
  297. }
  298. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  299. item.ItemStaffs = new List<ItemStaff>();
  300. foreach (string name in temHandlers)
  301. {
  302. ItemStaff itemStaff = new ItemStaff();
  303. int? iTem = GetStaff(name);
  304. if ((iTem != null))
  305. {
  306. //itemStaff.Item = item;
  307. itemStaff.DoPersonId = iTem.Value;
  308. item.ItemStaffs.Add(itemStaff);
  309. }
  310. else
  311. {
  312. itemStaff.DoPerson = new Staff()
  313. {
  314. Name = name,
  315. Account = name,
  316. Password = "12345678",
  317. IsCalPerformsnce = false,
  318. Status = "正式员工",
  319. StaffGradeId = 4
  320. };
  321. item.ItemStaffs.Add(itemStaff);
  322. }
  323. }
  324. if (item.ItemStaffs.Count == 0)
  325. {
  326. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  327. }
  328. if (row.Table.Columns.Contains("核稿人"))
  329. {
  330. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  331. }
  332. else
  333. {
  334. if (row.Table.Columns.Contains("案件核稿人"))
  335. {
  336. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  337. }
  338. }
  339. return item;
  340. }
  341. private PerformanceItem Row2Item_2(DataRow row, CalMonth calMonth)
  342. {
  343. PerformanceItem item = new PerformanceItem();
  344. item.CaseNo = row["我方文号"].ToString().Trim();
  345. item.CaseName= row["案件名称"].ToString().Trim();
  346. item.CaseType = row["案件类型"].ToString().Trim();
  347. item.BusinessType= row["业务类型"].ToString().Trim();
  348. item.Customer = new Customer();
  349. item.Customer.Name = row["客户名称"].ToString().Trim();
  350. item.CaseState = row["案件状态"].ToString().Trim();
  351. item.DoItem = row["处理事项"].ToString().Trim();
  352. DateTime temDate = new DateTime();
  353. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  354. {
  355. item.InternalDate = temDate;
  356. }
  357. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  358. {
  359. item.CustomerLimitDate = temDate;
  360. }
  361. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  362. {
  363. item.FirstDraftDate = temDate;
  364. }
  365. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  366. {
  367. item.FinalizationDate = temDate;
  368. }
  369. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  370. {
  371. item.EntrustingDate = temDate;
  372. }
  373. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  374. {
  375. item.FinishedDate = temDate;
  376. }
  377. item.DoItemState = row["处理状态"].ToString().Trim();
  378. string strHandler = "";
  379. if (row.Table.Columns.Contains("处理人"))
  380. {
  381. strHandler = row["处理人"].ToString().Trim();
  382. }
  383. else
  384. {
  385. if (row.Table.Columns.Contains("案件处理人"))
  386. {
  387. strHandler = row["案件处理人"].ToString().Trim();
  388. }
  389. }
  390. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  391. item.ItemStaffs = new List<ItemStaff>();
  392. foreach (string name in temHandlers)
  393. {
  394. ItemStaff itemStaff = new ItemStaff();
  395. int? iTem = GetStaff(name);
  396. if ((iTem != null))
  397. {
  398. //itemStaff.Item = item;
  399. itemStaff.DoPersonId = iTem.Value;
  400. item.ItemStaffs.Add(itemStaff);
  401. }
  402. else
  403. {
  404. itemStaff.DoPerson = new Staff()
  405. {
  406. Name = name,
  407. Account = name,
  408. Password = "12345678",
  409. IsCalPerformsnce = false,
  410. Status = "正式员工",
  411. StaffGradeId = 4
  412. };
  413. item.ItemStaffs.Add(itemStaff);
  414. }
  415. }
  416. if (item.ItemStaffs.Count == 0)
  417. {
  418. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  419. }
  420. if (row.Table.Columns.Contains("核稿人"))
  421. {
  422. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  423. }
  424. else
  425. {
  426. if (row.Table.Columns.Contains("案件核稿人"))
  427. {
  428. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  429. }
  430. }
  431. return item;
  432. }
  433. private PerformanceItem Row2Item_1(DataRow row, CalMonth calMonth)
  434. {
  435. PerformanceItem item = new PerformanceItem();
  436. item.ApplicationType = row["申请类型"].ToString().Trim();
  437. if (item.ApplicationType != "发明")
  438. {
  439. return null;
  440. }
  441. item.CaseNo = row["我方文号"].ToString().Trim();
  442. if (item.CaseNo.StartsWith("S"))
  443. {
  444. return null;
  445. }
  446. if (calMonth != null)
  447. {
  448. item.CalMonth = calMonth;
  449. }
  450. else
  451. {
  452. if (row.Table.Columns.Contains("绩效核算月份"))
  453. {
  454. string strjxyf = row["绩效核算月份"].ToString().Trim();
  455. string[] temYFs = strjxyf.Split(new char[] { '.' });
  456. item.CalMonth = new CalMonth();
  457. item.CalMonth.Year = int.Parse(temYFs[0]);
  458. item.CalMonth.Month = int.Parse(temYFs[1]);
  459. item.CalMonth.Status = 4;
  460. }
  461. else
  462. {
  463. item.CalMonth = new CalMonth();
  464. item.Status = 0;
  465. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  466. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  467. }
  468. }
  469. item.ApplicationType = row["申请类型"].ToString().Trim();
  470. item.BusinessType = "普通新申请"; // row["业务类型"].ToString().Trim();
  471. item.AgentFeedbackMemo = "发明一次OA授权"; //row["备注(填表注意事项)"].ToString().Trim();
  472. item.DoItem = "发明一次OA授权"; //row["处理事项"].ToString().Trim();
  473. string strHandler = "";
  474. if (row.Table.Columns.Contains("处理人"))
  475. {
  476. strHandler = row["处理人"].ToString().Trim();
  477. }
  478. else
  479. {
  480. if (row.Table.Columns.Contains("案件处理人"))
  481. {
  482. strHandler = row["案件处理人"].ToString().Trim();
  483. }
  484. }
  485. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  486. item.ItemStaffs = new List<ItemStaff>();
  487. foreach (string name in temHandlers)
  488. {
  489. ItemStaff itemStaff = new ItemStaff();
  490. int? iTem = GetStaff(name);
  491. if ((iTem != null))
  492. {
  493. //itemStaff.Item = item;
  494. itemStaff.DoPersonId = iTem.Value;
  495. item.ItemStaffs.Add(itemStaff);
  496. }
  497. else
  498. {
  499. itemStaff.DoPerson = new Staff()
  500. {
  501. Name = name,
  502. Account = name,
  503. Password = "12345678",
  504. IsCalPerformsnce = false,
  505. Status = "正式员工",
  506. StaffGradeId = 4
  507. };
  508. item.ItemStaffs.Add(itemStaff);
  509. }
  510. }
  511. if (item.ItemStaffs.Count == 0)
  512. {
  513. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  514. }
  515. if (row.Table.Columns.Contains("核稿人"))
  516. {
  517. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  518. }
  519. else
  520. {
  521. if (row.Table.Columns.Contains("案件核稿人"))
  522. {
  523. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  524. }
  525. }
  526. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  527. item.ApplicationName = row["申请人"].ToString().Trim();
  528. item.CaseName = row["案件名称"].ToString().Trim();
  529. //案件备注
  530. item.CaseMemo = $"发文日期:{row["发文日期"].ToString().Trim()}\r\n客户文号:{row["客户文号"].ToString().Trim()}\r\n上传日期:{row["上传日期"].ToString().Trim()}\r\n文件描述:{row["文件描述"].ToString().Trim()}";
  531. return item;
  532. }
  533. private PerformanceItem Row2Item(DataRow row, CalMonth calMonth)
  534. {
  535. PerformanceItem item = new PerformanceItem();
  536. item.CaseNo = row["我方文号"].ToString().Trim();
  537. if (item.CaseNo.StartsWith("S"))
  538. {
  539. return null;
  540. }
  541. if (calMonth != null)
  542. {
  543. item.CalMonth = calMonth;
  544. }
  545. else
  546. {
  547. if (row.Table.Columns.Contains("绩效核算月份"))
  548. {
  549. string strjxyf = row["绩效核算月份"].ToString().Trim();
  550. string[] temYFs = strjxyf.Split(new char[] { '.' });
  551. item.CalMonth = new CalMonth();
  552. item.CalMonth.Year = int.Parse(temYFs[0]);
  553. item.CalMonth.Month = int.Parse(temYFs[1]);
  554. item.CalMonth.Status = 4;
  555. }
  556. else
  557. {
  558. item.CalMonth = new CalMonth();
  559. item.Status = 0;
  560. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  561. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  562. }
  563. }
  564. item.ApplicationType = row["申请类型"].ToString().Trim();
  565. item.BusinessType = row["业务类型"].ToString().Trim();
  566. if (row.Table.Columns.Contains("备注(填表注意事项)"))
  567. item.AgentFeedbackMemo = row["备注(填表注意事项)"].ToString().Trim();
  568. item.DoItem = row["处理事项"].ToString().Trim();
  569. item.CaseStage = row["案件阶段"].ToString().Trim();
  570. item.CaseCoefficient = row["案件系数"].ToString().Trim();
  571. item.DoItemCoefficient = row["处理事项系数"].ToString().Trim();
  572. item.PreOastaffId = GetStaff(row["前一次OA处理人"].ToString().Trim());
  573. string strHandler = "";
  574. if (row.Table.Columns.Contains("处理人"))
  575. {
  576. strHandler = row["处理人"].ToString().Trim();
  577. }
  578. else
  579. {
  580. if (row.Table.Columns.Contains("案件处理人"))
  581. {
  582. strHandler = row["案件处理人"].ToString().Trim();
  583. }
  584. }
  585. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  586. item.ItemStaffs = new List<ItemStaff>();
  587. foreach (string name in temHandlers)
  588. {
  589. ItemStaff itemStaff = new ItemStaff();
  590. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  591. int? iTem = GetStaff(temName);
  592. if ((iTem != null))
  593. {
  594. //itemStaff.Item = item;
  595. itemStaff.DoPersonId = iTem.Value;
  596. item.ItemStaffs.Add(itemStaff);
  597. }
  598. else
  599. {
  600. itemStaff.DoPerson = new Staff()
  601. {
  602. Name = temName,
  603. Account = temName,
  604. Password = "12345678",
  605. IsCalPerformsnce = false,
  606. Status = "已离职",
  607. StaffGradeId = 4
  608. };
  609. item.ItemStaffs.Add(itemStaff);
  610. }
  611. }
  612. if (item.ItemStaffs.Count == 0)
  613. {
  614. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  615. }
  616. if (row.Table.Columns.Contains("核稿人"))
  617. {
  618. if (!string.IsNullOrEmpty(row["核稿人"].ToString().Trim()))
  619. {
  620. string temName = row["核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  621. item.ReviewerId = GetStaff(temName);
  622. }
  623. }
  624. else
  625. {
  626. if (row.Table.Columns.Contains("案件核稿人"))
  627. {
  628. if (!string.IsNullOrEmpty(row["案件核稿人"].ToString().Trim()))
  629. {
  630. string temName = row["案件核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  631. item.ReviewerId = GetStaff(temName);
  632. }
  633. }
  634. }
  635. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  636. item.ApplicationName = row["申请人"].ToString().Trim();
  637. DateTime temDate = new DateTime();
  638. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  639. {
  640. item.FinishedDate = temDate;
  641. }
  642. //定稿日
  643. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  644. {
  645. item.FinalizationDate = temDate;
  646. }
  647. //返稿日
  648. if (DateTime.TryParse(row["返稿日"].ToString().Trim(), out temDate))
  649. {
  650. item.ReturnDate = temDate;
  651. }
  652. //案件类型
  653. item.CaseType = row["案件类型"].ToString().Trim();
  654. //案件状态
  655. item.CaseState = row["案件状态"].ToString().Trim();
  656. //处理事项备注
  657. item.DoItemMemo = row["处理事项备注"].ToString().Trim();
  658. //处理状态
  659. item.DoItemState = row["处理状态"].ToString().Trim();
  660. //案件名称
  661. item.CaseName = row["案件名称"].ToString().Trim();
  662. //委案日期
  663. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  664. {
  665. item.EntrustingDate = temDate;
  666. }
  667. //客户期限
  668. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  669. {
  670. item.CustomerLimitDate = temDate;
  671. }
  672. //内部期限
  673. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  674. {
  675. item.InternalDate = temDate;
  676. }
  677. //初稿日
  678. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  679. {
  680. item.FirstDraftDate = temDate;
  681. }
  682. //备注(发文严重超期是否属客观原因,若为否,请填写原因)
  683. if (row.Table.Columns.Contains("备注(发文严重超期是否属客观原因,若为否,请填写原因)"))
  684. {
  685. item.OverDueMemo = row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"].ToString().Trim();
  686. }
  687. //案件备注
  688. item.CaseMemo = row["案件备注"].ToString().Trim();
  689. return item;
  690. }
  691. private int? GetStaff(string v)
  692. {
  693. var staff = spDb.Staffs.Where<Staff>(s => s.Name == v).FirstOrDefault();
  694. if(staff != null)
  695. {
  696. return staff.Id;
  697. }
  698. return null;
  699. }
  700. }
  701. }