feixian_weifajianguan/OpenAuth.App/ServiceApp/MiManager/MiViolationReportApp.cs

178 lines
5.4 KiB
C#

using DocumentFormat.OpenXml.Office.CustomUI;
using Infrastructure;
using OpenAuth.App.BaseApp.Base;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.App.ServiceApp.Request;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using SqlSugar;
namespace OpenAuth.App
{
public class MiViolationReportApp : SqlSugarBaseApp<MiViolationReport, SugarDbContext>
{
public MiViolationReportApp(
ISugarUnitOfWork<SugarDbContext> unitWork,
ISimpleClient<MiViolationReport> repository,
IAuth auth
) : base(unitWork, repository, auth)
{
}
#region 查询
/// <summary>
/// 分页
/// </summary>
public async Task<Response<PageInfo<List<MiViolationReport>>>> LoadAllPage(PageReq request)
{
RefAsync<int> totalCount = 0;
var result = new PageInfo<SysRole>();
var list = await base.Repository.AsQueryable()
.ToPageListAsync(request.page, request.limit, totalCount);
return new Response<PageInfo<List<MiViolationReport>>>
{
Result = new PageInfo<List<MiViolationReport>>
{
Items = list,
Total = totalCount
}
};
}
#endregion
public async Task<MiViolationReport> Get(object id)
{
return await Repository.GetByIdAsync(id);
}
/// <summary>
/// 添加
/// </summary>
public async Task<Response<bool>> Add(MiViolationReport model)
{
var flag = await Repository.InsertAsync(model);
return new Response<bool>
{
Result = flag,
Message = flag == true ? "success" : "error"
};
}
/// <summary>
/// 删除
/// </summary>
/// <param name="ids"></param>
public async Task<Response<bool>> Delete(List<MiViolationReport> 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(MiViolationReport 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"
};
}
}
public async Task<Response<bool>> Report(MiViolationReportRequest request)
{
using (var uwo = UnitWork.CreateContext())
{
//上报信息
var model = request.MapTo<MiViolationReport>();
model.Id = Guid.NewGuid().ToString();
model.Status = "待处理";
//现场照片
var photos = request.SencePhotos.MapToList<MiScenePhoto>();
photos.ForEach(a =>
{
a.Id = Guid.NewGuid().ToString();
a.ViolationReportId = model.Id;
});
var vehicleList = new List<MiVehicle>();
var vehicleImageList = new List<MiVehicleImage>();
foreach (var item in request.Vehicles)
{
//车辆信息
var vehicle = item.MapTo<MiVehicle>();
vehicle.Id = Guid.NewGuid().ToString();
vehicle.ViolationReportId = model.Id;
//车辆图片
var images = item.VehicleImages.MapToList<MiVehicleImage>();
images.ForEach(a =>
{
a.Id = Guid.NewGuid().ToString();
a.ViolationReportId = model.Id;
a.ParkingId = model.ParkingId;
a.VehicleId = vehicle.Id;
vehicleImageList.Add(a);
});
vehicleList.Add(vehicle);
}
await uwo.MiViolationReport.InsertAsync(model);
await uwo.MiScenePhoto.InsertRangeAsync(photos);
await uwo.MiVehicle.InsertRangeAsync(vehicleList);
await uwo.MiVehicleImage.InsertRangeAsync(vehicleImageList);
var flag = uwo.Commit();
return new Response<bool>
{
Result = flag,
Message = flag == true ? "success" : "error"
};
}
}
}
}