电子围栏推送服务
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

66 linhas
3.1KB

  1. using Dapper;
  2. using MySql.Data.MySqlClient;
  3. using System.Data;
  4. using TelpoPush.Fence.Worker.Models.CacheTemplates;
  5. namespace TelpoPush.Fence.Worker.Service.Cache
  6. {
  7. public class SqlMapper
  8. {
  9. private readonly IConfiguration _config;
  10. private static string gps_conn = "";
  11. private static string telcommon_conn = "";
  12. public SqlMapper(IConfiguration config)
  13. {
  14. _config = config;
  15. gps_conn = _config["ConnectionStrings:DB_Connection_String"].ToString();
  16. telcommon_conn = _config["ConnectionStrings:Telpo_common_ConnString"].ToString();
  17. }
  18. public DeviceInfoModel DeviceInfo(string imei)
  19. {
  20. using (IDbConnection connection = new MySqlConnection(gps_conn))
  21. {
  22. 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";
  23. return connection.QueryFirstOrDefault<DeviceInfoModel>(sql, new { imei });
  24. }
  25. }
  26. public List<string> DeviceFenceWifi(string imei, string geofence_id)
  27. {
  28. using (IDbConnection connection = new MySqlConnection(gps_conn))
  29. {
  30. var sql = @"SELECT wifi_info FROM gps_geofence_wifi WHERE imei=@imei AND geofence_id=@geofence_id";
  31. return connection.Query<string>(sql, new { imei, geofence_id }).ToList();
  32. }
  33. }
  34. public List<DeviceFenceModels> DeviceFenceAll()
  35. {
  36. using (IDbConnection connection = new MySqlConnection(gps_conn))
  37. {
  38. 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";
  39. return connection.Query<DeviceFenceModels>(sql ).ToList();
  40. }
  41. }
  42. public List<DeviceFenceModels> DeviceFencelist(string imei)
  43. {
  44. using (IDbConnection connection = new MySqlConnection(gps_conn))
  45. {
  46. 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";
  47. return connection.Query<DeviceFenceModels>(sql, new { imei }).ToList();
  48. }
  49. }
  50. public List<pointList> DeviceFencePointlist(string geofence_id)
  51. {
  52. using (IDbConnection connection = new MySqlConnection(gps_conn))
  53. {
  54. 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`";
  55. return connection.Query<pointList>(sql, new { geofence_id }).ToList();
  56. }
  57. }
  58. }
  59. }