SceneFlowApplicationService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using System.Web.Mvc;
  5. using Abp.Application.Services.Dto;
  6. using Abp.Auditing;
  7. using Abp.Authorization;
  8. using Abp.Domain.Repositories;
  9. using Abp.Runtime.Caching;
  10. using IwbZero.Auditing;
  11. using IwbZero.AppServiceBase;
  12. using IwbZero.ToolCommon.Lambda;
  13. using IwbZero.ToolCommon.StringModel;
  14. using WePlatform.Authorization;
  15. using WePlatform.Configuration;
  16. using WePlatform.WeLib.Package.Dto;
  17. using WePlatform.WeLib.SceneFlow.Dto;
  18. namespace WePlatform.WeLib.SceneFlow
  19. {
  20. [AbpAuthorize, AuditLog("情景流")]
  21. public class SceneFlowAppService : IwbAsyncCrudAppService<SceneFlowInfo, SceneFlowDto, string, IwbPagedRequestDto, SceneFlowCreateDto, SceneFlowUpdateDto >, ISceneFlowAppService
  22. {
  23. public SceneFlowAppService(
  24. ICacheManager cacheManager,
  25. IRepository<SceneFlowInfo, string> repository) : base(repository, "Id")
  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.Id, Text = l.FlowName });
  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.Id}\">{l.FlowName}</option>";
  50. }
  51. return str;
  52. }
  53. #endregion
  54. #region CURD
  55. [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgCreate)]
  56. public override async Task Create(SceneFlowCreateDto input)
  57. {
  58. input.Id= await AppGuidManager.GetNextRecordIdAsync(DataLibType.SceneFlowInfo);
  59. input.SceneFlowState = SceneFlowStateDefinition.New;
  60. await CreateEntity(input);
  61. }
  62. [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgUpdate)]
  63. public override async Task Update(SceneFlowUpdateDto input)
  64. {
  65. var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
  66. if (entity?.SceneFlowState == SceneFlowStateDefinition.Solidified)
  67. {
  68. CheckErrors($"情景流已固化确认,不能再操作!");
  69. return;
  70. }
  71. await UpdateEntity(input);
  72. }
  73. [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgDelete)]
  74. public override async Task Delete(EntityDto<string> input)
  75. {
  76. var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
  77. if (entity?.SceneFlowState == SceneFlowStateDefinition.Solidified)
  78. {
  79. CheckErrors($"情景流已固化确认,不能再操作!");
  80. return;
  81. }
  82. await base.Delete(input);
  83. }
  84. [DisableAuditing]
  85. [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgQuery)]
  86. public override async Task<PagedResultDto<SceneFlowDto>> GetAll(IwbPagedRequestDto input)
  87. {
  88. var query = CreateFilteredQuery(input);
  89. //query = ApplyFilter(query, input);
  90. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  91. query = ApplySorting(query, input);
  92. query = ApplyPaging(query, input);
  93. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  94. var dtoList = new PagedResultDto<SceneFlowDto>(totalCount, entities.Select(MapToEntityDto).ToList());
  95. return dtoList;
  96. }
  97. #region GetEntity/Dto
  98. /// <summary>
  99. /// 查询实体Dto
  100. /// </summary>
  101. /// <param name="input"></param>
  102. /// <returns></returns>
  103. [DisableAuditing]
  104. [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgQuery)]
  105. public override async Task<SceneFlowDto> GetDto(EntityDto<string> input)
  106. {
  107. var entity = await GetEntity(input);
  108. return MapToEntityDto(entity);
  109. }
  110. /// <summary>
  111. /// 查询实体Dto
  112. /// </summary>
  113. /// <param name="id"></param>
  114. /// <returns></returns>
  115. [DisableAuditing]
  116. [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgQuery)]
  117. public override async Task<SceneFlowDto> GetDtoById(string id)
  118. {
  119. var entity = await GetEntityById(id);
  120. return MapToEntityDto(entity);
  121. }
  122. /// <summary>
  123. /// 查询实体Dto(需指明自定义字段)
  124. /// </summary>
  125. /// <param name="no"></param>
  126. /// <returns></returns>
  127. [DisableAuditing]
  128. [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgQuery)]
  129. public override async Task<SceneFlowDto> GetDtoByNo(string no)
  130. {
  131. var entity = await GetEntityByNo(no);
  132. return MapToEntityDto(entity);
  133. }
  134. /// <summary>
  135. /// 查询实体
  136. /// </summary>
  137. /// <param name="input"></param>
  138. /// <returns></returns>
  139. [DisableAuditing]
  140. [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgQuery)]
  141. public override async Task<SceneFlowInfo> GetEntity(EntityDto<string> input)
  142. {
  143. var entity = await GetEntityById(input.Id);
  144. return entity;
  145. }
  146. /// <summary>
  147. /// 查询实体
  148. /// </summary>
  149. /// <param name="id"></param>
  150. /// <returns></returns>
  151. [DisableAuditing]
  152. [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgQuery)]
  153. public override async Task<SceneFlowInfo> GetEntityById(string id)
  154. {
  155. return await Repository.FirstOrDefaultAsync(a=>a.Id==id);
  156. }
  157. /// <summary>
  158. /// 查询实体(需指明自定义字段)
  159. /// </summary>
  160. /// <param name="no"></param>
  161. /// <returns></returns>
  162. [DisableAuditing]
  163. [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgQuery)]
  164. public override async Task<SceneFlowInfo> GetEntityByNo(string no)
  165. {
  166. //CheckGetPermission();
  167. if (string.IsNullOrEmpty(KeyFiledName))
  168. {
  169. ThrowError("NoKeyFieldName");
  170. }
  171. return await base.GetEntityByNo(no);
  172. }
  173. #endregion
  174. #region Hide
  175. /// <summary>
  176. /// 根据给定的<see cref="IwbPagedRequestDto"/>创建 <see cref="IQueryable{SceneFlowInfo}"/>过滤查询.
  177. /// </summary>
  178. /// <param name="input">The input.</param>
  179. protected override IQueryable<SceneFlowInfo> CreateFilteredQuery(IwbPagedRequestDto input)
  180. {
  181. var query = Repository.GetAllIncluding(a => a.SceneCategoryInfo);
  182. var pagedInput = input as IIwbPagedRequest;
  183. if (pagedInput == null)
  184. {
  185. return query;
  186. }
  187. if (!string.IsNullOrEmpty(pagedInput.KeyWords))
  188. {
  189. object keyWords = pagedInput.KeyWords;
  190. LambdaObject obj = new LambdaObject()
  191. {
  192. FieldType = (LambdaFieldType)pagedInput.FieldType,
  193. FieldName = pagedInput.KeyField,
  194. FieldValue = keyWords,
  195. ExpType = (LambdaExpType)pagedInput.ExpType
  196. };
  197. var exp = obj.GetExp<SceneFlowInfo>();
  198. query = exp != null ? query.Where(exp) : query;
  199. }
  200. if (pagedInput.SearchList != null && pagedInput.SearchList.Count > 0)
  201. {
  202. List<LambdaObject> objList = new List<LambdaObject>();
  203. foreach (var o in pagedInput.SearchList)
  204. {
  205. if (string.IsNullOrEmpty(o.KeyWords))
  206. continue;
  207. if (o.KeyField.ToLower() == "sceneCategory".ToLower())
  208. {
  209. query = query.Where(a => a.SceneCategoryInfo.CategoryPath.Contains(o.KeyWords));
  210. continue;
  211. }
  212. object keyWords = o.KeyWords;
  213. objList.Add(new LambdaObject
  214. {
  215. FieldType = (LambdaFieldType)o.FieldType,
  216. FieldName = o.KeyField,
  217. FieldValue = keyWords,
  218. ExpType = (LambdaExpType)o.ExpType
  219. });
  220. }
  221. var exp = objList.GetExp<SceneFlowInfo>();
  222. query = exp != null ? query.Where(exp) : query;
  223. }
  224. return query;
  225. }
  226. //protected override IQueryable<SceneFlowInfo> ApplySorting(IQueryable<SceneFlowInfo> query, IwbPagedRequestDto input)
  227. //{
  228. // return query.OrderBy(a => a.No);
  229. //}
  230. //protected override IQueryable<SceneFlowInfo> ApplyPaging(IQueryable<SceneFlowInfo> query, IwbPagedRequestDto input)
  231. //{
  232. // if (input is IPagedResultRequest pagedInput)
  233. // {
  234. // return query.Skip(pagedInput.SkipCount).Take(pagedInput.MaxResultCount);
  235. // }
  236. // return query;
  237. //}
  238. #endregion
  239. #endregion
  240. /// <summary>
  241. /// 拷贝情景流
  242. /// </summary>
  243. /// <param name="input"></param>
  244. /// <returns></returns>
  245. [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgCopy), AuditLog("拷贝情景流")]
  246. public async Task Copy(EntityDto<string> input)
  247. {
  248. var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
  249. if (entity == null)
  250. {
  251. CheckErrors($"没有查询到编号为{input.Id}的情景流!");
  252. }
  253. var dto = MapToEntityDto(entity);
  254. var newEntity = ObjectMapper.Map<SceneFlowInfo>(dto);
  255. newEntity.Id = await AppGuidManager.GetNextRecordIdAsync(DataLibType.SceneFlowInfo);
  256. newEntity.FlowName = $"{newEntity.FlowName}_副本";
  257. newEntity.SceneFlowState = SceneFlowStateDefinition.New;
  258. await Repository.InsertAsync(newEntity);
  259. }
  260. /// <summary>
  261. /// 固化情景流
  262. /// </summary>
  263. /// <param name="input"></param>
  264. /// <returns></returns>
  265. //[AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgSolidify), AuditLog("固化情景流")]
  266. public async Task Solidify(SolidifyDto input)
  267. {
  268. var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
  269. if (entity == null)
  270. {
  271. CheckErrors($"没有查询到编号为{input.Id}的情景流!");
  272. return;
  273. }
  274. if (entity.SceneFlowState == SceneFlowStateDefinition.Solidified)
  275. {
  276. CheckErrors($"情景流已固化确认,请勿重复操作!");
  277. return;
  278. }
  279. entity.FlowName = input.NewName.IsEmpty() ? entity.FlowName : input.NewName;
  280. entity.SceneFlowState = SceneFlowStateDefinition.Solidified;
  281. await Repository.UpdateAsync(entity);
  282. }
  283. }
  284. }