| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Web.Mvc;
- using Abp.Application.Services.Dto;
- using Abp.Auditing;
- using Abp.Authorization;
- using Abp.Domain.Repositories;
- using Abp.Runtime.Caching;
- using IwbZero.Auditing;
- using IwbZero.AppServiceBase;
- using IwbZero.ToolCommon.Lambda;
- using IwbZero.ToolCommon.StringModel;
- using WePlatform.Authorization;
- using WePlatform.Configuration;
- using WePlatform.WeLib.Package.Dto;
- using WePlatform.WeLib.SceneFlow.Dto;
- namespace WePlatform.WeLib.SceneFlow
- {
- [AbpAuthorize, AuditLog("情景流")]
- public class SceneFlowAppService : IwbAsyncCrudAppService<SceneFlowInfo, SceneFlowDto, string, IwbPagedRequestDto, SceneFlowCreateDto, SceneFlowUpdateDto >, ISceneFlowAppService
- {
- public SceneFlowAppService(
- ICacheManager cacheManager,
- IRepository<SceneFlowInfo, string> repository) : base(repository, "Id")
- {
- CacheManager = cacheManager;
- }
- protected override bool KeyIsAuto { get; set; } = false;
- #region GetSelect
- [DisableAuditing]
- public override async Task<List<SelectListItem>> GetSelectList()
- {
- var list = await Repository.GetAllListAsync();
- var sList = new List<SelectListItem> {new SelectListItem {Text = @"请选择...", Value = "", Selected = true}};
- foreach (var l in list)
- {
- sList.Add(new SelectListItem { Value = l.Id, Text = l.FlowName });
- }
- return sList;
- }
- [DisableAuditing]
- public override async Task<string> GetSelectStr()
- {
- var list = await Repository.GetAllListAsync();
- string str = "<option value=\"\" selected>请选择...</option>";
- foreach (var l in list)
- {
- str += $"<option value=\"{l.Id}\">{l.FlowName}</option>";
- }
- return str;
- }
- #endregion
- #region CURD
- [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgCreate)]
- public override async Task Create(SceneFlowCreateDto input)
- {
- input.Id= await AppGuidManager.GetNextRecordIdAsync(DataLibType.SceneFlowInfo);
- input.SceneFlowState = SceneFlowStateDefinition.New;
- await CreateEntity(input);
- }
- [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgUpdate)]
- public override async Task Update(SceneFlowUpdateDto input)
- {
- var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
- if (entity?.SceneFlowState == SceneFlowStateDefinition.Solidified)
- {
- CheckErrors($"情景流已固化确认,不能再操作!");
- return;
- }
- await UpdateEntity(input);
- }
- [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgDelete)]
- public override async Task Delete(EntityDto<string> input)
- {
- var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
- if (entity?.SceneFlowState == SceneFlowStateDefinition.Solidified)
- {
- CheckErrors($"情景流已固化确认,不能再操作!");
- return;
- }
- await base.Delete(input);
- }
-
- [DisableAuditing]
- [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgQuery)]
- public override async Task<PagedResultDto<SceneFlowDto>> GetAll(IwbPagedRequestDto input)
- {
- var query = CreateFilteredQuery(input);
- //query = ApplyFilter(query, input);
- var totalCount = await AsyncQueryableExecuter.CountAsync(query);
- query = ApplySorting(query, input);
- query = ApplyPaging(query, input);
- var entities = await AsyncQueryableExecuter.ToListAsync(query);
- var dtoList = new PagedResultDto<SceneFlowDto>(totalCount, entities.Select(MapToEntityDto).ToList());
- return dtoList;
- }
- #region GetEntity/Dto
- /// <summary>
- /// 查询实体Dto
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [DisableAuditing]
- [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgQuery)]
- public override async Task<SceneFlowDto> GetDto(EntityDto<string> input)
- {
- var entity = await GetEntity(input);
- return MapToEntityDto(entity);
- }
- /// <summary>
- /// 查询实体Dto
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [DisableAuditing]
- [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgQuery)]
- public override async Task<SceneFlowDto> GetDtoById(string id)
- {
- var entity = await GetEntityById(id);
- return MapToEntityDto(entity);
- }
- /// <summary>
- /// 查询实体Dto(需指明自定义字段)
- /// </summary>
- /// <param name="no"></param>
- /// <returns></returns>
- [DisableAuditing]
- [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgQuery)]
- public override async Task<SceneFlowDto> GetDtoByNo(string no)
- {
- var entity = await GetEntityByNo(no);
- return MapToEntityDto(entity);
- }
- /// <summary>
- /// 查询实体
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [DisableAuditing]
- [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgQuery)]
- public override async Task<SceneFlowInfo> GetEntity(EntityDto<string> input)
- {
- var entity = await GetEntityById(input.Id);
- return entity;
- }
- /// <summary>
- /// 查询实体
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [DisableAuditing]
- [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgQuery)]
- public override async Task<SceneFlowInfo> GetEntityById(string id)
- {
- return await Repository.FirstOrDefaultAsync(a=>a.Id==id);
- }
- /// <summary>
- /// 查询实体(需指明自定义字段)
- /// </summary>
- /// <param name="no"></param>
- /// <returns></returns>
- [DisableAuditing]
- [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgQuery)]
- public override async Task<SceneFlowInfo> GetEntityByNo(string no)
- {
- //CheckGetPermission();
- if (string.IsNullOrEmpty(KeyFiledName))
- {
- ThrowError("NoKeyFieldName");
- }
- return await base.GetEntityByNo(no);
- }
- #endregion
- #region Hide
- /// <summary>
- /// 根据给定的<see cref="IwbPagedRequestDto"/>创建 <see cref="IQueryable{SceneFlowInfo}"/>过滤查询.
- /// </summary>
- /// <param name="input">The input.</param>
- protected override IQueryable<SceneFlowInfo> CreateFilteredQuery(IwbPagedRequestDto input)
- {
- var query = Repository.GetAllIncluding(a => a.SceneCategoryInfo);
- var pagedInput = input as IIwbPagedRequest;
- if (pagedInput == null)
- {
- return query;
- }
- if (!string.IsNullOrEmpty(pagedInput.KeyWords))
- {
- object keyWords = pagedInput.KeyWords;
- LambdaObject obj = new LambdaObject()
- {
- FieldType = (LambdaFieldType)pagedInput.FieldType,
- FieldName = pagedInput.KeyField,
- FieldValue = keyWords,
- ExpType = (LambdaExpType)pagedInput.ExpType
- };
- var exp = obj.GetExp<SceneFlowInfo>();
- query = exp != null ? query.Where(exp) : query;
- }
- if (pagedInput.SearchList != null && pagedInput.SearchList.Count > 0)
- {
- List<LambdaObject> objList = new List<LambdaObject>();
- foreach (var o in pagedInput.SearchList)
- {
- if (string.IsNullOrEmpty(o.KeyWords))
- continue;
- if (o.KeyField.ToLower() == "sceneCategory".ToLower())
- {
- query = query.Where(a => a.SceneCategoryInfo.CategoryPath.Contains(o.KeyWords));
- 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<SceneFlowInfo>();
- query = exp != null ? query.Where(exp) : query;
- }
- return query;
- }
- //protected override IQueryable<SceneFlowInfo> ApplySorting(IQueryable<SceneFlowInfo> query, IwbPagedRequestDto input)
- //{
- // return query.OrderBy(a => a.No);
- //}
- //protected override IQueryable<SceneFlowInfo> ApplyPaging(IQueryable<SceneFlowInfo> query, IwbPagedRequestDto input)
- //{
- // if (input is IPagedResultRequest pagedInput)
- // {
- // return query.Skip(pagedInput.SkipCount).Take(pagedInput.MaxResultCount);
- // }
- // return query;
- //}
- #endregion
- #endregion
- /// <summary>
- /// 拷贝情景流
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgCopy), AuditLog("拷贝情景流")]
- public async Task Copy(EntityDto<string> input)
- {
- var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
- if (entity == null)
- {
- CheckErrors($"没有查询到编号为{input.Id}的情景流!");
- }
- var dto = MapToEntityDto(entity);
- var newEntity = ObjectMapper.Map<SceneFlowInfo>(dto);
- newEntity.Id = await AppGuidManager.GetNextRecordIdAsync(DataLibType.SceneFlowInfo);
- newEntity.FlowName = $"{newEntity.FlowName}_副本";
- newEntity.SceneFlowState = SceneFlowStateDefinition.New;
- await Repository.InsertAsync(newEntity);
- }
- /// <summary>
- /// 固化情景流
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- //[AbpAuthorize(PermissionNames.PagesWePlayerMgFlowMgSolidify), AuditLog("固化情景流")]
- public async Task Solidify(SolidifyDto input)
- {
- var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
- if (entity == null)
- {
- CheckErrors($"没有查询到编号为{input.Id}的情景流!");
- return;
- }
- if (entity.SceneFlowState == SceneFlowStateDefinition.Solidified)
- {
- CheckErrors($"情景流已固化确认,请勿重复操作!");
- return;
- }
- entity.FlowName = input.NewName.IsEmpty() ? entity.FlowName : input.NewName;
- entity.SceneFlowState = SceneFlowStateDefinition.Solidified;
- await Repository.UpdateAsync(entity);
- }
- }
- }
|