瀏覽代碼

2020/04/24 Jessica
Actions:
1.因為MachineOperateRecord 新增欄位修正ServerTriggerService
2.新增 Charging Station、BasicInformationofEVSEs APIs

Jessica.Tseng 4 年之前
父節點
當前提交
9a1936276e

+ 31 - 13
EVCB_OCPP.WEBAPI/Controllers/Version1/CPOController.cs

@@ -14,14 +14,6 @@ using EVCB_OCPP.WEBAPI.Models.WebAPI.Dto;
 
 namespace EVCB_OCPP.WEBAPI.Controllers.Version1
 {
-    public class TT
-    {
-        public bool Result { get; set; }
-
-        public int Timeout { set; get; }
-
-        public string Msg { set; get; }
-    }
 
     [RoutePrefix("api/v1/cpo")]
     [CPOAuthentication]
@@ -60,7 +52,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     ChargingStationService _service = new ChargingStationService();
                     var _innerResponse = new { Stations = _service.GetStationsbyCustomerId(_customerId) };
                     result.Data = JsonConvert.SerializeObject(_innerResponse, EVCBConfiguration.JSONSERIALIZER_FORMAT);
-
+                    result.StatusCode = (int)CPO_StatusCode.Success;
+                    result.StatusMessage = CPO_StatusMessage.SUCCESS;
+                    statusCode = HttpStatusCode.OK;
                 }
                 return Request.CreateResponse(statusCode, result);
             }
@@ -78,19 +72,43 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
         [Route("information")]
         [ResponseType(typeof(CPOOuterResponse))]
         [HttpGet]
-        public HttpResponseMessage BasicInformationofEVSEs(string StationId, DateTime? DateFrom = null, DateTime? DateTo = null, int? Offset = 0, int? Limit = 1)
+        public HttpResponseMessage BasicInformationofEVSEs(int StationId, DateTime? DateFrom = null, DateTime? DateTo = null, int? Offset = 0, int? Limit = 1)
         {
 
             var result = new CPOOuterResponse();
             HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
             try
             {
+                ChargePointService _CPService = new ChargePointService();
+                var tt = _CPService.GetLastUpdatedTimebyMachineId("0da4f4a6-a952-46f0-b2f3-696385a9a56a");
                 if (Request.Headers.Contains(EVCBConfiguration.Header_PartnerId))
                 {
                     var _customerId = Request.Headers.GetValues(EVCBConfiguration.Header_PartnerId).First();
-                    EVSEService _service = new EVSEService();
-                    var _innerResponse = new { Stations = _service.GetEVSEsbyCustomerIdAndStationId(_customerId, StationId) };
-                    result.Data = JsonConvert.SerializeObject(_innerResponse);
+
+                    var _innerResponse = new { EVSEs =new List<EVSE>() };
+                    ChargingStationService _stationService = new ChargingStationService();
+
+                    if (_stationService.ContainsStation(_customerId, StationId))
+                    {
+                        if (DateTo.HasValue)
+                        {
+                            if (!DateFrom.HasValue)
+                            {
+                                                                      
+                                result.StatusMessage = CPO_StatusMessage.ERROR_MSG_PARAMETER_OUTOFRANGE_INCORRECT;
+                                result.StatusCode = (int)CPO_StatusCode.PARAMETER_OUTOFRANGE_INCORRECT;                               
+                                statusCode = HttpStatusCode.BadRequest;
+                                return Request.CreateResponse(statusCode, result);
+                            }
+                        }
+                        _innerResponse = new { EVSEs = _stationService.GetEVSEsbyStationId(StationId, DateFrom, DateTo, Offset.Value, Limit.Value) };
+                    
+
+                    }
+                    result.Data = JsonConvert.SerializeObject(_innerResponse, EVCBConfiguration.JSONSERIALIZER_FORMAT);
+                    result.StatusCode = (int)CPO_StatusCode.Success;
+                    result.StatusMessage = CPO_StatusMessage.SUCCESS;
+                    statusCode = HttpStatusCode.OK;
 
                 }
                 return Request.CreateResponse(statusCode, result);

+ 2 - 2
EVCB_OCPP.WEBAPI/Controllers/Version1/InternalController.cs

@@ -258,11 +258,11 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
             return Request.CreateResponse(statusCode, result);
         }
 
-        [Route("diagonostics")]
+        [Route("diagnostics")]
         [ResponseType(typeof(ErrorResponse))]
         [ResponseType(typeof(InternalGenericResponse))]
         [HttpGet]
-        public HttpResponseMessage Diagonostics(string ChargeBoxId, Uri Location, int Retries = -1, int RetryInterval = -1, string StartTime = null, string StopTime = null)
+        public HttpResponseMessage Diagnostics(string ChargeBoxId, Uri Location, int Retries = -1, int RetryInterval = -1, string StartTime = null, string StopTime = null)
         {
             string uuid = Guid.NewGuid().ToString();
             var result = new InternalGenericResponse();

+ 1 - 1
EVCB_OCPP.WEBAPI/EVCBConfiguration.cs

@@ -21,7 +21,7 @@ namespace EVCB_OCPP.WEBAPI
 
         public static readonly string ERRORMESSAGE_FORMAT = "{0}:{1}";
 
-        public static readonly DateTime DefaultTime = new DateTime(627982848000000000, DateTimeKind.Utc);
+        public static readonly DateTime DefaultTime = new DateTime(1991,1,1,0,0,0, DateTimeKind.Utc);
 
 
         public static readonly string ERROR_MSG_INVALIDHEADER = "Invaild Headers";

+ 3 - 2
EVCB_OCPP.WEBAPI/EVCB_OCPP.WEBAPI.csproj

@@ -236,15 +236,16 @@
     <Compile Include="Models\WebAPI\ComandExecution.cs" />
     <Compile Include="Models\WebAPI\CPOResponseDescription.cs" />
     <Compile Include="Models\WebAPI\CPOOuterResponse.cs" />
-    <Compile Include="Models\WebAPI\Dto\ChargingStation.cs" />
     <Compile Include="Models\WebAPI\Dto\CommandResponseType.cs" />
     <Compile Include="Models\WebAPI\Dto\CommandResultType.cs" />
     <Compile Include="Models\WebAPI\Dto\CommandType.cs" />
     <Compile Include="Models\WebAPI\Dto\Connector.cs" />
     <Compile Include="Models\WebAPI\Dto\ConnectorPowerType.cs" />
+    <Compile Include="Models\WebAPI\Dto\ConnectorStatus.cs" />
     <Compile Include="Models\WebAPI\Dto\ConnectorType.cs" />
     <Compile Include="Models\WebAPI\Dto\EVSE.cs" />
     <Compile Include="Models\WebAPI\Dto\GeoLocation.cs" />
+    <Compile Include="Models\WebAPI\Dto\Machine.cs" />
     <Compile Include="Models\WebAPI\Dto\ReserveNowRequest.cs" />
     <Compile Include="Models\WebAPI\Dto\StartSessionRequest.cs" />
     <Compile Include="Models\WebAPI\Dto\Status.cs" />
@@ -257,11 +258,11 @@
     <Compile Include="Models\WebAPI\SetChargingProfileRequest.cs" />
     <Compile Include="Models\WebAPI\SingleConfigurationRequest.cs" />
     <Compile Include="Models\WebAPI\StartTransactionRequest.cs" />
+    <Compile Include="Models\WebAPI\Station.cs" />
     <Compile Include="Models\WebAPI\TriggerMessageRequest.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Services\ChargePointService.cs" />
     <Compile Include="Services\CustomerService.cs" />
-    <Compile Include="Services\EVSEService.cs" />
     <Compile Include="Services\HttpClientService.cs" />
     <Compile Include="Services\InternalHttpClient.cs" />
     <Compile Include="Services\ServerTriggerService.cs" />

+ 2 - 1
EVCB_OCPP.WEBAPI/Handlers/InernalAuthentication.cs

@@ -22,7 +22,7 @@ namespace EVCB_OCPP.WEBAPI.Handlers
         public Task<HttpResponseMessage> ExecuteAuthorizationFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func<Task<HttpResponseMessage>> continuation)
         {
             HttpStatusCode _status = HttpStatusCode.Unauthorized;
-            ErrorResponse _errorResponse = new ErrorResponse() { Code = 2001, Message = EVCBConfiguration.ERROR_MSG_INVALIDHEADER };
+            ErrorResponse _errorResponse = new ErrorResponse() { Code = 2001, Message = EVCBConfiguration.ERROR_MSG_INVALIDHEADER, ErrorDetail=string.Empty };
 
             try
             {
@@ -137,6 +137,7 @@ namespace EVCB_OCPP.WEBAPI.Handlers
             }
             else
             {
+                formatMessage = string.Format("These header must contain {0}, {1} and {2} ", EVCBConfiguration.Header_PartnerId, EVCBConfiguration.Header_Signature, EVCBConfiguration.Header_Timestamp);
                 return false;
             }
         }

+ 0 - 16
EVCB_OCPP.WEBAPI/Models/WebAPI/Dto/ChargingStation.cs

@@ -1,16 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-
-namespace EVCB_OCPP.WEBAPI.Models.WebAPI.Dto
-{
-    public class ChargingStation
-    {
-        public string Id { set; get; }
-
-        public string Name { set; get; }
-
-        public GeoLocation Coordinates { set; get; }
-    }
-}

+ 2 - 0
EVCB_OCPP.WEBAPI/Models/WebAPI/Dto/Connector.cs

@@ -9,6 +9,8 @@ namespace EVCB_OCPP.WEBAPI.Models.WebAPI.Dto
 {
     public class Connector
     {
+        public int ConnectorId { set; get; }
+
         [JsonConverter(typeof(StringEnumConverter))]
         public Status Status { set; get; }
 

+ 4 - 2
EVCB_OCPP.WEBAPI/Models/WebAPI/Dto/ConnectorPowerType.cs

@@ -7,8 +7,10 @@ namespace EVCB_OCPP.WEBAPI.Models.WebAPI.Dto
 {
     public enum ConnectorPowerType
     {
-        AC_1_PHASE,
+        Unknown=-1,
+        AC_1_PHASE =1,
         AC_3_PHASE,
-        DC
+        DC,
+        
     }
 }

+ 15 - 0
EVCB_OCPP.WEBAPI/Models/WebAPI/Dto/ConnectorStatus.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace EVCB_OCPP.WEBAPI.Models.WebAPI.Dto
+{
+    public class ConnectorStatus
+    {
+        public int ConnectorId { set; get; }
+
+     
+        public int Status { set; get; }
+    }
+}

+ 6 - 5
EVCB_OCPP.WEBAPI/Models/WebAPI/Dto/ConnectorType.cs

@@ -7,11 +7,12 @@ namespace EVCB_OCPP.WEBAPI.Models.WebAPI.Dto
 {
     public enum ConnectorType
     {
-        CHADEMO,
+        Other=-1,
+        CHADEMO =1,
         AC,
-        CCS1,
-        CCS2,
-        GB,
-        Other
+        CCS1_COMBO,
+        CCS2_COMBO,
+        GBT
+      
     }
 }

+ 5 - 1
EVCB_OCPP.WEBAPI/Models/WebAPI/Dto/EVSE.cs

@@ -1,4 +1,5 @@
-using System;
+using Newtonsoft.Json;
+using System;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
 using System.Linq;
@@ -21,5 +22,8 @@ namespace EVCB_OCPP.WEBAPI.Models.WebAPI.Dto
 
         public GeoLocation Coordinates { set; get; }

         public DateTime LastUpdated { set; get; }
+
+        [JsonIgnore]
+        public int NumberofConnectors { set; get; }
     }
 }

+ 69 - 0
EVCB_OCPP.WEBAPI/Models/WebAPI/Dto/Machine.cs

@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace EVCB_OCPP.WEBAPI.Models.WebAPI.Dto
+{
+    public partial class Machine
+    {
+        public Machine()
+        {
+           
+        }
+
+     
+        public string Id { get; set; }
+
+       
+        public string ChargeBoxId { get; set; }
+
+     
+        /// <summary>
+        /// 建立時間
+        /// </summary>       
+        public DateTime CreatedOn { get; set; }
+
+       
+
+        /// <summary>
+        /// 充電槍個數
+        /// </summary>
+        public int GunAmt { get; set; }
+
+
+
+        /// <summary>
+        ///Offline更新時間
+        /// </summary>
+        public DateTime OfflineOn { get; set; }
+
+
+
+        public int RatedPower { set; get; }
+
+      
+        public decimal Latitude { set; get; }
+
+    
+        public decimal Longitude { set; get; }
+
+        /// <summary>
+        /// 是否在線
+        /// </summary>
+        public bool Online { get; set; }
+
+
+        /// <summary>
+        /// ConnectorType
+        /// </summary>        
+        public string ConnectorType { get; set; }
+
+        /// <summary>
+        /// ConnectorPowerType
+        /// </summary>      
+        public string ConnectorPowerType { get; set; }
+
+
+    }
+}

+ 31 - 0
EVCB_OCPP.WEBAPI/Models/WebAPI/Station.cs

@@ -0,0 +1,31 @@
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace EVCB_OCPP.WEBAPI.Models.WebAPI
+{
+    public class Station
+    {
+        public int Id { set; get; }
+
+
+        public string Name { set; get; }
+
+        [JsonIgnore]
+        public decimal Latitude { set; get; }
+
+        [JsonIgnore]
+        public decimal Longitude { set; get; }
+
+        public GetLocation Coordinates { set; get; }
+    }
+
+    public class GetLocation
+    {      
+        public decimal Latitude { set; get; }
+
+        public decimal Longitude { set; get; }
+    }
+}

+ 196 - 1
EVCB_OCPP.WEBAPI/Services/ChargePointService.cs

@@ -1,6 +1,7 @@
 using Dapper;
 using EVCB_OCPP.Packet.Messages.SubTypes;
 using EVCB_OCPP.WEBAPI.Models;
+using EVCB_OCPP.WEBAPI.Models.WebAPI.Dto;
 using System;
 using System.Collections.Generic;
 using System.Configuration;
@@ -22,6 +23,83 @@ namespace EVCB_OCPP.WEBAPI.Services
     {
         string mainConnectionString = ConfigurationManager.ConnectionStrings["MainDBContext"].ConnectionString;
 
+        public DateTime GetLastUpdatedTimebyMachineId(string machineId)
+        {
+            DateTime lastUpdatedOn = DateTime.UtcNow;
+            using (SqlConnection conn = new SqlConnection(mainConnectionString))
+            {
+                var parameters = new DynamicParameters();
+
+                parameters.Add("@MachineId", machineId, DbType.String, ParameterDirection.Input);
+                parameters.Add("@LastUpdatedTime", lastUpdatedOn, DbType.DateTime, ParameterDirection.Output);
+                conn.Execute("GetBasicInfoLastUpdatedTimeById", parameters, commandType: System.Data.CommandType.StoredProcedure);
+                lastUpdatedOn = DateTime.SpecifyKind(parameters.Get<DateTime>("@LastUpdatedTime"), DateTimeKind.Utc);
+            }
+
+            return lastUpdatedOn;
+
+        }
+
+
+        public EVSE GetBasicInfobyId(string machineId)
+        {
+            EVSE cp = new EVSE();
+            Machine _machine = new Machine();
+            using (SqlConnection conn = new SqlConnection(mainConnectionString))
+            {
+                var parameters = new DynamicParameters();
+                parameters.Add("@Id", machineId, DbType.String, ParameterDirection.Input);
+                string strSql = "Select ChargeBoxId,RatedPower,Online,OfflineOn ,GunAmt,Latitude,Longitude,ConnectorType,ConnectorPowerType from [dbo].[Machine] where Id=@Id; ";
+                _machine = conn.Query<Machine>(strSql, parameters).FirstOrDefault();
+            }
+            if (_machine != null)
+            {
+                cp.ChargeBoxId = _machine.ChargeBoxId;
+                cp.NumberofConnectors = _machine.GunAmt;
+                cp.RatedPower = _machine.RatedPower;
+                cp.Status = _machine.Online ? Status.Available : Status.Remove;
+                cp.LastUpdated = _machine.CreatedOn > _machine.OfflineOn ? _machine.CreatedOn : _machine.OfflineOn;
+                cp.Coordinates = new GeoLocation() { Latitude = _machine.Latitude.ToString(), Longitude = _machine.Longitude.ToString() };
+                cp.Connectors = new List<Connector>();
+                var _Connectors = GetConnectorStatus(_machine.ChargeBoxId);
+                for (int i = 1; i <= _machine.GunAmt; i++)
+                {
+                    var _RefConnector = _Connectors.Where(x => x.ConnectorId == i).FirstOrDefault();
+                    cp.Connectors.Add(new Connector()
+                    {
+                        ConnectorId = _RefConnector == null ? i : _RefConnector.ConnectorId,
+                        Status = cp.Status == Status.Remove ? Status.Remove : _RefConnector == null ? Status.Unknown : ConvertConnectorStatus(_RefConnector.Status),
+                        ConnectorType = ConvertConnectorType(int.Parse(_machine.ConnectorType.Split(',')[i - 1])),
+                        PowerType = ConvertConnectorPowerType(int.Parse(_machine.ConnectorPowerType.Split(',')[i - 1])),
+                    });
+                }
+            }
+
+
+
+            return _machine == null ? null : cp;
+        }
+
+       
+
+        public List<ConnectorStatus> GetConnectorStatus(string chargeBoxId)
+        {
+
+            List<ConnectorStatus> _Connectors = new List<ConnectorStatus>();
+            using (SqlConnection conn = new SqlConnection(mainConnectionString))
+            {
+                var parameters = new DynamicParameters();
+                parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
+                string strSql = "Select ConnectorId,Status from [dbo].[ConnectorStatus] where ChargeBoxId=@ChargeBoxId order by  ConnectorId; ";
+                _Connectors = conn.Query<ConnectorStatus>(strSql, parameters).SkipWhile(x => x.ConnectorId == 0).ToList();
+            }
+
+
+
+            return _Connectors;
+        }
+
+
         public int GetNumberofConnectors(string chargeBoxId)
         {
             int count = 0;
@@ -68,7 +146,7 @@ namespace EVCB_OCPP.WEBAPI.Services
             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();               
+                connectorId = conn.Query<Int32>(strSql, parameters).FirstOrDefault();
             }
 
             return connectorId;
@@ -272,5 +350,122 @@ namespace EVCB_OCPP.WEBAPI.Services
             return detail;
         }
 
+
+        private Status ConvertConnectorStatus(int value)
+        {
+            Status result = Status.Unknown;
+
+            switch (value)
+            {
+                case 1://Available
+                    {
+                        result = Status.Available;
+                    }
+                    break;
+                case 2://Preparing
+                case 3://Charging
+                case 4://SuspendedEVSE
+                case 5://SuspendedEV
+                case 6://Finishing
+                    {
+                        result = Status.Charging;
+                    }
+                    break;
+                case 7://Unavailable
+                    {
+                        result = Status.Unavailable;
+                    }
+                    break;
+                case 8://Reserved
+                    {
+                        result = Status.Reserved;
+                    }
+                    break;
+                case 9://Faulted
+                    {
+                        result = Status.Faulted;
+                    }
+                    break;
+                default:
+                    break;
+
+
+
+            }
+            return result;
+
+        }
+
+        private ConnectorPowerType ConvertConnectorPowerType(int value)
+        {
+            ConnectorPowerType result = ConnectorPowerType.Unknown;
+
+            switch (value)
+            {
+                case 1://AC_1_PHASE
+                    {
+                        result = ConnectorPowerType.AC_1_PHASE;
+                    }
+                    break;
+                case 2://AC_3_PHASE
+                    {
+                        result = ConnectorPowerType.AC_3_PHASE;
+                    }
+                    break;
+                case 3://DC
+                    {
+                        result = ConnectorPowerType.DC;
+                    }
+                    break;
+                default:
+                    break;
+
+
+
+            }
+            return result;
+
+        }
+
+        private ConnectorType ConvertConnectorType(int value)
+        {
+            ConnectorType result = ConnectorType.Other;
+
+            switch (value)
+            {
+                case 1://CHADEMO
+                    {
+                        result = ConnectorType.CHADEMO;
+                    }
+                    break;
+                case 2://AC
+                    {
+                        result = ConnectorType.AC;
+                    }
+                    break;
+                case 3://CCS1_COMBO
+                    {
+                        result = ConnectorType.CCS1_COMBO;
+                    }
+                    break;
+                case 4://CCS2_COMBO
+                    {
+                        result = ConnectorType.CCS2_COMBO;
+                    }
+                    break;
+                case 5://GBT
+                    {
+                        result = ConnectorType.GBT;
+                    }
+                    break;
+                default:
+                    break;
+
+
+
+            }
+            return result;
+        }
+
     }
 }

+ 93 - 6
EVCB_OCPP.WEBAPI/Services/ChargingStationService.cs

@@ -1,6 +1,11 @@
-using EVCB_OCPP.WEBAPI.Models.WebAPI.Dto;
+using Dapper;
+using EVCB_OCPP.WEBAPI.Models.WebAPI;
+using EVCB_OCPP.WEBAPI.Models.WebAPI.Dto;
 using System;
 using System.Collections.Generic;
+using System.Configuration;
+using System.Data;
+using System.Data.SqlClient;
 using System.Linq;
 using System.Web;
 
@@ -9,20 +14,102 @@ namespace EVCB_OCPP.WEBAPI.Services
 
     public interface IChargingStationService
     {
-        List<ChargingStation> GetStationsbyCustomerId(string customerId);
+        List<Station> GetStationsbyCustomerId(string customerId);
+
+        List<EVSE> GetEVSEsbyStationId(int stationId, DateTime? dateFrom, DateTime? dateTo, int offset, int limit);
 
     }
     public class ChargingStationService : IChargingStationService
     {
-        public List<ChargingStation> GetStationsbyCustomerId(string customerId)
+
+        string mainConnectionString = ConfigurationManager.ConnectionStrings["MainDBContext"].ConnectionString;
+        string webConnectionString = ConfigurationManager.ConnectionStrings["WebDBContext"].ConnectionString;
+        public List<Station> GetStationsbyCustomerId(string customerId)
         {
-            return new List<ChargingStation>();
+            List<Station> _stations = new List<Station>();
+
+            var parameters = new DynamicParameters();
+            parameters.Add("@CustomerId", customerId, DbType.String, ParameterDirection.Input);
+            using (SqlConnection conn = new SqlConnection(webConnectionString))
+            {
+                string strSql = "Select Id, Name ,Latitude,Longitude from [dbo].[Station] where CustomerId=@CustomerId; ";
+                _stations = conn.Query<Station>(strSql, parameters).ToList();
+
+            }
+
+            if (_stations != null)
+            {
+                foreach (var station in _stations)
+                {
+                    station.Coordinates = new GetLocation() { Latitude = station.Latitude, Longitude = station.Longitude };
+                }
+            }
+            return _stations;
         }
 
+        public bool ContainsStation(string customerId, int stationId)
+        {
+            bool isContains = false;
+
+            var parameters = new DynamicParameters();
+            parameters.Add("@CustomerId", customerId, DbType.String, ParameterDirection.Input);
+            parameters.Add("@Id", stationId, DbType.Int32, ParameterDirection.Input);
+            using (SqlConnection conn = new SqlConnection(webConnectionString))
+            {
+                string strSql = "Select count(*) from [dbo].[Station] where CustomerId=@CustomerId and Id=@Id; ";
+                isContains = conn.ExecuteScalar<Int32>(strSql, parameters) > 0 ? true : false;
+            }
+
+            return isContains;
+        }
 
-        public List<EVSE> GetEVSEsbyStationId(string customerId,int stationId)
+
+        public List<EVSE> GetEVSEsbyStationId(int stationId, DateTime? dateFrom, DateTime? dateTo, int offset = -1, int limit = 10)
         {
-            return new List<EVSE>();
+            List<EVSE> _chargePoints = new List<EVSE>();
+            var parameters = new DynamicParameters();
+            parameters.Add("@StationId", stationId, DbType.Int16, ParameterDirection.Input);
+            int counter = 0;
+            int startIndex = offset == -1 ? 0 : offset;
+            limit = limit + startIndex;
+            List<string> machineIds = new List<string>();
+            using (SqlConnection conn = new SqlConnection(webConnectionString))
+            {
+                string strSql = "Select MachineId from [dbo].[StationMachine] where StationId=@StationId; ";
+                machineIds = conn.Query<String>(strSql, parameters).ToList();
+            }
+            ChargePointService _CPService = new ChargePointService();
+            while (startIndex < limit && startIndex < machineIds.Count)
+            {
+                var _machineUpdateOn = _CPService.GetLastUpdatedTimebyMachineId(machineIds[startIndex]);
+                      
+             
+                if (dateFrom.HasValue && _machineUpdateOn < dateFrom.Value.ToUniversalTime())
+                {
+                    limit++;
+                    startIndex++;
+                    continue;
+                }
+
+                if (dateFrom.HasValue && dateTo.HasValue && (_machineUpdateOn < dateFrom.Value.ToUniversalTime() || _machineUpdateOn > dateTo.Value.ToUniversalTime()))
+                {
+                    limit++;
+                    startIndex++;
+                    continue;
+                }
+
+               var _machine = _CPService.GetBasicInfobyId(machineIds[startIndex]);
+                _machine.LastUpdated = _machineUpdateOn;
+                _machine.StationId = stationId;
+                _chargePoints.Add(_machine);
+                startIndex++;
+
+            }
+            return _chargePoints;
         }
+
+
+
+
     }
 }

+ 0 - 39
EVCB_OCPP.WEBAPI/Services/EVSEService.cs

@@ -1,39 +0,0 @@
-using EVCB_OCPP.WEBAPI.Models.WebAPI.Dto;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-
-namespace EVCB_OCPP.WEBAPI.Services
-{
-
-    public interface IEVSEService
-    {
-        List<EVSE> GetEVSEsbyCustomerIdAndStationId(string customerId, string stationId);
-
-        EVSE GetEVSEbyChargeBoxId(string chargeBoxId);
-
-
-     //   EVSE GetEVSEbyChargeBoxId(string chargeBoxId);
-
-
-
-    }
-    public class EVSEService : IEVSEService
-    {
-        public EVSE GetEVSEbyChargeBoxId(string chargeBoxId)
-        {
-            throw new NotImplementedException();
-        }
-
-        public List<EVSE> GetEVSEsbyCustomerId(string customerId)
-        {
-            throw new NotImplementedException();
-        }
-
-        public List<EVSE> GetEVSEsbyCustomerIdAndStationId(string customerId, string stationId)
-        {
-            throw new NotImplementedException();
-        }
-    }
-}

+ 1 - 8
EVCB_OCPP.WEBAPI/Services/HttpClientService.cs

@@ -66,14 +66,7 @@ namespace EVCB_OCPP.WEBAPI.Services
 
             Init();
         }
-
-
-        //public HttpClientService(IServiceCollection services)
-        //{
-        //    _services = services;
-        //    Init();
-
-        //}
+       
 
         private void Init()
         {

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

@@ -101,11 +101,11 @@ namespace EVCB_OCPP.WEBAPI.Services
         {
             string sql_MachineOperateRecord = "INSERT INTO [dbo].[MachineOperateRecord](SerialNo, RequestType, RequestContent,Status, CreatedOn, FinishedOn,"
          + " EVSE_Value, EVSE_Status, ChargeBoxId, Action, ReportedOn) VALUES (@SerialNo, @RequestType, @RequestContent, @Status, @CreatedOn, @FinishedOn, @EVSE_Value, "
-         + "@EVSE_Status, @ChargeBoxId, @Action);";
+         + "@EVSE_Status, @ChargeBoxId, @Action,@ReportedOn);";
 
             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,@ReportedOn);";
+                ", @UpdatedOn);";
 
             string key = string.Empty;
             var parameters = new DynamicParameters();
@@ -127,7 +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);
+            parameters.Add("@ReportedOn", EVCBConfiguration.DefaultTime, DbType.DateTime, ParameterDirection.Input);
 
 
             using (SqlConnection conn = new SqlConnection(mainConnectionString))

+ 3 - 1
EVCB_OCPP.WEBAPI/Web.config

@@ -11,7 +11,9 @@
     <add name="ConnectionLogDBContext" connectionString="data source=172.1.2.187\SQLEXPRESS2017;initial catalog=StandardOCPP_ConnectionLog;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
     <add name="MainDBContext" connectionString="data source=172.1.2.187\SQLEXPRESS2017;initial catalog=StandardOCPP_Main;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
     <add name="MeterValueDBContext" connectionString="data source=172.1.2.187\SQLEXPRESS2017;initial catalog=StandardOCPP_MeterValue;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
-     <add name="APILogDBContext" connectionString="data source=172.1.2.187\SQLEXPRESS2017;initial catalog=StandardOCPP_APILog;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
+    <add name="APILogDBContext" connectionString="data source=172.1.2.187\SQLEXPRESS2017;initial catalog=StandardOCPP_APILog;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
+    <add name="WebDBContext" connectionString="data source=172.1.2.187\SQLEXPRESS2017;initial catalog=StandardOCPP_Web;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
+
   </connectionStrings>
   <appSettings>
     <add key="webpages:Version" value="3.0.0.0" />