PerformanceItemServices.cs 15 KB

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