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
{
///
/// 消息推送模块
///
public class LasaPlatformPushApp : SqlSugarBaseApp
{
public LasaPlatformPushApp(ISugarUnitOfWork unitWork, ISimpleClient repository, IAuth auth): base(unitWork, repository, auth)
{
}
///
/// 获取推送平台
///
///
///
///
///
public async Task>>> GetPlatformList(int page, int limit, string key)
{
RefAsync 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>>
{
Result = new PageInfo> { Items = list, Total = totalCount }
};
}
}
///
/// 添加平台信息
///
///
///
public async Task> 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
{
Result = true,
Message = "添加成功"
};
else
return new Response
{
Result = false,
Message = "添加失败"
};
}
}
//修改平台信息
public async Task> 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
{
Result = true,
Message = "修改成功"
};
}
else
{
return new Response
{
Result = false,
Message = "修改失败"
};
}
}
}
//删除平台信息
public async Task> DeletePlatform(string id)
{
using (var db = UnitWork.CreateContext())
{
await db.LasaPlatform.DeleteByIdAsync(id);
if (db.Commit())
return new Response
{
Result = true,
Message = "删除成功"
};
else
return new Response
{
Result = false,
Message = "删除失败"
};
}
}
///
/// 添加ai算法任务信息
///
///
///
public async Task> 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
{
Result = true,
Message = "添加成功"
};
else
return new Response
{
Result = false,
Message = "添加失败"
};
}
}
///
/// 添加ai算法推送log
///
///
///
public async Task> 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
{
Result = true,
Message = "添加成功"
};
else
return new Response
{
Result = false,
Message = "添加失败"
};
}
}
}
}