Procházet zdrojové kódy

Merge branch 'v2' of https://git.i2edu.net/packages/light-apiengine into v2

fei.li před 4 roky
rodič
revize
7548b1e469

+ 5 - 1
controllers/gen/SysWfController_gen.go

@@ -124,11 +124,15 @@ func (c *SysWfController) Recall(ctx *gin.Context) {
 }
 
 func (c *SysWfController) Interrupt(ctx *gin.Context) {
-	//
 	db := c.apiengine.BusinessOrmEngine[ctx.GetString("domain")]
 	partial.SysWf_Interrupt(&entitys.CtrlContext{c.apiengine, ctx, db, c.apiengine.PlatformOrmEngine})
 }
 
+func (c *SysWfController) RepairSync(ctx *gin.Context) {
+	db := c.apiengine.BusinessOrmEngine[ctx.GetString("domain")]
+	partial.SysWf_RepairSync(&entitys.CtrlContext{c.apiengine, ctx, db, c.apiengine.PlatformOrmEngine})
+}
+
 // Designer
 // @Title Designer
 // @Description 修改流程定义

+ 22 - 0
controllers/partial/SysWfController.go

@@ -210,6 +210,28 @@ func SysWf_Interrupt(c *entitys.CtrlContext) {
 	}
 }
 
+// _Interrupt
+// @Title _Interrupt
+// @Description 终止
+// @Param	instance_id      false  ""
+// @Success 200 {object} models.Account
+// @Failure 403 :id is empty
+func SysWf_RepairSync(c *entitys.CtrlContext) {
+	obj := map[string]interface{}{}
+	err := c.Ctx.Bind(&obj)
+	if err != nil {
+		c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
+		return
+	}
+	instanceId := fmt.Sprintf("%v", obj["instance_id"])
+	bytess, err := wfclient.NewWFClient(c).RepairSync(instanceId, obj, c)
+	if err == nil {
+		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
+	} else {
+		c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
+	}
+}
+
 // _Designer
 // @Title _Designer
 // @Description 修改流程定义

+ 6 - 3
engine/auth/auth.go

@@ -2,11 +2,13 @@ package auth
 
 import (
 	"errors"
+	"strconv"
+	"sync"
+	"time"
+
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
 	sysmodel "git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
 	sysutils "git.qianqiusoft.com/qianqiusoft/light-apiengine/utils"
-	"strconv"
-	"time"
 )
 
 type IAuth interface {
@@ -61,7 +63,7 @@ func GetAuth(t string) IAuth {
  * @param1 userInfo: 用户信息
  */
 func AddToGlobalTokenStore(c *entitys.CtrlContext, userInfo *sysmodel.SysUser) (*sysmodel.LoginReturnInfo, error) {
-	token := &entitys.Token{}
+	token := &entitys.Token{Lock: new(sync.RWMutex)}
 	timestamp := uint64(time.Now().UnixNano())
 	timestamp_str := strconv.FormatUint(timestamp, 10)
 	sec_tooken := sysutils.GenerateToken(userInfo.LoginId + timestamp_str)
@@ -98,6 +100,7 @@ func AddToGlobalTokenStore(c *entitys.CtrlContext, userInfo *sysmodel.SysUser) (
 	data.Name = businessUser.Name
 	data.Mobile = businessUser.Mobile
 	data.Email = businessUser.Email
+	data.Avatar = businessUser.Avatar
 
 	// 查找用户对应角色
 	var roles []sysmodel.SysRole

+ 2 - 1
engine/auth/auth_client.go

@@ -9,6 +9,7 @@ import (
 	"fmt"
 	"net"
 	"strconv"
+	"sync"
 	"time"
 
 	"git.qianqiusoft.com/library/glog"
@@ -366,7 +367,7 @@ func uint64ToBytes(v int) []byte {
 
 // 转token
 func bytesToToken(content []byte) (*entitys.Token, error) {
-	token := &entitys.Token{}
+	token := &entitys.Token{Lock: new(sync.RWMutex)}
 	var index int = 0
 	var size int
 	var err error = nil

+ 18 - 3
engine/system_init.go

@@ -5,13 +5,28 @@ import (
 	"regexp"
 	"time"
 
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/config"
 	"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"
 )
 
+// InitializeWithDefaultValue defined
+func InitializeWithDefaultValue(init int64, dlt int64) int64 {
+	if init == 0 {
+		return dlt
+	}
+	return init
+}
+
 func createDatabase(orm *xorm.Engine) {
+	maxLifeTime := InitializeWithDefaultValue(config.AppConfig.GetInt("max_life_time"), 10)
+	maxIdleConns := InitializeWithDefaultValue(config.AppConfig.GetInt("max_idle_conns"), 10)
+	maxOpenConns := InitializeWithDefaultValue(config.AppConfig.GetInt("max_open_conns"), 30)
+	fmt.Println("maxLifeTime = ", maxLifeTime)
+	fmt.Println("maxIdleConns = ", maxIdleConns)
+	fmt.Println("maxOpenConns = ", maxOpenConns)
 	if orm.DriverName() == "mysql" {
 		dbname := orm.DataSourceName()
 		reg := regexp.MustCompile("(.*)/(.*)(\\?.*)")
@@ -22,9 +37,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)
+			db.SetConnMaxLifetime(time.Duration(maxLifeTime) * time.Minute)
+			db.SetMaxIdleConns(int(maxIdleConns))
+			db.SetMaxOpenConns(int(maxOpenConns))
 			_, 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)

+ 3 - 0
entitys/token.go

@@ -1,6 +1,9 @@
 package entitys
 
+import "sync"
+
 type Token struct {
+	Lock         *sync.RWMutex
 	Result       int                    `json:"-"`
 	UserId       string                 `json:"user_id"`
 	AccessToken  string                 `json:"access_token"`

+ 5 - 2
models/LocalTime.go

@@ -42,9 +42,12 @@ func (t *LocalTime) UnmarshalJSON(data []byte) error {
 
 	if len(dataStr) > 19 {
 		dataStr = dataStr[0:19]
-		if dataStr == "1970-01-01 00:00:00" {
-			dataStr = timeFormat
+		if strings.Index(dataStr, "000") == 0 {
+			dataStr = zeroTime
 		}
+		// if dataStr == "1970-01-01 00:00:00" {
+		// 	dataStr = timeFormat
+		// }
 	} else if len(dataStr) == 10 {
 		dataStr += " 00:00:00"
 	} else if len(dataStr) == 13 {

+ 1 - 1
models/Sql_SysUser.go

@@ -2,7 +2,7 @@ package models
 
 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
+			id,login_id,password,name,full_name,mobile,email,avatar,org_id,type,status,domain,create_by,create_time,last_update_by,last_update_time,del_flag
         from sys_user
 		where %v = ? and del_flag = 0 and status = 0`
 

+ 2 - 0
models/SysMenu_gen.go

@@ -39,6 +39,8 @@ type SysMenu struct {
 	Hidden int32 `xorm:"'hidden' notnull "json:"hidden"`
 	//是否删除 1:删除   0:正常
 	DelFlag int32 `xorm:"'del_flag' notnull "json:"del_flag"`
+	//编码
+	Meta string `xorm:"'meta' varchar(1024) notnull "json:"meta"`
 }
 
 func (t *SysMenu) TableName() string {

+ 3 - 0
routers/sys_wf_gen.go

@@ -43,6 +43,9 @@ func registerSysWfRouter(e *engine.ApiEngine) {
 	//v1.GET("/recall",ctrler.Recall)
 	v1.POST("/interrupt", ctrler.Interrupt)
 
+	//v1.GET("/recall",ctrler.Recall)
+	v1.POST("/repair", ctrler.RepairSync)
+
 	//v1.GET("/newstep",ctrler.Recall)
 	v1.POST("/newstep", ctrler.NewStep)
 

+ 1 - 1
sqlconfig/light-apiengine/sys_menu_gen.xml

@@ -8,7 +8,7 @@
     </sql>
     <sql id="update_sys_menu">
         update sys_menu set
-		`name` = ?name,`code` = ?code,`parent` = ?parent,`inheritance` = ?inheritance,`url` = ?url,`component` = ?component,`perms` = ?perms,`type` = ?type,`icon` = ?icon,`order_num` = ?order_num,`create_by` = ?create_by,`create_time` = ?create_time,`last_update_by` = ?last_update_by,`last_update_time` = ?last_update_time,`hidden` = ?hidden,`del_flag` = ?del_flag
+		`name` = ?name,`code` = ?code,`meta` = ?meta,`parent` = ?parent,`inheritance` = ?inheritance,`url` = ?url,`component` = ?component,`perms` = ?perms,`type` = ?type,`icon` = ?icon,`order_num` = ?order_num,`create_by` = ?create_by,`create_time` = ?create_time,`last_update_by` = ?last_update_by,`last_update_time` = ?last_update_time,`hidden` = ?hidden,`del_flag` = ?del_flag
 		where id = ?id
     </sql>
     <sql id="deleteone_sys_menu">

+ 31 - 2
wfclient/client.go

@@ -259,7 +259,7 @@ func (w *WFClient) Run(instanceId, userId, choice, options, nextStep string, c *
 	for _, callbackKye := range callbacks {
 		callWFCallback(callbackKye, &CallbackArg{
 			DefineId:     RunRespInfo.DefineId,
-			InstanceId:   RunRespInfo.DefineId,
+			InstanceId:   RunRespInfo.InstanceId,
 			DefineName:   RunRespInfo.DefineName,
 			InstanceName: RunRespInfo.InstanceName,
 			FormData:     RunRespInfo.FormData,
@@ -285,7 +285,7 @@ func (w *WFClient) Run(instanceId, userId, choice, options, nextStep string, c *
 	for _, callbackKye := range linkCallbacks {
 		callWFCallback(callbackKye, &CallbackArg{
 			DefineId:     RunRespInfo.DefineId,
-			InstanceId:   RunRespInfo.DefineId,
+			InstanceId:   RunRespInfo.InstanceId,
 			DefineName:   RunRespInfo.DefineName,
 			InstanceName: RunRespInfo.InstanceName,
 			FormData:     RunRespInfo.FormData,
@@ -535,6 +535,35 @@ func (w *WFClient) Interrupt(definedId string, formData map[string]interface{},
 	return bytess, err
 }
 
+//同步修复回调
+func (w *WFClient) RepairSync(definedId string, formData map[string]interface{}, c *entitys.CtrlContext) ([]byte, error) {
+	var RunRespInfo struct {
+		DefineId      string      `json:"define_id"`
+		InstanceId    string      `json:"instance_id"`
+		DefineName    string      `json:"define_name"`
+		InstanceName  string      `json:"instance_name"`
+		Choices       []*Choice   `json:"choices"`
+		Transition    *Transition `json:"transition"`
+		StepType      string      `json:"step_type"`
+		FormData      string      `json:"form_data"`
+		StepName      string      `json:"step_name"`
+		ActorType     string      `json:"actor_type"`
+		Executor      string      `json:"executor"`
+		StartCallback string      `json:"start_callback"`
+	}
+	callWFCallback("repairSync", &CallbackArg{
+		DefineId:     RunRespInfo.DefineId,
+		InstanceId:   definedId,
+		DefineName:   RunRespInfo.DefineName,
+		InstanceName: RunRespInfo.InstanceName,
+		FormData:     formData["form_data"].(string),
+		Executor:     RunRespInfo.Executor,
+		UserId:       w.userId,
+		Context:      c,
+	})
+	return []byte{}, nil
+}
+
 //撤回
 func (w *WFClient) Delete(definedId string) ([]byte, error) {
 	url := w.getFullUrl("/api/wf_define/delete")