ImportReportJob.cs 20 KB

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