Переглянути джерело

1. UCAR Auth 拿掉自動允許功能
2.台泥
a.StationName 改下發郵遞區號
b.DataTransfer ID_CreditDeductResult增加參數

Jessica Tseng 3 роки тому
батько
коміт
8eebb1dd86

+ 2 - 2
EVCB_OCPP.WSServer/Dto/TTCStationInfoDto.cs → EVCB_OCPP.WSServer/Dto/TCCStationInfoDto.cs

@@ -6,13 +6,13 @@ using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Dto
 {
-    public class TTCStationInfoDto
+    public class TCCStationInfoDto
     {
         public decimal Lat { set; get; }
 
         public decimal Long { set; get; }
 
-        public string Name { set; get; }
+        public string ZipCode { set; get; }
 
     }
 }

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

@@ -136,7 +136,7 @@
     <Compile Include="Dto\StationFee.cs" />
     <Compile Include="Dto\TCCWeatherDto.cs" />
     <Compile Include="Dto\TransactionEnergy.cs" />
-    <Compile Include="Dto\TTCStationInfoDto.cs" />
+    <Compile Include="Dto\TCCStationInfoDto.cs" />
     <Compile Include="Message\OCPP16MessageHandler.cs" />
     <Compile Include="Message\OCPP20MessageHandler.cs" />
     <Compile Include="Message\SecurityProfileHandler.cs" />

+ 4 - 0
EVCB_OCPP.WSServer/GlobalConfig.cs

@@ -14,6 +14,10 @@ namespace EVCB_OCPP.WSServer
             ""
         };
 
+        public static string TCC_API_URL = string.Empty;
+
+        public static string TCC_SALTKEY = string.Empty;
+
 
         /// <summary>
         /// 預設心跳間隔時間 單位:秒

+ 54 - 8
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -24,12 +24,29 @@ using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Message
 {
+    public class ID_CreditDeductResult
+    {
+        public int txId { set; get; }
+
+        public string creditNo { set; get; }
+
+
+        public bool deductResult { set; get; }
+
+        public bool isDonateInvoice { set; get; }
+
+
+        public decimal amount { set; get; }
+
+        public string approvalNo { set; get; }
+
+    }
 
     internal partial class ProfileHandler
     {
         static private ILogger logger = NLog.LogManager.GetCurrentClassLogger();
         string webConnectionString = ConfigurationManager.ConnectionStrings["WebDBContext"].ConnectionString;
-
+        private OuterHttpClient httpClient = new OuterHttpClient();
         async internal Task<MessageResult> ExecuteCoreRequest(Actions action, ClientData session, IRequest request)
         {
             Stopwatch watch = new Stopwatch();
@@ -45,9 +62,38 @@ namespace EVCB_OCPP.WSServer.Message
                 {
                     case Actions.DataTransfer:
                         {
+                            DataTransferRequest _request = request as DataTransferRequest;
+                            var creditDeductResult = JsonConvert.DeserializeObject<ID_CreditDeductResult>(_request.data);
+                            var confirm = new DataTransferConfirmation() { status = DataTransferStatus.Accepted };
+                            if (_request.messageId == "ID_CreditDeductResult")
+                            {
+                                if (session.CustomerId == new Guid("009E603C-79CD-4620-A2B8-D9349C0E8AD8"))
+                                {
+                                    var report = new
+                                    {
+                                        ChargeBoxId = session.ChargeBoxId,
+                                        IsDonateInvoice = creditDeductResult.isDonateInvoice,
+                                        CreditNo = creditDeductResult.creditNo,
+                                        DeductResult = creditDeductResult.deductResult,
+                                        SessionId = creditDeductResult.txId,
+                                        approvalNo= creditDeductResult.approvalNo,
+                                        amount = creditDeductResult.amount,
+
+                                    };
+
+                                    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);
+                                }
+
+
+
+                                confirm.data = JsonConvert.SerializeObject(new { txId = creditDeductResult.txId, creditNo = creditDeductResult.creditNo, msgId = _request.messageId });
+                            }
 
 
-                            var confirm = new DataTransferConfirmation() { status = DataTransferStatus.Accepted };
 
                             result.Message = confirm;
                             result.Success = true;
@@ -717,7 +763,7 @@ namespace EVCB_OCPP.WSServer.Message
 
                                         if (feedto.StopTime != GlobalConfig.DefaultNullTime)
                                         {
-                                            
+
                                             // 計算停車費
                                             var fee = decimal.Parse(feedto.Fee.Split('&')[1]);
                                             decimal accountBalance = 0;
@@ -746,30 +792,30 @@ namespace EVCB_OCPP.WSServer.Message
                                                 if (bill.Count == 1)
                                                 {
                                                     confirmbill = bill;
-                                                    receipt += string.Format("| {0} - {1}:| {2} kWh @ ${3}/kWh=${4}", tx.StartTime.ToString("hh:mm tt", new CultureInfo("en-us")),confirmbill[0].PeriodEnergy.ToString("0.0000"), tx.StopTime.ToString("hh:mm tt", new CultureInfo("en-us")), bill[0].Fee, bill[0].Total);
+                                                    receipt += string.Format("| {0} - {1}:| {2} kWh @ ${3}/kWh=${4}", tx.StartTime.ToString("hh:mm tt", new CultureInfo("en-us")), confirmbill[0].PeriodEnergy.ToString("0.0000"), tx.StopTime.ToString("hh:mm tt", new CultureInfo("en-us")), bill[0].Fee, bill[0].Total);
                                                     break;
                                                 }
                                                 if (bill.Count > 1)
                                                 {
                                                     var time = startTime.ToString("hh:mm tt", new CultureInfo("en-us"));
-                                                    var tt = bill.Where(x => x.StartTime ==time).FirstOrDefault();
+                                                    var tt = bill.Where(x => x.StartTime == time).FirstOrDefault();
                                                     confirmbill.Add(tt);
                                                     if (confirmbill.Count == 1)
                                                     {
                                                         confirmbill[0].StartTime = tx.StartTime.ToString("hh:mm tt", new CultureInfo("en-us"));
                                                     }
-                                                   
+
 
                                                     var stopTimeText = tx.StopTime.ToString("hh:mm tt", new CultureInfo("en-us"));
                                                     if (confirmbill[confirmbill.Count - 1].StartTime.Contains(stopTimeText.Split(' ')[1]))
                                                     {
                                                         var subHourText = (int.Parse(stopTimeText.Split(':')[0])).ToString();
                                                         subHourText = subHourText.Length == 1 ? "0" + subHourText : subHourText;
-                                                        if(confirmbill[confirmbill.Count - 1].StartTime.Contains(subHourText))
+                                                        if (confirmbill[confirmbill.Count - 1].StartTime.Contains(subHourText))
                                                         {
                                                             confirmbill[confirmbill.Count - 1].EndTime = stopTimeText;
                                                         }
-                                                      
+
                                                     }
                                                     receipt += string.Format("| {0} - {1}:| {2} kWh @ ${3}/kWh=${4}", confirmbill[confirmbill.Count - 1].StartTime, confirmbill[confirmbill.Count - 1].EndTime,
                                                         confirmbill[confirmbill.Count - 1].PeriodEnergy.ToString("0.0000"), confirmbill[confirmbill.Count - 1].Fee, confirmbill[confirmbill.Count - 1].Total);

+ 1 - 1
EVCB_OCPP.WSServer/Message/OCPP16MessageHandler.cs

@@ -243,7 +243,7 @@ namespace EVCB_OCPP.WSServer.Message
             }
             catch (Exception ex)
             {
-                throw new Exception(string.Format("Parse Error=> {0} Problem: {0}", message, ex.Message));
+                throw new Exception(string.Format("Parse Error=>  Problem: {0}", ex.Message));
 
             }
 

+ 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("858c529")]
+[assembly: AssemblyInformationalVersion("cb3c28e")]

+ 21 - 6
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -119,7 +119,7 @@ namespace EVCB_OCPP.WSServer
                 Console.WriteLine("Please check App.Config setting .");
                 return;
             }
-
+            ReadTCCSetting();
             OpenNetwork();
 
             Task serverCommandTask = new Task(ServerMessageTrigger, _ct);
@@ -334,18 +334,30 @@ namespace EVCB_OCPP.WSServer
 
 
         #region 台泥
-        async private Task<TTCStationInfoDto> GetStationInfo(string machineId)
+
+
+        private void ReadTCCSetting()
+        {
+            using (var db = new MainDBContext())
+            {
+                var info = db.Customer.Where(x => x.Id == new Guid("009E603C-79CD-4620-A2B8-D9349C0E8AD8")).Select(x => new { x.ApiUrl, x.ApiKey }).FirstOrDefault();
+                GlobalConfig.TCC_API_URL = info.ApiUrl;
+                GlobalConfig.TCC_SALTKEY = info.ApiKey;
+
+            }
+        }
+        async private Task<TCCStationInfoDto> GetStationInfo(string machineId)
         {
-            TTCStationInfoDto stationInfo = null;
+            TCCStationInfoDto stationInfo = null;
             if (string.IsNullOrEmpty(machineId)) return stationInfo;
             using (SqlConnection conn = new SqlConnection(webConnectionString))
             {
                 var parameters = new DynamicParameters();
                 parameters.Add("@MachineId", machineId, DbType.String, ParameterDirection.Input);
-                string sql = " SELECT CAST([Latitude] as DECIMAL(5,2)) Lat,CAST([Longitude] as DECIMAL(5, 2))  Long ,[Name] FROM[StationMachine]  left join [dbo].[Station]" +
+                string sql = " SELECT CAST([Latitude] as DECIMAL(5,2)) Lat,CAST([Longitude] as DECIMAL(5, 2))  Long ,SUBSTRING([Address],1,3) as zipcode FROM[StationMachine]  left join [dbo].[Station]" +
                "  on[StationMachine].StationId = Station.[Id]  where StationMachine.MachineId=@MachineId; ";
 
-                var result = await conn.QueryAsync<TTCStationInfoDto>(sql, parameters);
+                var result = await conn.QueryAsync<TCCStationInfoDto>(sql, parameters);
                 stationInfo = result.FirstOrDefault();
             }
 
@@ -766,7 +778,7 @@ namespace EVCB_OCPP.WSServer
                                             if (stationInfo != null)
                                             {
                                                 session.StationLocation = string.Format("{0},{1}", stationInfo.Lat, stationInfo.Long);
-                                                session.StationName = stationInfo.Name;
+                                                session.StationName = stationInfo.ZipCode;
                                             }
                                             using (var db = new MainDBContext())
                                             {
@@ -831,6 +843,9 @@ namespace EVCB_OCPP.WSServer
 
                                         }
 
+
+
+
                                     }
                                     else
                                     {

+ 1 - 4
EVCB_OCPP.WSServer/Service/OuterBusinessService.cs

@@ -118,10 +118,7 @@ namespace EVCB_OCPP.WSServer.Service
 
                 logger.Error(chargeBoxId + " OuterBusinessService.Authorize Ex: " + ex.ToString());
             }
-            if (CustomerId.ToLower() == "9e6bfdcc-09fb-4dab-a428-43fe507600a3")
-            {
-                result.status = AuthorizationStatus.Accepted;               
-            }
+         
             return result;
 
         }