AppealController.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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. namespace wispro.sp.api.Controllers
  19. {
  20. [Route("api/[controller]/[action]")]
  21. [ApiController]
  22. //[Authorize]
  23. public class AppealController : ControllerBase
  24. {
  25. spDbContext Context;
  26. public AppealController(spDbContext context)
  27. {
  28. Context = context;
  29. }
  30. public List<AppealType> GetAppealTypes()
  31. {
  32. return Context.AppealTypes.ToList();
  33. }
  34. /// <summary>
  35. /// 统计指定客户、指定月份新申请案件各案件系数的案件数量
  36. /// </summary>
  37. /// <param name="CustomerId">指定客户Id</param>
  38. /// <param name="CalmonthId">指定月份Id</param>
  39. /// <returns></returns>
  40. public CaseCoefficientStatistics GetCCSRecord(int CustomerId,int CalmonthId)
  41. {
  42. CaseCoefficientStatistics retObject = new CaseCoefficientStatistics();
  43. retObject.customer = Context.Customers.FirstOrDefault(c=>c.Id== CustomerId);
  44. string strSQL = $"SELECT CaseCoefficient,count(*) as CaseCoefficientCount " +
  45. "FROM PerformanceItem " +
  46. $"where CalMonthId = {CalmonthId} and CustomerId = {CustomerId} and Type = '新申请' and(AgentFeedbackMemo <> '已算绩效' or AgentFeedbackMemo is null) " +
  47. "group by CaseCoefficient";
  48. var conn= Context.Database.GetDbConnection();
  49. if(conn.State != System.Data.ConnectionState.Open)
  50. {
  51. conn.Open();
  52. }
  53. try
  54. {
  55. var cmd = conn.CreateCommand();
  56. cmd.CommandText = strSQL;
  57. var reader = cmd.ExecuteReader();
  58. while (reader.Read())
  59. {
  60. string strKey = (reader.IsDBNull(0) || string.IsNullOrEmpty(reader.GetString(0))) ? "B" : reader.GetString(0);
  61. switch (strKey)
  62. {
  63. case "A":
  64. retObject.ACount += reader.GetInt32(1);
  65. retObject.Totals += reader.GetInt32(1);
  66. break;
  67. case "S":
  68. retObject.SCount += reader.GetInt32(1);
  69. retObject.Totals += reader.GetInt32(1);
  70. break;
  71. default:
  72. retObject.Totals += reader.GetInt32(1);
  73. break;
  74. }
  75. }
  76. cmd.Dispose();
  77. return retObject;
  78. }
  79. catch (Exception ex)
  80. {
  81. throw ex;
  82. }
  83. finally
  84. {
  85. conn.Close();
  86. }
  87. }
  88. public List<InputField> GetInputField(int appealTypeId, int state)
  89. {
  90. var retList = Context.InputFields
  91. .Where<InputField>(ip => ip.AppealTypeId == appealTypeId && ip.AppealState == state)
  92. .Include(p => p.SelectValues)
  93. .ToList();
  94. string str = System.Text.Json.JsonSerializer.Serialize(retList, new JsonSerializerOptions()
  95. {
  96. ReferenceHandler = ReferenceHandler.Preserve
  97. });
  98. Log(str);
  99. foreach (var inputField in retList)
  100. {
  101. if (inputField.SelectValues != null)
  102. {
  103. foreach(var ifValue in inputField.SelectValues)
  104. {
  105. ifValue.InputField = null;
  106. }
  107. }
  108. }
  109. return retList;
  110. }
  111. /// <summary>
  112. /// 创建申诉流程
  113. /// </summary>
  114. /// <param name="ItemId"></param>
  115. /// <param name="typeid"></param>
  116. /// <param name="reviewerId"></param>
  117. /// <param name="appealObject"></param>
  118. /// <returns></returns>
  119. public ApiSaveResponse CreateAppeal(int ItemId, int typeid, int reviewerId, AppealObject appealObject)
  120. {
  121. ApiSaveResponse response = new ApiSaveResponse();
  122. response.Success = true;
  123. AppealRecord appealRecord = new AppealRecord();
  124. if(ItemId > 0)
  125. {
  126. appealRecord.ItemId = ItemId;
  127. }
  128. else
  129. {
  130. appealRecord.ItemId = null;
  131. }
  132. appealRecord.TypeId = typeid;
  133. appealRecord.ReviewerId = reviewerId;
  134. appealRecord.CreaterId = Context.Staffs.Where<Staff>(s => s.Name == User.Identity.Name).FirstOrDefault().Id;
  135. appealRecord.CreateTime = DateTime.Now;
  136. var t = Context.Database.BeginTransaction();
  137. try
  138. {
  139. Context.AppealRecords.Add(appealRecord);
  140. Context.SaveChanges();
  141. foreach (var fieldValue in appealObject.inputFieldValues)
  142. {
  143. fieldValue.InputField = null;
  144. fieldValue.AppealRecordId = appealRecord.Id;
  145. }
  146. Context.InputFieldValues.AddRange(appealObject.inputFieldValues);
  147. foreach (var file in appealObject.attachFiles)
  148. {
  149. var temFile = Context.AttachFiles.Where<AttachFile>(f => f.Id == file.Id).FirstOrDefault();
  150. temFile.AppealRecordId = appealRecord.Id;
  151. temFile.UploadUserId = appealRecord.CreaterId;
  152. }
  153. Context.SaveChanges();
  154. var temType = Context.AppealTypes.FirstOrDefault(c=>c.Id == appealRecord.TypeId);
  155. if (!string.IsNullOrEmpty(temType.ApplealObject))
  156. {
  157. IDoAppealObject doAppeal = (IDoAppealObject)Activator.CreateInstance(Type.GetType(appealRecord.Type.ApplealObject));
  158. doAppeal.DoAppeal(appealObject, appealRecord.Id, Context);
  159. }
  160. t.Commit();
  161. var Reviewer = Context.Staffs.Where<Staff>(s => s.Id == appealRecord.ReviewerId).FirstOrDefault();
  162. if(appealRecord.Type == null)
  163. {
  164. appealRecord.Type = Context.AppealTypes.FirstOrDefault(p=>p.Id == appealRecord.TypeId);
  165. }
  166. string strSubject = appealRecord.Type.Name;
  167. 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>";
  168. string strTo = Reviewer.Mail;
  169. if (!string.IsNullOrEmpty(strTo))
  170. {
  171. _ = QuartzUtil.AddMailJob(strSubject, strBody, Reviewer.Name, strTo);
  172. }
  173. 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>";
  174. _ = QuartzUtil.AddMailJob(strSubject, strBody, "钟子敏", "zhongzimin@china-wispro.com");
  175. _ = QuartzUtil.AddMailJob(strSubject, strBody, "夏敏", "xiamin@china-wispro.com");
  176. _ = QuartzUtil.AddMailJob(strSubject, strBody, "吴芳", "wufang@china-wispro.com");
  177. return response;
  178. }
  179. catch (Exception ex)
  180. {
  181. t.Rollback();
  182. response.Success = false;
  183. response.ErrorMessage = "申诉时发生错误!";
  184. return response;
  185. }
  186. }
  187. public ApiSaveResponse ReviewerAppeal(int appealRecordId,AppealObject appealObject)
  188. {
  189. ApiSaveResponse response = new ApiSaveResponse();
  190. response.Success = true;
  191. var appealRecord = Context.AppealRecords.Where<AppealRecord>(p => p.Id == appealRecordId).FirstOrDefault();
  192. if(appealRecord != null)
  193. {
  194. if (appealRecord.ItemId.HasValue)
  195. {
  196. var item = Context.PerformanceItems.Include(p=>p.CalMonth).FirstOrDefault(p => p.Id == appealRecord.ItemId.Value);
  197. if(item == null)
  198. {
  199. response.Success = false;
  200. response.ErrorMessage = "无效的ItemId!";
  201. return response;
  202. }
  203. else
  204. {
  205. if(item.CalMonth.Status != 0)
  206. {
  207. response.Success = false;
  208. response.ErrorMessage = "指定的绩效已经归档!";
  209. return response;
  210. }
  211. }
  212. }
  213. var t = Context.Database.BeginTransaction();
  214. try
  215. {
  216. appealRecord.ReviewerId = Context.Staffs.Where<Staff>(s => s.Name == User.Identity.Name).FirstOrDefault().Id;
  217. appealRecord.State = 1;
  218. appealRecord.ReviewTime = DateTime.Now;
  219. Context.SaveChanges();
  220. foreach (var fieldValue in appealObject.inputFieldValues)
  221. {
  222. fieldValue.InputField = null;
  223. fieldValue.AppealRecordId = appealRecord.Id;
  224. }
  225. Context.InputFieldValues.AddRange(appealObject.inputFieldValues);
  226. Context.SaveChanges();
  227. if (appealObject.attachFiles != null)
  228. {
  229. foreach (var file in appealObject.attachFiles)
  230. {
  231. var temFile = Context.AttachFiles.Where<AttachFile>(f => f.Id == file.Id).FirstOrDefault();
  232. temFile.AppealRecordId = appealRecord.Id;
  233. temFile.UploadUserId = appealRecord.ReviewerId;
  234. }
  235. }
  236. List<InputFieldValue> inputFieldValues = Context.InputFieldValues
  237. .Where<InputFieldValue>(p => p.AppealRecordId == appealRecordId
  238. && p.InputField.MapObjectField != null)
  239. .Include(i=>i.InputField)
  240. .ToList();
  241. foreach(InputFieldValue inputFieldValue in inputFieldValues)
  242. {
  243. SaveValueToMapObject(appealRecord, inputFieldValue);
  244. }
  245. Context.SaveChanges();
  246. if(appealRecord.Type == null)
  247. {
  248. appealRecord.Type = Context.AppealTypes.FirstOrDefault(s=>s.Id == appealRecord.TypeId);
  249. }
  250. if (!string.IsNullOrEmpty(appealRecord.Type.ReviewObject))
  251. {
  252. IDoAppealObject doAppeal = (IDoAppealObject)Activator.CreateInstance(Type.GetType(appealRecord.Type.ReviewObject));
  253. doAppeal.DoAppeal(appealObject, appealRecord.Id,Context);
  254. }
  255. Context.SaveChanges();
  256. if(appealRecord.ItemId.HasValue)
  257. {
  258. var item = Context.PerformanceItems
  259. .Include(p => p.ItemStaffs)
  260. .Include(p => p.Customer)
  261. .Include(p=>p.Reviewer)
  262. .FirstOrDefault(p=>p.Id == appealRecord.ItemId);
  263. new PerformanceItemController(Context, new Services.FileTaskCacheService()).RefreshPoint(item);
  264. }
  265. t.Commit();
  266. return response;
  267. }
  268. catch (Exception ex)
  269. {
  270. t.Rollback();
  271. response.Success = false;
  272. response.ErrorMessage = ex.Message;
  273. return response;
  274. }
  275. }
  276. else
  277. {
  278. response.Success = true;
  279. response.ErrorMessage = "申诉不存在!";
  280. return response;
  281. }
  282. }
  283. private object ConvertSimpleType(object value, Type destinationType)
  284. {
  285. object returnValue;
  286. if ((value == null) || destinationType.IsInstanceOfType(value))
  287. {
  288. return value;
  289. }
  290. string str = value as string;
  291. if ((str != null) && (str.Length == 0))
  292. {
  293. return null;
  294. }
  295. TypeConverter converter = TypeDescriptor.GetConverter(destinationType);
  296. bool flag = converter.CanConvertFrom(value.GetType());
  297. if (!flag)
  298. {
  299. converter = TypeDescriptor.GetConverter(value.GetType());
  300. }
  301. if (!flag && !converter.CanConvertTo(destinationType))
  302. {
  303. throw new InvalidOperationException("无法转换成类型:" + value.ToString() + "==>" + destinationType);
  304. }
  305. try
  306. {
  307. returnValue = flag ? converter.ConvertFrom(null, null, value) : converter.ConvertTo(null, null, value, destinationType);
  308. }
  309. catch (Exception e)
  310. {
  311. throw new InvalidOperationException("类型转换出错:" + value.ToString() + "==>" + destinationType, e);
  312. }
  313. return returnValue;
  314. }
  315. private void SaveValueToMapObject(AppealRecord appealRecord, InputFieldValue inputFieldValue)
  316. {
  317. if (!string.IsNullOrEmpty(inputFieldValue.InputField.MapObjectField))
  318. {
  319. bool isSave = false;
  320. if (!string.IsNullOrEmpty(inputFieldValue.InputField.MapSaveCondition))
  321. {
  322. string[] conditions = inputFieldValue.InputField.MapSaveCondition.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
  323. if (conditions.Length == 1)
  324. {
  325. if (appealRecord.State == int.Parse(conditions[0]))
  326. {
  327. isSave = true;
  328. }
  329. }
  330. else
  331. {
  332. if (appealRecord.State == int.Parse(conditions[0]))
  333. {
  334. InputFieldValue temValue =
  335. Context.InputFieldValues.Where<InputFieldValue>(v =>
  336. v.AppealRecordId == appealRecord.Id &&
  337. v.InputField.Id == int.Parse(conditions[1]) &&
  338. v.Value == conditions[2])
  339. .FirstOrDefault();
  340. if (temValue != null)
  341. {
  342. isSave = true;
  343. }
  344. }
  345. }
  346. }
  347. else
  348. {
  349. isSave = true;
  350. }
  351. if (isSave)
  352. {
  353. InputField field = inputFieldValue.InputField;
  354. PerformanceItem Item = Context.PerformanceItems.Where<PerformanceItem>(p =>
  355. p.Id == appealRecord.ItemId)
  356. .Include(p => p.ItemStaffs).ThenInclude(it=>it.DoPerson)
  357. .Include(p => p.Reviewer)
  358. .FirstOrDefault();
  359. bool ItemIsNull = false;
  360. if(Item == null)
  361. {
  362. ItemIsNull = true;
  363. Item = new PerformanceItem();
  364. }
  365. if (!string.IsNullOrEmpty(field.MapObjectField) && !string.IsNullOrEmpty(field.MapObjectFieldLabel))
  366. {
  367. List<InputFieldValue> temValues = new List<InputFieldValue>();
  368. string[] pList = field.MapObjectField.Split(new char[] { '.' });
  369. string[] plList = field.MapObjectFieldLabel.Split(new char[] { '.' });
  370. var pInfo = Item.GetType().GetProperty(pList[0]);
  371. var o = pInfo.GetValue(Item);
  372. if (Array.IndexOf(o.GetType().GetInterfaces(), typeof(IEnumerable)) > -1)
  373. {
  374. List<string> Values = new List<string>();
  375. List<string> Labels = new List<string>();
  376. var objList = o as IEnumerable;
  377. foreach (var obj in objList)
  378. {
  379. var objLabel = obj;
  380. for (int i = 1; i < plList.Length; i++)
  381. {
  382. objLabel = objLabel.GetType().GetProperty(plList[i]).GetValue(objLabel);
  383. }
  384. if (objLabel.ToString() == inputFieldValue.Label)
  385. {
  386. var objValue = obj;
  387. for (int i = 1; i < pList.Length - 1; i++)
  388. {
  389. objValue = objValue.GetType().GetProperty(pList[i]).GetValue(objValue);
  390. }
  391. objValue.GetType().GetProperty(pList[pList.Length - 1])
  392. .SetValue(objValue, ConvertSimpleType(inputFieldValue.Value,Type.GetType(inputFieldValue.InputField.FieldType)));
  393. }
  394. }
  395. }
  396. }
  397. else
  398. {
  399. Item.GetType().GetProperty(field.MapObjectField).SetValue(Item, ConvertSimpleType(inputFieldValue.Value, Type.GetType(inputFieldValue.InputField.FieldType)));
  400. }
  401. }
  402. }
  403. }
  404. public List<AppealRecord> GetAppealRecords(int userId)
  405. {
  406. try
  407. {
  408. var data = Context.AppealRecords.Where<AppealRecord>(p => p.Id > 0);
  409. if (userId > 0)
  410. {
  411. data = Context.AppealRecords.Where<AppealRecord>(ar => (ar.CreaterId == userId || (ar.ReviewerId == userId && ar.State != 1)) && ar.Type.NeedReview == true);
  412. }
  413. var retList = data
  414. .Include(p => p.Reviewer)
  415. .Include(p => p.Creater)
  416. .Include(p => p.Item)
  417. .Include(p => p.Type)
  418. .ToList();
  419. foreach (var record in retList)
  420. {
  421. replaceDataForSerialize(record);
  422. }
  423. //string str = System.Text.Json.JsonSerializer.Serialize(retList);
  424. //System.Diagnostics.Debug.WriteLine(str);
  425. //Log(str);
  426. return retList;
  427. }
  428. catch (Exception ex)
  429. {
  430. Log(ex.ToString());
  431. return new List<AppealRecord>();
  432. }
  433. }
  434. private void replaceDataForSerialize(AppealRecord record)
  435. {
  436. if(record.Creater !=null)
  437. {
  438. Staff temStaff = new Staff()
  439. {
  440. Name = record.Creater.Name,
  441. Id = record.Creater.Id,
  442. ItemStaffs = null,
  443. ReviewerItems = null,
  444. Customers = null,
  445. Positions = null,
  446. StaffGrade = null,
  447. };
  448. record.Creater = temStaff;
  449. //record.Creater.ItemStaffs = null;
  450. //record.Creater.ReviewerItems = null;
  451. //record.Creater.Customers = null;
  452. //record.Creater.Positions = null;
  453. //record.Creater.StaffGrade = null;
  454. }
  455. if (record.Reviewer != null)
  456. {
  457. Staff temStaff = new Staff() {
  458. Name = record.Reviewer.Name,
  459. Id = record.Creater.Id,
  460. ItemStaffs = null,
  461. ReviewerItems = null,
  462. Customers = null,
  463. Positions = null,
  464. StaffGrade = null,
  465. };
  466. record.Reviewer = temStaff;
  467. //record.Reviewer.ItemStaffs = null;
  468. //record.Reviewer.Customers = null;
  469. //record.Reviewer.ReviewerItems = null;
  470. //record.Reviewer.Positions = null;
  471. //record.Reviewer.StaffGrade = null;
  472. }
  473. if (record.Item != null)
  474. {
  475. PerformanceItem temItem = new PerformanceItem()
  476. {
  477. Id = record.Item.Id,
  478. CaseNo = record.Item.CaseNo,
  479. CaseName = record.Item.CaseName,
  480. CalMonthId = record.Item.CalMonthId
  481. };
  482. record.Item = temItem;
  483. //record.Item.ItemStaffs = null;
  484. //record.Item.PreOastaff = null;
  485. //record.Item.Reviewer = null;
  486. //record.Item.WorkflowUser = null;
  487. //record.Item.Customer = null;
  488. //record.Item.CalMonth = null;
  489. }
  490. if(record.Type != null)
  491. {
  492. record.Type.ReviewerExpress = null;
  493. record.Type.CanDoExpress = null;
  494. record.Type.ApplealObject = null;
  495. record.Type.CanDoExpress = null;
  496. record.Type.ReviewerExpress = null;
  497. }
  498. //record.Type.ReviewerExpress = null;
  499. }
  500. [HttpPost]
  501. public List<AppealRecord> QueryByFilter(AppealRecordFilter filter)
  502. {
  503. var data = Context.AppealRecords.Where<AppealRecord>(s => true);
  504. if(filter.AppealTypeId > 0)
  505. {
  506. data = Context.AppealRecords.Where(f=>f.TypeId == filter.AppealTypeId);
  507. }
  508. if(!string.IsNullOrEmpty(filter.CaseNo))
  509. {
  510. data = data.Where(s=>s.Item.CaseNo.Contains(filter.CaseNo));
  511. }
  512. if (!string.IsNullOrEmpty(filter.CreateUser))
  513. {
  514. data = data.Where(s => s.Creater.Name.Contains(filter.CreateUser));
  515. }
  516. if (!string.IsNullOrEmpty(filter.Reviewer))
  517. {
  518. data = data.Where(s => s.Reviewer.Name.Contains(filter.Reviewer));
  519. }
  520. if (filter.beginCreateTime.HasValue)
  521. {
  522. data = data.Where(s => s.CreateTime>=filter.beginCreateTime.Value );
  523. }
  524. if (filter.endCreateTime.HasValue)
  525. {
  526. data = data.Where(s => s.CreateTime <= filter.endCreateTime.Value);
  527. }
  528. if (filter.beginReviewTime.HasValue)
  529. {
  530. data = data.Where(s => s.ReviewTime >= filter.beginReviewTime.Value);
  531. }
  532. if (filter.endReviewTime.HasValue)
  533. {
  534. data = data.Where(s => s.ReviewTime <= filter.endReviewTime.Value);
  535. }
  536. var retList = data
  537. .Include(p => p.Reviewer)
  538. .Include(p => p.Creater)
  539. .Include(p => p.Item)
  540. .Include(p => p.Type)
  541. .ToList();
  542. foreach (var record in retList)
  543. {
  544. replaceDataForSerialize(record);
  545. }
  546. return retList;
  547. }
  548. public AppealRecord GetAppealRecord(int Id)
  549. {
  550. var data = Context.AppealRecords.Where<AppealRecord>(ar => ar.Id == Id);
  551. return data.Include(p => p.Reviewer)
  552. .Include(p => p.Creater)
  553. .Include(p => p.Item)
  554. .Include(p => p.Type).FirstOrDefault();
  555. }
  556. public List<InputFieldValue> GetInputFieldValues(int id, int state)
  557. {
  558. var result = Context.InputFieldValues.Where<InputFieldValue>(f => f.AppealRecordId == id && f.InputField.AppealState == state);
  559. return result.Include(i => i.InputField).ToList();
  560. }
  561. public List<InputFieldValue> GetAllInputFieldValue(int id)
  562. {
  563. var result = Context.InputFieldValues.Where<InputFieldValue>(f => f.AppealRecordId == id);
  564. return result.Include(i => i.InputField).ToList();
  565. }
  566. public List<AttachFile> GetAppealRecordAttachFiles(int appealRecordId)
  567. {
  568. var result = Context.AttachFiles.Where<AttachFile>(at => at.AppealRecordId == appealRecordId).Include(f => f.UploadUser);
  569. return result.ToList();
  570. }
  571. public ApiSaveResponse ChangeRecordReviewer(int RecordId,int ReviewerId)
  572. {
  573. var data = Context.AppealRecords.FirstOrDefault<AppealRecord>(ar => ar.Id == RecordId);
  574. if(data != null)
  575. {
  576. var reviewer = Context.Staffs.FirstOrDefault(s => s.Id == ReviewerId);
  577. var CurrentUser = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
  578. if ((CurrentUser.Id == data.CreaterId || CurrentUser.Id == data.ReviewerId) && data.State ==0)
  579. {
  580. if (reviewer != null)
  581. {
  582. data.ReviewerId = ReviewerId;
  583. Context.SaveChanges();
  584. return new ApiSaveResponse()
  585. {
  586. Success = true
  587. };
  588. }
  589. else
  590. {
  591. return new ApiSaveResponse()
  592. {
  593. Success = false,
  594. ErrorMessage = "指定的审核人不存在"
  595. };
  596. }
  597. }
  598. else
  599. {
  600. return new ApiSaveResponse()
  601. {
  602. Success = false,
  603. ErrorMessage = "只有申诉人和审核人在未审核状态时才能变更审核人"
  604. };
  605. }
  606. }
  607. else
  608. {
  609. return new ApiSaveResponse()
  610. {
  611. Success = false,
  612. ErrorMessage = "指定的申诉记录不存在"
  613. };
  614. }
  615. }
  616. private void Log(string strMessage)
  617. {
  618. StreamWriter sw = System.IO.File.AppendText("c:\\temp\\log.txt");
  619. sw.WriteLine($"{strMessage}");
  620. sw.Flush();
  621. sw.Close();
  622. sw.Dispose();
  623. }
  624. }
  625. }