|
|
@ -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("更改失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|