185 lines
6.1 KiB
C#
185 lines
6.1 KiB
C#
using Infrastructure;
|
|
using Infrastructure.Cache;
|
|
using Infrastructure.CloudSdk.minio;
|
|
using Microsoft.DotNet.InternalAbstractions;
|
|
using Microsoft.Extensions.Logging;
|
|
using OpenAuth.App.BaseApp.Base;
|
|
using OpenAuth.App.BasicQueryService;
|
|
using OpenAuth.App.Interface;
|
|
using OpenAuth.Repository;
|
|
using OpenAuth.Repository.Domain;
|
|
using OpenAuth.WebApi;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace OpenAuth.App.ServiceApp
|
|
{
|
|
/// <summary>
|
|
/// 消息推送模块
|
|
/// </summary>
|
|
public class LasaPlatformPushApp : SqlSugarBaseApp<LasaPlatform, SugarDbContext>
|
|
{
|
|
public LasaPlatformPushApp(ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<LasaPlatform> repository, IAuth auth): base(unitWork, repository, auth)
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 获取推送平台
|
|
/// </summary>
|
|
/// <param name="page"></param>
|
|
/// <param name="limit"></param>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
public async Task<Response<PageInfo<List<LasaPlatform>>>> GetPlatformList(int page, int limit, string key)
|
|
{
|
|
RefAsync<int> totalCount = 0;
|
|
using (var db = UnitWork.CreateContext())
|
|
{
|
|
var list = await db.LasaPlatform.AsQueryable()
|
|
.Where((a) => a.IsDelete == false)
|
|
.WhereIF(!string.IsNullOrEmpty(key), (a) => a.PlatformName.Contains(key))
|
|
.ToPageListAsync(page, limit, totalCount);
|
|
return new Response<PageInfo<List<LasaPlatform>>>
|
|
{
|
|
Result = new PageInfo<List<LasaPlatform>> { Items = list, Total = totalCount }
|
|
};
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 添加平台信息
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns></returns>
|
|
public async Task<Response<bool>> AddPlatform(LasaPlatform info)
|
|
{
|
|
using (var db = UnitWork.CreateContext())
|
|
{
|
|
info.Id = Guid.NewGuid().ToString();
|
|
info.IsDelete = false;
|
|
await db.LasaPlatform.InsertAsync(info);
|
|
if (db.Commit())
|
|
return new Response<bool>
|
|
{
|
|
Result = true,
|
|
Message = "添加成功"
|
|
};
|
|
else
|
|
return new Response<bool>
|
|
{
|
|
Result = false,
|
|
Message = "添加失败"
|
|
};
|
|
}
|
|
}
|
|
//修改平台信息
|
|
public async Task<Response<bool>> UpdatePlatform(LasaPlatform info)
|
|
{
|
|
using (var db = UnitWork.CreateContext())
|
|
{
|
|
// 编辑
|
|
await db.LasaPlatform.UpdateAsync(u => new LasaPlatform
|
|
{
|
|
Url = info.Url,
|
|
PlatformName = info.PlatformName,
|
|
RoutingKey = info.RoutingKey,
|
|
Exchange = info.Exchange
|
|
}, u => u.Id == info.Id);
|
|
// 提交事务
|
|
if (db.Commit())
|
|
{
|
|
return new Response<bool>
|
|
{
|
|
Result = true,
|
|
Message = "修改成功"
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return new Response<bool>
|
|
{
|
|
Result = false,
|
|
Message = "修改失败"
|
|
};
|
|
}
|
|
}
|
|
}
|
|
//删除平台信息
|
|
public async Task<Response<bool>> DeletePlatform(string id)
|
|
{
|
|
using (var db = UnitWork.CreateContext())
|
|
{
|
|
await db.LasaPlatform.DeleteByIdAsync(id);
|
|
if (db.Commit())
|
|
return new Response<bool>
|
|
{
|
|
Result = true,
|
|
Message = "删除成功"
|
|
};
|
|
else
|
|
return new Response<bool>
|
|
{
|
|
Result = false,
|
|
Message = "删除失败"
|
|
};
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加ai算法任务信息
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns></returns>
|
|
public async Task<Response<bool>> AddTaskAi(LasaTaskAi info)
|
|
{
|
|
using (var db = UnitWork.CreateContext())
|
|
{
|
|
if (string.IsNullOrEmpty(info.Id))
|
|
info.Id = Guid.NewGuid().ToString();
|
|
await db.LasaTaskAi.InsertAsync(info);
|
|
if (db.Commit())
|
|
return new Response<bool>
|
|
{
|
|
Result = true,
|
|
Message = "添加成功"
|
|
};
|
|
else
|
|
return new Response<bool>
|
|
{
|
|
Result = false,
|
|
Message = "添加失败"
|
|
};
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 添加ai算法推送log
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns></returns>
|
|
public async Task<Response<bool>> AddTaskAi(LasaTaskAiLog info)
|
|
{
|
|
using (var db = UnitWork.CreateContext())
|
|
{
|
|
if (string.IsNullOrEmpty(info.Id))
|
|
info.Id = Guid.NewGuid().ToString();
|
|
await db.LasaTaskAiLog.InsertAsync(info);
|
|
if (db.Commit())
|
|
return new Response<bool>
|
|
{
|
|
Result = true,
|
|
Message = "添加成功"
|
|
};
|
|
else
|
|
return new Response<bool>
|
|
{
|
|
Result = false,
|
|
Message = "添加失败"
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|