using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using AutoMapper; using GxPress.Common.Tools; using GxPress.Entity; using GxPress.Repository.Interface.AppReport; using GxPress.Request.App.AppReport; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace GxPress.Api.AdminControllers { /// /// App数据报表 /// [Route("api/admin/app-report")] [ApiController] [Authorize] public class AdminAppReportController : ControllerBase { private readonly IAppReportRepository _appReportRepository; private readonly IMapper _mapper; public AdminAppReportController(IAppReportRepository appReportRepository,IMapper mapper) { _appReportRepository = appReportRepository; _mapper = mapper; } /// /// 添加 /// /// /// [HttpPut("add")] public async Task Insert(AppReportRequest request) { request.IocUrl = StringUtils.RemoveDomain(request.IocUrl); var appReport = _mapper.Map(request); return await _appReportRepository.InsertAsync(appReport); } /// /// 修改 /// /// /// [HttpPost("update")] public async Task Update(AppReportRequest request) { request.IocUrl = StringUtils.RemoveDomain(request.IocUrl); var appReport = _mapper.Map(request); return await _appReportRepository.UpdateAsync(appReport); } /// /// 查询 /// /// [HttpPost("list")] public async Task> GetAppReportList() { var result= await _appReportRepository.GetAppReportListAsync(); var appReportList = result as AppReport[] ?? result.ToArray(); foreach (var appReport in appReportList) { appReport.IocUrl = StringUtils.AddDomain(appReport.IocUrl); } return appReportList; } /// /// 删除 /// /// /// [HttpDelete("{id}")] public async Task Delete(int id) { return await _appReportRepository.DeleteAsyncTask(id); } /// /// 根据type查询数据 /// /// /// [HttpGet("{reportType}")] public async Task GetAppReport(int reportType) { var appReport = await _appReportRepository.GetAppReport(reportType); appReport.IocUrl = StringUtils.AddDomain(appReport.IocUrl); return appReport; } } }