CurrentRmStoreHousesApplicationService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using System.Web.Mvc;
  6. using Abp.Application.Services.Dto;
  7. using Abp.Auditing;
  8. using Abp.Authorization;
  9. using Abp.Domain.Repositories;
  10. using Abp.Json;
  11. using Abp.Runtime.Caching;
  12. using Abp.Timing;
  13. using IwbZero.Auditing;
  14. using IwbZero.AppServiceBase;
  15. using IwbZero.IdentityFramework;
  16. using Newtonsoft.Json;
  17. using ShwasherSys.Authorization.Permissions;
  18. using ShwasherSys.ProductStoreInfo;
  19. using ShwasherSys.ProductStoreInfo.Dto;
  20. using ShwasherSys.RmStore.Dto;
  21. namespace ShwasherSys.RmStore
  22. {
  23. [AbpAuthorize]
  24. public class CurrentRmStoreHouseAppService : IwbZeroAsyncCrudAppService<CurrentRmStoreHouse, CurrentRmStoreHouseDto, string, IwbPagedRequestDto, CurrentRmStoreHouseCreateDto, CurrentRmStoreHouseUpdateDto >, ICurrentRmStoreHouseAppService
  25. {
  26. public CurrentRmStoreHouseAppService(
  27. ICacheManager cacheManager,
  28. IRepository<CurrentRmStoreHouse, string> repository, IRepository<ViewCurrentRmStoreHouse, string> viewCurrentRmStoreHouseRepository, IRepository<RmEnterStore, string> rmEnterStoreRepository, IRepository<RmOutStore, string> rmOutStoreRepository) : base(repository, "Id")
  29. {
  30. ViewCurrentRmStoreHouseRepository = viewCurrentRmStoreHouseRepository;
  31. RmEnterStoreRepository = rmEnterStoreRepository;
  32. RmOutStoreRepository = rmOutStoreRepository;
  33. CacheManager = cacheManager;
  34. }
  35. protected override bool KeyIsAuto { get; set; } = false;
  36. protected IRepository<ViewCurrentRmStoreHouse,string> ViewCurrentRmStoreHouseRepository { get; }
  37. protected IRepository<RmEnterStore,string> RmEnterStoreRepository { get; }
  38. protected IRepository<RmOutStore,string> RmOutStoreRepository { get; }
  39. #region GetSelect
  40. [DisableAuditing]
  41. public override async Task<List<SelectListItem>> GetSelectList()
  42. {
  43. var list = await Repository.GetAllListAsync();
  44. var sList = new List<SelectListItem> {new SelectListItem {Text = @"请选择...", Value = "", Selected = true}};
  45. foreach (var l in list)
  46. {
  47. //sList.Add(new SelectListItem { Value = l.Id, Text = l. });
  48. }
  49. return sList;
  50. }
  51. [DisableAuditing]
  52. public override async Task<string> GetSelectStr()
  53. {
  54. var list = await Repository.GetAllListAsync();
  55. string str = "<option value=\"\" selected>请选择...</option>";
  56. foreach (var l in list)
  57. {
  58. //str += $"<option value=\"{l.Id}\">{l.}</option>";
  59. }
  60. return str;
  61. }
  62. #endregion
  63. #region CURD
  64. [DisableAuditing]
  65. [AbpAuthorize(PermissionNames.PagesRawMaterialStoreRmCurrentStoreMg)]
  66. public override async Task<PagedResultDto<CurrentRmStoreHouseDto>> GetAll(IwbPagedRequestDto input)
  67. {
  68. var query = CreateFilteredQuery(input);
  69. query = ApplyFilter(query, input);
  70. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  71. query = ApplySorting(query, input);
  72. query = ApplyPaging(query, input);
  73. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  74. var dtoList = new PagedResultDto<CurrentRmStoreHouseDto>(totalCount, entities.Select(MapToEntityDto).ToList());
  75. return dtoList;
  76. }
  77. #region GetEntity/Dto
  78. /// <summary>
  79. /// 查询实体Dto
  80. /// </summary>
  81. /// <param name="input"></param>
  82. /// <returns></returns>
  83. [DisableAuditing]
  84. [AbpAuthorize(PermissionNames.PagesRawMaterialStoreRmCurrentStoreMgQuery)]
  85. public override async Task<CurrentRmStoreHouseDto> GetDto(EntityDto<string> input)
  86. {
  87. var entity = await GetEntity(input);
  88. return MapToEntityDto(entity);
  89. }
  90. /// <summary>
  91. /// 查询实体Dto
  92. /// </summary>
  93. /// <param name="id"></param>
  94. /// <returns></returns>
  95. [DisableAuditing]
  96. [AbpAuthorize(PermissionNames.PagesRawMaterialStoreRmCurrentStoreMgQuery)]
  97. public override async Task<CurrentRmStoreHouseDto> GetDtoById(string id)
  98. {
  99. var entity = await GetEntityById(id);
  100. return MapToEntityDto(entity);
  101. }
  102. /// <summary>
  103. /// 查询实体Dto(需指明自定义字段)
  104. /// </summary>
  105. /// <param name="no"></param>
  106. /// <returns></returns>
  107. [DisableAuditing]
  108. [AbpAuthorize(PermissionNames.PagesRawMaterialStoreRmCurrentStoreMgQuery)]
  109. public override async Task<CurrentRmStoreHouseDto> GetDtoByNo(string no)
  110. {
  111. var entity = await GetEntityByNo(no);
  112. return MapToEntityDto(entity);
  113. }
  114. /// <summary>
  115. /// 查询实体
  116. /// </summary>
  117. /// <param name="input"></param>
  118. /// <returns></returns>
  119. [DisableAuditing]
  120. [AbpAuthorize(PermissionNames.PagesRawMaterialStoreRmCurrentStoreMgQuery)]
  121. public override async Task<CurrentRmStoreHouse> GetEntity(EntityDto<string> input)
  122. {
  123. var entity = await GetEntityById(input.Id);
  124. return entity;
  125. }
  126. /// <summary>
  127. /// 查询实体
  128. /// </summary>
  129. /// <param name="id"></param>
  130. /// <returns></returns>
  131. [DisableAuditing]
  132. [AbpAuthorize(PermissionNames.PagesRawMaterialStoreRmCurrentStoreMgQuery)]
  133. public override async Task<CurrentRmStoreHouse> GetEntityById(string id)
  134. {
  135. return await Repository.FirstOrDefaultAsync(a=>a.Id==id);
  136. }
  137. /// <summary>
  138. /// 查询实体(需指明自定义字段)
  139. /// </summary>
  140. /// <param name="no"></param>
  141. /// <returns></returns>
  142. [DisableAuditing]
  143. [AbpAuthorize(PermissionNames.PagesRawMaterialStoreRmCurrentStoreMgQuery)]
  144. public override async Task<CurrentRmStoreHouse> GetEntityByNo(string no)
  145. {
  146. //CheckGetPermission();
  147. if (string.IsNullOrEmpty(KeyFiledName))
  148. {
  149. ThrowError("NoKeyFieldName");
  150. }
  151. return await base.GetEntityByNo(no);
  152. }
  153. #endregion
  154. #region Hide
  155. ///// <summary>
  156. ///// 根据给定的<see cref="IwbPagedRequestDto"/>创建 <see cref="IQueryable{CurrentRmStoreHouse}"/>过滤查询.
  157. ///// </summary>
  158. ///// <param name="input">The input.</param>
  159. //protected override IQueryable<CurrentRmStoreHouse> CreateFilteredQuery(IwbPagedRequestDto input)
  160. //{
  161. // var query = Repository.GetAll();
  162. // var pagedInput = input as IIwbPagedRequest;
  163. // if (pagedInput == null)
  164. // {
  165. // return query;
  166. // }
  167. // if (!string.IsNullOrEmpty(pagedInput.KeyWords))
  168. // {
  169. // object keyWords = pagedInput.KeyWords;
  170. // LambdaObject obj = new LambdaObject()
  171. // {
  172. // FieldType = (LambdaFieldType)pagedInput.FieldType,
  173. // FieldName = pagedInput.KeyField,
  174. // FieldValue = keyWords,
  175. // ExpType = (LambdaExpType)pagedInput.ExpType
  176. // };
  177. // var exp = obj.GetExp<CurrentRmStoreHouse>();
  178. // query = exp != null ? query.Where(exp) : query;
  179. // }
  180. // if (pagedInput.SearchList != null && pagedInput.SearchList.Count > 0)
  181. // {
  182. // List<LambdaObject> objList = new List<LambdaObject>();
  183. // foreach (var o in pagedInput.SearchList)
  184. // {
  185. // if (string.IsNullOrEmpty(o.KeyWords))
  186. // continue;
  187. // object keyWords = o.KeyWords;
  188. // objList.Add(new LambdaObject
  189. // {
  190. // FieldType = (LambdaFieldType)o.FieldType,
  191. // FieldName = o.KeyField,
  192. // FieldValue = keyWords,
  193. // ExpType = (LambdaExpType)o.ExpType
  194. // });
  195. // }
  196. // var exp = objList.GetExp<CurrentRmStoreHouse>();
  197. // query = exp != null ? query.Where(exp) : query;
  198. // }
  199. // return query;
  200. //}
  201. //protected override IQueryable<CurrentRmStoreHouse> ApplySorting(IQueryable<CurrentRmStoreHouse> query, IwbPagedRequestDto input)
  202. //{
  203. // return query.OrderBy(a => a.No);
  204. //}
  205. //protected override IQueryable<CurrentRmStoreHouse> ApplyPaging(IQueryable<CurrentRmStoreHouse> query, IwbPagedRequestDto input)
  206. //{
  207. // if (input is IPagedResultRequest pagedInput)
  208. // {
  209. // return query.Skip(pagedInput.SkipCount).Take(pagedInput.MaxResultCount);
  210. // }
  211. // return query;
  212. //}
  213. #endregion
  214. #endregion
  215. [DisableAuditing]
  216. [AbpAuthorize(PermissionNames.PagesRawMaterialStoreRmCurrentStoreMgQuery)]
  217. public async Task<PagedResultDto<ViewCurrentRmStoreHouse>> GetAllView(IwbPagedRequestDto input)
  218. {
  219. var query = ViewCurrentRmStoreHouseRepository.GetAll();
  220. query = ApplyFilter(query, input);
  221. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  222. query = _ApplySorting(query, input);
  223. query = _ApplyPaging(query, input);
  224. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  225. var dtoList = new PagedResultDto<ViewCurrentRmStoreHouse>(totalCount, entities);
  226. return dtoList;
  227. }
  228. [AbpAuthorize(PermissionNames.PagesRawMaterialStoreRmCurrentStoreMgAddEnter)]
  229. public async Task<RmEnterStore> AddEnter(AddRmEnterStore input)
  230. {
  231. //string jsonInput = input.ToJsonString();
  232. //RmEnterStore enter = JsonConvert.DeserializeObject<RmEnterStore>(jsonInput);
  233. RmEnterStore enter = ObjectMapper.Map<RmEnterStore>(input);
  234. enter.Id = Guid.NewGuid().ToString("N");
  235. enter.ApplyQuantity = input.Quantity;
  236. enter.Quantity = 0;
  237. enter.ApplyEnterDate = Clock.Now;
  238. enter.ApplyStatus = RmEnterOutStatusEnum.Applying.ToInt();
  239. enter.CreateSourceType = CreateSourceType.Manual.ToInt();
  240. enter.IsClose = false;
  241. return await RmEnterStoreRepository.InsertAsync(enter);
  242. }
  243. [AbpAuthorize(PermissionNames.PagesRawMaterialStoreRmCurrentStoreMgAddOut)]
  244. public async Task<RmOutStore> AddOut(AddRmOutStoreDto input)
  245. {
  246. var entity =
  247. await Repository.FirstOrDefaultAsync(i =>
  248. i.Id == input.CurrentRmStoreHouseNo);
  249. var canUserQuantity = entity.Quantity - entity.FreezeQuantity;
  250. if (canUserQuantity < input.Quantity)
  251. {
  252. CheckErrors(new IwbIdentityResult("出库数量不能大于可用数量!"));
  253. }
  254. entity.FreezeQuantity += input.Quantity ?? 0;
  255. RmOutStore outStore = new RmOutStore()
  256. {
  257. Id = Guid.NewGuid().ToString("N"),
  258. RmProductNo = entity.RmProductNo,
  259. StoreHouseId = entity.StoreHouseId,
  260. ApplyStatus = RmEnterOutStatusEnum.Applying.ToInt(),
  261. IsClose = false,
  262. IsConfirm = false,
  263. Quantity = input.Quantity ?? 0,
  264. ActualQuantity = 0,
  265. ApplyOutDate = Clock.Now,
  266. CreateSourceType = CreateSourceType.Manual.ToInt(),
  267. ProductBatchNum = entity.ProductBatchNum,
  268. CurrentRmStoreHouseNo = input.CurrentRmStoreHouseNo
  269. };
  270. await Repository.UpdateAsync(entity);
  271. return await RmOutStoreRepository.InsertAsync(outStore);
  272. }
  273. }
  274. }