CaseManager.razor.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. using AntDesign;
  2. using AntDesign.TableModels;
  3. using Microsoft.AspNetCore.Components;
  4. using Microsoft.AspNetCore.Components.Web;
  5. using Microsoft.Extensions.Configuration;
  6. using ServiceStack;
  7. using ServiceStack.Script;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Threading.Tasks;
  12. using wispro.sp.entity;
  13. using wispro.sp.share;
  14. using wispro.sp.web.Pages.Organization;
  15. using wispro.sp.web.Services;
  16. namespace wispro.sp.web.Pages.AppCase
  17. {
  18. public partial class CaseManager
  19. {
  20. [Inject]
  21. protected IconService iconService { get; set; }
  22. public TableFilter<string>[] CaseCoeFilters = new TableFilter<string>[] {
  23. new() { Text = "S", Value = "S" },
  24. new() { Text = "A", Value = "A" },
  25. new() { Text = "B", Value = "B" },
  26. new() { Text = "C", Value = "C" },
  27. new() { Text = "D", Value = "D" }
  28. };
  29. [Inject]
  30. protected AppealTypeService apTypeService { get; set; }
  31. private List<PerformanceItem> _Datas;
  32. private List<StaffStatistics> MyStatistics;
  33. IEnumerable<PerformanceItem> selectedItems = new List<PerformanceItem>();
  34. private CalMonth HandlingCalMonth;
  35. private List<CalMonth> calMonths;
  36. int _pageIndex = 1;
  37. int _pageSize = 10;
  38. int _total;
  39. bool _loading = false;
  40. private Table<PerformanceItem> table;
  41. [Inject] public PerformanceItemServices _ItemService { get; set; }
  42. [Inject] public MessageService _message { get; set; }
  43. [Inject] protected NavigationManager NavigationManager { get; set; }
  44. [Inject] protected IUserService _userService { get; set; }
  45. [Inject] protected CalMonthServices _CalMonthService { get; set; }
  46. [Inject] IConfiguration _configuration { get; set; }
  47. [Inject] protected IAuthService _authService { get; set; }
  48. [Inject] protected AppealTypeService AppealTypeService { get;set; }
  49. protected override async Task OnInitializedAsync()
  50. {
  51. await _authService.CanVisitResource();
  52. await iconService.CreateFromIconfontCN("//at.alicdn.com/t/font_8d5l8fzk5b87iudi.js");
  53. calMonths = await _CalMonthService.GetAll();
  54. if (calMonths != null && calMonths.Count > 0)
  55. {
  56. await calMonthClick(calMonths[0]);
  57. }
  58. }
  59. private async Task HandleTableChange(QueryModel<PerformanceItem> queryModel)
  60. {
  61. var _user = await _userService.GetUser();
  62. _loading = true;
  63. var data = await _ItemService.Query(HandlingCalMonth, queryModel);
  64. _Datas = data.Results;
  65. _total = data.TotalCount;
  66. _loading = false;
  67. StateHasChanged();
  68. }
  69. private async Task calMonthClick(CalMonth calMonth)
  70. {
  71. HandlingCalMonth = calMonth;
  72. var data = await _ItemService.Query(HandlingCalMonth,_pageIndex ,_pageSize,null);
  73. _Datas = data.Results;
  74. _total = data.TotalCount;
  75. _loading = false;
  76. StateHasChanged();
  77. }
  78. bool isGuiDang = false;
  79. private async Task GuidangCalMonth(CalMonth calMonth)
  80. {
  81. isGuiDang = true;
  82. //还未实现,此处需要添加归档代码
  83. var fileData = await _ItemService.FinishedCalMonth(calMonth);
  84. while (!fileData.Finished)
  85. {
  86. fileData = await _ItemService.getExportDataProcessing(fileData.Id);
  87. await Task.Delay(1000);
  88. }
  89. if (!string.IsNullOrEmpty(fileData.ErrorMessage))
  90. {
  91. //calMonths = await _CalMonthService.GetAll();
  92. calMonth.Status = 4;
  93. //calMonthClick(calMonth);
  94. }
  95. isGuiDang = false;
  96. StateHasChanged();
  97. }
  98. private int serialNumber(int pageIndex, int pageSize, int id)
  99. {
  100. int iIndex = 0;
  101. foreach (PerformanceItem sf in _Datas)
  102. {
  103. iIndex++;
  104. if (sf.Id == id)
  105. {
  106. break;
  107. }
  108. }
  109. return (pageIndex - 1) * pageSize + iIndex;
  110. }
  111. bool isDownloading = false;
  112. private async Task ExportDataAsync(CalMonth calMonth)
  113. {
  114. isDownloading = true;
  115. var fileData = await _ItemService.ExportData(calMonth.Id);
  116. while (!fileData.Finished)
  117. {
  118. try
  119. {
  120. fileData = await _ItemService.getExportDataProcessing(fileData.Id);
  121. await Task.Delay(100);
  122. }
  123. catch {
  124. await Task.Delay(1000);
  125. }
  126. }
  127. NavigationManager.NavigateTo($"{_configuration.GetValue<string>("APIUrl")}FileProcesTask/Download?Id={fileData.Id}");
  128. isDownloading = false;
  129. }
  130. private async Task ExportJXDataAsync(CalMonth calMonth)
  131. {
  132. isDownloading = true;
  133. var fileData = await _ItemService.ExportJXReport(calMonth.Year,calMonth.Month);
  134. while (!fileData.Finished)
  135. {
  136. fileData = await _ItemService.getExportDataProcessing(fileData.Id);
  137. await Task.Delay(20);
  138. }
  139. NavigationManager.NavigateTo($"{_configuration.GetValue<string>("APIUrl")}FileProcesTask/Download?Id={fileData.Id}");
  140. isDownloading = false;
  141. }
  142. private async Task ExportCCSDataAsync(CalMonth calMonth)
  143. {
  144. isDownloading = true;
  145. var fileData = await AppealTypeService.ExportCustomerCCSFile(calMonth.Id);
  146. while (!fileData.Finished)
  147. {
  148. fileData = await _ItemService.getExportDataProcessing(fileData.Id);
  149. await Task.Delay(20);
  150. }
  151. NavigationManager.NavigateTo($"{_configuration.GetValue<string>("APIUrl")}FileProcesTask/Download?Id={fileData.Id}");
  152. isDownloading = false;
  153. }
  154. private async Task ExportCurrentMonthJXList()
  155. {
  156. isDownloading = true;
  157. var fileData = await _ItemService.CurrentData2Excel(HandlingCalMonth);
  158. while (!fileData.Finished)
  159. {
  160. fileData = await _ItemService.getExportDataProcessing(fileData.Id);
  161. await Task.Delay(20);
  162. }
  163. NavigationManager.NavigateTo($"{_configuration.GetValue<string>("APIUrl")}FileProcesTask/Download?Id={fileData.Id}");
  164. isDownloading = false;
  165. }
  166. async Task OnRefresh(PerformanceItem item)
  167. {
  168. item = await _ItemService.RefreshItem(item.Id);
  169. table.ReloadData();
  170. StateHasChanged();
  171. }
  172. private bool ShowSettingModal = false;
  173. private List<AllocationRatio> allocationRatios = null;
  174. private PerformanceItem CurrentItem = null;
  175. async Task ONJXAllocationRatios(PerformanceItem item)
  176. {
  177. CurrentItem = item;
  178. allocationRatios = await _ItemService.getARatios(item);
  179. if(allocationRatios == null)
  180. {
  181. allocationRatios= new List<AllocationRatio>();
  182. }
  183. if(item.ReviewerId != null && allocationRatios.Where(p=>p.PersonId == item.ReviewerId ).Count()==0)
  184. {
  185. allocationRatios.Add(new AllocationRatio() {
  186. ItemId = item.Id,
  187. PersonId = item.ReviewerId.Value,
  188. Ratio = 0,
  189. ActualAmount = 0
  190. });
  191. }
  192. if (item.ExternalHandlerId != null && allocationRatios.Where(p => p.PersonId == item.ExternalHandlerId).Count() == 0)
  193. {
  194. allocationRatios.Add(new AllocationRatio()
  195. {
  196. ItemId = item.Id,
  197. PersonId = item.ExternalHandlerId.Value,
  198. Ratio = 0,
  199. ActualAmount = 0
  200. });
  201. }
  202. foreach(var iStaff in item.ItemStaffs)
  203. {
  204. if (allocationRatios.Where(p => p.PersonId == iStaff.DoPersonId).Count() == 0)
  205. {
  206. allocationRatios.Add(new AllocationRatio()
  207. {
  208. ItemId = item.Id,
  209. PersonId = iStaff.DoPersonId,
  210. Ratio = 0,
  211. ActualAmount = 0
  212. });
  213. }
  214. }
  215. ShowSettingModal = true;
  216. }
  217. private AllocationRatio getAllocationRatio(Staff person)
  218. {
  219. var retObj= allocationRatios.Where(a => a.PersonId == person.Id).FirstOrDefault();
  220. if (retObj == null)
  221. {
  222. retObj = new AllocationRatio() {
  223. Person = person,
  224. PersonId = person.Id,
  225. Ratio = 0,
  226. ItemId = CurrentItem.Id
  227. };
  228. }
  229. return retObj;
  230. }
  231. private async System.Threading.Tasks.Task btnOk(MouseEventArgs e)
  232. {
  233. foreach(var ar in allocationRatios)
  234. {
  235. ar.Person = null;
  236. ar.Item = null;
  237. }
  238. Console.WriteLine("1");
  239. var zeros = allocationRatios.Where(i => i.Ratio.Value == 0).ToList();
  240. foreach(var a in zeros)
  241. {
  242. allocationRatios.Remove(a);
  243. }
  244. Console.WriteLine("2");
  245. if (allocationRatios.Sum(i => i.Ratio.Value) == 100)
  246. {
  247. await _ItemService.SaveAllocationRatios(allocationRatios);
  248. ShowSettingModal = false;
  249. StateHasChanged();
  250. }
  251. else
  252. {
  253. Console.WriteLine("3");
  254. await _message.Error("分配比率相加应该等于100!");
  255. }
  256. }
  257. private void btnCancel(MouseEventArgs e)
  258. {
  259. ShowSettingModal = false;
  260. }
  261. async Task<string> CalItemJX(PerformanceItem item)
  262. {
  263. return null;
  264. }
  265. private bool isExistAllocationRatios(PerformanceItem item)
  266. {
  267. return (item.AllocationRatios != null && item.AllocationRatios.Count > 0);
  268. }
  269. private string AllocationRatioString(PerformanceItem item)
  270. {
  271. string strTem = string.Empty;
  272. if (item.AllocationRatios != null)
  273. {
  274. foreach (var ra in item.AllocationRatios)
  275. {
  276. strTem = $"{strTem},{ra.Person.Name}【{ra.Ratio}%】";
  277. }
  278. }
  279. if (!string.IsNullOrEmpty(strTem))
  280. {
  281. strTem = strTem.Substring(1);
  282. }
  283. return strTem;
  284. }
  285. private async Task getAllocationRatios(PerformanceItem item)
  286. {
  287. string strTem = "";
  288. var ratios = await _ItemService.getARatios(item);
  289. item.AllocationRatios = ratios;
  290. StateHasChanged();
  291. }
  292. }
  293. }