PerformanceItemServices.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. using AntDesign.TableModels;
  2. using Microsoft.AspNetCore.Components.Authorization;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Net.Http;
  7. using System.Net.Http.Json;
  8. using System.Threading.Tasks;
  9. using wispro.sp.entity;
  10. using wispro.sp.share;
  11. using wispro.sp.web.Auth;
  12. using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
  13. namespace wispro.sp.web.Services
  14. {
  15. public class PerformanceItemServices
  16. {
  17. private readonly IHttpService _httpClient;
  18. private readonly JwtAuthenticationStateProvider _jwt;
  19. public PerformanceItemServices(IHttpService httpClient, AuthenticationStateProvider jwt)
  20. {
  21. _httpClient = httpClient;
  22. _jwt = (JwtAuthenticationStateProvider)jwt;
  23. }
  24. public async Task<ListApiResponse<PerformanceItem>> GetItems(int _pageIndex, int _pageSize)
  25. {
  26. ListApiResponse<PerformanceItem> data = await _httpClient.Get<ListApiResponse<PerformanceItem>>($"PerformanceItem/Query?pageIndex={_pageIndex}&pageSize={_pageSize}");
  27. return data;
  28. }
  29. public async Task<ApiSaveResponse> SaveFieldChange(int id, string Field, string value)
  30. {
  31. ApiSaveResponse data = await _httpClient.Get<ApiSaveResponse>($"PerformanceItem/UpdateFieldValue?id={id}&field={Field}&value={value}");
  32. return data;
  33. }
  34. public async Task<PerformanceItem> GetPerformancItem(int Id)
  35. {
  36. PerformanceItem data = await _httpClient.Get<PerformanceItem>($"PerformanceItem/Get?Id={Id}");
  37. return data;
  38. }
  39. public async Task<ListApiResponse<PerformanceItem>> GetMyList(int userid, jxType type, int pageIndex = 1, int pageSize = 5)
  40. {
  41. ListApiResponse<PerformanceItem> data = await _httpClient.Get<ListApiResponse<PerformanceItem>>($"PerformanceItem/GetMyList?userid={userid}&Type={Convert.ToInt32(type)}&pageIndex={pageIndex}&pageSize={pageSize}");
  42. return data;
  43. }
  44. public async Task<FileProcessTask> ExportData(int calMonthId)
  45. {
  46. QueryFilter query = new QueryFilter();
  47. query.CalMonthId = calMonthId;
  48. query.PageIndex = 1;
  49. query.PageSize = 1;
  50. query.ConditionTree = new List<FieldCondition>();
  51. query.Sorts = new List<OrderField>();
  52. var fileData = await _httpClient.Post<FileProcessTask>($"PerformanceItem/ExportData", query);
  53. return fileData;
  54. }
  55. public async Task<FileProcessTask> ExportJXReport(int Year, int month)
  56. {
  57. var fileData = await _httpClient.Get<FileProcessTask>($"PerformanceItem/GetStaticsReport?Year={Year}&Month={month}");
  58. return fileData;
  59. }
  60. public async Task<FileProcessTask> CurrentData2Excel(CalMonth calMonth)
  61. {
  62. var fileData = await _httpClient.Get<FileProcessTask>($"PerformanceItem/CurrentData2Excel?Year={calMonth.Year}&Month={calMonth.Month}");
  63. return fileData;
  64. }
  65. public async Task<FileProcessTask> ExportData(int calMonthId, int userid, jxType jxType, int DoingOrReview = 0)
  66. {
  67. QueryFilter query = new QueryFilter();
  68. query.userId = userid;
  69. query.jxType = jxType;
  70. query.CalMonthId = calMonthId;
  71. query.DoingOrReview = DoingOrReview;
  72. query.PageIndex = 1;
  73. query.PageSize = 1;
  74. query.ConditionTree = new List<FieldCondition>();
  75. query.Sorts = new List<OrderField>();
  76. var fileData = await _httpClient.Post<FileProcessTask>($"PerformanceItem/ExportData", query);
  77. return fileData;
  78. }
  79. public async Task<FileProcessTask> getExportDataProcessing(string id)
  80. {
  81. var fileData = await _httpClient.Get<FileProcessTask>($"FileProcesTask/Get?Id={id}");
  82. return fileData;
  83. }
  84. public async Task<ListApiResponse<PerformanceItem>> Query(CalMonth calMonth, int pageIndex, int pageSize, string sortFieldName)
  85. {
  86. QueryFilter query = new QueryFilter();
  87. query.userId = 0;
  88. query.jxType = jxType.all;
  89. query.CalMonthId = calMonth.Id;
  90. query.PageIndex = pageIndex;
  91. query.PageSize = pageSize;
  92. if (!string.IsNullOrEmpty(sortFieldName))
  93. {
  94. query.Sorts = new List<OrderField>()
  95. {
  96. new OrderField(){FieldName = sortFieldName}
  97. };
  98. }
  99. var data = await _httpClient.Post<ListApiResponse<PerformanceItem>>($"PerformanceItem/QueryFilter", query);
  100. return data;
  101. }
  102. public async Task<FileProcessTask> FinishedCalMonth(CalMonth calMonth)
  103. {
  104. var ret = await _httpClient.Get<FileProcessTask>($"PerformanceItem/FinishedCalMonth?year={calMonth.Year}&month={calMonth.Month}");
  105. return ret;
  106. }
  107. public async Task<ListApiResponse<PerformanceItem>> Query(CalMonth calMonth, QueryModel<PerformanceItem> queryModel)
  108. {
  109. QueryFilter query = new QueryFilter();
  110. query.userId = 0;
  111. query.jxType = jxType.all;
  112. query.CalMonthId = calMonth.Id;
  113. if (queryModel != null)
  114. {
  115. query.PageIndex = queryModel.PageIndex;
  116. query.PageSize = queryModel.PageSize;
  117. query.ConditionTree = new List<FieldCondition>();
  118. foreach (var filter in queryModel.FilterModel)
  119. {
  120. foreach (var f in filter.Filters)
  121. {
  122. FieldCondition condition = new FieldCondition() { FieldName = filter.FieldName };
  123. condition.Value = f.Value.ToString();
  124. condition.ValueType = typeof(PerformanceItem).GetProperty(filter.FieldName).PropertyType.ToString();
  125. switch (f.FilterCompareOperator)
  126. {
  127. case AntDesign.TableFilterCompareOperator.Contains:
  128. condition.Operator = OperatorEnum.Contains;
  129. break;
  130. case AntDesign.TableFilterCompareOperator.EndsWith:
  131. condition.Operator = OperatorEnum.EndWith;
  132. break;
  133. case AntDesign.TableFilterCompareOperator.Equals:
  134. condition.Operator = OperatorEnum.EndWith;
  135. break;
  136. case AntDesign.TableFilterCompareOperator.GreaterThan:
  137. condition.Operator = OperatorEnum.Greater;
  138. break;
  139. case AntDesign.TableFilterCompareOperator.GreaterThanOrEquals:
  140. condition.Operator = OperatorEnum.GreaterEqual;
  141. break;
  142. case AntDesign.TableFilterCompareOperator.LessThan:
  143. condition.Operator = OperatorEnum.Less;
  144. break;
  145. case AntDesign.TableFilterCompareOperator.LessThanOrEquals:
  146. condition.Operator = OperatorEnum.LessEqual;
  147. break;
  148. case AntDesign.TableFilterCompareOperator.NotContains:
  149. condition.Operator = OperatorEnum.NotContains;
  150. break;
  151. case AntDesign.TableFilterCompareOperator.NotEquals:
  152. condition.Operator = OperatorEnum.NotEqual;
  153. break;
  154. case AntDesign.TableFilterCompareOperator.StartsWith:
  155. condition.Operator = OperatorEnum.StartsWith;
  156. break;
  157. }
  158. switch (f.FilterCondition)
  159. {
  160. case AntDesign.TableFilterCondition.And:
  161. condition.LogicOperate = LogicEnum.And;
  162. break;
  163. case AntDesign.TableFilterCondition.Or:
  164. condition.LogicOperate = LogicEnum.Or;
  165. break;
  166. default:
  167. condition.LogicOperate = LogicEnum.And;
  168. break;
  169. }
  170. query.ConditionTree.Add(condition);
  171. }
  172. }
  173. query.Sorts = new List<OrderField>();
  174. foreach (var sort in queryModel.SortModel)
  175. {
  176. if (!string.IsNullOrEmpty(sort.Sort))
  177. {
  178. query.Sorts.Add(new OrderField() { FieldName = sort.FieldName, Sort = (sort.Sort == "descend" ? 1 : 0) });
  179. }
  180. }
  181. }
  182. else
  183. {
  184. query.PageIndex = 1;
  185. query.PageSize = 1;
  186. query.ConditionTree = new List<FieldCondition>();
  187. query.Sorts = new List<OrderField>();
  188. }
  189. var data = await _httpClient.Post<ListApiResponse<PerformanceItem>>($"PerformanceItem/QueryFilter", query);
  190. //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(queryModel));
  191. return data;
  192. }
  193. public async Task<ListApiResponse<PerformanceItem>> Query(int calMonthId, int userid, jxType type, QueryModel<PerformanceItem> queryModel, int DoingOrReview = 0)
  194. {
  195. QueryFilter query = new QueryFilter();
  196. query.CalMonthId = calMonthId;
  197. query.userId = userid;
  198. query.jxType = type;
  199. query.DoingOrReview = DoingOrReview;
  200. if (queryModel != null)
  201. {
  202. query.PageIndex = queryModel.PageIndex;
  203. query.PageSize = queryModel.PageSize;
  204. query.ConditionTree = new List<FieldCondition>();
  205. foreach (var filter in queryModel.FilterModel)
  206. {
  207. foreach (var f in filter.Filters)
  208. {
  209. FieldCondition condition = new FieldCondition() { FieldName = filter.FieldName };
  210. condition.Value = f.Value.ToString();
  211. condition.ValueType = typeof(PerformanceItem).GetProperty(filter.FieldName).PropertyType.ToString();
  212. switch (f.FilterCompareOperator)
  213. {
  214. case AntDesign.TableFilterCompareOperator.Contains:
  215. condition.Operator = OperatorEnum.Contains;
  216. break;
  217. case AntDesign.TableFilterCompareOperator.EndsWith:
  218. condition.Operator = OperatorEnum.EndWith;
  219. break;
  220. case AntDesign.TableFilterCompareOperator.Equals:
  221. condition.Operator = OperatorEnum.EndWith;
  222. break;
  223. case AntDesign.TableFilterCompareOperator.GreaterThan:
  224. condition.Operator = OperatorEnum.Greater;
  225. break;
  226. case AntDesign.TableFilterCompareOperator.GreaterThanOrEquals:
  227. condition.Operator = OperatorEnum.GreaterEqual;
  228. break;
  229. case AntDesign.TableFilterCompareOperator.LessThan:
  230. condition.Operator = OperatorEnum.Less;
  231. break;
  232. case AntDesign.TableFilterCompareOperator.LessThanOrEquals:
  233. condition.Operator = OperatorEnum.LessEqual;
  234. break;
  235. case AntDesign.TableFilterCompareOperator.NotContains:
  236. condition.Operator = OperatorEnum.NotContains;
  237. break;
  238. case AntDesign.TableFilterCompareOperator.NotEquals:
  239. condition.Operator = OperatorEnum.NotEqual;
  240. break;
  241. case AntDesign.TableFilterCompareOperator.StartsWith:
  242. condition.Operator = OperatorEnum.StartsWith;
  243. break;
  244. }
  245. switch (f.FilterCondition)
  246. {
  247. case AntDesign.TableFilterCondition.And:
  248. condition.LogicOperate = LogicEnum.And;
  249. break;
  250. case AntDesign.TableFilterCondition.Or:
  251. condition.LogicOperate = LogicEnum.Or;
  252. break;
  253. default:
  254. condition.LogicOperate = LogicEnum.And;
  255. break;
  256. }
  257. query.ConditionTree.Add(condition);
  258. }
  259. }
  260. query.Sorts = new List<OrderField>();
  261. foreach (var sort in queryModel.SortModel)
  262. {
  263. if (!string.IsNullOrEmpty(sort.Sort))
  264. {
  265. query.Sorts.Add(new OrderField() { FieldName = sort.FieldName, Sort = (sort.Sort == "descend" ? 1 : 0) });
  266. }
  267. }
  268. }
  269. else
  270. {
  271. query.PageIndex = 1;
  272. query.PageSize = 1;
  273. query.ConditionTree = new List<FieldCondition>();
  274. query.Sorts = new List<OrderField>();
  275. }
  276. var data = await _httpClient.Post<ListApiResponse<PerformanceItem>>($"PerformanceItem/QueryFilter", query);
  277. //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(queryModel));
  278. return data;
  279. }
  280. public async Task<PerformanceItem> RefreshItem(int Id)
  281. {
  282. var data = await _httpClient.Get<ApiSaveResponse>($"PerformanceItem/RefreshFromIPEasyById?itemId={Id}");
  283. return await _httpClient.Get<PerformanceItem>($"PerformanceItem/PerformanceItem?Id={Id}");
  284. }
  285. public async Task<List<StaffStatistics>> CalMyStatistics(int year, int month, int? userid = null)
  286. {
  287. var data = await _httpClient.Get<List<StaffStatistics>>($"PerformanceItem/CalMyStatistics?userid={userid}&year={year}&month={month}");
  288. return data;
  289. }
  290. public async Task<List<StaffStatistics>> CalItemStatistics(int ItemId)
  291. {
  292. var data = await _httpClient.Get<List<StaffStatistics>>($"PerformanceItem/CalItemJX?itemid={ItemId}");
  293. return data;
  294. }
  295. #region 绩效等级计算
  296. public async Task StatisticsLevelCount(int year, int month)
  297. {
  298. await _httpClient.Get<bool>($"PerformanceItem/StatisticsLevelCount?year={year}&month={month}");
  299. }
  300. public async Task<LevelStatisticsResult> CalAgentLevel(int year, int quarter, string GradeCode)
  301. {
  302. var data = await _httpClient.Get<LevelStatisticsResult>($"PerformanceItem/CalAgentLevel?year={year}&quarter={quarter}&GradeCode={GradeCode}");
  303. return data;
  304. }
  305. public async Task<List<AllocationRatio>> getARatios(PerformanceItem item)
  306. {
  307. var data = await _httpClient.Get<List<AllocationRatio>>($"PerformanceItem/CalAllocationRatios?itemId={item.Id}");
  308. return data;
  309. }
  310. public async Task SaveAllocationRatios(List<AllocationRatio> allocationRatios)
  311. {
  312. await _httpClient.Post($"PerformanceItem/SaveAllocationRatios", allocationRatios);
  313. //throw new NotImplementedException();
  314. }
  315. #endregion
  316. }
  317. }