| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Dynamic.Core;
- using System.Threading.Tasks;
- using Abp.Application.Services.Dto;
- using Abp.Authorization;
- using Abp.Domain.Repositories;
- using Abp.Extensions;
- using Abp.Timing;
- using Abp.UI;
- using IwbZero.AppServiceBase;
- using ShwasherSys.Authorization.Permissions;
- using ShwasherSys.CustomerInfo.Dto;
- using ShwasherSys.EntityFramework.Repositories;
- using ShwasherSys.Lambda;
- using ShwasherSys.Order;
- using ShwasherSys.ProductInfo;
- using ShwasherSys.ProductInfo.Dto;
- namespace ShwasherSys.CustomerInfo
- {
- [AbpAuthorize]
- public class CustomerDefaultProductAppService :ShwasherAsyncCrudAppService<CustomerDefaultProduct, CustomerDefaultProductDto, int, PagedRequestDto, CustomerDefaultProductCreateDto, CustomerDefaultProductUpdateDto >, ICustomerDefaultProductAppService
- {
- protected IRepository<Product,string> ProductRepository;
- protected IRepository<OrderItem> OrderItemRepository;
- protected IRepository<OrderHeader,string> OrderHeaderRepository;
- public CustomerDefaultProductAppService(IRepository<CustomerDefaultProduct, int> repository, IRepository<Product, string> productRepository, IRepository<OrderItem> orderItemRepository, IRepository<OrderHeader, string> orderHeaderRepository) : base(repository)
- {
- ProductRepository = productRepository;
- OrderItemRepository = orderItemRepository;
- OrderHeaderRepository = orderHeaderRepository;
- }
- protected override string GetPermissionName { get; set; } = PermissionNames.PagesCustomerInfoCustomers;
- protected override string GetAllPermissionName { get; set; } = PermissionNames.PagesCustomerInfoCustomers;
- protected override string CreatePermissionName { get; set; } = PermissionNames.PagesCustomerInfoCustomersCreateDefaultProduct;
- protected override string UpdatePermissionName { get; set; } = PermissionNames.PagesCustomerInfoCustomersUpdateDefaultProduct;
- protected override string DeletePermissionName { get; set; } = PermissionNames.PagesCustomerInfoCustomersDeleteDefaultProduct;
- public override async Task<PagedResultDto<CustomerDefaultProductDto>> GetAll(PagedRequestDto input)
- {
- CheckGetAllPermission();
- var query = CreateFilteredQuery(input);
- 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<CustomerDefaultProduct>();
- query = query.Where(exp);
- }
-
- var totalCount = await AsyncQueryableExecuter.CountAsync(query);
- var loProducts = ProductRepository.GetAll().Where(i=>i.IsLock=="N");
- var loCustomerDefaultProductDto = from d in query join p in loProducts on d.ProductNo equals p.Id
- orderby d.TimeLastMod descending
- select new CustomerDefaultProductDto()
- {
- CustomerId = d.CustomerId,
- CustomerProductName = d.CustomerProductName,
- Id = d.Id,
- ProductNo = d.ProductNo,
- ProductName = p.ProductName,
- Sequence = d.Sequence,
- TimeLastMod = d.TimeLastMod,
- PartNo=d.PartNo
- };
- loCustomerDefaultProductDto = loCustomerDefaultProductDto.OrderBy(i => i.Sequence);
- //query = ApplySorting(query, input);
- loCustomerDefaultProductDto = loCustomerDefaultProductDto.Skip(input.SkipCount).Take(input.MaxResultCount);
- var entities = await AsyncQueryableExecuter.ToListAsync(loCustomerDefaultProductDto);
- var dtos = new PagedResultDto<CustomerDefaultProductDto>(
- totalCount,
- entities
- );
- return dtos;
- }
- public override async Task<CustomerDefaultProductDto> Create(CustomerDefaultProductCreateDto input)
- {
- CheckCreatePermission();
- string lcProductNos = input?.ProductNo;
- string lcCustomerId = input?.CustomerId;
- if (!lcProductNos.IsNullOrEmpty() && lcProductNos.EndsWith(","))
- {
- lcProductNos = lcProductNos.Substring(0, lcProductNos.Length - 1);
- }
- if (lcProductNos.IsNullOrEmpty()|| lcCustomerId.IsNullOrEmpty())
- {
- throw new UserFriendlyException("传入参数有误!");
- }
- var loExistProducts = Repository.GetAll().Where(i => i.CustomerId == lcCustomerId).OrderByDescending(i => i.Sequence);
- var obj = loExistProducts.FirstOrDefault();
- string[] pNos = lcProductNos?.Split(',');
- int index = obj == null ? 1 : obj.Sequence;
- if (pNos != null)
-
- foreach (var s in pNos)
- {
- var exist = loExistProducts.FirstOrDefault(i => i.ProductNo == s);
- if (exist != null)
- {
- continue;
- }
- CustomerDefaultProduct loCustomerDefaultProduct = new CustomerDefaultProduct()
- {
- CustomerId = lcCustomerId,
- ProductNo = s,
- Sequence = index,
- TimeLastMod = Clock.Now,
-
- };
- await Repository.InsertAsync(loCustomerDefaultProduct);
- index++;
- }
- return new CustomerDefaultProductDto();
- }
- public override async Task<CustomerDefaultProductDto> Update(CustomerDefaultProductUpdateDto input)
- {
- var loExistProducts =await Repository.FirstOrDefaultAsync(i => i.CustomerId == input.CustomerId &&i.PartNo==input.PartNo);
- if (loExistProducts != null && loExistProducts.Id != input.Id)
- {
- throw new UserFriendlyException($"零件号重复!该客户维护的产品{loExistProducts.ProductNo },已经使用了零件号{loExistProducts.PartNo}!");
- }
- return await base.Update(input);
- }
- /*public string GetDefualtProductByOrderItemNo(int orderItemNo)
- {
- var orderItem = OrderItemRepository.Get(orderItemNo);
- return GetDefualtProductByOrderNo(orderItem.OrderNo);
- }
- public string GetDefualtProductByOrderNo(string orderNo)
- {
- var orderHeader = OrderHeaderRepository.Get(orderNo);
- return GetDefualtProductByCustomerId(orderHeader.CustomerId);
- }
- public string GetDefualtProductByCustomerId(string customerId)
- {
- var defualtProducts = Repository.GetAll().Where(i => i.CustomerId == customerId);
- string lcRetval = "";
- foreach (var item in defualtProducts)
- {
- lcRetval += $"<option value=\"{item.ProductNo}\">{item.ProductNo}</option>";
- }
- return lcRetval;
- }*/
- }
- }
|