ImportReportJob.cs 32 KB

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