ImportReportJob.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  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. return item;
  381. }
  382. private PerformanceItem Row2Item_2(DataRow row, CalMonth calMonth)
  383. {
  384. PerformanceItem item = new PerformanceItem();
  385. item.CaseNo = row["我方文号"].ToString().Trim();
  386. item.CaseName= row["案件名称"].ToString().Trim();
  387. item.CaseType = row["案件类型"].ToString().Trim();
  388. item.BusinessType= row["业务类型"].ToString().Trim();
  389. item.Customer = new Customer();
  390. item.Customer.Name = row["客户名称"].ToString().Trim();
  391. item.CaseState = row["案件状态"].ToString().Trim();
  392. item.DoItem = row["处理事项"].ToString().Trim();
  393. DateTime temDate = new DateTime();
  394. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  395. {
  396. item.InternalDate = temDate;
  397. }
  398. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  399. {
  400. item.CustomerLimitDate = temDate;
  401. }
  402. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  403. {
  404. item.FirstDraftDate = temDate;
  405. }
  406. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  407. {
  408. item.FinalizationDate = temDate;
  409. }
  410. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  411. {
  412. item.EntrustingDate = temDate;
  413. }
  414. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  415. {
  416. item.FinishedDate = temDate;
  417. }
  418. item.DoItemState = row["处理状态"].ToString().Trim();
  419. string strHandler = "";
  420. if (row.Table.Columns.Contains("处理人"))
  421. {
  422. strHandler = row["处理人"].ToString().Trim();
  423. }
  424. else
  425. {
  426. if (row.Table.Columns.Contains("案件处理人"))
  427. {
  428. strHandler = row["案件处理人"].ToString().Trim();
  429. }
  430. }
  431. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  432. item.ItemStaffs = new List<ItemStaff>();
  433. foreach (string name in temHandlers)
  434. {
  435. ItemStaff itemStaff = new ItemStaff();
  436. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  437. int? iTem = GetStaff(temName);
  438. if ((iTem != null))
  439. {
  440. //itemStaff.Item = item;
  441. itemStaff.DoPersonId = iTem.Value;
  442. item.ItemStaffs.Add(itemStaff);
  443. }
  444. else
  445. {
  446. itemStaff.DoPerson = new Staff()
  447. {
  448. Name = temName,
  449. Account = temName,
  450. Password = "12345678",
  451. IsCalPerformsnce = false,
  452. Status = "试用期",
  453. StaffGradeId = 4
  454. };
  455. item.ItemStaffs.Add(itemStaff);
  456. }
  457. }
  458. if (item.ItemStaffs.Count == 0)
  459. {
  460. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  461. }
  462. if (row.Table.Columns.Contains("核稿人"))
  463. {
  464. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  465. }
  466. else
  467. {
  468. if (row.Table.Columns.Contains("案件核稿人"))
  469. {
  470. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  471. }
  472. }
  473. if (row.Table.Columns.Contains("业务人员"))
  474. {
  475. if (!string.IsNullOrEmpty(row["业务人员"].ToString().Trim()))
  476. {
  477. string temName = row["业务人员"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  478. item.WorkflowUserId = GetStaff(temName);
  479. }
  480. }
  481. return item;
  482. }
  483. private PerformanceItem Row2Item_1(DataRow row, CalMonth calMonth)
  484. {
  485. PerformanceItem item = new PerformanceItem();
  486. item.ApplicationType = row["申请类型"].ToString().Trim();
  487. if (item.ApplicationType != "发明")
  488. {
  489. return null;
  490. }
  491. item.CaseNo = row["我方文号"].ToString().Trim();
  492. if (item.CaseNo.StartsWith("S"))
  493. {
  494. return null;
  495. }
  496. if (calMonth != null)
  497. {
  498. item.CalMonth = calMonth;
  499. }
  500. else
  501. {
  502. if (row.Table.Columns.Contains("绩效核算月份"))
  503. {
  504. string strjxyf = row["绩效核算月份"].ToString().Trim();
  505. string[] temYFs = strjxyf.Split(new char[] { '.' });
  506. item.CalMonth = new CalMonth();
  507. item.CalMonth.Year = int.Parse(temYFs[0]);
  508. item.CalMonth.Month = int.Parse(temYFs[1]);
  509. item.CalMonth.Status = 4;
  510. }
  511. else
  512. {
  513. item.CalMonth = new CalMonth();
  514. item.Status = 0;
  515. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  516. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  517. }
  518. }
  519. item.ApplicationType = row["申请类型"].ToString().Trim();
  520. item.BusinessType = "普通新申请"; // row["业务类型"].ToString().Trim();
  521. item.AgentFeedbackMemo = "发明一次OA授权"; //row["备注(填表注意事项)"].ToString().Trim();
  522. item.DoItem = "发明一次OA授权"; //row["处理事项"].ToString().Trim();
  523. string strHandler = "";
  524. if (row.Table.Columns.Contains("处理人"))
  525. {
  526. strHandler = row["处理人"].ToString().Trim();
  527. }
  528. else
  529. {
  530. if (row.Table.Columns.Contains("案件处理人"))
  531. {
  532. strHandler = row["案件处理人"].ToString().Trim();
  533. }
  534. }
  535. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  536. item.ItemStaffs = new List<ItemStaff>();
  537. foreach (string name in temHandlers)
  538. {
  539. ItemStaff itemStaff = new ItemStaff();
  540. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  541. int? iTem = GetStaff(temName);
  542. if ((iTem != null))
  543. {
  544. //itemStaff.Item = item;
  545. itemStaff.DoPersonId = iTem.Value;
  546. item.ItemStaffs.Add(itemStaff);
  547. }
  548. else
  549. {
  550. itemStaff.DoPerson = new Staff()
  551. {
  552. Name = temName,
  553. Account = temName,
  554. Password = "12345678",
  555. IsCalPerformsnce = false,
  556. Status = "试用期",
  557. StaffGradeId = 4
  558. };
  559. item.ItemStaffs.Add(itemStaff);
  560. }
  561. }
  562. if (item.ItemStaffs.Count == 0)
  563. {
  564. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  565. }
  566. if (row.Table.Columns.Contains("核稿人"))
  567. {
  568. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  569. }
  570. else
  571. {
  572. if (row.Table.Columns.Contains("案件核稿人"))
  573. {
  574. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  575. }
  576. }
  577. if (row.Table.Columns.Contains("业务人员"))
  578. {
  579. if (!string.IsNullOrEmpty(row["业务人员"].ToString().Trim()))
  580. {
  581. string temName = row["业务人员"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  582. item.WorkflowUserId = GetStaff(temName);
  583. }
  584. }
  585. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  586. item.ApplicationName = row["申请人"].ToString().Trim();
  587. item.CaseName = row["案件名称"].ToString().Trim();
  588. //案件备注
  589. item.CaseMemo = $"发文日期:{row["发文日期"].ToString().Trim()}\r\n客户文号:{row["客户文号"].ToString().Trim()}\r\n上传日期:{row["上传日期"].ToString().Trim()}\r\n文件描述:{row["文件描述"].ToString().Trim()}";
  590. if (row.Table.Columns.Contains("翻译字数"))
  591. {
  592. //item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  593. var strWordCount = row["翻译字数"].ToString().Trim();
  594. if (string.IsNullOrEmpty(strWordCount))
  595. {
  596. try
  597. {
  598. item.WordCount = int.Parse(strWordCount);
  599. }
  600. catch { }
  601. }
  602. }
  603. return item;
  604. }
  605. private PerformanceItem Row2Item(DataRow row, CalMonth calMonth)
  606. {
  607. PerformanceItem item = new PerformanceItem();
  608. item.CaseNo = row["我方文号"].ToString().Trim();
  609. if (item.CaseNo.StartsWith("S"))
  610. {
  611. return null;
  612. }
  613. if (calMonth != null)
  614. {
  615. item.CalMonth = calMonth;
  616. }
  617. else
  618. {
  619. if (row.Table.Columns.Contains("绩效核算月份"))
  620. {
  621. string strjxyf = row["绩效核算月份"].ToString().Trim();
  622. string[] temYFs = strjxyf.Split(new char[] { '.' });
  623. item.CalMonth = new CalMonth();
  624. item.CalMonth.Year = int.Parse(temYFs[0]);
  625. item.CalMonth.Month = int.Parse(temYFs[1]);
  626. item.CalMonth.Status = 4;
  627. }
  628. else
  629. {
  630. item.CalMonth = new CalMonth();
  631. item.Status = 0;
  632. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  633. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  634. }
  635. }
  636. item.ApplicationType = row["申请类型"].ToString().Trim();
  637. item.BusinessType = row["业务类型"].ToString().Trim();
  638. if (row.Table.Columns.Contains("备注(填表注意事项)"))
  639. item.AgentFeedbackMemo = row["备注(填表注意事项)"].ToString().Trim();
  640. item.DoItem = row["处理事项"].ToString().Trim();
  641. item.CaseStage = row["案件阶段"].ToString().Trim();
  642. item.CaseCoefficient = row["案件系数"].ToString().Trim();
  643. item.DoItemCoefficient = row["处理事项系数"].ToString().Trim();
  644. item.PreOastaffId = GetStaff(row["前一次OA处理人"].ToString().Trim());
  645. string strHandler = "";
  646. if (row.Table.Columns.Contains("处理人"))
  647. {
  648. strHandler = row["处理人"].ToString().Trim();
  649. }
  650. else
  651. {
  652. if (row.Table.Columns.Contains("案件处理人"))
  653. {
  654. strHandler = row["案件处理人"].ToString().Trim();
  655. }
  656. }
  657. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  658. item.ItemStaffs = new List<ItemStaff>();
  659. foreach (string name in temHandlers)
  660. {
  661. ItemStaff itemStaff = new ItemStaff();
  662. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  663. int? iTem = GetStaff(temName);
  664. if ((iTem != null))
  665. {
  666. //itemStaff.Item = item;
  667. itemStaff.DoPersonId = iTem.Value;
  668. item.ItemStaffs.Add(itemStaff);
  669. }
  670. else
  671. {
  672. itemStaff.DoPerson = new Staff()
  673. {
  674. Name = temName,
  675. Account = temName,
  676. Password = "12345678",
  677. IsCalPerformsnce = false,
  678. Status = "试用期",
  679. StaffGradeId = 4
  680. };
  681. item.ItemStaffs.Add(itemStaff);
  682. }
  683. }
  684. if (item.ItemStaffs.Count == 0)
  685. {
  686. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  687. }
  688. if (row.Table.Columns.Contains("核稿人"))
  689. {
  690. if (!string.IsNullOrEmpty(row["核稿人"].ToString().Trim()))
  691. {
  692. string temName = row["核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  693. item.ReviewerId = GetStaff(temName);
  694. }
  695. }
  696. else
  697. {
  698. if (row.Table.Columns.Contains("案件核稿人"))
  699. {
  700. if (!string.IsNullOrEmpty(row["案件核稿人"].ToString().Trim()))
  701. {
  702. string temName = row["案件核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  703. item.ReviewerId = GetStaff(temName);
  704. }
  705. }
  706. }
  707. if (row.Table.Columns.Contains("业务人员"))
  708. {
  709. if (!string.IsNullOrEmpty(row["业务人员"].ToString().Trim()))
  710. {
  711. string temName = row["业务人员"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  712. item.WorkflowUserId = GetStaff(temName);
  713. }
  714. }
  715. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  716. item.ApplicationName = row["申请人"].ToString().Trim();
  717. DateTime temDate = new DateTime();
  718. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  719. {
  720. item.FinishedDate = temDate;
  721. }
  722. //定稿日
  723. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  724. {
  725. item.FinalizationDate = temDate;
  726. }
  727. //返稿日
  728. if (DateTime.TryParse(row["返稿日"].ToString().Trim(), out temDate))
  729. {
  730. item.ReturnDate = temDate;
  731. }
  732. //案件类型
  733. item.CaseType = row["案件类型"].ToString().Trim();
  734. //案件状态
  735. item.CaseState = row["案件状态"].ToString().Trim();
  736. //处理事项备注
  737. item.DoItemMemo = row["处理事项备注"].ToString().Trim();
  738. //处理状态
  739. item.DoItemState = row["处理状态"].ToString().Trim();
  740. //案件名称
  741. item.CaseName = row["案件名称"].ToString().Trim();
  742. //委案日期
  743. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  744. {
  745. item.EntrustingDate = temDate;
  746. }
  747. //客户期限
  748. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  749. {
  750. item.CustomerLimitDate = temDate;
  751. }
  752. //内部期限
  753. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  754. {
  755. item.InternalDate = temDate;
  756. }
  757. //初稿日
  758. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  759. {
  760. item.FirstDraftDate = temDate;
  761. }
  762. //备注(发文严重超期是否属客观原因,若为否,请填写原因)
  763. if (row.Table.Columns.Contains("备注(发文严重超期是否属客观原因,若为否,请填写原因)"))
  764. {
  765. item.OverDueMemo = row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"].ToString().Trim();
  766. }
  767. //案件备注
  768. item.CaseMemo = row["案件备注"].ToString().Trim();
  769. if (row.Table.Columns.Contains("翻译字数"))
  770. {
  771. //item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  772. var strWordCount = row["翻译字数"].ToString().Trim();
  773. if (string.IsNullOrEmpty(strWordCount))
  774. {
  775. try
  776. {
  777. item.WordCount = int.Parse(strWordCount);
  778. }
  779. catch { }
  780. }
  781. }
  782. return item;
  783. }
  784. private int? GetStaff(string v)
  785. {
  786. var staff = spDb.Staffs.Where<Staff>(s => s.Name == v).FirstOrDefault();
  787. if(staff != null)
  788. {
  789. return staff.Id;
  790. }
  791. return null;
  792. }
  793. }
  794. }