ImportReportJob.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  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. return Task.CompletedTask;
  92. }
  93. private void DownloadReport(string ReportName,CalMonth calMonth,bool isModifyDate,bool isFirstOA=false)
  94. {
  95. string strFileSavePath = utility.ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  96. string filename = $"{ReportName.Trim()}.xlsx";
  97. string strFilePath = System.IO.Path.Combine(strFileSavePath, filename);
  98. string strFinalPath = System.IO.Path.Combine(strFileSavePath, $"{calMonth.Year}{calMonth.Month}-{filename}");
  99. int tryCount = 0;
  100. tryAgain:
  101. try
  102. {
  103. wispro.sp.utility.IPEasyUtility.DownloadReport(ReportName, isModifyDate);
  104. if (!System.IO.File.Exists(strFilePath))
  105. {
  106. throw new ApplicationException("超时!");
  107. }
  108. }
  109. catch {
  110. tryCount++;
  111. if (tryCount < 5)
  112. {
  113. goto tryAgain;
  114. }
  115. }
  116. System.Threading.Thread.Sleep(5000);
  117. InputPerformanceItem(strFilePath, true, false, 1, calMonth, isFirstOA);
  118. System.IO.File.Move(strFilePath, strFinalPath);
  119. }
  120. private void DownloadProject(CalMonth calMonth)
  121. {
  122. string strFileSavePath = utility.ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  123. int tryCount = 0;
  124. string[] ReportNames =new string[] { "每月绩效统计--专案进度跟踪~S卷", "每月绩效统计--专案开卷报表~S卷" };
  125. List<PerformanceItem> pfItems = new List<PerformanceItem>();
  126. foreach (var ReportName in ReportNames)
  127. {
  128. tryAgain:
  129. try
  130. {
  131. wispro.sp.utility.IPEasyUtility.DownloadReport(ReportName, false);
  132. }
  133. catch
  134. {
  135. tryCount++;
  136. if (tryCount < 5)
  137. {
  138. goto tryAgain;
  139. }
  140. }
  141. System.Threading.Thread.Sleep(5000);
  142. string filename = $"{ReportName.Trim().Replace("~","_")}.xlsx";
  143. string strFilePath = System.IO.Path.Combine(strFileSavePath, filename);
  144. string strFinalPath = System.IO.Path.Combine(strFileSavePath, $"{calMonth.Year}{calMonth.Month}-{filename}");
  145. var Items = GetProjectItem(strFilePath, calMonth, ReportName.Contains("专案开卷报表"));
  146. foreach(var item in Items)
  147. {
  148. var temObj = pfItems.FirstOrDefault<PerformanceItem>(s => s.CaseNo == item.CaseNo);
  149. if(temObj == null)
  150. {
  151. item.Type = "专案";
  152. pfItems.Add(item);
  153. }
  154. }
  155. System.IO.File.Move(strFilePath, strFinalPath);
  156. }
  157. //List<BasePointRule> rules = spDb.BasePointRules.ToList<BasePointRule>();
  158. foreach (var item in pfItems)
  159. {
  160. SaveProjectItem(item);
  161. }
  162. }
  163. private void SaveProjectItem(PerformanceItem item)
  164. {
  165. var temObj = spDb.ProjectInfos.FirstOrDefault(p=>p.CaseNo == item.CaseNo);
  166. if (temObj == null)
  167. {
  168. ProjectInfo project = new ProjectInfo();
  169. project.CaseNo = item.CaseNo;
  170. project.CaseName = item.CaseName;
  171. project.BusinessType = item.BusinessType;
  172. if(item.Customer != null)
  173. {
  174. var temCustomer = spDb.Customers.FirstOrDefault(c => c.Name == item.Customer.Name);
  175. if(temCustomer != null)
  176. {
  177. project.CustomerId = temCustomer.Id;
  178. }
  179. }
  180. project.CaseState = 0;
  181. project.CaseType = item.CaseType;
  182. project.ReviewerId = item.ReviewerId;
  183. project.WorkflowUserId = item.WorkflowUserId;
  184. spDb.ProjectInfos.Add(project);
  185. }
  186. spDb.SaveChanges();
  187. }
  188. private List<PerformanceItem> GetProjectItem(string strPath,CalMonth calMonth,bool isOpenSheet)
  189. {
  190. DataTable dt = NPOIExcel.ExcelToDataTable(strPath, true, true, 1);
  191. #region 删除重复行
  192. DataTable temdt = new DataTable();
  193. foreach (DataColumn col in dt.Columns)
  194. {
  195. DataColumn temCol = new DataColumn();
  196. temCol.ColumnName = col.ColumnName;
  197. temCol.DataType = col.DataType;
  198. temCol.Caption = col.Caption;
  199. temdt.Columns.Add(temCol);
  200. }
  201. new ExcelHelper().MerageDataTable(temdt, dt);
  202. #endregion
  203. List<PerformanceItem> Items = new List<PerformanceItem>();
  204. int iRow = 0;
  205. foreach (DataRow row in temdt.Rows)
  206. {
  207. string strDebug = $"{++iRow}\t{row["我方文号"]}";
  208. PerformanceItem item = null;
  209. if (!isOpenSheet)
  210. {
  211. item = Row2Item_2(row, calMonth);
  212. }
  213. else
  214. {
  215. item = Row2Item_3(row, calMonth);
  216. }
  217. if (item != null)
  218. {
  219. item.CalMonth = calMonth;
  220. item.CalMonthId = calMonth.Id;
  221. Items.Add(item);
  222. }
  223. }
  224. return Items;
  225. }
  226. private Task InputPerformanceItem(string strExcelFile, bool isColumnName, bool ignorHideRows = false, int ColumnNameRow = 0, CalMonth calMonth = null, bool isFirstOAFile = false)
  227. {
  228. DataTable dt = NPOIExcel.ExcelToDataTable(strExcelFile, isColumnName, ignorHideRows, ColumnNameRow);
  229. #region 删除重复行
  230. DataTable temdt = new DataTable();
  231. foreach (DataColumn col in dt.Columns)
  232. {
  233. DataColumn temCol = new DataColumn();
  234. temCol.ColumnName = col.ColumnName;
  235. temCol.DataType = col.DataType;
  236. temCol.Caption = col.Caption;
  237. temdt.Columns.Add(temCol);
  238. }
  239. new ExcelHelper().MerageDataTable(temdt, dt);
  240. #endregion
  241. List<BasePointRule> rules = spDb.BasePointRules.ToList<BasePointRule>();
  242. int iRow = 0;
  243. foreach (DataRow row in temdt.Rows)
  244. {
  245. string strDebug = $"{++iRow}\t{row["我方文号"]}";
  246. PerformanceItem item = null;
  247. if (isFirstOAFile)
  248. {
  249. item = Row2Item_1(row, calMonth);
  250. }
  251. else
  252. {
  253. item = Row2Item(row, calMonth);
  254. }
  255. if (item != null)
  256. {
  257. if (!InValidDoItem.Contains(item.DoItem))
  258. {
  259. //foreach(var temObj in item.ItemStaffs)
  260. //{
  261. // temObj.DoPerson.Name = temObj.DoPerson.Name.Replace("-君龙", "");
  262. //}
  263. SavePerformanceItem(item, rules);
  264. strDebug = $"{strDebug}\t保存成功";
  265. }
  266. else
  267. {
  268. strDebug = $"{strDebug}\t无效处理事项";
  269. }
  270. }
  271. else
  272. {
  273. strDebug = $"{strDebug}\t转换Item为Null";
  274. }
  275. System.Diagnostics.Debug.WriteLine(strDebug);
  276. }
  277. return Task.CompletedTask;
  278. }
  279. private Task SavePerformanceItem(PerformanceItem item,List<BasePointRule> rules)
  280. {
  281. try
  282. {
  283. Utility.Utility.CalBasePoint(item, rules);
  284. var ret= new Controllers.PerformanceItemController(spDb,new Services.FileTaskCacheService()).New(item);
  285. if (ret.Success == false)
  286. {
  287. System.Diagnostics.Debug.WriteLine(ret.ErrorMessage);
  288. }
  289. }
  290. catch (Exception ex)
  291. {
  292. System.Diagnostics.Debug.WriteLine(ex.Message);
  293. }
  294. return Task.CompletedTask;
  295. }
  296. private PerformanceItem Row2Item_3(DataRow row, CalMonth calMonth)
  297. {
  298. PerformanceItem item = new PerformanceItem();
  299. item.CaseNo = row["我方文号"].ToString().Trim();
  300. item.CaseName = row["案件名称"].ToString().Trim();
  301. item.CaseType = row["案件类型"].ToString().Trim();
  302. item.BusinessType = row["业务类型"].ToString().Trim();
  303. item.Customer = new Customer();
  304. item.Customer.Name = row["客户名称"].ToString().Trim();
  305. item.CaseState = row["案件状态"].ToString().Trim();
  306. DateTime temDate = new DateTime();
  307. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  308. {
  309. item.EntrustingDate = temDate;
  310. }
  311. string strHandler = "";
  312. if (row.Table.Columns.Contains("处理人"))
  313. {
  314. strHandler = row["处理人"].ToString().Trim();
  315. }
  316. else
  317. {
  318. if (row.Table.Columns.Contains("案件处理人"))
  319. {
  320. strHandler = row["案件处理人"].ToString().Trim();
  321. }
  322. }
  323. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  324. item.ItemStaffs = new List<ItemStaff>();
  325. foreach (string name in temHandlers)
  326. {
  327. ItemStaff itemStaff = new ItemStaff();
  328. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  329. int? iTem = GetStaff(temName);
  330. if ((iTem != null))
  331. {
  332. //itemStaff.Item = item;
  333. itemStaff.DoPersonId = iTem.Value;
  334. item.ItemStaffs.Add(itemStaff);
  335. }
  336. else
  337. {
  338. itemStaff.DoPerson = new Staff()
  339. {
  340. Name = temName,
  341. Account = temName,
  342. Password = "12345678",
  343. IsCalPerformsnce = false,
  344. Status = "试用期",
  345. StaffGradeId = 4
  346. };
  347. item.ItemStaffs.Add(itemStaff);
  348. }
  349. }
  350. if (item.ItemStaffs.Count == 0)
  351. {
  352. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  353. }
  354. if (row.Table.Columns.Contains("核稿人"))
  355. {
  356. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  357. }
  358. else
  359. {
  360. if (row.Table.Columns.Contains("案件核稿人"))
  361. {
  362. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  363. }
  364. }
  365. if (row.Table.Columns.Contains("业务人员"))
  366. {
  367. item.WorkflowUserId = GetStaff(row["业务人员"].ToString().Trim());
  368. }
  369. if (row.Table.Columns.Contains("国家(地区)"))
  370. {
  371. item.Country = row["国家(地区)"].ToString().Trim();
  372. }
  373. return item;
  374. }
  375. private PerformanceItem Row2Item_2(DataRow row, CalMonth calMonth)
  376. {
  377. PerformanceItem item = new PerformanceItem();
  378. item.CaseNo = row["我方文号"].ToString().Trim();
  379. item.CaseName= row["案件名称"].ToString().Trim();
  380. item.CaseType = row["案件类型"].ToString().Trim();
  381. item.BusinessType= row["业务类型"].ToString().Trim();
  382. item.Customer = new Customer();
  383. item.Customer.Name = row["客户名称"].ToString().Trim();
  384. item.CaseState = row["案件状态"].ToString().Trim();
  385. item.DoItem = row["处理事项"].ToString().Trim();
  386. if (row.Table.Columns.Contains("国家(地区)"))
  387. {
  388. item.Country = row["国家(地区)"].ToString().Trim();
  389. }
  390. DateTime temDate = new DateTime();
  391. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  392. {
  393. item.InternalDate = temDate;
  394. }
  395. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  396. {
  397. item.CustomerLimitDate = temDate;
  398. }
  399. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  400. {
  401. item.FirstDraftDate = temDate;
  402. }
  403. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  404. {
  405. item.FinalizationDate = temDate;
  406. }
  407. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  408. {
  409. item.EntrustingDate = temDate;
  410. }
  411. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  412. {
  413. item.FinishedDate = temDate;
  414. }
  415. item.DoItemState = row["处理状态"].ToString().Trim();
  416. string strHandler = "";
  417. if (row.Table.Columns.Contains("处理人"))
  418. {
  419. strHandler = row["处理人"].ToString().Trim();
  420. }
  421. else
  422. {
  423. if (row.Table.Columns.Contains("案件处理人"))
  424. {
  425. strHandler = row["案件处理人"].ToString().Trim();
  426. }
  427. }
  428. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  429. item.ItemStaffs = new List<ItemStaff>();
  430. foreach (string name in temHandlers)
  431. {
  432. ItemStaff itemStaff = new ItemStaff();
  433. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  434. int? iTem = GetStaff(temName);
  435. if ((iTem != null))
  436. {
  437. //itemStaff.Item = item;
  438. itemStaff.DoPersonId = iTem.Value;
  439. item.ItemStaffs.Add(itemStaff);
  440. }
  441. else
  442. {
  443. itemStaff.DoPerson = new Staff()
  444. {
  445. Name = temName,
  446. Account = temName,
  447. Password = "12345678",
  448. IsCalPerformsnce = false,
  449. Status = "试用期",
  450. StaffGradeId = 4
  451. };
  452. item.ItemStaffs.Add(itemStaff);
  453. }
  454. }
  455. if (item.ItemStaffs.Count == 0)
  456. {
  457. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  458. }
  459. if (row.Table.Columns.Contains("核稿人"))
  460. {
  461. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  462. }
  463. else
  464. {
  465. if (row.Table.Columns.Contains("案件核稿人"))
  466. {
  467. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  468. }
  469. }
  470. if (row.Table.Columns.Contains("业务人员"))
  471. {
  472. if (!string.IsNullOrEmpty(row["业务人员"].ToString().Trim()))
  473. {
  474. string temName = row["业务人员"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  475. item.WorkflowUserId = GetStaff(temName);
  476. }
  477. }
  478. return item;
  479. }
  480. private PerformanceItem Row2Item_1(DataRow row, CalMonth calMonth)
  481. {
  482. PerformanceItem item = new PerformanceItem();
  483. item.ApplicationType = row["申请类型"].ToString().Trim();
  484. if (item.ApplicationType != "发明")
  485. {
  486. return null;
  487. }
  488. item.CaseNo = row["我方文号"].ToString().Trim();
  489. if (item.CaseNo.StartsWith("S"))
  490. {
  491. return null;
  492. }
  493. if (calMonth != null)
  494. {
  495. item.CalMonth = calMonth;
  496. }
  497. else
  498. {
  499. if (row.Table.Columns.Contains("绩效核算月份"))
  500. {
  501. string strjxyf = row["绩效核算月份"].ToString().Trim();
  502. string[] temYFs = strjxyf.Split(new char[] { '.' });
  503. item.CalMonth = new CalMonth();
  504. item.CalMonth.Year = int.Parse(temYFs[0]);
  505. item.CalMonth.Month = int.Parse(temYFs[1]);
  506. item.CalMonth.Status = 4;
  507. }
  508. else
  509. {
  510. item.CalMonth = new CalMonth();
  511. item.Status = 0;
  512. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  513. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  514. }
  515. }
  516. item.ApplicationType = row["申请类型"].ToString().Trim();
  517. item.BusinessType = "普通新申请"; // row["业务类型"].ToString().Trim();
  518. item.AgentFeedbackMemo = "发明一次OA授权"; //row["备注(填表注意事项)"].ToString().Trim();
  519. item.DoItem = "发明一次OA授权"; //row["处理事项"].ToString().Trim();
  520. string strHandler = "";
  521. if (row.Table.Columns.Contains("处理人"))
  522. {
  523. strHandler = row["处理人"].ToString().Trim();
  524. }
  525. else
  526. {
  527. if (row.Table.Columns.Contains("案件处理人"))
  528. {
  529. strHandler = row["案件处理人"].ToString().Trim();
  530. }
  531. }
  532. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  533. item.ItemStaffs = new List<ItemStaff>();
  534. foreach (string name in temHandlers)
  535. {
  536. ItemStaff itemStaff = new ItemStaff();
  537. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  538. int? iTem = GetStaff(temName);
  539. if ((iTem != null))
  540. {
  541. //itemStaff.Item = item;
  542. itemStaff.DoPersonId = iTem.Value;
  543. item.ItemStaffs.Add(itemStaff);
  544. }
  545. else
  546. {
  547. itemStaff.DoPerson = new Staff()
  548. {
  549. Name = temName,
  550. Account = temName,
  551. Password = "12345678",
  552. IsCalPerformsnce = false,
  553. Status = "试用期",
  554. StaffGradeId = 4
  555. };
  556. item.ItemStaffs.Add(itemStaff);
  557. }
  558. }
  559. if (item.ItemStaffs.Count == 0)
  560. {
  561. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  562. }
  563. if (row.Table.Columns.Contains("核稿人"))
  564. {
  565. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  566. }
  567. else
  568. {
  569. if (row.Table.Columns.Contains("案件核稿人"))
  570. {
  571. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  572. }
  573. }
  574. if (row.Table.Columns.Contains("业务人员"))
  575. {
  576. if (!string.IsNullOrEmpty(row["业务人员"].ToString().Trim()))
  577. {
  578. string temName = row["业务人员"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  579. item.WorkflowUserId = GetStaff(temName);
  580. }
  581. }
  582. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  583. item.ApplicationName = row["申请人"].ToString().Trim();
  584. item.CaseName = row["案件名称"].ToString().Trim();
  585. if (row.Table.Columns.Contains("国家(地区)"))
  586. {
  587. item.Country = row["国家(地区)"].ToString().Trim();
  588. }
  589. //案件备注
  590. item.CaseMemo = $"发文日期:{row["发文日期"].ToString().Trim()}\r\n客户文号:{row["客户文号"].ToString().Trim()}\r\n上传日期:{row["上传日期"].ToString().Trim()}\r\n文件描述:{row["文件描述"].ToString().Trim()}";
  591. if (row.Table.Columns.Contains("翻译字数"))
  592. {
  593. //item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  594. var strWordCount = row["翻译字数"].ToString().Trim();
  595. if (string.IsNullOrEmpty(strWordCount))
  596. {
  597. try
  598. {
  599. item.WordCount = int.Parse(strWordCount);
  600. }
  601. catch { }
  602. }
  603. }
  604. return item;
  605. }
  606. private PerformanceItem Row2Item(DataRow row, CalMonth calMonth)
  607. {
  608. PerformanceItem item = new PerformanceItem();
  609. item.CaseNo = row["我方文号"].ToString().Trim();
  610. if (item.CaseNo.StartsWith("S"))
  611. {
  612. return null;
  613. }
  614. if (calMonth != null)
  615. {
  616. item.CalMonth = calMonth;
  617. }
  618. else
  619. {
  620. if (row.Table.Columns.Contains("绩效核算月份"))
  621. {
  622. string strjxyf = row["绩效核算月份"].ToString().Trim();
  623. string[] temYFs = strjxyf.Split(new char[] { '.' });
  624. item.CalMonth = new CalMonth();
  625. item.CalMonth.Year = int.Parse(temYFs[0]);
  626. item.CalMonth.Month = int.Parse(temYFs[1]);
  627. item.CalMonth.Status = 4;
  628. }
  629. else
  630. {
  631. item.CalMonth = new CalMonth();
  632. item.Status = 0;
  633. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  634. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  635. }
  636. }
  637. item.ApplicationType = row["申请类型"].ToString().Trim();
  638. item.BusinessType = row["业务类型"].ToString().Trim();
  639. if (row.Table.Columns.Contains("国家(地区)"))
  640. {
  641. item.Country = row["国家(地区)"].ToString().Trim();
  642. }
  643. if (row.Table.Columns.Contains("备注(填表注意事项)"))
  644. item.AgentFeedbackMemo = row["备注(填表注意事项)"].ToString().Trim();
  645. item.DoItem = row["处理事项"].ToString().Trim();
  646. item.CaseStage = row["案件阶段"].ToString().Trim();
  647. item.CaseCoefficient = row["案件系数"].ToString().Trim();
  648. item.DoItemCoefficient = row["处理事项系数"].ToString().Trim();
  649. item.PreOastaffId = GetStaff(row["前一次OA处理人"].ToString().Trim());
  650. string strHandler = "";
  651. if (row.Table.Columns.Contains("处理人"))
  652. {
  653. strHandler = row["处理人"].ToString().Trim();
  654. }
  655. else
  656. {
  657. if (row.Table.Columns.Contains("案件处理人"))
  658. {
  659. strHandler = row["案件处理人"].ToString().Trim();
  660. }
  661. }
  662. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  663. item.ItemStaffs = new List<ItemStaff>();
  664. foreach (string name in temHandlers)
  665. {
  666. ItemStaff itemStaff = new ItemStaff();
  667. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  668. int? iTem = GetStaff(temName);
  669. if ((iTem != null))
  670. {
  671. //itemStaff.Item = item;
  672. itemStaff.DoPersonId = iTem.Value;
  673. item.ItemStaffs.Add(itemStaff);
  674. }
  675. else
  676. {
  677. itemStaff.DoPerson = new Staff()
  678. {
  679. Name = temName,
  680. Account = temName,
  681. Password = "12345678",
  682. IsCalPerformsnce = false,
  683. Status = "试用期",
  684. StaffGradeId = 4
  685. };
  686. item.ItemStaffs.Add(itemStaff);
  687. }
  688. }
  689. if (item.ItemStaffs.Count == 0)
  690. {
  691. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  692. }
  693. if (row.Table.Columns.Contains("核稿人"))
  694. {
  695. if (!string.IsNullOrEmpty(row["核稿人"].ToString().Trim()))
  696. {
  697. string temName = row["核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  698. item.ReviewerId = GetStaff(temName);
  699. }
  700. }
  701. else
  702. {
  703. if (row.Table.Columns.Contains("案件核稿人"))
  704. {
  705. if (!string.IsNullOrEmpty(row["案件核稿人"].ToString().Trim()))
  706. {
  707. string temName = row["案件核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  708. item.ReviewerId = GetStaff(temName);
  709. }
  710. }
  711. }
  712. if (row.Table.Columns.Contains("业务人员"))
  713. {
  714. if (!string.IsNullOrEmpty(row["业务人员"].ToString().Trim()))
  715. {
  716. string temName = row["业务人员"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  717. item.WorkflowUserId = GetStaff(temName);
  718. }
  719. }
  720. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  721. item.ApplicationName = row["申请人"].ToString().Trim();
  722. DateTime temDate = new DateTime();
  723. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  724. {
  725. item.FinishedDate = temDate;
  726. }
  727. //定稿日
  728. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  729. {
  730. item.FinalizationDate = temDate;
  731. }
  732. //返稿日
  733. if (DateTime.TryParse(row["返稿日"].ToString().Trim(), out temDate))
  734. {
  735. item.ReturnDate = temDate;
  736. }
  737. //案件类型
  738. item.CaseType = row["案件类型"].ToString().Trim();
  739. //案件状态
  740. item.CaseState = row["案件状态"].ToString().Trim();
  741. //处理事项备注
  742. item.DoItemMemo = row["处理事项备注"].ToString().Trim();
  743. //处理状态
  744. item.DoItemState = row["处理状态"].ToString().Trim();
  745. //案件名称
  746. item.CaseName = row["案件名称"].ToString().Trim();
  747. //委案日期
  748. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  749. {
  750. item.EntrustingDate = temDate;
  751. }
  752. //客户期限
  753. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  754. {
  755. item.CustomerLimitDate = temDate;
  756. }
  757. //内部期限
  758. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  759. {
  760. item.InternalDate = temDate;
  761. }
  762. //初稿日
  763. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  764. {
  765. item.FirstDraftDate = temDate;
  766. }
  767. //备注(发文严重超期是否属客观原因,若为否,请填写原因)
  768. if (row.Table.Columns.Contains("备注(发文严重超期是否属客观原因,若为否,请填写原因)"))
  769. {
  770. item.OverDueMemo = row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"].ToString().Trim();
  771. }
  772. //案件备注
  773. item.CaseMemo = row["案件备注"].ToString().Trim();
  774. if (row.Table.Columns.Contains("翻译字数"))
  775. {
  776. //item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  777. var strWordCount = row["翻译字数"].ToString().Trim();
  778. if (string.IsNullOrEmpty(strWordCount))
  779. {
  780. try
  781. {
  782. item.WordCount = int.Parse(strWordCount);
  783. }
  784. catch { }
  785. }
  786. }
  787. return item;
  788. }
  789. private int? GetStaff(string v)
  790. {
  791. if (!string.IsNullOrEmpty(v))
  792. {
  793. string temName = v.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  794. var staff = spDb.Staffs.Where<Staff>(s => s.Name == temName).FirstOrDefault();
  795. if (staff != null)
  796. {
  797. return staff.Id;
  798. }
  799. }
  800. return null;
  801. }
  802. }
  803. }