clear:formatting code
This commit is contained in:
1 parent
426cec1b62
commit
8c554d7ee7
52 files changed
+486
-502
No files matched your search
@@ -7,3 +7,4 @@ temp/
|
||||
vendor
|
||||
config/settings.dev.yml
|
||||
go-admin
|
||||
middleware/demo.go
|
||||
@@ -47,7 +47,6 @@ func ServerInfo(c *gin.Context) {
|
||||
cpuDic := make(map[string]interface{}, 0)
|
||||
cpuDic["cpuNum"], _ = cpu.Counts(false)
|
||||
|
||||
|
||||
app.Custum(c, gin.H{
|
||||
"code": 200,
|
||||
"os": osDic,
|
||||
|
||||
@@ -86,7 +86,7 @@ func GetConfigByConfigKey(c *gin.Context) {
|
||||
result, err := Config.Get()
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
app.OK(c, result,result.ConfigValue)
|
||||
app.OK(c, result, result.ConfigValue)
|
||||
}
|
||||
|
||||
// @Summary 添加配置
|
||||
@@ -107,7 +107,7 @@ func InsertConfig(c *gin.Context) {
|
||||
result, err := data.Create()
|
||||
tools.HasError(err, "", -1)
|
||||
|
||||
app.OK(c, result,"")
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
// @Summary 修改配置
|
||||
@@ -127,7 +127,7 @@ func UpdateConfig(c *gin.Context) {
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
result, err := data.Update(data.ConfigId)
|
||||
tools.HasError(err, "", -1)
|
||||
app.OK(c, result,"")
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
// @Summary 删除配置
|
||||
@@ -145,5 +145,3 @@ func DeleteConfig(c *gin.Context) {
|
||||
tools.HasError(err, "修改失败", 500)
|
||||
app.OK(c, result, msg.DeletedSuccess)
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -26,17 +26,17 @@ func GetDeptList(c *gin.Context) {
|
||||
Dept.DataScope = tools.GetUserIdStr(c)
|
||||
result, err := Dept.SetDept(true)
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
app.OK(c,result,"")
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
func GetDeptTree(c *gin.Context) {
|
||||
var Dept models.SysDept
|
||||
Dept.DeptName = c.Request.FormValue("deptName")
|
||||
Dept.Status= c.Request.FormValue("status")
|
||||
Dept.Status = c.Request.FormValue("status")
|
||||
Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId"))
|
||||
result, err := Dept.SetDept(false)
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
app.OK(c,result,"")
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
// @Summary 部门列表数据
|
||||
@@ -53,7 +53,7 @@ func GetDept(c *gin.Context) {
|
||||
Dept.DataScope = tools.GetUserIdStr(c)
|
||||
result, err := Dept.Get()
|
||||
tools.HasError(err, msg.NotFound, 404)
|
||||
app.OK(c,result, msg.GetSuccess)
|
||||
app.OK(c, result, msg.GetSuccess)
|
||||
}
|
||||
|
||||
// @Summary 添加部门
|
||||
@@ -73,7 +73,7 @@ func InsertDept(c *gin.Context) {
|
||||
data.CreateBy = tools.GetUserIdStr(c)
|
||||
result, err := data.Create()
|
||||
tools.HasError(err, "", -1)
|
||||
app.OK(c,result, msg.CreatedSuccess)
|
||||
app.OK(c, result, msg.CreatedSuccess)
|
||||
}
|
||||
|
||||
// @Summary 修改部门
|
||||
@@ -94,7 +94,7 @@ func UpdateDept(c *gin.Context) {
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
result, err := data.Update(data.DeptId)
|
||||
tools.HasError(err, "", -1)
|
||||
app.OK(c,result, msg.UpdatedSuccess)
|
||||
app.OK(c, result, msg.UpdatedSuccess)
|
||||
}
|
||||
|
||||
// @Summary 删除部门
|
||||
@@ -109,7 +109,7 @@ func DeleteDept(c *gin.Context) {
|
||||
id, err := tools.StringToInt(c.Param("id"))
|
||||
_, err = data.Delete(id)
|
||||
tools.HasError(err, "删除失败", 500)
|
||||
app.OK(c,"", msg.DeletedSuccess)
|
||||
app.OK(c, "", msg.DeletedSuccess)
|
||||
}
|
||||
|
||||
func GetDeptTreeRoleselect(c *gin.Context) {
|
||||
@@ -124,7 +124,7 @@ func GetDeptTreeRoleselect(c *gin.Context) {
|
||||
menuIds, err = SysRole.GetRoleDeptId()
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
}
|
||||
app.Custum(c,gin.H{
|
||||
app.Custum(c, gin.H{
|
||||
"code": 200,
|
||||
"depts": result,
|
||||
"checkedKeys": menuIds,
|
||||
|
||||
@@ -148,5 +148,5 @@ func DeleteDictData(c *gin.Context) {
|
||||
IDS := tools.IdsStrToIdsIntGroup("dictCode", c)
|
||||
result, err := data.BatchDelete(IDS)
|
||||
tools.HasError(err, "修改失败", 500)
|
||||
app.OK(c,result,"删除成功")
|
||||
app.OK(c, result, "删除成功")
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package system
|
||||
|
||||
import(
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -33,8 +33,7 @@ $(function(){
|
||||
</html>
|
||||
`
|
||||
|
||||
|
||||
func HelloWorld(c *gin.Context){
|
||||
func HelloWorld(c *gin.Context) {
|
||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||
c.String(200, INDEX)
|
||||
c.String(200, INDEX)
|
||||
}
|
||||
+4
-4
@@ -54,7 +54,7 @@ func GetPost(c *gin.Context) {
|
||||
Post.PostId, _ = tools.StringToInt(c.Param("postId"))
|
||||
result, err := Post.Get()
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
app.OK(c,result,"")
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
// @Summary 添加岗位
|
||||
@@ -74,7 +74,7 @@ func InsertPost(c *gin.Context) {
|
||||
tools.HasError(err, "", 500)
|
||||
result, err := data.Create()
|
||||
tools.HasError(err, "", -1)
|
||||
app.OK(c,result,"")
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
// @Summary 修改岗位
|
||||
@@ -95,7 +95,7 @@ func UpdatePost(c *gin.Context) {
|
||||
tools.HasError(err, "", -1)
|
||||
result, err := data.Update(data.PostId)
|
||||
tools.HasError(err, "", -1)
|
||||
app.OK(c,result,"修改成功")
|
||||
app.OK(c, result, "修改成功")
|
||||
}
|
||||
|
||||
// @Summary 删除岗位
|
||||
@@ -111,5 +111,5 @@ func DeletePost(c *gin.Context) {
|
||||
IDS := tools.IdsStrToIdsIntGroup("postId", c)
|
||||
result, err := data.BatchDelete(IDS)
|
||||
tools.HasError(err, "删除失败", 500)
|
||||
app.OK(c,result,"删除成功")
|
||||
app.OK(c, result, "删除成功")
|
||||
}
|
||||
@@ -31,7 +31,7 @@ func GetDBColumnList(c *gin.Context) {
|
||||
}
|
||||
|
||||
data.TableName = c.Request.FormValue("tableName")
|
||||
tools2.Assert(data.TableName=="","table name cannot be empty!",500)
|
||||
tools2.Assert(data.TableName == "", "table name cannot be empty!", 500)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||
tools2.HasError(err, "", -1)
|
||||
|
||||
|
||||
+7
-7
@@ -73,8 +73,8 @@ func GenCode(c *gin.Context) {
|
||||
_ = tools2.PathCreate("./apis/" + tab.ModuleName + "/")
|
||||
_ = tools2.PathCreate("./models/")
|
||||
_ = tools2.PathCreate("./router/")
|
||||
_ = tools2.PathCreate(config.GenConfig.FrontPath+"/api/")
|
||||
_ = tools2.PathCreate(config.GenConfig.FrontPath+"/views/"+tab.PackageName)
|
||||
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/api/")
|
||||
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.PackageName)
|
||||
|
||||
var b1 bytes.Buffer
|
||||
err = t1.Execute(&b1, tab)
|
||||
@@ -92,15 +92,15 @@ func GenCode(c *gin.Context) {
|
||||
tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.PackageName+".js")
|
||||
tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.PackageName+"/index.vue")
|
||||
|
||||
oldTest:="// {{认证路由自动补充在此处请勿删除}}"
|
||||
newText:="// {{认证路由自动补充在此处请勿删除}} \r\n register"+tab.ClassName+"Router(v1,authMiddleware)"
|
||||
oldTest := "// {{认证路由自动补充在此处请勿删除}}"
|
||||
newText := "// {{认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1,authMiddleware)"
|
||||
|
||||
helper := tools2.ReplaceHelper{
|
||||
Root: "./router/router.go",
|
||||
OldText:oldTest,
|
||||
Root: "./router/router.go",
|
||||
OldText: oldTest,
|
||||
NewText: newText,
|
||||
}
|
||||
if helper.OldText == helper.NewText{
|
||||
if helper.OldText == helper.NewText {
|
||||
log.Println("error !! the NewText isEqual the OldText")
|
||||
return
|
||||
}
|
||||
|
||||
+35
-35
@@ -18,46 +18,46 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
)
|
||||
)
|
||||
|
||||
var (
|
||||
configYml string
|
||||
port string
|
||||
mode string
|
||||
StartCmd = &cobra.Command{
|
||||
Use: "server",
|
||||
Short: "Start API server",
|
||||
Example: "go-admin server config/settings.yml",
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
usage()
|
||||
setup()
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return run()
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
StartCmd.PersistentFlags().StringVarP(&configYml, "config", "c", "config/settings.yml", "Start server with provided configuration file")
|
||||
StartCmd.PersistentFlags().StringVarP(&port, "port", "p", "8000", "Tcp port server listening on")
|
||||
StartCmd.PersistentFlags().StringVarP(&mode, "mode", "m", "dev", "server mode ; eg:dev,test,prod")
|
||||
var (
|
||||
configYml string
|
||||
port string
|
||||
mode string
|
||||
StartCmd = &cobra.Command{
|
||||
Use: "server",
|
||||
Short: "Start API server",
|
||||
Example: "go-admin server config/settings.yml",
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
usage()
|
||||
setup()
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return run()
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func usage() {
|
||||
usageStr := `starting api server`
|
||||
log.Printf("%s\n", usageStr)
|
||||
}
|
||||
func init() {
|
||||
StartCmd.PersistentFlags().StringVarP(&configYml, "config", "c", "config/settings.yml", "Start server with provided configuration file")
|
||||
StartCmd.PersistentFlags().StringVarP(&port, "port", "p", "8000", "Tcp port server listening on")
|
||||
StartCmd.PersistentFlags().StringVarP(&mode, "mode", "m", "dev", "server mode ; eg:dev,test,prod")
|
||||
}
|
||||
|
||||
func setup() {
|
||||
//1. 读取配置
|
||||
config.ConfigSetup(configYml)
|
||||
//2. 设置日志
|
||||
tools.InitLogger()
|
||||
//3. 初始化数据库链接
|
||||
database.Setup(config.DatabaseConfig.Driver)
|
||||
func usage() {
|
||||
usageStr := `starting api server`
|
||||
log.Printf("%s\n", usageStr)
|
||||
}
|
||||
|
||||
mycasbin.Setup()
|
||||
func setup() {
|
||||
//1. 读取配置
|
||||
config.ConfigSetup(configYml)
|
||||
//2. 设置日志
|
||||
tools.InitLogger()
|
||||
//3. 初始化数据库链接
|
||||
database.Setup(config.DatabaseConfig.Driver)
|
||||
|
||||
mycasbin.Setup()
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package database
|
||||
|
||||
|
||||
func Setup(driver string) {
|
||||
dbType := driver
|
||||
if dbType == "mysql" {
|
||||
|
||||
@@ -47,4 +47,4 @@ func (e *SqLite) GetConnect() string {
|
||||
|
||||
func (e *SqLite) GetDriver() string {
|
||||
return config.DatabaseConfig.Driver
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -19,6 +19,6 @@ var CasbinEnforcer *casbin.Enforcer
|
||||
// go-admin Version Info
|
||||
var Version string
|
||||
|
||||
func init() {
|
||||
func init() {
|
||||
Version = "1.0.10"
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -6,9 +6,7 @@ import (
|
||||
|
||||
var RequestLogger = &logrus.Entry{}
|
||||
|
||||
|
||||
|
||||
func init() {
|
||||
func init() {
|
||||
// TODO: requestLogger log format
|
||||
// RequestLogger = logrus.WithFields(logrus.Fields{"request_id": request_id, "user_ip": user_ip})
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -8,4 +8,4 @@ func Ping(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
}
|
||||
+12
-13
@@ -75,12 +75,12 @@ func DiskCheck(c *gin.Context) {
|
||||
func OSCheck(c *gin.Context) {
|
||||
status := http.StatusOK
|
||||
app.Custum(c, gin.H{
|
||||
"code": 200,
|
||||
"status": status,
|
||||
"goOs": runtime.GOOS,
|
||||
"compiler": runtime.Compiler,
|
||||
"numCpu": runtime.NumCPU(),
|
||||
"version": runtime.Version(),
|
||||
"code": 200,
|
||||
"status": status,
|
||||
"goOs": runtime.GOOS,
|
||||
"compiler": runtime.Compiler,
|
||||
"numCpu": runtime.NumCPU(),
|
||||
"version": runtime.Version(),
|
||||
"numGoroutine": runtime.NumGoroutine(),
|
||||
})
|
||||
}
|
||||
@@ -153,13 +153,12 @@ func RAMCheck(c *gin.Context) {
|
||||
text = "WARNING"
|
||||
}
|
||||
|
||||
|
||||
app.Custum(c, gin.H{
|
||||
"code": 200,
|
||||
"msg": text,
|
||||
"status": status,
|
||||
"used": usedMB,
|
||||
"total": totalMB,
|
||||
"usedPercent": usedPercent,
|
||||
"code": 200,
|
||||
"msg": text,
|
||||
"status": status,
|
||||
"used": usedMB,
|
||||
"total": totalMB,
|
||||
"usedPercent": usedPercent,
|
||||
})
|
||||
}
|
||||
+12
-12
@@ -8,18 +8,18 @@ import (
|
||||
|
||||
type DictData struct {
|
||||
DictCode int `gorm:"primary_key;AUTO_INCREMENT" json:"dictCode" example:"1"` //字典编码
|
||||
DictSort int `gorm:"" json:"dictSort"` //显示顺序
|
||||
DictLabel string `gorm:"size:128;" json:"dictLabel"` //数据标签
|
||||
DictValue string `gorm:"size:255;" json:"dictValue"` //数据键值
|
||||
DictType string `gorm:"size:64;" json:"dictType"` //字典类型
|
||||
CssClass string `gorm:"size:128;" json:"cssClass"` //
|
||||
ListClass string `gorm:"size:128;" json:"listClass"` //
|
||||
IsDefault string `gorm:"size:8;" json:"isDefault"` //
|
||||
Status string `gorm:"size:4;" json:"status"` //状态
|
||||
Default string `gorm:"size:8;" json:"default"` //
|
||||
CreateBy string `gorm:"size:64;" json:"createBy"` //
|
||||
UpdateBy string `gorm:"size:64;" json:"updateBy"` //
|
||||
Remark string `gorm:"size:255;" json:"remark"` //备注
|
||||
DictSort int `gorm:"" json:"dictSort"` //显示顺序
|
||||
DictLabel string `gorm:"size:128;" json:"dictLabel"` //数据标签
|
||||
DictValue string `gorm:"size:255;" json:"dictValue"` //数据键值
|
||||
DictType string `gorm:"size:64;" json:"dictType"` //字典类型
|
||||
CssClass string `gorm:"size:128;" json:"cssClass"` //
|
||||
ListClass string `gorm:"size:128;" json:"listClass"` //
|
||||
IsDefault string `gorm:"size:8;" json:"isDefault"` //
|
||||
Status string `gorm:"size:4;" json:"status"` //状态
|
||||
Default string `gorm:"size:8;" json:"default"` //
|
||||
CreateBy string `gorm:"size:64;" json:"createBy"` //
|
||||
UpdateBy string `gorm:"size:64;" json:"updateBy"` //
|
||||
Remark string `gorm:"size:255;" json:"remark"` //备注
|
||||
Params string `gorm:"-" json:"params"`
|
||||
DataScope string `gorm:"-" json:"dataScope"`
|
||||
BaseModel
|
||||
|
||||
+3
-3
@@ -10,9 +10,9 @@ type DictType struct {
|
||||
DictId int `gorm:"primary_key;AUTO_INCREMENT" json:"dictId"`
|
||||
DictName string `gorm:"size:128;" json:"dictName"` //字典名称
|
||||
DictType string `gorm:"size:128;" json:"dictType"` //字典类型
|
||||
Status string `gorm:"size:4;" json:"status"` //状态
|
||||
DataScope string `gorm:"-" json:"dataScope"` //
|
||||
Params string `gorm:"-" json:"params"` //
|
||||
Status string `gorm:"size:4;" json:"status"` //状态
|
||||
DataScope string `gorm:"-" json:"dataScope"` //
|
||||
Params string `gorm:"-" json:"params"` //
|
||||
CreateBy string `gorm:"size:11;" json:"createBy"` //创建者
|
||||
UpdateBy string `gorm:"size:11;" json:"updateBy"` //更新者
|
||||
Remark string `gorm:"size:255;" json:"remark"` //备注
|
||||
|
||||
+10
-10
@@ -7,19 +7,19 @@ import (
|
||||
|
||||
type LoginLog struct {
|
||||
InfoId int `json:"infoId" gorm:"primary_key;AUTO_INCREMENT"` //主键
|
||||
Username string `json:"username" gorm:"size:128;"` //用户名
|
||||
Status string `json:"status" gorm:"size:4;"` //状态
|
||||
Ipaddr string `json:"ipaddr" gorm:"size:255;"` //ip地址
|
||||
LoginLocation string `json:"loginLocation" gorm:"size:255;"` //归属地
|
||||
Browser string `json:"browser" gorm:"size:255;"` //浏览器
|
||||
Os string `json:"os" gorm:"size:255;"` //系统
|
||||
Platform string `json:"platform" gorm:"size:255;"` // 固件
|
||||
Username string `json:"username" gorm:"size:128;"` //用户名
|
||||
Status string `json:"status" gorm:"size:4;"` //状态
|
||||
Ipaddr string `json:"ipaddr" gorm:"size:255;"` //ip地址
|
||||
LoginLocation string `json:"loginLocation" gorm:"size:255;"` //归属地
|
||||
Browser string `json:"browser" gorm:"size:255;"` //浏览器
|
||||
Os string `json:"os" gorm:"size:255;"` //系统
|
||||
Platform string `json:"platform" gorm:"size:255;"` // 固件
|
||||
LoginTime time.Time `json:"loginTime" gorm:"type:timestamp;"` //登录时间
|
||||
CreateBy string `json:"createBy" gorm:"size:128;"` //创建人
|
||||
UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者
|
||||
CreateBy string `json:"createBy" gorm:"size:128;"` //创建人
|
||||
UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者
|
||||
DataScope string `json:"dataScope" gorm:"-"` //数据
|
||||
Params string `json:"params" gorm:"-"` //
|
||||
Remark string `json:"remark" gorm:"size:255;"` //备注
|
||||
Remark string `json:"remark" gorm:"size:255;"` //备注
|
||||
Msg string `json:"msg" gorm:"size:255;"`
|
||||
BaseModel
|
||||
}
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
type BaseModel struct {
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
DeletedAt *time.Time `json:"deletedAt"`
|
||||
}
|
||||
+21
-21
@@ -8,28 +8,28 @@ import (
|
||||
//sys_operlog
|
||||
type SysOperLog struct {
|
||||
OperId int `json:"operId" gorm:"primary_key;AUTO_INCREMENT"` //日志编码
|
||||
Title string `json:"title" gorm:"size:255;"` //操作模块
|
||||
BusinessType string `json:"businessType" gorm:"size:128;"` //操作类型
|
||||
Title string `json:"title" gorm:"size:255;"` //操作模块
|
||||
BusinessType string `json:"businessType" gorm:"size:128;"` //操作类型
|
||||
BusinessTypes string `json:"businessTypes" gorm:"size:128;"`
|
||||
Method string `json:"method" gorm:"size:128;"` //函数
|
||||
RequestMethod string `json:"requestMethod" gorm:"size:128;"` //请求方式
|
||||
OperatorType string `json:"operatorType" gorm:"size:128;"` //操作类型
|
||||
OperName string `json:"operName" gorm:"size:128;"` //操作者
|
||||
DeptName string `json:"deptName" gorm:"size:128;"` //部门名称
|
||||
OperUrl string `json:"operUrl" gorm:"size:255;"` //访问地址
|
||||
OperIp string `json:"operIp" gorm:"size:128;"` //客户端ip
|
||||
OperLocation string `json:"operLocation" gorm:"size:128;"` //访问位置
|
||||
OperParam string `json:"operParam" gorm:"size:255;"` //请求参数
|
||||
Status string `json:"status" gorm:"size:4;"` //操作状态
|
||||
OperTime time.Time `json:"operTime" gorm:"type:timestamp;"` //操作时间
|
||||
JsonResult string `json:"jsonResult" gorm:"size:255;"` //返回数据
|
||||
CreateBy string `json:"createBy" gorm:"size:128;"` //创建人
|
||||
UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者
|
||||
DataScope string `json:"dataScope" gorm:"-"` //数据
|
||||
Params string `json:"params" gorm:"-"` //参数
|
||||
Remark string `json:"remark" gorm:"size:255;"` //备注
|
||||
LatencyTime string `json:"latencyime" gorm:"size:128;"` //耗时
|
||||
UserAgent string `json:"userAgent" gorm:"size:255;"` //ua
|
||||
Method string `json:"method" gorm:"size:128;"` //函数
|
||||
RequestMethod string `json:"requestMethod" gorm:"size:128;"` //请求方式
|
||||
OperatorType string `json:"operatorType" gorm:"size:128;"` //操作类型
|
||||
OperName string `json:"operName" gorm:"size:128;"` //操作者
|
||||
DeptName string `json:"deptName" gorm:"size:128;"` //部门名称
|
||||
OperUrl string `json:"operUrl" gorm:"size:255;"` //访问地址
|
||||
OperIp string `json:"operIp" gorm:"size:128;"` //客户端ip
|
||||
OperLocation string `json:"operLocation" gorm:"size:128;"` //访问位置
|
||||
OperParam string `json:"operParam" gorm:"size:255;"` //请求参数
|
||||
Status string `json:"status" gorm:"size:4;"` //操作状态
|
||||
OperTime time.Time `json:"operTime" gorm:"type:timestamp;"` //操作时间
|
||||
JsonResult string `json:"jsonResult" gorm:"size:255;"` //返回数据
|
||||
CreateBy string `json:"createBy" gorm:"size:128;"` //创建人
|
||||
UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者
|
||||
DataScope string `json:"dataScope" gorm:"-"` //数据
|
||||
Params string `json:"params" gorm:"-"` //参数
|
||||
Remark string `json:"remark" gorm:"size:255;"` //备注
|
||||
LatencyTime string `json:"latencyime" gorm:"size:128;"` //耗时
|
||||
UserAgent string `json:"userAgent" gorm:"size:255;"` //ua
|
||||
BaseModel
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -7,11 +7,11 @@ import (
|
||||
|
||||
type Post struct {
|
||||
PostId int `gorm:"primary_key;AUTO_INCREMENT" json:"postId"` //岗位编号
|
||||
PostName string `gorm:"size:128;" json:"postName"` //岗位名称
|
||||
PostCode string `gorm:"size:128;" json:"postCode"` //岗位代码
|
||||
Sort int `gorm:"" json:"sort"` //岗位排序
|
||||
Status string `gorm:"size:4;" json:"status"` //状态
|
||||
Remark string `gorm:"size:255;" json:"remark"` //描述
|
||||
PostName string `gorm:"size:128;" json:"postName"` //岗位名称
|
||||
PostCode string `gorm:"size:128;" json:"postCode"` //岗位代码
|
||||
Sort int `gorm:"" json:"sort"` //岗位排序
|
||||
Status string `gorm:"size:4;" json:"status"` //状态
|
||||
Remark string `gorm:"size:255;" json:"remark"` //描述
|
||||
CreateBy string `gorm:"size:128;" json:"createBy"`
|
||||
UpdateBy string `gorm:"size:128;" json:"updateBy"`
|
||||
DataScope string `gorm:"-" json:"dataScope"`
|
||||
|
||||
+9
-9
@@ -8,14 +8,14 @@ import (
|
||||
|
||||
type SysRole struct {
|
||||
RoleId int `json:"roleId" gorm:"primary_key;AUTO_INCREMENT"` // 角色编码
|
||||
RoleName string `json:"roleName" gorm:"size:128;"` // 角色名称
|
||||
Status string `json:"status" gorm:"size:4;"` //
|
||||
RoleKey string `json:"roleKey" gorm:"size:128;"` //角色代码
|
||||
RoleSort int `json:"roleSort" gorm:""` //角色排序
|
||||
Flag string `json:"flag" gorm:"size:128;"` //
|
||||
CreateBy string `json:"createBy" gorm:"size:128;"` //
|
||||
UpdateBy string `json:"updateBy" gorm:"size:128;"` //
|
||||
Remark string `json:"remark" gorm:"size:255;"` //备注
|
||||
RoleName string `json:"roleName" gorm:"size:128;"` // 角色名称
|
||||
Status string `json:"status" gorm:"size:4;"` //
|
||||
RoleKey string `json:"roleKey" gorm:"size:128;"` //角色代码
|
||||
RoleSort int `json:"roleSort" gorm:""` //角色排序
|
||||
Flag string `json:"flag" gorm:"size:128;"` //
|
||||
CreateBy string `json:"createBy" gorm:"size:128;"` //
|
||||
UpdateBy string `json:"updateBy" gorm:"size:128;"` //
|
||||
Remark string `json:"remark" gorm:"size:255;"` //备注
|
||||
Admin bool `json:"admin" gorm:"size:4;"`
|
||||
DataScope string `json:"dataScope" gorm:"size:128;"`
|
||||
Params string `json:"params" gorm:"-"`
|
||||
@@ -52,7 +52,7 @@ func (role *SysRole) GetPage(pageSize int, pageIndex int) ([]SysRole, int, error
|
||||
// 数据权限控制
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = tools.StringToInt(role.DataScope)
|
||||
table,err := dataPermission.GetDataScope("sys_role", table)
|
||||
table, err := dataPermission.GetDataScope("sys_role", table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
+3
-4
@@ -42,13 +42,13 @@ type SysUserId struct {
|
||||
type SysUserB struct {
|
||||
NickName string `gorm:"size:128" json:"nickName"` // 昵称
|
||||
Phone string `gorm:"size:11" json:"phone"` // 手机号
|
||||
RoleId int `gorm:"" json:"roleId"` // 角色编码
|
||||
RoleId int `gorm:"" json:"roleId"` // 角色编码
|
||||
Salt string `gorm:"size:255" json:"salt"` //盐
|
||||
Avatar string `gorm:"size:255" json:"avatar"` //头像
|
||||
Sex string `gorm:"size:255" json:"sex"` //性别
|
||||
Email string `gorm:"size:128" json:"email"` //邮箱
|
||||
DeptId int `gorm:"" json:"deptId"` //部门编码
|
||||
PostId int `gorm:"" json:"postId"` //职位编码
|
||||
DeptId int `gorm:"" json:"deptId"` //部门编码
|
||||
PostId int `gorm:"" json:"postId"` //职位编码
|
||||
CreateBy string `gorm:"size:128" json:"createBy"` //
|
||||
UpdateBy string `gorm:"size:128" json:"updateBy"` //
|
||||
Remark string `gorm:"size:255" json:"remark"` //备注
|
||||
@@ -59,7 +59,6 @@ type SysUserB struct {
|
||||
BaseModel
|
||||
}
|
||||
|
||||
|
||||
type SysUser struct {
|
||||
SysUserId
|
||||
SysUserB
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
)
|
||||
|
||||
type SysColumns struct {
|
||||
ColumnId int `gorm:"primary_key;auto_increment" json:"columnId"`
|
||||
TableId int `gorm:"" json:"tableId"`
|
||||
ColumnId int `gorm:"primary_key;auto_increment" json:"columnId"`
|
||||
TableId int `gorm:"" json:"tableId"`
|
||||
ColumnName string `gorm:"size:128;" json:"columnName"`
|
||||
ColumnComment string `gorm:"column:column_comment;size:128;" json:"columnComment"`
|
||||
ColumnType string `gorm:"column:column_type;size:128;" json:"columnType"`
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type SysTables struct {
|
||||
TableId int `gorm:"primary_key;auto_increment" json:"tableId"` //表编码
|
||||
TableId int `gorm:"primary_key;auto_increment" json:"tableId"` //表编码
|
||||
TBName string `gorm:"column:table_name;size:255;" json:"tableName"` //表名称
|
||||
TableComment string `gorm:"size:255;" json:"tableComment"` //表备注
|
||||
ClassName string `gorm:"size:255;" json:"className"` //类名
|
||||
|
||||
@@ -24,8 +24,6 @@ e = some(where (p.eft == allow))
|
||||
m = r.sub == p.sub && (keyMatch2(r.obj, p.obj) || keyMatch(r.obj, p.obj)) && (r.act == p.act || p.act == "*")
|
||||
`
|
||||
|
||||
|
||||
|
||||
func Setup() {
|
||||
Apter, err := gormAdapter.NewAdapterByDB(global.Eloquent)
|
||||
if err != nil {
|
||||
|
||||
@@ -5,9 +5,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
Info *log.Logger
|
||||
Info *log.Logger
|
||||
Warning *log.Logger
|
||||
Error * log.Logger
|
||||
Error *log.Logger
|
||||
)
|
||||
|
||||
|
||||
+1
-6
@@ -7,8 +7,6 @@ import (
|
||||
jwt "go-admin/pkg/jwtauth"
|
||||
)
|
||||
|
||||
|
||||
|
||||
// 路由示例
|
||||
func InitExamplesRouter(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gin.Engine {
|
||||
|
||||
@@ -32,10 +30,7 @@ func examplesNoCheckRoleRouter(r *gin.Engine) {
|
||||
// 需要认证的路由示例
|
||||
func examplesCheckRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddleware) {
|
||||
v1 := r.Group("/api/v1")
|
||||
v1.GET("/checkrole",nil)
|
||||
v1.GET("/checkrole", nil)
|
||||
|
||||
// {{认证路由自动补充在此处请勿删除}}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+68
-68
@@ -7,119 +7,119 @@ _ "time"
|
||||
)
|
||||
|
||||
type {{.ClassName}} struct {
|
||||
{{ range .Columns -}}
|
||||
{{ range .Columns -}}
|
||||
{{$x := .Pk}}
|
||||
{{- if ($x) }}
|
||||
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key"` // {{.ColumnComment}}
|
||||
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key"` // {{.ColumnComment}}
|
||||
{{- else if eq .GoField "CreatedAt" -}}
|
||||
{{- else if eq .GoField "UpdatedAt" -}}
|
||||
{{- else if eq .GoField "DeletedAt" -}}
|
||||
{{- else }}
|
||||
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};"` // {{.ColumnComment}}{{end -}}
|
||||
{{- end }}
|
||||
DataScope string `json:"dataScope" gorm:"-"`
|
||||
Params string `json:"params" gorm:"-"`
|
||||
BaseModel
|
||||
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};"` // {{.ColumnComment}}{{end -}}
|
||||
{{- end }}
|
||||
DataScope string `json:"dataScope" gorm:"-"`
|
||||
Params string `json:"params" gorm:"-"`
|
||||
BaseModel
|
||||
}
|
||||
|
||||
func ({{.ClassName}}) TableName() string {
|
||||
return "{{.TBName}}"
|
||||
return "{{.TBName}}"
|
||||
}
|
||||
|
||||
// 创建{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Create() ({{.ClassName}}, error) {
|
||||
var doc {{.ClassName}}
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
}
|
||||
doc = *e
|
||||
return doc, nil
|
||||
var doc {{.ClassName}}
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
}
|
||||
doc = *e
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
|
||||
// 获取{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Get() ({{.ClassName}}, error) {
|
||||
var doc {{.ClassName}}
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
{{ range .Columns }}
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
{{ range .Columns }}
|
||||
{{$x := .Pk}}
|
||||
{{- if ($x) }}
|
||||
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
|
||||
table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}})
|
||||
}
|
||||
{{- else if .IsQuery }}
|
||||
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
|
||||
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
|
||||
table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}})
|
||||
}
|
||||
}
|
||||
{{- else if .IsQuery }}
|
||||
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
|
||||
table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}})
|
||||
}
|
||||
{{ end -}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
if err := table.First(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
return doc, nil
|
||||
if err := table.First(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
// 获取{{.ClassName}}带分页
|
||||
func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}}, int, error) {
|
||||
var doc []{{.ClassName}}
|
||||
var doc []{{.ClassName}}
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
{{ range .Columns }}
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
{{ range .Columns }}
|
||||
{{- if .IsQuery }}
|
||||
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
|
||||
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
|
||||
table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}})
|
||||
}
|
||||
}
|
||||
{{ end -}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
|
||||
table,err := dataPermission.GetDataScope(e.TableName(), table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
var count int
|
||||
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
|
||||
table,err := dataPermission.GetDataScope(e.TableName(), table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
var count int
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
// 更新{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Update(id int) (update {{.ClassName}}, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil {
|
||||
return
|
||||
}
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 删除{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Delete(id int) (success bool, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
success = true
|
||||
return
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
success = true
|
||||
return
|
||||
}
|
||||
|
||||
//批量删除
|
||||
func (e *{{.ClassName}}) BatchDelete(id []int) (Result bool, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} in (?)", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||
return
|
||||
}
|
||||
Result = true
|
||||
return
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} in (?)", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||
return
|
||||
}
|
||||
Result = true
|
||||
return
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/middleware"
|
||||
"go-admin/apis/{{.ModuleName}}"
|
||||
jwt "go-admin/pkg/jwtauth"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/middleware"
|
||||
"go-admin/apis/{{.ModuleName}}"
|
||||
jwt "go-admin/pkg/jwtauth"
|
||||
)
|
||||
|
||||
// 需认证的路由代码
|
||||
|
||||
+109
-93
@@ -3,23 +3,25 @@
|
||||
<div class="app-container">
|
||||
<el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
|
||||
{{range .Columns}}
|
||||
{{- $x := .IsQuery -}}
|
||||
{{- if ($x) -}}
|
||||
<el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}">
|
||||
{{if eq .DictType "" -}}
|
||||
<el-input v-model="queryParams.{{.JsonField}}" placeholder="请输入{{.ColumnComment}}" clearable size="small" @keyup.enter.native="handleQuery" />
|
||||
{{- else -}}
|
||||
<el-select v-model="queryParams.{{.JsonField}}" placeholder="{{$tableComment}}{{.ColumnComment}}" clearable size="small">
|
||||
<el-option
|
||||
v-for="dict in {{.JsonField}}Options"
|
||||
:key="dict.dictValue"
|
||||
:label="dict.dictLabel"
|
||||
:value="dict.dictValue"
|
||||
/>
|
||||
</el-select>
|
||||
{{- end}}
|
||||
</el-form-item>
|
||||
{{end}}
|
||||
{{- $x := .IsQuery -}}
|
||||
{{- if ($x) -}}
|
||||
<el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}">
|
||||
{{if eq .DictType "" -}}
|
||||
<el-input v-model="queryParams.{{.JsonField}}" placeholder="请输入{{.ColumnComment}}" clearable
|
||||
size="small" @keyup.enter.native="handleQuery"/>
|
||||
{{- else -}}
|
||||
<el-select v-model="queryParams.{{.JsonField}}"
|
||||
placeholder="{{$tableComment}}{{.ColumnComment}}" clearable size="small">
|
||||
<el-option
|
||||
v-for="dict in {{.JsonField}}Options"
|
||||
:key="dict.dictValue"
|
||||
:label="dict.dictLabel"
|
||||
:value="dict.dictValue"
|
||||
/>
|
||||
</el-select>
|
||||
{{- end}}
|
||||
</el-form-item>
|
||||
{{end}}
|
||||
{{- end }}
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||
@@ -35,7 +37,8 @@
|
||||
icon="el-icon-plus"
|
||||
size="mini"
|
||||
@click="handleAdd"
|
||||
>新增</el-button>
|
||||
>新增
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
@@ -45,7 +48,8 @@
|
||||
size="mini"
|
||||
:disabled="single"
|
||||
@click="handleUpdate"
|
||||
>修改</el-button>
|
||||
>修改
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
@@ -55,27 +59,30 @@
|
||||
size="mini"
|
||||
:disabled="multiple"
|
||||
@click="handleDelete"
|
||||
>删除</el-button>
|
||||
>删除
|
||||
</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="{{.ModuleName}}List" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column type="selection" width="55" align="center"/>
|
||||
{{- range .Columns -}}
|
||||
{{- $x := .IsList -}}
|
||||
{{- if ($x) }}
|
||||
{{- if ne .DictType "" -}}
|
||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}" :formatter="{{.JsonField}}Format" width="100">
|
||||
<template slot-scope="scope">
|
||||
{{ "{{" }} {{.JsonField}}Format(scope.row) {{"}}"}}
|
||||
</template>
|
||||
</el-table-column>
|
||||
{{- end -}}
|
||||
{{- if eq .DictType "" -}}
|
||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}" :show-overflow-tooltip="true" />
|
||||
{{- end -}}
|
||||
{{- $x := .IsList -}}
|
||||
{{- if ($x) }}
|
||||
{{- if ne .DictType "" -}}
|
||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}"
|
||||
:formatter="{{.JsonField}}Format" width="100">
|
||||
<template slot-scope="scope">
|
||||
{{ "{{" }} {{.JsonField}}Format(scope.row) {{"}}"}}
|
||||
</template>
|
||||
</el-table-column>
|
||||
{{- end -}}
|
||||
{{- if eq .DictType "" -}}
|
||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}"
|
||||
:show-overflow-tooltip="true"/>
|
||||
{{- end -}}
|
||||
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template slot-scope="scope">
|
||||
@@ -85,14 +92,16 @@
|
||||
type="text"
|
||||
icon="el-icon-edit"
|
||||
@click="handleUpdate(scope.row)"
|
||||
>修改</el-button>
|
||||
>修改
|
||||
</el-button>
|
||||
<el-button
|
||||
v-permisaction="['{{.PackageName}}:{{.ModuleName}}:remove']"
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-delete"
|
||||
@click="handleDelete(scope.row)"
|
||||
>删除</el-button>
|
||||
>删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -109,36 +118,38 @@
|
||||
<el-dialog :title="title" :visible.sync="open" width="500px">
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
||||
{{ range .Columns }}
|
||||
{{- $x := .IsInsert -}}
|
||||
{{- if ($x) -}}
|
||||
{{- if (.Pk) }}
|
||||
{{- else if eq .GoField "CreatedAt" -}}
|
||||
{{- else if eq .GoField "UpdatedAt" -}}
|
||||
{{- else if eq .GoField "DeletedAt" -}}
|
||||
{{- else if eq .GoField "UpdateBy" -}}
|
||||
{{- else if eq .GoField "CreateBy" -}}
|
||||
{{- else }}
|
||||
<el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}" >
|
||||
{{ if eq "input" .HtmlType -}}
|
||||
<el-input v-model="form.{{.JsonField}}" placeholder="{{.ColumnComment}}" {{if eq .IsEdit "false" -}}:disabled="isEdit" {{- end}}/>
|
||||
{{- else if eq "select" .HtmlType -}}
|
||||
<el-select v-model="form.{{.JsonField}}" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
|
||||
<el-option label="demo1" value="demo1" />
|
||||
<el-option label="demo2" value="demo2" />
|
||||
</el-select>
|
||||
{{- else if eq "radio" .HtmlType -}}
|
||||
<el-radio-group v-model="form.{{.JsonField}}">
|
||||
<el-radio
|
||||
v-for="dict in {{.JsonField}}Options"
|
||||
:key="dict.dictValue"
|
||||
:label="dict.dictValue"
|
||||
>{{"{{"}} dict.dictLabel {{"}}"}}</el-radio>
|
||||
</el-radio-group>
|
||||
{{- end }}
|
||||
</el-form-item>
|
||||
{{- $x := .IsInsert -}}
|
||||
{{- if ($x) -}}
|
||||
{{- if (.Pk) }}
|
||||
{{- else if eq .GoField "CreatedAt" -}}
|
||||
{{- else if eq .GoField "UpdatedAt" -}}
|
||||
{{- else if eq .GoField "DeletedAt" -}}
|
||||
{{- else if eq .GoField "UpdateBy" -}}
|
||||
{{- else if eq .GoField "CreateBy" -}}
|
||||
{{- else }}
|
||||
<el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}">
|
||||
{{ if eq "input" .HtmlType -}}
|
||||
<el-input v-model="form.{{.JsonField}}" placeholder="{{.ColumnComment}}"
|
||||
{{if eq .IsEdit "false" -}}:disabled="isEdit" {{- end}}/>
|
||||
{{- else if eq "select" .HtmlType -}}
|
||||
<el-select
|
||||
v-model="form.{{.JsonField}}" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
|
||||
<el-option label="demo1" value="demo1"/>
|
||||
<el-option label="demo2" value="demo2"/>
|
||||
</el-select>
|
||||
{{- else if eq "radio" .HtmlType -}}
|
||||
<el-radio-group v-model="form.{{.JsonField}}">
|
||||
<el-radio
|
||||
v-for="dict in {{.JsonField}}Options"
|
||||
:key="dict.dictValue"
|
||||
:label="dict.dictValue"
|
||||
>{{"{{"}} dict.dictLabel {{"}}"}}</el-radio>
|
||||
</el-radio-group>
|
||||
{{- end }}
|
||||
</el-form-item>
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
@@ -149,7 +160,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { list{{.ClassName}}, get{{.ClassName}}, del{{.ClassName}}, add{{.ClassName}}, update{{.ClassName}} } from '@/api/{{.PackageName}}'
|
||||
import {add, del, get, list, update} from '@/api/'
|
||||
|
||||
export default {
|
||||
name: 'Config',
|
||||
@@ -172,7 +183,7 @@
|
||||
isEdit: false,
|
||||
// 类型数据字典
|
||||
typeOptions: [],
|
||||
{{.ModuleName}}List:[],
|
||||
{{.ModuleName}}List: [],
|
||||
{{range .Columns}}
|
||||
{{- if ne .DictType "" -}}
|
||||
{{.JsonField}}Options: [],
|
||||
@@ -182,28 +193,30 @@
|
||||
queryParams: {
|
||||
pageIndex: 1,
|
||||
pageSize: 10,
|
||||
{{ range .Columns }}
|
||||
{{- if (.IsQuery) -}}
|
||||
{{.JsonField}}:undefined,
|
||||
{{ end -}}
|
||||
{{- end }}
|
||||
},
|
||||
// 表单参数
|
||||
form: {
|
||||
},
|
||||
// 表单校验
|
||||
rules: {
|
||||
{{- range .Columns -}}
|
||||
{{- $x := .IsQuery -}}
|
||||
{{- if ($x) -}}
|
||||
{{.JsonField}}:
|
||||
[
|
||||
{required: true, message: '{{.ColumnComment}}不能为空', trigger: 'blur'}
|
||||
],
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
}
|
||||
{{ range .Columns }}
|
||||
{{- if (.IsQuery) -}}
|
||||
{{.JsonField}}:
|
||||
undefined,
|
||||
{{ end -}}
|
||||
{{- end }}
|
||||
},
|
||||
// 表单参数
|
||||
form: {
|
||||
}
|
||||
,
|
||||
// 表单校验
|
||||
rules: {
|
||||
{{- range .Columns -}}
|
||||
{{- $x := .IsQuery -}}
|
||||
{{- if ($x) -}}
|
||||
{{.JsonField}}:
|
||||
[
|
||||
{required: true, message: '{{.ColumnComment}}不能为空', trigger: 'blur'}
|
||||
],
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getList()
|
||||
@@ -243,11 +256,12 @@
|
||||
{{- else if eq .GoField "UpdateBy" -}}
|
||||
{{- else if eq .GoField "CreateBy" -}}
|
||||
{{- else }}
|
||||
{{.JsonField}}: undefined,
|
||||
{{.JsonField}}:
|
||||
undefined,
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
}
|
||||
}
|
||||
this.resetForm('form')
|
||||
},
|
||||
{{range .Columns}}
|
||||
@@ -285,7 +299,8 @@
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset()
|
||||
const {{.PkJsonField}} = row.{{.PkJsonField}} || this.ids
|
||||
const {{.PkJsonField}} =
|
||||
row.{{.PkJsonField}} || this.ids
|
||||
get{{.ClassName}}({{.PkJsonField}}).then(response => {
|
||||
this.form = response.data
|
||||
this.open = true
|
||||
@@ -294,7 +309,7 @@
|
||||
})
|
||||
},
|
||||
/** 提交按钮 */
|
||||
submitForm: function() {
|
||||
submitForm: function () {
|
||||
this.$refs['form'].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.form.{{.PkJsonField}} !== undefined) {
|
||||
@@ -328,12 +343,13 @@
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(function() {
|
||||
}).then(function () {
|
||||
return del{{.ClassName}}(Ids)
|
||||
}).then(() => {
|
||||
this.getList()
|
||||
this.msgSuccess('删除成功')
|
||||
}).catch(function() {})
|
||||
}).catch(function () {
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+62
-62
@@ -21,40 +21,40 @@ import (
|
||||
// @Router /api/v1/configList [get]
|
||||
// @Security Bearer
|
||||
func Get{{.ClassName}}List(c *gin.Context) {
|
||||
var data models.{{.ClassName}}
|
||||
var err error
|
||||
var pageSize = 10
|
||||
var pageIndex = 1
|
||||
var data models.{{.ClassName}}
|
||||
var err error
|
||||
var pageSize = 10
|
||||
var pageIndex = 1
|
||||
|
||||
if size := c.Request.FormValue("pageSize"); size != "" {
|
||||
pageSize = pkg.StrToInt(err, size)
|
||||
}
|
||||
if size := c.Request.FormValue("pageSize"); size != "" {
|
||||
pageSize = pkg.StrToInt(err, size)
|
||||
}
|
||||
|
||||
if index := c.Request.FormValue("pageIndex"); index != "" {
|
||||
pageIndex = pkg.StrToInt(err, index)
|
||||
}
|
||||
if index := c.Request.FormValue("pageIndex"); index != "" {
|
||||
pageIndex = pkg.StrToInt(err, index)
|
||||
}
|
||||
|
||||
{{ range .Columns -}}
|
||||
{{$z := .IsQuery}}
|
||||
{{- if ($z) -}}
|
||||
data.{{.GoField}} = c.Request.FormValue("{{.JsonField}}")
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
{{ range .Columns -}}
|
||||
{{$z := .IsQuery}}
|
||||
{{- if ($z) -}}
|
||||
data.{{.GoField}} = c.Request.FormValue("{{.JsonField}}")
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
|
||||
data.DataScope = utils.GetUserIdStr(c)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||
pkg.HasError(err, "", -1)
|
||||
data.DataScope = utils.GetUserIdStr(c)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||
pkg.HasError(err, "", -1)
|
||||
|
||||
var mp = make(map[string]interface{}, 3)
|
||||
mp["list"] = result
|
||||
mp["count"] = count
|
||||
mp["pageIndex"] = pageIndex
|
||||
mp["pageIndex"] = pageSize
|
||||
var mp = make(map[string]interface{}, 3)
|
||||
mp["list"] = result
|
||||
mp["count"] = count
|
||||
mp["pageIndex"] = pageIndex
|
||||
mp["pageIndex"] = pageSize
|
||||
|
||||
var res app.Response
|
||||
res.Data = mp
|
||||
var res app.Response
|
||||
res.Data = mp
|
||||
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @Summary 获取配置
|
||||
@@ -65,15 +65,15 @@ func Get{{.ClassName}}List(c *gin.Context) {
|
||||
// @Router /api/v1/config/{configId} [get]
|
||||
// @Security Bearer
|
||||
func Get{{.ClassName}}(c *gin.Context) {
|
||||
var data models.{{.ClassName}}
|
||||
data.{{.PkGoField}}, _ = utils.StringToInt(c.Param("{{.PkJsonField}}"))
|
||||
result, err := data.Get()
|
||||
pkg.HasError(err, "抱歉未找到相关信息", -1)
|
||||
var data models.{{.ClassName}}
|
||||
data.{{.PkGoField}}, _ = utils.StringToInt(c.Param("{{.PkJsonField}}"))
|
||||
result, err := data.Get()
|
||||
pkg.HasError(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
var res app.Response
|
||||
res.Data = result
|
||||
var res app.Response
|
||||
res.Data = result
|
||||
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @Summary 添加配置
|
||||
@@ -82,45 +82,45 @@ func Get{{.ClassName}}(c *gin.Context) {
|
||||
// @Accept application/json
|
||||
// @Product application/json
|
||||
// @Param data body models.{{.ClassName}} true "data"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
||||
// @Router /api/v1/dict/data [post]
|
||||
// @Security Bearer
|
||||
func Insert{{.ClassName}}(c *gin.Context) {
|
||||
var data models.{{.ClassName}}
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
data.CreateBy = utils.GetUserIdStr(c)
|
||||
pkg.HasError(err, "", 500)
|
||||
result, err := data.Create()
|
||||
pkg.HasError(err, "", -1)
|
||||
var data models.{{.ClassName}}
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
data.CreateBy = utils.GetUserIdStr(c)
|
||||
pkg.HasError(err, "", 500)
|
||||
result, err := data.Create()
|
||||
pkg.HasError(err, "", -1)
|
||||
|
||||
var res app.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
var res app.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
|
||||
}
|
||||
|
||||
func Update{{.ClassName}}(c *gin.Context) {
|
||||
var data models.{{.ClassName}}
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
pkg.HasError(err, "数据解析失败", -1)
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
result, err := data.Update(data.{{.PkGoField}})
|
||||
pkg.HasError(err, "", -1)
|
||||
var data models.{{.ClassName}}
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
pkg.HasError(err, "数据解析失败", -1)
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
result, err := data.Update(data.{{.PkGoField}})
|
||||
pkg.HasError(err, "", -1)
|
||||
|
||||
var res app.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
var res app.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
func Delete{{.ClassName}}(c *gin.Context) {
|
||||
var data models.{{.ClassName}}
|
||||
id, err := utils.StringToInt(c.Param("{{.PkJsonField}}"))
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
_, err = data.Delete(id)
|
||||
pkg.HasError(err, "修改失败", 500)
|
||||
var data models.{{.ClassName}}
|
||||
id, err := utils.StringToInt(c.Param("{{.PkJsonField}}"))
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
_, err = data.Delete(id)
|
||||
pkg.HasError(err, "修改失败", 500)
|
||||
|
||||
var res app.Response
|
||||
res.Msg = "删除成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
var res app.Response
|
||||
res.Msg = "删除成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"text/template"
|
||||
)
|
||||
|
||||
|
||||
func TestGoModelTemplate(t *testing.T) {
|
||||
t1, err := template.ParseFiles("model.go.template")
|
||||
if err != nil {
|
||||
|
||||
+60
-60
@@ -1,104 +1,104 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
orm "go-admin/global"
|
||||
"go-admin/utils"
|
||||
"time"
|
||||
orm "go-admin/global"
|
||||
"go-admin/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
type {{.ClassName}} struct {
|
||||
|
||||
{{ range .Columns -}}
|
||||
{{ range .Columns -}}
|
||||
{{$x := .Pk}}
|
||||
// {{.ColumnComment}}
|
||||
{{if ($x)}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"column:{{.ColumnName}};primary_key"`{{else}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"column:{{.ColumnName}};"`{{end}}
|
||||
{{ end -}}
|
||||
// {{.ColumnComment}}
|
||||
{{if ($x)}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"column:{{.ColumnName}};primary_key"`{{else}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"column:{{.ColumnName}};"`{{end}}
|
||||
{{ end -}}
|
||||
}
|
||||
|
||||
// 创建{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Create() ({{.ClassName}}, error) {
|
||||
var doc {{.ClassName}}
|
||||
doc.IsDel = "0"
|
||||
e.CreateTime = time.Now().String()
|
||||
result := orm.Eloquent.Table("{{.TableName}}").Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
}
|
||||
doc = *e
|
||||
return doc, nil
|
||||
var doc {{.ClassName}}
|
||||
doc.IsDel = "0"
|
||||
e.CreateTime = time.Now().String()
|
||||
result := orm.Eloquent.Table("{{.TableName}}").Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
}
|
||||
doc = *e
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
// 获取{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Get() ({{.ClassName}}, error) {
|
||||
var doc {{.ClassName}}
|
||||
var doc {{.ClassName}}
|
||||
|
||||
table := orm.Eloquent.Table("{{.TableName}}")
|
||||
{{ range .Columns -}}
|
||||
table := orm.Eloquent.Table("{{.TableName}}")
|
||||
{{ range .Columns -}}
|
||||
{{$z := .IsQuery}}
|
||||
{{- if ($z) -}}if e.{{.GoField}} != "" {
|
||||
table = table.Where("{{.ColumnName}} = ?", e.{{.GoField}})
|
||||
table = table.Where("{{.ColumnName}} = ?", e.{{.GoField}})
|
||||
}
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
if err := table.First(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
return doc, nil
|
||||
if err := table.First(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
// 获取{{.ClassName}}带分页
|
||||
func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}}, int32, error) {
|
||||
var doc []{{.ClassName}}
|
||||
var doc []{{.ClassName}}
|
||||
|
||||
table := orm.Eloquent.Select("*").Table("{{.TableName}}")
|
||||
{{ range .Columns -}}
|
||||
table := orm.Eloquent.Select("*").Table("{{.TableName}}")
|
||||
{{ range .Columns -}}
|
||||
{{$z := .IsQuery}}
|
||||
{{- if ($z) -}}if e.{{.GoField}} != "" {
|
||||
table = table.Where("{{.ColumnName}} = ?", e.{{.GoField}})
|
||||
table = table.Where("{{.ColumnName}} = ?", e.{{.GoField}})
|
||||
}
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
// 数据权限控制
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
|
||||
table,err := dataPermission.GetDataScope("{{.TableName}}", table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
var count int32
|
||||
table = table.Offset((pageIndex - 1) * pageSize).Limit(pageSize)
|
||||
if err := table.Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
return doc, count, nil
|
||||
// 数据权限控制
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
|
||||
table,err := dataPermission.GetDataScope("{{.TableName}}", table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
var count int32
|
||||
table = table.Offset((pageIndex - 1) * pageSize).Limit(pageSize)
|
||||
if err := table.Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
// 更新{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Update(id int) (update {{.ClassName}}, err error) {
|
||||
if err = orm.Eloquent.Table("{{.TableName}}").Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil {
|
||||
return
|
||||
}
|
||||
if err = orm.Eloquent.Table("{{.TableName}}").Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table("{{.TableName}}").Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table("{{.TableName}}").Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 删除{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Delete(id int) (success bool, err error) {
|
||||
|
||||
if err = orm.Eloquent.Table("{{.TableName}}").Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
success = true
|
||||
return
|
||||
if err = orm.Eloquent.Table("{{.TableName}}").Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
success = true
|
||||
return
|
||||
}
|
||||
|
||||
+4
-9
@@ -10,10 +10,10 @@ type Response struct {
|
||||
}
|
||||
|
||||
type Page struct {
|
||||
List interface{} `json:"list"`
|
||||
Count int `json:"count"`
|
||||
PageIndex int `json:"pageIndex"`
|
||||
PageSize int `json:"pageSize"`
|
||||
List interface{} `json:"list"`
|
||||
Count int `json:"count"`
|
||||
PageIndex int `json:"pageIndex"`
|
||||
PageSize int `json:"pageSize"`
|
||||
}
|
||||
|
||||
type PageResponse struct {
|
||||
@@ -25,7 +25,6 @@ type PageResponse struct {
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
|
||||
func (res *Response) ReturnOK() *Response {
|
||||
res.Code = 200
|
||||
return res
|
||||
@@ -36,11 +35,7 @@ func (res *Response) ReturnError(code int) *Response {
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
func (res *PageResponse) ReturnOK() *PageResponse {
|
||||
res.Code = 200
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ func OK(c *gin.Context, data interface{}, msg string) {
|
||||
}
|
||||
|
||||
// 分页数据处理
|
||||
func PageOK(c *gin.Context, result interface{},count int,pageIndex int,pageSize int, msg string) {
|
||||
func PageOK(c *gin.Context, result interface{}, count int, pageIndex int, pageSize int, msg string) {
|
||||
var res PageResponse
|
||||
res.Data.List = result
|
||||
res.Data.Count = count
|
||||
@@ -40,5 +40,5 @@ func PageOK(c *gin.Context, result interface{},count int,pageIndex int,pageSize
|
||||
|
||||
// 兼容函数
|
||||
func Custum(c *gin.Context, data gin.H) {
|
||||
c.JSON(http.StatusOK,data)
|
||||
c.JSON(http.StatusOK, data)
|
||||
}
|
||||
@@ -20,9 +20,8 @@ type configJsonBody struct {
|
||||
DriverDigit *base64Captcha.DriverDigit
|
||||
}
|
||||
|
||||
|
||||
func DriverStringFunc() (id, b64s string, err error) {
|
||||
e :=configJsonBody{}
|
||||
func DriverStringFunc() (id, b64s string, err error) {
|
||||
e := configJsonBody{}
|
||||
e.Id = uuid.New().String()
|
||||
e.DriverString = base64Captcha.NewDriverString(46, 140, 2, 2, 4, "234567890abcdefghjkmnpqrstuvwxyz", &color.RGBA{240, 240, 246, 246}, []string{"wqy-microhei.ttc"})
|
||||
driver := e.DriverString.ConvertFonts()
|
||||
@@ -30,7 +29,6 @@ func DriverStringFunc() (id, b64s string, err error) {
|
||||
return cap.Generate()
|
||||
}
|
||||
|
||||
|
||||
func DriverDigitFunc() (id, b64s string, err error) {
|
||||
e := configJsonBody{}
|
||||
e.Id = uuid.New().String()
|
||||
@@ -38,4 +36,4 @@ func DriverDigitFunc() (id, b64s string, err error) {
|
||||
driver := e.DriverDigit
|
||||
cap := base64Captcha.NewCaptcha(driver, store)
|
||||
return cap.Generate()
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func portDefault(cfg *viper.Viper) string {
|
||||
}
|
||||
|
||||
func isHttpsDefault(cfg *viper.Viper) bool {
|
||||
if cfg.GetString("ishttps") == "" || cfg.GetBool("ishttps") == false{
|
||||
if cfg.GetString("ishttps") == "" || cfg.GetBool("ishttps") == false {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
|
||||
@@ -16,7 +16,6 @@ var cfgLog *viper.Viper
|
||||
var cfgSsl *viper.Viper
|
||||
var cfgGen *viper.Viper
|
||||
|
||||
|
||||
//载入配置文件
|
||||
func ConfigSetup(path string) {
|
||||
viper.SetConfigFile(path)
|
||||
@@ -25,7 +24,6 @@ func ConfigSetup(path string) {
|
||||
log.Fatal(fmt.Sprintf("Read config file fail: %s", err.Error()))
|
||||
}
|
||||
|
||||
|
||||
//Replace environment variables
|
||||
err = viper.ReadConfig(strings.NewReader(os.ExpandEnv(string(content))))
|
||||
if err != nil {
|
||||
@@ -69,7 +67,6 @@ func ConfigSetup(path string) {
|
||||
GenConfig = InitGen(cfgGen)
|
||||
}
|
||||
|
||||
|
||||
func SetConfig(configPath string, key string, value interface{}) {
|
||||
viper.AddConfigPath(configPath)
|
||||
viper.Set(key, value)
|
||||
|
||||
@@ -19,4 +19,3 @@ func InitDatabase(cfg *viper.Viper) *Database {
|
||||
}
|
||||
|
||||
var DatabaseConfig = new(Database)
|
||||
|
||||
+4
-4
@@ -3,14 +3,14 @@ package config
|
||||
import "github.com/spf13/viper"
|
||||
|
||||
type Gen struct {
|
||||
DBName string
|
||||
FrontPath string
|
||||
DBName string
|
||||
FrontPath string
|
||||
}
|
||||
|
||||
func InitGen(cfg *viper.Viper) *Gen {
|
||||
return &Gen{
|
||||
DBName: cfg.GetString("dbname"),
|
||||
FrontPath: cfg.GetString("frontpath"),
|
||||
DBName: cfg.GetString("dbname"),
|
||||
FrontPath: cfg.GetString("frontpath"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -3,13 +3,13 @@ package config
|
||||
import "github.com/spf13/viper"
|
||||
|
||||
type Log struct {
|
||||
Dir string
|
||||
Dir string
|
||||
Operdb bool
|
||||
}
|
||||
|
||||
func InitLog(cfg *viper.Viper) *Log {
|
||||
return &Log{
|
||||
Dir: cfg.GetString("dir"),
|
||||
Dir: cfg.GetString("dir"),
|
||||
Operdb: cfg.GetBool("operdb"),
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -5,9 +5,9 @@ type (
|
||||
)
|
||||
|
||||
const (
|
||||
ModeDev Mode = "dev" //开发模式
|
||||
ModeTest Mode = "test" //测试模式
|
||||
ModeProd Mode = "prod" //生产模式
|
||||
Mysql = "mysql" //mysql数据库标识
|
||||
ModeDev Mode = "dev" //开发模式
|
||||
ModeTest Mode = "test" //测试模式
|
||||
ModeProd Mode = "prod" //生产模式
|
||||
Mysql = "mysql" //mysql数据库标识
|
||||
Sqlite = "sqlite3" //sqlite
|
||||
)
|
||||
+6
-5
@@ -55,7 +55,7 @@ func FileRemove(name string) {
|
||||
}
|
||||
}
|
||||
|
||||
func FileZip(dst, src string,notContPath string) (err error) {
|
||||
func FileZip(dst, src string, notContPath string) (err error) {
|
||||
//创建准备写入的文件
|
||||
fw, err := os.Create(dst)
|
||||
defer fw.Close()
|
||||
@@ -119,6 +119,7 @@ type ReplaceHelper struct {
|
||||
OldText string //需要替换的文本
|
||||
NewText string //新的文本
|
||||
}
|
||||
|
||||
func (h *ReplaceHelper) DoWrok() error {
|
||||
|
||||
return filepath.Walk(h.Root, h.walkCallback)
|
||||
@@ -134,7 +135,7 @@ func (h ReplaceHelper) walkCallback(path string, f os.FileInfo, err error) error
|
||||
return nil
|
||||
}
|
||||
if f.IsDir() {
|
||||
log.Println("DIR:",path)
|
||||
log.Println("DIR:", path)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -146,8 +147,8 @@ func (h ReplaceHelper) walkCallback(path string, f os.FileInfo, err error) error
|
||||
return err
|
||||
}
|
||||
content := string(buf)
|
||||
log.Printf("h.OldText: %s \n",h.OldText)
|
||||
log.Printf("h.NewText: %s \n",h.NewText)
|
||||
log.Printf("h.OldText: %s \n", h.OldText)
|
||||
log.Printf("h.NewText: %s \n", h.NewText)
|
||||
|
||||
//替换
|
||||
newContent := strings.Replace(content, h.OldText, h.NewText, -1)
|
||||
@@ -156,4 +157,4 @@ func (h ReplaceHelper) walkCallback(path string, f os.FileInfo, err error) error
|
||||
ioutil.WriteFile(path, []byte(newContent), 0)
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,4 +4,4 @@ import "strconv"
|
||||
|
||||
func Float64ToString(e float64) string {
|
||||
return strconv.FormatFloat(e, 'E', -1, 64)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,4 +4,4 @@ import "strconv"
|
||||
|
||||
func IntToString(e int) string {
|
||||
return strconv.Itoa(e)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,4 +4,4 @@ import "strconv"
|
||||
|
||||
func Int64ToString(e int64) string {
|
||||
return strconv.FormatInt(e, 10)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -30,4 +30,4 @@ func GetLocation(ip string) string {
|
||||
return "未知位置"
|
||||
}
|
||||
return m["province"] + "-" + m["city"]
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ func InitLogger() {
|
||||
log.FieldKeyLevel: "@level",
|
||||
log.FieldKeyMsg: "@message"}})
|
||||
|
||||
|
||||
switch Mode(config2.ApplicationConfig.Mode) {
|
||||
case ModeDev, ModeTest:
|
||||
log.SetOutput(os.Stdout)
|
||||
|
||||
@@ -17,7 +17,6 @@ func StringToInt(e string) (int, error) {
|
||||
return strconv.Atoi(e)
|
||||
}
|
||||
|
||||
|
||||
func GetCurrentTimeStr() string {
|
||||
return time.Now().Format("2006/01/02 15:04:05")
|
||||
}
|
||||
@@ -26,7 +25,6 @@ func GetCurrentTime() time.Time {
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
|
||||
func StructToJsonStr(e interface{}) (string, error) {
|
||||
if b, err := json.Marshal(e); err == nil {
|
||||
return string(b), err
|
||||
|
||||
+1
-2
@@ -10,7 +10,6 @@ func IdsStrToIdsIntGroup(key string, c *gin.Context) []int {
|
||||
return idsStrToIdsIntGroup(c.Param(key))
|
||||
}
|
||||
|
||||
|
||||
func idsStrToIdsIntGroup(keys string) []int {
|
||||
IDS := make([]int, 0)
|
||||
ids := strings.Split(keys, ",")
|
||||
@@ -19,4 +18,4 @@ func idsStrToIdsIntGroup(keys string) []int {
|
||||
IDS = append(IDS, ID)
|
||||
}
|
||||
return IDS
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user