| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Web.Mvc;
- using Abp.Application.Services.Dto;
- using Abp.Auditing;
- using Abp.Authorization;
- using Abp.Domain.Repositories;
- using Abp.Extensions;
- using Abp.Runtime.Caching;
- using AutoMapper;
- using IwbZero.Auditing;
- using IwbZero.AppServiceBase;
- using IwbZero.IdentityFramework;
- using IwbZero.Setting;
- using VberTech.Authorization.Permissions;
- using VberTech.BaseSysInfo;
- using VberTech.Lambda;
- using VberTech.Customers.Dto;
- namespace VberTech.Customers
- {
- [AbpAuthorize]
- public class CustomerSupplierAppService : VberTechAsyncCrudAppService<CustomerSupplier, CustomerSupplierDto, int, PagedRequestDto, CustomerSupplierCreateDto, CustomerSupplierUpdateDto>, ICustomerSupplierAppService
- {
- public IRepository<CustomerSupplierType> CustomerSupplierTypeRepository { get; }
- public IRepository<CustomerSupplierAddress> CustomerSupplierAddressRepository { get; }
- public IRepository<CustomerSupplierPerson> CustomerSupplierPersonRepository { get; }
- public IRepository<CustomerDefaultProduct> CustomerDefaultProductRepository { get; }
- public CustomerSupplierAppService(
- IIwbSettingManager settingManager,
- ICacheManager cacheManager,
- IRepository<CustomerSupplier, int> repository, IRepository<CustomerSupplierType> customerSupplierTypeRepository, IRepository<CustomerSupplierAddress> customerSupplierAddressRepository, IRepository<CustomerDefaultProduct> customerDefaultProductRepository, IRepository<CustomerSupplierPerson> customerSupplierPersonRepository) : base(repository, "CustomerSupplierNo")
- {
- CustomerSupplierTypeRepository = customerSupplierTypeRepository;
- CustomerSupplierAddressRepository = customerSupplierAddressRepository;
- CustomerDefaultProductRepository = customerDefaultProductRepository;
- CustomerSupplierPersonRepository = customerSupplierPersonRepository;
- SettingManager = settingManager;
- CacheManager = cacheManager;
- }
- protected override bool KeyIsAuto { get; set; } = false;
- #region GetSelect
- [DisableAuditing]
- public async Task<string> GetTypeSelectStr()
- {
- var list = await CustomerSupplierTypeRepository.GetAllListAsync(a => a.ParentNo != "root");
- string str = "<option value=\"0\" disabled selected>请选择...</option>";
- foreach (var l in list)
- {
- str += $"<option value=\"{l.TypeNo}\" parent=\"{l.ParentNo}\" data-id=\"{l.Id}\">{l.TypeName}</option>";
- }
- return str;
- }
- [DisableAuditing]
- public async Task<List<SelectListItem>> GetSelectList()
- {
- var list = await Repository.GetAllListAsync();
- var slist = new List<SelectListItem> {new SelectListItem {Text = @"请选择...", Value = "", Selected = true}};
- foreach (var l in list)
- {
- //slist.Add(new SelectListItem { Text = l., Value = l. });
- }
- return slist;
- }
- [DisableAuditing]
- public async Task<string> GetSelectStr()
- {
- var list = await Repository.GetAllListAsync();
- string str = "<option value=\"\" selected>请选择...</option>";
- foreach (var l in list)
- {
- //str += $"<option value=\"{l.}\">{l.}</option>";
- }
- return str;
- }
- [DisableAuditing]
- public async Task<List<TreeDto>> GetTypeTree()
- {
- var list = (await CustomerSupplierTypeRepository.GetAllListAsync(a => a.ParentNo != "root"));
- return GetChildTypes(list, "0");
- }
- private List<TreeDto> GetChildTypes(List<CustomerSupplierType> list, string parentNo)
- {
- var dtoList = new List<TreeDto>();
- var parents = list.Where(a => a.ParentNo == parentNo).ToList();
- if (!parents.Any())
- {
- return null;
- }
- foreach (var item in parents)
- {
- var dto = new TreeDto
- {
- Id = item.Id + "",
- Text = item.TypeName,
- Nodes = GetChildTypes(list, item.TypeNo)
- };
- dtoList.Add(dto);
- }
- return dtoList;
- }
- #endregion
- #region CURD
- [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierMgCreate)]
- public override async Task<CustomerSupplierDto> Create(CustomerSupplierCreateDto input)
- {
- return await CreateEntity(input);
- }
- [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierMgUpdate)]
- public override async Task<CustomerSupplierDto> Update(CustomerSupplierUpdateDto input)
- {
- return await UpdateEntity(input);
- }
- [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierMgDelete)]
- public override Task Delete(EntityDto<int> input)
- {
- return Repository.DeleteAsync(input.Id);
- }
- [DisableAuditing]
- [AbpAuthorize(PermissionNames.PagesCustomerSupplier)]
- public override async Task<PagedResultDto<CustomerSupplierDto>> GetAll(PagedRequestDto input)
- {
- var query = CreateFilteredQuery(input);
- query = ApplyFilter(query, input);
- var totalCount = await AsyncQueryableExecuter.CountAsync(query);
- query = ApplySorting(query, input);
- query = ApplyPaging(query, input);
- var entities = await AsyncQueryableExecuter.ToListAsync(query);
- var dtoList = new PagedResultDto<CustomerSupplierDto>(totalCount, entities.Select(MapToEntityDto).ToList());
- return dtoList;
- }
- #region Get
- [DisableAuditing]
- [AbpAuthorize(PermissionNames.PagesCustomerSupplier)]
- public override Task<CustomerSupplier> GetEntityById(int id)
- {
- return Repository.FirstOrDefaultAsync(id);
- }
- [DisableAuditing]
- [AbpAuthorize(PermissionNames.PagesCustomerSupplier)]
- public override Task<CustomerSupplier> GetEntityByNo(string no)
- {
- if (KeyFiledName.IsNullOrEmpty())
- {
- CheckErrors(IwbIdentityResult.Failed("编码/编号字段不明确,请检查后再操作!"));
- }
- LambdaObject obj = new LambdaObject()
- {
- FieldType = LambdaFieldType.S,
- FieldName = KeyFiledName,
- FieldValue = no,
- ExpType = LambdaExpType.Equal
- };
- var exp = obj.GetExp<CustomerSupplier>();
- return Repository.FirstOrDefaultAsync(exp);
- }
- [DisableAuditing]
- [AbpAuthorize(PermissionNames.PagesCustomerSupplier)]
- public override async Task<CustomerSupplierDto> GetDtoById(int id)
- {
- var entity = await GetEntityById(id);
- return MapToEntityDto(entity);
- }
- [DisableAuditing]
- [AbpAuthorize(PermissionNames.PagesCustomerSupplier)]
- public override async Task<CustomerSupplierDto> GetDtoByNo(string no)
- {
- var entity = await GetEntityByNo(no);
- return MapToEntityDto(entity);
- }
- #endregion
- #region Hide
- //protected override IQueryable<CustomerSupplier> ApplyFilter(IQueryable<CustomerSupplier> query, TGetAllInput input)
- //{
- // if (!input.KeyWords.IsNullOrEmpty())
- // {
- // object keyWords = input.KeyWords;
- // LambdaObject obj = new LambdaObject()
- // {
- // FieldType = (LambdaFieldType)input.FieldType,
- // FieldName = input.KeyField,
- // FieldValue = keyWords,
- // ExpType = (LambdaExpType)input.ExpType
- // };
- // var exp = obj.GetExp<CustomerSupplier>();
- // query = query.Where(exp);
- // }
- // if (input.SearchList != null && input.SearchList.Count > 0)
- // {
- // List<LambdaObject> objList = new List<LambdaObject>();
- // foreach (var o in input.SearchList)
- // {
- // if (o.KeyWords.IsNullOrEmpty())
- // continue;
- // object keyWords = o.KeyWords;
- // objList.Add(new LambdaObject
- // {
- // FieldType = (LambdaFieldType)o.FieldType,
- // FieldName = o.KeyField,
- // FieldValue = keyWords,
- // ExpType = (LambdaExpType)o.ExpType
- // });
- // }
- // var exp = objList.GetExp<CustomerSupplier>();
- // query = query.Where(exp);
- // }
- // return query;
- //}
- //protected override IQueryable<CustomerSupplier> ApplySorting(IQueryable<CustomerSupplier> query, PagedRequestDto input)
- //{
- // return query.OrderBy(a => a.No);
- //}
- //protected override IQueryable<CustomerSupplier> ApplyPaging(IQueryable<CustomerSupplier> query, PagedRequestDto input)
- //{
- // if (input is IPagedResultRequest pagedInput)
- // {
- // return query.Skip(pagedInput.SkipCount).Take(pagedInput.MaxResultCount);
- // }
- // return query;
- //}
- #endregion
- #endregion
- #region Address
- [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierAddressMg)]
- public async Task<List<CustomerSupplierAddressDto>> GetAllAddress(PagedRequestDto input)
- {
- var query = CustomerSupplierAddressRepository.GetAll();
- query = ApplyFilterEx<CustomerSupplierAddress>(query, input);
- query = ApplySortingEx<CustomerSupplierAddress>(query, input);
- var entities = await AsyncQueryableExecuter.ToListAsync(query);
- var dtoList = ObjectMapper.Map<List<CustomerSupplierAddressDto>>(entities);
- return dtoList;
- }
- [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierAddressMgCreateAddress)]
- public async Task<CustomerSupplierAddress> CreateAddress(CustomerSupplierAddressCreateDto input)
- {
- CustomerSupplierAddress entity = ObjectMapper.Map<CustomerSupplierAddress>(input);
- return await CustomerSupplierAddressRepository.InsertAsync(entity);
- }
- [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierAddressMgUpdateAddress)]
- public async Task<CustomerSupplierAddress> UpdateAddress(CustomerSupplierAddressUpdateDto input)
- {
- CustomerSupplierAddress entity = ObjectMapper.Map<CustomerSupplierAddress>(input);
- return await CustomerSupplierAddressRepository.UpdateAsync(entity);
- }
- [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierAddressMgDeleteAddress)]
- public Task DeleteAddress(EntityDto<int> input)
- {
- return CustomerSupplierAddressRepository.DeleteAsync(input.Id);
- }
- #endregion
- #region Person
- [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierPersonMg)]
- public async Task<List<CustomerSupplierPersonDto>> GetAllPerson(PagedRequestDto input)
- {
- var query = CustomerSupplierPersonRepository.GetAll();
- query = ApplyFilterEx(query, input);
- query = ApplySortingEx(query, input);
- var entities = await AsyncQueryableExecuter.ToListAsync(query);
- var dtoList = ObjectMapper.Map<List<CustomerSupplierPersonDto>>(entities);
- return dtoList;
- }
- [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierPersonMgCreatePerson)]
- public async Task<CustomerSupplierPerson> CreatePerson(CustomerSupplierPersonCreateDto input)
- {
- CustomerSupplierPerson entity = ObjectMapper.Map<CustomerSupplierPerson>(input);
- return await CustomerSupplierPersonRepository.InsertAsync(entity);
- }
- [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierPersonMgUpdatePerson)]
- public async Task<CustomerSupplierPerson> UpdatePerson(CustomerSupplierPersonUpdateDto input)
- {
- CustomerSupplierPerson entity = ObjectMapper.Map<CustomerSupplierPerson>(input);
- return await CustomerSupplierPersonRepository.UpdateAsync(entity);
- }
- [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerSupplierPersonMgDeletePerson)]
- public Task DeletePerson(EntityDto<int> input)
- {
- return CustomerSupplierPersonRepository.DeleteAsync(input.Id);
- }
- #endregion
- #region DefaultPerson
- [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerDefaultProductMg)]
- public async Task<List<CustomerDefaultProductDto>> GetAllProduct(PagedRequestDto input)
- {
- var query = CustomerDefaultProductRepository.GetAll();
- query = ApplyFilterEx(query, input);
- query = ApplySortingEx(query, input);
- var entities = await AsyncQueryableExecuter.ToListAsync(query);
- var dtoList = ObjectMapper.Map<List<CustomerDefaultProductDto>>(entities);
- return dtoList;
- }
- [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerDefaultProductMgCreateProduct)]
- public async Task<CustomerDefaultProduct> CreateProduct(CustomerDefaultProductCreateDto input)
- {
- CustomerDefaultProduct entity = ObjectMapper.Map<CustomerDefaultProduct>(input);
- return await CustomerDefaultProductRepository.InsertAsync(entity);
- }
- [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerDefaultProductMgUpdateProduct)]
- public async Task<CustomerDefaultProduct> UpdateProduct(CustomerDefaultProductUpdateDto input)
- {
- CustomerDefaultProduct entity = ObjectMapper.Map<CustomerDefaultProduct>(input);
- return await CustomerDefaultProductRepository.UpdateAsync(entity);
- }
- [AbpAuthorize(PermissionNames.PagesCustomerSupplierCustomerDefaultProductMgDeleteProduct)]
- public Task DeleteProduct(EntityDto<int> input)
- {
- return CustomerDefaultProductRepository.DeleteAsync(input.Id);
- }
- #endregion
-
-
- }
- }
|