IPEasyController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. IgnoreNullValues = true
  63. };
  64. string strJson = System.Text.Json.JsonSerializer.Serialize<PerformanceItem>(Item,options);
  65. using (var file = System.IO.File.CreateText(path))
  66. {
  67. file.Write(strJson);
  68. }
  69. }
  70. #endregion
  71. public PerformanceItem GetCaseInfo(string CaseNo)
  72. {
  73. var retItem = GetFromCache(CaseNo);
  74. if (retItem != null)
  75. {
  76. return retItem;
  77. }
  78. else
  79. {
  80. dynamic retObj = wispro.sp.utility.IPEasyUtility.GetCaseInfo(CaseNo);
  81. PerformanceItem Item = new PerformanceItem();
  82. Item.CaseName = retObj.CaseName;
  83. Item.CaseNo = retObj.CaseNo;
  84. Item.Customer = new Customer();
  85. Item.Customer.Name = retObj.CustomerName;
  86. Item.Customer.Name = Item.Customer.Name.Replace("(null)", "");
  87. Item.ApplicationType = retObj.ApplicationType;
  88. Item.BusinessType = retObj.BusinessType;
  89. Item.CaseCoefficient = retObj.CaseCoefficient;
  90. Item.CaseMemo = retObj.CaseMemo;
  91. Item.CaseState = retObj.CaseState;
  92. Item.CaseType = retObj.CaseType;
  93. SaveToCache(Item);
  94. return Item;
  95. }
  96. }
  97. public PerformanceItem GetItemInfo(string CaseNo, string DoItem)
  98. {
  99. var retItem = GetFromCache(CaseNo,DoItem);
  100. if (retItem != null)
  101. {
  102. return retItem;
  103. }
  104. else
  105. {
  106. dynamic retObj = new Job.UpdateJXDataFromIPEasyJob().GetItemFromIPEasyDB(new PerformanceItem() {
  107. CaseNo = CaseNo,DoItem = DoItem
  108. },new spDbContext());// wispro.sp.utility.IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem);
  109. PerformanceItem Item = new PerformanceItem();
  110. Item.CaseName = retObj.CaseName;
  111. Item.CaseNo = retObj.CaseNo;
  112. Item.DoItem = retObj.DoItem;
  113. Item.CustomerLimitDate = string.IsNullOrEmpty(retObj.CustomerLimitDate) ? null : DateTime.Parse(retObj.CustomerLimitDate);
  114. Item.Customer = new Customer();
  115. Item.Customer.Name = retObj.CustomerName;
  116. Item.Customer.Name = Item.Customer.Name.Replace("(null)", "");
  117. Item.DoItemCoefficient = retObj.DoItemCoefficient;
  118. Item.DoItemMemo = retObj.DoItemMemo;
  119. Item.DoItemState = retObj.DoItemState;
  120. Item.EntrustingDate = string.IsNullOrEmpty(retObj.EntrustingDate) ? null : DateTime.Parse(retObj.EntrustingDate);
  121. Item.FinalizationDate = string.IsNullOrEmpty(retObj.FinalizationDate) ? null : DateTime.Parse(retObj.FinalizationDate);
  122. Item.FinishedDate = string.IsNullOrEmpty(retObj.FinishedDate) ? null : DateTime.Parse(retObj.FinishedDate);
  123. //Item.FirstDraftDate = string.IsNullOrEmpty(retObj.FirstDraftDate) ? null : DateTime.Parse(retObj.FirstDraftDate);
  124. Item.InternalDate = string.IsNullOrEmpty(retObj.InternalDate) ? null : DateTime.Parse(retObj.InternalDate);
  125. Item.WordCount = string.IsNullOrEmpty(retObj.WordCount) ? null : int.Parse(retObj.WordCount);
  126. if (!string.IsNullOrEmpty(retObj.DoPersons))
  127. {
  128. Item.ItemStaffs = new List<ItemStaff>();
  129. string[] names = retObj.DoPersons.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  130. foreach (var name in names)
  131. {
  132. ItemStaff iStaff = new ItemStaff();
  133. iStaff.DoPerson = Context.Staffs.Where<Staff>(s => s.Name == name).FirstOrDefault();
  134. if (iStaff.DoPerson == null)
  135. {
  136. iStaff.DoPerson = new Staff() { Name = name };
  137. }
  138. else
  139. {
  140. iStaff.DoPersonId = iStaff.DoPerson.Id;
  141. }
  142. Item.ItemStaffs.Add(iStaff);
  143. }
  144. }
  145. Item.ReturnDate = string.IsNullOrEmpty(retObj.ReturnDate) ? null : DateTime.Parse(retObj.ReturnDate);
  146. if (!string.IsNullOrEmpty(retObj.Reviewer))
  147. {
  148. string name = retObj.Reviewer;
  149. var temReviewer = Context.Staffs.Where<Staff>(s => s.Name == name).FirstOrDefault();
  150. if (temReviewer == null)
  151. {
  152. Item.Reviewer = new Staff() { Name = retObj.Reviewer };
  153. }
  154. else
  155. {
  156. Item.Reviewer = temReviewer;
  157. Item.ReviewerId = temReviewer.Id;
  158. }
  159. }
  160. Item.ApplicationType = retObj.ApplicationType;
  161. Item.BusinessType = retObj.BusinessType;
  162. Item.CaseCoefficient = retObj.CaseCoefficient;
  163. Item.CaseMemo = retObj.CaseMemo;
  164. Item.CaseStage = retObj.CaseStage;
  165. Item.CaseState = retObj.CaseState;
  166. Item.CaseType = retObj.CaseType;
  167. SaveToCache(Item);
  168. return Item;
  169. }
  170. }
  171. public PerformanceItem GetDoItemInfo(string CaseNo, string DoItem,string caseStage)
  172. {
  173. var retItem = GetFromCache(CaseNo, DoItem);
  174. if (retItem != null)
  175. {
  176. return retItem;
  177. }
  178. else
  179. {
  180. dynamic retObj = new Job.UpdateJXDataFromIPEasyJob().GetItemFromIPEasyDB(
  181. new PerformanceItem() { CaseNo =CaseNo,DoItem=DoItem,CaseStage = caseStage},
  182. new spDbContext()
  183. ); //wispro.sp.utility.IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem,caseStage);
  184. PerformanceItem Item = new PerformanceItem();
  185. Item.CaseName = retObj.CaseName;
  186. Item.CaseNo = retObj.CaseNo;
  187. Item.DoItem = retObj.DoItem;
  188. Item.CustomerLimitDate = string.IsNullOrEmpty(retObj.CustomerLimitDate) ? null : DateTime.Parse(retObj.CustomerLimitDate);
  189. Item.Customer = new Customer();
  190. Item.Customer.Name = retObj.CustomerName;
  191. Item.Customer.Name = Item.Customer.Name.Replace("(null)", "");
  192. Item.DoItemCoefficient = retObj.DoItemCoefficient;
  193. Item.DoItemMemo = retObj.DoItemMemo;
  194. Item.DoItemState = retObj.DoItemState;
  195. Item.EntrustingDate = string.IsNullOrEmpty(retObj.EntrustingDate) ? null : DateTime.Parse(retObj.EntrustingDate);
  196. Item.FinalizationDate = string.IsNullOrEmpty(retObj.FinalizationDate) ? null : DateTime.Parse(retObj.FinalizationDate);
  197. Item.FinishedDate = string.IsNullOrEmpty(retObj.FinishedDate) ? null : DateTime.Parse(retObj.FinishedDate);
  198. //Item.FirstDraftDate = string.IsNullOrEmpty(retObj.FirstDraftDate) ? null : DateTime.Parse(retObj.FirstDraftDate);
  199. Item.InternalDate = string.IsNullOrEmpty(retObj.InternalDate) ? null : DateTime.Parse(retObj.InternalDate);
  200. Item.WordCount = string.IsNullOrEmpty(retObj.WordCount) ? null : int.Parse(retObj.WordCount);
  201. if (!string.IsNullOrEmpty(retObj.DoPersons))
  202. {
  203. Item.ItemStaffs = new List<ItemStaff>();
  204. string[] names = retObj.DoPersons.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  205. foreach (var name in names)
  206. {
  207. ItemStaff iStaff = new ItemStaff();
  208. iStaff.DoPerson = Context.Staffs.Where<Staff>(s => s.Name == name).FirstOrDefault();
  209. if (iStaff.DoPerson == null)
  210. {
  211. iStaff.DoPerson = new Staff() { Name = name };
  212. }
  213. else
  214. {
  215. iStaff.DoPersonId = iStaff.DoPerson.Id;
  216. }
  217. Item.ItemStaffs.Add(iStaff);
  218. }
  219. }
  220. Item.ReturnDate = string.IsNullOrEmpty(retObj.ReturnDate) ? null : DateTime.Parse(retObj.ReturnDate);
  221. if (!string.IsNullOrEmpty(retObj.Reviewer))
  222. {
  223. string name = retObj.Reviewer;
  224. var temReviewer = Context.Staffs.Where<Staff>(s => s.Name == name).FirstOrDefault();
  225. if (temReviewer == null)
  226. {
  227. Item.Reviewer = new Staff() { Name = retObj.Reviewer };
  228. }
  229. else
  230. {
  231. Item.Reviewer = temReviewer;
  232. Item.ReviewerId = temReviewer.Id;
  233. }
  234. }
  235. Item.ApplicationType = retObj.ApplicationType;
  236. Item.BusinessType = retObj.BusinessType;
  237. Item.CaseCoefficient = retObj.CaseCoefficient;
  238. Item.CaseMemo = retObj.CaseMemo;
  239. Item.CaseStage = retObj.CaseStage;
  240. Item.CaseState = retObj.CaseState;
  241. Item.CaseType = retObj.CaseType;
  242. SaveToCache(Item);
  243. return Item;
  244. }
  245. }
  246. }
  247. }