CaseManager.razor.cs 14 KB

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