Browse Source

查询优化

yuedefeng 6 years ago
parent
commit
15493570fd

+ 16 - 15
src/dashoo.cn/backend/api/business/oilsupplier/selectbusiness/selectservice.go

@@ -1,13 +1,15 @@
 package selectbusiness
 
 import (
-	"strconv"
-
 	. "dashoo.cn/backend/api/mydb"
 	"dashoo.cn/utils"
 	"github.com/go-xorm/xorm"
+	"strconv"
 )
 
+type TotalResult struct {
+	Total int64 `xorm:"INT(11) 'total'"`
+}
 type SelectService struct {
 	MyServiceBase
 }
@@ -19,10 +21,9 @@ func GetSelectService(xormEngine *xorm.Engine) *SelectService {
 }
 
 func (s *SelectService) GetMyPagingEntitiesWithOrderBytbl(supplierTableName, supplierCertTableName, OilInfoChangeName, OilSupplierCert2FileName string, pageIndex, itemsPerPage int64, orderby string, asc bool, entitiesPtr interface{}, where,having string) (total int64) {
-	var resultsSlice []map[string][]byte
 
 	//获取总记录数
-	sqlCount := `select count(*) from (`
+	/*sqlCount := `select count(*) from (`
 	sqlCount += `select a.Id,a.SupplierName,b.AccessCardNo,max(c.OldSupplierName) OldSupplierName,b.SupplierTypeCode,`
 	sqlCount += `a.LegalPerson,a.RegCapital,a.Mobile,b.AuditDate,b.ApplyTime,b.InFlag,a.ContactName,a.CommercialNo, `
 	sqlCount += `a.DepositBank,a.HseTraining,a.CompanyType,a.SetupTime,a.Address,a.Province,a.City,a.Street, `
@@ -33,10 +34,10 @@ func (s *SelectService) GetMyPagingEntitiesWithOrderBytbl(supplierTableName, sup
 	sqlCount += `left join ` + OilInfoChangeName + ` c  on c.SupplierId = a.Id `
 	sqlCount += `left join ` + OilSupplierCert2FileName + ` d  on d.SupplierId = b.Id `
 	sqlCount += `where ` + where
-	sqlCount += `group by a.Id,b.Id `+having+`) f`
+	sqlCount += `group by a.Id,b.Id `+having+`) f`*/
 
 	var sql string
-	sql = `select a.Id,a.SupplierName,b.AccessCardNo,max(c.OldSupplierName) OldSupplierName,b.SupplierTypeCode,`
+	sql = `select SQL_CALC_FOUND_ROWS a.Id,a.SupplierName,b.AccessCardNo,max(c.OldSupplierName) OldSupplierName,b.SupplierTypeCode,`
 	sql += `a.LegalPerson,a.RegCapital,a.Mobile,b.AuditDate,b.ApplyTime,b.InFlag,a.ContactName,a.CommercialNo, `
 	sql += `a.DepositBank,a.HseTraining,a.CompanyType,a.SetupTime,a.Address,a.Province,a.City,a.Street, `
 	sql += `a.LinkAddress,a.LinkProvince,a.LinkCity,a.LinkStreet,a.BusinessScope, `
@@ -54,17 +55,17 @@ func (s *SelectService) GetMyPagingEntitiesWithOrderBytbl(supplierTableName, sup
 		sql += ` order by ` + orderby + ` DESC `
 	}
 	sql += ` limit ` + utils.ToStr((pageIndex-1)*itemsPerPage) + "," + utils.ToStr(itemsPerPage)
-	s.DBE.SQL(sql).Find(entitiesPtr)
 
-	resultsSlice, _ = s.DBE.Query(sqlCount)
 
-	if len(resultsSlice) > 0 {
-		results := resultsSlice[0]
-		for _, value := range results {
-			total, _ = strconv.ParseInt(string(value), 10, 64)
-			break
-		}
-	}
+	sqlCount := "SELECT FOUND_ROWS() as total"
+
+	var totalResult TotalResult
+	session := s.DBE.NewSession()
+	session.Begin()
+	session.SQL(sql).Find(entitiesPtr)
+	session.SQL(sqlCount).Get(&totalResult)
+	session.Commit()
+	total = totalResult.Total
 
 	return total
 }

+ 13 - 6
src/dashoo.cn/backend/api/conf/app.conf

@@ -73,9 +73,16 @@ domain=oil_supplier
 
 [workflow]
 callbackHost=http://36dcae10.ngrok.io
-goodsModuleHost=http://10.76.248.23/upfile/dc1/3,01644aa886ae
-basisModuleHost=http://10.76.248.23/upfile/dc1/6,016598c26eb3
-techModuleHost=http://10.76.248.23/upfile/dc1/3,016626750eab
-OriginUrl=http://localhost:8080/acti-api/api
-AposeUrl=http://localhost:8080/acti-api/api/apose
-BaseUrl=http://localhost:8080/acti-api/api/acti
+# goodsModuleHost=http://10.76.248.23/upfile/dc1/3,01644aa886ae
+# basisModuleHost=http://10.76.248.23/upfile/dc1/6,016598c26eb3
+# techModuleHost=http://10.76.248.23/upfile/dc1/3,016626750eab
+# OriginUrl=http://localhost:8080/acti-api/api
+# AposeUrl=http://localhost:8080/acti-api/api/apose
+# BaseUrl=http://localhost:8080/acti-api/api/acti
+
+goodsModuleHost=http://weed1.labsop.cn:9390/3,255b9fa42e11
+basisModuleHost=http://weed1.labsop.cn:9390/6,255cf143a0f3
+techModuleHost=http://weed1.labsop.cn:9390/5,255d5b2ece8c
+OriginUrl=http://47.92.212.59:8080/acti-api/api		
+AposeUrl=http://47.92.212.59:8080/acti-api/api/apose		
+BaseUrl=http://47.92.212.59:8080/acti-api/api/acti