202 lines
6.4 KiB
C#
202 lines
6.4 KiB
C#
|
|
using DocumentFormat.OpenXml.Office.CustomUI;
|
|
using Infrastructure;
|
|
using NPOI.SS.Util;
|
|
using OpenAuth.App.BaseApp.Base;
|
|
using OpenAuth.App.Interface;
|
|
using OpenAuth.App.Request;
|
|
using OpenAuth.App.Response;
|
|
using OpenAuth.App.ServiceApp.Request;
|
|
using OpenAuth.App.ServiceApp.Response;
|
|
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)
|
|
{
|
|
//等级
|
|
var level = _auth.GetCurrentUser().Orgs.Min(a => a.Level);
|
|
//路径
|
|
var cascadeId = _auth.GetCurrentUser().Orgs.Where(a => a.Level == level).First().CascadeId;
|
|
|
|
RefAsync<int> totalCount = 0;
|
|
|
|
var list = await base.Repository.AsQueryable()
|
|
.LeftJoin<SysOrg>((r, o) => r.ReportUnit == o.Id.ToString())
|
|
.Where((r,o)=>o.CascadeId.Contains(cascadeId))
|
|
.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<ReportDetail> Get(string id)
|
|
{
|
|
//基础信息
|
|
var model = Repository.GetByIdAsync(id).MapTo<ReportDetail>();
|
|
|
|
model.Vehicles = new List<Vehicle>();
|
|
|
|
model.SencePhotos = base.Repository.AsSugarClient()
|
|
.Queryable<MiScenePhoto>()
|
|
.Where(a => a.ViolationReportId == id)
|
|
.Select(a => new SencePhoto { Image = a.Image }, true).ToList();
|
|
|
|
model.Vehicles = base.Repository.AsSugarClient()
|
|
.Queryable<MiVehicle>()
|
|
.Includes(a => a.MiVehicleImages)
|
|
.Where(a => a.ViolationReportId == id)
|
|
.Select(a => new Vehicle { LicensePlate = a.LicensePlate }, true).ToList();
|
|
return model;
|
|
}
|
|
|
|
|
|
/// <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"
|
|
};
|
|
}
|
|
}
|
|
|
|
}
|
|
} |