PerformanceItemServices.cs 15 KB

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