ImportReportJob.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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. }
  77. else
  78. {
  79. spDb.CalMonths.Add(calMonth);
  80. spDb.SaveChanges();
  81. }
  82. //每月绩效统计--发客户超过一个月未完成案件
  83. NewMethod("506aa7ad-c3f4-4ec6-9ec8-ff6b92dcd7c1", "每月绩效统计--发客户超过一个月未完成案件.xlsx", calMonth);
  84. //每月绩效统计--上个月递交完成案件
  85. NewMethod("d7308cd2-71e4-4444-9f47-f4d731ddb26a", "每月绩效统计--上个月递交完成案件.xlsx", calMonth);
  86. //每月绩效统计--中国一次OA授权表
  87. NewMethod("72454834-afdd-4b98-b42a-0bc912d07610", "每月绩效统计--中国一次OA授权表.xlsx", calMonth,true);
  88. return Task.CompletedTask;
  89. }
  90. private void NewMethod(string reportId,string filename, CalMonth calMonth,bool isFirstOA = false)
  91. {
  92. string strFileSavePath = utility.ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  93. wispro.sp.utility.IPEasyUtility.DownloadReport(reportId, filename);
  94. string strFilePath = System.IO.Path.Combine(strFileSavePath, filename);
  95. string strFinalPath = System.IO.Path.Combine(strFileSavePath, $"{calMonth.Year}{calMonth.Month}-{filename}");
  96. InputPerformanceItem(strFilePath, true, false, 1, calMonth,isFirstOA);
  97. System.IO.File.Move(strFilePath, strFinalPath);
  98. }
  99. private Task InputPerformanceItem(string strExcelFile, bool isColumnName, bool ignorHideRows = false, int ColumnNameRow = 0, CalMonth calMonth = null, bool isFirstOAFile = false)
  100. {
  101. DataTable dt = NPOIExcel.ExcelToDataTable(strExcelFile, isColumnName, ignorHideRows, ColumnNameRow);
  102. #region 删除重复行
  103. DataTable temdt = new DataTable();
  104. foreach (DataColumn col in dt.Columns)
  105. {
  106. DataColumn temCol = new DataColumn();
  107. temCol.ColumnName = col.ColumnName;
  108. temCol.DataType = col.DataType;
  109. temCol.Caption = col.Caption;
  110. temdt.Columns.Add(temCol);
  111. }
  112. new ExcelHelper().MerageDataTable(temdt, dt);
  113. #endregion
  114. List<BasePointRule> rules = spDb.BasePointRules.ToList<BasePointRule>();
  115. foreach (DataRow row in temdt.Rows)
  116. {
  117. PerformanceItem item = null;
  118. if (isFirstOAFile)
  119. {
  120. item = Row2Item_1(row, calMonth);
  121. }
  122. else
  123. {
  124. item = Row2Item(row, calMonth);
  125. }
  126. if (item != null)
  127. {
  128. if (!InValidDoItem.Contains(item.DoItem))
  129. {
  130. SavePerformanceItem(item,rules);
  131. }
  132. }
  133. }
  134. return Task.CompletedTask;
  135. }
  136. private Task SavePerformanceItem(PerformanceItem item,List<BasePointRule> rules)
  137. {
  138. try
  139. {
  140. #region 计算基本点数值及绩效类型
  141. rules.Sort((a, b) => {
  142. var o = b.Priority - a.Priority;
  143. return o;
  144. });
  145. Func<BasePointRule, PerformanceItem, double> pow = (x, y) => (y.WordCount == null) ? x.Point : (double)y.WordCount / 1000.00 * 0.18;
  146. foreach (BasePointRule rule in rules)
  147. {
  148. var interpreter = new Interpreter();
  149. //item.ApplicationType
  150. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(rule.Rule, "p");
  151. bool result = func.Invoke(item);
  152. if (result)
  153. {
  154. item.BasePoint = pow.Invoke(rule, item);
  155. item.Type = rule.Type;
  156. break;
  157. }
  158. }
  159. #endregion
  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. int? iTem = GetStaff(name);
  317. if ((iTem != null))
  318. {
  319. //itemStaff.Item = item;
  320. itemStaff.DoPersonId = iTem.Value;
  321. item.ItemStaffs.Add(itemStaff);
  322. }
  323. else
  324. {
  325. itemStaff.DoPerson = new Staff()
  326. {
  327. Name = name,
  328. Account = name,
  329. Password = "12345678",
  330. IsCalPerformsnce = false,
  331. Status = "已离职",
  332. StaffGradeId = 4
  333. };
  334. item.ItemStaffs.Add(itemStaff);
  335. }
  336. }
  337. if (item.ItemStaffs.Count == 0)
  338. {
  339. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  340. }
  341. if (row.Table.Columns.Contains("核稿人"))
  342. {
  343. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim());
  344. }
  345. else
  346. {
  347. if (row.Table.Columns.Contains("案件核稿人"))
  348. {
  349. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim());
  350. }
  351. }
  352. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  353. item.ApplicationName = row["申请人"].ToString().Trim();
  354. DateTime temDate = new DateTime();
  355. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  356. {
  357. item.FinishedDate = temDate;
  358. }
  359. //定稿日
  360. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  361. {
  362. item.FinalizationDate = temDate;
  363. }
  364. //返稿日
  365. if (DateTime.TryParse(row["返稿日"].ToString().Trim(), out temDate))
  366. {
  367. item.ReturnDate = temDate;
  368. }
  369. //案件类型
  370. item.CaseType = row["案件类型"].ToString().Trim();
  371. //案件状态
  372. item.CaseState = row["案件状态"].ToString().Trim();
  373. //处理事项备注
  374. item.DoItemMemo = row["处理事项备注"].ToString().Trim();
  375. //处理状态
  376. item.DoItemState = row["处理状态"].ToString().Trim();
  377. //案件名称
  378. item.CaseName = row["案件名称"].ToString().Trim();
  379. //委案日期
  380. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  381. {
  382. item.EntrustingDate = temDate;
  383. }
  384. //客户期限
  385. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  386. {
  387. item.CustomerLimitDate = temDate;
  388. }
  389. //内部期限
  390. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  391. {
  392. item.InternalDate = temDate;
  393. }
  394. //初稿日
  395. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  396. {
  397. item.FirstDraftDate = temDate;
  398. }
  399. //备注(发文严重超期是否属客观原因,若为否,请填写原因)
  400. if (row.Table.Columns.Contains("备注(发文严重超期是否属客观原因,若为否,请填写原因)"))
  401. {
  402. item.OverDueMemo = row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"].ToString().Trim();
  403. }
  404. //案件备注
  405. item.CaseMemo = row["案件备注"].ToString().Trim();
  406. return item;
  407. }
  408. private int? GetStaff(string v)
  409. {
  410. var staff = spDb.Staffs.Where<Staff>(s => s.Name == v).FirstOrDefault();
  411. if(staff != null)
  412. {
  413. return staff.Id;
  414. }
  415. return null;
  416. }
  417. }
  418. }