155 lines
4.8 KiB
C#
155 lines
4.8 KiB
C#
|
|
using Infrastructure;
|
|
using OpenAuth.App.BaseApp.Base;
|
|
using OpenAuth.App.Interface;
|
|
using OpenAuth.App.Request;
|
|
using OpenAuth.App.Response;
|
|
using OpenAuth.Repository;
|
|
using OpenAuth.Repository.Domain;
|
|
using Org.BouncyCastle.Ocsp;
|
|
using SqlSugar;
|
|
using SqlSugar.Extensions;
|
|
using System.Text;
|
|
|
|
namespace OpenAuth.App
|
|
{
|
|
public class MiMinePointApp : SqlSugarBaseApp<MiMinePoint, SugarDbContext>
|
|
{
|
|
public MiMinePointApp(
|
|
ISugarUnitOfWork<SugarDbContext> unitWork,
|
|
ISimpleClient<MiMinePoint> repository,
|
|
IAuth auth
|
|
) : base(unitWork, repository, auth)
|
|
{
|
|
|
|
}
|
|
|
|
#region 查询
|
|
/// <summary>
|
|
/// 分页
|
|
/// </summary>
|
|
public async Task<Response<PageInfo<List<MiMinePoint>>>> LoadAllPage(PageReq request)
|
|
{
|
|
RefAsync<int> totalCount = 0;
|
|
var result = new PageInfo<SysRole>();
|
|
var list = await base.Repository.AsQueryable()
|
|
.WhereIF(!string.IsNullOrEmpty(request.key), r => r.Name.Contains(request.key))
|
|
.OrderBy(r => r.Name)
|
|
.ToPageListAsync(request.page, request.limit, totalCount);
|
|
|
|
return new Response<PageInfo<List<MiMinePoint>>>
|
|
{
|
|
Result = new PageInfo<List<MiMinePoint>>
|
|
{
|
|
Items = list,
|
|
Total = totalCount
|
|
}
|
|
};
|
|
}
|
|
#endregion
|
|
|
|
public async Task<MiMinePoint> Get(string id)
|
|
{
|
|
return await base.Repository.GetByIdAsync(id);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 添加
|
|
/// </summary>
|
|
public async Task<Response<bool>> Add(MiMinePoint model)
|
|
{
|
|
using (var uow = base.UnitWork.CreateContext())
|
|
{
|
|
MiMinePoint point = model.MapTo<MiMinePoint>();
|
|
point.Id = Guid.NewGuid().ToString();
|
|
point.CreateTime = DateTime.Now;
|
|
point.geom = null;
|
|
|
|
|
|
if (!string.IsNullOrEmpty(model.geom))
|
|
{
|
|
var flag = await uow.MiMinePoint.InsertAsync(point);
|
|
|
|
string _wktModel = model.geom;
|
|
StringBuilder geomSql = new StringBuilder();
|
|
geomSql.AppendFormat(
|
|
$" update mi_mine_point set \"geom\" = st_geomfromtext('{_wktModel}',4326) where \"Id\" = '{point.Id}'");
|
|
if (flag)
|
|
{
|
|
var flag1=await uow.Db.Ado.ExecuteCommandAsync(geomSql.ToString());
|
|
if(uow.Commit()&&flag1 > 0)
|
|
{
|
|
return new Response<bool> { Result = true, Message = "操作成功" };
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var flag = await uow.MiMinePoint.InsertAsync(point);
|
|
if (uow.Commit() && flag)
|
|
{
|
|
return new Response<bool> { Result = true, Message = "操作成功" };
|
|
}
|
|
}
|
|
|
|
// 如果执行到这里,说明操作失败
|
|
return new Response<bool> { Result = false, Message = "操作失败" };
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <param name="ids"></param>
|
|
public async Task<Response<bool>> Delete(List<MiMinePoint> models)
|
|
{
|
|
var flag = await Repository.DeleteAsync(models);
|
|
|
|
return new Response<bool>
|
|
{
|
|
Result = flag,
|
|
Message = flag == true ? "success" : "error"
|
|
};
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public async Task<Response<bool>> Update(MiMinePoint model)
|
|
{
|
|
bool flag = await base.Repository.UpdateAsync(model);
|
|
|
|
return new Response<bool>
|
|
{
|
|
Result = flag,
|
|
Message = flag == true ? "success" : "error"
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 事务示例
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public async Task<Response<bool>> AssignModule()
|
|
{
|
|
using (var uwo = UnitWork.CreateContext())
|
|
{
|
|
//await uwo.SysRoleElement.InsertRangeAsync(model.ElementIds.Select(a => new SysRoleElement { RoleId = model.RoleId, ElementId = a }).ToList());
|
|
|
|
var flag = uwo.Commit();
|
|
return new Response<bool>
|
|
{
|
|
Result = flag,
|
|
Message = flag == true ? "success" : "error"
|
|
};
|
|
}
|
|
}
|
|
|
|
}
|
|
} |