using Entity.DbModel.Station; using Entity.DbModel.System.App; using Entity.Dto.Req; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Utils; using Repository.Station; using SqlSugar; namespace Service.Station; [Scope] public class VehicleService : BaseServices { private readonly BaseVehicleRepository _baseVehicleRepository; public VehicleService( BaseVehicleRepository baseVehicleRepository ) { _baseVehicleRepository = baseVehicleRepository; } /// /// 获取车辆 /// /// /// public async Task> Page(PageVehicleReq input) { RefAsync total = 0; var items = await _baseVehicleRepository.QueryPageAsync( entity => true, !string.IsNullOrWhiteSpace(input.VehicleNo), u => u.VehicleNo.Equals(input.VehicleNo.Trim()), !string.IsNullOrWhiteSpace(input.VehicleVin), u => u.VehicleVin.Equals(input.VehicleVin.Trim()), !string.IsNullOrWhiteSpace(input.VehicleMac), u => u.VehicleMac.Equals(input.VehicleMac.Trim()), u => u.CreatedTime, OrderByType.Desc, input.PageNum, input.PageSize, total); return new PageResult() { PageNum = input.PageNum, PageSize = input.PageSize, ToTal = total, Rows = items, }; } /// /// 获取所有车队 /// /// public List GetVehicle() { return _baseVehicleRepository.Query(); } /// /// 新增车队 /// /// /// public virtual Result AddVehicleReq(AddVehicleReq input) { var existingUser = _baseVehicleRepository.QueryByClause(u => u.VehicleVin == input.VehicleVin ); if (existingUser!=null) { return Result.Fail(); } // 插入新用户 _baseVehicleRepository.Insert(input); return Result.Success(); } /// /// 车队修改 /// /// /// public virtual Result UpdateVehicle(UpdateVehicleReq vehicle) { var existingTeam = _baseVehicleRepository.QueryById(vehicle.Id); if (existingTeam==null) { return Result.Fail("车辆不存在"); } List list = _baseVehicleRepository.QueryListByClause(i=>i.Id!=vehicle.Id && i.VehicleVin==vehicle.VehicleVin); if (list!=null && list.Count>0) { return Result.Fail("车辆已经存在"); } BaseVehicle db = new BaseVehicle() { Id = vehicle.Id, VehicleVin = vehicle.VehicleVin, VehicleMac = vehicle.VehicleMac, VehicleNo = vehicle.VehicleNo, Company = vehicle.Company, Departments = vehicle.Departments, CreatedTime = existingTeam.CreatedTime }; _baseVehicleRepository.Update(db); return Result.Success(); } /// /// 车队删除 /// /// /// /// public virtual Result DeleteVehicle(List input) { _baseVehicleRepository.DeleteByIds(input); return Result.Success(); } }