Browse Source

1. 台泥新增功能
------------------
a.新增DataTransfer ID_GetTxUserInfo(收到StartTransaction 丟給電樁),取得資訊後回報到客戶後台
b.下發時區 TimeOffset
c. Fix扣款回報 Request 格式 (ID_CreditDeductResult)

Jessica Tseng 3 years ago
parent
commit
defcf52c68

BIN
EVCB_OCPP.WSServer/DLL/EVCB_OCPP.Packet.dll


+ 19 - 0
EVCB_OCPP.WSServer/Dto/ID_GetTxUserInfo.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EVCB_OCPP.WSServer.Dto
+{
+    public class ID_GetTxUserInfo
+    {
+        public string TxId { set; get; }
+
+        public Guid? SerialNo { set; get; }
+
+        public int ConnectorId { set; get; }
+
+        public DateTime StartTime { set; get; }
+    }
+}

+ 1 - 0
EVCB_OCPP.WSServer/EVCB_OCPP.WSServer.csproj

@@ -133,6 +133,7 @@
   <ItemGroup>
     <Compile Include="Dto\ChargingPrice.cs" />
     <Compile Include="Dto\ErrorDetails.cs" />
+    <Compile Include="Dto\ID_GetTxUserInfo.cs" />
     <Compile Include="Dto\StationFee.cs" />
     <Compile Include="Dto\TCCWeatherDto.cs" />
     <Compile Include="Dto\TransactionEnergy.cs" />

+ 80 - 3
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -80,12 +80,15 @@ namespace EVCB_OCPP.WSServer.Message
                                         TotalCost = creditDeductResult.amount,
 
                                     };
-
+                                    logger.Debug(string.Format("URL:{0}", GlobalConfig.TCC_API_URL + "prepare_issue_invoice"));
+                                    logger.Debug(JsonConvert.SerializeObject(report));
                                     var response = await httpClient.Post(GlobalConfig.TCC_API_URL + "prepare_issue_invoice", new Dictionary<string, string>()
                                         {
                                             { "PartnerId",session.CustomerId.ToString()}
 
-                                        }, JsonConvert.SerializeObject(report, GlobalConfig.JSONSERIALIZER_FORMAT), GlobalConfig.TCC_SALTKEY);
+                                        }, report, GlobalConfig.TCC_SALTKEY);
+
+                                    logger.Debug(JsonConvert.SerializeObject(response));
                                 }
 
 
@@ -661,6 +664,7 @@ namespace EVCB_OCPP.WSServer.Message
             {
                 switch (action)
                 {
+                    
                     case Actions.DataTransfer:
                         {
                             DataTransferConfirmation _confirm = confirm as DataTransferConfirmation;
@@ -700,7 +704,7 @@ namespace EVCB_OCPP.WSServer.Message
                                         List<ChargingBill> bill = new List<ChargingBill>();
                                         List<ChargingPrice> chargingPrices = new List<ChargingPrice>();
                                         var txEnergy = JsonConvert.DeserializeObject<TransactionEnergy>(_confirm.data);
-                                        var feedto = db.TransactionRecord.Where(x => x.Id == txEnergy.TxId).Select(x => new { Fee = x.Fee, StopTime = x.StopTime, StartTime = x.StartTime }).FirstOrDefault();
+                                        var feedto = db.TransactionRecord.Where(x => x.Id == txEnergy.TxId).Select(x => new { Id = x.Id, ConnectorId = x.ConnectorId, Fee = x.Fee, StopTime = x.StopTime, StartTime = x.StartTime }).FirstOrDefault();
 
                                         if (feedto == null || string.IsNullOrEmpty(feedto.Fee)) return result;
                                         string currency = feedto.Fee.Substring(feedto.Fee.Length - 3);
@@ -879,6 +883,30 @@ namespace EVCB_OCPP.WSServer.Message
 
                                             db.SaveChanges();
 
+                                            using (var meterdb = new MeterValueDBContext())
+                                            {
+                                                string sp = "[dbo].[uspInsertMeterValueRecord] @ChargeBoxId," +
+                                   "@ConnectorId,@Value,@CreatedOn,@ContextId,@FormatId,@MeasurandId,@PhaseId,@LocationId,@UnitId,@TransactionId";
+
+                                                List<SqlParameter> parameter = new List<SqlParameter>
+                                                {
+                                                      new SqlParameter("ChargeBoxId",session.ChargeBoxId),
+                                                      new SqlParameter("ConnectorId",  (byte)feedto.ConnectorId),
+                                                      new SqlParameter("Value",sum),
+                                                      new SqlParameter("CreatedOn",DateTime.UtcNow),
+                                                      new SqlParameter("ContextId",(int)ReadingContext.Sample_Periodic),
+                                                      new SqlParameter("FormatId",(int)ValueFormat.Raw),
+                                                      new SqlParameter("MeasurandId",(int)Measurand.TotalCost),
+                                                      new SqlParameter("PhaseId", -1),
+                                                      new SqlParameter("LocationId", -1),
+                                                      new SqlParameter("UnitId", -1),
+                                                      new SqlParameter("TransactionId",feedto.Id),
+                                                };
+
+
+                                                meterdb.Database.ExecuteSqlCommand(sp, parameter.ToArray());
+                                            }
+
                                             using (SqlConnection conn = new SqlConnection(webConnectionString))
                                             {
                                                 var parameters = new DynamicParameters();
@@ -951,12 +979,61 @@ namespace EVCB_OCPP.WSServer.Message
                                             }); ;
 
                                             db.SaveChanges();
+
+                                            using (var meterdb = new MeterValueDBContext())
+                                            {
+                                                string sp = "[dbo].[uspInsertMeterValueRecord] @ChargeBoxId," +
+                       "@ConnectorId,@Value,@CreatedOn,@ContextId,@FormatId,@MeasurandId,@PhaseId,@LocationId,@UnitId,@TransactionId";
+
+                                                List<SqlParameter> parameter = new List<SqlParameter>
+                                                {
+                                                      new SqlParameter("ChargeBoxId",session.ChargeBoxId),
+                                                      new SqlParameter("ConnectorId",  (byte)feedto.ConnectorId),
+                                                      new SqlParameter("Value",sum),
+                                                      new SqlParameter("CreatedOn",DateTime.UtcNow),
+                                                      new SqlParameter("ContextId",(int)ReadingContext.Sample_Periodic),
+                                                      new SqlParameter("FormatId",(int)ValueFormat.Raw),
+                                                      new SqlParameter("MeasurandId",(int)Measurand.ChargingCost),
+                                                      new SqlParameter("PhaseId", -1),
+                                                      new SqlParameter("LocationId", -1),
+                                                      new SqlParameter("UnitId", -1),
+                                                      new SqlParameter("TransactionId",feedto.Id),
+                                                };
+
+
+                                                meterdb.Database.ExecuteSqlCommand(sp, parameter.ToArray());
+                                            }
+
                                         }
 
 
                                     }
 
 
+                                }
+                                if(_request.messageId== "ID_GetTxUserInfo")
+                                {
+                                    var txUserInfo = JsonConvert.DeserializeObject<ID_GetTxUserInfo>(_confirm.data);
+                                    if (session.CustomerId == new Guid("009E603C-79CD-4620-A2B8-D9349C0E8AD8"))
+                                    {
+                                        var request = new
+                                        {
+                                            ChargeBoxId = session.ChargeBoxId,
+                                            ConnectorId = txUserInfo.ConnectorId,
+                                            SessionId = txUserInfo.TxId,
+                                            SerialNo = txUserInfo.SerialNo,
+                                            StartTime = txUserInfo.StartTime.ToString(GlobalConfig.UTC_DATETIMEFORMAT)
+                                        };
+                                      
+                                        var response =  httpClient.Post(GlobalConfig.TCC_API_URL + "start_session", new Dictionary<string, string>()
+                                        {
+                                            { "PartnerId",session.CustomerId.ToString()}
+
+                                        }, request, GlobalConfig.TCC_SALTKEY);
+
+                                        logger.Debug(JsonConvert.SerializeObject(response));
+                                    }
+
                                 }
                             }
                         }

+ 1 - 1
EVCB_OCPP.WSServer/Properties/AssemblyInfo.cs

@@ -35,4 +35,4 @@ using System.Runtime.InteropServices;
 [assembly: AssemblyVersion("0.1.0.0")]
 [assembly: AssemblyFileVersion("0.1.0.0")]
 
-[assembly: AssemblyInformationalVersion("cb3c28e")]
+[assembly: AssemblyInformationalVersion("2b889db")]

+ 55 - 2
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -801,14 +801,36 @@ namespace EVCB_OCPP.WSServer
                                                     InMessage = string.Empty
 
                                                 });
+
+
+                                                db.ServerMessage.Add(new ServerMessage()
+                                                {
+                                                    ChargeBoxId = session.ChargeBoxId,
+                                                    CreatedBy = "Server",
+                                                    CreatedOn = DateTime.UtcNow,
+                                                    OutAction = Actions.ChangeConfiguration.ToString(),
+                                                    OutRequest = JsonConvert.SerializeObject(
+                                                         new ChangeConfigurationRequest()
+                                                         {
+                                                              key= "TimeOffset",
+                                                              value= "+08:00"
+
+                                                         },
+                                                         new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
+                                                    SerialNo = Guid.NewGuid().ToString(),
+                                                    InMessage = string.Empty
+
+                                                });
+
+
                                                 if (!TCCStationDic.ContainsKey(session.StationLocation))
                                                 {
-                                                    Console.WriteLine("!TCCStationDic.ContainsKey(session.StationLocation)" + session.ChargeBoxId);
+
                                                     _CheckWeatherDt = DateTime.UtcNow.AddDays(-1);
                                                 }
                                                 else
                                                 {
-                                                    Console.WriteLine("TCCStationDic.ContainsKey(session.StationLocation)" + session.ChargeBoxId);
+
                                                     db.ServerMessage.Add(new ServerMessage()
                                                     {
                                                         ChargeBoxId = session.ChargeBoxId,
@@ -853,6 +875,37 @@ namespace EVCB_OCPP.WSServer
                                     }
                                 }
 
+
+                                if (action == Actions.StartTransaction && session.CustomerId == new Guid("009E603C-79CD-4620-A2B8-D9349C0E8AD8") && replyResult.Message is StartTransactionConfirmation)
+                                {
+
+                                    StartTransactionConfirmation confirm = (StartTransactionConfirmation)replyResult.Message;
+                                    StartTransactionRequest request = (StartTransactionRequest)analysisResult.Message;
+                                    using (var db = new MainDBContext())
+                                    {
+                                        db.ServerMessage.Add(new ServerMessage()
+                                        {
+                                            ChargeBoxId = session.ChargeBoxId,
+                                            CreatedBy = "Server",
+                                            CreatedOn = DateTime.UtcNow,
+                                            OutAction = Actions.DataTransfer.ToString(),
+                                            OutRequest = JsonConvert.SerializeObject(
+                                                    new DataTransferRequest()
+                                                    {
+                                                        messageId = "ID_GetTxUserInfo",
+                                                        vendorId = "Phihong Technology",
+                                                        data = JsonConvert.SerializeObject(new { txId = confirm.transactionId, ConnectorId = request.connectorId })
+                                                    },
+                                                    new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
+                                            SerialNo = Guid.NewGuid().ToString(),
+                                            InMessage = string.Empty
+
+                                        });
+
+                                        db.SaveChanges();
+                                    }
+                                }
+
                             }
                             else
                             {