Form1.cs 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  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 Compare2DB();
  164. //await RefreshPerformanceItem(1);
  165. //await RefreshPerformanceItem(2);
  166. //await RefreshPerformanceItem(3);
  167. //await UserField2String(lstAJQL);
  168. //await UserField2String(lstAJXS);
  169. //await UserField2String(lstDoItemXS);
  170. //await UserField2String(lstJXBL);
  171. //await UserField2String(lstRXSX);
  172. //await UserField2String(lstYZCQ);
  173. //await ImportUsers();
  174. //await InputPerformanceItem("c:\\temp\\21.01-21.11 工程师绩效报表-总表.xlsx", true, false, 0);
  175. }
  176. private PerformanceItem Row2Item_1(DataRow row, List<Staff> Staffs, CalMonth calMonth)
  177. {
  178. PerformanceItem item = new PerformanceItem();
  179. item.ApplicationType = row["申请类型"].ToString().Trim();
  180. if(item.ApplicationType != "发明")
  181. {
  182. return null;
  183. }
  184. item.CaseNo = row["我方文号"].ToString().Trim();
  185. if (calMonth != null)
  186. {
  187. item.CalMonth = calMonth;
  188. }
  189. else
  190. {
  191. if (row.Table.Columns.Contains("绩效核算月份"))
  192. {
  193. string strjxyf = row["绩效核算月份"].ToString().Trim();
  194. string[] temYFs = strjxyf.Split(new char[] { '.' });
  195. item.CalMonth = new CalMonth();
  196. item.CalMonth.Year = int.Parse(temYFs[0]);
  197. item.CalMonth.Month = int.Parse(temYFs[1]);
  198. item.CalMonth.Status = 4;
  199. }
  200. else
  201. {
  202. item.CalMonth = new CalMonth();
  203. item.Status = 0;
  204. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  205. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  206. }
  207. }
  208. item.ApplicationType = row["申请类型"].ToString().Trim();
  209. item.BusinessType = "普通新申请"; // row["业务类型"].ToString().Trim();
  210. item.AgentFeedbackMemo = "发明一次OA授权"; //row["备注(填表注意事项)"].ToString().Trim();
  211. item.DoItem = "发明一次OA授权"; //row["处理事项"].ToString().Trim();
  212. string strHandler = "";
  213. if (row.Table.Columns.Contains("处理人"))
  214. {
  215. strHandler = row["处理人"].ToString().Trim();
  216. }
  217. else
  218. {
  219. if (row.Table.Columns.Contains("案件处理人"))
  220. {
  221. strHandler = row["案件处理人"].ToString().Trim();
  222. }
  223. }
  224. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  225. item.ItemStaffs = new List<ItemStaff>();
  226. foreach (string name in temHandlers)
  227. {
  228. ItemStaff itemStaff = new ItemStaff();
  229. int? iTem = GetStaff(name, Staffs);
  230. if ((iTem != null))
  231. {
  232. //itemStaff.Item = item;
  233. itemStaff.DoPersonId = iTem.Value;
  234. item.ItemStaffs.Add(itemStaff);
  235. }
  236. else
  237. {
  238. itemStaff.DoPerson = new Staff()
  239. {
  240. Name = name,
  241. Account = name,
  242. Password = "12345678",
  243. IsCalPerformsnce = false,
  244. Status = "正式员工",
  245. StaffGradeId = 4
  246. };
  247. item.ItemStaffs.Add(itemStaff);
  248. }
  249. }
  250. if (item.ItemStaffs.Count == 0)
  251. {
  252. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  253. }
  254. if (row.Table.Columns.Contains("核稿人"))
  255. {
  256. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim(), Staffs);
  257. }
  258. else
  259. {
  260. if (row.Table.Columns.Contains("案件核稿人"))
  261. {
  262. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim(), Staffs);
  263. }
  264. }
  265. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  266. item.ApplicationName = row["申请人"].ToString().Trim();
  267. item.CaseName = row["案件名称"].ToString().Trim();
  268. //案件备注
  269. item.CaseMemo = $"发文日期:{row["发文日期"].ToString().Trim()}\r\n客户文号:{row["客户文号"].ToString().Trim()}\r\n上传日期:{row["上传日期"].ToString().Trim()}\r\n文件描述:{row["文件描述"].ToString().Trim()}";
  270. return item;
  271. }
  272. private PerformanceItem Row2Item(DataRow row, List<Staff> Staffs,CalMonth calMonth)
  273. {
  274. PerformanceItem item = new PerformanceItem();
  275. item.CaseNo = row["我方文号"].ToString().Trim();
  276. if (calMonth != null)
  277. {
  278. item.CalMonth = calMonth;
  279. }
  280. else
  281. {
  282. if (row.Table.Columns.Contains("绩效核算月份"))
  283. {
  284. string strjxyf = row["绩效核算月份"].ToString().Trim();
  285. string[] temYFs = strjxyf.Split(new char[] { '.' });
  286. item.CalMonth = new CalMonth();
  287. item.CalMonth.Year = int.Parse(temYFs[0]);
  288. if (temYFs[1] == "1")
  289. {
  290. temYFs[1] = "10";
  291. }
  292. item.CalMonth.Month = int.Parse(temYFs[1]);
  293. item.CalMonth.Status = 4;
  294. }
  295. else
  296. {
  297. item.CalMonth = new CalMonth();
  298. item.Status = 0;
  299. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  300. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  301. }
  302. }
  303. item.ApplicationType = row["申请类型"].ToString().Trim();
  304. item.BusinessType = row["业务类型"].ToString().Trim();
  305. if (row.Table.Columns.Contains("备注(填表注意事项)"))
  306. item.AgentFeedbackMemo = row["备注(填表注意事项)"].ToString().Trim();
  307. item.DoItem = row["处理事项"].ToString().Trim();
  308. item.CaseStage = row["案件阶段"].ToString().Trim();
  309. item.CaseCoefficient = row["案件系数"].ToString().Trim();
  310. item.DoItemCoefficient = row["处理事项系数"].ToString().Trim();
  311. item.PreOastaffId = GetStaff(row["前一次OA处理人"].ToString().Trim(), Staffs);
  312. string strHandler = "";
  313. if (row.Table.Columns.Contains("处理人"))
  314. {
  315. strHandler = row["处理人"].ToString().Trim();
  316. }
  317. else
  318. {
  319. if (row.Table.Columns.Contains("案件处理人"))
  320. {
  321. strHandler = row["案件处理人"].ToString().Trim();
  322. }
  323. }
  324. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  325. item.ItemStaffs = new List<ItemStaff>();
  326. foreach (string name in temHandlers)
  327. {
  328. ItemStaff itemStaff = new ItemStaff();
  329. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  330. int? iTem = GetStaff(temName, Staffs);
  331. if ((iTem != null))
  332. {
  333. //itemStaff.Item = item;
  334. itemStaff.DoPersonId = iTem.Value;
  335. item.ItemStaffs.Add(itemStaff);
  336. }
  337. else
  338. {
  339. itemStaff.DoPerson = new Staff()
  340. {
  341. Name = temName,
  342. Account = temName,
  343. Password = "12345678",
  344. IsCalPerformsnce = false,
  345. Status = "已离职",
  346. StaffGradeId = 4
  347. };
  348. item.ItemStaffs.Add(itemStaff);
  349. }
  350. }
  351. if (item.ItemStaffs.Count == 0)
  352. {
  353. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  354. }
  355. if (row.Table.Columns.Contains("核稿人"))
  356. {
  357. if (!string.IsNullOrEmpty(row["核稿人"].ToString().Trim()))
  358. {
  359. string temName = row["核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  360. item.ReviewerId = GetStaff(temName.Trim(), Staffs);
  361. }
  362. }
  363. else
  364. {
  365. if (row.Table.Columns.Contains("案件核稿人"))
  366. {
  367. if (!string.IsNullOrEmpty(row["案件核稿人"].ToString().Trim()))
  368. {
  369. string temName = row["案件核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  370. item.ReviewerId = GetStaff(temName.Trim(), Staffs);
  371. }
  372. }
  373. }
  374. if (!string.IsNullOrEmpty(row["点数"].ToString().Trim())) {
  375. item.BasePoint = double.Parse(row["点数"].ToString().Trim());
  376. }
  377. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  378. item.ApplicationName = row["申请人"].ToString().Trim();
  379. DateTime temDate = new DateTime();
  380. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  381. {
  382. item.FinishedDate = temDate;
  383. }
  384. //定稿日
  385. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  386. {
  387. item.FinalizationDate = temDate;
  388. }
  389. //返稿日
  390. if (DateTime.TryParse(row["返稿日"].ToString().Trim(), out temDate))
  391. {
  392. item.ReturnDate = temDate;
  393. }
  394. //案件类型
  395. item.CaseType = row["案件类型"].ToString().Trim();
  396. //案件状态
  397. item.CaseState = row["案件状态"].ToString().Trim();
  398. //处理事项备注
  399. item.DoItemMemo = row["处理事项备注"].ToString().Trim();
  400. //处理状态
  401. item.DoItemState = row["处理状态"].ToString().Trim();
  402. //案件名称
  403. item.CaseName = row["案件名称"].ToString().Trim();
  404. //委案日期
  405. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  406. {
  407. item.EntrustingDate = temDate;
  408. }
  409. //客户期限
  410. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  411. {
  412. item.CustomerLimitDate = temDate;
  413. }
  414. //内部期限
  415. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  416. {
  417. item.InternalDate = temDate;
  418. }
  419. //初稿日
  420. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  421. {
  422. item.FirstDraftDate = temDate;
  423. }
  424. //备注(发文严重超期是否属客观原因,若为否,请填写原因)
  425. if (row.Table.Columns.Contains("备注(发文严重超期是否属客观原因,若为否,请填写原因)"))
  426. {
  427. item.OverDueMemo = row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"].ToString().Trim();
  428. }
  429. //案件备注
  430. item.CaseMemo = row["案件备注"].ToString().Trim();
  431. return item;
  432. }
  433. private async Task InputPerformanceItem(string strExcelFile,bool isColumnName,bool ignorHideRows=false,int ColumnNameRow=0,CalMonth calMonth=null,bool isFirstOAFile=false)
  434. {
  435. DataTable dt = NPOIExcel.ExcelToDataTable(strExcelFile, isColumnName,ignorHideRows,ColumnNameRow);
  436. #region 删除重复行
  437. DataTable temdt = new DataTable();
  438. foreach (DataColumn col in dt.Columns)
  439. {
  440. DataColumn temCol = new DataColumn();
  441. temCol.ColumnName = col.ColumnName;
  442. temCol.DataType = col.DataType;
  443. temCol.Caption = col.Caption;
  444. temdt.Columns.Add(temCol);
  445. }
  446. new ExcelHelper().MerageDataTable(temdt, dt);
  447. #endregion
  448. List<Staff> Staffs =await GetStaffsAsync();
  449. foreach(DataRow row in temdt.Rows)
  450. {
  451. PerformanceItem item = null;
  452. if (isFirstOAFile)
  453. {
  454. item = Row2Item_1(row, Staffs, calMonth);
  455. }
  456. else
  457. {
  458. item = Row2Item(row, Staffs, calMonth);
  459. }
  460. if (item != null )
  461. {
  462. System.Diagnostics.Debug.WriteLine($"{DateTime.Now}\t{item.CaseNo}\t{item.CaseName}");
  463. if (!InValidDoItem.Contains(item.DoItem))
  464. {
  465. await SavePerformanceItem(item);
  466. }
  467. }
  468. }
  469. }
  470. private async Task Compare2DB()
  471. {
  472. if (Token == null)
  473. {
  474. await Login();
  475. }
  476. HttpClient http = CreateHttp();
  477. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  478. var data = await http.GetFromJsonAsync<PerformanceItem>($"{strAPIBaseUri}/api/PerformanceItem/CompareExcel2DB");
  479. //await GetDoItemInfo("PACN2027395", "处理审查意见", "一通");
  480. }
  481. private async Task RefreshPerformanceItem(int Type)
  482. {
  483. if (Token == null)
  484. {
  485. await Login();
  486. }
  487. await RefreshItemAsync(Type);
  488. //await GetDoItemInfo("PACN2027395", "处理审查意见", "一通");
  489. }
  490. List<string> lstJXBL = new List<string>() {
  491. "柳芳","杨超","何倚雯","李姣","张庆玲","李建民","李申","李莉","刘桂兰"
  492. ,"唐双","瞿璨","张鹏","钟锦光","翁旋艺","钟子敏"
  493. };
  494. List<string> lstAJXS = new List<string>() {
  495. "柳芳","杨超","何倚雯","李姣","张庆玲","李建民","李申","李莉","刘桂兰"
  496. ,"唐双","瞿璨","张鹏","钟锦光","翁旋艺","钟子敏","邢丽霞",
  497. "李庆波","黄瑜","程利","黎坚怡","舒丽亚","管自英","张晓薇","刘希"
  498. };
  499. List<string> lstDoItemXS = new List<string>() {
  500. "吴继红","赖玲玲","郭竟微","陈鹤","王本鼎","高凌云","周煜祥","何丹风",
  501. "田婵玉","孙心洁","陈舒敏","邢丽霞"
  502. };
  503. List<string> lstAJQL = new List<string>() {
  504. "柳芳","杨超","何倚雯","李姣","张庆玲","李建民","李申","李莉","刘桂兰"
  505. ,"唐双","瞿璨","张鹏","钟锦光","翁旋艺","吴继红","赖玲玲","郭竟微","陈鹤",
  506. "王本鼎","高凌云","周煜祥","何丹风","田婵玉","孙心洁","陈舒敏","钟子敏",
  507. "李庆波","黄瑜","程利","黎坚怡","舒丽亚","管自英","张晓薇","刘希"
  508. };
  509. List<string> lstYZCQ = new List<string>() {
  510. "吴继红","赖玲玲","郭竟微","陈鹤","王本鼎","高凌云","周煜祥","何丹风",
  511. "田婵玉","孙心洁","陈舒敏"
  512. };
  513. List<string> lstRXSX = new List<string>() {
  514. "夏敏","柳芳","杨超","何倚雯","李姣","张庆玲","李建民","李申","李莉","刘桂兰"
  515. ,"唐双","瞿璨","张鹏","钟锦光","翁旋艺","钟子敏","李庆波","黄瑜","程利",
  516. "黎坚怡","舒丽亚","管自英","张晓薇","刘希"
  517. };
  518. private async Task UserField2String(List<string> lstList)
  519. {
  520. if (Token == null)
  521. {
  522. await Login();
  523. }
  524. //List<Staff> Reviewers = await getReviewers(14232, 1);
  525. //Reviewers = await getReviewers(14232, 5);
  526. List<Staff> Staffs = await GetStaffsAsync();
  527. List<UserField> lstUsers = new List<UserField>();
  528. foreach(var name in lstList)
  529. {
  530. lstUsers.Add(new UserField()
  531. {
  532. UserConditionType = UserConditionType.Staff,
  533. UserType = UserType.Staff,
  534. UserValue = GetStaff(name, Staffs).ToString()
  535. });
  536. }
  537. JsonSerializerOptions options = new() { IgnoreNullValues = true };
  538. var strJson = System.Text.Json.JsonSerializer.Serialize(lstUsers, lstUsers.GetType(), options);
  539. System.Diagnostics.Debug.WriteLine(strJson);
  540. }
  541. private int? GetStaff(string v, List<Staff> staffs)
  542. {
  543. if (!string.IsNullOrEmpty(v))
  544. {
  545. string[] temNames = v.Trim().Split(new char[] { '-' },StringSplitOptions.RemoveEmptyEntries);
  546. foreach (Staff sf in staffs)
  547. {
  548. if(sf.Name == temNames[0])
  549. {
  550. return sf.Id;
  551. }
  552. }
  553. }
  554. return null;
  555. }
  556. private async Task ImportUsers()
  557. {
  558. OpenFileDialog ofd = new OpenFileDialog();
  559. if (ofd.ShowDialog() == DialogResult.OK)
  560. {
  561. string fileName = ofd.FileName;
  562. DataTable dt = NPOIExcel.ExcelToDataTable(fileName, true, false, 1);
  563. if(Token == null)
  564. {
  565. await Login();
  566. }
  567. List<StaffGrade> staffGrades = await GetStaffGrades();
  568. foreach (DataRow row in dt.Rows)
  569. {
  570. Staff staff = new Staff();
  571. staff.Account = row["用户名"].ToString().Trim();
  572. staff.Name = row["姓名"].ToString().Trim();
  573. staff.Tel = row["电话号码"].ToString().Trim();
  574. staff.Mobile = row["手机号码"].ToString().Trim();
  575. staff.Sex = row["性别"].ToString().Trim();
  576. staff.Mail = row["邮箱"].ToString().Trim();
  577. string strGrade = row["工程师等级"].ToString().Trim(); // + "级";
  578. foreach (StaffGrade sg in staffGrades)
  579. {
  580. if (strGrade.Trim() == sg.Grade.Trim())
  581. {
  582. staff.StaffGradeId = sg.Id;
  583. break;
  584. }
  585. }
  586. staff.IsOnJob = (row["是否在职"].ToString().Trim() == "是");
  587. staff.Status = row["岗位状态"].ToString().Trim();
  588. staff.Department = row["部门"].ToString();
  589. staff.WorkPlace = row["工作地"].ToString();
  590. DateTime temDate;
  591. if (DateTime.TryParse(row["入职时间"].ToString(), out temDate))
  592. {
  593. staff.EntyDate = temDate;
  594. }
  595. var temStaff = await GetStaff(staff.Name);
  596. bool isSaved = false;
  597. if (temStaff == null)
  598. {
  599. isSaved = true;
  600. staff.Password = MD5Utility.GetMD5("12345678");
  601. }
  602. else
  603. {
  604. staff.Id = temStaff.Id;
  605. staff.Password = temStaff.Password;
  606. isSaved =
  607. (staff.Name != temStaff.Name) ||
  608. (staff.Account != temStaff.Account) ||
  609. (staff.Department != temStaff.Department) ||
  610. (staff.EntyDate != temStaff.EntyDate) ||
  611. (staff.IsOnJob != temStaff.IsOnJob) ||
  612. (staff.Mail != temStaff.Mail) ||
  613. (staff.Mobile != temStaff.Mobile) ||
  614. (staff.Sex != temStaff.Sex) ||
  615. (staff.Status != temStaff.Status) ||
  616. (staff.Tel != temStaff.Tel) ||
  617. (staff.WorkPlace != temStaff.WorkPlace) ||
  618. (staff.StaffGradeId != temStaff.StaffGradeId);
  619. }
  620. if (isSaved)
  621. {
  622. //staff.IsCalPerformsnce = (row["是否核算绩效"].ToString() == "是");
  623. //staff.Memo = row["备注"].ToString().Trim();
  624. //staff.StaffGradeId = row["姓名"].ToString();
  625. await SaveStaff(staff);
  626. }
  627. }
  628. }
  629. }
  630. private string getPinYin(string str)
  631. {
  632. string retStr = "";
  633. for(int i = 0; i < str.Length; i++)
  634. {
  635. ChineseChar cc = new ChineseChar(str[i]);
  636. retStr = retStr + cc.Pinyins[0].ToLower().Replace("1","")
  637. .Replace("2", "").Replace("3", "").Replace("4", "");
  638. }
  639. return retStr;
  640. }
  641. string strAPIBaseUri = "http://localhost:39476";// "https://47.106.221.167"; //
  642. userToken Token;
  643. public async Task Login()
  644. {
  645. share.webViewObject.loginDto dto = new share.webViewObject.loginDto();
  646. dto.Name = "caiyangl";
  647. dto.Password = "Lqftiu807005";
  648. var response =await CreateHttp().PostAsJsonAsync<loginDto>($"{strAPIBaseUri}/api/account/Login", dto);
  649. if (response.IsSuccessStatusCode)
  650. {
  651. Token = await response.Content.ReadFromJsonAsync<userToken>();
  652. }
  653. }
  654. public async Task<entity.workflowDefine.Workflow> GetWorkflow(int Id, HttpClient _httpClient)
  655. {
  656. var ret = await _httpClient.GetFromJsonAsync<entity.workflowDefine.Workflow>($"{strAPIBaseUri}/api/WorkflowEngine/GetWorkflow?workflowId={Id}");
  657. return ret;
  658. }
  659. public async Task<List<entity.workflowDefine.Step>> GetSteps(int Id, HttpClient _httpClient)
  660. {
  661. var ret = await _httpClient.GetFromJsonAsync<List<entity.workflowDefine.Step>>($"{strAPIBaseUri}/api/WorkflowEngine/GetSteps?workflowId={Id}");
  662. return ret;
  663. }
  664. public async Task<List<entity.workflowDefine.Action>> GetActions(int workflowId, HttpClient _httpClient)
  665. {
  666. var ret = await _httpClient.GetFromJsonAsync<List<entity.workflowDefine.Action>>($"{strAPIBaseUri}/api/WorkflowEngine/GetActions?workflowId={workflowId}");
  667. return ret;
  668. }
  669. public async Task<List<entity.workflowDefine.TrasferCondition>> GetTransfers(int workflowId, HttpClient _httpClient)
  670. {
  671. var ret = await _httpClient.GetFromJsonAsync<List<entity.workflowDefine.TrasferCondition>>($"{strAPIBaseUri}/api/WorkflowEngine/GetTrasfers?workflowId={workflowId}");
  672. return ret;
  673. }
  674. private async Task SaveStaff(Staff obj)
  675. {
  676. HttpClient http = CreateHttp();
  677. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  678. var data = await http.PostAsJsonAsync<wispro.sp.entity.Staff>($"{strAPIBaseUri}/api/Staff/Save", obj);
  679. if (data.IsSuccessStatusCode)
  680. {
  681. ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
  682. //await Task.Delay(1000);
  683. if (result.Success)
  684. {
  685. }
  686. else
  687. {
  688. }
  689. }
  690. else
  691. {
  692. }
  693. }
  694. private async Task<Staff> GetStaff(string strName)
  695. {
  696. HttpClient http = CreateHttp();
  697. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  698. try
  699. {
  700. var data = await http.GetFromJsonAsync<wispro.sp.entity.Staff>($"{strAPIBaseUri}/api/Staff/GetByName?Name={strName}");
  701. return data;
  702. }
  703. catch
  704. {
  705. return null;
  706. }
  707. }
  708. private async Task SaveBasePointRule(BasePointRule obj)
  709. {
  710. HttpClient http = CreateHttp();
  711. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  712. var data = await http.PostAsJsonAsync<BasePointRule>($"{strAPIBaseUri}/api/BasePointRule/New", obj);
  713. if (data.IsSuccessStatusCode)
  714. {
  715. ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
  716. //await Task.Delay(1000);
  717. if (result.Success)
  718. {
  719. }
  720. else
  721. {
  722. System.Diagnostics.Debug.WriteLine($"保存错误: {obj.Rule}\t{obj.PointExpress}\r\n{result.ErrorMessage}");
  723. }
  724. }
  725. else
  726. {
  727. System.Diagnostics.Debug.WriteLine($"调用API错误: {obj.Type}\t{obj.Rule}");
  728. }
  729. }
  730. private async Task SavePerformanceItem(PerformanceItem obj)
  731. {
  732. HttpClient http = CreateHttp();
  733. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  734. if (obj.CalMonth.Month == 10)
  735. {
  736. System.Diagnostics.Debug.WriteLine($"{obj.CalMonth.Year}-{obj.CalMonth.Month}\t{obj.CaseNo}");
  737. }
  738. var isExist = await http.PostAsJsonAsync<PerformanceItem>($"{strAPIBaseUri}/api/PerformanceItem/IsExist", obj);
  739. if (isExist.IsSuccessStatusCode && await isExist.Content.ReadFromJsonAsync<bool>()==false)
  740. {
  741. var data = await http.PostAsJsonAsync<PerformanceItem>($"{strAPIBaseUri}/api/PerformanceItem/New", obj);
  742. if (data.IsSuccessStatusCode)
  743. {
  744. ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
  745. //await Task.Delay(1000);
  746. if (result.Success)
  747. {
  748. }
  749. else
  750. {
  751. System.Diagnostics.Debug.WriteLine($"保存错误: {obj.CaseNo}\t{obj.DoItem}\r\n{result.ErrorMessage}");
  752. }
  753. }
  754. else
  755. {
  756. System.Diagnostics.Debug.WriteLine($"调用API错误: {obj.CaseNo}\t{obj.DoItem}");
  757. }
  758. }
  759. }
  760. private HttpClient CreateHttp()
  761. {
  762. HttpClientHandler clientHandler = new HttpClientHandler();
  763. clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
  764. return new HttpClient(clientHandler);
  765. }
  766. private async Task<List<StaffGrade>> GetStaffGrades()
  767. {
  768. HttpClient http = CreateHttp();
  769. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  770. var _StaffGrade = await http.GetFromJsonAsync<List<StaffGrade>>($"{strAPIBaseUri}/api/StaffGrade/GetAll");
  771. return _StaffGrade;
  772. }
  773. private async Task<List<Staff>> GetStaffsAsync()
  774. {
  775. HttpClient http = CreateHttp();
  776. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  777. ListApiResponse<Staff> data = await http.GetFromJsonAsync<ListApiResponse<Staff>>($"{strAPIBaseUri}/api/Staff/Query?pageIndex=1&pageSize=1000");
  778. return data.Results;
  779. }
  780. private async Task<PerformanceItem> RefreshItemAsync(int type)
  781. {
  782. HttpClient http = CreateHttp();
  783. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  784. var data = await http.GetFromJsonAsync<PerformanceItem>($"{strAPIBaseUri}/api/PerformanceItem/RefreshFromIPEasy_Batch?type={type}");
  785. return data;
  786. }
  787. private async Task<List<Staff>> getReviewers(int itemId,int appealTypeId)
  788. {
  789. HttpClient http = CreateHttp();
  790. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  791. List<Staff> data = await http.GetFromJsonAsync<List<Staff>>($"{strAPIBaseUri}/api/Staff/GetReviewers?itemId={itemId}&appealTypeId={appealTypeId}");
  792. return data;
  793. }
  794. private async Task<PerformanceItem> GetDoItemInfo(string CaseNo, string DoItem, string caseStage)
  795. {
  796. HttpClient http = CreateHttp();
  797. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token.Token);
  798. PerformanceItem data = await http.GetFromJsonAsync<PerformanceItem>($"{strAPIBaseUri}/api/IPEasy/GetDoItemInfo?CaseNo={CaseNo}&DoItem={DoItem}&caseStage={caseStage}");
  799. return data;
  800. }
  801. private void button4_Click(object sender, EventArgs e)
  802. {
  803. Stopwatch watch = new Stopwatch();
  804. watch.Start();
  805. dynamic retObj = wispro.sp.utility.IPEasyUtility.GetPerformanceRecord("S2112392-洗碗机调查分析","提出报告");
  806. PerformanceItem Item = new PerformanceItem();
  807. Item.CaseName = retObj.CaseName;
  808. Item.CaseNo = retObj.CaseNo;
  809. Item.DoItem = retObj.DoItem;
  810. Item.CustomerLimitDate = string.IsNullOrEmpty(retObj.CustomerLimitDate) ? null : DateTime.Parse(retObj.CustomerLimitDate);
  811. Item.Customer = new Customer();
  812. Item.Customer.Name = retObj.CustomerName;
  813. Item.DoItemCoefficient = retObj.DoItemCoefficient;
  814. Item.DoItemMemo = retObj.DoItemMemo;
  815. Item.DoItemState = retObj.DoItemState;
  816. Item.EntrustingDate = string.IsNullOrEmpty(retObj.EntrustingDate) ? null : DateTime.Parse(retObj.EntrustingDate);
  817. Item.FinalizationDate = string.IsNullOrEmpty(retObj.FinalizationDate) ? null : DateTime.Parse(retObj.FinalizationDate);
  818. Item.FinishedDate = string.IsNullOrEmpty(retObj.FinishedDate) ? null : DateTime.Parse(retObj.FinishedDate);
  819. //Item.FirstDraftDate = string.IsNullOrEmpty(retObj.FirstDraftDate) ? null : DateTime.Parse(retObj.FirstDraftDate);
  820. Item.InternalDate = string.IsNullOrEmpty(retObj.InternalDate) ? null : DateTime.Parse(retObj.InternalDate);
  821. if (!string.IsNullOrEmpty(retObj.DoPersons))
  822. {
  823. Item.ItemStaffs = new List<ItemStaff>();
  824. string[] names = retObj.DoPersons.ToString().Split(new char[] { ','},StringSplitOptions.RemoveEmptyEntries);
  825. foreach(var name in names)
  826. {
  827. ItemStaff iStaff = new ItemStaff();
  828. iStaff.DoPerson = new Staff() { Name = name };
  829. Item.ItemStaffs.Add(iStaff);
  830. }
  831. }
  832. Item.ReturnDate = string.IsNullOrEmpty(retObj.ReturnDate) ? null : DateTime.Parse(retObj.ReturnDate);
  833. if (!string.IsNullOrEmpty(retObj.Reviewer))
  834. {
  835. Item.Reviewer = new Staff() { Name = retObj.Reviewer };
  836. }
  837. Item.ApplicationType = retObj.ApplicationType;
  838. Item.BusinessType = retObj.BusinessType;
  839. Item.CaseCoefficient = retObj.CaseCoefficient;
  840. Item.CaseMemo = retObj.CaseMemo;
  841. Item.CaseStage = retObj.CaseStage;
  842. Item.CaseState = retObj.CaseState;
  843. Item.CaseType = retObj.CaseType;
  844. watch.Stop();
  845. System.Diagnostics.Debug.WriteLine("用时{0}毫秒", watch.ElapsedMilliseconds);//获取当前实例测量得出的总运行时间(以毫秒为单位)
  846. //wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--上个月递交完成案件", true);
  847. //wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--发客户超过一个月未完成案件", false);
  848. //wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--中国一次OA授权表", true);
  849. ////每月绩效统计--发客户超过一个月未完成案件
  850. //NewMethod("506aa7ad-c3f4-4ec6-9ec8-ff6b92dcd7c1", "每月绩效统计--发客户超过一个月未完成案件.xlsx", calMonth);
  851. ////每月绩效统计--上个月递交完成案件
  852. //NewMethod("d7308cd2-71e4-4444-9f47-f4d731ddb26a", "每月绩效统计--上个月递交完成案件.xlsx", calMonth);
  853. ////每月绩效统计--中国一次OA授权表
  854. //NewMethod("72454834-afdd-4b98-b42a-0bc912d07610", "每月绩效统计--中国一次OA授权表.xlsx", calMonth, true);
  855. }
  856. }
  857. }