|
- using Dapper;
- using MySql.Data.MySqlClient;
- using System.Data;
- using TelpoPush.Fence.Worker.Models.CacheTemplates;
-
- namespace TelpoPush.Fence.Worker.Service.Cache
- {
- public class SqlMapper
- {
- private readonly IConfiguration _config;
- private static string gps_conn = "";
- private static string telcommon_conn = "";
- public SqlMapper(IConfiguration config)
- {
- _config = config;
- gps_conn = _config["ConnectionStrings:DB_Connection_String"].ToString();
- telcommon_conn = _config["ConnectionStrings:Telpo_common_ConnString"].ToString();
- }
-
- public DeviceInfoModel DeviceInfo(string imei)
- {
- using (IDbConnection connection = new MySqlConnection(gps_conn))
- {
- var sql = @"SELECT d.device_id deviceId, p.nick_name deviceName,p.api_uid apiUid,d.serialno imei, d.org_uid orgId, d.active_status activeStatus,active_time activeTime FROM gps_device as d LEFT JOIN `gps_person` as p on p.device_id=d.device_id WHERE d.serialno=@imei";
- return connection.QueryFirstOrDefault<DeviceInfoModel>(sql, new { imei });
- }
- }
-
- public List<string> DeviceFenceWifi(string imei, string geofence_id)
- {
- using (IDbConnection connection = new MySqlConnection(gps_conn))
- {
- var sql = @"SELECT wifi_info FROM gps_geofence_wifi WHERE imei=@imei AND geofence_id=@geofence_id";
- return connection.Query<string>(sql, new { imei, geofence_id }).ToList();
- }
- }
-
- public List<DeviceFenceModels> DeviceFenceAll()
- {
- using (IDbConnection connection = new MySqlConnection(gps_conn))
- {
- var sql = @"SELECT geofence_id geofenceId,geofence_name geofenceName, device_id deviceId, serialno AS imei, radius, center_lat latitude, center_lng longitude, fence_type fenceType, is_active isActive, app_type appType, alarm_type alarmType, address FROM gps_geofence";
- return connection.Query<DeviceFenceModels>(sql ).ToList();
- }
- }
-
- public List<DeviceFenceModels> DeviceFencelist(string imei)
- {
- using (IDbConnection connection = new MySqlConnection(gps_conn))
- {
- var sql = @"SELECT geofence_id geofenceId,geofence_name geofenceName, device_id deviceId, serialno AS imei, radius, center_lat latitude, center_lng longitude, fence_type fenceType, is_active isActive, app_type appType, alarm_type alarmType, address FROM gps_geofence where serialno=@imei";
- return connection.Query<DeviceFenceModels>(sql, new { imei }).ToList();
- }
- }
-
- public List<pointList> DeviceFencePointlist(string geofence_id)
- {
- using (IDbConnection connection = new MySqlConnection(gps_conn))
- {
- var sql = @"SELECT geofence_id geofenceId, radius, longitude, latitude, vertex_index AS `index` FROM gps_geofence_details where geofence_id=@geofence_id ORDER BY `index`";
- return connection.Query<pointList>(sql, new { geofence_id }).ToList();
- }
- }
- }
- }
|