ImportReportJob.cs 35 KB

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