using Entity.DbModel.System.App; using Entity.Dto.Req; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Entity; using Repository.System.App; using SqlSugar; namespace Service.System.App; [Scope()] public class AppCustomerVehicleService : BaseServices { private readonly AppCustomerVehicleRepository _appCustomerVehicleRepository; public AppCustomerVehicleService( AppCustomerVehicleRepository appCustomerVehicleRepository ) { _appCustomerVehicleRepository = appCustomerVehicleRepository; } /// /// 车辆分页查询 /// /// /// public async Task> Page(PageCustomerVehicleReq input) { RefAsync total = 0; if (!input.CustomerId.HasValue) { return new PageResult(); } var items = await _appCustomerVehicleRepository.QueryPageAsync( entity => true, (input.CustomerId.HasValue), u => u.CustomerId.Equals(input.CustomerId), !string.IsNullOrWhiteSpace(input.CarNo), u => u.CarNo.Equals(input.CarNo.Trim()), (input.AuditStatus.HasValue), u => u.AuditStatus.Equals(input.AuditStatus), u => u.CreatedTime, OrderByType.Desc, input.PageNum, input.PageSize, total); return new PageResult() { PageNum = input.PageNum, PageSize = input.PageSize, ToTal = total, Rows = items, }; } /// /// 车辆新增 /// /// /// public virtual async Task AddCustomerVehicle(AddCustomerVehicleReq input) { if (!input.CustomerId.HasValue) { return "客户id为空"; } AppCustomerVehicle vehicle = await _appCustomerVehicleRepository.QueryByClauseAsync(u => u.CarNo == input.CarNo); if (vehicle != null) { return "该车牌已被绑定请先解绑"; } input.ApplyTime = DateTime.Now; input.AuditStatus = 0; await _appCustomerVehicleRepository.InsertAsync(input); // 查询新ID AppCustomerVehicle newVehicle = await _appCustomerVehicleRepository.QueryByClauseAsync(u => u.CarNo == input.CarNo); return "新增车辆:" + newVehicle.CarNo; } /// /// 车辆审核 /// /// /// public virtual async Task> AuditVehicle(VehicleAuditReq req) { var vehicle = await _appCustomerVehicleRepository.QueryByClauseAsync(u => u.CarNo == req.CarNo); if (vehicle == null) { return Result.Fail("车辆不存在"); } vehicle.AuditId = req.AuditId; vehicle.AuditTime = DateTime.Now; vehicle.AuditStatus = req.AuditStatus; vehicle.AuditName = req.AuditName; var updateAsync = await _appCustomerVehicleRepository.UpdateAsync(vehicle, true); return updateAsync > 0 ? Result.Success("修改成功") : Result.Fail("修改失败"); } /// /// 删除解绑车辆 /// /// /// /// public virtual async Task DeleteCustomerVehicle(DeleteCustomerVehicleReq input) { var vehicle = await _appCustomerVehicleRepository.QueryByClauseAsync(u => u.Id == input.Id); if (vehicle == null) throw new ArgumentException($"车辆不存在"); return await _appCustomerVehicleRepository.DeleteAsync(vehicle); } }