浏览代码

Merge branch 'v2' of https://git.qianqiusoft.com/qianqiusoft/light-apiengine into v2

huangyh 5 年之前
父节点
当前提交
ec6216f9b6

+ 3 - 1
controllers/partial/SystemController.go

@@ -2861,8 +2861,10 @@ func System_FindDataPermissionPage(c *entitys.CtrlContext) {
 
 	page, _ := strconv.Atoi(c.Ctx.DefaultQuery("page", "1"))
 	rows, _ := strconv.Atoi(c.Ctx.DefaultQuery("rows", "10"))
+	name := c.Ctx.Query("name")
+	code := c.Ctx.Query("code")
 
-	paramMap_i_t := map[string]interface{}{"page": page, "rows": rows}
+	paramMap_i_t := map[string]interface{}{"page": page, "rows": rows, "name": name, "code": code}
 	result, err := sysutils.PageSearch(c.Db, "system", "find_data_permission_page", "sys_data_permission", paramMap_i_t)
 	if err == nil {
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", result})

+ 18 - 2
engine/apiengine.go

@@ -2,6 +2,7 @@ package engine
 
 import (
 	"fmt"
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/middleware/logger"
 	"time"
 
 	//"github.com/gin-contrib/sessions"
@@ -22,6 +23,8 @@ import (
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/engine/auth"
 )
 
+var apiEngine *ApiEngine = nil
+
 type ApiEngine struct {
 	entitys.ApiEngineInterface
 	PlatformOrmEngine *xorm.Engine
@@ -40,8 +43,8 @@ func (g *ApiEngine) GetAllBusinessDb() map[string]*xorm.Engine {
 }
 
 func Default() *ApiEngine {
-	apiengine := NewApiEngine("mysql", config.AppConfig.DataSource, fmt.Sprintf(":%d", config.AppConfig.HttpPort))
-	return apiengine
+	apiEngine = NewApiEngine("mysql", config.AppConfig.DataSource, fmt.Sprintf(":%d", config.AppConfig.HttpPort))
+	return apiEngine
 }
 
 func NewApiEngine(driverName, dataSourceName string, addr string) *ApiEngine {
@@ -51,6 +54,9 @@ func NewApiEngine(driverName, dataSourceName string, addr string) *ApiEngine {
 	engine.PlatformOrmEngine, err = xorm.NewEngine(driverName, dataSourceName)
 	printError(err)
 
+	engine.PlatformOrmEngine.ShowSQL(true)
+	engine.PlatformOrmEngine.ShowExecTime(true)
+
 	initOrmEngine(engine.PlatformOrmEngine, driverName)
 	if config.AppConfig.SyncDb {
 
@@ -59,6 +65,7 @@ func NewApiEngine(driverName, dataSourceName string, addr string) *ApiEngine {
 	engine.GinEngine = gin.Default()
 
 	engine.GinEngine.Use(gzip.Gzip(gzip.DefaultCompression))
+	engine.GinEngine.Use(logger.LoggerMiddleware())
 
 	//启动session
 	//store := sessions.NewCookieStore([]byte("secret"))
@@ -149,3 +156,12 @@ func (g *ApiEngine) Run() {
 
 	g.GinEngine.Run(g.Listen_addr)
 }
+
+/**
+ * @brief: 获取对应业务engine,主要用于无法通过参数获取db的地方,例如init中启动定时器
+ * @param1 domain: 域名
+ * @return1: engine
+ */
+func GetBusinessDb(domain string) *xorm.Engine {
+	return apiEngine.BusinessOrmEngine[domain]
+}

+ 1 - 0
light-apiengine.xml

@@ -1291,6 +1291,7 @@
             <column name="status" caption="状态 0:禁用   1:正常" type="int32"/>
             <column isNull="false" name="sync_flag" caption="是否同步了数据库标志" type="int32"/>
             <column isNull="false" name="domain" caption="域" type="string" size="50" dbtype="varchar(36)"/>
+            <column isNull="false" name="copy_right" caption="版权" type="string" size="500" dbtype="varchar(500)"/>
             <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
             <column isNull="false" name="create_time" caption="创建时间" type="local_time" />
             <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>

+ 1 - 1
middleware/logger/cassandra.go

@@ -70,7 +70,7 @@ func cassandraLogHandler(logInfo *LogInfo){
 	reqDate := logInfo.ReqTime.Format("20060102")
 	//q := session.Query(cqlformat, __appName, reqDate, logInfo.ReqTime.Format("2006-01-02 15:04:05"), logInfo.ReqMethod, logInfo.ReqUrl, logInfo.ReqProto, logInfo.ReqUa, logInfo.ReqReferer, logInfo.ReqPostData, logInfo.RespTime.Format("2006-01-02 15:04:05"), logInfo.RespBody, logInfo.RespCode, logInfo.RespMsg, logInfo.RespData, logInfo.CostTime)
 	batch := session.NewBatch(gocql.UnloggedBatch)		// 应该批量插入多条,例如20条
-	batch.Query(cqlformat, __appName, reqDate, logInfo.ReqTime.Format("2006-01-02 15:04:05"), logInfo.LoginId,logInfo.ReqMethod, logInfo.ReqUrl, logInfo.ReqProto, logInfo.ReqUa, logInfo.ReqReferer, logInfo.ReqPostData, logInfo.RespTime.Format("2006-01-02 15:04:05"), logInfo.RespBody, logInfo.RespCode, logInfo.RespMsg, logInfo.RespData, logInfo.CostTime)
+	batch.Query(cqlformat, __appName, reqDate, logInfo.ReqTime.Format("2006-01-02 15:04:05"), logInfo.LoginId,logInfo.ReqMethod, logInfo.ReqUrl, logInfo.ReqProto, logInfo.ReqUa, logInfo.ReqReferer, strings.TrimSpace(logInfo.ReqPostData), logInfo.RespTime.Format("2006-01-02 15:04:05"), strings.TrimSpace(logInfo.RespBody), logInfo.RespCode, strings.TrimSpace(logInfo.RespMsg), strings.TrimSpace(logInfo.RespData), logInfo.CostTime)
 	if err := session.ExecuteBatch(batch); err != nil {
 		glog.Errorln("批量插入日志错误:", err)
 		return

+ 1 - 1
middleware/logger/logger.go

@@ -68,6 +68,7 @@ func init(){
 
 	// 设置app名称
 	__appName = config.AppConfig.GetKey("app_name")
+	__logInfoChan = make(chan *LogInfo, 2000)
 
 	// 日志处理
 	logProcess()
@@ -105,7 +106,6 @@ func LoggerMiddleware()gin.HandlerFunc{
 		logInfo.ReqPostData = c.Request.PostForm.Encode()
 		logInfo.ReqClientIp = c.ClientIP()
 
-
 		token := c.GetHeader("token")
 		if token != "" {
 			tk := utils.GetGlobalTokenStore().Get(token)

+ 25 - 22
models/SysDomain_gen.go

@@ -1,48 +1,51 @@
-package models
 
+package models
 import (
-//__import_packages__
+	//__import_packages__
 )
 
 type SysDomain struct {
 	//主键
-	Id string `xorm:"'id' varchar(36) pk notnull "json:"id"`
+	Id   string     `xorm:"'id' varchar(36) pk   notnull "json:"id"` 
 	//名称
-	Name string `xorm:"'name' varchar(36) notnull "json:"name"`
+	Name   string     `xorm:"'name' varchar(36)   notnull "json:"name"` 
 	//全名
-	FullName string `xorm:"'full_name' varchar(36) notnull "json:"full_name"`
+	FullName   string     `xorm:"'full_name' varchar(36)   notnull "json:"full_name"` 
 	//负责人
-	ContactName string `xorm:"'contact_name' varchar(36) notnull "json:"contact_name"`
+	ContactName   string     `xorm:"'contact_name' varchar(36)   notnull "json:"contact_name"` 
 	//负责人邮箱
-	ContactEmail string `xorm:"'contact_email' varchar(50) notnull "json:"contact_email"`
+	ContactEmail   string     `xorm:"'contact_email' varchar(50)   notnull "json:"contact_email"` 
 	//负责人电话
-	ContactMobile string `xorm:"'contact_mobile' varchar(50) notnull "json:"contact_mobile"`
+	ContactMobile   string     `xorm:"'contact_mobile' varchar(50)   notnull "json:"contact_mobile"` 
 	//数据库链接串
-	DataSource string `xorm:"'data_source' varchar(200) notnull "json:"data_source"`
+	DataSource   string     `xorm:"'data_source' varchar(200)   notnull "json:"data_source"` 
 	//网址
-	DomainUrl string `xorm:"'domain_url' varchar(200) notnull "json:"domain_url"`
+	DomainUrl   string     `xorm:"'domain_url' varchar(200)   notnull "json:"domain_url"` 
 	//登录页
-	LoginUrl string `xorm:"'login_url' varchar(200) notnull "json:"login_url"`
+	LoginUrl   string     `xorm:"'login_url' varchar(200)   notnull "json:"login_url"` 
 	//样式
-	Theme string `xorm:"'theme' varchar(50) null "json:"theme"`
+	Theme   string     `xorm:"'theme' varchar(50)   null "json:"theme"` 
 	//域类型
-	Type int32 `xorm:"'type' notnull "json:"type"`
+	Type   int32     `xorm:"'type'   notnull "json:"type"` 
 	//状态 0:禁用   1:正常
-	Status int32 `xorm:"'status' notnull "json:"status"`
+	Status   int32     `xorm:"'status'   notnull "json:"status"` 
 	//是否同步了数据库标志
-	SyncFlag int32 `xorm:"'sync_flag' notnull "json:"sync_flag"`
+	SyncFlag   int32     `xorm:"'sync_flag'   notnull "json:"sync_flag"` 
 	//域
-	Domain string `xorm:"'domain' varchar(36) notnull "json:"domain"`
+	Domain   string     `xorm:"'domain' varchar(36)   notnull "json:"domain"` 
+	//版权
+	CopyRight   string     `xorm:"'copy_right' varchar(500)   notnull "json:"copy_right"` 
 	//创建人
-	CreateBy string `xorm:"'create_by' varchar(36) notnull "json:"create_by"`
+	CreateBy   string     `xorm:"'create_by' varchar(36)   notnull "json:"create_by"` 
 	//创建时间
-	CreateTime LocalTime `xorm:"'create_time' notnull "json:"create_time"`
+	CreateTime   LocalTime     `xorm:"'create_time'   notnull "json:"create_time"` 
 	//最后更新人
-	LastUpdateBy string `xorm:"'last_update_by' varchar(36) notnull "json:"last_update_by"`
+	LastUpdateBy   string     `xorm:"'last_update_by' varchar(36)   notnull "json:"last_update_by"` 
 	//最后更新时间
-	LastUpdateTime int64 `xorm:"'last_update_time' notnull "json:"last_update_time"`
+	LastUpdateTime   int64     `xorm:"'last_update_time'   notnull "json:"last_update_time"` 
 	//是否删除 1:删除   0:正常
-	DelFlag int32 `xorm:"'del_flag' notnull "json:"del_flag"`
+	DelFlag   int32     `xorm:"'del_flag'   notnull "json:"del_flag"` 
+
 }
 
 func (t *SysDomain) TableName() string {
@@ -50,6 +53,6 @@ func (t *SysDomain) TableName() string {
 }
 
 func init() {
-	AddTableName("sys_domain")
+    AddTableName("sys_domain")
 	RegisterModel(new(SysDomain))
 }

+ 8 - 2
sqlconfig/system_controller/system_find_data_permission_page_count.tpl

@@ -1,7 +1,13 @@
 
 select
-    count(*) records
+    count(sys_data_permission.id) records
 from
     sys_data_permission
 where
-	del_flag = 0
+    sys_data_permission.del_flag = 0
+    {{if ne .name ""}}
+        AND sys_data_permission.name like '%{{.name}}%'
+    {{end}}
+    {{if ne .code ""}}
+        AND sys_data_permission.code like '%{{.code}}%'
+    {{end}}

+ 7 - 1
sqlconfig/system_controller/system_find_data_permission_page_select.tpl

@@ -4,5 +4,11 @@ select
 from
     sys_data_permission
 where
-    del_flag = 0
+    sys_data_permission.del_flag = 0
+    {{if ne .name ""}}
+        AND sys_data_permission.name like '%{{.name}}%'
+    {{end}}
+    {{if ne .code ""}}
+        AND sys_data_permission.code like '%{{.code}}%'
+    {{end}}
 LIMIT {{.rows}} OFFSET {{.offset}}