ImportReportJob.cs 19 KB

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