ImportReportJob.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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. var lstStaff = spDb.Staffs.Where<Staff>(s=>s.ItemStaffs.Where<ItemStaff>(p=>p.Item.CalMonthId == calMonth.Id).Count<ItemStaff>()>0);
  90. foreach (var staff in lstStaff.ToList<Staff>())
  91. {
  92. string strSubject = $"{calMonth.Year}年{calMonth.Month}月绩效数据确认通知";
  93. string strBody = $"<html><body>{staff.Name},您好!<br/></br/>&nbsp;&nbsp;&nbsp;&nbsp;<div>{calMonth.Year}年{calMonth.Month}月绩效数据已生成,请在{DateTime.Now.AddDays(4).ToString("yyyy年MM月dd日")}之前确认完成!</div></body></html>";
  94. string strTo = "luocaiyang@wispro-china.com";
  95. _ = QuartzUtil.AddMailJob(strSubject, strBody, staff.Name, strTo);
  96. }
  97. return Task.CompletedTask;
  98. }
  99. private void DownloadReport(string ReportName,CalMonth calMonth,bool isModifyDate,bool isFirstOA=false)
  100. {
  101. string strFileSavePath = utility.ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  102. wispro.sp.utility.IPEasyUtility.DownloadReport(ReportName, isModifyDate);
  103. System.Threading.Thread.Sleep(5000);
  104. string filename = $"{ReportName.Trim()}.xlsx";
  105. string strFilePath = System.IO.Path.Combine(strFileSavePath, filename);
  106. string strFinalPath = System.IO.Path.Combine(strFileSavePath, $"{calMonth.Year}{calMonth.Month}-{filename}");
  107. InputPerformanceItem(strFilePath, true, false, 1, calMonth, isFirstOA);
  108. System.IO.File.Move(strFilePath, strFinalPath);
  109. }
  110. private void NewMethod(string reportId,string filename, CalMonth calMonth,bool isFirstOA = false)
  111. {
  112. string strFileSavePath = utility.ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  113. wispro.sp.utility.IPEasyUtility.DownloadReport(reportId, filename);
  114. string strFilePath = System.IO.Path.Combine(strFileSavePath, filename);
  115. string strFinalPath = System.IO.Path.Combine(strFileSavePath, $"{calMonth.Year}{calMonth.Month}-{filename}");
  116. InputPerformanceItem(strFilePath, true, false, 1, calMonth,isFirstOA);
  117. System.IO.File.Move(strFilePath, strFinalPath);
  118. }
  119. private Task InputPerformanceItem(string strExcelFile, bool isColumnName, bool ignorHideRows = false, int ColumnNameRow = 0, CalMonth calMonth = null, bool isFirstOAFile = false)
  120. {
  121. DataTable dt = NPOIExcel.ExcelToDataTable(strExcelFile, isColumnName, ignorHideRows, ColumnNameRow);
  122. #region 删除重复行
  123. DataTable temdt = new DataTable();
  124. foreach (DataColumn col in dt.Columns)
  125. {
  126. DataColumn temCol = new DataColumn();
  127. temCol.ColumnName = col.ColumnName;
  128. temCol.DataType = col.DataType;
  129. temCol.Caption = col.Caption;
  130. temdt.Columns.Add(temCol);
  131. }
  132. new ExcelHelper().MerageDataTable(temdt, dt);
  133. #endregion
  134. List<BasePointRule> rules = spDb.BasePointRules.ToList<BasePointRule>();
  135. int iRow = 0;
  136. foreach (DataRow row in temdt.Rows)
  137. {
  138. string strDebug = $"{++iRow}\t{row["我方文号"]}";
  139. PerformanceItem item = null;
  140. if (isFirstOAFile)
  141. {
  142. item = Row2Item_1(row, calMonth);
  143. }
  144. else
  145. {
  146. item = Row2Item(row, calMonth);
  147. }
  148. if (item != null)
  149. {
  150. if (!InValidDoItem.Contains(item.DoItem))
  151. {
  152. SavePerformanceItem(item,rules);
  153. strDebug = $"{strDebug}\t保存成功";
  154. }
  155. else
  156. {
  157. strDebug = $"{strDebug}\t无效处理事项";
  158. }
  159. }
  160. else
  161. {
  162. strDebug = $"{strDebug}\t转换Item为Null";
  163. }
  164. System.Diagnostics.Debug.WriteLine(strDebug);
  165. }
  166. return Task.CompletedTask;
  167. }
  168. private Task SavePerformanceItem(PerformanceItem item,List<BasePointRule> rules)
  169. {
  170. try
  171. {
  172. Utility.Utility.CalBasePoint(item, rules);
  173. new Controllers.PerformanceItemController(spDb).New(item);
  174. }
  175. catch (Exception ex)
  176. {
  177. System.Diagnostics.Debug.WriteLine(ex.Message);
  178. }
  179. return Task.CompletedTask;
  180. }
  181. private PerformanceItem Row2Item_1(DataRow row, CalMonth calMonth)
  182. {
  183. PerformanceItem item = new PerformanceItem();
  184. item.ApplicationType = row["申请类型"].ToString().Trim();
  185. if (item.ApplicationType != "发明")
  186. {
  187. return null;
  188. }
  189. item.CaseNo = row["我方文号"].ToString().Trim();
  190. if (calMonth != null)
  191. {
  192. item.CalMonth = calMonth;
  193. }
  194. else
  195. {
  196. if (row.Table.Columns.Contains("绩效核算月份"))
  197. {
  198. string strjxyf = row["绩效核算月份"].ToString().Trim();
  199. string[] temYFs = strjxyf.Split(new char[] { '.' });
  200. item.CalMonth = new CalMonth();
  201. item.CalMonth.Year = int.Parse(temYFs[0]);
  202. item.CalMonth.Month = int.Parse(temYFs[1]);
  203. item.CalMonth.Status = 4;
  204. }
  205. else
  206. {
  207. item.CalMonth = new CalMonth();
  208. item.Status = 0;
  209. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  210. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  211. }
  212. }
  213. item.ApplicationType = row["申请类型"].ToString().Trim();
  214. item.BusinessType = "普通新申请"; // row["业务类型"].ToString().Trim();
  215. item.AgentFeedbackMemo = "发明一次OA授权"; //row["备注(填表注意事项)"].ToString().Trim();
  216. item.DoItem = "发明一次OA授权"; //row["处理事项"].ToString().Trim();
  217. string strHandler = "";
  218. if (row.Table.Columns.Contains("处理人"))
  219. {
  220. strHandler = row["处理人"].ToString().Trim();
  221. }
  222. else
  223. {
  224. if (row.Table.Columns.Contains("案件处理人"))
  225. {
  226. strHandler = row["案件处理人"].ToString().Trim();
  227. }
  228. }
  229. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  230. item.ItemStaffs = new List<ItemStaff>();
  231. foreach (string name in temHandlers)
  232. {
  233. ItemStaff itemStaff = new ItemStaff();
  234. int? iTem = GetStaff(name);
  235. if ((iTem != null))
  236. {
  237. //itemStaff.Item = item;
  238. itemStaff.DoPersonId = iTem.Value;
  239. item.ItemStaffs.Add(itemStaff);
  240. }
  241. else
  242. {
  243. itemStaff.DoPerson = new Staff()
  244. {
  245. Name = name,
  246. Account = name,
  247. Password = "12345678",
  248. IsCalPerformsnce = false,
  249. Status = "正式员工",
  250. StaffGradeId = 4
  251. };
  252. item.ItemStaffs.Add(itemStaff);
  253. }
  254. }
  255. if (item.ItemStaffs.Count == 0)
  256. {
  257. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  258. }
  259. if (row.Table.Columns.Contains("核稿人"))
  260. {
  261. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  262. }
  263. else
  264. {
  265. if (row.Table.Columns.Contains("案件核稿人"))
  266. {
  267. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  268. }
  269. }
  270. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  271. item.ApplicationName = row["申请人"].ToString().Trim();
  272. item.CaseName = row["案件名称"].ToString().Trim();
  273. //案件备注
  274. item.CaseMemo = $"发文日期:{row["发文日期"].ToString().Trim()}\r\n客户文号:{row["客户文号"].ToString().Trim()}\r\n上传日期:{row["上传日期"].ToString().Trim()}\r\n文件描述:{row["文件描述"].ToString().Trim()}";
  275. return item;
  276. }
  277. private PerformanceItem Row2Item(DataRow row, CalMonth calMonth)
  278. {
  279. PerformanceItem item = new PerformanceItem();
  280. item.CaseNo = row["我方文号"].ToString().Trim();
  281. if (calMonth != null)
  282. {
  283. item.CalMonth = calMonth;
  284. }
  285. else
  286. {
  287. if (row.Table.Columns.Contains("绩效核算月份"))
  288. {
  289. string strjxyf = row["绩效核算月份"].ToString().Trim();
  290. string[] temYFs = strjxyf.Split(new char[] { '.' });
  291. item.CalMonth = new CalMonth();
  292. item.CalMonth.Year = int.Parse(temYFs[0]);
  293. item.CalMonth.Month = int.Parse(temYFs[1]);
  294. item.CalMonth.Status = 4;
  295. }
  296. else
  297. {
  298. item.CalMonth = new CalMonth();
  299. item.Status = 0;
  300. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  301. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  302. }
  303. }
  304. item.ApplicationType = row["申请类型"].ToString().Trim();
  305. item.BusinessType = row["业务类型"].ToString().Trim();
  306. if (row.Table.Columns.Contains("备注(填表注意事项)"))
  307. item.AgentFeedbackMemo = row["备注(填表注意事项)"].ToString().Trim();
  308. item.DoItem = row["处理事项"].ToString().Trim();
  309. item.CaseStage = row["案件阶段"].ToString().Trim();
  310. item.CaseCoefficient = row["案件系数"].ToString().Trim();
  311. item.DoItemCoefficient = row["处理事项系数"].ToString().Trim();
  312. item.PreOastaffId = GetStaff(row["前一次OA处理人"].ToString().Trim());
  313. string strHandler = "";
  314. if (row.Table.Columns.Contains("处理人"))
  315. {
  316. strHandler = row["处理人"].ToString().Trim();
  317. }
  318. else
  319. {
  320. if (row.Table.Columns.Contains("案件处理人"))
  321. {
  322. strHandler = row["案件处理人"].ToString().Trim();
  323. }
  324. }
  325. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  326. item.ItemStaffs = new List<ItemStaff>();
  327. foreach (string name in temHandlers)
  328. {
  329. ItemStaff itemStaff = new ItemStaff();
  330. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  331. int? iTem = GetStaff(temName);
  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 = temName,
  343. Account = temName,
  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. if (!string.IsNullOrEmpty(row["核稿人"].ToString().Trim()))
  359. {
  360. string temName = row["核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  361. item.ReviewerId = GetStaff(temName);
  362. }
  363. }
  364. else
  365. {
  366. if (row.Table.Columns.Contains("案件核稿人"))
  367. {
  368. if (!string.IsNullOrEmpty(row["案件核稿人"].ToString().Trim()))
  369. {
  370. string temName = row["案件核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  371. item.ReviewerId = GetStaff(temName);
  372. }
  373. }
  374. }
  375. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  376. item.ApplicationName = row["申请人"].ToString().Trim();
  377. DateTime temDate = new DateTime();
  378. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  379. {
  380. item.FinishedDate = temDate;
  381. }
  382. //定稿日
  383. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  384. {
  385. item.FinalizationDate = temDate;
  386. }
  387. //返稿日
  388. if (DateTime.TryParse(row["返稿日"].ToString().Trim(), out temDate))
  389. {
  390. item.ReturnDate = temDate;
  391. }
  392. //案件类型
  393. item.CaseType = row["案件类型"].ToString().Trim();
  394. //案件状态
  395. item.CaseState = row["案件状态"].ToString().Trim();
  396. //处理事项备注
  397. item.DoItemMemo = row["处理事项备注"].ToString().Trim();
  398. //处理状态
  399. item.DoItemState = row["处理状态"].ToString().Trim();
  400. //案件名称
  401. item.CaseName = row["案件名称"].ToString().Trim();
  402. //委案日期
  403. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  404. {
  405. item.EntrustingDate = temDate;
  406. }
  407. //客户期限
  408. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  409. {
  410. item.CustomerLimitDate = temDate;
  411. }
  412. //内部期限
  413. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  414. {
  415. item.InternalDate = temDate;
  416. }
  417. //初稿日
  418. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  419. {
  420. item.FirstDraftDate = temDate;
  421. }
  422. //备注(发文严重超期是否属客观原因,若为否,请填写原因)
  423. if (row.Table.Columns.Contains("备注(发文严重超期是否属客观原因,若为否,请填写原因)"))
  424. {
  425. item.OverDueMemo = row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"].ToString().Trim();
  426. }
  427. //案件备注
  428. item.CaseMemo = row["案件备注"].ToString().Trim();
  429. return item;
  430. }
  431. private int? GetStaff(string v)
  432. {
  433. var staff = spDb.Staffs.Where<Staff>(s => s.Name == v).FirstOrDefault();
  434. if(staff != null)
  435. {
  436. return staff.Id;
  437. }
  438. return null;
  439. }
  440. }
  441. }