AppealController.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.EntityFrameworkCore;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Reflection;
  12. using System.Text.Json.Serialization;
  13. using System.Text.Json;
  14. using System.Threading.Tasks;
  15. using wispro.sp.api.Job;
  16. using wispro.sp.entity;
  17. using wispro.sp.share;
  18. using Fizzler;
  19. using static wispro.sp.api.Controllers.PerformanceItemController;
  20. using System.Threading;
  21. using wispro.sp.api.Services;
  22. using Microsoft.Data.SqlClient;
  23. using System.Data;
  24. using wispro.sp.utility;
  25. using OpenQA.Selenium.DevTools.V85.CSS;
  26. namespace wispro.sp.api.Controllers
  27. {
  28. [Route("api/[controller]/[action]")]
  29. [ApiController]
  30. //[Authorize]
  31. public class AppealController : ControllerBase
  32. {
  33. spDbContext Context;
  34. IFileTaskService fileTaskService;
  35. public AppealController(spDbContext context, IFileTaskService _fileTaskService)
  36. {
  37. Context = context;
  38. fileTaskService = _fileTaskService;
  39. }
  40. public List<AppealType> GetAppealTypes()
  41. {
  42. return Context.AppealTypes.ToList();
  43. }
  44. /// <summary>
  45. /// 统计指定客户、指定月份新申请案件各案件系数的案件数量
  46. /// </summary>
  47. /// <param name="CustomerId">指定客户Id</param>
  48. /// <param name="CalmonthId">指定月份Id</param>
  49. /// <returns></returns>
  50. public CaseCoefficientStatistics GetCCSRecord(int? CustomerId,int CalmonthId)
  51. {
  52. CaseCoefficientStatistics retObject = new CaseCoefficientStatistics();
  53. if(CustomerId != null)
  54. {
  55. retObject.customer = Context.Customers.FirstOrDefault(c => c.Id == CustomerId);
  56. }
  57. var myGroups = Context.PerformanceItems
  58. .Where(p=>
  59. p.Type=="新申请"
  60. && (p.AgentFeedbackMemo != "已算绩效" || string.IsNullOrEmpty(p.AgentFeedbackMemo))
  61. && p.CalMonthId == CalmonthId
  62. && p.CustomerId == CustomerId)
  63. .GroupBy(p => p.CaseCoefficient)
  64. .Select(g => new { CaseCoefficient = g.Key, Count = g.Count() });
  65. if(CustomerId == null)
  66. {
  67. myGroups = Context.PerformanceItems
  68. .Where(p =>
  69. p.Type == "新申请"
  70. && (p.AgentFeedbackMemo != "已算绩效" || string.IsNullOrEmpty(p.AgentFeedbackMemo))
  71. && p.CalMonthId == CalmonthId)
  72. .GroupBy(p => p.CaseCoefficient)
  73. .Select(g => new { CaseCoefficient = g.Key, Count = g.Count() });
  74. }
  75. foreach (var g in myGroups)
  76. {
  77. string strKey = ( string.IsNullOrEmpty(g.CaseCoefficient)) ? "B" : g.CaseCoefficient;
  78. switch (strKey)
  79. {
  80. case "A":
  81. retObject.ACount += g.Count;
  82. retObject.Totals += g.Count;
  83. break;
  84. case "S":
  85. retObject.SCount += g.Count;
  86. retObject.Totals += g.Count;
  87. break;
  88. default:
  89. retObject.Totals += g.Count;
  90. break;
  91. }
  92. }
  93. return retObject;
  94. #region SQL
  95. //string strSQL = $"SELECT CaseCoefficient,count(*) as CaseCoefficientCount " +
  96. // "FROM PerformanceItem " +
  97. // $"where CalMonthId = {CalmonthId} and CustomerId = {CustomerId} and Type = '新申请' and(AgentFeedbackMemo <> '已算绩效' or AgentFeedbackMemo is null) " +
  98. // "group by CaseCoefficient";
  99. //var conn= Context.Database.GetDbConnection();
  100. //if(conn.State != System.Data.ConnectionState.Open)
  101. //{
  102. // conn.Open();
  103. //}
  104. //try
  105. //{
  106. // var cmd = conn.CreateCommand();
  107. // cmd.CommandText = strSQL;
  108. // var reader = cmd.ExecuteReader();
  109. // while (reader.Read())
  110. // {
  111. // string strKey = (reader.IsDBNull(0) || string.IsNullOrEmpty(reader.GetString(0))) ? "B" : reader.GetString(0);
  112. // switch (strKey)
  113. // {
  114. // case "A":
  115. // retObject.ACount += reader.GetInt32(1);
  116. // retObject.Totals += reader.GetInt32(1);
  117. // break;
  118. // case "S":
  119. // retObject.SCount += reader.GetInt32(1);
  120. // retObject.Totals += reader.GetInt32(1);
  121. // break;
  122. // default:
  123. // retObject.Totals += reader.GetInt32(1);
  124. // break;
  125. // }
  126. // }
  127. // cmd.Dispose();
  128. // return retObject;
  129. //}
  130. //catch (Exception ex)
  131. //{
  132. // throw ex;
  133. //}
  134. //finally
  135. //{
  136. // conn.Close();
  137. //}
  138. #endregion
  139. }
  140. public FileProcessTask GetStaticsReport(int CalMonthId)
  141. {
  142. CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Id == CalMonthId);
  143. if (calMonth != null)
  144. {
  145. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}客户案件系数统计.xlsx";
  146. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  147. var filePath = Path.Combine(attachfileSavePath, filename);
  148. var fileTask = new FileProcessTask()
  149. {
  150. Id = Guid.NewGuid().ToString(),
  151. FileName = filename,
  152. FilePath = filePath,
  153. Processed = 0
  154. };
  155. fileTaskService.Add(fileTask);
  156. ExportDataResult result = new ExportDataResult()
  157. {
  158. fileTask = fileTask,
  159. calMonth = calMonth
  160. };
  161. ExportStaticReport(result);
  162. //System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportStaticReport));
  163. //t.Start(result);
  164. return fileTask;
  165. }
  166. return null;
  167. }
  168. private void ExportStaticReport(object exportDataResult)
  169. {
  170. ExportDataResult result = (ExportDataResult)exportDataResult;
  171. FileProcessTask file = result.fileTask;
  172. CalMonth calMonth = result.calMonth;
  173. var retList = GetCCSRecords(calMonth.Id);
  174. DataTable dt = new DataTable();
  175. dt.Columns.Add("客户名称");
  176. dt.Columns.Add("S案件阈值");
  177. dt.Columns.Add("A案件阈值");
  178. dt.Columns.Add("案件总数",typeof(int));
  179. dt.Columns.Add("S案件数", typeof(int));
  180. dt.Columns.Add("A案件数", typeof(int));
  181. foreach(var ccsObj in retList)
  182. {
  183. var row = dt.NewRow();
  184. row["客户名称"] = ccsObj.customer.Name;
  185. row["S案件阈值"] =$"{((ccsObj.customer.SRate == null) ? 5: ccsObj.customer.SRate)}%" ;
  186. row["A案件阈值"] = $"{((ccsObj.customer.ARate == null) ? 30: ccsObj.customer.ARate)}%";
  187. row["案件总数"] = ccsObj.Totals;
  188. row["S案件数"] = ccsObj.SCount;
  189. row["A案件数"] = ccsObj.ACount;
  190. dt.Rows.Add(row);
  191. }
  192. NPOIExcel.DataTableToExcel(dt, result.fileTask.FilePath);
  193. result.fileTask.Finished = true;
  194. }
  195. public List<CaseCoefficientStatistics> GetCCSRecords(int CalmonthId)
  196. {
  197. var AllCustomers = Context.Customers.ToList();
  198. var myGroups = Context.PerformanceItems
  199. .Where(p =>
  200. p.Type == "新申请"
  201. && (p.AgentFeedbackMemo != "已算绩效" || string.IsNullOrEmpty(p.AgentFeedbackMemo))
  202. && p.CalMonthId == CalmonthId)
  203. .GroupBy(p => new { CustomerId = p.CustomerId, CaseCeoffcient = p.CaseCoefficient })
  204. .Select(g => new { CaseCoefficient = g.Key.CaseCeoffcient,CustomerId=g.Key.CustomerId, Count = g.Count() });
  205. List<CaseCoefficientStatistics> retList= new List<CaseCoefficientStatistics>();
  206. foreach (var g in myGroups)
  207. {
  208. CaseCoefficientStatistics temObject = retList.Where(p=>p.customer.Id == g.CustomerId).FirstOrDefault();
  209. if(temObject == null)
  210. {
  211. temObject = new CaseCoefficientStatistics() {
  212. customer = AllCustomers.FirstOrDefault(c => c.Id == g.CustomerId)
  213. };
  214. retList.Add(temObject);
  215. }
  216. string strKey = g.CaseCoefficient;
  217. switch (strKey)
  218. {
  219. case "A":
  220. temObject.ACount += g.Count;
  221. temObject.Totals += g.Count;
  222. break;
  223. case "S":
  224. temObject.SCount += g.Count;
  225. temObject.Totals += g.Count;
  226. break;
  227. default:
  228. temObject.Totals += g.Count;
  229. break;
  230. }
  231. }
  232. return retList;
  233. }
  234. public List<InputField> GetInputField(int appealTypeId, int state)
  235. {
  236. var retList = Context.InputFields
  237. .Where<InputField>(ip => ip.AppealTypeId == appealTypeId && ip.AppealState == state)
  238. .Include(p => p.SelectValues)
  239. .ToList();
  240. string str = System.Text.Json.JsonSerializer.Serialize(retList, new JsonSerializerOptions()
  241. {
  242. ReferenceHandler = ReferenceHandler.Preserve
  243. });
  244. Log(str);
  245. foreach (var inputField in retList)
  246. {
  247. if (inputField.SelectValues != null)
  248. {
  249. foreach(var ifValue in inputField.SelectValues)
  250. {
  251. ifValue.InputField = null;
  252. }
  253. }
  254. }
  255. return retList;
  256. }
  257. /// <summary>
  258. /// 创建申诉流程
  259. /// </summary>
  260. /// <param name="ItemId"></param>
  261. /// <param name="typeid"></param>
  262. /// <param name="reviewerId"></param>
  263. /// <param name="appealObject"></param>
  264. /// <returns></returns>
  265. public ApiSaveResponse CreateAppeal(int ItemId, int typeid, int reviewerId, AppealObject appealObject)
  266. {
  267. ApiSaveResponse response = new ApiSaveResponse();
  268. response.Success = true;
  269. AppealRecord appealRecord = new AppealRecord();
  270. if(ItemId > 0)
  271. {
  272. appealRecord.ItemId = ItemId;
  273. }
  274. else
  275. {
  276. appealRecord.ItemId = null;
  277. }
  278. appealRecord.TypeId = typeid;
  279. appealRecord.ReviewerId = reviewerId;
  280. appealRecord.CreaterId = Context.Staffs.Where<Staff>(s => s.Name == User.Identity.Name).FirstOrDefault().Id;
  281. appealRecord.CreateTime = DateTime.Now;
  282. var t = Context.Database.BeginTransaction();
  283. try
  284. {
  285. Context.AppealRecords.Add(appealRecord);
  286. Context.SaveChanges();
  287. foreach (var fieldValue in appealObject.inputFieldValues)
  288. {
  289. fieldValue.InputField = null;
  290. fieldValue.AppealRecordId = appealRecord.Id;
  291. }
  292. Context.InputFieldValues.AddRange(appealObject.inputFieldValues);
  293. foreach (var file in appealObject.attachFiles)
  294. {
  295. var temFile = Context.AttachFiles.Where<AttachFile>(f => f.Id == file.Id).FirstOrDefault();
  296. temFile.AppealRecordId = appealRecord.Id;
  297. temFile.UploadUserId = appealRecord.CreaterId;
  298. }
  299. Context.SaveChanges();
  300. var temType = Context.AppealTypes.FirstOrDefault(c=>c.Id == appealRecord.TypeId);
  301. if (!string.IsNullOrEmpty(temType.ApplealObject))
  302. {
  303. IDoAppealObject doAppeal = (IDoAppealObject)Activator.CreateInstance(Type.GetType(appealRecord.Type.ApplealObject));
  304. doAppeal.DoAppeal(appealObject, appealRecord.Id, Context);
  305. }
  306. t.Commit();
  307. var Reviewer = Context.Staffs.Where<Staff>(s => s.Id == appealRecord.ReviewerId).FirstOrDefault();
  308. if(appealRecord.Type == null)
  309. {
  310. appealRecord.Type = Context.AppealTypes.FirstOrDefault(p=>p.Id == appealRecord.TypeId);
  311. }
  312. string strSubject = appealRecord.Type.Name;
  313. string strBody = $"<div style=\"position:absolute;width:800;height:300;margin-top:50px;margin-left:200px;margin-right:200px;box-shadow:0px 0px 3px 3px #ccc \"><div style= \"margin-top: 20px; margin-left:20px;;font-size:14px; \">{Reviewer.Name},您好!</div><div style= \"margin-top: 25px; margin-left:20px;font-size:14px; \"><div>{User.Identity.Name} 向您提交了{appealRecord.Type.Name}申诉,请使用<a href= \"http://1.116.113.26\">绩效系统</a>在<B>{utility.ConfigHelper.GetSectionValue("Lastest_feedback_date")}日</B>前完成审核!</div><div style= \"margin-top: 100px;margin-right:15px; padding-bottom: 20px; font-size:14px;color:#888888;float:right; \">小美集团绩效管理系统</div></div>";
  314. string strTo = Reviewer.Mail;
  315. if (!string.IsNullOrEmpty(strTo))
  316. {
  317. _ = QuartzUtil.AddMailJob(strSubject, strBody, Reviewer.Name, strTo);
  318. }
  319. strBody = $"<div style=\"position:absolute;width:800;height:300;margin-top:50px;margin-left:200px;margin-right:200px;box-shadow:0px 0px 3px 3px #ccc \"><div style= \"margin-top: 20px; margin-left:20px;;font-size:14px; \">{Reviewer.Name},您好!</div><div style= \"margin-top: 25px; margin-left:20px;font-size:14px; \"><div>{User.Identity.Name} 向您提交了{appealRecord.Type.Name}申诉,请使用<a href= \"http://1.116.113.26\">绩效系统</a>查看详情!</div><div style= \"margin-top: 100px;margin-right:15px; padding-bottom: 20px; font-size:14px;color:#888888;float:right; \">小美集团绩效管理系统</div></div>";
  320. _ = QuartzUtil.AddMailJob(strSubject, strBody, "钟子敏", "zhongzimin@china-wispro.com");
  321. //_ = QuartzUtil.AddMailJob(strSubject, strBody, "夏敏", "xiamin@china-wispro.com");
  322. _ = QuartzUtil.AddMailJob(strSubject, strBody, "吴芳", "wufang@china-wispro.com");
  323. return response;
  324. }
  325. catch (Exception ex)
  326. {
  327. t.Rollback();
  328. response.Success = false;
  329. response.ErrorMessage = "申诉时发生错误!";
  330. return response;
  331. }
  332. }
  333. public ApiSaveResponse ReviewerAppeal(int appealRecordId,AppealObject appealObject)
  334. {
  335. ApiSaveResponse response = new ApiSaveResponse();
  336. response.Success = true;
  337. var appealRecord = Context.AppealRecords.Where<AppealRecord>(p => p.Id == appealRecordId).FirstOrDefault();
  338. if(appealRecord != null)
  339. {
  340. if (appealRecord.ItemId.HasValue)
  341. {
  342. var item = Context.PerformanceItems.Include(p=>p.CalMonth).FirstOrDefault(p => p.Id == appealRecord.ItemId.Value);
  343. if(item == null)
  344. {
  345. response.Success = false;
  346. response.ErrorMessage = "无效的ItemId!";
  347. return response;
  348. }
  349. else
  350. {
  351. if(item.CalMonth.Status != 0)
  352. {
  353. response.Success = false;
  354. response.ErrorMessage = "指定的绩效已经归档!";
  355. return response;
  356. }
  357. }
  358. }
  359. var t = Context.Database.BeginTransaction();
  360. try
  361. {
  362. appealRecord.ReviewerId = Context.Staffs.Where<Staff>(s => s.Name == User.Identity.Name).FirstOrDefault().Id;
  363. appealRecord.State = 1;
  364. appealRecord.ReviewTime = DateTime.Now;
  365. Context.SaveChanges();
  366. foreach (var fieldValue in appealObject.inputFieldValues)
  367. {
  368. fieldValue.InputField = null;
  369. fieldValue.AppealRecordId = appealRecord.Id;
  370. }
  371. Context.InputFieldValues.AddRange(appealObject.inputFieldValues);
  372. Context.SaveChanges();
  373. if (appealObject.attachFiles != null)
  374. {
  375. foreach (var file in appealObject.attachFiles)
  376. {
  377. var temFile = Context.AttachFiles.Where<AttachFile>(f => f.Id == file.Id).FirstOrDefault();
  378. temFile.AppealRecordId = appealRecord.Id;
  379. temFile.UploadUserId = appealRecord.ReviewerId;
  380. }
  381. }
  382. List<InputFieldValue> inputFieldValues = Context.InputFieldValues
  383. .Where<InputFieldValue>(p => p.AppealRecordId == appealRecordId
  384. && p.InputField.MapObjectField != null)
  385. .Include(i=>i.InputField)
  386. .ToList();
  387. foreach(InputFieldValue inputFieldValue in inputFieldValues)
  388. {
  389. SaveValueToMapObject(appealRecord, inputFieldValue);
  390. }
  391. Context.SaveChanges();
  392. if(appealRecord.Type == null)
  393. {
  394. appealRecord.Type = Context.AppealTypes.FirstOrDefault(s=>s.Id == appealRecord.TypeId);
  395. }
  396. if (!string.IsNullOrEmpty(appealRecord.Type.ReviewObject))
  397. {
  398. IDoAppealObject doAppeal = (IDoAppealObject)Activator.CreateInstance(Type.GetType(appealRecord.Type.ReviewObject));
  399. doAppeal.DoAppeal(appealObject, appealRecord.Id,Context);
  400. }
  401. Context.SaveChanges();
  402. if(appealRecord.ItemId.HasValue)
  403. {
  404. var item = Context.PerformanceItems
  405. .Include(p => p.ItemStaffs)
  406. .Include(p => p.Customer)
  407. .Include(p=>p.Reviewer)
  408. .FirstOrDefault(p=>p.Id == appealRecord.ItemId);
  409. new PerformanceItemController(Context, new Services.FileTaskCacheService()).RefreshPoint(item);
  410. }
  411. t.Commit();
  412. return response;
  413. }
  414. catch (Exception ex)
  415. {
  416. t.Rollback();
  417. response.Success = false;
  418. response.ErrorMessage = ex.Message;
  419. return response;
  420. }
  421. }
  422. else
  423. {
  424. response.Success = true;
  425. response.ErrorMessage = "申诉不存在!";
  426. return response;
  427. }
  428. }
  429. private object ConvertSimpleType(object value, Type destinationType)
  430. {
  431. object returnValue;
  432. if ((value == null) || destinationType.IsInstanceOfType(value))
  433. {
  434. return value;
  435. }
  436. string str = value as string;
  437. if ((str != null) && (str.Length == 0))
  438. {
  439. return null;
  440. }
  441. TypeConverter converter = TypeDescriptor.GetConverter(destinationType);
  442. bool flag = converter.CanConvertFrom(value.GetType());
  443. if (!flag)
  444. {
  445. converter = TypeDescriptor.GetConverter(value.GetType());
  446. }
  447. if (!flag && !converter.CanConvertTo(destinationType))
  448. {
  449. throw new InvalidOperationException("无法转换成类型:" + value.ToString() + "==>" + destinationType);
  450. }
  451. try
  452. {
  453. returnValue = flag ? converter.ConvertFrom(null, null, value) : converter.ConvertTo(null, null, value, destinationType);
  454. }
  455. catch (Exception e)
  456. {
  457. throw new InvalidOperationException("类型转换出错:" + value.ToString() + "==>" + destinationType, e);
  458. }
  459. return returnValue;
  460. }
  461. private void SaveValueToMapObject(AppealRecord appealRecord, InputFieldValue inputFieldValue)
  462. {
  463. if (!string.IsNullOrEmpty(inputFieldValue.InputField.MapObjectField))
  464. {
  465. bool isSave = false;
  466. if (!string.IsNullOrEmpty(inputFieldValue.InputField.MapSaveCondition))
  467. {
  468. string[] conditions = inputFieldValue.InputField.MapSaveCondition.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
  469. if (conditions.Length == 1)
  470. {
  471. if (appealRecord.State == int.Parse(conditions[0]))
  472. {
  473. isSave = true;
  474. }
  475. }
  476. else
  477. {
  478. if (appealRecord.State == int.Parse(conditions[0]))
  479. {
  480. InputFieldValue temValue =
  481. Context.InputFieldValues.Where<InputFieldValue>(v =>
  482. v.AppealRecordId == appealRecord.Id &&
  483. v.InputField.Id == int.Parse(conditions[1]) &&
  484. v.Value == conditions[2])
  485. .FirstOrDefault();
  486. if (temValue != null)
  487. {
  488. isSave = true;
  489. }
  490. }
  491. }
  492. }
  493. else
  494. {
  495. isSave = true;
  496. }
  497. if (isSave)
  498. {
  499. InputField field = inputFieldValue.InputField;
  500. PerformanceItem Item = Context.PerformanceItems.Where<PerformanceItem>(p =>
  501. p.Id == appealRecord.ItemId)
  502. .Include(p => p.ItemStaffs).ThenInclude(it=>it.DoPerson)
  503. .Include(p => p.Reviewer)
  504. .FirstOrDefault();
  505. bool ItemIsNull = false;
  506. if(Item == null)
  507. {
  508. ItemIsNull = true;
  509. Item = new PerformanceItem();
  510. }
  511. if (!string.IsNullOrEmpty(field.MapObjectField) && !string.IsNullOrEmpty(field.MapObjectFieldLabel))
  512. {
  513. List<InputFieldValue> temValues = new List<InputFieldValue>();
  514. string[] pList = field.MapObjectField.Split(new char[] { '.' });
  515. string[] plList = field.MapObjectFieldLabel.Split(new char[] { '.' });
  516. var pInfo = Item.GetType().GetProperty(pList[0]);
  517. var o = pInfo.GetValue(Item);
  518. if (Array.IndexOf(o.GetType().GetInterfaces(), typeof(IEnumerable)) > -1)
  519. {
  520. List<string> Values = new List<string>();
  521. List<string> Labels = new List<string>();
  522. var objList = o as IEnumerable;
  523. foreach (var obj in objList)
  524. {
  525. var objLabel = obj;
  526. for (int i = 1; i < plList.Length; i++)
  527. {
  528. objLabel = objLabel.GetType().GetProperty(plList[i]).GetValue(objLabel);
  529. }
  530. if (objLabel.ToString() == inputFieldValue.Label)
  531. {
  532. var objValue = obj;
  533. for (int i = 1; i < pList.Length - 1; i++)
  534. {
  535. objValue = objValue.GetType().GetProperty(pList[i]).GetValue(objValue);
  536. }
  537. objValue.GetType().GetProperty(pList[pList.Length - 1])
  538. .SetValue(objValue, ConvertSimpleType(inputFieldValue.Value,Type.GetType(inputFieldValue.InputField.FieldType)));
  539. }
  540. }
  541. }
  542. }
  543. else
  544. {
  545. Item.GetType().GetProperty(field.MapObjectField).SetValue(Item, ConvertSimpleType(inputFieldValue.Value, Type.GetType(inputFieldValue.InputField.FieldType)));
  546. }
  547. }
  548. }
  549. }
  550. public List<AppealRecord> GetAppealRecords(int userId)
  551. {
  552. try
  553. {
  554. var data = Context.AppealRecords.Where<AppealRecord>(p => p.Id > 0);
  555. if (userId > 0)
  556. {
  557. data = Context.AppealRecords.Where<AppealRecord>(ar => (ar.CreaterId == userId || (ar.ReviewerId == userId && ar.State != 1)) && ar.Type.NeedReview == true);
  558. }
  559. var retList = data
  560. .Include(p => p.Reviewer)
  561. .Include(p => p.Creater)
  562. .Include(p => p.Item)
  563. .Include(p => p.Type)
  564. .OrderBy(p => p.State)
  565. .ToList();
  566. foreach (var record in retList)
  567. {
  568. replaceDataForSerialize(record);
  569. }
  570. //string str = System.Text.Json.JsonSerializer.Serialize(retList);
  571. //System.Diagnostics.Debug.WriteLine(str);
  572. //Log(str);
  573. return retList;
  574. }
  575. catch (Exception ex)
  576. {
  577. Log(ex.ToString());
  578. return new List<AppealRecord>();
  579. }
  580. }
  581. private void replaceDataForSerialize(AppealRecord record)
  582. {
  583. if(record.Creater !=null)
  584. {
  585. Staff temStaff = new Staff()
  586. {
  587. Name = record.Creater.Name,
  588. Id = record.Creater.Id,
  589. ItemStaffs = null,
  590. ReviewerItems = null,
  591. Customers = null,
  592. Positions = null,
  593. StaffGrade = null,
  594. };
  595. record.Creater = temStaff;
  596. //record.Creater.ItemStaffs = null;
  597. //record.Creater.ReviewerItems = null;
  598. //record.Creater.Customers = null;
  599. //record.Creater.Positions = null;
  600. //record.Creater.StaffGrade = null;
  601. }
  602. if (record.Reviewer != null)
  603. {
  604. Staff temStaff = new Staff() {
  605. Name = record.Reviewer.Name,
  606. Id = record.Creater.Id,
  607. ItemStaffs = null,
  608. ReviewerItems = null,
  609. Customers = null,
  610. Positions = null,
  611. StaffGrade = null,
  612. };
  613. record.Reviewer = temStaff;
  614. //record.Reviewer.ItemStaffs = null;
  615. //record.Reviewer.Customers = null;
  616. //record.Reviewer.ReviewerItems = null;
  617. //record.Reviewer.Positions = null;
  618. //record.Reviewer.StaffGrade = null;
  619. }
  620. if (record.Item != null)
  621. {
  622. PerformanceItem temItem = new PerformanceItem()
  623. {
  624. Id = record.Item.Id,
  625. CaseNo = record.Item.CaseNo,
  626. DoItem = record.Item.DoItem,
  627. CaseName = record.Item.CaseName,
  628. CalMonthId = record.Item.CalMonthId
  629. };
  630. record.Item = temItem;
  631. //record.Item.ItemStaffs = null;
  632. //record.Item.PreOastaff = null;
  633. //record.Item.Reviewer = null;
  634. //record.Item.WorkflowUser = null;
  635. //record.Item.Customer = null;
  636. //record.Item.CalMonth = null;
  637. }
  638. if(record.Type != null)
  639. {
  640. record.Type.ReviewerExpress = null;
  641. record.Type.CanDoExpress = null;
  642. record.Type.ApplealObject = null;
  643. record.Type.CanDoExpress = null;
  644. record.Type.ReviewerExpress = null;
  645. }
  646. //record.Type.ReviewerExpress = null;
  647. }
  648. [HttpPost]
  649. public List<AppealRecord> QueryByFilter(AppealRecordFilter filter)
  650. {
  651. var data = Context.AppealRecords.Where<AppealRecord>(s => true);
  652. if(filter.AppealTypeId > 0)
  653. {
  654. data = Context.AppealRecords.Where(f=>f.TypeId == filter.AppealTypeId);
  655. }
  656. if(!string.IsNullOrEmpty(filter.CaseNo))
  657. {
  658. data = data.Where(s=>s.Item.CaseNo.Contains(filter.CaseNo));
  659. }
  660. if (!string.IsNullOrEmpty(filter.CreateUser))
  661. {
  662. data = data.Where(s => s.Creater.Name.Contains(filter.CreateUser));
  663. }
  664. if (!string.IsNullOrEmpty(filter.Reviewer))
  665. {
  666. data = data.Where(s => s.Reviewer.Name.Contains(filter.Reviewer));
  667. }
  668. if (filter.beginCreateTime.HasValue)
  669. {
  670. data = data.Where(s => s.CreateTime>=filter.beginCreateTime.Value );
  671. }
  672. if (filter.endCreateTime.HasValue)
  673. {
  674. data = data.Where(s => s.CreateTime <= filter.endCreateTime.Value);
  675. }
  676. if (filter.beginReviewTime.HasValue)
  677. {
  678. data = data.Where(s => s.ReviewTime >= filter.beginReviewTime.Value);
  679. }
  680. if (filter.endReviewTime.HasValue)
  681. {
  682. data = data.Where(s => s.ReviewTime <= filter.endReviewTime.Value);
  683. }
  684. var retList = data
  685. .Include(p => p.Reviewer)
  686. .Include(p => p.Creater)
  687. .Include(p => p.Item)
  688. .Include(p => p.Type)
  689. .OrderBy(p => p.State)
  690. .ToList();
  691. foreach (var record in retList)
  692. {
  693. replaceDataForSerialize(record);
  694. }
  695. return retList;
  696. }
  697. public AppealRecord GetAppealRecord(int Id)
  698. {
  699. var data = Context.AppealRecords.Where<AppealRecord>(ar => ar.Id == Id);
  700. return data.Include(p => p.Reviewer)
  701. .Include(p => p.Creater)
  702. .Include(p => p.Item)
  703. .Include(p => p.Type).FirstOrDefault();
  704. }
  705. public List<InputFieldValue> GetInputFieldValues(int id, int state)
  706. {
  707. var result = Context.InputFieldValues.Where<InputFieldValue>(f => f.AppealRecordId == id && f.InputField.AppealState == state);
  708. return result.Include(i => i.InputField).ToList();
  709. }
  710. public List<InputFieldValue> GetAllInputFieldValue(int id)
  711. {
  712. var result = Context.InputFieldValues.Where<InputFieldValue>(f => f.AppealRecordId == id);
  713. return result.Include(i => i.InputField).ToList();
  714. }
  715. public List<AttachFile> GetAppealRecordAttachFiles(int appealRecordId)
  716. {
  717. var result = Context.AttachFiles.Where<AttachFile>(at => at.AppealRecordId == appealRecordId).Include(f => f.UploadUser);
  718. return result.ToList();
  719. }
  720. public ApiSaveResponse ChangeRecordReviewer(int RecordId,int ReviewerId)
  721. {
  722. var data = Context.AppealRecords.FirstOrDefault<AppealRecord>(ar => ar.Id == RecordId);
  723. if(data != null)
  724. {
  725. var reviewer = Context.Staffs.FirstOrDefault(s => s.Id == ReviewerId);
  726. var CurrentUser = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
  727. if ((CurrentUser.Id == data.CreaterId || CurrentUser.Id == data.ReviewerId) && data.State ==0)
  728. {
  729. if (reviewer != null)
  730. {
  731. data.ReviewerId = ReviewerId;
  732. Context.SaveChanges();
  733. return new ApiSaveResponse()
  734. {
  735. Success = true
  736. };
  737. }
  738. else
  739. {
  740. return new ApiSaveResponse()
  741. {
  742. Success = false,
  743. ErrorMessage = "指定的审核人不存在"
  744. };
  745. }
  746. }
  747. else
  748. {
  749. return new ApiSaveResponse()
  750. {
  751. Success = false,
  752. ErrorMessage = "只有申诉人和审核人在未审核状态时才能变更审核人"
  753. };
  754. }
  755. }
  756. else
  757. {
  758. return new ApiSaveResponse()
  759. {
  760. Success = false,
  761. ErrorMessage = "指定的申诉记录不存在"
  762. };
  763. }
  764. }
  765. private void Log(string strMessage)
  766. {
  767. StreamWriter sw = System.IO.File.AppendText("c:\\temp\\log.txt");
  768. sw.WriteLine($"{strMessage}");
  769. sw.Flush();
  770. sw.Close();
  771. sw.Dispose();
  772. }
  773. }
  774. }