ImportReportJob.cs 32 KB

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