1
This commit is contained in:
parent
59b31a0d6d
commit
701a1fb650
@ -20,11 +20,10 @@ module.exports = class {
|
|||||||
['!data', common.UserGroup()]
|
['!data', common.UserGroup()]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
'method': 'POST',
|
'method': 'POST',
|
||||||
'name': 'add',
|
'name': 'add',
|
||||||
'desc': '添加邮件',
|
'desc': '添加用户组',
|
||||||
'group': 'user_group',
|
'group': 'user_group',
|
||||||
'url': 'api/v1/user_group/add',
|
'url': 'api/v1/user_group/add',
|
||||||
'header': [
|
'header': [
|
||||||
@ -40,7 +39,26 @@ module.exports = class {
|
|||||||
new common.RspHead(),
|
new common.RspHead(),
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'method': 'POST',
|
||||||
|
'name': 'add',
|
||||||
|
'desc': '编辑用户组',
|
||||||
|
'group': 'user_group',
|
||||||
|
'url': 'api/v1/user_group/edit',
|
||||||
|
'header': [
|
||||||
|
],
|
||||||
|
'is_json_params': true,
|
||||||
|
'params': [
|
||||||
|
new common.RspHead(),
|
||||||
|
['group_id', 0, '组id'],
|
||||||
|
['group_name', '', '组名'],
|
||||||
|
['group_desc', '', '描述'],
|
||||||
|
['enabled', 0, '是否启用'],
|
||||||
|
],
|
||||||
|
'response': [
|
||||||
|
new common.RspHead(),
|
||||||
|
]
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,4 +22,147 @@ func (this *UserGroupApi) List(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *UserGroupApi) Add(c *gin.Context) {
|
func (this *UserGroupApi) Add(c *gin.Context) {
|
||||||
|
req := struct {
|
||||||
|
GroupName string `binding:"required" json:"group_name"`
|
||||||
|
GroupDesc string `json:"group_desc"`
|
||||||
|
Enabled int32 `json:"enabled"`
|
||||||
|
}{}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
db := f5.GetApp().GetOrmDb(constant.MAIL_DB)
|
||||||
|
if err := db.Where("group_name = ?", req.GroupName).Take(new(system.UserGroup)).Error; err == nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 2,
|
||||||
|
"message": "组名已存在",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
if !f5.IsOrmErrRecordNotFound(err) {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 500,
|
||||||
|
"message": "sever internal error:" + err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||||
|
group := new(system.UserGroup)
|
||||||
|
group.GroupId = f5.GetApp().NewLockNodeUuid()
|
||||||
|
group.GroupName = req.GroupName
|
||||||
|
group.GroupDesc = req.GroupDesc
|
||||||
|
group.Enabled = req.Enabled
|
||||||
|
group.CreateTime = nowDaySeconds
|
||||||
|
group.ModifyTime = nowDaySeconds
|
||||||
|
if err := db.Create(group).Error; err != nil {
|
||||||
|
if !f5.IsOrmErrRecordNotFound(err) {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 500,
|
||||||
|
"message": "sever internal error:" + err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 0,
|
||||||
|
"message": "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UserGroupApi) Edit(c *gin.Context) {
|
||||||
|
req := struct {
|
||||||
|
GroupId int64 `binding:"required" json:"group_id"`
|
||||||
|
GroupName string `binding:"required" json:"group_name"`
|
||||||
|
GroupDesc string `json:"group_desc"`
|
||||||
|
Enabled int32 `json:"enabled"`
|
||||||
|
}{}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
group := new(system.UserGroup)
|
||||||
|
db := f5.GetApp().GetOrmDb(constant.MAIL_DB)
|
||||||
|
if err := db.Take(group, req.GroupId).Error; err != nil {
|
||||||
|
if !f5.IsOrmErrRecordNotFound(err) {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 500,
|
||||||
|
"message": "sever internal error:" + err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 2,
|
||||||
|
"message": "无法查到记录",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||||
|
group.GroupName = req.GroupName
|
||||||
|
group.GroupDesc = req.GroupDesc
|
||||||
|
group.Enabled = req.Enabled
|
||||||
|
group.ModifyTime = nowDaySeconds
|
||||||
|
if err := db.Save(group).Error; err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 500,
|
||||||
|
"message": "sever internal error:" + err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 0,
|
||||||
|
"message": "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UserGroupApi) Del(c *gin.Context) {
|
||||||
|
req := struct {
|
||||||
|
GroupId int64 `binding:"required" json:"group_id"`
|
||||||
|
}{}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 1,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
group := new(system.UserGroup)
|
||||||
|
db := f5.GetApp().GetOrmDb(constant.MAIL_DB)
|
||||||
|
if err := db.Take(group, req.GroupId).Error; err != nil {
|
||||||
|
if !f5.IsOrmErrRecordNotFound(err) {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 500,
|
||||||
|
"message": "sever internal error:" + err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 2,
|
||||||
|
"message": "无法查到记录",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||||
|
group.ModifyTime = nowDaySeconds
|
||||||
|
if err := db.Delete(group).Error; err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 500,
|
||||||
|
"message": "sever internal error:" + err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 0,
|
||||||
|
"message": "",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package system
|
package system
|
||||||
|
|
||||||
type Mail struct {
|
type Mail struct {
|
||||||
MailId int64 `gorm:"unique;column:mail_id" json:"mail_id"`
|
MailId int64 `gorm:"primaryKey;column:mail_id" json:"mail_id"`
|
||||||
MailType int32 `gorm:"column:mail_type" json:"mail_type"`
|
MailType int32 `gorm:"column:mail_type" json:"mail_type"`
|
||||||
Subject string `gorm:"column:subject" json:"subject"`
|
Subject string `gorm:"column:subject" json:"subject"`
|
||||||
Content string `gorm:"column:content" json:"content"`
|
Content string `gorm:"column:content" json:"content"`
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package system
|
package system
|
||||||
|
|
||||||
type UserGroup struct {
|
type UserGroup struct {
|
||||||
GroupId int64 `gorm:"unique;column:group_id" json:"group_id"`
|
GroupId int64 `gorm:"primaryKey;column:group_id" json:"group_id"`
|
||||||
GroupName string `gorm:"unique;column:group_name" json:"group_name"`
|
GroupName string `gorm:"unique;column:group_name" json:"group_name"`
|
||||||
GroupDesc string `gorm:"column:group_desc" json:"group_desc"`
|
GroupDesc string `gorm:"group_desc" json:"group_desc"`
|
||||||
Enabled int32 `gorm:"unique;column:enabled" json:"enabled"`
|
Enabled int32 `gorm:"column:enabled" json:"enabled"`
|
||||||
Deleted int32 `gorm:"unique;column:deleted" json:"deleted"`
|
Deleted int32 `gorm:"column:deleted" json:"deleted"`
|
||||||
CreateTime int32 `gorm:"unique;column:createtime" json:"createtime"`
|
CreateTime int32 `gorm:"column:createtime" json:"createtime"`
|
||||||
ModifyTime int32 `gorm:"unique;column:modifytime" json:"modifytime"`
|
ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (UserGroup) TableName() string {
|
func (UserGroup) TableName() string {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user