119 lines
4.0 KiB
C#
119 lines
4.0 KiB
C#
using Infrastructure;
|
|
using OpenAuth.App.BaseApp.Base;
|
|
using OpenAuth.App.Interface;
|
|
using OpenAuth.App.ServiceApp.GoView.Request;
|
|
using OpenAuth.App.ServiceApp.GoView.Response;
|
|
using OpenAuth.Repository;
|
|
using OpenAuth.Repository.Domain.GoView;
|
|
using SqlSugar;
|
|
|
|
namespace OpenAuth.App.ServiceApp.GoView;
|
|
|
|
public class GoViewProjectApp : SqlSugarBaseApp<GoviewProject, SugarDbContext>
|
|
{
|
|
public GoViewProjectApp(ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<GoviewProject> repository,
|
|
IAuth auth) : base(unitWork, repository, auth)
|
|
{
|
|
}
|
|
|
|
public async Task<AjaxResult> DeleteProject(string ids)
|
|
{
|
|
var idArray = ids.Split(",");
|
|
var flag = await Repository.DeleteByIdsAsync(idArray);
|
|
return flag ? AjaxResult.Success("删除成功") : AjaxResult.Error("删除失败");
|
|
}
|
|
|
|
public async Task<AjaxResult> UpdateProject(GoviewProject project)
|
|
{
|
|
var flag = await Repository.AsUpdateable(project).IgnoreNullColumns().ExecuteCommandAsync();
|
|
return flag > 0 ? AjaxResult.Success("修改成功") : AjaxResult.Error("修改失败");
|
|
}
|
|
|
|
public async Task<AjaxResult> Create(GoviewProject project)
|
|
{
|
|
project.State = -1;
|
|
project.CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
var userId = _auth.GetUserId();
|
|
project.CreateUserId = userId;
|
|
project.Id = Guid.NewGuid().ToString();
|
|
var flag = await Repository.InsertAsync(project);
|
|
return flag ? AjaxResult.Success("创建成功") : AjaxResult.Error("创建失败");
|
|
}
|
|
|
|
public async Task<AjaxResult> Publish(GoViewProjectRequest req)
|
|
{
|
|
var prj = new GoviewProject
|
|
{
|
|
Id = req.Id,
|
|
State = req.State
|
|
};
|
|
var flag = await Repository.AsUpdateable(prj).IgnoreNullColumns().ExecuteCommandAsync() > 0;
|
|
return flag ? AjaxResult.Success("操作成功") : AjaxResult.Error("操作失败");
|
|
}
|
|
|
|
public async Task<ResultTable> List(GoViewProjectPage page)
|
|
{
|
|
RefAsync<int> total = 0;
|
|
var list = await Repository.AsQueryable()
|
|
.ToPageListAsync(page.page, page.limit, total);
|
|
|
|
return new ResultTable()
|
|
{
|
|
Code = 200,
|
|
Msg = "获取成功",
|
|
Count = total,
|
|
Data = list
|
|
};
|
|
}
|
|
|
|
public async Task<AjaxResult> GetData(string projectId)
|
|
{
|
|
var prj = await Repository.AsQueryable().SingleAsync(a => a.Id == projectId);
|
|
if (prj == null)
|
|
{
|
|
return AjaxResult.Error("项目不存在");
|
|
}
|
|
|
|
var vo = prj.MapTo<ProjectResponse>();
|
|
var data = await Repository.ChangeRepository<SugarRepositiry<GoviewProjectData>>().AsQueryable()
|
|
.SingleAsync(a => a.ProjectId == projectId);
|
|
|
|
if (data != null)
|
|
{
|
|
vo.Content = data.Content;
|
|
}
|
|
|
|
return AjaxResult.SuccessData(200, vo);
|
|
}
|
|
|
|
public async Task<AjaxResult> SaveData(GoviewProjectData data)
|
|
{
|
|
// 更新还是保存,
|
|
var project = await Repository.AsQueryable().SingleAsync(a => a.Id == data.ProjectId);
|
|
if (project == null)
|
|
{
|
|
throw new Exception("项目不存在");
|
|
}
|
|
|
|
var prjData = await Repository
|
|
.ChangeRepository<SugarRepositiry<GoviewProjectData>>()
|
|
.AsQueryable()
|
|
.SingleAsync(a => a.ProjectId == data.ProjectId);
|
|
bool flag;
|
|
if (prjData == null)
|
|
{
|
|
data.Id = Guid.NewGuid().ToString();
|
|
flag = await Repository.ChangeRepository<SugarRepositiry<GoviewProjectData>>().InsertAsync(data);
|
|
}
|
|
else
|
|
{
|
|
flag = await Repository
|
|
.ChangeRepository<SugarRepositiry<GoviewProjectData>>()
|
|
.AsUpdateable(data)
|
|
.IgnoreNullColumns()
|
|
.ExecuteCommandAsync() > 0;
|
|
}
|
|
|
|
return flag ? AjaxResult.Success("数据保存成功") : AjaxResult.Error("数据保存失败");
|
|
}
|
|
} |