Browse Source

2020/04/17 Jessica
Actions:
1.新增 給外部呼叫的API & 修改內部呼叫API
2.因應資料庫結構調整 做邏輯的調整 配合Domain c118c63

Jessica.Tseng 5 years ago
parent
commit
a3a119440e

+ 1 - 0
EVCB_OCPP.WEBAPI/Controllers/Version1/CPOController.cs

@@ -1083,6 +1083,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     case 2103:
                     case 2104:
                     case 2105:
+                    case 2106:
                         {
                             result.StatusCode = innerResponse.ErrorCode;
                             result.StatusMessage = innerResponse.Message;

+ 25 - 17
EVCB_OCPP.WEBAPI/Controllers/Version1/InternalController.cs

@@ -132,7 +132,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     Code = 2999,
                     Message = EVCBConfiguration.ERROR_MSG_UNEXPECTEDERROR,
                     ErrorDetail = string.Format(EVCBConfiguration.ERRORMESSAGE_FORMAT, "Availability", ex.ToString())
-                   
+
                 });
             }
 
@@ -193,7 +193,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     Code = 2999,
                     Message = EVCBConfiguration.ERROR_MSG_UNEXPECTEDERROR,
                     ErrorDetail = string.Format(EVCBConfiguration.ERRORMESSAGE_FORMAT, "ChangeConfiguration", ex.ToString())
-                   
+
                 });
             }
 
@@ -251,7 +251,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     Code = 2999,
                     Message = EVCBConfiguration.ERROR_MSG_UNEXPECTEDERROR,
                     ErrorDetail = string.Format(EVCBConfiguration.ERRORMESSAGE_FORMAT, "GetConfiguration", ex.ToString())
-                   
+
                 });
             }
 
@@ -317,7 +317,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     Code = 2999,
                     Message = EVCBConfiguration.ERROR_MSG_UNEXPECTEDERROR,
                     ErrorDetail = string.Format(EVCBConfiguration.ERRORMESSAGE_FORMAT, "GetDiagonostics", ex.ToString())
-                   
+
                 });
             }
 
@@ -364,7 +364,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
 
                 });
 
-              
+
             }
 
             return Request.CreateResponse(statusCode, result);
@@ -481,7 +481,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     ErrorDetail = string.Format(EVCBConfiguration.ERRORMESSAGE_FORMAT, "StartTransaction", ex.ToString())
 
                 });
-               
+
             }
 
             return Request.CreateResponse(statusCode, result);
@@ -504,9 +504,17 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 {
 
                     return Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse() { Code = 2101, Message = EVCBConfiguration.ERROR_MSG_CHARGEBOXID_ISNT_EXIST_OR_OFFLINE });
+                }             
+
+                var _ConnectorId = chargePointService.GetConnectorwithOngoingTransaction(ChargeBoxId, TransactionId);
+
+                if (_ConnectorId == -1)
+                {
+                    // 充完電 & 這個充電序不存在
+                    return Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse() { Code = 2106, Message = EVCBConfiguration.ERROR_MSG_TX_FINISHED_OR_NOTFOUND });
                 }
 
-                var _ConnectorStatus = chargePointService.GetChargePointCurrentSatus(ChargeBoxId, TransactionId % 10);
+                var _ConnectorStatus = chargePointService.GetChargePointCurrentSatus(ChargeBoxId, _ConnectorId);
 
                 if (!(_ConnectorStatus.HasValue && _ConnectorStatus == ChargePointStatus.Charging))
                 {
@@ -549,7 +557,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
 
                 });
 
-               
+
             }
 
 
@@ -637,7 +645,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 });
 
 
-              
+
             }
 
             return Request.CreateResponse(statusCode, result);
@@ -698,7 +706,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     ErrorDetail = string.Format(EVCBConfiguration.ERRORMESSAGE_FORMAT, "CancelResrvation", ex.ToString())
 
                 });
-              
+
             }
 
             return Request.CreateResponse(statusCode, result);
@@ -759,7 +767,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     ErrorDetail = string.Format(EVCBConfiguration.ERRORMESSAGE_FORMAT, "Reset", ex.ToString())
 
                 });
-             
+
             }
 
             return Request.CreateResponse(statusCode, result);
@@ -845,7 +853,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     ErrorDetail = string.Format(EVCBConfiguration.ERRORMESSAGE_FORMAT, "SendLocalList", ex.ToString())
 
                 });
-              
+
             }
 
             return Request.CreateResponse(statusCode, result);
@@ -900,7 +908,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     ErrorDetail = string.Format(EVCBConfiguration.ERRORMESSAGE_FORMAT, "ClearCache", ex.ToString())
 
                 });
-                
+
             }
 
             return Request.CreateResponse(statusCode, result);
@@ -1038,7 +1046,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
             catch (Exception ex)
             {
 
-              
+
                 return Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse()
                 {
                     Code = 2999,
@@ -1104,7 +1112,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     ErrorDetail = string.Format(EVCBConfiguration.ERRORMESSAGE_FORMAT, "TriggerMessage", ex.ToString())
 
                 });
-               
+
             }
 
             return Request.CreateResponse(statusCode, result);
@@ -1163,7 +1171,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
 
                 });
 
-               
+
             }
 
             return Request.CreateResponse(statusCode, result);
@@ -1227,7 +1235,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     ErrorDetail = string.Format(EVCBConfiguration.ERRORMESSAGE_FORMAT, "CompositeSchedule", ex.ToString())
 
                 });
-               
+
             }
 
             return Request.CreateResponse(statusCode, result);

+ 1 - 0
EVCB_OCPP.WEBAPI/EVCBConfiguration.cs

@@ -35,6 +35,7 @@ namespace EVCB_OCPP.WEBAPI
         public static readonly string ERROR_MSG_CONNECTOR_ISNOT_AVAILIABLE_MODE = "Connector is not in available mode.";
         public static readonly string ERROR_MSG_CONNECTOR_ISNOT_CHARGING_MODE = "Connector is not in charging mode.";
         public static readonly string ERROR_MSG_DATA_NOTFOUND = "Oops! We can't find the details with request.";
+        public static readonly string ERROR_MSG_TX_FINISHED_OR_NOTFOUND = "Transaction is finished or not found.";
 
         public static JsonSerializerSettings JSONSERIALIZER_FORMAT = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None };
 

+ 1 - 1
EVCB_OCPP.WEBAPI/Models/TransactionRecordModel.cs

@@ -22,7 +22,7 @@ namespace EVCB_OCPP.WEBAPI.Models
         /// <summary>
         /// TransactionId
         /// </summary>     
-        public int TransactionId { get; set; }
+        public int Id { get; set; }
 
 
        

+ 2 - 1
EVCB_OCPP.WEBAPI/Models/WebAPI/CPOResponseDescription.cs

@@ -17,7 +17,7 @@ namespace EVCB_OCPP.WEBAPI.Models.WebAPI
         ChargePoint_OFFLINE_OR_UNAVAILABLE = 2103,
         SESSION_FINISHED = 2104,
         ChargePoint_UNCHARGING_MODE = 2105,
-
+        TX_FINISHED_OR_NOTFOUND = 2106,
 
 
 
@@ -46,5 +46,6 @@ namespace EVCB_OCPP.WEBAPI.Models.WebAPI
         public static readonly string ERROR_MSG_CANT_FIND_SESSIONDETAIL = "Can't find the session details.";
         public static readonly string ERROR_MSG_CONNECTOR_ISNOT_CHARGING_MODE = "Connector is not in charging mode.";
         public static readonly string ERROR_MSG_INNERSERVICE_ERROR = "An internal error has occurred.";
+        public static readonly string ERROR_MSG_TX_FINISHED_OR_NOTFOUND = "Transaction is finished or not found.";
     }
 }

+ 25 - 7
EVCB_OCPP.WEBAPI/Services/ChargePointService.cs

@@ -56,6 +56,23 @@ namespace EVCB_OCPP.WEBAPI.Services
             return exists;
         }
 
+        public int GetConnectorwithOngoingTransaction(string chargeBoxId, int transactionId)
+        {
+            int connectorId = -1;
+
+            if (string.IsNullOrEmpty(chargeBoxId)) return connectorId;
+
+            var parameters = new DynamicParameters();
+            parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
+            parameters.Add("@TransactionId", transactionId, DbType.Int32, ParameterDirection.Input);
+            using (SqlConnection conn = new SqlConnection(mainConnectionString))
+            {
+                string strSql = "Select ConnectorId from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and Id= @TransactionId and StopTime='1991/01/01'; ";
+                connectorId = conn.Query<Int32>(strSql, parameters).FirstOrDefault();               
+            }
+
+            return connectorId;
+        }
 
 
 
@@ -71,7 +88,7 @@ namespace EVCB_OCPP.WEBAPI.Services
             parameters.Add("@TransactionId", transactionId, DbType.Int32, ParameterDirection.Input);
             using (SqlConnection conn = new SqlConnection(mainConnectionString))
             {
-                string strSql = "Select TransactionId from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and TransactionId= @TransactionId and StopTime='1991/01/01'; ";
+                string strSql = "Select Id from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and Id= @TransactionId and StopTime='1991/01/01'; ";
                 int id = conn.Query<Int32>(strSql, parameters).FirstOrDefault();
                 exists = id > 0 ? true : false;
             }
@@ -172,7 +189,7 @@ namespace EVCB_OCPP.WEBAPI.Services
                     using (SqlConnection conn = new SqlConnection(mainConnectionString))
                     {
                         string date = DateTime.UtcNow.ToString("yyMMdd");
-                        string strSql = "Select Top(1) * from [dbo].[ConnectorMeterValueRecord" + date + "] where ChargeBoxId=@ChargeBoxId and TransactionId=@TransactionId and MeasurandId=@MeasurandId order by CreatedOn desc;";
+                        string strSql = "Select Top(1) * from [dbo].[ConnectorMeterValueRecord" + date + "] where ChargeBoxId=@ChargeBoxId and Id=@TransactionId and MeasurandId=@MeasurandId order by CreatedOn desc;";
                         meterModel = conn.Query<ConnectorMeterValueModel>(strSql, parameters, null, true, EVCBConfiguration.DB_DefaultConnectionTimeout).FirstOrDefault();
 
                     }
@@ -198,11 +215,12 @@ namespace EVCB_OCPP.WEBAPI.Services
 
 
                     }
-                }catch
+                }
+                catch
                 {
                     break;
                 }
-              
+
             }
 
             return meterValues;
@@ -224,7 +242,7 @@ namespace EVCB_OCPP.WEBAPI.Services
                 using (SqlConnection conn = new SqlConnection(mainConnectionString))
                 {
                     string date = DateTime.UtcNow.ToString("yyMMdd");
-                    string strSql = "Select Top(1) * from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and TransactionId=@TransactionId and StopTime!='1991-01-01 00:00:00.000' ;";
+                    string strSql = "Select Top(1) * from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and Id=@TransactionId and StopTime!='1991-01-01 00:00:00.000' ;";
                     transactionModel = conn.Query<TransactionRecordModel>(strSql, parameters, null, true, EVCBConfiguration.DB_DefaultConnectionTimeout).FirstOrDefault();
 
                 }
@@ -247,10 +265,10 @@ namespace EVCB_OCPP.WEBAPI.Services
             }
             catch
             {
-               
+
             }
 
-            
+
             return detail;
         }
 

+ 3 - 2
EVCB_OCPP.WEBAPI/Services/ServerTriggerService.cs

@@ -100,12 +100,12 @@ namespace EVCB_OCPP.WEBAPI.Services
         public void AddMessage(string ChargeBoxId, string uuid, IRequest request)
         {
             string sql_MachineOperateRecord = "INSERT INTO [dbo].[MachineOperateRecord](SerialNo, RequestType, RequestContent,Status, CreatedOn, FinishedOn,"
-         + " EVSE_Value, EVSE_Status, ChargeBoxId, Action) VALUES (@SerialNo, @RequestType, @RequestContent, @Status, @CreatedOn, @FinishedOn, @EVSE_Value, "
+         + " EVSE_Value, EVSE_Status, ChargeBoxId, Action, ReportedOn) VALUES (@SerialNo, @RequestType, @RequestContent, @Status, @CreatedOn, @FinishedOn, @EVSE_Value, "
          + "@EVSE_Status, @ChargeBoxId, @Action);";
 
             string sql_ServerMessage = "INSERT INTO [dbo].[ServerMessage] (SerialNo, OutAction, OutRequest, InMessage, CreatedOn, CreatedBy, ReceivedOn, ChargeBoxId" +
                 ", UpdatedOn)  VALUES (@SerialNo, @OutAction, @OutRequest, @InMessage, @CreatedOn, @CreatedBy, @ReceivedOn, @ChargeBoxId" +
-                ", @UpdatedOn);";
+                ", @UpdatedOn,@ReportedOn);";
 
             string key = string.Empty;
             var parameters = new DynamicParameters();
@@ -127,6 +127,7 @@ namespace EVCB_OCPP.WEBAPI.Services
             parameters.Add("@CreatedBy", "WebAPI", DbType.String, ParameterDirection.Input);
             parameters.Add("@ReceivedOn", EVCBConfiguration.DefaultTime, DbType.DateTime, ParameterDirection.Input);
             parameters.Add("@UpdatedOn", EVCBConfiguration.DefaultTime, DbType.DateTime, ParameterDirection.Input);
+            parameters.Add("@UpdatedOn", EVCBConfiguration.DefaultTime, DbType.DateTime, ParameterDirection.Input);
 
 
             using (SqlConnection conn = new SqlConnection(mainConnectionString))