|
|
@ -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;
|
|
|
|
|
|
|
|
|
|
|
@ -84,20 +87,44 @@ public class SwapOrderController : ControllerBase
|
|
|
|
[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());
|
|
|
|
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
|
|
|
|
|
|
SwapOrder swapOrder = mapper.Map<SwapOrder>(req);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var swap = swapOrderService.QueryByClause(u => u.Sn == req.Sn);
|
|
|
|
|
|
|
|
if (swap != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Result<bool>.Fail("新增失败!订单号重复");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
swapOrderService.Insert(swapOrder);
|
|
|
|
// 映射数据
|
|
|
|
return Result<bool>.Success(true,"新增成功");
|
|
|
|
var config = new MapperConfiguration(cfg =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cfg.CreateMap<SwapOrder, AddSwapOrderReq>().ReverseMap();
|
|
|
|
|
|
|
|
cfg.CreateMap<SwapOrderBattery, SwapOrderBatteryReq>().ReverseMap();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 转换换电订单
|
|
|
|
|
|
|
|
SwapOrder swapOrder = mapper.Map<SwapOrder>(req);
|
|
|
|
|
|
|
|
swapOrder.Sn = SwapOrderNoGenerator.GenerateOrderNo(StaticStationInfo.StationNo);
|
|
|
|
|
|
|
|
SwapOrder order = await swapOrderService.InsertAsync(swapOrder);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool batteriesInserted = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (req.batteryList.Any())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 绑定订单
|
|
|
|
|
|
|
|
List<SwapOrderBattery> swapOrderBatteries = mapper.Map<List<SwapOrderBattery>>(req.batteryList);
|
|
|
|
|
|
|
|
foreach (var swapOrderBattery in swapOrderBatteries)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
swapOrderBattery.SwapOrderSn = swapOrder.Sn;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
batteriesInserted = await swapOrderBatteryService.InsertAsync(swapOrderBatteries);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (order != null && batteriesInserted)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 提交
|
|
|
|
|
|
|
|
transactionScope.Complete();
|
|
|
|
|
|
|
|
return Result<bool>.Success(true, "新增成功");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Result<bool>.Fail(false, "新增失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -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 config = new MapperConfiguration(cfg => cfg.CreateMap<SwapOrder, ModifySwapOrderReq>().ReverseMap());
|
|
|
|
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
|
|
|
|
|
|
SwapOrder swapOrder = mapper.Map<SwapOrder>(req);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (swapOrderService.Update(swapOrder))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Result<bool>.Success(true,"更改成功");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
cfg.CreateMap<SwapOrderBattery, SwapOrderBatteryReq>().ReverseMap();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
|
|
|
|
|
|
SwapOrder swapOrder = mapper.Map<SwapOrder>(req);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool orderUpdated = swapOrderService.Update(swapOrder);
|
|
|
|
|
|
|
|
bool batteriesUpdated = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( req.batteryList.Any())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 绑定订单
|
|
|
|
|
|
|
|
List<SwapOrderBattery> swapOrderBatteries = mapper.Map<List<SwapOrderBattery>>(req.batteryList);
|
|
|
|
|
|
|
|
foreach (var swapOrderBattery in swapOrderBatteries)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
swapOrderBattery.SwapOrderSn = swapOrder.Sn;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新电池订单
|
|
|
|
|
|
|
|
batteriesUpdated = await swapOrderBatteryService.UpdateAsync(swapOrderBatteries);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (orderUpdated && batteriesUpdated)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 提交
|
|
|
|
|
|
|
|
transactionScope.Complete();
|
|
|
|
|
|
|
|
return Result<bool>.Success(true, "更改成功");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Result<bool>.Fail("更改失败");
|
|
|
|
return Result<bool>.Fail("更改失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|