public static DynamicSql SqlProjectFields( this DynamicSql query, DeviceQueryProjection model) { query = DynamicSql.DeepClone(query); var finalFields = model.GetFieldsArr() .Where(f => DeviceQueryProjection.Projections.ContainsKey(f)) .Select(f => DeviceQueryProjection.Projections[f]); if (finalFields.Any()) { var projectionClause = string.Join(',', finalFields); query.DynamicForm = query.DynamicForm .Replace(DynamicSql.PROJECTION, projectionClause); } var finalResults = model.GetFieldsArr() .Where(f => DeviceQueryProjection.Results.ContainsKey(f)) .Select(f => DeviceQueryProjection.Results[f]); query.MultiResults.AddRange(finalResults); return(query); }
public static DynamicSql SqlJoin( this DynamicSql query, DeviceQueryProjection model) { query = DynamicSql.DeepClone(query); var joins = model.GetFieldsArr() .Where(f => DeviceQueryProjection.Joins.ContainsKey(f)) .Select(f => DeviceQueryProjection.Joins[f]); if (joins.Any()) { var joinClause = string.Join('\n', joins); query.DynamicForm = query.DynamicForm .Replace(DynamicSql.JOIN, joinClause); } return(query); }
public IDictionary <string, object> GetDeviceDynamic( DeviceQueryRow row, DeviceQueryProjection projection, DeviceQueryOptions options) { var obj = new Dictionary <string, object>(); foreach (var f in projection.GetFieldsArr()) { switch (f) { case DeviceQueryProjection.INFO: { var entity = row.Device; obj["id"] = entity.Id; obj["code"] = entity.Code; obj["name"] = entity.Name; obj["description"] = entity.Description; obj["area_id"] = entity.AreaId; obj["buliding_id"] = entity.BuildingId; obj["floor_id"] = entity.FloorId; obj["location_id"] = entity.LocationId; obj["lat"] = entity.Lat; obj["lon"] = entity.Lon; obj["schedule_id"] = entity.ScheduleId; } break; case DeviceQueryProjection.AREA: { var entity = row.Area; if (entity != null) { obj["area"] = new { id = entity.Id, name = entity.Name, code = entity.Code, } } ; } break; case DeviceQueryProjection.FLOOR: { var entity = row.Floor; if (entity != null) { obj["floor"] = new { id = entity.Id, name = entity.Name, code = entity.Code, floor_plan_svg = entity.FloorPlanSvg } } ; } break; case DeviceQueryProjection.BUILDING: { var entity = row.Building; if (entity != null) { obj["building"] = new { id = entity.Id, name = entity.Name, code = entity.Code } } ; } break; case DeviceQueryProjection.LOCATION: { var entity = row.Location; if (entity != null) { obj["location"] = new { id = entity.Id, name = entity.Name, code = entity.Code, } } ; } break; case DeviceQueryProjection.ACCOUNT: { var entity = row.DeviceAccount; obj["account"] = new { id = entity.Id, username = entity.UserName }; } break; case DeviceQueryProjection.SCHEDULE: { var entity = row.Schedule; if (entity != null) { obj["schedule"] = new { id = entity.Id, name = entity.Name, code = entity.Code, } } ; } break; } } return(obj); }