You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							248 lines
						
					
					
						
							10 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							248 lines
						
					
					
						
							10 KiB
						
					
					
				
								using Microsoft.AspNetCore.Authorization;
							 | 
						|
								using Microsoft.AspNetCore.Mvc;
							 | 
						|
								using Microsoft.EntityFrameworkCore;
							 | 
						|
								using Shentun.Peis.Models;
							 | 
						|
								using Shentun.Peis.PeisReports;
							 | 
						|
								using Shentun.Peis.ReportFormats;
							 | 
						|
								using System;
							 | 
						|
								using System.Collections.Generic;
							 | 
						|
								using System.Linq;
							 | 
						|
								using System.Text;
							 | 
						|
								using System.Threading.Tasks;
							 | 
						|
								using Volo.Abp.Application.Dtos;
							 | 
						|
								using Volo.Abp.Application.Services;
							 | 
						|
								using Volo.Abp.Domain.Repositories;
							 | 
						|
								using Volo.Abp.Identity;
							 | 
						|
								using Volo.Abp.ObjectMapping;
							 | 
						|
								using static Org.BouncyCastle.Bcpg.Attr.ImageAttrib;
							 | 
						|
								
							 | 
						|
								namespace Shentun.Peis.ReportFormatTemplates
							 | 
						|
								{
							 | 
						|
								    //[Authorize]
							 | 
						|
								    public class ReportFormatTemplateAppService : CrudAppService<
							 | 
						|
								            ReportFormatTemplate, //The Book entity
							 | 
						|
								            ReportFormatTemplateDto, //Used to show books
							 | 
						|
								            string, //Primary key of the book entity
							 | 
						|
								            PagedAndSortedResultRequestDto, //Used for paging/sorting
							 | 
						|
								            CreateReportFormatTemplateDto,
							 | 
						|
								            UpdateReportFormatTemplateDto>
							 | 
						|
								    {
							 | 
						|
								        private readonly IRepository<IdentityUser, Guid> _userRepository;
							 | 
						|
								        private readonly IRepository<Report, string> _reportRepository;
							 | 
						|
								        private readonly IRepository<ReportFormat, string> _reportFormatRepository;
							 | 
						|
								        private readonly IRepository<ReportFormatTemplate, string> _reportFormatTemplateRepository;
							 | 
						|
								        private readonly ReportFormatTemplateManager _manager;
							 | 
						|
								        public ReportFormatTemplateAppService(
							 | 
						|
								            IRepository<ReportFormatTemplate, string> repository,
							 | 
						|
								            IRepository<IdentityUser, Guid> userRepository,
							 | 
						|
								            IRepository<Report, string> reportRepository,
							 | 
						|
								            IRepository<ReportFormat, string> reportFormatRepository,
							 | 
						|
								        ReportFormatTemplateManager manager)
							 | 
						|
								            : base(repository)
							 | 
						|
								        {
							 | 
						|
								            _userRepository = userRepository;
							 | 
						|
								            _manager = manager;
							 | 
						|
								            _reportFormatTemplateRepository = repository;
							 | 
						|
								            _reportFormatRepository = reportFormatRepository;
							 | 
						|
								            _reportRepository = reportRepository;
							 | 
						|
								        }
							 | 
						|
								        public async Task<List<ReportFormatTemplateDto>> GetReportTemplateAsync()
							 | 
						|
								        {
							 | 
						|
								            var query = from a in await _reportFormatRepository.GetQueryableAsync()
							 | 
						|
								                        join b in await _reportRepository.GetQueryableAsync() on a.ReportId equals b.Id into bb
							 | 
						|
								                        from ab in bb.DefaultIfEmpty()
							 | 
						|
								                        join c in await _reportFormatTemplateRepository.GetQueryableAsync() on a.Id equals c.ReportFormatId into cc
							 | 
						|
								                        from ac in cc.DefaultIfEmpty()
							 | 
						|
								                        where (a.IsDefault=='Y' &&ab.IsActive=='Y'&&ac.IsDefault== 'Y')
							 | 
						|
								                        select new
							 | 
						|
								                        {
							 | 
						|
								                            a,
							 | 
						|
								                            ab,
							 | 
						|
								                            ac
							 | 
						|
								                        };
							 | 
						|
								            //query = query.Where(p=>p.a.IsDefault.Equals("Y") && p.ab.IsActive.Equals("Y") && p.ac.IsDefault.Equals("Y"));
							 | 
						|
								
							 | 
						|
								            //var ss = query.ToQueryString();
							 | 
						|
								
							 | 
						|
								            var entlist = query.Select(s => new ReportFormatTemplateDto
							 | 
						|
								            {
							 | 
						|
								                Id = s.ab.Id,
							 | 
						|
								                ReportFormatId = s.ac.ReportFormatId,
							 | 
						|
								                DisplayName = s.ac.DisplayName,
							 | 
						|
								                TemplateFileType = s.ac.TemplateFileType,
							 | 
						|
								                TemplateFile = s.ac.TemplateFile,
							 | 
						|
								                DataSetJson = s.ac.DataSetJson,
							 | 
						|
								                IsSystem = s.ac.IsSystem,
							 | 
						|
								                IsDefault = s.ac.IsDefault,
							 | 
						|
								                LastModificationTime = s.ac.LastModificationTime,
							 | 
						|
								            }).ToList();
							 | 
						|
								            return entlist;
							 | 
						|
								        }
							 | 
						|
								        /// <summary>
							 | 
						|
								        /// 获取通过主键
							 | 
						|
								        /// </summary>
							 | 
						|
								        /// <param name="id"></param>
							 | 
						|
								        /// <returns></returns>
							 | 
						|
								        public override async Task<ReportFormatTemplateDto> GetAsync(string id)
							 | 
						|
								        {
							 | 
						|
								            var entity= await base.GetAsync(id);
							 | 
						|
								            var userList = await _userRepository.GetListAsync();
							 | 
						|
								            entity.IsDefaulted = entity.IsDefault.Equals('Y');
							 | 
						|
								            entity.IsSystemed = entity.IsSystem.Equals('Y');
							 | 
						|
								            entity.CreatorName = EntityHelper.GetUserNameNoSql(userList, entity.CreatorId);
							 | 
						|
								            entity.LastModifierName = EntityHelper.GetUserNameNoSql(userList, entity.LastModifierId);
							 | 
						|
								            return entity;
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        public async Task<ReportFormatTemplateDto> GetMaxByIdAsync()
							 | 
						|
								        {
							 | 
						|
								            var ent = (await Repository.GetListAsync()).Max(x => x.Id);
							 | 
						|
								            var entdto = new ReportFormatTemplateDto
							 | 
						|
								            {
							 | 
						|
								                Id = !string.IsNullOrEmpty(ent)?ent:"0001"
							 | 
						|
								            };
							 | 
						|
								            return entdto;
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        public async Task<ReportFormatTemplateDto> GetDefaultAsync(string formatId)
							 | 
						|
								        {
							 | 
						|
								            var ent = await _manager.GetDefaultAsync(formatId);
							 | 
						|
								
							 | 
						|
								            if (ent != null)
							 | 
						|
								            {
							 | 
						|
								                var userList = await _userRepository.GetListAsync();
							 | 
						|
								
							 | 
						|
								                var entdto = new ReportFormatTemplateDto
							 | 
						|
								                {
							 | 
						|
								                    CreationTime = ent.CreationTime,
							 | 
						|
								                    CreatorId = ent.CreatorId,
							 | 
						|
								                    DisplayName = ent.DisplayName,
							 | 
						|
								                    Id = ent.Id,
							 | 
						|
								                    ReportFormatId = ent.ReportFormatId,
							 | 
						|
								                    LastModificationTime = ent.LastModificationTime,
							 | 
						|
								                    LastModifierId = ent.LastModifierId,
							 | 
						|
								                    IsDefault = ent.IsDefault,
							 | 
						|
								                    IsSystem = ent.IsSystem,
							 | 
						|
								                    IsDefaulted = ent.IsDefault.Equals('Y'),
							 | 
						|
								                    IsSystemed = ent.IsSystem.Equals('Y'),
							 | 
						|
								                    TemplateFile=ent.TemplateFile,
							 | 
						|
								                    TemplateFileType=ent.TemplateFileType,
							 | 
						|
								                    DataSetJson = ent.DataSetJson,
							 | 
						|
								                    CreatorName = EntityHelper.GetUserNameNoSql(userList, ent.CreatorId),
							 | 
						|
								                    LastModifierName = EntityHelper.GetUserNameNoSql(userList, ent.LastModifierId)
							 | 
						|
								                };
							 | 
						|
								
							 | 
						|
								                return entdto;
							 | 
						|
								            }
							 | 
						|
								            else
							 | 
						|
								            {
							 | 
						|
								                return null;
							 | 
						|
								            }
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        /// <summary>
							 | 
						|
								        /// 获取列表  项目
							 | 
						|
								        /// </summary>
							 | 
						|
								        /// <param name="input"></param>
							 | 
						|
								        /// <returns></returns>
							 | 
						|
								        public override async Task<PagedResultDto<ReportFormatTemplateDto>> GetListAsync(PagedAndSortedResultRequestDto input)
							 | 
						|
								        {
							 | 
						|
								            return await base.GetListAsync(input);
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        /// <summary>
							 | 
						|
								        /// 获取列表  项目 可以带格式ID搜索
							 | 
						|
								        /// </summary>
							 | 
						|
								        /// <param name="reportFormatId"></param>
							 | 
						|
								        /// <returns></returns>
							 | 
						|
								        public async Task<PagedResultDto<ReportFormatTemplateDto>> GetListInReportFormatAsync(string reportFormatId)
							 | 
						|
								        {
							 | 
						|
								            int totalCount = 0;
							 | 
						|
								            var entlist = (await Repository.GetListAsync()).Where(m => m.ReportFormatId == reportFormatId);
							 | 
						|
								          
							 | 
						|
								            totalCount = entlist.Count();
							 | 
						|
								            var userList = await _userRepository.GetListAsync();
							 | 
						|
								            var entdto = entlist.Select(s => new ReportFormatTemplateDto
							 | 
						|
								            {
							 | 
						|
								                CreationTime = s.CreationTime,
							 | 
						|
								                CreatorId = s.CreatorId,
							 | 
						|
								                DisplayName = s.DisplayName,
							 | 
						|
								                Id = s.Id,
							 | 
						|
								                ReportFormatId = s.ReportFormatId,
							 | 
						|
								                LastModificationTime = s.LastModificationTime,
							 | 
						|
								                LastModifierId = s.LastModifierId,
							 | 
						|
								                IsDefault = s.IsDefault,
							 | 
						|
								                IsSystem=s.IsSystem,
							 | 
						|
								                IsDefaulted=s.IsDefault.Equals('Y'),
							 | 
						|
								                IsSystemed=s.IsSystem.Equals('Y'),
							 | 
						|
								                TemplateFile = s.TemplateFile,
							 | 
						|
								                TemplateFileType = s.TemplateFileType,
							 | 
						|
								                DataSetJson = s.DataSetJson,
							 | 
						|
								                CreatorName = EntityHelper.GetUserNameNoSql(userList, s.CreatorId),
							 | 
						|
								                LastModifierName = EntityHelper.GetUserNameNoSql(userList, s.LastModifierId)
							 | 
						|
								            }).ToList();
							 | 
						|
								
							 | 
						|
								            return new PagedResultDto<ReportFormatTemplateDto>(totalCount, entdto);
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        /// <summary>
							 | 
						|
								        /// 创建
							 | 
						|
								        /// </summary>
							 | 
						|
								        /// <param name="input"></param>
							 | 
						|
								        /// <returns></returns>
							 | 
						|
								        public override async Task<ReportFormatTemplateDto> CreateAsync(CreateReportFormatTemplateDto input)
							 | 
						|
								        {
							 | 
						|
								            var createEntity = ObjectMapper.Map<CreateReportFormatTemplateDto, ReportFormatTemplate>(input);
							 | 
						|
								            var entity = await _manager.CreateAsync(createEntity);
							 | 
						|
								            entity = await Repository.InsertAsync(entity);
							 | 
						|
								            var dto = ObjectMapper.Map<ReportFormatTemplate, ReportFormatTemplateDto>(entity);
							 | 
						|
								            return dto;
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        public async Task<ReportFormatTemplateDto> CopyCreateAsync(string id,string newId)
							 | 
						|
								        {
							 | 
						|
								            var entity = await _manager.CopyCreateAsync(id,newId);
							 | 
						|
								            entity = await Repository.InsertAsync(entity);
							 | 
						|
								            var dto = ObjectMapper.Map<ReportFormatTemplate, ReportFormatTemplateDto>(entity);
							 | 
						|
								            return dto;
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        /// <summary>
							 | 
						|
								        /// 更新
							 | 
						|
								        /// </summary>
							 | 
						|
								        /// <param name="id"></param>
							 | 
						|
								        /// <param name="input"></param>
							 | 
						|
								        /// <returns></returns>
							 | 
						|
								        public override async Task<ReportFormatTemplateDto> UpdateAsync(string id, UpdateReportFormatTemplateDto input)
							 | 
						|
								        {
							 | 
						|
								            var entity = await Repository.GetAsync(id);
							 | 
						|
								            var userList = await _userRepository.GetListAsync();
							 | 
						|
								            var sourceEntity = ObjectMapper.Map<UpdateReportFormatTemplateDto, ReportFormatTemplate>(input);
							 | 
						|
								            await _manager.UpdateAsync(sourceEntity, entity);
							 | 
						|
								            entity = await Repository.UpdateAsync(entity);
							 | 
						|
								            var  dto= ObjectMapper.Map<ReportFormatTemplate, ReportFormatTemplateDto>(entity);
							 | 
						|
								            dto.IsDefaulted = entity.IsDefault.Equals('Y');
							 | 
						|
								            dto.IsSystemed= entity.IsSystem.Equals('Y');
							 | 
						|
								            dto.CreatorName = EntityHelper.GetUserNameNoSql(userList, entity.CreatorId);
							 | 
						|
								            dto.LastModifierName = EntityHelper.GetUserNameNoSql(userList, entity.LastModifierId);
							 | 
						|
								            return dto;
							 | 
						|
								        }
							 | 
						|
								        /// <summary>
							 | 
						|
								        /// 删除
							 | 
						|
								        /// </summary>
							 | 
						|
								        /// <param name="id"></param>
							 | 
						|
								        /// <returns></returns>
							 | 
						|
								        public override Task DeleteAsync(string id)
							 | 
						|
								        {
							 | 
						|
								            return base.DeleteAsync(id);
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        [HttpPut("api/app/reportfomattemplate/updatedefault")]
							 | 
						|
								        public async Task UpdateDefaultAsync(string id)
							 | 
						|
								        {
							 | 
						|
								           await _manager.UpdateDefaultAsync(id);
							 | 
						|
								        }
							 | 
						|
								    }
							 | 
						|
								}
							 |