| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- using Abp.Application.Services.Dto;
- using Abp.Auditing;
- using Abp.Authorization;
- using Abp.Domain.Repositories;
- using Abp.Runtime.Caching;
- using IwbZero.AppServiceBase;
- using IwbZero.Auditing;
- using System.Data.Entity;
- using System.Linq;
- using System.Threading.Tasks;
- using WeApp.Authorization;
- using WeApp.BasicInfo.PhoneQuestion.Dto;
- using WeApp.Configuration;
- namespace WeApp.BasicInfo.PhoneQuestion
- {
- [AbpAuthorize, AuditLog("电话提问维护")]
- public class PhoneQuestionAppService : IwbAsyncCrudAppService<PhoneQuestionInfo, PhoneQuestionDto, string, IwbPagedRequestDto, PhoneQuestionCreateDto, PhoneQuestionUpdateDto>, IPhoneQuestionAppService
- {
- public PhoneQuestionAppService(
- ICacheManager cacheManager,
- IRepository<PhoneQuestionInfo, string> repository, IRepository<PhoneAnswerInfo> answerRepository) : base(repository, "Id")
- {
- AnswerRepository = answerRepository;
- CacheManager = cacheManager;
- }
- public IRepository<PhoneAnswerInfo> AnswerRepository { get; }
- protected override bool KeyIsAuto { get; set; } = false;
- #region CURD
- [AbpAuthorize(PermissionNames.PagesBasicMgPhoneQuestionMgCreate)]
- public override async Task Create(PhoneQuestionCreateDto input)
- {
- input.Id = await AppGuidManager.GetNextRecordIdAsync(DataLibType.PhoneQuestion);
- input.Type = PhoneQuestionTypeDefinition.Default;
- if (input.Answers.Any())
- {
- foreach (var answerDto in input.Answers)
- {
- var answer = new PhoneAnswerInfo()
- {
- Content = answerDto.Content,
- Keywords = answerDto.Keywords,
- Type = answerDto.Type,
- QuestionNo = input.Id
- };
- await AnswerRepository.InsertAsync(answer);
- }
- }
- await CreateEntity(input);
- }
- [AbpAuthorize(PermissionNames.PagesBasicMgPhoneQuestionMgUpdate)]
- public override async Task Update(PhoneQuestionUpdateDto input)
- {
- var dto = await UpdateEntity(input);
- if (dto != null && input.Answers.Any())
- {
- var answerOld = await AnswerRepository.GetAll().Where(a => a.QuestionNo == dto.Id).Select(a => a.Id)
- .ToListAsync();
- foreach (var answerDto in input.Answers)
- {
- if (answerDto.Id == null || answerDto.Id == 0)
- {
- var answer = new PhoneAnswerInfo()
- {
- Content = answerDto.Content,
- Keywords = answerDto.Keywords,
- Type = answerDto.Type,
- QuestionNo = dto.Id
- };
- await AnswerRepository.InsertAsync(answer);
- }
- else
- {
- var answer = await AnswerRepository.FirstOrDefaultAsync(a => a.Id == answerDto.Id);
- if (answer != null)
- {
- answerOld.Remove(answer.Id);
- answer.Keywords = answerDto.Keywords;
- answer.Content = answerDto.Content;
- answer.Type = answerDto.Type;
- answer.QuestionNo = dto.Id;
- }
- await AnswerRepository.UpdateAsync(answer);
- }
- }
- if (answerOld.Any())
- {
- await AnswerRepository.DeleteAsync(a => answerOld.Contains(a.Id));
- }
- }
- }
- [AbpAuthorize(PermissionNames.PagesBasicMgPhoneQuestionMgDelete)]
- public override Task Delete(EntityDto<string> input)
- {
- return DeleteEntity(input);
- }
- [DisableAuditing]
- public override async Task<PagedResultDto<PhoneQuestionDto>> 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<PhoneQuestionDto>(totalCount, entities.Select(MapToEntityDto).ToList());
- return dtoList;
- }
- #region GetEntity/Dto
- /// <summary>
- /// 查询实体Dto
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [DisableAuditing]
- public override async Task<PhoneQuestionDto> GetDto(EntityDto<string> input)
- {
- var entity = await GetEntity(input);
- return MapToEntityDto(entity);
- }
- /// <summary>
- /// 查询实体Dto
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [DisableAuditing]
- public override async Task<PhoneQuestionDto> GetDtoById(string id)
- {
- var entity = await GetEntityById(id);
- return MapToEntityDto(entity);
- }
- /// <summary>
- /// 查询实体Dto(需指明自定义字段)
- /// </summary>
- /// <param name="no"></param>
- /// <returns></returns>
- [DisableAuditing]
- public override async Task<PhoneQuestionDto> GetDtoByNo(string no)
- {
- var entity = await GetEntityByNo(no);
- return MapToEntityDto(entity);
- }
- /// <summary>
- /// 查询实体
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [DisableAuditing]
- public override async Task<PhoneQuestionInfo> GetEntity(EntityDto<string> input)
- {
- var entity = await GetEntityById(input.Id);
- return entity;
- }
- /// <summary>
- /// 查询实体
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [DisableAuditing]
- public override async Task<PhoneQuestionInfo> GetEntityById(string id)
- {
- return await Repository.FirstOrDefaultAsync(a => a.Id == id);
- }
- /// <summary>
- /// 查询实体(需指明自定义字段)
- /// </summary>
- /// <param name="no"></param>
- /// <returns></returns>
- [DisableAuditing]
- public override async Task<PhoneQuestionInfo> GetEntityByNo(string no)
- {
- //CheckGetPermission();
- if (string.IsNullOrEmpty(KeyFiledName))
- {
- ThrowError("NoKeyFieldName");
- }
- return await base.GetEntityByNo(no);
- }
- #endregion GetEntity/Dto
- #region Hide
- ///// <summary>
- ///// 根据给定的<see cref="IwbPagedRequestDto"/>创建 <see cref="IQueryable{PhoneQuestionInfo}"/>过滤查询.
- ///// </summary>
- ///// <param name="input">The input.</param>
- //protected override IQueryable<PhoneQuestionInfo> CreateFilteredQuery(IwbPagedRequestDto input)
- //{
- // var query = Repository.GetAll();
- // 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<PhoneQuestionInfo>();
- // 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;
- // 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<PhoneQuestionInfo>();
- // query = exp != null ? query.Where(exp) : query;
- // }
- // return query;
- //}
- //protected override IQueryable<PhoneQuestionInfo> ApplySorting(IQueryable<PhoneQuestionInfo> query, IwbPagedRequestDto input)
- //{
- // return query.OrderBy(a => a.No);
- //}
- //protected override IQueryable<PhoneQuestionInfo> ApplyPaging(IQueryable<PhoneQuestionInfo> query, IwbPagedRequestDto input)
- //{
- // if (input is IPagedResultRequest pagedInput)
- // {
- // return query.Skip(pagedInput.SkipCount).Take(pagedInput.MaxResultCount);
- // }
- // return query;
- //}
- #endregion Hide
- #endregion CURD
- }
- }
|