CustomerSuppliersApplicationService.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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.Extensions;
  10. using Abp.Runtime.Caching;
  11. using AutoMapper;
  12. using IwbZero.Auditing;
  13. using IwbZero.AppServiceBase;
  14. using IwbZero.IdentityFramework;
  15. using IwbZero.Setting;
  16. using VberTech.Authorization.Permissions;
  17. using VberTech.BaseSysInfo;
  18. using VberTech.Lambda;
  19. using VberTech.Customers.Dto;
  20. namespace VberTech.Customers
  21. {
  22. [AbpAuthorize]
  23. public class CustomerSupplierAppService : VberTechAsyncCrudAppService<CustomerSupplier, CustomerSupplierDto, int, PagedRequestDto, CustomerSupplierCreateDto, CustomerSupplierUpdateDto>, ICustomerSupplierAppService
  24. {
  25. public IRepository<CustomerSupplierType> CustomerSupplierTypeRepository { get; }
  26. public IRepository<CustomerSupplierAddress> CustomerSupplierAddressRepository { get; }
  27. public IRepository<CustomerSupplierPerson> CustomerSupplierPersonRepository { get; }
  28. public IRepository<CustomerDefaultProduct> CustomerDefaultProductRepository { get; }
  29. public CustomerSupplierAppService(
  30. IIwbSettingManager settingManager,
  31. ICacheManager cacheManager,
  32. IRepository<CustomerSupplier, int> repository, IRepository<CustomerSupplierType> customerSupplierTypeRepository, IRepository<CustomerSupplierAddress> customerSupplierAddressRepository, IRepository<CustomerDefaultProduct> customerDefaultProductRepository, IRepository<CustomerSupplierPerson> customerSupplierPersonRepository) : base(repository, "CustomerSupplierNo")
  33. {
  34. CustomerSupplierTypeRepository = customerSupplierTypeRepository;
  35. CustomerSupplierAddressRepository = customerSupplierAddressRepository;
  36. CustomerDefaultProductRepository = customerDefaultProductRepository;
  37. CustomerSupplierPersonRepository = customerSupplierPersonRepository;
  38. SettingManager = settingManager;
  39. CacheManager = cacheManager;
  40. }
  41. protected override bool KeyIsAuto { get; set; } = false;
  42. #region GetSelect
  43. [DisableAuditing]
  44. public async Task<string> GetTypeSelectStr()
  45. {
  46. var list = await CustomerSupplierTypeRepository.GetAllListAsync(a => a.ParentNo != "root");
  47. string str = "<option value=\"0\" disabled selected>请选择...</option>";
  48. foreach (var l in list)
  49. {
  50. str += $"<option value=\"{l.TypeNo}\" parent=\"{l.ParentNo}\" data-id=\"{l.Id}\">{l.TypeName}</option>";
  51. }
  52. return str;
  53. }
  54. [DisableAuditing]
  55. public async Task<List<SelectListItem>> GetSelectList()
  56. {
  57. var list = await Repository.GetAllListAsync();
  58. var slist = new List<SelectListItem> {new SelectListItem {Text = @"请选择...", Value = "", Selected = true}};
  59. foreach (var l in list)
  60. {
  61. //slist.Add(new SelectListItem { Text = l., Value = l. });
  62. }
  63. return slist;
  64. }
  65. [DisableAuditing]
  66. public async Task<string> GetSelectStr()
  67. {
  68. var list = await Repository.GetAllListAsync();
  69. string str = "<option value=\"\" selected>请选择...</option>";
  70. foreach (var l in list)
  71. {
  72. //str += $"<option value=\"{l.}\">{l.}</option>";
  73. }
  74. return str;
  75. }
  76. [DisableAuditing]
  77. public async Task<List<TreeDto>> GetTypeTree()
  78. {
  79. var list = (await CustomerSupplierTypeRepository.GetAllListAsync(a => a.ParentNo != "root"));
  80. return GetChildTypes(list, "0");
  81. }
  82. private List<TreeDto> GetChildTypes(List<CustomerSupplierType> list, string parentNo)
  83. {
  84. var dtoList = new List<TreeDto>();
  85. var parents = list.Where(a => a.ParentNo == parentNo).ToList();
  86. if (!parents.Any())
  87. {
  88. return null;
  89. }
  90. foreach (var item in parents)
  91. {
  92. var dto = new TreeDto
  93. {
  94. Id = item.Id + "",
  95. Text = item.TypeName,
  96. Nodes = GetChildTypes(list, item.TypeNo)
  97. };
  98. dtoList.Add(dto);
  99. }
  100. return dtoList;
  101. }
  102. #endregion
  103. #region CURD
  104. [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierMgCreate)]
  105. public override async Task<CustomerSupplierDto> Create(CustomerSupplierCreateDto input)
  106. {
  107. return await CreateEntity(input);
  108. }
  109. [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierMgUpdate)]
  110. public override async Task<CustomerSupplierDto> Update(CustomerSupplierUpdateDto input)
  111. {
  112. return await UpdateEntity(input);
  113. }
  114. [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierMgDelete)]
  115. public override Task Delete(EntityDto<int> input)
  116. {
  117. return Repository.DeleteAsync(input.Id);
  118. }
  119. [DisableAuditing]
  120. [AbpAuthorize(PermissionNames.PagesCustomerSupplier)]
  121. public override async Task<PagedResultDto<CustomerSupplierDto>> GetAll(PagedRequestDto input)
  122. {
  123. var query = CreateFilteredQuery(input);
  124. query = ApplyFilter(query, input);
  125. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  126. query = ApplySorting(query, input);
  127. query = ApplyPaging(query, input);
  128. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  129. var dtoList = new PagedResultDto<CustomerSupplierDto>(totalCount, entities.Select(MapToEntityDto).ToList());
  130. return dtoList;
  131. }
  132. #region Get
  133. [DisableAuditing]
  134. [AbpAuthorize(PermissionNames.PagesCustomerSupplier)]
  135. public override Task<CustomerSupplier> GetEntityById(int id)
  136. {
  137. return Repository.FirstOrDefaultAsync(id);
  138. }
  139. [DisableAuditing]
  140. [AbpAuthorize(PermissionNames.PagesCustomerSupplier)]
  141. public override Task<CustomerSupplier> GetEntityByNo(string no)
  142. {
  143. if (KeyFiledName.IsNullOrEmpty())
  144. {
  145. CheckErrors(IwbIdentityResult.Failed("编码/编号字段不明确,请检查后再操作!"));
  146. }
  147. LambdaObject obj = new LambdaObject()
  148. {
  149. FieldType = LambdaFieldType.S,
  150. FieldName = KeyFiledName,
  151. FieldValue = no,
  152. ExpType = LambdaExpType.Equal
  153. };
  154. var exp = obj.GetExp<CustomerSupplier>();
  155. return Repository.FirstOrDefaultAsync(exp);
  156. }
  157. [DisableAuditing]
  158. [AbpAuthorize(PermissionNames.PagesCustomerSupplier)]
  159. public override async Task<CustomerSupplierDto> GetDtoById(int id)
  160. {
  161. var entity = await GetEntityById(id);
  162. return MapToEntityDto(entity);
  163. }
  164. [DisableAuditing]
  165. [AbpAuthorize(PermissionNames.PagesCustomerSupplier)]
  166. public override async Task<CustomerSupplierDto> GetDtoByNo(string no)
  167. {
  168. var entity = await GetEntityByNo(no);
  169. return MapToEntityDto(entity);
  170. }
  171. #endregion
  172. #region Hide
  173. //protected override IQueryable<CustomerSupplier> ApplyFilter(IQueryable<CustomerSupplier> query, TGetAllInput input)
  174. //{
  175. // if (!input.KeyWords.IsNullOrEmpty())
  176. // {
  177. // object keyWords = input.KeyWords;
  178. // LambdaObject obj = new LambdaObject()
  179. // {
  180. // FieldType = (LambdaFieldType)input.FieldType,
  181. // FieldName = input.KeyField,
  182. // FieldValue = keyWords,
  183. // ExpType = (LambdaExpType)input.ExpType
  184. // };
  185. // var exp = obj.GetExp<CustomerSupplier>();
  186. // query = query.Where(exp);
  187. // }
  188. // if (input.SearchList != null && input.SearchList.Count > 0)
  189. // {
  190. // List<LambdaObject> objList = new List<LambdaObject>();
  191. // foreach (var o in input.SearchList)
  192. // {
  193. // if (o.KeyWords.IsNullOrEmpty())
  194. // continue;
  195. // object keyWords = o.KeyWords;
  196. // objList.Add(new LambdaObject
  197. // {
  198. // FieldType = (LambdaFieldType)o.FieldType,
  199. // FieldName = o.KeyField,
  200. // FieldValue = keyWords,
  201. // ExpType = (LambdaExpType)o.ExpType
  202. // });
  203. // }
  204. // var exp = objList.GetExp<CustomerSupplier>();
  205. // query = query.Where(exp);
  206. // }
  207. // return query;
  208. //}
  209. //protected override IQueryable<CustomerSupplier> ApplySorting(IQueryable<CustomerSupplier> query, PagedRequestDto input)
  210. //{
  211. // return query.OrderBy(a => a.No);
  212. //}
  213. //protected override IQueryable<CustomerSupplier> ApplyPaging(IQueryable<CustomerSupplier> query, PagedRequestDto input)
  214. //{
  215. // if (input is IPagedResultRequest pagedInput)
  216. // {
  217. // return query.Skip(pagedInput.SkipCount).Take(pagedInput.MaxResultCount);
  218. // }
  219. // return query;
  220. //}
  221. #endregion
  222. #endregion
  223. #region Address
  224. [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierAddressMg)]
  225. public async Task<List<CustomerSupplierAddressDto>> GetAllAddress(PagedRequestDto input)
  226. {
  227. var query = CustomerSupplierAddressRepository.GetAll();
  228. query = ApplyFilterEx<CustomerSupplierAddress>(query, input);
  229. query = ApplySortingEx<CustomerSupplierAddress>(query, input);
  230. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  231. var dtoList = ObjectMapper.Map<List<CustomerSupplierAddressDto>>(entities);
  232. return dtoList;
  233. }
  234. [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierAddressMgCreateAddress)]
  235. public async Task<CustomerSupplierAddress> CreateAddress(CustomerSupplierAddressCreateDto input)
  236. {
  237. CustomerSupplierAddress entity = ObjectMapper.Map<CustomerSupplierAddress>(input);
  238. return await CustomerSupplierAddressRepository.InsertAsync(entity);
  239. }
  240. [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierAddressMgUpdateAddress)]
  241. public async Task<CustomerSupplierAddress> UpdateAddress(CustomerSupplierAddressUpdateDto input)
  242. {
  243. CustomerSupplierAddress entity = ObjectMapper.Map<CustomerSupplierAddress>(input);
  244. return await CustomerSupplierAddressRepository.UpdateAsync(entity);
  245. }
  246. [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierAddressMgDeleteAddress)]
  247. public Task DeleteAddress(EntityDto<int> input)
  248. {
  249. return CustomerSupplierAddressRepository.DeleteAsync(input.Id);
  250. }
  251. #endregion
  252. #region Person
  253. [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierPersonMg)]
  254. public async Task<List<CustomerSupplierPersonDto>> GetAllPerson(PagedRequestDto input)
  255. {
  256. var query = CustomerSupplierPersonRepository.GetAll();
  257. query = ApplyFilterEx(query, input);
  258. query = ApplySortingEx(query, input);
  259. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  260. var dtoList = ObjectMapper.Map<List<CustomerSupplierPersonDto>>(entities);
  261. return dtoList;
  262. }
  263. [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierPersonMgCreatePerson)]
  264. public async Task<CustomerSupplierPerson> CreatePerson(CustomerSupplierPersonCreateDto input)
  265. {
  266. CustomerSupplierPerson entity = ObjectMapper.Map<CustomerSupplierPerson>(input);
  267. return await CustomerSupplierPersonRepository.InsertAsync(entity);
  268. }
  269. [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierPersonMgUpdatePerson)]
  270. public async Task<CustomerSupplierPerson> UpdatePerson(CustomerSupplierPersonUpdateDto input)
  271. {
  272. CustomerSupplierPerson entity = ObjectMapper.Map<CustomerSupplierPerson>(input);
  273. return await CustomerSupplierPersonRepository.UpdateAsync(entity);
  274. }
  275. [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierPersonMgDeletePerson)]
  276. public Task DeletePerson(EntityDto<int> input)
  277. {
  278. return CustomerSupplierPersonRepository.DeleteAsync(input.Id);
  279. }
  280. #endregion
  281. #region DefaultPerson
  282. [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerDefaultProductMg)]
  283. public async Task<List<CustomerDefaultProductDto>> GetAllProduct(PagedRequestDto input)
  284. {
  285. var query = CustomerDefaultProductRepository.GetAll();
  286. query = ApplyFilterEx(query, input);
  287. query = ApplySortingEx(query, input);
  288. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  289. var dtoList = ObjectMapper.Map<List<CustomerDefaultProductDto>>(entities);
  290. return dtoList;
  291. }
  292. [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerDefaultProductMgCreateProduct)]
  293. public async Task<CustomerDefaultProduct> CreateProduct(CustomerDefaultProductCreateDto input)
  294. {
  295. CustomerDefaultProduct entity = ObjectMapper.Map<CustomerDefaultProduct>(input);
  296. return await CustomerDefaultProductRepository.InsertAsync(entity);
  297. }
  298. [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerDefaultProductMgUpdateProduct)]
  299. public async Task<CustomerDefaultProduct> UpdateProduct(CustomerDefaultProductUpdateDto input)
  300. {
  301. CustomerDefaultProduct entity = ObjectMapper.Map<CustomerDefaultProduct>(input);
  302. return await CustomerDefaultProductRepository.UpdateAsync(entity);
  303. }
  304. [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerDefaultProductMgDeleteProduct)]
  305. public Task DeleteProduct(EntityDto<int> input)
  306. {
  307. return CustomerDefaultProductRepository.DeleteAsync(input.Id);
  308. }
  309. #endregion
  310. }
  311. }