|
@@ -0,0 +1,102 @@
|
|
|
+using FccLite.Web.Core.database;
|
|
|
+using FccLite.Web.Domain.FccStationInfo.Input;
|
|
|
+using FccLite.Web.utils.database;
|
|
|
+using Microsoft.AspNetCore.Cors.Infrastructure;
|
|
|
+using Microsoft.EntityFrameworkCore;
|
|
|
+using System.Net;
|
|
|
+using System.Xml.Linq;
|
|
|
+
|
|
|
+namespace FccLite.Web.Repositories.FccStationInfo
|
|
|
+{
|
|
|
+ public class StationRepository : IStationRepository
|
|
|
+ {
|
|
|
+ private readonly MysqlDbContext _dbContext;
|
|
|
+ public StationRepository(MysqlDbContext dbContext)
|
|
|
+ {
|
|
|
+ _dbContext = dbContext;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 通过id查找站点信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ /// <exception cref="NotImplementedException"></exception>
|
|
|
+ public async Task<Domain.FccStationInfo.FccStationInfo?> FindByID(long id)
|
|
|
+ {
|
|
|
+ Domain.FccStationInfo.FccStationInfo? station = await _dbContext.FccStationInfos.FindAsync(id);
|
|
|
+ return station;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 条件分页查询
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="page">页码</param>
|
|
|
+ /// <param name="pageSize">页数</param>
|
|
|
+ /// <param name="id">过滤条件——id</param>
|
|
|
+ /// <param name="name">过滤条件——站名</param>
|
|
|
+ /// <param name="longitude">过滤条件——经度</param>
|
|
|
+ /// <param name="latitude">过滤条件——纬度</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<IEnumerable<Domain.FccStationInfo.FccStationInfo>> GetPage(int page, int pageSize, long? id, string? name, decimal? longitude, decimal? latitude)
|
|
|
+ {
|
|
|
+ IQueryable<Domain.FccStationInfo.FccStationInfo> query = _dbContext.FccStationInfos.AsQueryable();
|
|
|
+ query = query.WhereIf(id != null, info => info.Id == id);
|
|
|
+ query = query.WhereIf(!string.IsNullOrEmpty(name), info => info.Name.Contains(name));
|
|
|
+ query = query.WhereIf(longitude != null, info => info.Longitude == longitude);
|
|
|
+ query = query.WhereIf(latitude != null, info => info.Latitude == latitude);
|
|
|
+
|
|
|
+ return await query.Skip((page - 1) * pageSize).Take(pageSize).ToListAsync();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 新增/修改站点信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="stationInfoInput">站点信息</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<Domain.FccStationInfo.FccStationInfo?> Save(StationInfoInput stationInfoInput)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (stationInfoInput == null) return null;
|
|
|
+ if (stationInfoInput.IsNotNorm()) return null;
|
|
|
+ if (stationInfoInput.Id != null)
|
|
|
+ {
|
|
|
+ Domain.FccStationInfo.FccStationInfo? station = await _dbContext.FccStationInfos.FindAsync(stationInfoInput.Id);
|
|
|
+
|
|
|
+ if (station == null) return null;
|
|
|
+
|
|
|
+ station.BuildId = stationInfoInput.BuildId;
|
|
|
+ station.Name = stationInfoInput.Name != null ? stationInfoInput.Name : "";
|
|
|
+ station.Longitude = (decimal)(stationInfoInput.Longitude != null ? stationInfoInput.Longitude : new decimal(0));
|
|
|
+ station.Latitude = (decimal)(stationInfoInput.Latitude != null ? stationInfoInput.Latitude : new decimal(0));
|
|
|
+ station.SmallProgram = stationInfoInput.SmallProgram;
|
|
|
+ station.CloudService = stationInfoInput.CloudService;
|
|
|
+ station.MqttService = stationInfoInput.MqttService;
|
|
|
+ station.IcardService = stationInfoInput.IcardService != null ? stationInfoInput.IcardService : "";
|
|
|
+ station.ServicePort = stationInfoInput.ServicePort;
|
|
|
+ station.WebSocketPort = stationInfoInput.WebSocketPort;
|
|
|
+ _dbContext.SaveChanges();
|
|
|
+ return station;
|
|
|
+ }
|
|
|
+ Domain.FccStationInfo.FccStationInfo? fccStationInfo = stationInfoInput.ToComponent();
|
|
|
+ _dbContext.FccStationInfos.Add(fccStationInfo);
|
|
|
+ _dbContext.SaveChanges();
|
|
|
+ return fccStationInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 通过id 删除站点信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id">站点id</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<bool> DeleteByID(long id)
|
|
|
+ {
|
|
|
+ Domain.FccStationInfo.FccStationInfo? info = await _dbContext.FccStationInfos.FindAsync(id);
|
|
|
+ if (info == null) return false;
|
|
|
+ _dbContext.FccStationInfos.Remove(info);
|
|
|
+ _dbContext.SaveChanges();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|