feat: 新增第三方登录认证和管理
This commit is contained in:
@@ -60,7 +60,7 @@ func ImportSQL() {
|
||||
processSQLFile(db, sqlPath)
|
||||
}
|
||||
|
||||
log.Println("process success")
|
||||
// log.Println("process success")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
@@ -93,8 +93,36 @@ func processSQLFile(db *gorm.DB, filePath string) {
|
||||
if strings.HasSuffix(line, ";") {
|
||||
// 执行 SQL 语句
|
||||
if err := db.Exec(sqlBuilder.String()).Error; err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
return
|
||||
errorStr := strings.ToLower(err.Error())
|
||||
// log.Printf("Exec SQL: %s\n", line)
|
||||
// log.Println(err.Error())
|
||||
if strings.Contains(errorStr, "duplicate column") {
|
||||
// 忽略重复字段错误
|
||||
// Error 1060 (42S21): Duplicate column name 'field_name'
|
||||
// SQL logic error: duplicate column name: title (1)
|
||||
} else if strings.Contains(errorStr, "duplicate key") {
|
||||
// 忽略重复索引错误
|
||||
// Error 1061 (42000): Duplicate key name 'key_name'
|
||||
} else if strings.Contains(errorStr, "duplicate entry") {
|
||||
// 忽略重复记录错误
|
||||
// Error 1062 (23000): Duplicate entry 'value' for key 'key_name'
|
||||
log.Println(err.Error())
|
||||
} else if strings.Contains(errorStr, "unknown column") {
|
||||
// 忽略未知字段错误
|
||||
// Error 1054 (42S22): Unknown column 'field_name' in 'table'
|
||||
} else if strings.Contains(errorStr, "can't drop") {
|
||||
// 忽略删除字段或索引错误
|
||||
// Error 1091 (42000): Can't DROP COLUMN `field_name`; check that it exists
|
||||
// Error 1091 (42000): Can't DROP 'idx_ne_type_id'; check that column/key exists
|
||||
} else if strings.Contains(errorStr, "doesn't match") {
|
||||
// 忽略列数不匹配错误
|
||||
// Error 1136 (21S01): Column count doesn't match value count at row 1
|
||||
log.Println(err.Error())
|
||||
} else {
|
||||
// 其他错误终止程序
|
||||
log.Fatalln(errorStr)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
sqlBuilder.Reset()
|
||||
|
||||
@@ -15,8 +15,14 @@ type localeItem struct {
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
var dataCache map[string][]localeItem = make(map[string][]localeItem)
|
||||
|
||||
// LoadLocaleData 加载国际化数据
|
||||
func LoadLocaleData(language string) []localeItem {
|
||||
if data, ok := dataCache[language]; ok {
|
||||
return data
|
||||
}
|
||||
|
||||
dictType := fmt.Sprintf("i18n_%s", language)
|
||||
dictTypeList := systemService.NewSysDictType.DictDataCache(dictType)
|
||||
localeData := []localeItem{}
|
||||
@@ -27,6 +33,7 @@ func LoadLocaleData(language string) []localeItem {
|
||||
Code: v.DictCode,
|
||||
})
|
||||
}
|
||||
dataCache[language] = localeData
|
||||
return localeData
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package collectlogs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -48,22 +47,11 @@ const (
|
||||
BUSINESS_TYPE_CLEAN = "8"
|
||||
)
|
||||
|
||||
const (
|
||||
// 操作人类别-其它
|
||||
OPERATOR_TYPE_OTHER = "0"
|
||||
|
||||
// 操作人类别-后台用户
|
||||
OPERATOR_TYPE_MANAGE = "1"
|
||||
|
||||
// 操作人类别-手机端用户
|
||||
OPERATOR_TYPE_MOBILE = "2"
|
||||
)
|
||||
|
||||
// Option 操作日志参数
|
||||
type Options struct {
|
||||
Title string `json:"title"` // 标题
|
||||
BusinessType string `json:"businessType"` // 类型,默认常量 BUSINESS_TYPE_OTHER
|
||||
OperatorType string `json:"operatorType"` // 操作人类别,默认常量 OPERATOR_TYPE_OTHER
|
||||
OperatorType string `json:"operatorType"` // 操作人类别
|
||||
IsSaveRequestData bool `json:"isSaveRequestData"` // 是否保存请求的参数
|
||||
IsSaveResponseData bool `json:"isSaveResponseData"` // 是否保存响应的参数
|
||||
}
|
||||
@@ -79,7 +67,6 @@ func OptionNew(title, businessType string) Options {
|
||||
return Options{
|
||||
Title: title,
|
||||
BusinessType: businessType,
|
||||
OperatorType: OPERATOR_TYPE_OTHER,
|
||||
IsSaveRequestData: true,
|
||||
IsSaveResponseData: true,
|
||||
}
|
||||
@@ -113,7 +100,7 @@ func OperateLog(options Options) gin.HandlerFunc {
|
||||
operLog := model.SysLogOperate{
|
||||
Title: options.Title,
|
||||
BusinessType: options.BusinessType,
|
||||
OperatorType: options.OperatorType,
|
||||
OperatorType: loginUser.User.UserType,
|
||||
Method: funcName,
|
||||
OperURL: c.Request.URL.Path,
|
||||
RequestMethod: c.Request.Method,
|
||||
@@ -125,10 +112,6 @@ func OperateLog(options Options) gin.HandlerFunc {
|
||||
TenantID: loginUser.User.Tenant.TenantID,
|
||||
}
|
||||
|
||||
if loginUser.User.UserType == "sys" {
|
||||
operLog.OperatorType = OPERATOR_TYPE_MANAGE
|
||||
}
|
||||
|
||||
// 是否需要保存request,参数和值
|
||||
if options.IsSaveRequestData {
|
||||
params := ctx.RequestParamsMap(c)
|
||||
@@ -158,8 +141,15 @@ func OperateLog(options Options) gin.HandlerFunc {
|
||||
contentDisposition := c.Writer.Header().Get("Content-Disposition")
|
||||
contentType := c.Writer.Header().Get("Content-Type")
|
||||
content := contentType + contentDisposition
|
||||
msg := fmt.Sprintf(`{"status":"%d","size":"%d","content-type":"%s"}`, status, c.Writer.Size(), content)
|
||||
operLog.OperMsg = msg
|
||||
msgByte, err := json.Marshal(map[string]any{
|
||||
"status": status,
|
||||
"size": c.Writer.Size(),
|
||||
"content-type": content,
|
||||
})
|
||||
if err != nil {
|
||||
operLog.OperMsg = ""
|
||||
}
|
||||
operLog.OperMsg = string(msgByte)
|
||||
}
|
||||
|
||||
// 日志记录时间
|
||||
|
||||
Reference in New Issue
Block a user