瀏覽代碼

Merge branch 'v2' of https://git.i2erp.cn/packages/light-apiengine into v2

aries.zhang 5 年之前
父節點
當前提交
7df1f3c3a7
共有 3 個文件被更改,包括 13 次插入5 次删除
  1. 6 2
      engine/system_init.go
  2. 1 1
      models/Sql_SysUser.go
  3. 6 2
      utils/page_util.go

+ 6 - 2
engine/system_init.go

@@ -2,12 +2,13 @@ package engine
 
 import (
 	"fmt"
+	"regexp"
+	"time"
+
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/logs"
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/utils"
 	"github.com/xormplus/xorm"
-	"regexp"
-	"time"
 )
 
 func createDatabase(orm *xorm.Engine) {
@@ -21,6 +22,9 @@ func createDatabase(orm *xorm.Engine) {
 			dbname = strings[2]
 			db, _ := xorm.NewEngine(orm.DriverName(), strings[1]+"/")
 			db.ShowSQL(true)
+			db.SetConnMaxLifetime(10 * time.Minute)
+			db.SetMaxIdleConns(10)
+			db.SetMaxOpenConns(80)
 			_, err := db.Sql("CREATE DATABASE IF NOT EXISTS `" + dbname + "` default charset utf8 COLLATE utf8_general_ci").Execute()
 			if err != nil {
 				fmt.Println("create database error", err)

+ 1 - 1
models/Sql_SysUser.go

@@ -4,7 +4,7 @@ var SqlUserLogin = `
         select
 			id,login_id,password,name,full_name,mobile,email,org_id,type,status,domain,create_by,create_time,last_update_by,last_update_time,del_flag
         from sys_user
-		where login_id = ?`
+		where login_id = ? and del_flag=0`
 
 var SqlUserInfoPage = `SELECT
   sys_user.*,

+ 6 - 2
utils/page_util.go

@@ -2,6 +2,7 @@ package utils
 
 import (
 	"fmt"
+
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
 	"github.com/xormplus/xorm"
 )
@@ -40,7 +41,10 @@ func PageSearch(engine *xorm.Engine, controllername string, apiname string, tabl
 		return &presult, nil
 	}
 
-	records := cresult[0]["records"].(int64)
+	var records int64
+	if cresult != nil && len(cresult) > 0 {
+		records = cresult[0]["records"].(int64)
+	}
 
 	var totalPageSize int64 = 0
 	if records < int64(rows) {
@@ -48,7 +52,7 @@ func PageSearch(engine *xorm.Engine, controllername string, apiname string, tabl
 	} else if records%int64(rows) == 0 {
 		totalPageSize = records / int64(rows)
 	} else {
-		totalPageSize = records / int64(rows) + 1
+		totalPageSize = records/int64(rows) + 1
 	}
 
 	presult := models.PageResult{}