ImportReportJob.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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. #region 计算基本点数值及绩效类型
  160. rules.Sort((a, b) => {
  161. var o = b.Priority - a.Priority;
  162. return o;
  163. });
  164. Func<BasePointRule, PerformanceItem, double> pow = (x, y) => (y.WordCount == null) ? x.Point : (double)y.WordCount / 1000.00 * 0.18;
  165. foreach (BasePointRule rule in rules)
  166. {
  167. var interpreter = new Interpreter();
  168. //item.ApplicationType
  169. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(rule.Rule, "p");
  170. bool result = func.Invoke(item);
  171. if (result)
  172. {
  173. item.BasePoint = pow.Invoke(rule, item);
  174. item.Type = rule.Type;
  175. break;
  176. }
  177. }
  178. #endregion
  179. new Controllers.PerformanceItemController(spDb).New(item);
  180. }
  181. catch(Exception ex)
  182. {
  183. }
  184. return Task.CompletedTask;
  185. }
  186. private PerformanceItem Row2Item_1(DataRow row, CalMonth calMonth)
  187. {
  188. PerformanceItem item = new PerformanceItem();
  189. item.ApplicationType = row["申请类型"].ToString().Trim();
  190. if (item.ApplicationType != "发明")
  191. {
  192. return null;
  193. }
  194. item.CaseNo = row["我方文号"].ToString().Trim();
  195. if (calMonth != null)
  196. {
  197. item.CalMonth = calMonth;
  198. }
  199. else
  200. {
  201. if (row.Table.Columns.Contains("绩效核算月份"))
  202. {
  203. string strjxyf = row["绩效核算月份"].ToString().Trim();
  204. string[] temYFs = strjxyf.Split(new char[] { '.' });
  205. item.CalMonth = new CalMonth();
  206. item.CalMonth.Year = int.Parse(temYFs[0]);
  207. item.CalMonth.Month = int.Parse(temYFs[1]);
  208. item.CalMonth.Status = 4;
  209. }
  210. else
  211. {
  212. item.CalMonth = new CalMonth();
  213. item.Status = 0;
  214. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  215. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  216. }
  217. }
  218. item.ApplicationType = row["申请类型"].ToString().Trim();
  219. item.BusinessType = "普通新申请"; // row["业务类型"].ToString().Trim();
  220. item.AgentFeedbackMemo = "发明一次OA授权"; //row["备注(填表注意事项)"].ToString().Trim();
  221. item.DoItem = "发明一次OA授权"; //row["处理事项"].ToString().Trim();
  222. string strHandler = "";
  223. if (row.Table.Columns.Contains("处理人"))
  224. {
  225. strHandler = row["处理人"].ToString().Trim();
  226. }
  227. else
  228. {
  229. if (row.Table.Columns.Contains("案件处理人"))
  230. {
  231. strHandler = row["案件处理人"].ToString().Trim();
  232. }
  233. }
  234. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  235. item.ItemStaffs = new List<ItemStaff>();
  236. foreach (string name in temHandlers)
  237. {
  238. ItemStaff itemStaff = new ItemStaff();
  239. int? iTem = GetStaff(name);
  240. if ((iTem != null))
  241. {
  242. //itemStaff.Item = item;
  243. itemStaff.DoPersonId = iTem.Value;
  244. item.ItemStaffs.Add(itemStaff);
  245. }
  246. else
  247. {
  248. itemStaff.DoPerson = new Staff()
  249. {
  250. Name = name,
  251. Account = name,
  252. Password = "12345678",
  253. IsCalPerformsnce = false,
  254. Status = "正式员工",
  255. StaffGradeId = 4
  256. };
  257. item.ItemStaffs.Add(itemStaff);
  258. }
  259. }
  260. if (item.ItemStaffs.Count == 0)
  261. {
  262. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  263. }
  264. if (row.Table.Columns.Contains("核稿人"))
  265. {
  266. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  267. }
  268. else
  269. {
  270. if (row.Table.Columns.Contains("案件核稿人"))
  271. {
  272. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  273. }
  274. }
  275. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  276. item.ApplicationName = row["申请人"].ToString().Trim();
  277. item.CaseName = row["案件名称"].ToString().Trim();
  278. //案件备注
  279. item.CaseMemo = $"发文日期:{row["发文日期"].ToString().Trim()}\r\n客户文号:{row["客户文号"].ToString().Trim()}\r\n上传日期:{row["上传日期"].ToString().Trim()}\r\n文件描述:{row["文件描述"].ToString().Trim()}";
  280. return item;
  281. }
  282. private PerformanceItem Row2Item(DataRow row, CalMonth calMonth)
  283. {
  284. PerformanceItem item = new PerformanceItem();
  285. item.CaseNo = row["我方文号"].ToString().Trim();
  286. if (calMonth != null)
  287. {
  288. item.CalMonth = calMonth;
  289. }
  290. else
  291. {
  292. if (row.Table.Columns.Contains("绩效核算月份"))
  293. {
  294. string strjxyf = row["绩效核算月份"].ToString().Trim();
  295. string[] temYFs = strjxyf.Split(new char[] { '.' });
  296. item.CalMonth = new CalMonth();
  297. item.CalMonth.Year = int.Parse(temYFs[0]);
  298. item.CalMonth.Month = int.Parse(temYFs[1]);
  299. item.CalMonth.Status = 4;
  300. }
  301. else
  302. {
  303. item.CalMonth = new CalMonth();
  304. item.Status = 0;
  305. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  306. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  307. }
  308. }
  309. item.ApplicationType = row["申请类型"].ToString().Trim();
  310. item.BusinessType = row["业务类型"].ToString().Trim();
  311. if (row.Table.Columns.Contains("备注(填表注意事项)"))
  312. item.AgentFeedbackMemo = row["备注(填表注意事项)"].ToString().Trim();
  313. item.DoItem = row["处理事项"].ToString().Trim();
  314. item.CaseStage = row["案件阶段"].ToString().Trim();
  315. item.CaseCoefficient = row["案件系数"].ToString().Trim();
  316. item.DoItemCoefficient = row["处理事项系数"].ToString().Trim();
  317. item.PreOastaffId = GetStaff(row["前一次OA处理人"].ToString().Trim());
  318. string strHandler = "";
  319. if (row.Table.Columns.Contains("处理人"))
  320. {
  321. strHandler = row["处理人"].ToString().Trim();
  322. }
  323. else
  324. {
  325. if (row.Table.Columns.Contains("案件处理人"))
  326. {
  327. strHandler = row["案件处理人"].ToString().Trim();
  328. }
  329. }
  330. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  331. item.ItemStaffs = new List<ItemStaff>();
  332. foreach (string name in temHandlers)
  333. {
  334. ItemStaff itemStaff = new ItemStaff();
  335. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  336. int? iTem = GetStaff(temName);
  337. if ((iTem != null))
  338. {
  339. //itemStaff.Item = item;
  340. itemStaff.DoPersonId = iTem.Value;
  341. item.ItemStaffs.Add(itemStaff);
  342. }
  343. else
  344. {
  345. itemStaff.DoPerson = new Staff()
  346. {
  347. Name = temName,
  348. Account = temName,
  349. Password = "12345678",
  350. IsCalPerformsnce = false,
  351. Status = "已离职",
  352. StaffGradeId = 4
  353. };
  354. item.ItemStaffs.Add(itemStaff);
  355. }
  356. }
  357. if (item.ItemStaffs.Count == 0)
  358. {
  359. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  360. }
  361. if (row.Table.Columns.Contains("核稿人"))
  362. {
  363. if (!string.IsNullOrEmpty(row["核稿人"].ToString().Trim()))
  364. {
  365. string temName = row["核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  366. item.ReviewerId = GetStaff(temName);
  367. }
  368. }
  369. else
  370. {
  371. if (row.Table.Columns.Contains("案件核稿人"))
  372. {
  373. if (!string.IsNullOrEmpty(row["案件核稿人"].ToString().Trim()))
  374. {
  375. string temName = row["案件核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  376. item.ReviewerId = GetStaff(temName);
  377. }
  378. }
  379. }
  380. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  381. item.ApplicationName = row["申请人"].ToString().Trim();
  382. DateTime temDate = new DateTime();
  383. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  384. {
  385. item.FinishedDate = temDate;
  386. }
  387. //定稿日
  388. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  389. {
  390. item.FinalizationDate = temDate;
  391. }
  392. //返稿日
  393. if (DateTime.TryParse(row["返稿日"].ToString().Trim(), out temDate))
  394. {
  395. item.ReturnDate = temDate;
  396. }
  397. //案件类型
  398. item.CaseType = row["案件类型"].ToString().Trim();
  399. //案件状态
  400. item.CaseState = row["案件状态"].ToString().Trim();
  401. //处理事项备注
  402. item.DoItemMemo = row["处理事项备注"].ToString().Trim();
  403. //处理状态
  404. item.DoItemState = row["处理状态"].ToString().Trim();
  405. //案件名称
  406. item.CaseName = row["案件名称"].ToString().Trim();
  407. //委案日期
  408. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  409. {
  410. item.EntrustingDate = temDate;
  411. }
  412. //客户期限
  413. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  414. {
  415. item.CustomerLimitDate = temDate;
  416. }
  417. //内部期限
  418. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  419. {
  420. item.InternalDate = temDate;
  421. }
  422. //初稿日
  423. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  424. {
  425. item.FirstDraftDate = temDate;
  426. }
  427. //备注(发文严重超期是否属客观原因,若为否,请填写原因)
  428. if (row.Table.Columns.Contains("备注(发文严重超期是否属客观原因,若为否,请填写原因)"))
  429. {
  430. item.OverDueMemo = row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"].ToString().Trim();
  431. }
  432. //案件备注
  433. item.CaseMemo = row["案件备注"].ToString().Trim();
  434. return item;
  435. }
  436. private int? GetStaff(string v)
  437. {
  438. var staff = spDb.Staffs.Where<Staff>(s => s.Name == v).FirstOrDefault();
  439. if(staff != null)
  440. {
  441. return staff.Id;
  442. }
  443. return null;
  444. }
  445. }
  446. }