Form1.cs 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. using DynamicExpresso;
  2. using Microsoft.International.Converters.PinYinConverter;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Configuration;
  7. using System.Data;
  8. using System.Diagnostics;
  9. using System.Drawing;
  10. using System.Drawing.Imaging;
  11. using System.Dynamic;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Net.Http;
  15. using System.Net.Http.Json;
  16. using System.Text;
  17. using System.Text.Json;
  18. using System.Threading.Tasks;
  19. using System.Windows.Forms;
  20. using wispro.sp.entity;
  21. using wispro.sp.entity.workflowDefine;
  22. using wispro.sp.share;
  23. using wispro.sp.share.Utility;
  24. using wispro.sp.share.webViewObject;
  25. using wispro.sp.utility;
  26. namespace wispro.sp.winClient
  27. {
  28. public partial class Form1 : Form
  29. {
  30. public Form1()
  31. {
  32. InitializeComponent();
  33. }
  34. private void button1_Click(object sender, EventArgs e)
  35. {
  36. DateTime startTime = DateTime.Now;
  37. frmMerageExcel frm = new frmMerageExcel();
  38. if (frm.ShowDialog() == DialogResult.OK)
  39. {
  40. MessageBox.Show($"合并完成,合并后文件保存在:\r\n{frm.SaveFilePath}\r\n用时:{DateTime.Now - startTime }");
  41. }
  42. }
  43. private void button2_Click(object sender, EventArgs e)
  44. {
  45. OpenFileDialog ofd = new OpenFileDialog()
  46. {
  47. Multiselect = false,
  48. Filter = "*.xls|*.xlsx"
  49. };
  50. string strDinashuRegularFile = ConfigurationSettings.AppSettings["DinashuRegularFile"];
  51. if (ofd.ShowDialog() == DialogResult.OK)
  52. {
  53. new ExcelHelper().FillDianShu(ofd.FileName, strDinashuRegularFile);
  54. }
  55. MessageBox.Show("完成点数输入!");
  56. }
  57. private string[] InValidDoItem = new string[]
  58. {
  59. "案件异常-催缴年费",
  60. "案件异常-视为放弃取得专利权",
  61. "办理登记手续",
  62. "办理登记手续-确认客户是否委托",
  63. "代理所变更",
  64. "绘图",
  65. "技术确认",
  66. "缴年费",
  67. "请求保密审查",
  68. "请求费减",
  69. "请求实审",
  70. "取得申请号",
  71. "取得证书",
  72. "取得专利权评价报告",
  73. "确认官方审查状况",
  74. "询问放弃或复审",
  75. "知识点总结",
  76. "专利权人发明人申请人信息变更",
  77. "专利挖掘与布局",
  78. "我方文号前缀带J",
  79. "开卷",
  80. "请求提前公开",
  81. "取得国际检索报告",
  82. "委外检索",
  83. "中止程序",
  84. "终止",
  85. "案件异常-视为撤回",
  86. "进入国家阶段提醒",
  87. "请求恢复权利",
  88. "请求优先权",
  89. "取得【无效宣告请求审查决定】",
  90. "撤回",
  91. "请求退款",
  92. "确认是否委托申请与类型",
  93. "专利交易",
  94. "专利权评价报告",
  95. "专利权人发明人申请人信息变更+代理所变更"
  96. };
  97. private async Task InitRules(bool isSave)
  98. {
  99. List<BasePointRule> rules = new List<BasePointRule>();
  100. DataTable dt = wispro.sp.utility.NPOIExcel.ExcelToDataTable("ExcelFiles\\20211109-绩效点数规则-lcy-v1.xlsx", true);
  101. PerformanceItem item = new PerformanceItem() { CaseNo = "PAEPO2016277", DoItem= "提交检索主题声明", };
  102. foreach(DataRow row in dt.Rows)
  103. {
  104. BasePointRule rule = new BasePointRule()
  105. {
  106. Rule = row["规则"].ToString(),
  107. PointExpress = row["点数计算"].ToString(),
  108. Priority = int.Parse(row["优先级修订"].ToString()),
  109. Type = row["类型"].ToString()
  110. };
  111. try
  112. {
  113. var interpreter = new Interpreter();
  114. //item.ApplicationType
  115. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(rule.Rule, "p");
  116. bool result = func.Invoke(item);
  117. if (result)
  118. {
  119. item.BasePoint = (double?)interpreter.Eval(rule.PointExpress);
  120. item.Type = rule.Type;
  121. System.Diagnostics.Debug.WriteLine("");
  122. }
  123. rules.Add(rule);
  124. }
  125. catch(Exception ex)
  126. {
  127. System.Diagnostics.Debug.WriteLine(rule.Rule + "\r\n" + ex.ToString());
  128. }
  129. }
  130. if (isSave)
  131. {
  132. foreach (BasePointRule rule in rules)
  133. {
  134. double d;
  135. if(double.TryParse(rule.PointExpress,out d))
  136. {
  137. rule.PointExpress = d.ToString("0.00");
  138. }
  139. await SaveBasePointRule(rule);
  140. }
  141. }
  142. }
  143. public async Task TestQueryFilter()
  144. {
  145. //QueryFilter filter = new QueryFilter();
  146. //filter.ConditionTree = new ExpressTree();
  147. //string ValueType = typeof(PerformanceItem).GetProperty("CaseNo").PropertyType.ToString();
  148. //FieldCondition condition1 = new FieldCondition() { FieldName = "CaseNo", Operator = OperatorEnum.Contains, Value = "PACN", ValueType = ValueType };
  149. //FieldCondition condition2 = new FieldCondition() { FieldName = "CaseNo", Operator = OperatorEnum.Contains, Value = "PAUS", ValueType = ValueType };
  150. //filter.ConditionTree.AddCondition(LogicEnum.And,condition1);
  151. //filter.ConditionTree.AddCondition(LogicEnum.Or, condition2);
  152. //System.Diagnostics.Debug.WriteLine(filter.ConditionTree.ToExpressString("s")); ;
  153. }
  154. enum enumTest
  155. {
  156. [Description("男")]
  157. man,
  158. [Description("女")]
  159. woman
  160. }
  161. private async void button3_Click(object sender, EventArgs e)
  162. {
  163. await GetTest();
  164. //await Compare2DB();
  165. //await RefreshPerformanceItem(1);
  166. //await RefreshPerformanceItem(2);
  167. //await RefreshPerformanceItem(3);
  168. //await UserField2String(lstAJQL);
  169. //await UserField2String(lstAJXS);
  170. //await UserField2String(lstDoItemXS);
  171. //await UserField2String(lstJXBL);
  172. //await UserField2String(lstRXSX);
  173. //await UserField2String(lstYZCQ);
  174. //await ImportUsers();
  175. //await InputPerformanceItem("c:\\temp\\21.01-21.11 工程师绩效报表-总表.xlsx", true, false, 0);
  176. }
  177. private PerformanceItem Row2Item_1(DataRow row, List<Staff> Staffs, CalMonth calMonth)
  178. {
  179. PerformanceItem item = new PerformanceItem();
  180. item.ApplicationType = row["申请类型"].ToString().Trim();
  181. if(item.ApplicationType != "发明")
  182. {
  183. return null;
  184. }
  185. item.CaseNo = row["我方文号"].ToString().Trim();
  186. if (calMonth != null)
  187. {
  188. item.CalMonth = calMonth;
  189. }
  190. else
  191. {
  192. if (row.Table.Columns.Contains("绩效核算月份"))
  193. {
  194. string strjxyf = row["绩效核算月份"].ToString().Trim();
  195. string[] temYFs = strjxyf.Split(new char[] { '.' });
  196. item.CalMonth = new CalMonth();
  197. item.CalMonth.Year = int.Parse(temYFs[0]);
  198. item.CalMonth.Month = int.Parse(temYFs[1]);
  199. item.CalMonth.Status = 4;
  200. }
  201. else
  202. {
  203. item.CalMonth = new CalMonth();
  204. item.Status = 0;
  205. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  206. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  207. }
  208. }
  209. item.ApplicationType = row["申请类型"].ToString().Trim();
  210. item.BusinessType = "普通新申请"; // row["业务类型"].ToString().Trim();
  211. item.AgentFeedbackMemo = "发明一次OA授权"; //row["备注(填表注意事项)"].ToString().Trim();
  212. item.DoItem = "发明一次OA授权"; //row["处理事项"].ToString().Trim();
  213. string strHandler = "";
  214. if (row.Table.Columns.Contains("处理人"))
  215. {
  216. strHandler = row["处理人"].ToString().Trim();
  217. }
  218. else
  219. {
  220. if (row.Table.Columns.Contains("案件处理人"))
  221. {
  222. strHandler = row["案件处理人"].ToString().Trim();
  223. }
  224. }
  225. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  226. item.ItemStaffs = new List<ItemStaff>();
  227. foreach (string name in temHandlers)
  228. {
  229. ItemStaff itemStaff = new ItemStaff();
  230. int? iTem = GetStaff(name, Staffs);
  231. if ((iTem != null))
  232. {
  233. //itemStaff.Item = item;
  234. itemStaff.DoPersonId = iTem.Value;
  235. item.ItemStaffs.Add(itemStaff);
  236. }
  237. else
  238. {
  239. itemStaff.DoPerson = new Staff()
  240. {
  241. Name = name,
  242. Account = name,
  243. Password = "12345678",
  244. IsCalPerformsnce = false,
  245. Status = "正式员工",
  246. StaffGradeId = 4
  247. };
  248. item.ItemStaffs.Add(itemStaff);
  249. }
  250. }
  251. if (item.ItemStaffs.Count == 0)
  252. {
  253. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  254. }
  255. if (row.Table.Columns.Contains("核稿人"))
  256. {
  257. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim(), Staffs);
  258. }
  259. else
  260. {
  261. if (row.Table.Columns.Contains("案件核稿人"))
  262. {
  263. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim(), Staffs);
  264. }
  265. }
  266. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  267. item.ApplicationName = row["申请人"].ToString().Trim();
  268. item.CaseName = row["案件名称"].ToString().Trim();
  269. //案件备注
  270. item.CaseMemo = $"发文日期:{row["发文日期"].ToString().Trim()}\r\n客户文号:{row["客户文号"].ToString().Trim()}\r\n上传日期:{row["上传日期"].ToString().Trim()}\r\n文件描述:{row["文件描述"].ToString().Trim()}";
  271. return item;
  272. }
  273. private PerformanceItem Row2Item(DataRow row, List<Staff> Staffs,CalMonth calMonth)
  274. {
  275. PerformanceItem item = new PerformanceItem();
  276. item.CaseNo = row["我方文号"].ToString().Trim();
  277. if (calMonth != null)
  278. {
  279. item.CalMonth = calMonth;
  280. }
  281. else
  282. {
  283. if (row.Table.Columns.Contains("绩效核算月份"))
  284. {
  285. string strjxyf = row["绩效核算月份"].ToString().Trim();
  286. string[] temYFs = strjxyf.Split(new char[] { '.' });
  287. item.CalMonth = new CalMonth();
  288. item.CalMonth.Year = int.Parse(temYFs[0]);
  289. if (temYFs[1] == "1")
  290. {
  291. temYFs[1] = "10";
  292. }
  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(), Staffs);
  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, Staffs);
  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.Trim(), Staffs);
  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.Trim(), Staffs);
  372. }
  373. }
  374. }
  375. if (!string.IsNullOrEmpty(row["点数"].ToString().Trim())) {
  376. item.BasePoint = double.Parse(row["点数"].ToString().Trim());
  377. }
  378. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  379. item.ApplicationName = row["申请人"].ToString().Trim();
  380. DateTime temDate = new DateTime();
  381. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  382. {
  383. item.FinishedDate = temDate;
  384. }
  385. //定稿日
  386. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  387. {
  388. item.FinalizationDate = temDate;
  389. }
  390. //返稿日
  391. if (DateTime.TryParse(row["返稿日"].ToString().Trim(), out temDate))
  392. {
  393. item.ReturnDate = temDate;
  394. }
  395. //案件类型
  396. item.CaseType = row["案件类型"].ToString().Trim();
  397. //案件状态
  398. item.CaseState = row["案件状态"].ToString().Trim();
  399. //处理事项备注
  400. item.DoItemMemo = row["处理事项备注"].ToString().Trim();
  401. //处理状态
  402. item.DoItemState = row["处理状态"].ToString().Trim();
  403. //案件名称
  404. item.CaseName = row["案件名称"].ToString().Trim();
  405. //委案日期
  406. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  407. {
  408. item.EntrustingDate = temDate;
  409. }
  410. //客户期限
  411. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  412. {
  413. item.CustomerLimitDate = temDate;
  414. }
  415. //内部期限
  416. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  417. {
  418. item.InternalDate = temDate;
  419. }
  420. //初稿日
  421. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  422. {
  423. item.FirstDraftDate = temDate;
  424. }
  425. //备注(发文严重超期是否属客观原因,若为否,请填写原因)
  426. if (row.Table.Columns.Contains("备注(发文严重超期是否属客观原因,若为否,请填写原因)"))
  427. {
  428. item.OverDueMemo = row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"].ToString().Trim();
  429. }
  430. //案件备注
  431. item.CaseMemo = row["案件备注"].ToString().Trim();
  432. return item;
  433. }
  434. private async Task InputPerformanceItem(string strExcelFile,bool isColumnName,bool ignorHideRows=false,int ColumnNameRow=0,CalMonth calMonth=null,bool isFirstOAFile=false)
  435. {
  436. DataTable dt = NPOIExcel.ExcelToDataTable(strExcelFile, isColumnName,ignorHideRows,ColumnNameRow);
  437. #region 删除重复行
  438. DataTable temdt = new DataTable();
  439. foreach (DataColumn col in dt.Columns)
  440. {
  441. DataColumn temCol = new DataColumn();
  442. temCol.ColumnName = col.ColumnName;
  443. temCol.DataType = col.DataType;
  444. temCol.Caption = col.Caption;
  445. temdt.Columns.Add(temCol);
  446. }
  447. new ExcelHelper().MerageDataTable(temdt, dt);
  448. #endregion
  449. List<Staff> Staffs =await GetStaffsAsync();
  450. foreach(DataRow row in temdt.Rows)
  451. {
  452. PerformanceItem item = null;
  453. if (isFirstOAFile)
  454. {
  455. item = Row2Item_1(row, Staffs, calMonth);
  456. }
  457. else
  458. {
  459. item = Row2Item(row, Staffs, calMonth);
  460. }
  461. if (item != null )
  462. {
  463. System.Diagnostics.Debug.WriteLine($"{DateTime.Now}\t{item.CaseNo}\t{item.CaseName}");
  464. if (!InValidDoItem.Contains(item.DoItem))
  465. {
  466. await SavePerformanceItem(item);
  467. }
  468. }
  469. }
  470. }
  471. private async Task Compare2DB()
  472. {
  473. if (Token == null)
  474. {
  475. await Login();
  476. }
  477. HttpClient http = CreateHttp();
  478. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  479. var data = await http.GetFromJsonAsync<PerformanceItem>($"{strAPIBaseUri}/api/PerformanceItem/CompareExcel2DB");
  480. //await GetDoItemInfo("PACN2027395", "处理审查意见", "一通");
  481. }
  482. private async Task RefreshPerformanceItem(int Type)
  483. {
  484. if (Token == null)
  485. {
  486. await Login();
  487. }
  488. await RefreshItemAsync(Type);
  489. //await GetDoItemInfo("PACN2027395", "处理审查意见", "一通");
  490. }
  491. List<string> lstJXBL = new List<string>() {
  492. "柳芳","杨超","何倚雯","李姣","张庆玲","李建民","李申","李莉","刘桂兰"
  493. ,"唐双","瞿璨","张鹏","钟锦光","翁旋艺","钟子敏"
  494. };
  495. List<string> lstAJXS = new List<string>() {
  496. "柳芳","杨超","何倚雯","李姣","张庆玲","李建民","李申","李莉","刘桂兰"
  497. ,"唐双","瞿璨","张鹏","钟锦光","翁旋艺","钟子敏","邢丽霞",
  498. "李庆波","黄瑜","程利","黎坚怡","舒丽亚","管自英","张晓薇","刘希"
  499. };
  500. List<string> lstDoItemXS = new List<string>() {
  501. "吴继红","赖玲玲","郭竟微","陈鹤","王本鼎","高凌云","周煜祥","何丹风",
  502. "田婵玉","孙心洁","陈舒敏","邢丽霞"
  503. };
  504. List<string> lstAJQL = new List<string>() {
  505. "柳芳","杨超","何倚雯","李姣","张庆玲","李建民","李申","李莉","刘桂兰"
  506. ,"唐双","瞿璨","张鹏","钟锦光","翁旋艺","吴继红","赖玲玲","郭竟微","陈鹤",
  507. "王本鼎","高凌云","周煜祥","何丹风","田婵玉","孙心洁","陈舒敏","钟子敏",
  508. "李庆波","黄瑜","程利","黎坚怡","舒丽亚","管自英","张晓薇","刘希"
  509. };
  510. List<string> lstYZCQ = new List<string>() {
  511. "吴继红","赖玲玲","郭竟微","陈鹤","王本鼎","高凌云","周煜祥","何丹风",
  512. "田婵玉","孙心洁","陈舒敏"
  513. };
  514. List<string> lstRXSX = new List<string>() {
  515. "夏敏","柳芳","杨超","何倚雯","李姣","张庆玲","李建民","李申","李莉","刘桂兰"
  516. ,"唐双","瞿璨","张鹏","钟锦光","翁旋艺","钟子敏","李庆波","黄瑜","程利",
  517. "黎坚怡","舒丽亚","管自英","张晓薇","刘希"
  518. };
  519. private async Task UserField2String(List<string> lstList)
  520. {
  521. if (Token == null)
  522. {
  523. await Login();
  524. }
  525. //List<Staff> Reviewers = await getReviewers(14232, 1);
  526. //Reviewers = await getReviewers(14232, 5);
  527. List<Staff> Staffs = await GetStaffsAsync();
  528. List<UserField> lstUsers = new List<UserField>();
  529. foreach(var name in lstList)
  530. {
  531. lstUsers.Add(new UserField()
  532. {
  533. UserConditionType = UserConditionType.Staff,
  534. UserType = UserType.Staff,
  535. UserValue = GetStaff(name, Staffs).ToString()
  536. });
  537. }
  538. JsonSerializerOptions options = new() { IgnoreNullValues = true };
  539. var strJson = System.Text.Json.JsonSerializer.Serialize(lstUsers, lstUsers.GetType(), options);
  540. System.Diagnostics.Debug.WriteLine(strJson);
  541. }
  542. private int? GetStaff(string v, List<Staff> staffs)
  543. {
  544. if (!string.IsNullOrEmpty(v))
  545. {
  546. string[] temNames = v.Trim().Split(new char[] { '-' },StringSplitOptions.RemoveEmptyEntries);
  547. foreach (Staff sf in staffs)
  548. {
  549. if(sf.Name == temNames[0])
  550. {
  551. return sf.Id;
  552. }
  553. }
  554. }
  555. return null;
  556. }
  557. private async Task ImportUsers()
  558. {
  559. OpenFileDialog ofd = new OpenFileDialog();
  560. if (ofd.ShowDialog() == DialogResult.OK)
  561. {
  562. string fileName = ofd.FileName;
  563. DataTable dt = NPOIExcel.ExcelToDataTable(fileName, true, false, 1);
  564. if(Token == null)
  565. {
  566. await Login();
  567. }
  568. List<StaffGrade> staffGrades = await GetStaffGrades();
  569. foreach (DataRow row in dt.Rows)
  570. {
  571. Staff staff = new Staff();
  572. staff.Account = row["用户名"].ToString().Trim();
  573. staff.Name = row["姓名"].ToString().Trim();
  574. staff.Tel = row["电话号码"].ToString().Trim();
  575. staff.Mobile = row["手机号码"].ToString().Trim();
  576. staff.Sex = row["性别"].ToString().Trim();
  577. staff.Mail = row["邮箱"].ToString().Trim();
  578. string strGrade = row["工程师等级"].ToString().Trim(); // + "级";
  579. foreach (StaffGrade sg in staffGrades)
  580. {
  581. if (strGrade.Trim() == sg.Grade.Trim())
  582. {
  583. staff.StaffGradeId = sg.Id;
  584. break;
  585. }
  586. }
  587. staff.IsOnJob = (row["是否在职"].ToString().Trim() == "是");
  588. staff.Status = row["岗位状态"].ToString().Trim();
  589. staff.Department = row["部门"].ToString();
  590. staff.WorkPlace = row["工作地"].ToString();
  591. DateTime temDate;
  592. if (DateTime.TryParse(row["入职时间"].ToString(), out temDate))
  593. {
  594. staff.EntyDate = temDate;
  595. }
  596. var temStaff = await GetStaff(staff.Name);
  597. bool isSaved = false;
  598. if (temStaff == null)
  599. {
  600. isSaved = true;
  601. staff.Password = MD5Utility.GetMD5("12345678");
  602. }
  603. else
  604. {
  605. staff.Id = temStaff.Id;
  606. staff.Password = temStaff.Password;
  607. isSaved =
  608. (staff.Name != temStaff.Name) ||
  609. (staff.Account != temStaff.Account) ||
  610. (staff.Department != temStaff.Department) ||
  611. (staff.EntyDate != temStaff.EntyDate) ||
  612. (staff.IsOnJob != temStaff.IsOnJob) ||
  613. (staff.Mail != temStaff.Mail) ||
  614. (staff.Mobile != temStaff.Mobile) ||
  615. (staff.Sex != temStaff.Sex) ||
  616. (staff.Status != temStaff.Status) ||
  617. (staff.Tel != temStaff.Tel) ||
  618. (staff.WorkPlace != temStaff.WorkPlace) ||
  619. (staff.StaffGradeId != temStaff.StaffGradeId);
  620. }
  621. if (isSaved)
  622. {
  623. //staff.IsCalPerformsnce = (row["是否核算绩效"].ToString() == "是");
  624. //staff.Memo = row["备注"].ToString().Trim();
  625. //staff.StaffGradeId = row["姓名"].ToString();
  626. await SaveStaff(staff);
  627. }
  628. }
  629. }
  630. }
  631. private string getPinYin(string str)
  632. {
  633. string retStr = "";
  634. for(int i = 0; i < str.Length; i++)
  635. {
  636. ChineseChar cc = new ChineseChar(str[i]);
  637. retStr = retStr + cc.Pinyins[0].ToLower().Replace("1","")
  638. .Replace("2", "").Replace("3", "").Replace("4", "");
  639. }
  640. return retStr;
  641. }
  642. string strAPIBaseUri = "http://localhost:39476";// "https://47.106.221.167"; //
  643. userToken Token;
  644. public async Task GetTest()
  645. {
  646. await Login();
  647. string strUrl = $"{strAPIBaseUri}/api/PerformanceItem/CurrentData2Excel";
  648. HttpClient http = CreateHttp();
  649. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  650. var response = await http.GetFromJsonAsync<FileProcessTask>(strUrl);
  651. while (!response.Finished)
  652. {
  653. response = await http.GetFromJsonAsync<FileProcessTask>($"{strAPIBaseUri}/api/FileProcesTask/Get?Id={response.Id}");
  654. System.Diagnostics.Debug.WriteLine($"{response.Processed}/{response.Size}");
  655. System.Threading.Thread.Sleep(2000);
  656. }
  657. byte[] data = await http.GetByteArrayAsync($"{strAPIBaseUri}/api/FileProcesTask/Download?Id={response.Id}");
  658. using (var file = System.IO.File.Create(response.FilePath))
  659. {
  660. file.Write(data, 0, data.Length);
  661. }
  662. #region aaa
  663. //DataTable dt = utility.NPOIExcel.ExcelToDataTable("C:\\temp\\userList.xlsx", true, false, 0);
  664. //foreach (DataRow row in dt.Rows)
  665. //{
  666. // string strAccount = row["Account"].ToString();
  667. // System.Diagnostics.Debug.WriteLine(strAccount);
  668. // string strStatus = row["Status"].ToString();
  669. // if (string.IsNullOrEmpty(strStatus))
  670. // {
  671. // strStatus = "未知";
  672. // }
  673. // string strMail = row["Mail"].ToString();
  674. // if (strAccount != "陈金勇" && strAccount!="南通流程邮箱")
  675. // {
  676. // string strUrl = $"{strAPIBaseUri}/api/Account/Modify?accountName={strAccount}&status={strStatus}&mail={strMail}";
  677. // var response = await CreateHttp().GetFromJsonAsync<ApiSaveResponse>(strUrl);
  678. // }
  679. // else
  680. // {
  681. // Console.WriteLine("");
  682. // }
  683. //}
  684. #endregion
  685. //var strUrl = "https://47.106.221.167/api/PerformanceItem/CalMyStatistics?userid=98&year=2021&month=12";
  686. //var response =await CreateHttp().GetFromJsonAsync<List<StaffStatistics>>(strUrl);
  687. }
  688. public async Task Login()
  689. {
  690. share.webViewObject.loginDto dto = new share.webViewObject.loginDto();
  691. dto.Name = "caiyangl";
  692. dto.Password = "Lqftiu807005";
  693. var response =await CreateHttp().PostAsJsonAsync<loginDto>($"{strAPIBaseUri}/api/account/Login", dto);
  694. if (response.IsSuccessStatusCode)
  695. {
  696. Token = await response.Content.ReadFromJsonAsync<userToken>();
  697. }
  698. }
  699. public async Task<entity.workflowDefine.Workflow> GetWorkflow(int Id, HttpClient _httpClient)
  700. {
  701. var ret = await _httpClient.GetFromJsonAsync<entity.workflowDefine.Workflow>($"{strAPIBaseUri}/api/WorkflowEngine/GetWorkflow?workflowId={Id}");
  702. return ret;
  703. }
  704. public async Task<List<entity.workflowDefine.Step>> GetSteps(int Id, HttpClient _httpClient)
  705. {
  706. var ret = await _httpClient.GetFromJsonAsync<List<entity.workflowDefine.Step>>($"{strAPIBaseUri}/api/WorkflowEngine/GetSteps?workflowId={Id}");
  707. return ret;
  708. }
  709. public async Task<List<entity.workflowDefine.Action>> GetActions(int workflowId, HttpClient _httpClient)
  710. {
  711. var ret = await _httpClient.GetFromJsonAsync<List<entity.workflowDefine.Action>>($"{strAPIBaseUri}/api/WorkflowEngine/GetActions?workflowId={workflowId}");
  712. return ret;
  713. }
  714. public async Task<List<entity.workflowDefine.TrasferCondition>> GetTransfers(int workflowId, HttpClient _httpClient)
  715. {
  716. var ret = await _httpClient.GetFromJsonAsync<List<entity.workflowDefine.TrasferCondition>>($"{strAPIBaseUri}/api/WorkflowEngine/GetTrasfers?workflowId={workflowId}");
  717. return ret;
  718. }
  719. private async Task SaveStaff(Staff obj)
  720. {
  721. HttpClient http = CreateHttp();
  722. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  723. var data = await http.PostAsJsonAsync<wispro.sp.entity.Staff>($"{strAPIBaseUri}/api/Staff/Save", obj);
  724. if (data.IsSuccessStatusCode)
  725. {
  726. ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
  727. //await Task.Delay(1000);
  728. if (result.Success)
  729. {
  730. }
  731. else
  732. {
  733. }
  734. }
  735. else
  736. {
  737. }
  738. }
  739. private async Task<Staff> GetStaff(string strName)
  740. {
  741. HttpClient http = CreateHttp();
  742. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  743. try
  744. {
  745. var data = await http.GetFromJsonAsync<wispro.sp.entity.Staff>($"{strAPIBaseUri}/api/Staff/GetByName?Name={strName}");
  746. return data;
  747. }
  748. catch
  749. {
  750. return null;
  751. }
  752. }
  753. private async Task SaveBasePointRule(BasePointRule obj)
  754. {
  755. HttpClient http = CreateHttp();
  756. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  757. var data = await http.PostAsJsonAsync<BasePointRule>($"{strAPIBaseUri}/api/BasePointRule/New", obj);
  758. if (data.IsSuccessStatusCode)
  759. {
  760. ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
  761. //await Task.Delay(1000);
  762. if (result.Success)
  763. {
  764. }
  765. else
  766. {
  767. System.Diagnostics.Debug.WriteLine($"保存错误: {obj.Rule}\t{obj.PointExpress}\r\n{result.ErrorMessage}");
  768. }
  769. }
  770. else
  771. {
  772. System.Diagnostics.Debug.WriteLine($"调用API错误: {obj.Type}\t{obj.Rule}");
  773. }
  774. }
  775. private async Task SavePerformanceItem(PerformanceItem obj)
  776. {
  777. HttpClient http = CreateHttp();
  778. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  779. if (obj.CalMonth.Month == 10)
  780. {
  781. System.Diagnostics.Debug.WriteLine($"{obj.CalMonth.Year}-{obj.CalMonth.Month}\t{obj.CaseNo}");
  782. }
  783. var isExist = await http.PostAsJsonAsync<PerformanceItem>($"{strAPIBaseUri}/api/PerformanceItem/IsExist", obj);
  784. if (isExist.IsSuccessStatusCode && await isExist.Content.ReadFromJsonAsync<bool>()==false)
  785. {
  786. var data = await http.PostAsJsonAsync<PerformanceItem>($"{strAPIBaseUri}/api/PerformanceItem/New", obj);
  787. if (data.IsSuccessStatusCode)
  788. {
  789. ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
  790. //await Task.Delay(1000);
  791. if (result.Success)
  792. {
  793. }
  794. else
  795. {
  796. System.Diagnostics.Debug.WriteLine($"保存错误: {obj.CaseNo}\t{obj.DoItem}\r\n{result.ErrorMessage}");
  797. }
  798. }
  799. else
  800. {
  801. System.Diagnostics.Debug.WriteLine($"调用API错误: {obj.CaseNo}\t{obj.DoItem}");
  802. }
  803. }
  804. }
  805. private HttpClient CreateHttp()
  806. {
  807. HttpClientHandler clientHandler = new HttpClientHandler();
  808. clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
  809. return new HttpClient(clientHandler);
  810. }
  811. private async Task<List<StaffGrade>> GetStaffGrades()
  812. {
  813. HttpClient http = CreateHttp();
  814. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  815. var _StaffGrade = await http.GetFromJsonAsync<List<StaffGrade>>($"{strAPIBaseUri}/api/StaffGrade/GetAll");
  816. return _StaffGrade;
  817. }
  818. private async Task<List<Staff>> GetStaffsAsync()
  819. {
  820. HttpClient http = CreateHttp();
  821. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  822. ListApiResponse<Staff> data = await http.GetFromJsonAsync<ListApiResponse<Staff>>($"{strAPIBaseUri}/api/Staff/Query?pageIndex=1&pageSize=1000");
  823. return data.Results;
  824. }
  825. private async Task<PerformanceItem> RefreshItemAsync(int type)
  826. {
  827. HttpClient http = CreateHttp();
  828. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  829. var data = await http.GetFromJsonAsync<PerformanceItem>($"{strAPIBaseUri}/api/PerformanceItem/RefreshFromIPEasy_Batch?type={type}");
  830. return data;
  831. }
  832. private async Task<List<Staff>> getReviewers(int itemId,int appealTypeId)
  833. {
  834. HttpClient http = CreateHttp();
  835. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  836. List<Staff> data = await http.GetFromJsonAsync<List<Staff>>($"{strAPIBaseUri}/api/Staff/GetReviewers?itemId={itemId}&appealTypeId={appealTypeId}");
  837. return data;
  838. }
  839. private async Task<PerformanceItem> GetDoItemInfo(string CaseNo, string DoItem, string caseStage)
  840. {
  841. HttpClient http = CreateHttp();
  842. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  843. PerformanceItem data = await http.GetFromJsonAsync<PerformanceItem>($"{strAPIBaseUri}/api/IPEasy/GetDoItemInfo?CaseNo={CaseNo}&DoItem={DoItem}&caseStage={caseStage}");
  844. return data;
  845. }
  846. private void button4_Click(object sender, EventArgs e)
  847. {
  848. Stopwatch watch = new Stopwatch();
  849. watch.Start();
  850. dynamic retObj = wispro.sp.utility.IPEasyUtility.GetPerformanceRecord("S2112392-洗碗机调查分析","提出报告");
  851. PerformanceItem Item = new PerformanceItem();
  852. Item.CaseName = retObj.CaseName;
  853. Item.CaseNo = retObj.CaseNo;
  854. Item.DoItem = retObj.DoItem;
  855. Item.CustomerLimitDate = string.IsNullOrEmpty(retObj.CustomerLimitDate) ? null : DateTime.Parse(retObj.CustomerLimitDate);
  856. Item.Customer = new Customer();
  857. Item.Customer.Name = retObj.CustomerName;
  858. Item.DoItemCoefficient = retObj.DoItemCoefficient;
  859. Item.DoItemMemo = retObj.DoItemMemo;
  860. Item.DoItemState = retObj.DoItemState;
  861. Item.EntrustingDate = string.IsNullOrEmpty(retObj.EntrustingDate) ? null : DateTime.Parse(retObj.EntrustingDate);
  862. Item.FinalizationDate = string.IsNullOrEmpty(retObj.FinalizationDate) ? null : DateTime.Parse(retObj.FinalizationDate);
  863. Item.FinishedDate = string.IsNullOrEmpty(retObj.FinishedDate) ? null : DateTime.Parse(retObj.FinishedDate);
  864. //Item.FirstDraftDate = string.IsNullOrEmpty(retObj.FirstDraftDate) ? null : DateTime.Parse(retObj.FirstDraftDate);
  865. Item.InternalDate = string.IsNullOrEmpty(retObj.InternalDate) ? null : DateTime.Parse(retObj.InternalDate);
  866. if (!string.IsNullOrEmpty(retObj.DoPersons))
  867. {
  868. Item.ItemStaffs = new List<ItemStaff>();
  869. string[] names = retObj.DoPersons.ToString().Split(new char[] { ','},StringSplitOptions.RemoveEmptyEntries);
  870. foreach(var name in names)
  871. {
  872. ItemStaff iStaff = new ItemStaff();
  873. iStaff.DoPerson = new Staff() { Name = name };
  874. Item.ItemStaffs.Add(iStaff);
  875. }
  876. }
  877. Item.ReturnDate = string.IsNullOrEmpty(retObj.ReturnDate) ? null : DateTime.Parse(retObj.ReturnDate);
  878. if (!string.IsNullOrEmpty(retObj.Reviewer))
  879. {
  880. Item.Reviewer = new Staff() { Name = retObj.Reviewer };
  881. }
  882. Item.ApplicationType = retObj.ApplicationType;
  883. Item.BusinessType = retObj.BusinessType;
  884. Item.CaseCoefficient = retObj.CaseCoefficient;
  885. Item.CaseMemo = retObj.CaseMemo;
  886. Item.CaseStage = retObj.CaseStage;
  887. Item.CaseState = retObj.CaseState;
  888. Item.CaseType = retObj.CaseType;
  889. watch.Stop();
  890. System.Diagnostics.Debug.WriteLine("用时{0}毫秒", watch.ElapsedMilliseconds);//获取当前实例测量得出的总运行时间(以毫秒为单位)
  891. //wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--上个月递交完成案件", true);
  892. //wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--发客户超过一个月未完成案件", false);
  893. //wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--中国一次OA授权表", true);
  894. ////每月绩效统计--发客户超过一个月未完成案件
  895. //NewMethod("506aa7ad-c3f4-4ec6-9ec8-ff6b92dcd7c1", "每月绩效统计--发客户超过一个月未完成案件.xlsx", calMonth);
  896. ////每月绩效统计--上个月递交完成案件
  897. //NewMethod("d7308cd2-71e4-4444-9f47-f4d731ddb26a", "每月绩效统计--上个月递交完成案件.xlsx", calMonth);
  898. ////每月绩效统计--中国一次OA授权表
  899. //NewMethod("72454834-afdd-4b98-b42a-0bc912d07610", "每月绩效统计--中国一次OA授权表.xlsx", calMonth, true);
  900. }
  901. }
  902. }