StoreHouseLocationsApplicationService.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System.Threading.Tasks;
  2. using Abp.Authorization;
  3. using Abp.Domain.Repositories;
  4. using Abp.Extensions;
  5. using IwbZero.AppServiceBase;
  6. using IwbZero.IdentityFramework;
  7. using Microsoft.AspNet.Identity;
  8. using ShwasherSys.Authorization.Permissions;
  9. using ShwasherSys.BasicInfo.Region.Dto;
  10. using ShwasherSys.BasicInfo.StoreHouseLocations.Dto;
  11. namespace ShwasherSys.BasicInfo.StoreHouseLocations
  12. {
  13. [AbpAuthorize]
  14. public class StoreHouseLocationsAppService : ShwasherAsyncCrudAppService<StoreHouseLocation, StoreHouseLocationDto, int, PagedRequestDto, StoreHouseLocationCreateDto, StoreHouseLocationUpdateDto >, IStoreHouseLocationsAppService
  15. {
  16. public StoreHouseLocationsAppService(IRepository<StoreHouseLocation, int> repository, IRepository<StoreHouse> storeHouseRepository) : base(repository, "StoreLocationNo")
  17. {
  18. StoreHouseRepository = storeHouseRepository;
  19. KeyIsAuto = false;
  20. }
  21. protected override string GetPermissionName { get; set; } = PermissionNames.PagesBasicInfoStoreHouseLocations;
  22. protected override string GetAllPermissionName { get; set; } = PermissionNames.PagesBasicInfoStoreHouseLocations;
  23. protected override string CreatePermissionName { get; set; } = PermissionNames.PagesBasicInfoStoreHouseLocationsCreate;
  24. protected override string UpdatePermissionName { get; set; } = PermissionNames.PagesBasicInfoStoreHouseLocationsUpdate;
  25. protected override string DeletePermissionName { get; set; } = PermissionNames.PagesBasicInfoStoreHouseLocationsDelete;
  26. protected IRepository<StoreHouse> StoreHouseRepository { get; }
  27. public override async Task<StoreHouseLocationDto> Create(StoreHouseLocationCreateDto input)
  28. {
  29. CheckCreatePermission();
  30. var storeHouse = StoreHouseRepository.Get(input.StoreHouseId ?? 0);
  31. string numPrex = storeHouse.StoreHouseTypeId != StoreHouseType.Finish ? input.StoreHouseId + "-"+ input.StoreAreaCode : input.StoreAreaCode;
  32. string suffix = "";
  33. if (storeHouse.StoreHouseTypeId != StoreHouseType.Rm)
  34. {
  35. if (input.ShelfNumber.IsNullOrEmpty() || input.ShelfLevel.IsNullOrEmpty() ||
  36. input.SequenceNo.IsNullOrEmpty())
  37. {
  38. CheckErrors(new IdentityResult("货架,层次或者列号不能为空!"));
  39. }
  40. //suffix = "-"+ input.ShelfNumber + "-" + input.ShelfLevel + "-" + input.SequenceNo;
  41. }
  42. suffix = (input.ShelfNumber.IsNullOrEmpty() ? "" : "-" + input.ShelfNumber) + (input.ShelfLevel.IsNullOrEmpty() ? "" : "-" + input.ShelfLevel) + (input.SequenceNo.IsNullOrEmpty() ? "" : "-" + input.SequenceNo);
  43. input.StoreLocationNo = numPrex+ suffix;
  44. var entity = await Repository.FirstOrDefaultAsync(i => i.StoreLocationNo == input.StoreLocationNo);
  45. if (entity != null)
  46. {
  47. CheckErrors(IwbIdentityResult.Failed("对应的库位信息已存在!"));
  48. }
  49. return await CreateEntity1(input);
  50. }
  51. public override async Task<StoreHouseLocationDto> Update(StoreHouseLocationUpdateDto input)
  52. {
  53. CheckUpdatePermission();
  54. //var storeHouse = StoreHouseRepository.Get(input.StoreHouseId ?? 0);
  55. //string numPrex = storeHouse.StoreHouseTypeId != StoreHouseType.Finish ? input.StoreHouseId + "-" + input.StoreAreaCode : input.StoreAreaCode;
  56. //string suffix = "";
  57. //if (storeHouse.StoreHouseTypeId != StoreHouseType.Rm)
  58. //{
  59. // if (input.ShelfNumber.IsNullOrEmpty() || input.ShelfLevel.IsNullOrEmpty() ||
  60. // input.SequenceNo.IsNullOrEmpty())
  61. // {
  62. // CheckErrors(new IdentityResult("货架,层次或者列号不能为空!"));
  63. // }
  64. //}
  65. //suffix = (input.ShelfNumber.IsNullOrEmpty()?"":"-" + input.ShelfNumber) + (input.ShelfLevel.IsNullOrEmpty()?"":"-" + input.ShelfLevel) + (input.SequenceNo.IsNullOrEmpty() ? "":"-" + input.SequenceNo);
  66. //input.StoreLocationNo = numPrex + suffix;
  67. var entity = await Repository.FirstOrDefaultAsync(i => i.StoreLocationNo == input.StoreLocationNo);
  68. if (entity==null)
  69. {
  70. CheckErrors(IwbIdentityResult.Failed("未查询到对应的库位信息!"));
  71. }
  72. MapToEntity(input, entity);
  73. await Repository.UpdateAsync(entity);
  74. return MapToEntityDto(entity);
  75. }
  76. }
  77. }