diff --git a/Entity/Api/Req/ModifySwapOrderReq.cs b/Entity/Api/Req/ModifySwapOrderReq.cs index 9ee8778..2e5d262 100644 --- a/Entity/Api/Req/ModifySwapOrderReq.cs +++ b/Entity/Api/Req/ModifySwapOrderReq.cs @@ -3,7 +3,7 @@ namespace Entity.Api.Req { /// - ///新增换电订单 + ///修改换电订单 /// public class ModifySwapOrderReq:AddSwapOrderReq { diff --git a/Entity/Api/Req/QuerySwapOrderPageReq.cs b/Entity/Api/Req/QuerySwapOrderPageReq.cs index 3344aed..e7dd063 100644 --- a/Entity/Api/Req/QuerySwapOrderPageReq.cs +++ b/Entity/Api/Req/QuerySwapOrderPageReq.cs @@ -52,5 +52,5 @@ public class QuerySwapOrderPageReq : QueryPageModel /// Default:0 /// Nullable:True /// - public int? SwapResult { get; set; } + public int SwapResult { get; set; } } \ No newline at end of file diff --git a/Service/Station/ChargeOrderService.cs b/Service/Station/ChargeOrderService.cs index a95e0c0..837ff86 100644 --- a/Service/Station/ChargeOrderService.cs +++ b/Service/Station/ChargeOrderService.cs @@ -9,7 +9,7 @@ using System.Linq.Expressions; namespace Service.Station; /// -/// 綩 +/// 綩 /// [Scope("SingleInstance")] public class ChargeOrderService : BaseServices @@ -46,11 +46,6 @@ public class ChargeOrderService : BaseServices Expression> condition2Expr = u => u.Sn == chargeOrder.Sn; where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); } - if (!string.IsNullOrEmpty(chargeOrder.Sn)) - { - Expression> condition2Expr = u => u.Sn == chargeOrder.Sn; - where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); - } if (!string.IsNullOrEmpty(chargeOrder.BatteryNo)) { Expression> condition2Expr = u => u.BatteryNo == chargeOrder.BatteryNo; diff --git a/Service/Station/SwapOrderService.cs b/Service/Station/SwapOrderService.cs new file mode 100644 index 0000000..89fce29 --- /dev/null +++ b/Service/Station/SwapOrderService.cs @@ -0,0 +1,81 @@ +using Entity.Api.Req; +using Entity.Api.Resp; +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkCore.Entity; +using Repository.Station; +using SqlSugar; +using System.Linq.Expressions; + +namespace Service.Station; +/// +/// 綩 +/// +[Scope("SingleInstance")] +public class SwapOrderService : BaseServices +{ + SwapOrderRepository swapOrderRepository; + public SwapOrderService(SwapOrderRepository dal) + { + swapOrderRepository = dal; + BaseDal = dal; + } + + + /// + /// ѯҳ + /// + /// + /// + public PageResult QuerySwapOrder(QuerySwapOrderPageReq swapOrder) + { + + //һյıʽ + Expression> where = null; + //// ʽ + ParameterExpression parameter = Expression.Parameter(typeof(SwapOrder), "u"); + + #region ̬ѯ + if (!string.IsNullOrEmpty(swapOrder.Sn)) + { + Expression> condition2Expr = u => u.Sn == swapOrder.Sn; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + if (!string.IsNullOrEmpty(swapOrder.VehicleNo)) + { + Expression> condition2Expr = u => u.VehicleNo == swapOrder.VehicleNo; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + if (!string.IsNullOrEmpty(swapOrder.VehicleMac)) + { + Expression> condition2Expr = u => u.VehicleMac == swapOrder.VehicleMac; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + if (!string.IsNullOrEmpty(swapOrder.VehicleVin)) + { + Expression> condition2Expr = u => u.VehicleVin == swapOrder.VehicleVin; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + if (swapOrder.SwapBeginTime != null && swapOrder.SwapBeginTime != DateTime.MinValue) + { + Expression> condition2Expr = u => u.SwapBeginTime == swapOrder.SwapBeginTime; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + if (swapOrder.SwapEndTime != null && swapOrder.SwapEndTime != DateTime.MinValue) + { + Expression> condition2Expr = u => u.SwapEndTime == swapOrder.SwapEndTime; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + if (swapOrder.SwapResult != 0) + { + Expression> condition2Expr = u => u.SwapResult == swapOrder.SwapResult; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + #endregion + + //ѯ + return PageResult.ConvertPage(swapOrderRepository.QueryIPageByCause(swapOrder, where)); + + + } +} \ No newline at end of file diff --git a/WebStarter/Controllers/ChargeOrderController.cs b/WebStarter/Controllers/ChargeOrderController.cs index abac89f..2d46f17 100644 --- a/WebStarter/Controllers/ChargeOrderController.cs +++ b/WebStarter/Controllers/ChargeOrderController.cs @@ -1,14 +1,16 @@ +using AutoMapper; using Entity.Api.Req; using Entity.Api.Resp; +using Entity.DbModel.Station; using HybirdFrameworkCore.Entity; using Microsoft.AspNetCore.Mvc; using Service.Station; namespace WebStarter.Controllers; -/** - * 充电订单 - */ +/// +/// 充电订单 +/// [ApiController] [Route("api/[controller]")] public class ChargeOrderController : ControllerBase @@ -21,54 +23,53 @@ public class ChargeOrderController : ControllerBase } /// - /// 分页数据 + /// 查询分页数据 /// /// [HttpPost("QueryPage")] public async Task>> QueryPage([FromBody] QueryChargeOrderReq req) { - chargeOrderService.QueryChargeOrder(req); - - return Result>.Success(null); - + return Result>.Success(chargeOrderService.QueryChargeOrder(req)); } - /// - /// 获取列表 + /// 修改充电订单 /// + /// /// - [HttpPost("GetList")] - public async Task>> GetList([FromBody] QueryChargeOrderReq req) - { - - return Result>.Success(null); - } - - /// - /// 修改充电订单 - /// - /// - /// - [HttpPost("Modify")] - public async Task> Modify([FromBody] ModifyChargeOrderReq req) + [HttpPost("Modify")] + public async Task> Modify([FromBody] ModifyChargeOrderReq req) + { + //映射数据 + var config = new MapperConfiguration(cfg => cfg.CreateMap().ReverseMap()); + IMapper mapper = config.CreateMapper(); + ChargeOrder chargeOrder = mapper.Map(req); + + if (chargeOrderService.Update(chargeOrder)) { - - return Result.Success(null); + return Result.Success("更改成功"); } - - - /// - /// 充电订单上报云端 - /// - /// - [HttpGet("UploadCloud/{id}")] - public async Task> UploadCloud(long id) + else { - - return Result.Success(null); + return Result.Fail("更改失败"); } - - + } + + + + + /// + /// 充电订单上报云端 + /// + /// + [HttpGet("UploadCloud/{id}")] + public async Task> UploadCloud(long id) + { + + return Result.Success(null); + } + + + } \ No newline at end of file diff --git a/WebStarter/Controllers/SwapOrderController.cs b/WebStarter/Controllers/SwapOrderController.cs index 542011f..e23edf9 100644 --- a/WebStarter/Controllers/SwapOrderController.cs +++ b/WebStarter/Controllers/SwapOrderController.cs @@ -1,27 +1,56 @@ +using AutoMapper; using Entity.Api.Req; using Entity.Api.Resp; +using Entity.DbModel.Station; using HybirdFrameworkCore.Entity; using Microsoft.AspNetCore.Mvc; +using Service.Station; namespace WebStarter.Controllers; -/** - * 换电订单 - */ +/// +/// 换电订单 +/// [ApiController] [Route("api/[controller]")] public class SwapOrderController : ControllerBase { + private readonly SwapOrderService swapOrderService; + public SwapOrderController(SwapOrderService swapOrderService) + { + this.swapOrderService = swapOrderService; + } /// - /// 分页数据 + /// 查询分页数据 /// /// [HttpPost("QueryPage")] public async Task>> QueryPage([FromBody] QuerySwapOrderPageReq req) { - - return Result>.Success(null); + + return Result>.Success(swapOrderService.QuerySwapOrder(req)); + } + /// + /// 新增 + /// + /// + [HttpPost("Add")] + public async Task> Add([FromBody] AddSwapOrderReq req) + { + //映射数据 + var config = new MapperConfiguration(cfg => cfg.CreateMap().ReverseMap()); + IMapper mapper = config.CreateMapper(); + SwapOrder swapOrder = mapper.Map(req); + + if (swapOrderService.Insert(swapOrder) != 0) + { + return Result.Success("新增成功"); + } + else + { + return Result.Fail("新增失败"); + } } /// @@ -32,33 +61,40 @@ public class SwapOrderController : ControllerBase [HttpPost("Modify")] public async Task> Modify([FromBody] ModifySwapOrderReq req) { - - return Result.Success(null); + //映射数据 + var config = new MapperConfiguration(cfg => cfg.CreateMap().ReverseMap()); + IMapper mapper = config.CreateMapper(); + SwapOrder swapOrder = mapper.Map(req); + + if (swapOrderService.Update(swapOrder)) + { + return Result.Success("更改成功"); + } + else + { + return Result.Fail("更改失败"); + } } /// /// 删除 /// - /// ids 订单列表 + /// ids id列表 /// [HttpPost("DeleteByIds")] public async Task> DeleteByIds([FromBody] List ids) { - - return Result.Success(null); - } - - /// - /// 换电订单上报云端 - /// - /// - [HttpPost("Add")] - public async Task> Add([FromBody] AddSwapOrderReq req) - { - - return Result.Success(null); + if (swapOrderService.DeleteByIds(ids)) + { + return Result.Success("删除成功"); + } + else + { + return Result.Fail("删除失败"); + } } + /// /// 换电订单上报云端 ///