ClientCompanyApplicationService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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.Company.Dto;
  14. using ContractService.Configuration;
  15. using ContractService.LegalContract;
  16. using IwbZero.Runtime.Session;
  17. using IwbZero.ToolCommon.StringModel;
  18. namespace ContractService.Client.Company
  19. {
  20. [AbpAuthorize, AuditLog("公司信息维护")]
  21. public class ClientCompanyAppService : IwbAsyncCrudAppService<ClientCompanyInfo, ClientCompanyDto, string, IwbPagedRequestDto, ClientCompanyCreateDto, ClientCompanyUpdateDto >, IClientCompanyAppService
  22. {
  23. public ClientCompanyAppService(
  24. ICacheManager cacheManager,
  25. IRepository<ClientCompanyInfo, 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.PagesClientMgCompanyMgCreate)]
  58. public override async Task Create(ClientCompanyCreateDto input)
  59. {
  60. ClientStaffInfo staff = input.StaffName.NotEmpty()
  61. ? new ClientStaffInfo()
  62. {
  63. Code = input.Code,
  64. Name = input.StaffName,
  65. Email = input.Email,
  66. Birthday = input.Birthday,
  67. Profile = input.Profile,
  68. PhoneNumber = input.PhoneNumber,
  69. PhoneNumber2 = input.PhoneNumber2,
  70. IdCard = input.IdCard
  71. }
  72. : null;
  73. var entity = MapToEntity(input);
  74. await LegalManager.CreateCompany(entity, staff);
  75. }
  76. [AbpAuthorize(PermissionNames.PagesClientMgCompanyMgUpdate)]
  77. public override async Task Update(ClientCompanyUpdateDto input)
  78. {
  79. var entity = await GetEntityById(input.Id);
  80. if (entity == null)
  81. {
  82. CheckErrors(NotExistMessage);
  83. }
  84. MapToEntity(input, entity);
  85. await LegalManager.UpdateCompany(entity);
  86. }
  87. [AbpAuthorize(PermissionNames.PagesClientMgCompanyMgDelete)]
  88. public override Task Delete(EntityDto<string> input)
  89. {
  90. return LegalManager.DeleteCompany(input.Id);
  91. }
  92. [DisableAuditing]
  93. [AbpAuthorize(PermissionNames.PagesClientMgCompanyMgQuery)]
  94. public override async Task<PagedResultDto<ClientCompanyDto>> GetAll(IwbPagedRequestDto input)
  95. {
  96. var query = CreateFilteredQuery(input);
  97. query = ApplyFilter(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<ClientCompanyDto>(totalCount, entities.Select(MapToEntityDto).ToList());
  103. return dtoList;
  104. }
  105. protected override ClientCompanyDto MapToEntityDto(ClientCompanyInfo entity)
  106. {
  107. var dto = base.MapToEntityDto(entity);
  108. var staff = LegalManager.QueryMasterStaffByCompany(dto.Id).FirstOrDefault();
  109. dto.MasterStaffNo= staff?.Id;
  110. dto.MasterStaffCode = staff?.Code;
  111. dto.MasterStaffName = staff?.Name;
  112. return dto;
  113. }
  114. protected override IQueryable<ClientCompanyInfo> SelfSorting(IQueryable<ClientCompanyInfo> query, IwbPagedRequestDto input)
  115. {
  116. return query.OrderByDescending(r => r.Id);
  117. }
  118. protected override IQueryable<ClientCompanyInfo> KeyWordFilter(IQueryable<ClientCompanyInfo> query, string keyword)
  119. {
  120. return query.Where(a => a.Id.Contains(keyword));
  121. }
  122. #region GetEntity/Dto
  123. /// <summary>
  124. /// 查询实体Dto
  125. /// </summary>
  126. /// <param name="input"></param>
  127. /// <returns></returns>
  128. [DisableAuditing]
  129. [AbpAuthorize(PermissionNames.PagesClientMgCompanyMgQuery)]
  130. public override async Task<ClientCompanyDto> GetDto(EntityDto<string> input)
  131. {
  132. var entity = await GetEntity(input);
  133. return MapToEntityDto(entity);
  134. }
  135. /// <summary>
  136. /// 查询实体Dto
  137. /// </summary>
  138. /// <param name="id"></param>
  139. /// <returns></returns>
  140. [DisableAuditing]
  141. [AbpAuthorize(PermissionNames.PagesClientMgCompanyMgQuery)]
  142. public override async Task<ClientCompanyDto> GetDtoById(string id)
  143. {
  144. var entity = await GetEntityById(id);
  145. return MapToEntityDto(entity);
  146. }
  147. /// <summary>
  148. /// 查询实体Dto(需指明自定义字段)
  149. /// </summary>
  150. /// <param name="no"></param>
  151. /// <returns></returns>
  152. [DisableAuditing]
  153. [AbpAuthorize(PermissionNames.PagesClientMgCompanyMgQuery)]
  154. public override async Task<ClientCompanyDto> GetDtoByNo(string no)
  155. {
  156. var entity = await GetEntityByNo(no);
  157. return MapToEntityDto(entity);
  158. }
  159. /// <summary>
  160. /// 查询实体
  161. /// </summary>
  162. /// <param name="input"></param>
  163. /// <returns></returns>
  164. [DisableAuditing]
  165. [AbpAuthorize(PermissionNames.PagesClientMgCompanyMgQuery)]
  166. public override async Task<ClientCompanyInfo> GetEntity(EntityDto<string> input)
  167. {
  168. var entity = await GetEntityById(input.Id);
  169. return entity;
  170. }
  171. /// <summary>
  172. /// 查询实体
  173. /// </summary>
  174. /// <param name="id"></param>
  175. /// <returns></returns>
  176. [DisableAuditing]
  177. [AbpAuthorize(PermissionNames.PagesClientMgCompanyMgQuery)]
  178. public override async Task<ClientCompanyInfo> GetEntityById(string id)
  179. {
  180. return await Repository.FirstOrDefaultAsync(a=>a.Id==id);
  181. }
  182. /// <summary>
  183. /// 查询实体(需指明自定义字段)
  184. /// </summary>
  185. /// <param name="no"></param>
  186. /// <returns></returns>
  187. [DisableAuditing]
  188. [AbpAuthorize(PermissionNames.PagesClientMgCompanyMgQuery)]
  189. public override async Task<ClientCompanyInfo> GetEntityByNo(string no)
  190. {
  191. //CheckGetPermission();
  192. if (string.IsNullOrEmpty(KeyFiledName))
  193. {
  194. ThrowError("NoKeyFieldName");
  195. }
  196. return await base.GetEntityByNo(no);
  197. }
  198. #endregion
  199. #region Hide
  200. ///// <summary>
  201. ///// 根据给定的<see cref="IwbPagedRequestDto"/>创建 <see cref="IQueryable{ClientCompanyInfo}"/>过滤查询.
  202. ///// </summary>
  203. ///// <param name="input">The input.</param>
  204. //protected override IQueryable<ClientCompanyInfo> CreateFilteredQuery(IwbPagedRequestDto input)
  205. //{
  206. // var query = Repository.GetAll();
  207. // var pagedInput = input as IIwbPagedRequest;
  208. // if (pagedInput == null)
  209. // {
  210. // return query;
  211. // }
  212. // if (!string.IsNullOrEmpty(pagedInput.KeyWords))
  213. // {
  214. // object keyWords = pagedInput.KeyWords;
  215. // LambdaObject obj = new LambdaObject()
  216. // {
  217. // FieldType = (LambdaFieldType)pagedInput.FieldType,
  218. // FieldName = pagedInput.KeyField,
  219. // FieldValue = keyWords,
  220. // ExpType = (LambdaExpType)pagedInput.ExpType
  221. // };
  222. // var exp = obj.GetExp<ClientCompanyInfo>();
  223. // query = exp != null ? query.Where(exp) : query;
  224. // }
  225. // if (pagedInput.SearchList != null && pagedInput.SearchList.Count > 0)
  226. // {
  227. // List<LambdaObject> objList = new List<LambdaObject>();
  228. // foreach (var o in pagedInput.SearchList)
  229. // {
  230. // if (string.IsNullOrEmpty(o.KeyWords))
  231. // continue;
  232. // object keyWords = o.KeyWords;
  233. // objList.Add(new LambdaObject
  234. // {
  235. // FieldType = (LambdaFieldType)o.FieldType,
  236. // FieldName = o.KeyField,
  237. // FieldValue = keyWords,
  238. // ExpType = (LambdaExpType)o.ExpType
  239. // });
  240. // }
  241. // var exp = objList.GetExp<ClientCompanyInfo>();
  242. // query = exp != null ? query.Where(exp) : query;
  243. // }
  244. // return query;
  245. //}
  246. //protected override IQueryable<ClientCompanyInfo> ApplySorting(IQueryable<ClientCompanyInfo> query, IwbPagedRequestDto input)
  247. //{
  248. // return query.OrderBy(a => a.No);
  249. //}
  250. //protected override IQueryable<ClientCompanyInfo> ApplyPaging(IQueryable<ClientCompanyInfo> query, IwbPagedRequestDto input)
  251. //{
  252. // if (input is IPagedResultRequest pagedInput)
  253. // {
  254. // return query.Skip(pagedInput.SkipCount).Take(pagedInput.MaxResultCount);
  255. // }
  256. // return query;
  257. //}
  258. #endregion
  259. #endregion
  260. /// <summary>
  261. /// 变更企业负责人
  262. /// </summary>
  263. /// <param name="input"></param>
  264. /// <returns></returns>
  265. [AbpAuthorize(PermissionNames.PagesClientMgCompanyMgMasterStaff), AuditLog("变更负责人")]
  266. public async Task MasterStaff(MasterDto input)
  267. {
  268. var companyNo = input.No ?? AbpSession.GetClaimValue(IwbConsts.UserCompanyLawFirmClaimType);
  269. await LegalManager.SetCompanyMasterStaff(companyNo, input.StaffNo);
  270. }
  271. }
  272. }