IPEasyController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text.Json;
  9. using System.Threading.Tasks;
  10. using wispro.sp.entity;
  11. namespace wispro.sp.api.Controllers
  12. {
  13. [Route("api/[controller]/[action]")]
  14. [ApiController]
  15. [Authorize]
  16. public class IPEasyController : ControllerBase
  17. {
  18. spDbContext Context;
  19. public IPEasyController(spDbContext context)
  20. {
  21. Context = context;
  22. }
  23. #region 将从IPEasy中获得的信息保存到临时文件或从文件中取出已存在的信息
  24. private PerformanceItem GetFromCache(string CaseNo, string DoItem = null)
  25. {
  26. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  27. string fileName = $"{CaseNo}{(string.IsNullOrEmpty(DoItem) ? "" : $"-{DoItem}")}.json";
  28. var path = Path.Combine(attachfileSavePath,
  29. fileName);
  30. if (System.IO.File.Exists(path))
  31. {
  32. if (new FileInfo(path).CreationTime < DateTime.Now.AddDays(-1))
  33. {
  34. return null;
  35. }
  36. using (var file = System.IO.File.OpenText(path))
  37. {
  38. string strJson = file.ReadToEnd();
  39. JsonSerializerOptions options = new System.Text.Json.JsonSerializerOptions()
  40. {
  41. IgnoreNullValues = true
  42. };
  43. return System.Text.Json.JsonSerializer.Deserialize<PerformanceItem>(strJson, options);
  44. }
  45. }
  46. else
  47. {
  48. return null;
  49. }
  50. }
  51. private void SaveToCache(PerformanceItem Item)
  52. {
  53. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  54. string fileName = $"{Item.CaseNo}{(string.IsNullOrEmpty(Item.DoItem) ? "" : $"-{Item.DoItem}")}.json";
  55. var path = Path.Combine(attachfileSavePath,
  56. fileName);
  57. if (System.IO.File.Exists(path))
  58. {
  59. System.IO.File.Delete(path);
  60. }
  61. JsonSerializerOptions options = new System.Text.Json.JsonSerializerOptions()
  62. {
  63. IgnoreNullValues = true
  64. };
  65. string strJson = System.Text.Json.JsonSerializer.Serialize<PerformanceItem>(Item, options);
  66. using (var file = System.IO.File.CreateText(path))
  67. {
  68. file.Write(strJson);
  69. }
  70. }
  71. #endregion
  72. public PerformanceItem GetCaseInfo(string CaseNo)
  73. {
  74. var retItem = GetFromCache(CaseNo);
  75. if (retItem != null)
  76. {
  77. return retItem;
  78. }
  79. else
  80. {
  81. dynamic retObj = wispro.sp.utility.IPEasyUtility.GetCaseInfo(CaseNo);
  82. PerformanceItem Item = new PerformanceItem();
  83. Item.CaseName = retObj.CaseName;
  84. Item.CaseNo = retObj.CaseNo;
  85. Item.Customer = new Customer();
  86. Item.Customer.Name = retObj.CustomerName;
  87. Item.Customer.Name = Item.Customer.Name.Replace("(null)", "");
  88. Item.ApplicationType = retObj.ApplicationType;
  89. Item.BusinessType = retObj.BusinessType;
  90. Item.CaseCoefficient = retObj.CaseCoefficient;
  91. Item.CaseMemo = retObj.CaseMemo;
  92. Item.CaseState = retObj.CaseState;
  93. Item.CaseType = retObj.CaseType;
  94. SaveToCache(Item);
  95. return Item;
  96. }
  97. }
  98. public PerformanceItem GetItemInfo(string CaseNo, string DoItem)
  99. {
  100. var retItem = GetFromCache(CaseNo, DoItem);
  101. if (retItem != null)
  102. {
  103. return retItem;
  104. }
  105. else
  106. {
  107. dynamic retObj = new Job.UpdateJXDataFromIPEasyJob().GetItemFromIPEasyDB(new PerformanceItem()
  108. {
  109. CaseNo = CaseNo,
  110. DoItem = DoItem
  111. }, new spDbContext());// wispro.sp.utility.IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem);
  112. PerformanceItem Item = new PerformanceItem();
  113. Item.CaseName = retObj.CaseName;
  114. Item.CaseNo = retObj.CaseNo;
  115. Item.DoItem = retObj.DoItem;
  116. Item.CustomerLimitDate = string.IsNullOrEmpty(retObj.CustomerLimitDate) ? null : DateTime.Parse(retObj.CustomerLimitDate);
  117. Item.Customer = new Customer();
  118. Item.Customer.Name = retObj.CustomerName;
  119. Item.Customer.Name = Item.Customer.Name.Replace("(null)", "");
  120. Item.DoItemCoefficient = retObj.DoItemCoefficient;
  121. Item.DoItemMemo = retObj.DoItemMemo;
  122. Item.DoItemState = retObj.DoItemState;
  123. Item.EntrustingDate = string.IsNullOrEmpty(retObj.EntrustingDate) ? null : DateTime.Parse(retObj.EntrustingDate);
  124. Item.FinalizationDate = string.IsNullOrEmpty(retObj.FinalizationDate) ? null : DateTime.Parse(retObj.FinalizationDate);
  125. Item.FinishedDate = string.IsNullOrEmpty(retObj.FinishedDate) ? null : DateTime.Parse(retObj.FinishedDate);
  126. //Item.FirstDraftDate = string.IsNullOrEmpty(retObj.FirstDraftDate) ? null : DateTime.Parse(retObj.FirstDraftDate);
  127. Item.InternalDate = string.IsNullOrEmpty(retObj.InternalDate) ? null : DateTime.Parse(retObj.InternalDate);
  128. Item.WordCount = string.IsNullOrEmpty(retObj.WordCount) ? null : int.Parse(retObj.WordCount);
  129. if (!string.IsNullOrEmpty(retObj.DoPersons))
  130. {
  131. Item.ItemStaffs = new List<ItemStaff>();
  132. string[] names = retObj.DoPersons.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  133. foreach (var name in names)
  134. {
  135. ItemStaff iStaff = new ItemStaff();
  136. iStaff.DoPerson = Context.Staffs.Where<Staff>(s => s.Name == name).FirstOrDefault();
  137. if (iStaff.DoPerson == null)
  138. {
  139. iStaff.DoPerson = new Staff() { Name = name };
  140. }
  141. else
  142. {
  143. iStaff.DoPersonId = iStaff.DoPerson.Id;
  144. }
  145. Item.ItemStaffs.Add(iStaff);
  146. }
  147. }
  148. Item.ReturnDate = string.IsNullOrEmpty(retObj.ReturnDate) ? null : DateTime.Parse(retObj.ReturnDate);
  149. if (!string.IsNullOrEmpty(retObj.Reviewer))
  150. {
  151. string name = retObj.Reviewer;
  152. var temReviewer = Context.Staffs.Where<Staff>(s => s.Name == name).FirstOrDefault();
  153. if (temReviewer == null)
  154. {
  155. Item.Reviewer = new Staff() { Name = retObj.Reviewer };
  156. }
  157. else
  158. {
  159. Item.Reviewer = temReviewer;
  160. Item.ReviewerId = temReviewer.Id;
  161. }
  162. }
  163. Item.ApplicationType = retObj.ApplicationType;
  164. Item.BusinessType = retObj.BusinessType;
  165. Item.CaseCoefficient = retObj.CaseCoefficient;
  166. Item.CaseMemo = retObj.CaseMemo;
  167. Item.CaseStage = retObj.CaseStage;
  168. Item.CaseState = retObj.CaseState;
  169. Item.CaseType = retObj.CaseType;
  170. SaveToCache(Item);
  171. return Item;
  172. }
  173. }
  174. public PerformanceItem GetDoItemInfo(string CaseNo, string DoItem, string caseStage)
  175. {
  176. var retItem = GetFromCache(CaseNo, DoItem);
  177. if (retItem != null)
  178. {
  179. return retItem;
  180. }
  181. else
  182. {
  183. dynamic retObj = new Job.UpdateJXDataFromIPEasyJob().GetItemFromIPEasyDB(
  184. new PerformanceItem() { CaseNo = CaseNo, DoItem = DoItem, CaseStage = caseStage },
  185. new spDbContext()
  186. ); //wispro.sp.utility.IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem,caseStage);
  187. PerformanceItem Item = new PerformanceItem();
  188. Item.CaseName = retObj.CaseName;
  189. Item.CaseNo = retObj.CaseNo;
  190. Item.DoItem = retObj.DoItem;
  191. Item.CustomerLimitDate = string.IsNullOrEmpty(retObj.CustomerLimitDate) ? null : DateTime.Parse(retObj.CustomerLimitDate);
  192. Item.Customer = new Customer();
  193. Item.Customer.Name = retObj.CustomerName;
  194. Item.Customer.Name = Item.Customer.Name.Replace("(null)", "");
  195. Item.DoItemCoefficient = retObj.DoItemCoefficient;
  196. Item.DoItemMemo = retObj.DoItemMemo;
  197. Item.DoItemState = retObj.DoItemState;
  198. Item.EntrustingDate = string.IsNullOrEmpty(retObj.EntrustingDate) ? null : DateTime.Parse(retObj.EntrustingDate);
  199. Item.FinalizationDate = string.IsNullOrEmpty(retObj.FinalizationDate) ? null : DateTime.Parse(retObj.FinalizationDate);
  200. Item.FinishedDate = string.IsNullOrEmpty(retObj.FinishedDate) ? null : DateTime.Parse(retObj.FinishedDate);
  201. //Item.FirstDraftDate = string.IsNullOrEmpty(retObj.FirstDraftDate) ? null : DateTime.Parse(retObj.FirstDraftDate);
  202. Item.InternalDate = string.IsNullOrEmpty(retObj.InternalDate) ? null : DateTime.Parse(retObj.InternalDate);
  203. Item.WordCount = string.IsNullOrEmpty(retObj.WordCount) ? null : int.Parse(retObj.WordCount);
  204. if (!string.IsNullOrEmpty(retObj.DoPersons))
  205. {
  206. Item.ItemStaffs = new List<ItemStaff>();
  207. string[] names = retObj.DoPersons.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  208. foreach (var name in names)
  209. {
  210. ItemStaff iStaff = new ItemStaff();
  211. iStaff.DoPerson = Context.Staffs.Where<Staff>(s => s.Name == name).FirstOrDefault();
  212. if (iStaff.DoPerson == null)
  213. {
  214. iStaff.DoPerson = new Staff() { Name = name };
  215. }
  216. else
  217. {
  218. iStaff.DoPersonId = iStaff.DoPerson.Id;
  219. }
  220. Item.ItemStaffs.Add(iStaff);
  221. }
  222. }
  223. Item.ReturnDate = string.IsNullOrEmpty(retObj.ReturnDate) ? null : DateTime.Parse(retObj.ReturnDate);
  224. if (!string.IsNullOrEmpty(retObj.Reviewer))
  225. {
  226. string name = retObj.Reviewer;
  227. var temReviewer = Context.Staffs.Where<Staff>(s => s.Name == name).FirstOrDefault();
  228. if (temReviewer == null)
  229. {
  230. Item.Reviewer = new Staff() { Name = retObj.Reviewer };
  231. }
  232. else
  233. {
  234. Item.Reviewer = temReviewer;
  235. Item.ReviewerId = temReviewer.Id;
  236. }
  237. }
  238. Item.ApplicationType = retObj.ApplicationType;
  239. Item.BusinessType = retObj.BusinessType;
  240. Item.CaseCoefficient = retObj.CaseCoefficient;
  241. Item.CaseMemo = retObj.CaseMemo;
  242. Item.CaseStage = retObj.CaseStage;
  243. Item.CaseState = retObj.CaseState;
  244. Item.CaseType = retObj.CaseType;
  245. SaveToCache(Item);
  246. return Item;
  247. }
  248. }
  249. }
  250. }