Form1.cs 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  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 = "https://47.106.221.167"; // "http://localhost:39476";//
  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. //每月绩效统计--发客户超过一个月未完成案件
  851. //DownloadReport("每月绩效统计--发客户超过一个月未完成案件", calMonth, false);
  852. //每月绩效统计--上个月递交完成案件
  853. //DownloadReport("每月绩效统计--上个月递交完成案件", calMonth, true);
  854. //每月绩效统计--中国一次OA授权表
  855. //DownloadReport("每月绩效统计--中国一次OA授权表", calMonth, true, true);
  856. //"每月绩效统计--专案进度跟踪~S卷", "每月绩效统计--专案开卷报表~S卷"
  857. wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--发客户超过一个月未完成案件", false);
  858. wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--上个月递交完成案件", true);
  859. wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--中国一次OA授权表", true);
  860. wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--专案进度跟踪~S卷", false);
  861. wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--专案开卷报表~S卷", false);
  862. #region aaa
  863. //dynamic retObj = wispro.sp.utility.IPEasyUtility.GetPerformanceRecord("S2112392-洗碗机调查分析","提出报告");
  864. //PerformanceItem Item = new PerformanceItem();
  865. //Item.CaseName = retObj.CaseName;
  866. //Item.CaseNo = retObj.CaseNo;
  867. //Item.DoItem = retObj.DoItem;
  868. //Item.CustomerLimitDate = string.IsNullOrEmpty(retObj.CustomerLimitDate) ? null : DateTime.Parse(retObj.CustomerLimitDate);
  869. //Item.Customer = new Customer();
  870. //Item.Customer.Name = retObj.CustomerName;
  871. //Item.DoItemCoefficient = retObj.DoItemCoefficient;
  872. //Item.DoItemMemo = retObj.DoItemMemo;
  873. //Item.DoItemState = retObj.DoItemState;
  874. //Item.EntrustingDate = string.IsNullOrEmpty(retObj.EntrustingDate) ? null : DateTime.Parse(retObj.EntrustingDate);
  875. //Item.FinalizationDate = string.IsNullOrEmpty(retObj.FinalizationDate) ? null : DateTime.Parse(retObj.FinalizationDate);
  876. //Item.FinishedDate = string.IsNullOrEmpty(retObj.FinishedDate) ? null : DateTime.Parse(retObj.FinishedDate);
  877. ////Item.FirstDraftDate = string.IsNullOrEmpty(retObj.FirstDraftDate) ? null : DateTime.Parse(retObj.FirstDraftDate);
  878. //Item.InternalDate = string.IsNullOrEmpty(retObj.InternalDate) ? null : DateTime.Parse(retObj.InternalDate);
  879. //if (!string.IsNullOrEmpty(retObj.DoPersons))
  880. //{
  881. // Item.ItemStaffs = new List<ItemStaff>();
  882. // string[] names = retObj.DoPersons.ToString().Split(new char[] { ','},StringSplitOptions.RemoveEmptyEntries);
  883. // foreach(var name in names)
  884. // {
  885. // ItemStaff iStaff = new ItemStaff();
  886. // iStaff.DoPerson = new Staff() { Name = name };
  887. // Item.ItemStaffs.Add(iStaff);
  888. // }
  889. //}
  890. //Item.ReturnDate = string.IsNullOrEmpty(retObj.ReturnDate) ? null : DateTime.Parse(retObj.ReturnDate);
  891. //if (!string.IsNullOrEmpty(retObj.Reviewer))
  892. //{
  893. // Item.Reviewer = new Staff() { Name = retObj.Reviewer };
  894. //}
  895. //Item.ApplicationType = retObj.ApplicationType;
  896. //Item.BusinessType = retObj.BusinessType;
  897. //Item.CaseCoefficient = retObj.CaseCoefficient;
  898. //Item.CaseMemo = retObj.CaseMemo;
  899. //Item.CaseStage = retObj.CaseStage;
  900. //Item.CaseState = retObj.CaseState;
  901. //Item.CaseType = retObj.CaseType;
  902. #endregion
  903. watch.Stop();
  904. System.Diagnostics.Debug.WriteLine("用时{0}毫秒", watch.ElapsedMilliseconds);//获取当前实例测量得出的总运行时间(以毫秒为单位)
  905. //wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--上个月递交完成案件", true);
  906. //wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--发客户超过一个月未完成案件", false);
  907. //wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--中国一次OA授权表", true);
  908. ////每月绩效统计--发客户超过一个月未完成案件
  909. //NewMethod("506aa7ad-c3f4-4ec6-9ec8-ff6b92dcd7c1", "每月绩效统计--发客户超过一个月未完成案件.xlsx", calMonth);
  910. ////每月绩效统计--上个月递交完成案件
  911. //NewMethod("d7308cd2-71e4-4444-9f47-f4d731ddb26a", "每月绩效统计--上个月递交完成案件.xlsx", calMonth);
  912. ////每月绩效统计--中国一次OA授权表
  913. //NewMethod("72454834-afdd-4b98-b42a-0bc912d07610", "每月绩效统计--中国一次OA授权表.xlsx", calMonth, true);
  914. }
  915. }
  916. }