Form1.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  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.Threading.Tasks;
  18. using System.Windows.Forms;
  19. using wispro.sp.entity;
  20. using wispro.sp.share;
  21. using wispro.sp.share.Utility;
  22. using wispro.sp.utility;
  23. namespace wispro.sp.winClient
  24. {
  25. public partial class Form1 : Form
  26. {
  27. public Form1()
  28. {
  29. InitializeComponent();
  30. }
  31. private void button1_Click(object sender, EventArgs e)
  32. {
  33. DateTime startTime = DateTime.Now;
  34. frmMerageExcel frm = new frmMerageExcel();
  35. if (frm.ShowDialog() == DialogResult.OK)
  36. {
  37. MessageBox.Show($"合并完成,合并后文件保存在:\r\n{frm.SaveFilePath}\r\n用时:{DateTime.Now - startTime }");
  38. }
  39. }
  40. private void button2_Click(object sender, EventArgs e)
  41. {
  42. OpenFileDialog ofd = new OpenFileDialog()
  43. {
  44. Multiselect = false,
  45. Filter = "*.xls|*.xlsx"
  46. };
  47. string strDinashuRegularFile = ConfigurationSettings.AppSettings["DinashuRegularFile"];
  48. if (ofd.ShowDialog() == DialogResult.OK)
  49. {
  50. new ExcelHelper().FillDianShu(ofd.FileName, strDinashuRegularFile);
  51. }
  52. MessageBox.Show("完成点数输入!");
  53. }
  54. private string[] InValidDoItem = new string[]
  55. {
  56. "案件异常-催缴年费",
  57. "案件异常-视为放弃取得专利权",
  58. "办理登记手续",
  59. "办理登记手续-确认客户是否委托",
  60. "代理所变更",
  61. "绘图",
  62. "技术确认",
  63. "缴年费",
  64. "请求保密审查",
  65. "请求费减",
  66. "请求实审",
  67. "取得申请号",
  68. "取得证书",
  69. "取得专利权评价报告",
  70. "确认官方审查状况",
  71. "询问放弃或复审",
  72. "知识点总结",
  73. "专利权人发明人申请人信息变更",
  74. "专利挖掘与布局",
  75. "我方文号前缀带J",
  76. "开卷",
  77. "请求提前公开",
  78. "取得国际检索报告",
  79. "委外检索",
  80. "中止程序",
  81. "终止",
  82. "案件异常-视为撤回",
  83. "进入国家阶段提醒",
  84. "请求恢复权利",
  85. "请求优先权",
  86. "取得【无效宣告请求审查决定】",
  87. "撤回",
  88. "请求退款",
  89. "确认是否委托申请与类型",
  90. "专利交易",
  91. "专利权评价报告",
  92. "专利权人发明人申请人信息变更+代理所变更"
  93. };
  94. private async Task InitRules(bool isSave)
  95. {
  96. List<BasePointRule> rules = new List<BasePointRule>();
  97. DataTable dt = wispro.sp.utility.NPOIExcel.ExcelToDataTable("ExcelFiles\\20211109-绩效点数规则-lcy-v1.xlsx", true);
  98. PerformanceItem item = new PerformanceItem() { CaseNo = "PAEPO2016277", DoItem= "提交检索主题声明", };
  99. foreach(DataRow row in dt.Rows)
  100. {
  101. BasePointRule rule = new BasePointRule()
  102. {
  103. Rule = row["规则"].ToString(),
  104. PointExpress = row["点数计算"].ToString(),
  105. Priority = int.Parse(row["优先级修订"].ToString()),
  106. Type = row["类型"].ToString()
  107. };
  108. try
  109. {
  110. var interpreter = new Interpreter();
  111. //item.ApplicationType
  112. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(rule.Rule, "p");
  113. bool result = func.Invoke(item);
  114. if (result)
  115. {
  116. item.BasePoint = (double?)interpreter.Eval(rule.PointExpress);
  117. item.Type = rule.Type;
  118. System.Diagnostics.Debug.WriteLine("");
  119. }
  120. rules.Add(rule);
  121. }
  122. catch(Exception ex)
  123. {
  124. System.Diagnostics.Debug.WriteLine(rule.Rule + "\r\n" + ex.ToString());
  125. }
  126. }
  127. if (isSave)
  128. {
  129. foreach (BasePointRule rule in rules)
  130. {
  131. double d;
  132. if(double.TryParse(rule.PointExpress,out d))
  133. {
  134. rule.PointExpress = d.ToString("0.00");
  135. }
  136. await SaveBasePointRule(rule);
  137. }
  138. }
  139. }
  140. public async Task TestQueryFilter()
  141. {
  142. //QueryFilter filter = new QueryFilter();
  143. //filter.ConditionTree = new ExpressTree();
  144. //string ValueType = typeof(PerformanceItem).GetProperty("CaseNo").PropertyType.ToString();
  145. //FieldCondition condition1 = new FieldCondition() { FieldName = "CaseNo", Operator = OperatorEnum.Contains, Value = "PACN", ValueType = ValueType };
  146. //FieldCondition condition2 = new FieldCondition() { FieldName = "CaseNo", Operator = OperatorEnum.Contains, Value = "PAUS", ValueType = ValueType };
  147. //filter.ConditionTree.AddCondition(LogicEnum.And,condition1);
  148. //filter.ConditionTree.AddCondition(LogicEnum.Or, condition2);
  149. //System.Diagnostics.Debug.WriteLine(filter.ConditionTree.ToExpressString("s")); ;
  150. }
  151. enum enumTest
  152. {
  153. [Description("男")]
  154. man,
  155. [Description("女")]
  156. woman
  157. }
  158. private async void button3_Click(object sender, EventArgs e)
  159. {
  160. //share.Utility.UserConditionHelper.GetPropertyDescription<Staff>(typeof(PerformanceItem).AssemblyQualifiedName);
  161. #region Demo流程数据
  162. //HttpClient http = new HttpClient();
  163. //int wfId = 6;
  164. //var workflow = await GetWorkflow(wfId, http);
  165. //var Steps = await GetSteps(wfId, http);
  166. //var Actions = await GetActions(wfId, http);
  167. //var Transfers = await GetTransfers(wfId,http);
  168. #endregion
  169. //FlowChartUtility flowChart = new FlowChartUtility();
  170. //flowChart.workflow = workflow;
  171. //flowChart.Steps = Steps;
  172. //flowChart.Transfers = Transfers;
  173. //string strSvg = flowChart.GetSvgString();
  174. ////var file = System.IO.File.CreateText("c:\\temp\\tem.svg");
  175. ////file.WriteLine(strSvg);
  176. ////file.Close();
  177. //System.Xml.XmlDocument xmdoc = new System.Xml.XmlDocument();
  178. //xmdoc.LoadXml(strSvg);
  179. //Svg.SvgDocument svg = Svg.SvgDocument.Open(xmdoc);
  180. //Bitmap bitmap = svg.Draw();
  181. //bitmap.Save("c:\\temp\\test.jpg",ImageFormat.Jpeg);
  182. //MemoryStream mStream = new MemoryStream();
  183. //bitmap.Save(mStream, ImageFormat.Jpeg);
  184. //byte[] bitMaps = new byte[mStream.Length];
  185. //mStream.Read(bitMaps, 0, (int)mStream.Length);
  186. //var test =wispro.sp.utility.EmunHelper.getEnumDescriptionDic<wispro.sp.entity.workflowDefine.LogicSymbols>();
  187. //Console.WriteLine("");
  188. //dynamic dynObj = new ExpandoObject();
  189. //dynObj.Name = "名称";
  190. //dynObj.Text = "aaabc";
  191. //List<dynamic> list = new List<dynamic>();
  192. //for(int i = 0; i < 3; i++)
  193. //{
  194. // dynamic d = new ExpandoObject();
  195. // d.Id = i + 1;
  196. // d.Filed1 = $"Field{i}";
  197. // d.Date = DateTime.Now.AddDays(i);
  198. // list.Add(d);
  199. //}
  200. //dynObj.List = list;
  201. //var temTxt = System.Text.Json.JsonSerializer.Serialize(dynObj);
  202. //var dynamic = System.Text.Json.JsonSerializer.Deserialize<ExpandoObject>(temTxt);
  203. //MessageBox.Show(((IDictionary<string, object>)dynamic)["Name"].ToString());
  204. //wispro.sp.utility.MailUtil.SendEmail("测试邮件标题","测试邮件内容","罗才洋","luocaiyang@139.com");
  205. //CreateAppealModel model = new CreateAppealModel();
  206. //HttpClient http = new HttpClient();
  207. //PerformanceItem item = await http.GetFromJsonAsync<wispro.sp.entity.PerformanceItem>($"{strAPIBaseUri}/api/PerformanceItem/Get?Id=7341");
  208. //List<AppealType> appealTypes = await http.GetFromJsonAsync<List<AppealType>>($"{strAPIBaseUri}/api/Appeal/GetAppealTypes");
  209. //var appealType = appealTypes.Where<AppealType>(a => a.Id == 1).FirstOrDefault();
  210. //await model.Init(item, appealType);
  211. ////await TestQueryFilter();
  212. //List<PerformanceItem> retList = new List<PerformanceItem>();
  213. //var test= retList.Where<PerformanceItem>(p => p.isDanger());
  214. //await InitRules(true);
  215. ////return;
  216. //await ImportUsers();
  217. await InputPerformanceItem("c:\\temp\\21.01-21.11 工程师绩效报表-总表.xlsx", true, false, 0);
  218. ////CalMonth cal = new CalMonth()
  219. ////{
  220. //// Year = 2021,
  221. //// Month = 9,
  222. //// Status = 0
  223. ////};
  224. ////await InputPerformanceItem(@"C:\Users\luowen\Downloads\每月绩效统计--发客户超过一个月未完成案件.xlsx", true,false,1, cal);
  225. ////await InputPerformanceItem(@"C:\Users\luowen\Downloads\每月绩效统计--上个月递交完成案件.xlsx", true, false, 1, cal);
  226. ////await InputPerformanceItem(@"C:\Users\luowen\Downloads\每月绩效统计--中国一次OA授权表.xlsx", true, false, 1, cal,true);
  227. //MessageBox.Show("导入完成!");
  228. }
  229. private PerformanceItem Row2Item_1(DataRow row, List<Staff> Staffs, CalMonth calMonth)
  230. {
  231. PerformanceItem item = new PerformanceItem();
  232. item.ApplicationType = row["申请类型"].ToString().Trim();
  233. if(item.ApplicationType != "发明")
  234. {
  235. return null;
  236. }
  237. item.CaseNo = row["我方文号"].ToString().Trim();
  238. if (calMonth != null)
  239. {
  240. item.CalMonth = calMonth;
  241. }
  242. else
  243. {
  244. if (row.Table.Columns.Contains("绩效核算月份"))
  245. {
  246. string strjxyf = row["绩效核算月份"].ToString().Trim();
  247. string[] temYFs = strjxyf.Split(new char[] { '.' });
  248. item.CalMonth = new CalMonth();
  249. item.CalMonth.Year = int.Parse(temYFs[0]);
  250. item.CalMonth.Month = int.Parse(temYFs[1]);
  251. item.CalMonth.Status = 4;
  252. }
  253. else
  254. {
  255. item.CalMonth = new CalMonth();
  256. item.Status = 0;
  257. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  258. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  259. }
  260. }
  261. item.ApplicationType = row["申请类型"].ToString().Trim();
  262. item.BusinessType = "普通新申请"; // row["业务类型"].ToString().Trim();
  263. item.AgentFeedbackMemo = "发明一次OA授权"; //row["备注(填表注意事项)"].ToString().Trim();
  264. item.DoItem = "发明一次OA授权"; //row["处理事项"].ToString().Trim();
  265. string strHandler = "";
  266. if (row.Table.Columns.Contains("处理人"))
  267. {
  268. strHandler = row["处理人"].ToString().Trim();
  269. }
  270. else
  271. {
  272. if (row.Table.Columns.Contains("案件处理人"))
  273. {
  274. strHandler = row["案件处理人"].ToString().Trim();
  275. }
  276. }
  277. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  278. item.ItemStaffs = new List<ItemStaff>();
  279. foreach (string name in temHandlers)
  280. {
  281. ItemStaff itemStaff = new ItemStaff();
  282. int? iTem = GetStaff(name, Staffs);
  283. if ((iTem != null))
  284. {
  285. //itemStaff.Item = item;
  286. itemStaff.DoPersonId = iTem.Value;
  287. item.ItemStaffs.Add(itemStaff);
  288. }
  289. else
  290. {
  291. itemStaff.DoPerson = new Staff()
  292. {
  293. Name = name,
  294. Account = name,
  295. Password = "12345678",
  296. IsCalPerformsnce = false,
  297. Status = "正式员工",
  298. StaffGradeId = 4
  299. };
  300. item.ItemStaffs.Add(itemStaff);
  301. }
  302. }
  303. if (item.ItemStaffs.Count == 0)
  304. {
  305. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  306. }
  307. if (row.Table.Columns.Contains("核稿人"))
  308. {
  309. item.ReviewerId = GetStaff(row["核稿人"].ToString().Trim(), Staffs);
  310. }
  311. else
  312. {
  313. if (row.Table.Columns.Contains("案件核稿人"))
  314. {
  315. item.ReviewerId = GetStaff(row["案件核稿人"].ToString().Trim(), Staffs);
  316. }
  317. }
  318. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  319. item.ApplicationName = row["申请人"].ToString().Trim();
  320. item.CaseName = row["案件名称"].ToString().Trim();
  321. //案件备注
  322. item.CaseMemo = $"发文日期:{row["发文日期"].ToString().Trim()}\r\n客户文号:{row["客户文号"].ToString().Trim()}\r\n上传日期:{row["上传日期"].ToString().Trim()}\r\n文件描述:{row["文件描述"].ToString().Trim()}";
  323. return item;
  324. }
  325. private PerformanceItem Row2Item(DataRow row, List<Staff> Staffs,CalMonth calMonth)
  326. {
  327. PerformanceItem item = new PerformanceItem();
  328. item.CaseNo = row["我方文号"].ToString().Trim();
  329. if (calMonth != null)
  330. {
  331. item.CalMonth = calMonth;
  332. }
  333. else
  334. {
  335. if (row.Table.Columns.Contains("绩效核算月份"))
  336. {
  337. string strjxyf = row["绩效核算月份"].ToString().Trim();
  338. string[] temYFs = strjxyf.Split(new char[] { '.' });
  339. item.CalMonth = new CalMonth();
  340. item.CalMonth.Year = int.Parse(temYFs[0]);
  341. if (temYFs[1] == "1")
  342. {
  343. temYFs[1] = "10";
  344. }
  345. item.CalMonth.Month = int.Parse(temYFs[1]);
  346. item.CalMonth.Status = 4;
  347. }
  348. else
  349. {
  350. item.CalMonth = new CalMonth();
  351. item.Status = 0;
  352. item.CalMonth.Year = DateTime.Now.AddMonths(-1).Year;
  353. item.CalMonth.Month = DateTime.Now.AddMonths(-1).Month;
  354. }
  355. }
  356. item.ApplicationType = row["申请类型"].ToString().Trim();
  357. item.BusinessType = row["业务类型"].ToString().Trim();
  358. if (row.Table.Columns.Contains("备注(填表注意事项)"))
  359. item.AgentFeedbackMemo = row["备注(填表注意事项)"].ToString().Trim();
  360. item.DoItem = row["处理事项"].ToString().Trim();
  361. item.CaseStage = row["案件阶段"].ToString().Trim();
  362. item.CaseCoefficient = row["案件系数"].ToString().Trim();
  363. item.DoItemCoefficient = row["处理事项系数"].ToString().Trim();
  364. item.PreOastaffId = GetStaff(row["前一次OA处理人"].ToString().Trim(), Staffs);
  365. string strHandler = "";
  366. if (row.Table.Columns.Contains("处理人"))
  367. {
  368. strHandler = row["处理人"].ToString().Trim();
  369. }
  370. else
  371. {
  372. if (row.Table.Columns.Contains("案件处理人"))
  373. {
  374. strHandler = row["案件处理人"].ToString().Trim();
  375. }
  376. }
  377. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  378. item.ItemStaffs = new List<ItemStaff>();
  379. foreach (string name in temHandlers)
  380. {
  381. ItemStaff itemStaff = new ItemStaff();
  382. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  383. int? iTem = GetStaff(temName, Staffs);
  384. if ((iTem != null))
  385. {
  386. //itemStaff.Item = item;
  387. itemStaff.DoPersonId = iTem.Value;
  388. item.ItemStaffs.Add(itemStaff);
  389. }
  390. else
  391. {
  392. itemStaff.DoPerson = new Staff()
  393. {
  394. Name = temName,
  395. Account = temName,
  396. Password = "12345678",
  397. IsCalPerformsnce = false,
  398. Status = "已离职",
  399. StaffGradeId = 4
  400. };
  401. item.ItemStaffs.Add(itemStaff);
  402. }
  403. }
  404. if (item.ItemStaffs.Count == 0)
  405. {
  406. System.Diagnostics.Debug.WriteLine($"没有处理人: {item.CaseNo}\t{item.DoItem}");
  407. }
  408. if (row.Table.Columns.Contains("核稿人"))
  409. {
  410. if (!string.IsNullOrEmpty(row["核稿人"].ToString().Trim()))
  411. {
  412. string temName = row["核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  413. item.ReviewerId = GetStaff(temName.Trim(), Staffs);
  414. }
  415. }
  416. else
  417. {
  418. if (row.Table.Columns.Contains("案件核稿人"))
  419. {
  420. if (!string.IsNullOrEmpty(row["案件核稿人"].ToString().Trim()))
  421. {
  422. string temName = row["案件核稿人"].ToString().Trim().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  423. item.ReviewerId = GetStaff(temName.Trim(), Staffs);
  424. }
  425. }
  426. }
  427. if (!string.IsNullOrEmpty(row["点数"].ToString().Trim())) {
  428. item.BasePoint = double.Parse(row["点数"].ToString().Trim());
  429. }
  430. item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
  431. item.ApplicationName = row["申请人"].ToString().Trim();
  432. DateTime temDate = new DateTime();
  433. if (DateTime.TryParse(row["处理事项完成日"].ToString().Trim(), out temDate))
  434. {
  435. item.FinishedDate = temDate;
  436. }
  437. //定稿日
  438. if (DateTime.TryParse(row["定稿日"].ToString().Trim(), out temDate))
  439. {
  440. item.FinalizationDate = temDate;
  441. }
  442. //返稿日
  443. if (DateTime.TryParse(row["返稿日"].ToString().Trim(), out temDate))
  444. {
  445. item.ReturnDate = temDate;
  446. }
  447. //案件类型
  448. item.CaseType = row["案件类型"].ToString().Trim();
  449. //案件状态
  450. item.CaseState = row["案件状态"].ToString().Trim();
  451. //处理事项备注
  452. item.DoItemMemo = row["处理事项备注"].ToString().Trim();
  453. //处理状态
  454. item.DoItemState = row["处理状态"].ToString().Trim();
  455. //案件名称
  456. item.CaseName = row["案件名称"].ToString().Trim();
  457. //委案日期
  458. if (DateTime.TryParse(row["委案日期"].ToString().Trim(), out temDate))
  459. {
  460. item.EntrustingDate = temDate;
  461. }
  462. //客户期限
  463. if (DateTime.TryParse(row["客户期限"].ToString().Trim(), out temDate))
  464. {
  465. item.CustomerLimitDate = temDate;
  466. }
  467. //内部期限
  468. if (DateTime.TryParse(row["内部期限"].ToString().Trim(), out temDate))
  469. {
  470. item.InternalDate = temDate;
  471. }
  472. //初稿日
  473. if (DateTime.TryParse(row["初稿日"].ToString().Trim(), out temDate))
  474. {
  475. item.FirstDraftDate = temDate;
  476. }
  477. //备注(发文严重超期是否属客观原因,若为否,请填写原因)
  478. if (row.Table.Columns.Contains("备注(发文严重超期是否属客观原因,若为否,请填写原因)"))
  479. {
  480. item.OverDueMemo = row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"].ToString().Trim();
  481. }
  482. //案件备注
  483. item.CaseMemo = row["案件备注"].ToString().Trim();
  484. return item;
  485. }
  486. private async Task InputPerformanceItem(string strExcelFile,bool isColumnName,bool ignorHideRows=false,int ColumnNameRow=0,CalMonth calMonth=null,bool isFirstOAFile=false)
  487. {
  488. DataTable dt = NPOIExcel.ExcelToDataTable(strExcelFile, isColumnName,ignorHideRows,ColumnNameRow);
  489. #region 删除重复行
  490. DataTable temdt = new DataTable();
  491. foreach (DataColumn col in dt.Columns)
  492. {
  493. DataColumn temCol = new DataColumn();
  494. temCol.ColumnName = col.ColumnName;
  495. temCol.DataType = col.DataType;
  496. temCol.Caption = col.Caption;
  497. temdt.Columns.Add(temCol);
  498. }
  499. new ExcelHelper().MerageDataTable(temdt, dt);
  500. #endregion
  501. List<Staff> Staffs =await GetStaffsAsync();
  502. foreach(DataRow row in temdt.Rows)
  503. {
  504. PerformanceItem item = null;
  505. if (isFirstOAFile)
  506. {
  507. item = Row2Item_1(row, Staffs, calMonth);
  508. }
  509. else
  510. {
  511. item = Row2Item(row, Staffs, calMonth);
  512. }
  513. if (item != null )
  514. {
  515. System.Diagnostics.Debug.WriteLine($"{DateTime.Now}\t{item.CaseNo}\t{item.CaseName}");
  516. if (!InValidDoItem.Contains(item.DoItem))
  517. {
  518. await SavePerformanceItem(item);
  519. }
  520. }
  521. }
  522. }
  523. private int? GetStaff(string v, List<Staff> staffs)
  524. {
  525. if (!string.IsNullOrEmpty(v))
  526. {
  527. string[] temNames = v.Trim().Split(new char[] { '-' },StringSplitOptions.RemoveEmptyEntries);
  528. foreach (Staff sf in staffs)
  529. {
  530. if(sf.Name == temNames[0])
  531. {
  532. return sf.Id;
  533. }
  534. }
  535. }
  536. return null;
  537. }
  538. private async Task ImportUsers()
  539. {
  540. DataTable dt = NPOIExcel.ExcelToDataTable(@"C:\temp\用户列表(2021年10月26日).xlsx", true,false,1);
  541. List<StaffGrade> staffGrades = await GetStaffGrades();
  542. foreach (DataRow row in dt.Rows)
  543. {
  544. Staff staff = new Staff();
  545. staff.Account = row["用户名"].ToString().Trim();
  546. staff.Name = row["姓名"].ToString().Trim();
  547. staff.Tel = row["电话号码"].ToString().Trim();
  548. staff.Mobile = row["手机号码"].ToString().Trim();
  549. staff.Sex = row["性别"].ToString().Trim();
  550. staff.Mail = row["邮箱"].ToString().Trim();
  551. string strGrade = row["工程师等级"].ToString().Trim(); // + "级";
  552. foreach (StaffGrade sg in staffGrades)
  553. {
  554. if (strGrade.Trim() == sg.Grade.Trim())
  555. {
  556. staff.StaffGradeId = sg.Id;
  557. break;
  558. }
  559. }
  560. staff.IsOnJob = (row["是否在职"].ToString().Trim()=="是");
  561. staff.Status = row["岗位状态"].ToString().Trim();
  562. staff.Department = row["部门"].ToString();
  563. staff.WorkPlace = row["工作地"].ToString();
  564. DateTime temDate;
  565. if (DateTime.TryParse(row["入职时间"].ToString(), out temDate))
  566. {
  567. staff.EntyDate = temDate;
  568. }
  569. //staff.IsCalPerformsnce = (row["是否核算绩效"].ToString() == "是");
  570. //staff.Memo = row["备注"].ToString().Trim();
  571. staff.Password = MD5Utility.GetMD5("12345678");
  572. //staff.StaffGradeId = row["姓名"].ToString();
  573. await SaveStaff(staff);
  574. }
  575. }
  576. private string getPinYin(string str)
  577. {
  578. string retStr = "";
  579. for(int i = 0; i < str.Length; i++)
  580. {
  581. ChineseChar cc = new ChineseChar(str[i]);
  582. retStr = retStr + cc.Pinyins[0].ToLower().Replace("1","")
  583. .Replace("2", "").Replace("3", "").Replace("4", "");
  584. }
  585. return retStr;
  586. }
  587. string strAPIBaseUri = "http://47.106.221.167:8081";
  588. public async Task<entity.workflowDefine.Workflow> GetWorkflow(int Id, HttpClient _httpClient)
  589. {
  590. var ret = await _httpClient.GetFromJsonAsync<entity.workflowDefine.Workflow>($"{strAPIBaseUri}/api/WorkflowEngine/GetWorkflow?workflowId={Id}");
  591. return ret;
  592. }
  593. public async Task<List<entity.workflowDefine.Step>> GetSteps(int Id, HttpClient _httpClient)
  594. {
  595. var ret = await _httpClient.GetFromJsonAsync<List<entity.workflowDefine.Step>>($"{strAPIBaseUri}/api/WorkflowEngine/GetSteps?workflowId={Id}");
  596. return ret;
  597. }
  598. public async Task<List<entity.workflowDefine.Action>> GetActions(int workflowId, HttpClient _httpClient)
  599. {
  600. var ret = await _httpClient.GetFromJsonAsync<List<entity.workflowDefine.Action>>($"{strAPIBaseUri}/api/WorkflowEngine/GetActions?workflowId={workflowId}");
  601. return ret;
  602. }
  603. public async Task<List<entity.workflowDefine.TrasferCondition>> GetTransfers(int workflowId, HttpClient _httpClient)
  604. {
  605. var ret = await _httpClient.GetFromJsonAsync<List<entity.workflowDefine.TrasferCondition>>($"{strAPIBaseUri}/api/WorkflowEngine/GetTrasfers?workflowId={workflowId}");
  606. return ret;
  607. }
  608. private async Task SaveStaff(Staff obj)
  609. {
  610. HttpClient http = new HttpClient();
  611. var data = await http.PostAsJsonAsync<wispro.sp.entity.Staff>($"{strAPIBaseUri}/api/Staff/Save", obj);
  612. if (data.IsSuccessStatusCode)
  613. {
  614. ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
  615. //await Task.Delay(1000);
  616. if (result.Success)
  617. {
  618. }
  619. else
  620. {
  621. }
  622. }
  623. else
  624. {
  625. }
  626. }
  627. private async Task SaveBasePointRule(BasePointRule obj)
  628. {
  629. HttpClient http = new HttpClient();
  630. var data = await http.PostAsJsonAsync<BasePointRule>($"{strAPIBaseUri}/api/BasePointRule/New", obj);
  631. if (data.IsSuccessStatusCode)
  632. {
  633. ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
  634. //await Task.Delay(1000);
  635. if (result.Success)
  636. {
  637. }
  638. else
  639. {
  640. System.Diagnostics.Debug.WriteLine($"保存错误: {obj.Rule}\t{obj.PointExpress}\r\n{result.ErrorMessage}");
  641. }
  642. }
  643. else
  644. {
  645. System.Diagnostics.Debug.WriteLine($"调用API错误: {obj.Type}\t{obj.Rule}");
  646. }
  647. }
  648. private async Task SavePerformanceItem(PerformanceItem obj)
  649. {
  650. HttpClient http = new HttpClient();
  651. if (obj.CalMonth.Month == 10)
  652. {
  653. System.Diagnostics.Debug.WriteLine($"{obj.CalMonth.Year}-{obj.CalMonth.Month}\t{obj.CaseNo}");
  654. }
  655. var isExist = await http.PostAsJsonAsync<PerformanceItem>($"{strAPIBaseUri}/api/PerformanceItem/IsExist", obj);
  656. if (isExist.IsSuccessStatusCode && await isExist.Content.ReadFromJsonAsync<bool>()==false)
  657. {
  658. var data = await http.PostAsJsonAsync<PerformanceItem>($"{strAPIBaseUri}/api/PerformanceItem/New", obj);
  659. if (data.IsSuccessStatusCode)
  660. {
  661. ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
  662. //await Task.Delay(1000);
  663. if (result.Success)
  664. {
  665. }
  666. else
  667. {
  668. System.Diagnostics.Debug.WriteLine($"保存错误: {obj.CaseNo}\t{obj.DoItem}\r\n{result.ErrorMessage}");
  669. }
  670. }
  671. else
  672. {
  673. System.Diagnostics.Debug.WriteLine($"调用API错误: {obj.CaseNo}\t{obj.DoItem}");
  674. }
  675. }
  676. }
  677. private async Task<List<StaffGrade>> GetStaffGrades()
  678. {
  679. HttpClient http = new HttpClient();
  680. var _StaffGrade = await http.GetFromJsonAsync<List<StaffGrade>>($"{strAPIBaseUri}/api/StaffGrade/GetAll");
  681. return _StaffGrade;
  682. }
  683. private async Task<List<Staff>> GetStaffsAsync()
  684. {
  685. HttpClient http = new HttpClient();
  686. ListApiResponse<Staff> data = await http.GetFromJsonAsync<ListApiResponse<Staff>>($"{strAPIBaseUri}/api/Staff/Query?pageIndex=1&pageSize=200");
  687. return data.Results;
  688. }
  689. private void button4_Click(object sender, EventArgs e)
  690. {
  691. Stopwatch watch = new Stopwatch();
  692. watch.Start();
  693. dynamic retObj = wispro.sp.utility.IPEasyUtility.GetPerformanceRecord("S2112392-洗碗机调查分析","提出报告");
  694. PerformanceItem Item = new PerformanceItem();
  695. Item.CaseName = retObj.CaseName;
  696. Item.CaseNo = retObj.CaseNo;
  697. Item.DoItem = retObj.DoItem;
  698. Item.CustomerLimitDate = string.IsNullOrEmpty(retObj.CustomerLimitDate) ? null : DateTime.Parse(retObj.CustomerLimitDate);
  699. Item.Customer = new Customer();
  700. Item.Customer.Name = retObj.CustomerName;
  701. Item.DoItemCoefficient = retObj.DoItemCoefficient;
  702. Item.DoItemMemo = retObj.DoItemMemo;
  703. Item.DoItemState = retObj.DoItemState;
  704. Item.EntrustingDate = string.IsNullOrEmpty(retObj.EntrustingDate) ? null : DateTime.Parse(retObj.EntrustingDate);
  705. Item.FinalizationDate = string.IsNullOrEmpty(retObj.FinalizationDate) ? null : DateTime.Parse(retObj.FinalizationDate);
  706. Item.FinishedDate = string.IsNullOrEmpty(retObj.FinishedDate) ? null : DateTime.Parse(retObj.FinishedDate);
  707. //Item.FirstDraftDate = string.IsNullOrEmpty(retObj.FirstDraftDate) ? null : DateTime.Parse(retObj.FirstDraftDate);
  708. Item.InternalDate = string.IsNullOrEmpty(retObj.InternalDate) ? null : DateTime.Parse(retObj.InternalDate);
  709. if (!string.IsNullOrEmpty(retObj.DoPersons))
  710. {
  711. Item.ItemStaffs = new List<ItemStaff>();
  712. string[] names = retObj.DoPersons.ToString().Split(new char[] { ','},StringSplitOptions.RemoveEmptyEntries);
  713. foreach(var name in names)
  714. {
  715. ItemStaff iStaff = new ItemStaff();
  716. iStaff.DoPerson = new Staff() { Name = name };
  717. Item.ItemStaffs.Add(iStaff);
  718. }
  719. }
  720. Item.ReturnDate = string.IsNullOrEmpty(retObj.ReturnDate) ? null : DateTime.Parse(retObj.ReturnDate);
  721. if (!string.IsNullOrEmpty(retObj.Reviewer))
  722. {
  723. Item.Reviewer = new Staff() { Name = retObj.Reviewer };
  724. }
  725. Item.ApplicationType = retObj.ApplicationType;
  726. Item.BusinessType = retObj.BusinessType;
  727. Item.CaseCoefficient = retObj.CaseCoefficient;
  728. Item.CaseMemo = retObj.CaseMemo;
  729. Item.CaseStage = retObj.CaseStage;
  730. Item.CaseState = retObj.CaseState;
  731. Item.CaseType = retObj.CaseType;
  732. watch.Stop();
  733. System.Diagnostics.Debug.WriteLine("用时{0}毫秒", watch.ElapsedMilliseconds);//获取当前实例测量得出的总运行时间(以毫秒为单位)
  734. //wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--上个月递交完成案件", true);
  735. //wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--发客户超过一个月未完成案件", false);
  736. //wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--中国一次OA授权表", true);
  737. ////每月绩效统计--发客户超过一个月未完成案件
  738. //NewMethod("506aa7ad-c3f4-4ec6-9ec8-ff6b92dcd7c1", "每月绩效统计--发客户超过一个月未完成案件.xlsx", calMonth);
  739. ////每月绩效统计--上个月递交完成案件
  740. //NewMethod("d7308cd2-71e4-4444-9f47-f4d731ddb26a", "每月绩效统计--上个月递交完成案件.xlsx", calMonth);
  741. ////每月绩效统计--中国一次OA授权表
  742. //NewMethod("72454834-afdd-4b98-b42a-0bc912d07610", "每月绩效统计--中国一次OA授权表.xlsx", calMonth, true);
  743. }
  744. }
  745. }