云平台测试更改

master
CZ 3 months ago
parent 5604e08a7f
commit e608310ae0

@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="BouncyCastle" Version="1.8.9" />
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.34" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />

@ -1,4 +1,5 @@
using System.Text;
using log4net;
using Newtonsoft.Json;
namespace Common.Util;
@ -6,17 +7,24 @@ namespace Common.Util;
public static class HttpUtil
{
private static readonly HttpClient httpClient = new HttpClient();
private static readonly ILog Log = LogManager.GetLogger(typeof(HttpUtil));
public static async void SendPostRequest<T>(T data, string url)
{
string jsonStr = JsonConvert.SerializeObject(data);
var content = new StringContent(jsonStr, Encoding.UTF8, "application/json");
try
{
string jsonStr = JsonConvert.SerializeObject(data);
var content = new StringContent(jsonStr, Encoding.UTF8, "application/json");
HttpResponseMessage response = await httpClient.PostAsync(url, content);
HttpResponseMessage response = await httpClient.PostAsync(url, content);
if (response.IsSuccessStatusCode)
if (response.IsSuccessStatusCode)
{
await response.Content.ReadAsStringAsync();
}
}
catch (Exception e)
{
await response.Content.ReadAsStringAsync();
Log.Info("HttpUtil SendPostRequest Error:"+e.StackTrace);
}
}
}

@ -126,5 +126,9 @@ namespace Entity.Api.Req
[SugarColumn(ColumnName = "can_upload")]
public int? CanUpload { get; set; }
/// <summary>
/// 枪号
/// </summary>
public string? OutChargerGunNo { get; set; }
}
}

@ -268,5 +268,14 @@ namespace Entity.Api.Resp
/// </summary>
public decimal? AcElecCount { get; set; }
/// <summary>
/// 站外1枪或2枪
/// </summary>
public string OutChargerGunNo { get; set; }
/// <summary>
/// 站内外订单标识 0站内1站外
/// </summary>
public int sign { get; set; }
}
}

@ -294,5 +294,11 @@ namespace Entity.DbModel.Station
/// </summary>
[SugarColumn(ColumnName = "reporting_times")]
public int ReportingTimes { get; set; }
/// <summary>
/// 站内外订单标识 0站内1站外
/// </summary>
[SugarColumn(ColumnName = "sign")]
public int Sign { get; set; } = 0;
}
}

@ -98,7 +98,7 @@ public class CloudConst
public static readonly string pileStartChargeRes = "pileStartChargeRes";
public static readonly string pileStopCharge = "pileStopCharge";
public static readonly string pileRealtimeRes = "pileRealtimeRes";
public static readonly string pileStopChargeRes = "pileStopChargeRes";
public static readonly string pileEndCharge = "pileEndCharge";
public static readonly string pileEndChargeRes = "pileEndChargeRes";

@ -3,8 +3,10 @@ using Common.Util;
using HybirdFrameworkCore.Autofac.Attribute;
using NewLife.Remoting;
using Newtonsoft.Json;
using Service.Cloud.Client;
using Service.Cloud.Common;
using Service.Cloud.Msg.Cloud.Req.OutCharger.Req;
using Service.Cloud.Msg.Host.Resp.OutCharger;
namespace Service.Cloud.Handler.OutCharger;
@ -23,5 +25,13 @@ public class PileStartChargeHandler : IBaseHandler
{
HttpUtil.SendPostRequest(pileStartCharge, "http://127.0.0.1:5035/api/OutCharger/SendStartOutCharger");
}
PileStartChargeResp res = new()
{
rs="1",
con=pileStartCharge.con,
pn=pileStartCharge.pn,
};
CloudClientMgr.CloudClient?.Publish(res);
}
}

@ -2,8 +2,10 @@
using Common.Util;
using HybirdFrameworkCore.Autofac.Attribute;
using Newtonsoft.Json;
using Service.Cloud.Client;
using Service.Cloud.Common;
using Service.Cloud.Msg.Cloud.Req.OutCharger.Req;
using Service.Cloud.Msg.Cloud.Resp.OutCharger;
namespace Service.Cloud.Handler.OutCharger;
@ -22,5 +24,12 @@ public class PileStopChargeHandler : IBaseHandler
{
HttpUtil.SendPostRequest(pileStopCharge, "http://127.0.0.1:5035/api/OutCharger/SendStopOutCharger");
}
PileRealtimeResp res = new()
{
rs="1",
pn=pileStopCharge.pn,
};
CloudClientMgr.CloudClient?.Publish(res);
}
}

@ -20,6 +20,6 @@ public class PileChargeRealtimeResp : ICmd
public string GetCmd()
{
return CloudConst.pileRealtimeRes;
return CloudConst.pileStopChargeRes;
}
}

@ -20,6 +20,6 @@ public class PileRealtimeResp : ICmd
public string GetCmd()
{
return CloudConst.pileRealtimeRes;
return CloudConst.pileStopChargeRes;
}
}

@ -81,7 +81,7 @@ public class PileEndCharge : ICmd
/// </summary>
public int? cesoc { get; set; }
/// <summary>
/*/// <summary>
/// 计费时间段个数
/// </summary>
public int? ctn { get; set; }
@ -89,8 +89,25 @@ public class PileEndCharge : ICmd
/// <summary>
/// 计费时间段列表
/// </summary>
public List<string> ctl { get; set; }
public List<Ctl> ctl { get; set; }*/
/// <summary>
/// 尖时段电量
/// </summary>
public float tp { get; set; }
/// <summary>
/// 峰时段电量
/// </summary>
public float pp { get; set; }
/// <summary>
/// 平时段电量
/// </summary>
public float fp { get; set; }
/// <summary>
/// 谷时段电量
/// </summary>
public float vp { get; set; }
/// <summary>
/// 充电车辆车架号
/// </summary>

@ -19,6 +19,6 @@ public class PileStopChargeResp : ICmd
public string GetCmd()
{
return CloudConst.pileRealtimeRes;
return CloudConst.pileStopChargeRes;
}
}

@ -0,0 +1,212 @@
using System.Linq.Expressions;
using AutoMapper;
using Entity.Api.Req;
using Entity.Api.Resp;
using Entity.DbModel.Station;
using Entity.Dto;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
using HybirdFrameworkCore.Utils;
using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Mvc;
using Repository.Station;
using Service.Cloud.Client;
namespace Service.Station;
/// <summary>
/// 站外充电订单
/// </summary>
[Scope("SingleInstance")]
public class ChargeOrderOutService: BaseServices<ChargeOrder>
{
ChargeOrderRepository chargeOrderRepository;
public ChargeOrderOutService(ChargeOrderRepository dal)
{
chargeOrderRepository = dal;
BaseDal = dal;
}
/// <summary>
/// 根据条件查询分页数据
/// </summary>
/// <param name="equipAlarmLevel"></param>
/// <returns></returns>
public PageResult<ChargeOrderResp> QueryChargeOrder(QueryChargeOrderReq chargeOrder)
{
//创建一个空的表达式树
Expression<Func<ChargeOrder, bool>> where = null;
//// 定义参数表达式
ParameterExpression parameter = Expression.Parameter(typeof(ChargeOrder), "u");
#region 构建动态查询树
where = queryTree(chargeOrder, where, parameter);
#endregion
//查询
return PageResult<ChargeOrderResp>.ConvertPage(chargeOrderRepository.QueryIPage(chargeOrder, where));
}
/// <summary>
/// 导出充电订单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<IActionResult> ExportChargeOrder(QueryChargeOrderReq chargeOrder)
{
// 查询订单
List<ChargeOrder> chargeOrders = await QueryChargeOrderListAsync(chargeOrder);
var config = new MapperConfiguration(cfg =>
{ cfg.CreateMap<ChargeOrderDto, ChargeOrder>().ReverseMap(); });
IMapper mapper = config.CreateMapper();
List<ChargeOrderDto> list = mapper.Map<List<ChargeOrderDto>>(chargeOrders);
IExcelExporter excelExporter = new ExcelExporter();
var res = await excelExporter.ExportAsByteArray(list);
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "充电订单.xlsx" };
}
/// <summary>
/// 查询需要导出订单
/// </summary>
/// <param name="chargeOrder"></param>
/// <returns></returns>
public async Task<List<ChargeOrder>> QueryChargeOrderListAsync(QueryChargeOrderReq chargeOrder)
{
Expression<Func<ChargeOrder, bool>> where = null;
ParameterExpression parameter = Expression.Parameter(typeof(ChargeOrder), "u");
#region 构建动态查询树
where = queryTree(chargeOrder, where, parameter);
#endregion
// 查询需要导出充电订单 不分页
return await chargeOrderRepository.QueryChargeOrderList(where);
}
private static Expression<Func<ChargeOrder, bool>>? queryTree(QueryChargeOrderReq chargeOrder, Expression<Func<ChargeOrder, bool>>? where, ParameterExpression parameter)
{
if (chargeOrder.Id != 0)
{
Expression<Func<ChargeOrder, bool>> condition1Expr = u => u.Id == chargeOrder.Id;
where = condition1Expr;
}
if (!string.IsNullOrEmpty(chargeOrder.Sn))
{
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.Sn == chargeOrder.Sn;
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (!string.IsNullOrEmpty(chargeOrder.BatteryNo))
{
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.BatteryNo == chargeOrder.BatteryNo;
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (!string.IsNullOrEmpty(chargeOrder.ChargerNo))
{
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.ChargerNo == chargeOrder.ChargerNo;
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
// 构建时间范围条件
if (chargeOrder.StartTime != null && chargeOrder.StartTime != DateTime.MinValue && chargeOrder.EndTime != null && chargeOrder.EndTime != DateTime.MinValue)
{
Expression<Func<ChargeOrder, bool>> conditionExpr = u => u.CreatedTime >= chargeOrder.StartTime && u.CreatedTime <= chargeOrder.EndTime;
where = conditionExpr;
}
if (chargeOrder.ChargeTimeCount!=null)
{
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.ChargeTimeCount == chargeOrder.ChargeTimeCount;
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (chargeOrder.StopReason != null)
{
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.StopReason == chargeOrder.StopReason;
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (!string.IsNullOrEmpty(chargeOrder.ElecPriceModelVersion))
{
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.ElecPriceModelVersion == chargeOrder.ElecPriceModelVersion;
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (!string.IsNullOrEmpty(chargeOrder.SwapOrderSn))
{
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.SwapOrderSn == chargeOrder.SwapOrderSn;
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (chargeOrder.CloudReportStatus != null)
{
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.CloudReportStatus == chargeOrder.CloudReportStatus;
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (!string.IsNullOrEmpty(chargeOrder.CloudChargeOrder))
{
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.CloudChargeOrder == chargeOrder.CloudChargeOrder;
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
if (!string.IsNullOrEmpty(chargeOrder.OutChargerGunNo))
{
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.OutChargerGunNo == chargeOrder.OutChargerGunNo;
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
//站外
{
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.Sign == 1;
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
return where;
}
/// <summary>
/// 充电订单手动上传云平台
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public Result<bool> Upload2Cloud(string id)
{
List<ChargeOrder> orders01 = BaseDal.QueryListByClause(it => it.Id == Convert.ToInt32(id));
List<ChargeOrder> orders = BaseDal.QueryListByClause(it => it.CloudChargeOrder == orders01[0].CloudChargeOrder);
if (ObjUtils.IsEmpty(orders))
{
return Result<bool>.Fail("数据不存在");
}
if ( orders[0].CloudReportStatus == 1)
{
return Result<bool>.Success(true, "已经上传到云平台");
}
CloudClientMgr.CloudClient?.PublishChargeOrder(orders, 2);
return Result<bool>.Success();
}
/// <summary>
/// 获取每日充电订单
/// </summary>
/// <returns></returns>
public List<ChargeOrder> DayChargeOrder()
{
// 获取今天的日期
DateTime today = DateTime.Today;
// 昨天 00:00
DateTime startOfYesterday = today.AddDays(-1);
// 昨天 23:59:59
DateTime endOfYesterday = startOfYesterday.AddDays(1).AddTicks(-1);
Expression<Func<ChargeOrder, bool>> predicate = x => x.StartTime >= startOfYesterday && x.StartTime <= endOfYesterday;
return QueryListByClause(predicate);
}
}

@ -154,6 +154,11 @@ public class ChargeOrderService : BaseServices<ChargeOrder>
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.CloudChargeOrder == chargeOrder.CloudChargeOrder;
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
{
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.Sign == 0;
where = where == null ? condition2Expr : Expression.Lambda<Func<ChargeOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
}
return where;
}

@ -0,0 +1,80 @@
using AutoMapper;
using Entity.Api.Req;
using Entity.Api.Resp;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc;
using Service.Station;
namespace WebStarter.Controllers;
/// <summary>
/// 充电订单
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class ChargeOrderOutController : ControllerBase
{
private readonly ChargeOrderOutService chargeOrderService;
public ChargeOrderOutController(ChargeOrderOutService chargeOrderService)
{
this.chargeOrderService = chargeOrderService;
}
/// <summary>
/// 查询分页数据
/// </summary>
/// <returns></returns>
[HttpPost("QueryPage")]
public async Task<Result<PageResult<ChargeOrderResp>>> QueryPage([FromBody] QueryChargeOrderReq req)
{
PageResult<ChargeOrderResp> queryChargeOrder = chargeOrderService.QueryChargeOrder(req);
return Result<PageResult<ChargeOrderResp>>.Success(queryChargeOrder);
}
/// <summary>
/// 修改充电订单
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost("Modify")]
public async Task<Result<bool>> Modify([FromBody] ModifyChargeOrderReq req)
{
//映射数据
var config = new MapperConfiguration(cfg => cfg.CreateMap<ChargeOrder, ModifyChargeOrderReq>().ReverseMap());
IMapper mapper = config.CreateMapper();
ChargeOrder chargeOrder = mapper.Map<ChargeOrder>(req);
if (chargeOrderService.Update(chargeOrder))
{
return Result<bool>.Success(true,"更改成功");
}
else
{
return Result<bool>.Fail("更改失败");
}
}
/// <summary>
/// 充电订单导出
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost]
[Route("export")]
public async Task<IActionResult> ExportChargeOrder([FromBody] QueryChargeOrderReq req)
{
return await chargeOrderService.ExportChargeOrder(req);
}
/// <summary>
/// 充电订单上报云端,入参传 CloudChargeOrder
/// </summary>
/// <returns></returns>
[HttpGet("UploadCloud/{id}")]
public Result<bool> UploadCloud(string id)
{
return chargeOrderService.Upload2Cloud(id);
}
}
Loading…
Cancel
Save