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.

119 lines
3.8 KiB

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<AppCustomerVehicle>
{
private readonly AppCustomerVehicleRepository _appCustomerVehicleRepository;
public AppCustomerVehicleService(
AppCustomerVehicleRepository appCustomerVehicleRepository
)
{
_appCustomerVehicleRepository = appCustomerVehicleRepository;
}
/// <summary>
/// 车辆分页查询
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<PageResult<AppCustomerVehicle>> Page(PageCustomerVehicleReq input)
{
RefAsync<int> total = 0;
if (!input.CustomerId.HasValue)
{
return new PageResult<AppCustomerVehicle>();
}
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<AppCustomerVehicle>()
{
PageNum = input.PageNum,
PageSize = input.PageSize,
ToTal = total,
Rows = items,
};
}
/// <summary>
/// 车辆新增
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public virtual async Task<string> 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;
}
/// <summary>
/// 车辆审核
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public virtual async Task<Result<string>> AuditVehicle(VehicleAuditReq req)
{
var vehicle = await _appCustomerVehicleRepository.QueryByClauseAsync(u => u.CarNo == req.CarNo);
if (vehicle == null)
{
return Result<string>.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<string>.Success("修改成功") : Result<string>.Fail("修改失败");
}
/// <summary>
/// 删除解绑车辆
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public virtual async Task<bool> DeleteCustomerVehicle(DeleteCustomerVehicleReq input)
{
var vehicle = await _appCustomerVehicleRepository.QueryByClauseAsync(u => u.Id == input.Id);
if (vehicle == null)
throw new ArgumentException($"车辆不存在");
return await _appCustomerVehicleRepository.DeleteAsync(vehicle);
}
}