FixedAssetsApplicationService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using System.Web.Mvc;
  7. using Abp.Application.Services.Dto;
  8. using Abp.Auditing;
  9. using Abp.Authorization;
  10. using Abp.Domain.Repositories;
  11. using Abp.Domain.Uow;
  12. using Abp.Runtime.Caching;
  13. using IwbZero.AppServiceBase;
  14. using IwbZero.Auditing;
  15. using IwbZero.Helper;
  16. using ShwasherSys.Authorization.Permissions;
  17. using ShwasherSys.CompanyInfo.FixedAssetInfo.Dto;
  18. namespace ShwasherSys.CompanyInfo.FixedAssetInfo
  19. {
  20. [AbpAuthorize, AuditLog("设备固定资产维护")]
  21. public class FixedAssetAppService : IwbZeroAsyncCrudAppService<FixedAsset, FixedAssetDto, int, IwbPagedRequestDto, FixedAssetCreateDto, FixedAssetUpdateDto >, IFixedAssetAppService
  22. {
  23. public FixedAssetAppService(
  24. ICacheManager cacheManager,
  25. IRepository<FixedAsset, int> repository) : base(repository, "No")
  26. {
  27. CacheManager = cacheManager;
  28. }
  29. protected override bool KeyIsAuto { get; set; } = false;
  30. #region GetSelect
  31. [DisableAuditing]
  32. public override async Task<List<SelectListItem>> GetSelectList()
  33. {
  34. var list = await Repository.GetAllListAsync();
  35. var sList = new List<SelectListItem> {new SelectListItem {Text = @"请选择设备固定资产...", Value = "", Selected = true}};
  36. foreach (var l in list)
  37. {
  38. sList.Add(new SelectListItem { Value = l.No, Text = l.Name });
  39. }
  40. return sList;
  41. }
  42. [DisableAuditing]
  43. public override async Task<string> GetSelectStr()
  44. {
  45. var list = await Repository.GetAllListAsync();
  46. string str = "<option value=\"\" selected>请选择设备固定资产...</option>";
  47. foreach (var l in list)
  48. {
  49. str += $"<option value=\"{l.No}\">{l.Name}</option>";
  50. }
  51. return str;
  52. }
  53. [DisableAuditing]
  54. public async Task<List<SelectListItem>> GetSelectListName()
  55. {
  56. var list = await Repository.GetAllListAsync();
  57. var sList = new List<SelectListItem> {new SelectListItem {Text = @"请选择设备固定资产...", Value = "", Selected = true}};
  58. foreach (var l in list)
  59. {
  60. sList.Add(new SelectListItem { Value = l.Name, Text = l.Name });
  61. }
  62. sList.Add(new SelectListItem {Text = @"其他", Value = "其他"});
  63. return sList;
  64. }
  65. [DisableAuditing]
  66. public async Task<string> GetSelectStrName()
  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.Name}\">{l.Name}</option>";
  73. }
  74. str+= $"<option value=\"其他\">其他</option>";
  75. return str;
  76. }
  77. #endregion
  78. #region CURD
  79. [AbpAuthorize(PermissionNames.PagesCompanyDieMaintenanceFixedAsset)]
  80. public override async Task Create(FixedAssetCreateDto input)
  81. {
  82. input.No = await MaintainTypeDefinition.GetDeviceNo(Repository);
  83. await CreateEntity(input);
  84. }
  85. private async Task<string> GetFixedAssetNo()
  86. {
  87. using (UnitOfWorkManager.Current.DisableFilter(AbpDataFilters.SoftDelete))
  88. {
  89. var lastEntity = await Repository.GetAll().OrderByDescending(a => a.CreationTime)
  90. .FirstOrDefaultAsync();
  91. int noLength = 4, index = 0;
  92. if (lastEntity != null)
  93. {
  94. var entityNo = lastEntity.No;
  95. int.TryParse(entityNo.Substring(entityNo.Length - noLength), out index);
  96. }
  97. index++;
  98. string no = $"SHSD-{index.LeftPad(noLength)}";
  99. if ((await Repository.CountAsync(a=>a.No==no)) > 0)
  100. {
  101. no = await GetFixedAssetNo();
  102. }
  103. return no;
  104. }
  105. }
  106. [AbpAuthorize(PermissionNames.PagesCompanyDieMaintenanceFixedAssetUpdate)]
  107. public override async Task Update(FixedAssetUpdateDto input)
  108. {
  109. await UpdateEntity(input);
  110. }
  111. [AbpAuthorize(PermissionNames.PagesCompanyDieMaintenanceFixedAssetDelete)]
  112. public override Task Delete(EntityDto<int> input)
  113. {
  114. return Repository.DeleteAsync(input.Id);
  115. }
  116. [DisableAuditing]
  117. [AbpAuthorize(PermissionNames.PagesCompanyDieMaintenanceFixedAssetQuery)]
  118. public override async Task<PagedResultDto<FixedAssetDto>> GetAll(IwbPagedRequestDto input)
  119. {
  120. var query = CreateFilteredQuery(input);
  121. query = ApplyFilter(query, input);
  122. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  123. query = ApplySorting(query, input);
  124. query = ApplyPaging(query, input);
  125. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  126. var dtoList = new PagedResultDto<FixedAssetDto>(totalCount, entities.Select(MapToEntityDto).ToList());
  127. return dtoList;
  128. }
  129. #region GetEntity/Dto
  130. /// <summary>
  131. /// 查询实体Dto
  132. /// </summary>
  133. /// <param name="input"></param>
  134. /// <returns></returns>
  135. [DisableAuditing]
  136. [AbpAuthorize(PermissionNames.PagesCompanyDieMaintenanceFixedAssetQuery)]
  137. public override async Task<FixedAssetDto> GetDto(EntityDto<int> input)
  138. {
  139. var entity = await GetEntity(input);
  140. return MapToEntityDto(entity);
  141. }
  142. /// <summary>
  143. /// 查询实体Dto
  144. /// </summary>
  145. /// <param name="id"></param>
  146. /// <returns></returns>
  147. [DisableAuditing]
  148. [AbpAuthorize(PermissionNames.PagesCompanyDieMaintenanceFixedAssetQuery)]
  149. public override async Task<FixedAssetDto> GetDtoById(int id)
  150. {
  151. var entity = await GetEntityById(id);
  152. return MapToEntityDto(entity);
  153. }
  154. /// <summary>
  155. /// 查询实体Dto(需指明自定义字段)
  156. /// </summary>
  157. /// <param name="no"></param>
  158. /// <returns></returns>
  159. [DisableAuditing]
  160. [AbpAuthorize(PermissionNames.PagesCompanyDieMaintenanceFixedAssetQuery)]
  161. public override async Task<FixedAssetDto> GetDtoByNo(string no)
  162. {
  163. var entity = await GetEntityByNo(no);
  164. return MapToEntityDto(entity);
  165. }
  166. /// <summary>
  167. /// 查询实体
  168. /// </summary>
  169. /// <param name="input"></param>
  170. /// <returns></returns>
  171. [DisableAuditing]
  172. [AbpAuthorize(PermissionNames.PagesCompanyDieMaintenanceFixedAssetQuery)]
  173. public override async Task<FixedAsset> GetEntity(EntityDto<int> input)
  174. {
  175. var entity = await GetEntityById(input.Id);
  176. return entity;
  177. }
  178. /// <summary>
  179. /// 查询实体
  180. /// </summary>
  181. /// <param name="id"></param>
  182. /// <returns></returns>
  183. [DisableAuditing]
  184. [AbpAuthorize(PermissionNames.PagesCompanyDieMaintenanceFixedAssetQuery)]
  185. public override async Task<FixedAsset> GetEntityById(int id)
  186. {
  187. return await Repository.FirstOrDefaultAsync(a=>a.Id==id);
  188. }
  189. /// <summary>
  190. /// 查询实体(需指明自定义字段)
  191. /// </summary>
  192. /// <param name="no"></param>
  193. /// <returns></returns>
  194. [DisableAuditing]
  195. [AbpAuthorize(PermissionNames.PagesCompanyDieMaintenanceFixedAssetQuery)]
  196. public override async Task<FixedAsset> GetEntityByNo(string no)
  197. {
  198. //CheckGetPermission();
  199. if (string.IsNullOrEmpty(KeyFiledName))
  200. {
  201. ThrowError("NoKeyFieldName");
  202. }
  203. return await base.GetEntityByNo(no);
  204. }
  205. #endregion
  206. #region Hide
  207. ///// <summary>
  208. ///// 根据给定的<see cref="IwbPagedRequestDto"/>创建 <see cref="IQueryable{FixedAsset}"/>过滤查询.
  209. ///// </summary>
  210. ///// <param name="input">The input.</param>
  211. //protected override IQueryable<FixedAsset> CreateFilteredQuery(IwbPagedRequestDto input)
  212. //{
  213. // var query = Repository.GetAll();
  214. // var pagedInput = input as IIwbPagedRequest;
  215. // if (pagedInput == null)
  216. // {
  217. // return query;
  218. // }
  219. // if (!string.IsNullOrEmpty(pagedInput.KeyWords))
  220. // {
  221. // object keyWords = pagedInput.KeyWords;
  222. // LambdaObject obj = new LambdaObject()
  223. // {
  224. // FieldType = (LambdaFieldType)pagedInput.FieldType,
  225. // FieldName = pagedInput.KeyField,
  226. // FieldValue = keyWords,
  227. // ExpType = (LambdaExpType)pagedInput.ExpType
  228. // };
  229. // var exp = obj.GetExp<FixedAsset>();
  230. // query = exp != null ? query.Where(exp) : query;
  231. // }
  232. // if (pagedInput.SearchList != null && pagedInput.SearchList.Count > 0)
  233. // {
  234. // List<LambdaObject> objList = new List<LambdaObject>();
  235. // foreach (var o in pagedInput.SearchList)
  236. // {
  237. // if (string.IsNullOrEmpty(o.KeyWords))
  238. // continue;
  239. // object keyWords = o.KeyWords;
  240. // objList.Add(new LambdaObject
  241. // {
  242. // FieldType = (LambdaFieldType)o.FieldType,
  243. // FieldName = o.KeyField,
  244. // FieldValue = keyWords,
  245. // ExpType = (LambdaExpType)o.ExpType
  246. // });
  247. // }
  248. // var exp = objList.GetExp<FixedAsset>();
  249. // query = exp != null ? query.Where(exp) : query;
  250. // }
  251. // return query;
  252. //}
  253. //protected override IQueryable<FixedAsset> ApplySorting(IQueryable<FixedAsset> query, IwbPagedRequestDto input)
  254. //{
  255. // return query.OrderBy(a => a.No);
  256. //}
  257. //protected override IQueryable<FixedAsset> ApplyPaging(IQueryable<FixedAsset> query, IwbPagedRequestDto input)
  258. //{
  259. // if (input is IPagedResultRequest pagedInput)
  260. // {
  261. // return query.Skip(pagedInput.SkipCount).Take(pagedInput.MaxResultCount);
  262. // }
  263. // return query;
  264. //}
  265. #endregion
  266. #endregion
  267. }
  268. }