CaseManager.razor.cs 12 KB

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