From ff26d21a4ca5c7a88cd77a3b0f488f390259007d Mon Sep 17 00:00:00 2001 From: JianWeie Date: Thu, 14 Oct 2021 13:21:26 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=A0=B9=E6=8D=AE=E7=BB=8F=E7=BA=AC=E5=BA=A6=E8=B7=9D?= =?UTF-8?q?=E7=A6=BB=E6=9F=A5=E8=AF=A2=E9=97=A8=E5=BA=97=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Shop/CoreCmsStoreRepository.cs | 67 ++++++++++++------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/CoreCms.Net.Repository/Shop/CoreCmsStoreRepository.cs b/CoreCms.Net.Repository/Shop/CoreCmsStoreRepository.cs index 6032a0e..febaa6c 100644 --- a/CoreCms.Net.Repository/Shop/CoreCmsStoreRepository.cs +++ b/CoreCms.Net.Repository/Shop/CoreCmsStoreRepository.cs @@ -146,38 +146,57 @@ namespace CoreCms.Net.Repository RefAsync totalCount = 0; //MySql与SqlServer查询语句相同 - var sql = string.Empty; + List page; if (latitude > 0 && longitude > 0) { var sqrt = "SQRT(power(SIN((" + latitude + "*PI()/180-(CoreCmsStore.latitude)*PI()/180)/2),2)+COS(" + latitude + "*PI()/180)*COS((CoreCmsStore.latitude)*PI()/180)*power(SIN((" + longitude + "*PI()/180-(CoreCmsStore.longitude)*PI()/180)/2),2))"; - sql = "SELECT id, storeName, mobile, linkMan, logoImage, areaId, address, coordinate, latitude, longitude, isDefault, createTime, updateTime, ROUND(6378.138*2*ASIN(" + sqrt + ")*1000,2) AS distance FROM CoreCmsStore"; + var sql = "SELECT id, storeName, mobile, linkMan, logoImage, areaId, address, coordinate, latitude, longitude, isDefault, createTime, updateTime, ROUND(6378.138*2*ASIN(" + sqrt + ")*1000,2) AS distance FROM CoreCmsStore"; + + page = await DbClient.SqlQueryable(sql) + .WhereIF(predicate != null, predicate) + .OrderByIF(orderByExpression != null, orderByExpression, orderByType) + .Select(p => new CoreCmsStore + { + id = p.id, + storeName = p.storeName, + mobile = p.mobile, + linkMan = p.linkMan, + logoImage = p.logoImage, + areaId = p.areaId, + address = p.address, + coordinate = p.coordinate, + latitude = p.latitude, + longitude = p.longitude, + isDefault = p.isDefault, + createTime = p.createTime, + updateTime = p.updateTime, + distance = Convert.ToDecimal(p.distance) + }).ToPageListAsync(pageIndex, pageSize, totalCount); } else { - sql = "SELECT id, storeName, mobile, linkMan, logoImage, areaId, address, coordinate, latitude, longitude, isDefault, createTime, updateTime, distance FROM CoreCmsStore"; + page = await DbClient.Queryable() + .WhereIF(predicate != null, predicate) + .OrderByIF(orderByExpression != null, orderByExpression, orderByType) + .Select(p => new CoreCmsStore + { + id = p.id, + storeName = p.storeName, + mobile = p.mobile, + linkMan = p.linkMan, + logoImage = p.logoImage, + areaId = p.areaId, + address = p.address, + coordinate = p.coordinate, + latitude = p.latitude, + longitude = p.longitude, + isDefault = p.isDefault, + createTime = p.createTime, + updateTime = p.updateTime, + distance = Convert.ToDecimal(p.distance) + }).ToPageListAsync(pageIndex, pageSize, totalCount); } - var page = await DbClient.SqlQueryable(sql) - .WhereIF(predicate != null, predicate) - .OrderByIF(orderByExpression != null, orderByExpression, orderByType) - .Select(p => new CoreCmsStore - { - id = p.id, - storeName = p.storeName, - mobile = p.mobile, - linkMan = p.linkMan, - logoImage = p.logoImage, - areaId = p.areaId, - address = p.address, - coordinate = p.coordinate, - latitude = p.latitude, - longitude = p.longitude, - isDefault = p.isDefault, - createTime = p.createTime, - updateTime = p.updateTime, - distance = Convert.ToDecimal(p.distance) - }).ToPageListAsync(pageIndex, pageSize, totalCount); - var list = new PageList(page, pageIndex, pageSize, totalCount); return list; }