瀏覽代碼

1. Fix 第三方API ActiveSession StartSession 回覆與文件不符合的部分
2.Fix 第三方API 開始充電 雙槍只能充右槍的問題

Jessica Tseng 3 年之前
父節點
當前提交
0bece3dc3a

+ 8 - 5
EVCB_OCPP.WEBAPI/Controllers/Version1/CPOController.cs

@@ -169,7 +169,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 ChargePointService _CPService = new ChargePointService();
 
                 if (!string.IsNullOrEmpty(request.ChargeBoxId) && request.ChargeBoxId.Length <= 25
-                   && _CPService.GetNumberofConnectors(request.ChargeBoxId) <= request.ConnectorId && request.ConnectorId > 0
+                   && _CPService.GetNumberofConnectors(request.ChargeBoxId) >= request.ConnectorId && request.ConnectorId > 0
                     && !string.IsNullOrEmpty(request.Token) && request.Token.Length <= 20)
                 {
 
@@ -1085,7 +1085,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                         });
 
                     }
-                    result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
+                    var _innerResponse = new { Sessions = _innerData };
+                    result.Data = JsonConvert.SerializeObject(_innerResponse, EVCBConfiguration.JSONSERIALIZER_FORMAT);
+
                     result.StatusCode = (int)CPO_StatusCode.Success;
                     result.StatusMessage = CPO_StatusMessage.Success;
                     statusCode = HttpStatusCode.OK;
@@ -1139,8 +1141,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     statusCode = HttpStatusCode.NotFound;
                     return Request.CreateResponse(statusCode, result);
                 }
+                var _innerResponse = new { SessionDetails = _innerData };
+                result.Data = JsonConvert.SerializeObject(_innerResponse, EVCBConfiguration.JSONSERIALIZER_FORMAT);
 
-                result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
                 result.StatusCode = (int)CPO_StatusCode.Success;
                 result.StatusMessage = CPO_StatusMessage.Success;
                 statusCode = HttpStatusCode.OK;
@@ -1545,7 +1548,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 }
 
                 result.SerialNo = uuid;
-                result.Data  = JsonConvert.SerializeObject(new { Result = CommandResponseType.Accepted.ToString(), Timeout = 60 });
+                result.Data = JsonConvert.SerializeObject(new { Result = CommandResponseType.Accepted.ToString(), Timeout = 60 });
                 await Task.Delay(10);
 
             }
@@ -1595,7 +1598,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 //create reqest
                 var _request = new DataTransferRequest()
                 {
-                    messageId = "SetUserPrice",               
+                    messageId = "SetUserPrice",
                     vendorId = "Phihong Technology",
                     data = JsonConvert.SerializeObject(request)
                 };

+ 4 - 1
EVCB_OCPP.WEBAPI/Models/SessionDetail.cs

@@ -8,7 +8,10 @@ namespace EVCB_OCPP.WEBAPI.Models
 {
     public class SessionDetail
     {
-        
+     
+        public string ChargeBoxId { get; set; }
+
+
         /// <summary>
         /// 槍號 
         /// </summary>       

+ 13 - 12
EVCB_OCPP.WEBAPI/Services/ChargePointService.cs

@@ -41,11 +41,11 @@ namespace EVCB_OCPP.WEBAPI.Services
                     time = parameters.Get<DateTime>("@LastUpdatedTime");
 
                 }
-                catch(Exception ex)
+                catch (Exception ex)
                 {
                     time = DateTime.UtcNow;
-                }              
-              
+                }
+
 
                 lastUpdatedOn = DateTime.SpecifyKind(time.Value, DateTimeKind.Utc);
 
@@ -114,7 +114,7 @@ namespace EVCB_OCPP.WEBAPI.Services
             }
             if (_machine != null)
             {
-                cp.ChargeBoxSystemID = _machine.ChargePointModel+_machine.ChargePointSerialNumber;
+                cp.ChargeBoxSystemID = _machine.ChargePointModel + _machine.ChargePointSerialNumber;
                 cp.ChargeBoxId = _machine.ChargeBoxId;
                 cp.NumberofConnectors = _machine.GunAmt;
                 cp.RatedPower = _machine.RatedPower;
@@ -423,7 +423,7 @@ namespace EVCB_OCPP.WEBAPI.Services
 
             try
             {
-            
+
                 bool restrictedRange = false;
                 if (startTime != new DateTime(1991, 1, 1))
                 {
@@ -431,7 +431,7 @@ namespace EVCB_OCPP.WEBAPI.Services
                     parameters.Add("@startTime", startTime, DbType.DateTime, ParameterDirection.Input);
                     parameters.Add("@stopTime", stopTime, DbType.DateTime, ParameterDirection.Input);
                 }
-               
+
                 using (SqlConnection conn = new SqlConnection(mainConnectionString))
                 {
                     string strSql = string.Empty;
@@ -439,17 +439,17 @@ namespace EVCB_OCPP.WEBAPI.Services
                     {
                         parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
                         parameters.Add("@TransactionId", sessionId, DbType.String, ParameterDirection.Input);
-                        strSql = "Select Top(1) * from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and Id=@TransactionId and StopTime!='1991-01-01 00:00:00.000' "+ (restrictedRange ? " and StartTime >=@startTime and  StartTime <=@stopTime" : "" )+ " Order by Id desc ;";
+                        strSql = "Select Top(1) * from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and Id=@TransactionId and StopTime!='1991-01-01 00:00:00.000' " + (restrictedRange ? " and StartTime >=@startTime and  StartTime <=@stopTime" : "") + " Order by Id desc ;";
                     }
                     else if (!string.IsNullOrEmpty(idTag) && string.IsNullOrEmpty(sessionId))
                     {
-                        if(!string.IsNullOrEmpty(chargeBoxId))
+                        if (!string.IsNullOrEmpty(chargeBoxId))
                         {
                             parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
                         }
-                   
+
                         parameters.Add("@StartIdTag", idTag, DbType.String, ParameterDirection.Input);
-                        strSql = "Select  * from [dbo].[TransactionRecord] where "+ (!string.IsNullOrEmpty(chargeBoxId)? " ChargeBoxId=@ChargeBoxId and  " :"")+ "  StartIdTag=@StartIdTag   and StopTime!='1991-01-01 00:00:00.000' " + (restrictedRange ? " and StartTime >=@startTime and  StartTime <=@stopTime" : "") + " Order by Id desc  ;";
+                        strSql = "Select  * from [dbo].[TransactionRecord] where " + (!string.IsNullOrEmpty(chargeBoxId) ? " ChargeBoxId=@ChargeBoxId and  " : "") + "  StartIdTag=@StartIdTag   and StopTime!='1991-01-01 00:00:00.000' " + (restrictedRange ? " and StartTime >=@startTime and  StartTime <=@stopTime" : "") + " Order by Id desc  ;";
 
                     }
                     else
@@ -462,7 +462,7 @@ namespace EVCB_OCPP.WEBAPI.Services
                     }
 
                     transactionModel = conn.Query<TransactionRecordModel>(strSql, parameters, null, true, EVCBConfiguration.DB_DefaultConnectionTimeout).ToList();
-                   
+
 
                 }
 
@@ -470,6 +470,7 @@ namespace EVCB_OCPP.WEBAPI.Services
                 {
                     detail.Add(new SessionDetail()
                     {
+                        ChargeBoxId = item.ChargeBoxId,
                         ConnectorId = (int)item.ConnectorId,
                         IdTag = item.StartIdTag,
                         MeterStart = item.MeterStart,
@@ -482,7 +483,7 @@ namespace EVCB_OCPP.WEBAPI.Services
                 }
 
             }
-            catch(Exception ex)
+            catch (Exception ex)
             {
 
             }