You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
5.4 KiB

7 months ago
using AutoMapper;
using Entity.Api.Req;
using Entity.Api.Resp;
7 months ago
using Entity.DbModel.Station;
using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc;
7 months ago
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
7 months ago
using Service.Station;
7 months ago
using System.Collections.Generic;
namespace WebStarter.Controllers;
7 months ago
/// <summary>
/// 换电订单
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class SwapOrderController : ControllerBase
{
7 months ago
private readonly SwapOrderService swapOrderService;
7 months ago
private readonly SwapOrderBatteryService swapOrderBatteryService;
private readonly SwapOrderStepService swapOrderStepService;
public SwapOrderController(SwapOrderService swapOrderService, SwapOrderBatteryService swapOrderBatteryService, SwapOrderStepService swapOrderStepService)
7 months ago
{
this.swapOrderService = swapOrderService;
7 months ago
this.swapOrderBatteryService = swapOrderBatteryService;
this.swapOrderStepService = swapOrderStepService;
7 months ago
}
7 months ago
/// <summary>
7 months ago
/// 查询分页数据
7 months ago
/// </summary>
/// <returns></returns>
[HttpPost("QueryPage")]
public async Task<Result<PageResult<SwapOrderResp>>> QueryPage([FromBody] QuerySwapOrderPageReq req)
{
7 months ago
var swapOrderResp = swapOrderService.QuerySwapOrder(req);
//获取所有订单号
var orderSns = swapOrderResp.Rows.Select(row => row.Sn).ToList();
//电池不要了
////查询订单电池数据
//List< SwapOrderBattery> batteryList = swapOrderBatteryService.QueryListByClause(u => orderSns.Contains(u.SwapOrderSn));
////映射
//var config = new MapperConfiguration(cfg => cfg.CreateMap<SwapOrderBatteryResp,SwapOrderBattery > ().ReverseMap());
//IMapper mapper = config.CreateMapper();
//List<SwapOrderBatteryResp> swapOrderBattery = mapper.Map<List<SwapOrderBatteryResp>>(batteryList);
////将电池数据添加到换电订单数据中
//for (int i = 0; i < swapOrderResp.Rows.Count; i++)
//{
// swapOrderResp.Rows[i].BatteryList = new List<SwapOrderBatteryResp>();
// swapOrderResp.Rows[i].BatteryList.AddRange(swapOrderBattery.Where(battery => battery.SwapOrderSn == swapOrderResp.Rows[i].Sn).ToList());
//}
//查询订单步序数据
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.Rows.Count; i++)
{
swapOrderResp.Rows[i].StepList = new List<SwapOrderStepResp>();
swapOrderResp.Rows[i].StepList.AddRange(swapOrderStep.Where(step => step.SwapOrderSn == swapOrderResp.Rows[i].Sn).ToList());
}
return Result<PageResult<SwapOrderResp>>.Success(swapOrderResp);
7 months ago
}
/// <summary>
/// 新增
/// </summary>
/// <returns></returns>
[HttpPost("Add")]
public async Task<Result<bool>> Add([FromBody] AddSwapOrderReq req)
{
//映射数据
7 months ago
var config = new MapperConfiguration(cfg => cfg.CreateMap<SwapOrder, AddSwapOrderReq>().ReverseMap());
7 months ago
IMapper mapper = config.CreateMapper();
SwapOrder swapOrder = mapper.Map<SwapOrder>(req);
7 months ago
var swap = swapOrderService.QueryByClause(u => u.Sn == req.Sn);
if (swap != null)
7 months ago
{
7 months ago
return Result<bool>.Fail("新增失败!订单号重复");
7 months ago
}
else
{
7 months ago
if (swapOrderService.Insert(swapOrder) != 0)
{
return Result<bool>.Success("新增成功");
}
else
{
return Result<bool>.Fail("新增失败");
}
7 months ago
}
7 months ago
7 months ago
}
/// <summary>
/// 修改换电订单
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost("Modify")]
public async Task<Result<bool>> Modify([FromBody] ModifySwapOrderReq req)
{
7 months ago
//映射数据
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("更改成功");
}
else
{
return Result<bool>.Fail("更改失败");
}
7 months ago
}
/// <summary>
/// 删除
/// </summary>
7 months ago
/// <param name="ids">ids id列表</param>
7 months ago
/// <returns></returns>
[HttpPost("DeleteByIds")]
public async Task<Result<bool>> DeleteByIds([FromBody] List<long> ids)
{
7 months ago
if (swapOrderService.DeleteByIds(ids))
{
return Result<bool>.Success("删除成功");
}
else
{
return Result<bool>.Fail("删除失败");
}
7 months ago
}
7 months ago
7 months ago
/// <summary>
/// 换电订单上报云端
/// </summary>
/// <returns></returns>
[HttpGet("UploadCloud/{id}")]
public async Task<Result<bool>> UploadCloud(long id)
{
return Result<bool>.Success(null);
}
}