/// <summary> /// 保养流程的蓄电池覆盖区域 /// </summary> /// <returns></returns> public ActionResult GetBaoYangBatteryCoverAreas(SearchBaoYangBatteryCoverAreaRequest request) { var result = _batteryManager.GetBaoYangBatteryCoverAreaList(request); return(Json(new { status = result != null, data = result, total = result?.FirstOrDefault()?.Total ?? 0, }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 这个是保养流程的,还有一个是蓄电池流程 /// </summary> /// <param name="request"></param> /// <returns></returns> public List <BaoYangBatteryCoverArea> GetBaoYangBatteryCoverAreaList(SearchBaoYangBatteryCoverAreaRequest request) { List <BaoYangBatteryCoverArea> list = null; try { var result = dbScopeManagerBaoYangRead.Execute(conn => _battery.SelectBaoYangBatteryCoverAreas(conn, request)); list = result.ToList(); var regions = list.Select(x => x.ProvinceId).Distinct().Select(x => GetRegionByRegionId(x)); list.ForEach(x => { var region = regions.FirstOrDefault(r => r != null && r.ProvinceId == x.ProvinceId); if (region != null) { //直辖市只到市 if (region.IsMunicipality) { if (region.ProvinceId == x.CityId) { x.CityName = region.ProvinceName; x.ProvinceName = region.ProvinceName; } } else { var city = region.ChildRegions?.FirstOrDefault(cr => cr != null && cr.CityId == x.CityId); if (city != null) { x.CityName = city.CityName; x.ProvinceName = city.ProvinceName; } } } }); } catch (Exception ex) { Logger.Error(ex.Message, ex); } return(list ?? new List <BaoYangBatteryCoverArea>()); }
/// <summary> /// 查询 /// </summary> /// <param name="dbHelper"></param> /// <param name="request"></param> /// <returns></returns> public IEnumerable <BaoYangBatteryCoverArea> SelectBaoYangBatteryCoverAreas(SqlConnection conn, SearchBaoYangBatteryCoverAreaRequest request) { const string sql = @"SELECT t.PKID , t.Brand , t.ProvinceId , t.CityId , t.Channels , t.IsEnabled , t.CreateDatetime , t.LastUpdateDateTime , COUNT(1) OVER ( ) AS Total FROM BaoYang.dbo.BaoYangBatteryCoverArea AS t WITH ( NOLOCK ) WHERE ( @Brand IS NULL OR @Brand = N'' OR t.Brand = @Brand ) AND ( @ProvinceId <= 0 OR t.ProvinceId = @ProvinceId ) AND ( @CityId <= 0 OR t.CityId = @CityId ) ORDER BY t.ProvinceId , t.CityId OFFSET @Skip ROWS FETCH NEXT @Take ROWS ONLY"; var take = request.PageSize; var skip = (request.PageIndex - 1) * take; var result = conn.Query <BaoYangBatteryCoverArea>(sql, new { Take = take, Skip = skip, ProvinceId = request.City, CityId = request.Province, request.Brand }, commandType: CommandType.Text); return(result); }