|
|
|
@ -7,6 +7,7 @@ using Entity.Dto;
|
|
|
|
|
using HybirdFrameworkCore.Entity;
|
|
|
|
|
using Magicodes.ExporterAndImporter.Excel;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Repository.Station;
|
|
|
|
|
using Service.Init;
|
|
|
|
|
using Service.Station;
|
|
|
|
|
using Swapping.Business.Common;
|
|
|
|
@ -23,13 +24,15 @@ public class SwapOrderController : ControllerBase
|
|
|
|
|
private readonly SwapOrderService swapOrderService;
|
|
|
|
|
private readonly SwapOrderBatteryService swapOrderBatteryService;
|
|
|
|
|
private readonly SwapOrderStepService swapOrderStepService;
|
|
|
|
|
private readonly SwapOrderReportCloudRepository swapOrderReportCloudRepository;
|
|
|
|
|
|
|
|
|
|
public SwapOrderController(SwapOrderService swapOrderService, SwapOrderBatteryService swapOrderBatteryService,
|
|
|
|
|
SwapOrderStepService swapOrderStepService)
|
|
|
|
|
SwapOrderStepService swapOrderStepService,SwapOrderReportCloudRepository swapOrderReportCloudRepository)
|
|
|
|
|
{
|
|
|
|
|
this.swapOrderService = swapOrderService;
|
|
|
|
|
this.swapOrderBatteryService = swapOrderBatteryService;
|
|
|
|
|
this.swapOrderStepService = swapOrderStepService;
|
|
|
|
|
this.swapOrderReportCloudRepository = swapOrderReportCloudRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -39,6 +42,13 @@ public class SwapOrderController : ControllerBase
|
|
|
|
|
[HttpPost("QueryPage")]
|
|
|
|
|
public async Task<Result<PageResult<SwapOrderResp>>> QueryPage([FromBody] QuerySwapOrderPageReq req)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(req.DownBatteryNo)||!string.IsNullOrEmpty(req.UpBatteryNo))
|
|
|
|
|
{
|
|
|
|
|
var result = BatteryCodeList(req);
|
|
|
|
|
return Result<PageResult<SwapOrderResp>>.Success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var swapOrderResp = swapOrderService.QuerySwapOrder(req);
|
|
|
|
|
|
|
|
|
|
//获取所有订单号
|
|
|
|
@ -56,22 +66,27 @@ public class SwapOrderController : ControllerBase
|
|
|
|
|
var config =
|
|
|
|
|
new MapperConfiguration(cfg => cfg.CreateMap<SwapOrderBatteryResp, SwapOrderBattery>().ReverseMap());
|
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
|
|
|
|
|
|
|
|
List<SwapOrderBatteryResp> swapOrderBattery = mapper.Map<List<SwapOrderBatteryResp>>(batteryList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<SwapOrderReportCloud> swapOrderReportClouds = swapOrderReportCloudRepository.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
|
|
|
|
|
|
|
|
|
|
//将电池数据添加到换电订单数据中
|
|
|
|
|
for (int i = 0; i < swapOrderResp.Rows.Count; i++)
|
|
|
|
|
foreach (var row in swapOrderResp.Rows)
|
|
|
|
|
{
|
|
|
|
|
row.BatteryList = swapOrderBattery.Where(battery => battery.SwapOrderSn == row.Sn).ToList();
|
|
|
|
|
queryReportCloudNumBySn.TryGetValue(row.Sn, out int? num);
|
|
|
|
|
row.ReportCloudNum = num ?? 0;
|
|
|
|
|
|
|
|
|
|
var matchingReport = swapOrderReportClouds.FirstOrDefault(r => r.SwapOrderSn == row.Sn);
|
|
|
|
|
if (matchingReport != null)
|
|
|
|
|
{
|
|
|
|
|
swapOrderResp.Rows[i].BatteryList = new List<SwapOrderBatteryResp>();
|
|
|
|
|
swapOrderResp.Rows[i].BatteryList.AddRange(swapOrderBattery
|
|
|
|
|
.Where(battery => battery.SwapOrderSn == swapOrderResp.Rows[i].Sn).ToList());
|
|
|
|
|
queryReportCloudNumBySn.TryGetValue(swapOrderResp.Rows[i].Sn, out int? num);
|
|
|
|
|
if (num == null)
|
|
|
|
|
foreach (var battery in row.BatteryList)
|
|
|
|
|
{
|
|
|
|
|
num = 0;
|
|
|
|
|
battery.Vtm = matchingReport.Vtm;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
swapOrderResp.Rows[i].ReportCloudNum = num;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查询订单步序数据
|
|
|
|
@ -91,10 +106,88 @@ public class SwapOrderController : ControllerBase
|
|
|
|
|
swapOrderResp.Rows[i].StepList
|
|
|
|
|
.AddRange(swapOrderStep.Where(step => step.SwapOrderSn == swapOrderResp.Rows[i].Sn).ToList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Result<PageResult<SwapOrderResp>>.Success(swapOrderResp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private PageResult<SwapOrderResp> BatteryCodeList(QuerySwapOrderPageReq req)
|
|
|
|
|
{
|
|
|
|
|
PageResult<SwapOrderBatteryResp> batteryCodeList = swapOrderBatteryService.QuerySwapOrderBatteryList(req);
|
|
|
|
|
|
|
|
|
|
var batteryOrderSn = batteryCodeList.Rows.Select(row => row.SwapOrderSn).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<SwapOrder> swapOrderRespList = swapOrderService.QueryListByClause(u => batteryOrderSn.Contains(u.Sn));
|
|
|
|
|
//获取所有订单号
|
|
|
|
|
var orderSns = swapOrderRespList.Select(row => row.Sn).ToList();
|
|
|
|
|
|
|
|
|
|
//查询上报云平台次数
|
|
|
|
|
Dictionary<string, int?> queryReportCloudNumBySn = swapOrderService.QueryReportCloudNumBySn(orderSns);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////查询订单电池数据
|
|
|
|
|
List<SwapOrderBattery> batteryList =
|
|
|
|
|
swapOrderBatteryService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
|
|
|
|
|
|
|
|
|
|
var config = new MapperConfiguration(cfg =>
|
|
|
|
|
{
|
|
|
|
|
cfg.CreateMap<SwapOrderResp, SwapOrder>().ReverseMap();
|
|
|
|
|
cfg.CreateMap<SwapOrderBatteryResp, SwapOrderBattery>().ReverseMap();
|
|
|
|
|
});
|
|
|
|
|
//映射
|
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
|
|
|
|
|
|
|
|
List<SwapOrderBatteryResp> swapOrderBattery = mapper.Map<List<SwapOrderBatteryResp>>(batteryList);
|
|
|
|
|
|
|
|
|
|
List<SwapOrderResp> swapOrderResp = mapper.Map<List<SwapOrderResp>>(swapOrderRespList);
|
|
|
|
|
|
|
|
|
|
List<SwapOrderReportCloud> swapOrderReportClouds = swapOrderReportCloudRepository.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//将电池数据添加到换电订单数据中
|
|
|
|
|
foreach (var row in swapOrderResp)
|
|
|
|
|
{
|
|
|
|
|
row.BatteryList = swapOrderBattery.Where(battery => battery.SwapOrderSn == row.Sn).ToList();
|
|
|
|
|
queryReportCloudNumBySn.TryGetValue(row.Sn, out int? num);
|
|
|
|
|
row.ReportCloudNum = num ?? 0;
|
|
|
|
|
|
|
|
|
|
var matchingReport = swapOrderReportClouds.FirstOrDefault(r => r.SwapOrderSn == row.Sn);
|
|
|
|
|
if (matchingReport != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var battery in row.BatteryList)
|
|
|
|
|
{
|
|
|
|
|
battery.Vtm = matchingReport.Vtm;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查询订单步序数据
|
|
|
|
|
var stepList = swapOrderStepService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
|
|
|
|
|
stepList = stepList.OrderBy(s => s.Sort).ToList();
|
|
|
|
|
|
|
|
|
|
//映射
|
|
|
|
|
var config2 = new MapperConfiguration(cfg => cfg.CreateMap<SwapOrderStep, SwapOrderStepResp>().ReverseMap());
|
|
|
|
|
IMapper mapper2 = config2.CreateMapper();
|
|
|
|
|
List<SwapOrderStepResp> swapOrderStep = mapper2.Map<List<SwapOrderStepResp>>(stepList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//将步序数据添加到换电订单数据中
|
|
|
|
|
for (int i = 0; i < swapOrderResp.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
swapOrderResp[i].StepList = new List<SwapOrderStepResp>();
|
|
|
|
|
swapOrderResp[i].StepList
|
|
|
|
|
.AddRange(swapOrderStep.Where(step => step.SwapOrderSn == swapOrderResp[i].Sn).ToList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PageResult<SwapOrderResp> result = new PageResult<SwapOrderResp>()
|
|
|
|
|
{
|
|
|
|
|
PageNum = req.PageNum,
|
|
|
|
|
PageSize = req.PageSize,
|
|
|
|
|
ToTal = batteryCodeList.ToTal,
|
|
|
|
|
Rows = swapOrderResp
|
|
|
|
|
};
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 新增
|
|
|
|
|
/// </summary>
|
|
|
|
@ -261,6 +354,8 @@ public class SwapOrderController : ControllerBase
|
|
|
|
|
dto.UpBatteryNo = swapOrderBatteryResp.UpBatteryNo;
|
|
|
|
|
dto.UpBatterySoc = swapOrderBatteryResp.UpBatterySoc;
|
|
|
|
|
dto.UpBatteryRealSoc = swapOrderBatteryResp.UpBatteryRealSoc;
|
|
|
|
|
dto.DownBatteryBinNo = swapOrderBatteryResp.DownBatteryBinNo;
|
|
|
|
|
dto.UpBatteryBinNo = swapOrderBatteryResp.UpBatteryBinNo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|