ImportReportJob.cs 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  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) && !isDBNotFinishedDate(item))
  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 bool isDBNotFinishedDate(PerformanceItem item)
  280. {
  281. return (item.DoItem == "处理审查意见" && item.FinishedDate == null);
  282. }
  283. private Task SavePerformanceItem(PerformanceItem item,List<BasePointRule> rules)
  284. {
  285. try
  286. {
  287. Utility.Utility.CalBasePoint(item, rules);
  288. var ret= new Controllers.PerformanceItemController(spDb,new Services.FileTaskCacheService()).New(item);
  289. if (ret.Success == false)
  290. {
  291. System.Diagnostics.Debug.WriteLine(ret.ErrorMessage);
  292. }
  293. }
  294. catch (Exception ex)
  295. {
  296. System.Diagnostics.Debug.WriteLine(ex.Message);
  297. }
  298. return Task.CompletedTask;
  299. }
  300. private PerformanceItem Row2Item_3(DataRow row, CalMonth calMonth)
  301. {
  302. PerformanceItem item = new PerformanceItem();
  303. item.CaseNo = row["我方文号"].ToString().Trim();
  304. item.CaseName = row["案件名称"].ToString().Trim();
  305. item.CaseType = row["案件类型"].ToString().Trim();
  306. item.BusinessType = row["业务类型"].ToString().Trim();
  307. item.Customer = new Customer();
  308. item.Customer.Name = row["客户名称"].ToString().Trim();
  309. item.CaseState = row["案件状态"].ToString().Trim();
  310. DateTime temDate = new DateTime();
  311. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  312. {
  313. item.EntrustingDate = temDate;
  314. }
  315. string strHandler = "";
  316. if (row.Table.Columns.Contains("处理人"))
  317. {
  318. strHandler = row["处理人"].ToString().Trim();
  319. }
  320. else
  321. {
  322. if (row.Table.Columns.Contains("案件处理人"))
  323. {
  324. strHandler = row["案件处理人"].ToString().Trim();
  325. }
  326. }
  327. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  328. item.ItemStaffs = new List<ItemStaff>();
  329. foreach (string name in temHandlers)
  330. {
  331. ItemStaff itemStaff = new ItemStaff();
  332. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  333. if (!name.Contains("君龙"))
  334. {
  335. temName = name.Trim();
  336. }
  337. int? iTem = GetStaff(name);
  338. if ((iTem != null))
  339. {
  340. //itemStaff.Item = item;
  341. itemStaff.DoPersonId = iTem.Value;
  342. item.ItemStaffs.Add(itemStaff);
  343. }
  344. else
  345. {
  346. itemStaff.DoPerson = new Staff()
  347. {
  348. Name = temName,
  349. Account = temName,
  350. Password = "12345678",
  351. IsCalPerformsnce = false,
  352. Status = "试用期",
  353. StaffGradeId = 4
  354. };
  355. item.ItemStaffs.Add(itemStaff);
  356. }
  357. }
  358. if (item.ItemStaffs.Count == 0)
  359. {
  360. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  361. }
  362. if (row.Table.Columns.Contains("核稿人"))
  363. {
  364. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  365. }
  366. else
  367. {
  368. if (row.Table.Columns.Contains("案件核稿人"))
  369. {
  370. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  371. }
  372. }
  373. if (row.Table.Columns.Contains("业务人员"))
  374. {
  375. item.WorkflowUserId = GetStaff(row["业务人员"].ToString().Trim());
  376. }
  377. if (row.Table.Columns.Contains("国家(地区)"))
  378. {
  379. item.Country = row["国家(地区)"].ToString().Trim();
  380. }
  381. return item;
  382. }
  383. private PerformanceItem Row2Item_2(DataRow row, CalMonth calMonth)
  384. {
  385. PerformanceItem item = new PerformanceItem();
  386. item.CaseNo = row["我方文号"].ToString().Trim();
  387. item.CaseName= row["案件名称"].ToString().Trim();
  388. item.CaseType = row["案件类型"].ToString().Trim();
  389. item.BusinessType= row["业务类型"].ToString().Trim();
  390. item.Customer = new Customer();
  391. item.Customer.Name = row["客户名称"].ToString().Trim();
  392. item.CaseState = row["案件状态"].ToString().Trim();
  393. item.DoItem = row["处理事项"].ToString().Trim();
  394. if (row.Table.Columns.Contains("国家(地区)"))
  395. {
  396. item.Country = row["国家(地区)"].ToString().Trim();
  397. }
  398. DateTime temDate = new DateTime();
  399. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  400. {
  401. item.InternalDate = temDate;
  402. }
  403. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  404. {
  405. item.CustomerLimitDate = temDate;
  406. }
  407. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  408. {
  409. item.FirstDraftDate = temDate;
  410. }
  411. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  412. {
  413. item.FinalizationDate = temDate;
  414. }
  415. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  416. {
  417. item.EntrustingDate = temDate;
  418. }
  419. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  420. {
  421. item.FinishedDate = temDate;
  422. }
  423. item.DoItemState = row["处理状态"].ToString().Trim();
  424. string strHandler = "";
  425. if (row.Table.Columns.Contains("处理人"))
  426. {
  427. strHandler = row["处理人"].ToString().Trim();
  428. }
  429. else
  430. {
  431. if (row.Table.Columns.Contains("案件处理人"))
  432. {
  433. strHandler = row["案件处理人"].ToString().Trim();
  434. }
  435. }
  436. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  437. item.ItemStaffs = new List<ItemStaff>();
  438. foreach (string name in temHandlers)
  439. {
  440. ItemStaff itemStaff = new ItemStaff();
  441. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  442. if (!name.Contains("君龙"))
  443. {
  444. temName = name.Trim();
  445. }
  446. int? iTem = GetStaff(temName);
  447. if ((iTem != null))
  448. {
  449. //itemStaff.Item = item;
  450. itemStaff.DoPersonId = iTem.Value;
  451. item.ItemStaffs.Add(itemStaff);
  452. }
  453. else
  454. {
  455. itemStaff.DoPerson = new Staff()
  456. {
  457. Name = temName,
  458. Account = temName,
  459. Password = "12345678",
  460. IsCalPerformsnce = false,
  461. Status = "试用期",
  462. StaffGradeId = 4
  463. };
  464. item.ItemStaffs.Add(itemStaff);
  465. }
  466. }
  467. if (item.ItemStaffs.Count == 0)
  468. {
  469. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  470. }
  471. if (row.Table.Columns.Contains("核稿人"))
  472. {
  473. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  474. }
  475. else
  476. {
  477. if (row.Table.Columns.Contains("案件核稿人"))
  478. {
  479. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  480. }
  481. }
  482. if (row.Table.Columns.Contains("业务人员"))
  483. {
  484. if (!string.IsNullOrEmpty(row["业务人员"].ToString().Trim()))
  485. {
  486. string name = row["业务人员"].ToString().Trim();
  487. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  488. if (!name.Contains("君龙"))
  489. {
  490. temName = name.Trim();
  491. }
  492. item.WorkflowUserId = GetStaff(temName);
  493. }
  494. }
  495. return item;
  496. }
  497. private PerformanceItem Row2Item_1(DataRow row, CalMonth calMonth)
  498. {
  499. PerformanceItem item = new PerformanceItem();
  500. item.ApplicationType = row["申请类型"].ToString().Trim();
  501. if (item.ApplicationType != "发明")
  502. {
  503. return null;
  504. }
  505. item.CaseNo = row["我方文号"].ToString().Trim();
  506. if (item.CaseNo.StartsWith("S"))
  507. {
  508. return null;
  509. }
  510. if (calMonth != null)
  511. {
  512. item.CalMonth = calMonth;
  513. }
  514. else
  515. {
  516. if (row.Table.Columns.Contains("绩效核算月份"))
  517. {
  518. string strjxyf = row["绩效核算月份"].ToString().Trim();
  519. string[] temYFs = strjxyf.Split(new char[] { '.' });
  520. item.CalMonth = new CalMonth();
  521. item.CalMonth.Year = int.Parse(temYFs[0]);
  522. item.CalMonth.Month = int.Parse(temYFs[1]);
  523. item.CalMonth.Status = 4;
  524. }
  525. else
  526. {
  527. item.CalMonth = new CalMonth();
  528. item.Status = 0;
  529. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  530. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  531. }
  532. }
  533. item.ApplicationType = row["申请类型"].ToString().Trim();
  534. item.BusinessType = "普通新申请"; // row["业务类型"].ToString().Trim();
  535. item.AgentFeedbackMemo = "发明一次OA授权"; //row["备注(填表注意事项)"].ToString().Trim();
  536. item.DoItem = "发明一次OA授权"; //row["处理事项"].ToString().Trim();
  537. string strHandler = "";
  538. if (row.Table.Columns.Contains("处理人"))
  539. {
  540. strHandler = row["处理人"].ToString().Trim();
  541. }
  542. else
  543. {
  544. if (row.Table.Columns.Contains("案件处理人"))
  545. {
  546. strHandler = row["案件处理人"].ToString().Trim();
  547. }
  548. }
  549. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  550. item.ItemStaffs = new List<ItemStaff>();
  551. foreach (string name in temHandlers)
  552. {
  553. ItemStaff itemStaff = new ItemStaff();
  554. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  555. if (!name.Contains("君龙"))
  556. {
  557. temName = name.Trim();
  558. }
  559. int? iTem = GetStaff(temName);
  560. if ((iTem != null))
  561. {
  562. //itemStaff.Item = item;
  563. itemStaff.DoPersonId = iTem.Value;
  564. item.ItemStaffs.Add(itemStaff);
  565. }
  566. else
  567. {
  568. itemStaff.DoPerson = new Staff()
  569. {
  570. Name = temName,
  571. Account = temName,
  572. Password = "12345678",
  573. IsCalPerformsnce = false,
  574. Status = "试用期",
  575. StaffGradeId = 4
  576. };
  577. item.ItemStaffs.Add(itemStaff);
  578. }
  579. }
  580. if (item.ItemStaffs.Count == 0)
  581. {
  582. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  583. }
  584. if (row.Table.Columns.Contains("核稿人"))
  585. {
  586. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  587. }
  588. else
  589. {
  590. if (row.Table.Columns.Contains("案件核稿人"))
  591. {
  592. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  593. }
  594. }
  595. if (row.Table.Columns.Contains("业务人员"))
  596. {
  597. if (!string.IsNullOrEmpty(row["业务人员"].ToString().Trim()))
  598. {
  599. string name = row["业务人员"].ToString();
  600. string temName = row["业务人员"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  601. if (!name.Contains("君龙"))
  602. {
  603. temName = name.Trim();
  604. }
  605. item.WorkflowUserId = GetStaff(temName);
  606. }
  607. }
  608. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  609. item.ApplicationName = row["申请人"].ToString().Trim();
  610. item.CaseName = row["案件名称"].ToString().Trim();
  611. if (row.Table.Columns.Contains("国家(地区)"))
  612. {
  613. item.Country = row["国家(地区)"].ToString().Trim();
  614. }
  615. //案件备注
  616. item.CaseMemo = $"发文日期:{row["发文日期"].ToString().Trim()}\r\n客户文号:{row["客户文号"].ToString().Trim()}\r\n上传日期:{row["上传日期"].ToString().Trim()}\r\n文件描述:{row["文件描述"].ToString().Trim()}";
  617. if (row.Table.Columns.Contains("翻译字数"))
  618. {
  619. //item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  620. var strWordCount = row["翻译字数"].ToString().Trim();
  621. if (string.IsNullOrEmpty(strWordCount))
  622. {
  623. try
  624. {
  625. item.WordCount = int.Parse(strWordCount);
  626. }
  627. catch { }
  628. }
  629. }
  630. return item;
  631. }
  632. private PerformanceItem Row2Item(DataRow row, CalMonth calMonth)
  633. {
  634. PerformanceItem item = new PerformanceItem();
  635. item.CaseNo = row["我方文号"].ToString().Trim();
  636. if (item.CaseNo.StartsWith("S"))
  637. {
  638. return null;
  639. }
  640. if (calMonth != null)
  641. {
  642. item.CalMonth = calMonth;
  643. }
  644. else
  645. {
  646. if (row.Table.Columns.Contains("绩效核算月份"))
  647. {
  648. string strjxyf = row["绩效核算月份"].ToString().Trim();
  649. string[] temYFs = strjxyf.Split(new char[] { '.' });
  650. item.CalMonth = new CalMonth();
  651. item.CalMonth.Year = int.Parse(temYFs[0]);
  652. item.CalMonth.Month = int.Parse(temYFs[1]);
  653. item.CalMonth.Status = 4;
  654. }
  655. else
  656. {
  657. item.CalMonth = new CalMonth();
  658. item.Status = 0;
  659. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  660. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  661. }
  662. }
  663. item.ApplicationType = row["申请类型"].ToString().Trim();
  664. item.BusinessType = row["业务类型"].ToString().Trim();
  665. if (row.Table.Columns.Contains("国家(地区)"))
  666. {
  667. item.Country = row["国家(地区)"].ToString().Trim();
  668. }
  669. if (row.Table.Columns.Contains("备注(填表注意事项)"))
  670. item.AgentFeedbackMemo = row["备注(填表注意事项)"].ToString().Trim();
  671. item.DoItem = row["处理事项"].ToString().Trim();
  672. item.CaseStage = row["案件阶段"].ToString().Trim();
  673. item.CaseCoefficient = row["案件系数"].ToString().Trim();
  674. item.DoItemCoefficient = row["处理事项系数"].ToString().Trim();
  675. item.PreOastaffId = GetStaff(row["前一次OA处理人"].ToString().Trim());
  676. string strHandler = "";
  677. if (row.Table.Columns.Contains("处理人"))
  678. {
  679. strHandler = row["处理人"].ToString().Trim();
  680. }
  681. else
  682. {
  683. if (row.Table.Columns.Contains("案件处理人"))
  684. {
  685. strHandler = row["案件处理人"].ToString().Trim();
  686. }
  687. }
  688. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  689. item.ItemStaffs = new List<ItemStaff>();
  690. foreach (string name in temHandlers)
  691. {
  692. ItemStaff itemStaff = new ItemStaff();
  693. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  694. if (!name.Contains("君龙"))
  695. {
  696. temName = name.Trim();
  697. }
  698. int? iTem = GetStaff(temName);
  699. if ((iTem != null))
  700. {
  701. //itemStaff.Item = item;
  702. itemStaff.DoPersonId = iTem.Value;
  703. item.ItemStaffs.Add(itemStaff);
  704. }
  705. else
  706. {
  707. itemStaff.DoPerson = new Staff()
  708. {
  709. Name = temName,
  710. Account = temName,
  711. Password = "12345678",
  712. IsCalPerformsnce = false,
  713. Status = "试用期",
  714. StaffGradeId = 4
  715. };
  716. item.ItemStaffs.Add(itemStaff);
  717. }
  718. }
  719. if (item.ItemStaffs.Count == 0)
  720. {
  721. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  722. }
  723. if (row.Table.Columns.Contains("核稿人"))
  724. {
  725. if (!string.IsNullOrEmpty(row["核稿人"].ToString().Trim()))
  726. {
  727. string name = row["核稿人"].ToString();
  728. string temName = name.Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  729. if (!name.Contains("君龙"))
  730. {
  731. temName = name.Trim();
  732. }
  733. item.ReviewerId = GetStaff(temName);
  734. }
  735. }
  736. else
  737. {
  738. if (row.Table.Columns.Contains("案件核稿人"))
  739. {
  740. if (!string.IsNullOrEmpty(row["案件核稿人"].ToString().Trim()))
  741. {
  742. string name = row["案件核稿人"].ToString();
  743. string temName = row["案件核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  744. if (!name.Contains("君龙"))
  745. {
  746. temName = name.Trim();
  747. }
  748. item.ReviewerId = GetStaff(temName);
  749. }
  750. }
  751. }
  752. if (row.Table.Columns.Contains("业务人员"))
  753. {
  754. if (!string.IsNullOrEmpty(row["业务人员"].ToString().Trim()))
  755. {
  756. string name = row["业务人员"].ToString();
  757. string temName = row["业务人员"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  758. if (!name.Contains("君龙"))
  759. {
  760. temName = name.Trim();
  761. }
  762. item.WorkflowUserId = GetStaff(temName);
  763. }
  764. }
  765. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  766. item.ApplicationName = row["申请人"].ToString().Trim();
  767. DateTime temDate = new DateTime();
  768. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  769. {
  770. item.FinishedDate = temDate;
  771. }
  772. //定稿日
  773. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  774. {
  775. item.FinalizationDate = temDate;
  776. }
  777. //返稿日
  778. if (DateTime.TryParse(row["返稿日"].ToString().Trim(), out temDate))
  779. {
  780. item.ReturnDate = temDate;
  781. }
  782. //案件类型
  783. item.CaseType = row["案件类型"].ToString().Trim();
  784. //案件状态
  785. item.CaseState = row["案件状态"].ToString().Trim();
  786. //处理事项备注
  787. item.DoItemMemo = row["处理事项备注"].ToString().Trim();
  788. //处理状态
  789. item.DoItemState = row["处理状态"].ToString().Trim();
  790. //案件名称
  791. item.CaseName = row["案件名称"].ToString().Trim();
  792. //委案日期
  793. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  794. {
  795. item.EntrustingDate = temDate;
  796. }
  797. //客户期限
  798. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  799. {
  800. item.CustomerLimitDate = temDate;
  801. }
  802. //内部期限
  803. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  804. {
  805. item.InternalDate = temDate;
  806. }
  807. //初稿日
  808. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  809. {
  810. item.FirstDraftDate = temDate;
  811. }
  812. //备注(发文严重超期是否属客观原因,若为否,请填写原因)
  813. if (row.Table.Columns.Contains("备注(发文严重超期是否属客观原因,若为否,请填写原因)"))
  814. {
  815. item.OverDueMemo = row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"].ToString().Trim();
  816. }
  817. //案件备注
  818. item.CaseMemo = row["案件备注"].ToString().Trim();
  819. if (row.Table.Columns.Contains("翻译字数"))
  820. {
  821. //item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  822. var strWordCount = row["翻译字数"].ToString().Trim();
  823. if (string.IsNullOrEmpty(strWordCount))
  824. {
  825. try
  826. {
  827. item.WordCount = int.Parse(strWordCount);
  828. }
  829. catch { }
  830. }
  831. }
  832. return item;
  833. }
  834. private int? GetStaff(string v)
  835. {
  836. if (!string.IsNullOrEmpty(v))
  837. {
  838. string temName = v.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  839. if (!v.Contains("君龙"))
  840. {
  841. temName = v;
  842. }
  843. var staff = spDb.Staffs.Where<Staff>(s => s.Name == temName).FirstOrDefault();
  844. if (staff != null)
  845. {
  846. return staff.Id;
  847. }
  848. }
  849. return null;
  850. }
  851. }
  852. }