CaseManager.razor.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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. {
  134. await Task.Delay(1000);
  135. }
  136. }
  137. NavigationManager.NavigateTo($"{_configuration.GetValue<string>("APIUrl")}FileProcesTask/Download?Id={fileData.Id}");
  138. isDownloading = false;
  139. }
  140. private async Task ExportJXDataAsync(CalMonth calMonth)
  141. {
  142. isDownloading = true;
  143. var fileData = await _ItemService.ExportJXReport(calMonth.Year, calMonth.Month);
  144. while (!fileData.Finished)
  145. {
  146. fileData = await _ItemService.getExportDataProcessing(fileData.Id);
  147. await Task.Delay(20);
  148. }
  149. NavigationManager.NavigateTo($"{_configuration.GetValue<string>("APIUrl")}FileProcesTask/Download?Id={fileData.Id}");
  150. isDownloading = false;
  151. }
  152. private async Task ExportJXPointAsync(CalMonth calMonth)
  153. {
  154. isDownloading = true;
  155. var fileData = await _ItemService.ExportJXPointReport(calMonth.Year, calMonth.Month);
  156. while (!fileData.Finished)
  157. {
  158. fileData = await _ItemService.getExportDataProcessing(fileData.Id);
  159. await Task.Delay(20);
  160. }
  161. NavigationManager.NavigateTo($"{_configuration.GetValue<string>("APIUrl")}FileProcesTask/Download?Id={fileData.Id}");
  162. isDownloading = false;
  163. }
  164. private async Task ExportJXMoneyAsync(CalMonth calMonth)
  165. {
  166. isDownloading = true;
  167. var fileData = await _ItemService.ExportJXMoneyAsync(calMonth.Year, calMonth.Month);
  168. while (!fileData.Finished)
  169. {
  170. fileData = await _ItemService.getExportDataProcessing(fileData.Id);
  171. await Task.Delay(20);
  172. }
  173. NavigationManager.NavigateTo($"{_configuration.GetValue<string>("APIUrl")}FileProcesTask/Download?Id={fileData.Id}");
  174. isDownloading = false;
  175. }
  176. private async Task ExportJXTotalMoneyAsync(CalMonth calMonth)
  177. {
  178. isDownloading = true;
  179. var fileData = await _ItemService.ExportJXTotalMoneyAsync(calMonth.Year, calMonth.Month);
  180. while (!fileData.Finished)
  181. {
  182. fileData = await _ItemService.getExportDataProcessing(fileData.Id);
  183. await Task.Delay(20);
  184. }
  185. NavigationManager.NavigateTo($"{_configuration.GetValue<string>("APIUrl")}FileProcesTask/Download?Id={fileData.Id}");
  186. isDownloading = false;
  187. }
  188. private async Task ExportCCSDataAsync(CalMonth calMonth)
  189. {
  190. isDownloading = true;
  191. var fileData = await AppealTypeService.ExportCustomerCCSFile(calMonth.Id);
  192. while (!fileData.Finished)
  193. {
  194. fileData = await _ItemService.getExportDataProcessing(fileData.Id);
  195. await Task.Delay(20);
  196. }
  197. NavigationManager.NavigateTo($"{_configuration.GetValue<string>("APIUrl")}FileProcesTask/Download?Id={fileData.Id}");
  198. isDownloading = false;
  199. }
  200. private async Task ExportCurrentMonthJXList()
  201. {
  202. isDownloading = true;
  203. var fileData = await _ItemService.CurrentData2Excel(HandlingCalMonth);
  204. while (!fileData.Finished)
  205. {
  206. fileData = await _ItemService.getExportDataProcessing(fileData.Id);
  207. await Task.Delay(20);
  208. }
  209. NavigationManager.NavigateTo($"{_configuration.GetValue<string>("APIUrl")}FileProcesTask/Download?Id={fileData.Id}");
  210. isDownloading = false;
  211. }
  212. async Task OnRefresh(PerformanceItem item)
  213. {
  214. item = await _ItemService.RefreshItem(item.Id);
  215. table.ReloadData();
  216. StateHasChanged();
  217. }
  218. private bool ShowSettingModal = false;
  219. private List<AllocationRatio> allocationRatios = null;
  220. private PerformanceItem CurrentItem = null;
  221. async Task ONJXAllocationRatios(PerformanceItem item)
  222. {
  223. CurrentItem = item;
  224. allocationRatios = await _ItemService.getARatios(item);
  225. if (allocationRatios == null)
  226. {
  227. allocationRatios = new List<AllocationRatio>();
  228. }
  229. if (item.ReviewerId != null && allocationRatios.Where(p => p.PersonId == item.ReviewerId).Count() == 0)
  230. {
  231. allocationRatios.Add(new AllocationRatio()
  232. {
  233. ItemId = item.Id,
  234. PersonId = item.ReviewerId.Value,
  235. Ratio = 0,
  236. ActualAmount = 0
  237. });
  238. }
  239. if (item.ExternalHandlerId != null && allocationRatios.Where(p => p.PersonId == item.ExternalHandlerId).Count() == 0)
  240. {
  241. allocationRatios.Add(new AllocationRatio()
  242. {
  243. ItemId = item.Id,
  244. PersonId = item.ExternalHandlerId.Value,
  245. Ratio = 0,
  246. ActualAmount = 0
  247. });
  248. }
  249. foreach (var iStaff in item.ItemStaffs)
  250. {
  251. if (allocationRatios.Where(p => p.PersonId == iStaff.DoPersonId).Count() == 0)
  252. {
  253. allocationRatios.Add(new AllocationRatio()
  254. {
  255. ItemId = item.Id,
  256. PersonId = iStaff.DoPersonId,
  257. Ratio = 0,
  258. ActualAmount = 0
  259. });
  260. }
  261. }
  262. ShowSettingModal = true;
  263. }
  264. private AllocationRatio getAllocationRatio(Staff person)
  265. {
  266. var retObj = allocationRatios.Where(a => a.PersonId == person.Id).FirstOrDefault();
  267. if (retObj == null)
  268. {
  269. retObj = new AllocationRatio()
  270. {
  271. Person = person,
  272. PersonId = person.Id,
  273. Ratio = 0,
  274. ItemId = CurrentItem.Id
  275. };
  276. }
  277. return retObj;
  278. }
  279. private async System.Threading.Tasks.Task btnOk(MouseEventArgs e)
  280. {
  281. foreach (var ar in allocationRatios)
  282. {
  283. ar.Person = null;
  284. ar.Item = null;
  285. }
  286. Console.WriteLine("1");
  287. var zeros = allocationRatios.Where(i => i.Ratio.Value == 0).ToList();
  288. foreach (var a in zeros)
  289. {
  290. allocationRatios.Remove(a);
  291. }
  292. Console.WriteLine("2");
  293. if (allocationRatios.Sum(i => i.Ratio.Value) == 100)
  294. {
  295. await _ItemService.SaveAllocationRatios(allocationRatios);
  296. ShowSettingModal = false;
  297. StateHasChanged();
  298. }
  299. else
  300. {
  301. Console.WriteLine("3");
  302. await _message.Error("分配比率相加应该等于100!");
  303. }
  304. }
  305. private void btnCancel(MouseEventArgs e)
  306. {
  307. ShowSettingModal = false;
  308. }
  309. async Task<string> CalItemJX(PerformanceItem item)
  310. {
  311. return null;
  312. }
  313. private bool isExistAllocationRatios(PerformanceItem item)
  314. {
  315. return (item.AllocationRatios != null && item.AllocationRatios.Count > 0);
  316. }
  317. private Double ActualAmount(PerformanceItem item)
  318. {
  319. double ret = 0.0;
  320. if (item.AllocationRatios != null)
  321. {
  322. foreach (var ra in item.AllocationRatios)
  323. {
  324. ret += ra.ActualAmount.Value;
  325. }
  326. }
  327. return ret;
  328. }
  329. private string AllocationRatioString(PerformanceItem item)
  330. {
  331. string strTem = string.Empty;
  332. if (item.AllocationRatios != null)
  333. {
  334. foreach (var ra in item.AllocationRatios)
  335. {
  336. strTem = $"{strTem},{ra.Person.Name}【实际金额:{ra.ActualAmount},比率:{ra.Ratio}%】";
  337. }
  338. }
  339. if (!string.IsNullOrEmpty(strTem))
  340. {
  341. strTem = strTem.Substring(1);
  342. }
  343. return strTem;
  344. }
  345. private async Task getAllocationRatios(PerformanceItem item)
  346. {
  347. string strTem = "";
  348. var ratios = await _ItemService.getARatios(item);
  349. item.AllocationRatios = ratios;
  350. StateHasChanged();
  351. }
  352. }
  353. }