using Furion; using Furion.DependencyInjection; using Furion.DynamicApiController; using Furion.FriendlyException; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Myshipping.Core.Service; using Myshipping.Core; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using Myshipping.Application.Entity; using Myshipping.Application.Service.Fee.Dto; using Mapster; using Furion.DistributedIDGenerator; namespace Myshipping.Application.Service.TaskManagePlat { /// /// 任务API配置 /// [ApiDescriptionSettings("Application", Name = "TaskAPI", Order = 10)] public class TaskAPIService : IDynamicApiController, ITransient { private readonly SqlSugarRepository _rep; public TaskAPIService(SqlSugarRepository rep) { _rep = rep; } /// /// 分页查询任务API配置 /// /// /// [HttpPost] [ApiDescriptionSettings(Name = "Page")] public async Task> Page(TaskAPIInput input) { var query = _rep.AsQueryable() .Select(u => new TaskAPIInfo { PK_ID = u.PK_ID, APIName = u.APIName, URL = u.URL, RequestMethod = u.RequestMethod, Key = u.Key, SecretKey = u.SecretKey, SYSTEM_CODE = u.SYSTEM_CODE, SYSTEM_NAME = u.SYSTEM_NAME }); return await query.ToPagedListAsync(input.PageNo, input.PageSize); } /// /// 增加任务API配置 /// /// /// [HttpPost] [ApiDescriptionSettings(Name = "Add")] public async Task Add(AddTaskAPIInput input) { var entity = input.Adapt(); entity.PK_ID = IDGen.NextID().ToString(); await _rep.InsertAsync(entity); } /// /// 删除任务API配置 /// /// /// [HttpPost] [ApiDescriptionSettings(Name = "Delete")] public async Task Delete(DeleteTaskAPIInput input) { var entity = await _rep.FirstOrDefaultAsync(u => u.PK_ID == input.PK_ID) ?? throw Oops.Oh("数据不存在"); entity.IsDeleted = true; await _rep.UpdateAsync(entity); } /// /// 更新任务API配置 /// /// /// [HttpPost] [ApiDescriptionSettings(Name = "Update")] public async Task Update(UpdateTaskAPIInput input) { var entity = input.Adapt(); await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } /// /// 获取任务API配置详情 /// /// /// [HttpPost] [ApiDescriptionSettings(Name = "Detail")] public async Task Get(GetTaskApiInfoInput input) { return await _rep.FirstOrDefaultAsync(u => u.PK_ID == input.PK_ID); } /// /// 获取任务API配置列表 /// /// /// [HttpGet] [ApiDescriptionSettings(Name = "List")] public async Task> List([FromQuery] TaskAPIInput input) { return await _rep.AsQueryable().Select().ToListAsync(); } } }