diff --git a/Common/Common.csproj b/Common/Common.csproj index 941439a..21eacdf 100644 --- a/Common/Common.csproj +++ b/Common/Common.csproj @@ -8,6 +8,7 @@ + diff --git a/Common/Util/HttpUtil.cs b/Common/Util/HttpUtil.cs index 0ba10df..92c4eb1 100644 --- a/Common/Util/HttpUtil.cs +++ b/Common/Util/HttpUtil.cs @@ -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 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); } } } \ No newline at end of file diff --git a/Entity/Api/Req/QueryChargeOrderReq.cs b/Entity/Api/Req/QueryChargeOrderReq.cs index 2371789..d9f2c8f 100644 --- a/Entity/Api/Req/QueryChargeOrderReq.cs +++ b/Entity/Api/Req/QueryChargeOrderReq.cs @@ -126,5 +126,9 @@ namespace Entity.Api.Req [SugarColumn(ColumnName = "can_upload")] public int? CanUpload { get; set; } + /// + /// 枪号 + /// + public string? OutChargerGunNo { get; set; } } } diff --git a/Entity/Api/Resp/ChargeOrderResp.cs b/Entity/Api/Resp/ChargeOrderResp.cs index d972e6d..f8f7602 100644 --- a/Entity/Api/Resp/ChargeOrderResp.cs +++ b/Entity/Api/Resp/ChargeOrderResp.cs @@ -268,5 +268,14 @@ namespace Entity.Api.Resp /// public decimal? AcElecCount { get; set; } + /// + /// 站外1枪或2枪 + /// + public string OutChargerGunNo { get; set; } + + /// + /// 站内外订单标识 0站内1站外 + /// + public int sign { get; set; } } } diff --git a/Entity/DbModel/Station/ChargeOrder.cs b/Entity/DbModel/Station/ChargeOrder.cs index 0c4c99b..d7c2f44 100644 --- a/Entity/DbModel/Station/ChargeOrder.cs +++ b/Entity/DbModel/Station/ChargeOrder.cs @@ -294,5 +294,11 @@ namespace Entity.DbModel.Station /// [SugarColumn(ColumnName = "reporting_times")] public int ReportingTimes { get; set; } + + /// + /// 站内外订单标识 0站内1站外 + /// + [SugarColumn(ColumnName = "sign")] + public int Sign { get; set; } = 0; } } diff --git a/Service/Cloud/Common/CloudConst.cs b/Service/Cloud/Common/CloudConst.cs index 453b956..4c92382 100644 --- a/Service/Cloud/Common/CloudConst.cs +++ b/Service/Cloud/Common/CloudConst.cs @@ -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"; diff --git a/Service/Cloud/Handler/OutCharger/PileStartChargeHandler.cs b/Service/Cloud/Handler/OutCharger/PileStartChargeHandler.cs index eee497b..72c8262 100644 --- a/Service/Cloud/Handler/OutCharger/PileStartChargeHandler.cs +++ b/Service/Cloud/Handler/OutCharger/PileStartChargeHandler.cs @@ -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); } } \ No newline at end of file diff --git a/Service/Cloud/Handler/OutCharger/PileStopChargeHandler.cs b/Service/Cloud/Handler/OutCharger/PileStopChargeHandler.cs index 01cda9c..53af951 100644 --- a/Service/Cloud/Handler/OutCharger/PileStopChargeHandler.cs +++ b/Service/Cloud/Handler/OutCharger/PileStopChargeHandler.cs @@ -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); } } \ No newline at end of file diff --git a/Service/Cloud/Msg/Cloud/Resp/OutCharger/PileChargeRealtimeResp.cs b/Service/Cloud/Msg/Cloud/Resp/OutCharger/PileChargeRealtimeResp.cs index 789cbd8..583f959 100644 --- a/Service/Cloud/Msg/Cloud/Resp/OutCharger/PileChargeRealtimeResp.cs +++ b/Service/Cloud/Msg/Cloud/Resp/OutCharger/PileChargeRealtimeResp.cs @@ -20,6 +20,6 @@ public class PileChargeRealtimeResp : ICmd public string GetCmd() { - return CloudConst.pileRealtimeRes; + return CloudConst.pileStopChargeRes; } } \ No newline at end of file diff --git a/Service/Cloud/Msg/Cloud/Resp/OutCharger/PileRealtimeResp.cs b/Service/Cloud/Msg/Cloud/Resp/OutCharger/PileRealtimeResp.cs index 254c83a..fb6d20a 100644 --- a/Service/Cloud/Msg/Cloud/Resp/OutCharger/PileRealtimeResp.cs +++ b/Service/Cloud/Msg/Cloud/Resp/OutCharger/PileRealtimeResp.cs @@ -20,6 +20,6 @@ public class PileRealtimeResp : ICmd public string GetCmd() { - return CloudConst.pileRealtimeRes; + return CloudConst.pileStopChargeRes; } } \ No newline at end of file diff --git a/Service/Cloud/Msg/Host/Req/OutCharger/PileEndCharge.cs b/Service/Cloud/Msg/Host/Req/OutCharger/PileEndCharge.cs index 03f842e..d764644 100644 --- a/Service/Cloud/Msg/Host/Req/OutCharger/PileEndCharge.cs +++ b/Service/Cloud/Msg/Host/Req/OutCharger/PileEndCharge.cs @@ -81,7 +81,7 @@ public class PileEndCharge : ICmd /// public int? cesoc { get; set; } - /// + /*/// /// 计费时间段个数 /// public int? ctn { get; set; } @@ -89,8 +89,25 @@ public class PileEndCharge : ICmd /// /// 计费时间段列表 /// - public List ctl { get; set; } + public List ctl { get; set; }*/ + /// + /// 尖时段电量 + /// + public float tp { get; set; } + /// + /// 峰时段电量 + /// + public float pp { get; set; } + /// + /// 平时段电量 + /// + public float fp { get; set; } + /// + /// 谷时段电量 + /// + public float vp { get; set; } + /// /// 充电车辆车架号 /// diff --git a/Service/Cloud/Msg/Host/Resp/OutCharger/PileStopChargeResp.cs b/Service/Cloud/Msg/Host/Resp/OutCharger/PileStopChargeResp.cs index 89c2519..b39bab4 100644 --- a/Service/Cloud/Msg/Host/Resp/OutCharger/PileStopChargeResp.cs +++ b/Service/Cloud/Msg/Host/Resp/OutCharger/PileStopChargeResp.cs @@ -19,6 +19,6 @@ public class PileStopChargeResp : ICmd public string GetCmd() { - return CloudConst.pileRealtimeRes; + return CloudConst.pileStopChargeRes; } } \ No newline at end of file diff --git a/Service/Station/ChargeOrderOutService.cs b/Service/Station/ChargeOrderOutService.cs new file mode 100644 index 0000000..9aac74d --- /dev/null +++ b/Service/Station/ChargeOrderOutService.cs @@ -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; + +/// +/// 站外充电订单 +/// +[Scope("SingleInstance")] +public class ChargeOrderOutService: BaseServices +{ + ChargeOrderRepository chargeOrderRepository; + public ChargeOrderOutService(ChargeOrderRepository dal) + { + chargeOrderRepository = dal; + BaseDal = dal; + } + + /// + /// 根据条件查询分页数据 + /// + /// + /// + public PageResult QueryChargeOrder(QueryChargeOrderReq chargeOrder) + { + + //创建一个空的表达式树 + Expression> where = null; + //// 定义参数表达式 + ParameterExpression parameter = Expression.Parameter(typeof(ChargeOrder), "u"); + + #region 构建动态查询树 + where = queryTree(chargeOrder, where, parameter); + + #endregion + + //查询 + return PageResult.ConvertPage(chargeOrderRepository.QueryIPage(chargeOrder, where)); + + } + /// + /// 导出充电订单 + /// + /// + /// + public async Task ExportChargeOrder(QueryChargeOrderReq chargeOrder) + { + // 查询订单 + List chargeOrders = await QueryChargeOrderListAsync(chargeOrder); + + var config = new MapperConfiguration(cfg => + { cfg.CreateMap().ReverseMap(); }); + IMapper mapper = config.CreateMapper(); + + List list = mapper.Map>(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" }; + } + /// + /// 查询需要导出订单 + /// + /// + /// + public async Task> QueryChargeOrderListAsync(QueryChargeOrderReq chargeOrder) + { + Expression> where = null; + ParameterExpression parameter = Expression.Parameter(typeof(ChargeOrder), "u"); + + #region 构建动态查询树 + where = queryTree(chargeOrder, where, parameter); + #endregion + + // 查询需要导出充电订单 不分页 + return await chargeOrderRepository.QueryChargeOrderList(where); + } + + private static Expression>? queryTree(QueryChargeOrderReq chargeOrder, Expression>? where, ParameterExpression parameter) + { + if (chargeOrder.Id != 0) + { + Expression> condition1Expr = u => u.Id == chargeOrder.Id; + where = condition1Expr; + } + if (!string.IsNullOrEmpty(chargeOrder.Sn)) + { + Expression> condition2Expr = u => u.Sn == chargeOrder.Sn; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + if (!string.IsNullOrEmpty(chargeOrder.BatteryNo)) + { + Expression> condition2Expr = u => u.BatteryNo == chargeOrder.BatteryNo; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + + if (!string.IsNullOrEmpty(chargeOrder.ChargerNo)) + { + Expression> condition2Expr = u => u.ChargerNo == chargeOrder.ChargerNo; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + + // 构建时间范围条件 + if (chargeOrder.StartTime != null && chargeOrder.StartTime != DateTime.MinValue && chargeOrder.EndTime != null && chargeOrder.EndTime != DateTime.MinValue) + { + Expression> conditionExpr = u => u.CreatedTime >= chargeOrder.StartTime && u.CreatedTime <= chargeOrder.EndTime; + where = conditionExpr; + } + + + if (chargeOrder.ChargeTimeCount!=null) + { + Expression> condition2Expr = u => u.ChargeTimeCount == chargeOrder.ChargeTimeCount; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + if (chargeOrder.StopReason != null) + { + Expression> condition2Expr = u => u.StopReason == chargeOrder.StopReason; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + if (!string.IsNullOrEmpty(chargeOrder.ElecPriceModelVersion)) + { + Expression> condition2Expr = u => u.ElecPriceModelVersion == chargeOrder.ElecPriceModelVersion; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + if (!string.IsNullOrEmpty(chargeOrder.SwapOrderSn)) + { + Expression> condition2Expr = u => u.SwapOrderSn == chargeOrder.SwapOrderSn; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + if (chargeOrder.CloudReportStatus != null) + { + Expression> condition2Expr = u => u.CloudReportStatus == chargeOrder.CloudReportStatus; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + if (!string.IsNullOrEmpty(chargeOrder.CloudChargeOrder)) + { + Expression> condition2Expr = u => u.CloudChargeOrder == chargeOrder.CloudChargeOrder; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + if (!string.IsNullOrEmpty(chargeOrder.OutChargerGunNo)) + { + Expression> condition2Expr = u => u.OutChargerGunNo == chargeOrder.OutChargerGunNo; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + + //站外 + { + Expression> condition2Expr = u => u.Sign == 1; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } + + return where; + } + + + /// + /// 充电订单手动上传云平台 + /// + /// + /// + public Result Upload2Cloud(string id) + { + List orders01 = BaseDal.QueryListByClause(it => it.Id == Convert.ToInt32(id)); + + List orders = BaseDal.QueryListByClause(it => it.CloudChargeOrder == orders01[0].CloudChargeOrder); + + if (ObjUtils.IsEmpty(orders)) + { + return Result.Fail("数据不存在"); + } + + if ( orders[0].CloudReportStatus == 1) + { + return Result.Success(true, "已经上传到云平台"); + } + + CloudClientMgr.CloudClient?.PublishChargeOrder(orders, 2); + return Result.Success(); + } + /// + /// 获取每日充电订单 + /// + /// + public List DayChargeOrder() + { + // 获取今天的日期 + DateTime today = DateTime.Today; + + // 昨天 00:00 + DateTime startOfYesterday = today.AddDays(-1); + + // 昨天 23:59:59 + DateTime endOfYesterday = startOfYesterday.AddDays(1).AddTicks(-1); + + Expression> predicate = x => x.StartTime >= startOfYesterday && x.StartTime <= endOfYesterday; + + return QueryListByClause(predicate); + } +} \ No newline at end of file diff --git a/Service/Station/ChargeOrderService.cs b/Service/Station/ChargeOrderService.cs index e9695b1..702b21a 100644 --- a/Service/Station/ChargeOrderService.cs +++ b/Service/Station/ChargeOrderService.cs @@ -154,6 +154,11 @@ public class ChargeOrderService : BaseServices Expression> condition2Expr = u => u.CloudChargeOrder == chargeOrder.CloudChargeOrder; where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); } + + { + Expression> condition2Expr = u => u.Sign == 0; + where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + } return where; } diff --git a/WebStarter/Controllers/ChargeOrderOutController.cs b/WebStarter/Controllers/ChargeOrderOutController.cs new file mode 100644 index 0000000..33c1230 --- /dev/null +++ b/WebStarter/Controllers/ChargeOrderOutController.cs @@ -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; + +/// +/// 充电订单 +/// +[ApiController] +[Route("api/[controller]")] +public class ChargeOrderOutController : ControllerBase +{ + private readonly ChargeOrderOutService chargeOrderService; + + public ChargeOrderOutController(ChargeOrderOutService chargeOrderService) + { + this.chargeOrderService = chargeOrderService; + } + + /// + /// 查询分页数据 + /// + /// + [HttpPost("QueryPage")] + public async Task>> QueryPage([FromBody] QueryChargeOrderReq req) + { + PageResult queryChargeOrder = chargeOrderService.QueryChargeOrder(req); + return Result>.Success(queryChargeOrder); + } + + /// + /// 修改充电订单 + /// + /// + /// + [HttpPost("Modify")] + public async Task> Modify([FromBody] ModifyChargeOrderReq req) + { + //映射数据 + var config = new MapperConfiguration(cfg => cfg.CreateMap().ReverseMap()); + IMapper mapper = config.CreateMapper(); + ChargeOrder chargeOrder = mapper.Map(req); + + if (chargeOrderService.Update(chargeOrder)) + { + return Result.Success(true,"更改成功"); + } + else + { + return Result.Fail("更改失败"); + } + + } + + /// + /// 充电订单导出 + /// + /// + /// + [HttpPost] + [Route("export")] + public async Task ExportChargeOrder([FromBody] QueryChargeOrderReq req) + { + return await chargeOrderService.ExportChargeOrder(req); + } + /// + /// 充电订单上报云端,入参传 CloudChargeOrder + /// + /// + [HttpGet("UploadCloud/{id}")] + public Result UploadCloud(string id) + { + return chargeOrderService.Upload2Cloud(id); + } +} \ No newline at end of file