ClientStaffApplicationService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using System.Web.Mvc;
  5. using Abp.Application.Services.Dto;
  6. using Abp.Auditing;
  7. using Abp.Authorization;
  8. using Abp.Domain.Repositories;
  9. using Abp.Runtime.Caching;
  10. using IwbZero.Auditing;
  11. using IwbZero.AppServiceBase;
  12. using ContractService.Authorization;
  13. using ContractService.Client.Staff.Dto;
  14. using ContractService.Configuration;
  15. using ContractService.LegalContract;
  16. using IwbZero.Runtime.Session;
  17. using IwbZero.ToolCommon.StringModel;
  18. namespace ContractService.Client.Staff
  19. {
  20. [AbpAuthorize, AuditLog("企业员工信息维护")]
  21. public class ClientStaffAppService : IwbAsyncCrudAppService<ClientStaffInfo, ClientStaffDto, string, IwbPagedRequestDto, ClientStaffCreateDto, ClientStaffUpdateDto >, IClientStaffAppService
  22. {
  23. public ClientStaffAppService(
  24. ICacheManager cacheManager,
  25. IRepository<ClientStaffInfo, string> repository, LegalManager legalManager) : base(repository, "Id")
  26. {
  27. LegalManager = legalManager;
  28. CacheManager = cacheManager;
  29. }
  30. protected override bool KeyIsAuto { get; set; } = false;
  31. public LegalManager LegalManager { get; }
  32. #region GetSelect
  33. [DisableAuditing]
  34. public override async Task<List<SelectListItem>> GetSelectList()
  35. {
  36. var list = await Repository.GetAllListAsync();
  37. var sList = new List<SelectListItem> {new SelectListItem {Text = @"请选择...", Value = "", Selected = true}};
  38. foreach (var l in list)
  39. {
  40. sList.Add(new SelectListItem { Value = l.Id, Text = l.Name });
  41. }
  42. return sList;
  43. }
  44. [DisableAuditing]
  45. public override async Task<string> GetSelectStr()
  46. {
  47. var list = await Repository.GetAllListAsync();
  48. string str = "<option value=\"\" selected>请选择...</option>";
  49. foreach (var l in list)
  50. {
  51. str += $"<option value=\"{l.Id}\">{l.Name}</option>";
  52. }
  53. return str;
  54. }
  55. #endregion
  56. #region CURD
  57. [AbpAuthorize(PermissionNames.PagesClientMgStaffMgCreate)]
  58. public override async Task Create(ClientStaffCreateDto input)
  59. {
  60. var entity = MapToEntity(input);
  61. entity.CompanyNo = input.CompanyNo.Empty() ? AbpSession.GetClaimValue(IwbConsts.UserCompanyLawFirmClaimType) : input.CompanyNo;
  62. await LegalManager.CreateStaff(entity);
  63. }
  64. [AbpAuthorize(PermissionNames.PagesClientMgStaffMgUpdate)]
  65. public override async Task Update(ClientStaffUpdateDto input)
  66. {
  67. var entity = await GetEntityById(input.Id);
  68. if (entity == null)
  69. {
  70. CheckErrors(NotExistMessage);
  71. }
  72. MapToEntity(input, entity);
  73. await LegalManager.UpdateStaff(entity);
  74. }
  75. [AbpAuthorize(PermissionNames.PagesClientMgStaffMgDelete)]
  76. public override Task Delete(EntityDto<string> input)
  77. {
  78. return LegalManager.DeleteStaff(input.Id);
  79. }
  80. [DisableAuditing]
  81. [AbpAuthorize(PermissionNames.PagesClientMgStaffMgQuery)]
  82. public override async Task<PagedResultDto<ClientStaffDto>> GetAll(IwbPagedRequestDto input)
  83. {
  84. LegalManager.CheckAccount(AccountTypeDefinition.System, AccountTypeDefinition.Client);
  85. var query = LegalManager.QueryAllStaff();
  86. if (input.SearchList.Any(a => a.KeyField.ToLower() == "company"))
  87. {
  88. var search = input.SearchList.FirstOrDefault(a => a.KeyField.ToLower() == "company");
  89. var no = search?.KeyWords;
  90. if (search != null) input.SearchList.Remove(search);
  91. query = LegalManager.QueryCompanyAllStaffs(no);
  92. }
  93. if (!string.IsNullOrEmpty(input.KeyWords))
  94. {
  95. query = input.KeyField.ToLower() == "keyword" ? KeyWordFilter(query, input.KeyWords) : KeyWordFilter(query, input);
  96. }
  97. query = SearchListFilter(query, input);
  98. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  99. query = _ApplySorting(query, input);
  100. query = _ApplyPaging(query, input);
  101. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  102. var dtoList = new PagedResultDto<ClientStaffDto>(totalCount, entities.Select(a=>new ClientStaffDto(a) ).ToList());
  103. return dtoList;
  104. }
  105. //protected ClientStaffDto MapToEntityDto(ClientStaffInfoClone entity)
  106. //{
  107. // var dto = new ClientStaffDto();
  108. // dto.CompanyName = entity.CompanyInfo?.Name;
  109. // dto.OrganizationName = entity.OrganizationInfo?.Name;
  110. // return dto;
  111. //}
  112. protected override IQueryable<ClientStaffInfo> SelfSorting(IQueryable<ClientStaffInfo> query, IwbPagedRequestDto input)
  113. {
  114. return query.OrderByDescending(r => r.Id);
  115. }
  116. protected override IQueryable<ClientStaffInfo> KeyWordFilter(IQueryable<ClientStaffInfo> query, string keyword)
  117. {
  118. return query.Where(a =>
  119. a.Name.Contains(keyword) || a.UserName.Contains(keyword) ||
  120. (a.CompanyInfo != null && (a.CompanyInfo.Name.Contains(keyword)|| a.CompanyInfo.DisplayName.Contains(keyword))) ||
  121. (a.OrganizationInfo != null && a.OrganizationInfo.Name.Contains(keyword)));
  122. }
  123. protected IQueryable<ClientStaffInfoClone> KeyWordFilter(IQueryable<ClientStaffInfoClone> query, string keyword)
  124. {
  125. return query.Where(a =>
  126. a.Name.Contains(keyword) || a.PhoneNumber.Contains(keyword) || a.UserName.Contains(keyword) ||
  127. (a.CompanyInfo != null && (a.CompanyInfo.Name.Contains(keyword)|| a.CompanyInfo.DisplayName.Contains(keyword))) ||
  128. (a.OrganizationInfo != null && a.OrganizationInfo.Name.Contains(keyword)));
  129. }
  130. #region GetEntity/Dto
  131. /// <summary>
  132. /// 查询实体Dto
  133. /// </summary>
  134. /// <param name="input"></param>
  135. /// <returns></returns>
  136. [DisableAuditing]
  137. [AbpAuthorize(PermissionNames.PagesClientMgStaffMgQuery)]
  138. public override async Task<ClientStaffDto> GetDto(EntityDto<string> input)
  139. {
  140. var entity = await GetEntity(input);
  141. return MapToEntityDto(entity);
  142. }
  143. /// <summary>
  144. /// 查询实体Dto
  145. /// </summary>
  146. /// <param name="id"></param>
  147. /// <returns></returns>
  148. [DisableAuditing]
  149. [AbpAuthorize(PermissionNames.PagesClientMgStaffMgQuery)]
  150. public override async Task<ClientStaffDto> GetDtoById(string id)
  151. {
  152. var entity = await GetEntityById(id);
  153. return MapToEntityDto(entity);
  154. }
  155. /// <summary>
  156. /// 查询实体Dto(需指明自定义字段)
  157. /// </summary>
  158. /// <param name="no"></param>
  159. /// <returns></returns>
  160. [DisableAuditing]
  161. [AbpAuthorize(PermissionNames.PagesClientMgStaffMgQuery)]
  162. public override async Task<ClientStaffDto> GetDtoByNo(string no)
  163. {
  164. var entity = await GetEntityByNo(no);
  165. return MapToEntityDto(entity);
  166. }
  167. /// <summary>
  168. /// 查询实体
  169. /// </summary>
  170. /// <param name="input"></param>
  171. /// <returns></returns>
  172. [DisableAuditing]
  173. [AbpAuthorize(PermissionNames.PagesClientMgStaffMgQuery)]
  174. public override async Task<ClientStaffInfo> GetEntity(EntityDto<string> input)
  175. {
  176. var entity = await GetEntityById(input.Id);
  177. return entity;
  178. }
  179. /// <summary>
  180. /// 查询实体
  181. /// </summary>
  182. /// <param name="id"></param>
  183. /// <returns></returns>
  184. [DisableAuditing]
  185. [AbpAuthorize(PermissionNames.PagesClientMgStaffMgQuery)]
  186. public override async Task<ClientStaffInfo> GetEntityById(string id)
  187. {
  188. return await Repository.FirstOrDefaultAsync(a=>a.Id==id);
  189. }
  190. /// <summary>
  191. /// 查询实体(需指明自定义字段)
  192. /// </summary>
  193. /// <param name="no"></param>
  194. /// <returns></returns>
  195. [DisableAuditing]
  196. [AbpAuthorize(PermissionNames.PagesClientMgStaffMgQuery)]
  197. public override async Task<ClientStaffInfo> GetEntityByNo(string no)
  198. {
  199. //CheckGetPermission();
  200. if (string.IsNullOrEmpty(KeyFiledName))
  201. {
  202. ThrowError("NoKeyFieldName");
  203. }
  204. return await base.GetEntityByNo(no);
  205. }
  206. #endregion
  207. #region Hide
  208. ///// <summary>
  209. ///// 根据给定的<see cref="IwbPagedRequestDto"/>创建 <see cref="IQueryable{ClientStaffInfo}"/>过滤查询.
  210. ///// </summary>
  211. ///// <param name="input">The input.</param>
  212. //protected override IQueryable<ClientStaffInfo> CreateFilteredQuery(IwbPagedRequestDto input)
  213. //{
  214. // var query = Repository.GetAll();
  215. // var pagedInput = input as IIwbPagedRequest;
  216. // if (pagedInput == null)
  217. // {
  218. // return query;
  219. // }
  220. // if (!string.IsNullOrEmpty(pagedInput.KeyWords))
  221. // {
  222. // object keyWords = pagedInput.KeyWords;
  223. // LambdaObject obj = new LambdaObject()
  224. // {
  225. // FieldType = (LambdaFieldType)pagedInput.FieldType,
  226. // FieldName = pagedInput.KeyField,
  227. // FieldValue = keyWords,
  228. // ExpType = (LambdaExpType)pagedInput.ExpType
  229. // };
  230. // var exp = obj.GetExp<ClientStaffInfo>();
  231. // query = exp != null ? query.Where(exp) : query;
  232. // }
  233. // if (pagedInput.SearchList != null && pagedInput.SearchList.Count > 0)
  234. // {
  235. // List<LambdaObject> objList = new List<LambdaObject>();
  236. // foreach (var o in pagedInput.SearchList)
  237. // {
  238. // if (string.IsNullOrEmpty(o.KeyWords))
  239. // continue;
  240. // object keyWords = o.KeyWords;
  241. // objList.Add(new LambdaObject
  242. // {
  243. // FieldType = (LambdaFieldType)o.FieldType,
  244. // FieldName = o.KeyField,
  245. // FieldValue = keyWords,
  246. // ExpType = (LambdaExpType)o.ExpType
  247. // });
  248. // }
  249. // var exp = objList.GetExp<ClientStaffInfo>();
  250. // query = exp != null ? query.Where(exp) : query;
  251. // }
  252. // return query;
  253. //}
  254. //protected override IQueryable<ClientStaffInfo> ApplySorting(IQueryable<ClientStaffInfo> query, IwbPagedRequestDto input)
  255. //{
  256. // return query.OrderBy(a => a.No);
  257. //}
  258. //protected override IQueryable<ClientStaffInfo> ApplyPaging(IQueryable<ClientStaffInfo> query, IwbPagedRequestDto input)
  259. //{
  260. // if (input is IPagedResultRequest pagedInput)
  261. // {
  262. // return query.Skip(pagedInput.SkipCount).Take(pagedInput.MaxResultCount);
  263. // }
  264. // return query;
  265. //}
  266. #endregion
  267. #endregion
  268. /// <summary>
  269. /// 绑定账号
  270. /// </summary>
  271. /// <param name="input"></param>
  272. /// <returns></returns>
  273. [AbpAuthorize(PermissionNames.PagesClientMgStaffMgBind), AuditLog("绑定账号")]
  274. public async Task Bind(BindDto input)
  275. {
  276. await LegalManager.BindStaffAccount(input.StaffNo, input.UserName);
  277. }
  278. /// <summary>
  279. /// 解绑账号
  280. /// </summary>
  281. /// <param name="input"></param>
  282. /// <returns></returns>
  283. [AbpAuthorize(PermissionNames.PagesClientMgStaffMgUnBind), AuditLog("解绑账号")]
  284. public async Task UnBind(EntityDto<string> input)
  285. {
  286. await LegalManager.UnBindStaffAccount(input.Id);
  287. }
  288. }
  289. }