You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
3.7 KiB
131 lines
3.7 KiB
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<BaseVehicle>
|
|
{
|
|
private readonly BaseVehicleRepository _baseVehicleRepository;
|
|
|
|
public VehicleService(
|
|
BaseVehicleRepository baseVehicleRepository
|
|
)
|
|
{
|
|
_baseVehicleRepository = baseVehicleRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取车辆
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public async Task<PageResult<BaseVehicle>> Page(PageVehicleReq input)
|
|
{
|
|
RefAsync<int> 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<BaseVehicle>()
|
|
{
|
|
PageNum = input.PageNum,
|
|
PageSize = input.PageSize,
|
|
ToTal = total,
|
|
Rows = items,
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取所有车队
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<BaseVehicle> GetVehicle()
|
|
{
|
|
return _baseVehicleRepository.Query();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增车队
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public virtual Result<bool> AddVehicleReq(AddVehicleReq input)
|
|
{
|
|
var existingUser =
|
|
_baseVehicleRepository.QueryByClause(u =>
|
|
u.VehicleVin == input.VehicleVin );
|
|
|
|
if (existingUser!=null)
|
|
{
|
|
return Result<bool>.Fail();
|
|
}
|
|
|
|
// 插入新用户
|
|
_baseVehicleRepository.Insert(input);
|
|
|
|
return Result<bool>.Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 车队修改
|
|
/// </summary>
|
|
/// <param name="vehicle"></param>
|
|
/// <returns></returns>
|
|
public virtual Result<string> UpdateVehicle(UpdateVehicleReq vehicle)
|
|
{
|
|
var existingTeam =
|
|
_baseVehicleRepository.QueryById(vehicle.Id);
|
|
|
|
if (existingTeam==null)
|
|
{
|
|
return Result<string>.Fail("车辆不存在");
|
|
}
|
|
List<BaseVehicle> list =
|
|
_baseVehicleRepository.QueryListByClause(i=>i.Id!=vehicle.Id && i.VehicleVin==vehicle.VehicleVin);
|
|
|
|
if (list!=null && list.Count>0)
|
|
{
|
|
return Result<string>.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<string>.Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 车队删除
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="ArgumentException"></exception>
|
|
public virtual Result<bool> DeleteVehicle(List<long> input)
|
|
{
|
|
_baseVehicleRepository.DeleteByIds(input);
|
|
|
|
return Result<bool>.Success();
|
|
}
|
|
} |