手动添加换电订单

master
tq 6 months ago
parent db8ab68fd4
commit 53722d5aaa

@ -117,5 +117,15 @@
/// 云平台订单号 /// 云平台订单号
/// </summary> /// </summary>
public string? CloudSn { get;set;} public string? CloudSn { get;set;}
/// <summary>
/// Desc:换电类型:;0手动换电;1自动换电
/// Default:0
/// Nullable:True
/// </summary>
public int? SwapModel { get; set; }
/// <summary>
/// 换电电池
/// </summary>
public List<SwapOrderBatteryReq> batteryList;
} }
} }

@ -1,3 +1,5 @@
using System.ComponentModel.DataAnnotations;
namespace Entity.Api.Req; namespace Entity.Api.Req;
public partial class ElecPriceModelVersionDetailReq public partial class ElecPriceModelVersionDetailReq
@ -11,7 +13,11 @@ public partial class ElecPriceModelVersionDetailReq
/// <summary> /// <summary>
/// 价格 /// 价格
/// </summary> /// </summary>
public int? Price {get;set;} // public int? Price {get;set;}
public double Price { get; set; }
/// <summary> /// <summary>
/// Desc:尖峰平谷类型;1-尖2-峰3-平4-谷 /// Desc:尖峰平谷类型;1-尖2-峰3-平4-谷
/// </summary> /// </summary>

@ -125,5 +125,15 @@ namespace Entity.Api.Req
/// </summary> /// </summary>
public string? CloudSn { get; set; } public string? CloudSn { get; set; }
/// <summary>
/// Desc:换电类型:;0手动换电;1自动换电
/// Default:0
/// Nullable:True
/// </summary>
public int? SwapModel { get; set; }
/// <summary>
/// 换电电池
/// </summary>
public List<UpdateSwapOrderBatteryReq> batteryList;
} }
} }

@ -0,0 +1,162 @@
namespace Entity.Api.Req;
///<summary>
///换电订单电池
///</summary>
public class SwapOrderBatteryReq
{
/// <summary>
/// Desc:亏电包编码
/// Default:
/// Nullable:True
/// </summary>
public string? DownBatteryNo { get; set; }
/// <summary>
/// Desc:亏电包soc
/// Default:
/// Nullable:True
/// </summary>
public decimal? DownBatterySoc { get; set; }
/// <summary>
/// Desc:亏电包soe
/// Default:
/// Nullable:True
/// </summary>
public decimal? DownBatterySoe { get; set; }
/// <summary>
/// Desc:亏电包真实soc
/// Default:
/// Nullable:True
/// </summary>
public decimal? DownBatteryRealSoc { get; set; }
/// <summary>
/// Desc:亏电包上次换电结算时soc
/// Default:
/// Nullable:True
/// </summary>
public decimal? DownBatteryLastSoc { get; set; }
/// <summary>
/// Desc:亏电包上次换电结算时soe
/// Default:
/// Nullable:True
/// </summary>
public decimal? DownBatteryLastSoe { get; set; }
/// <summary>
/// Desc:亏电包站内充电能量(累计)
/// Default:
/// Nullable:True
/// </summary>
public decimal? DownBatteryInChageElecCount { get; set; }
/// <summary>
/// Desc:亏电包站外插枪充电能量(累计)
/// Default:
/// Nullable:True
/// </summary>
public decimal? DownBatteryOutChageElecCount { get; set; }
/// <summary>
/// Desc:亏电包站外回充能量(累计)
/// Default:
/// Nullable:True
/// </summary>
public decimal? DownBatteryOutReChagreCount { get; set; }
/// <summary>
/// Desc:亏电包站外放电能量(累计)
/// Default:
/// Nullable:True
/// </summary>
public decimal? DownBatteryInDischageElecCount { get; set; }
/// <summary>
/// Desc:亏电包站内放电电能量(累计)
/// Default:
/// Nullable:True
/// </summary>
public decimal? DownBatteryOutDischageElecCount { get; set; }
/// <summary>
/// Desc:放电池仓位号 亏电包仓号
/// Default:
/// Nullable:True
/// </summary>
public int? DownBatteryBinNo { get; set; }
/// <summary>
/// Desc:满电包编码
/// Default:
/// Nullable:True
/// </summary>
public string? UpBatteryNo { get; set; }
/// <summary>
/// Desc:满电包soc
/// Default:
/// Nullable:True
/// </summary>
public decimal? UpBatterySoc { get; set; }
/// <summary>
/// Desc:满电包soe
/// Default:
/// Nullable:True
/// </summary>
public decimal? UpBatterySoe { get; set; }
/// <summary>
/// Desc:满电包真实soc
/// Default:
/// Nullable:True
/// </summary>
public decimal? UpBatteryRealSoc { get; set; }
/// <summary>
/// Desc:满电包站内充电能量(累计)
/// Default:
/// Nullable:True
/// </summary>
public decimal? UpBatteryInChageElecCount { get; set; }
/// <summary>
/// Desc:满电包站外插枪充电能量(累计)
/// Default:
/// Nullable:True
/// </summary>
public decimal? UpBatteryOutChageElecCount { get; set; }
/// <summary>
/// Desc:满电包站外回充能量(累计)
/// Default:
/// Nullable:True
/// </summary>
public decimal? UpBatteryOutReChagreCount { get; set; }
/// <summary>
/// Desc:满电包站外放电能量(累计)
/// Default:
/// Nullable:True
/// </summary>
public decimal? UpBatteryInDischageElecCount { get; set; }
/// <summary>
/// Desc:满电包站内放电电能量(累计)
/// Default:
/// Nullable:True
/// </summary>
public decimal? UpBatteryOutDischageElecCount { get; set; }
/// <summary>
/// Desc:取电池仓位号 满电包仓号
/// Default:
/// Nullable:True
/// </summary>
public int? UpBatteryBinNo { get; set; }
}

@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;
namespace Entity.Api.Req;
public class UpdateSwapOrderBatteryReq:SwapOrderBatteryReq
{
/// <summary>
/// Desc:id
/// Default:
/// Nullable:False
/// </summary>
[Required]
public int Id { get; set; }
}

@ -13,8 +13,8 @@ public class ElecPriceModelVersionDetailResp
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
public int? Price {get;set;} // public int? Price {get;set;}
public double Price { get; set; }
/// <summary> /// <summary>
/// Desc:尖峰平谷类型;1-尖2-峰3-平4-谷 /// Desc:尖峰平谷类型;1-尖2-峰3-平4-谷
/// Default: /// Default:

@ -66,8 +66,9 @@ namespace Entity.DbModel.Station
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="price")] // [SugarColumn(ColumnName="price")]
public int? Price {get;set;} // public int? Price {get;set;}
public double Price { get; set; }
/// <summary> /// <summary>
/// Desc:尖峰平谷类型;1-尖2-峰3-平4-谷 /// Desc:尖峰平谷类型;1-尖2-峰3-平4-谷

@ -9,7 +9,7 @@ using System.Linq.Expressions;
namespace Service.Station; namespace Service.Station;
/// <summary> /// <summary>
/// 换电订单电池 /// 换电订单电池
/// </summary> /// </summary>
[Scope("SingleInstance")] [Scope("SingleInstance")]
public class SwapOrderBatteryService : BaseServices<SwapOrderBattery> public class SwapOrderBatteryService : BaseServices<SwapOrderBattery>
@ -23,19 +23,19 @@ public class SwapOrderBatteryService : BaseServices<SwapOrderBattery>
/// <summary> /// <summary>
/// 根据条件查询分页数据 /// 根据条件查询分页数据
/// </summary> /// </summary>
/// <param name="equipAlarmLevel"></param> /// <param name="equipAlarmLevel"></param>
/// <returns></returns> /// <returns></returns>
public PageResult<SwapOrderBatteryResp> QuerySwapOrderBattery(QuerySwapOrderBatteryReq swapOrderBattery) public PageResult<SwapOrderBatteryResp> QuerySwapOrderBattery(QuerySwapOrderBatteryReq swapOrderBattery)
{ {
//创建一个空的表达式树 //创建一个空的表达式树
Expression<Func<SwapOrderBattery, bool>> where = null; Expression<Func<SwapOrderBattery, bool>> where = null;
//// 定义参数表达式 //// 定义参数表达式
ParameterExpression parameter = Expression.Parameter(typeof(SwapOrderBattery), "u"); ParameterExpression parameter = Expression.Parameter(typeof(SwapOrderBattery), "u");
#region 构建动态查询树 #region 构建动态查询树
if (swapOrderBattery.Id != 0) if (swapOrderBattery.Id != 0)
{ {
Expression<Func<SwapOrderBattery, bool>> condition1Expr = u => u.Id == swapOrderBattery.Id; Expression<Func<SwapOrderBattery, bool>> condition1Expr = u => u.Id == swapOrderBattery.Id;
@ -79,7 +79,7 @@ public class SwapOrderBatteryService : BaseServices<SwapOrderBattery>
} }
#endregion #endregion
//查询 //查询
return PageResult<SwapOrderBatteryResp>.ConvertPage(_swapOrderBatteryRepository.QueryIPageByCause(swapOrderBattery, where)); return PageResult<SwapOrderBatteryResp>.ConvertPage(_swapOrderBatteryRepository.QueryIPageByCause(swapOrderBattery, where));

@ -29,7 +29,8 @@ public class ChargeOrderController : ControllerBase
[HttpPost("QueryPage")] [HttpPost("QueryPage")]
public async Task<Result<PageResult<ChargeOrderResp>>> QueryPage([FromBody] QueryChargeOrderReq req) public async Task<Result<PageResult<ChargeOrderResp>>> QueryPage([FromBody] QueryChargeOrderReq req)
{ {
return Result<PageResult<ChargeOrderResp>>.Success(chargeOrderService.QueryChargeOrder(req)); PageResult<ChargeOrderResp> queryChargeOrder = chargeOrderService.QueryChargeOrder(req);
return Result<PageResult<ChargeOrderResp>>.Success(queryChargeOrder);
} }
/// <summary> /// <summary>

@ -1,10 +1,13 @@
using System.Transactions;
using AutoMapper; using AutoMapper;
using Entity.Api.Req; using Entity.Api.Req;
using Entity.Api.Resp; using Entity.Api.Resp;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Service.Init;
using Service.Station; using Service.Station;
using Swapping.Business.Common;
namespace WebStarter.Controllers; namespace WebStarter.Controllers;
@ -83,22 +86,46 @@ public class SwapOrderController : ControllerBase
/// <returns></returns> /// <returns></returns>
[HttpPost("Add")] [HttpPost("Add")]
public async Task<Result<bool>> Add([FromBody] AddSwapOrderReq req) public async Task<Result<bool>> Add([FromBody] AddSwapOrderReq req)
{
using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{ {
// 映射数据 // 映射数据
var config = new MapperConfiguration(cfg => cfg.CreateMap<SwapOrder, AddSwapOrderReq>().ReverseMap()); var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<SwapOrder, AddSwapOrderReq>().ReverseMap();
cfg.CreateMap<SwapOrderBattery, SwapOrderBatteryReq>().ReverseMap();
});
IMapper mapper = config.CreateMapper(); IMapper mapper = config.CreateMapper();
// 转换换电订单
SwapOrder swapOrder = mapper.Map<SwapOrder>(req); SwapOrder swapOrder = mapper.Map<SwapOrder>(req);
swapOrder.Sn = SwapOrderNoGenerator.GenerateOrderNo(StaticStationInfo.StationNo);
SwapOrder order = await swapOrderService.InsertAsync(swapOrder);
var swap = swapOrderService.QueryByClause(u => u.Sn == req.Sn); bool batteriesInserted = true;
if (swap != null)
if (req.batteryList.Any())
{
// 绑定订单
List<SwapOrderBattery> swapOrderBatteries = mapper.Map<List<SwapOrderBattery>>(req.batteryList);
foreach (var swapOrderBattery in swapOrderBatteries)
{ {
return Result<bool>.Fail("新增失败!订单号重复"); swapOrderBattery.SwapOrderSn = swapOrder.Sn;
} }
else
batteriesInserted = await swapOrderBatteryService.InsertAsync(swapOrderBatteries);
}
if (order != null && batteriesInserted)
{ {
swapOrderService.Insert(swapOrder); // 提交
transactionScope.Complete();
return Result<bool>.Success(true, "新增成功"); return Result<bool>.Success(true, "新增成功");
} }
return Result<bool>.Fail(false, "新增失败");
}
} }
/// <summary> /// <summary>
@ -109,17 +136,47 @@ public class SwapOrderController : ControllerBase
[HttpPost("Modify")] [HttpPost("Modify")]
public async Task<Result<bool>> Modify([FromBody] ModifySwapOrderReq req) public async Task<Result<bool>> Modify([FromBody] ModifySwapOrderReq req)
{ {
using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
var existingOrder = await swapOrderService.QueryByClauseAsync(u => u.Sn == req.Sn && u.Id != req.Id);
if (existingOrder != null)
{
return Result<bool>.Fail("订单号已存在");
}
// 映射数据 // 映射数据
var config = new MapperConfiguration(cfg => cfg.CreateMap<SwapOrder, ModifySwapOrderReq>().ReverseMap()); var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<SwapOrder, ModifySwapOrderReq>().ReverseMap();
cfg.CreateMap<SwapOrderBattery, SwapOrderBatteryReq>().ReverseMap();
});
IMapper mapper = config.CreateMapper(); IMapper mapper = config.CreateMapper();
SwapOrder swapOrder = mapper.Map<SwapOrder>(req); SwapOrder swapOrder = mapper.Map<SwapOrder>(req);
if (swapOrderService.Update(swapOrder)) bool orderUpdated = swapOrderService.Update(swapOrder);
bool batteriesUpdated = true;
if ( req.batteryList.Any())
{ {
return Result<bool>.Success(true,"更改成功"); // 绑定订单
List<SwapOrderBattery> swapOrderBatteries = mapper.Map<List<SwapOrderBattery>>(req.batteryList);
foreach (var swapOrderBattery in swapOrderBatteries)
{
swapOrderBattery.SwapOrderSn = swapOrder.Sn;
} }
else
// 更新电池订单
batteriesUpdated = await swapOrderBatteryService.UpdateAsync(swapOrderBatteries);
}
if (orderUpdated && batteriesUpdated)
{ {
// 提交
transactionScope.Complete();
return Result<bool>.Success(true, "更改成功");
}
return Result<bool>.Fail("更改失败"); return Result<bool>.Fail("更改失败");
} }
} }

Loading…
Cancel
Save