ImportReportJob.cs 32 KB

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