1
This commit is contained in:
commit
78d2218a2e
@ -2,21 +2,22 @@ package system
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"f5"
|
"f5"
|
||||||
"github.com/gin-gonic/gin"
|
"jccommon"
|
||||||
"main/common"
|
"main/common"
|
||||||
"main/constant"
|
"main/constant"
|
||||||
"main/model/system"
|
"main/model/system"
|
||||||
"net/http"
|
"net/http"
|
||||||
"q5"
|
"q5"
|
||||||
"jccommon"
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MailApi struct {
|
type MailApi struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MailApi) ListMail(c *gin.Context) {
|
func (this *MailApi) ListMail(c *gin.Context) {
|
||||||
var pageSize int32 = 100
|
var pageSize = q5.SafeToInt32(c.DefaultQuery("pagesize", ""))
|
||||||
var cursor int64 = 0
|
var cursor = q5.SafeToInt64(c.DefaultQuery("cursor", ""))
|
||||||
orderBy := ""
|
orderBy := ""
|
||||||
sql := "SELECT * FROM t_mail WHERE 1=1 and unikey is not null "
|
sql := "SELECT * FROM t_mail WHERE 1=1 and unikey is not null "
|
||||||
subFilters := []f5.DbQueryFilter{}
|
subFilters := []f5.DbQueryFilter{}
|
||||||
@ -24,30 +25,35 @@ func (this *MailApi) ListMail(c *gin.Context) {
|
|||||||
inSub := `tag1 IN (` + q5.ToString(jccommon.MAIL_TAG1_CUSTOM)
|
inSub := `tag1 IN (` + q5.ToString(jccommon.MAIL_TAG1_CUSTOM)
|
||||||
inSub += ")"
|
inSub += ")"
|
||||||
//q5.AppendSlice(&subFilters, f5.GetDbFilter().Custom(inSub).And())
|
//q5.AppendSlice(&subFilters, f5.GetDbFilter().Custom(inSub).And())
|
||||||
|
f5.GetDbFilter().Custom("deleted = 0").And()
|
||||||
}
|
}
|
||||||
mails := []*system.Mail{}
|
mails := []*system.Mail{}
|
||||||
|
rspObj := struct {
|
||||||
|
Code int32 `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Cursor int64 `json:"cursor"`
|
||||||
|
Remaining int32 `json:"remaining"`
|
||||||
|
Data []*system.Mail `json:"data"`
|
||||||
|
}{}
|
||||||
f5.GetGoStyleDb().StreamPageQuery(
|
f5.GetGoStyleDb().StreamPageQuery(
|
||||||
constant.MAIL_DB,
|
constant.MAIL_DB,
|
||||||
pageSize,
|
pageSize,
|
||||||
cursor,
|
cursor,
|
||||||
sql,
|
sql,
|
||||||
[]string{
|
[]string{},
|
||||||
},
|
|
||||||
f5.GetDbFilter().Comp(subFilters...),
|
f5.GetDbFilter().Comp(subFilters...),
|
||||||
orderBy,
|
orderBy,
|
||||||
func (err error, pagination *f5.StreamPagination) {
|
func(err error, pagination *f5.StreamPagination) {
|
||||||
//rspObj.Page.FillPage(pagination)
|
rspObj.Cursor = pagination.NextCursor
|
||||||
|
rspObj.Remaining = pagination.Remaining
|
||||||
},
|
},
|
||||||
func (ds *f5.DataSet) {
|
func(ds *f5.DataSet) {
|
||||||
p := new(system.Mail)
|
p := new(system.Mail)
|
||||||
f5.UnmarshalModel(ds, p)
|
f5.UnmarshalModel(ds, p)
|
||||||
q5.AppendSlice(&mails, p)
|
q5.AppendSlice(&mails, p)
|
||||||
})
|
})
|
||||||
c.JSON(http.StatusOK, gin.H{
|
rspObj.Data = mails
|
||||||
"code": 0,
|
c.JSON(http.StatusOK, rspObj)
|
||||||
"message": "",
|
|
||||||
"data": mails,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MailApi) AddMail(c *gin.Context) {
|
func (this *MailApi) AddMail(c *gin.Context) {
|
||||||
@ -81,10 +87,21 @@ func (this *MailApi) AddMail(c *gin.Context) {
|
|||||||
f5.RspErr2(c, 101, "unikey param error")
|
f5.RspErr2(c, 101, "unikey param error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var count int64 = 0
|
||||||
|
if f5.GetApp().GetOrmDb(constant.MAIL_DB).Table("t_mail").Where("unikey = ?", reqJson.UniKey).Count(&count); count > 0 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 2,
|
||||||
|
"message": "unikey 重复",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||||
mail := new(system.Mail)
|
mail := new(system.Mail)
|
||||||
mail.MailId = f5.GetApp().NewLockNodeUuid()
|
mail.MailId = f5.GetApp().NewLockNodeUuid()
|
||||||
mail.MailType = reqJson.MailType
|
mail.MailType = reqJson.MailType
|
||||||
|
mail.UniKey = reqJson.UniKey
|
||||||
mail.SendTime = reqJson.SendTime
|
mail.SendTime = reqJson.SendTime
|
||||||
mail.ExpireTime = reqJson.ExpireTime
|
mail.ExpireTime = reqJson.ExpireTime
|
||||||
mail.UserRegStartTime = reqJson.UserRegStartTime
|
mail.UserRegStartTime = reqJson.UserRegStartTime
|
||||||
@ -97,8 +114,11 @@ func (this *MailApi) AddMail(c *gin.Context) {
|
|||||||
mail.Tag2 = jccommon.MAIL_TAG2_CUSTOM_NORMAL
|
mail.Tag2 = jccommon.MAIL_TAG2_CUSTOM_NORMAL
|
||||||
mail.CreateTime = nowDaySeconds
|
mail.CreateTime = nowDaySeconds
|
||||||
mail.ModifyTime = nowDaySeconds
|
mail.ModifyTime = nowDaySeconds
|
||||||
if f5.GetApp().GetOrmDb(constant.MAIL_DB).Create(mail).Error == nil {
|
if f5.GetApp().GetOrmDb(constant.MAIL_DB).Create(mail).Error != nil {
|
||||||
f5.RspErr2(c, 500, "server internal error")
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 500,
|
||||||
|
"message": "",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@ -142,6 +162,16 @@ func (this *MailApi) EditMail(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var count int64 = 0
|
||||||
|
if f5.GetApp().GetOrmDb(constant.MAIL_DB).Where("mail_id = ?", reqJson.MailId).Count(&count); count < 1 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 2,
|
||||||
|
"message": "mailid不存在",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||||
mail := new(system.Mail)
|
mail := new(system.Mail)
|
||||||
mail.MailId = reqJson.MailId
|
mail.MailId = reqJson.MailId
|
||||||
@ -154,7 +184,38 @@ func (this *MailApi) EditMail(c *gin.Context) {
|
|||||||
mail.Content = reqJson.Content
|
mail.Content = reqJson.Content
|
||||||
mail.Attachments = reqJson.Attachments
|
mail.Attachments = reqJson.Attachments
|
||||||
mail.Recipients = reqJson.Recipients
|
mail.Recipients = reqJson.Recipients
|
||||||
mail.CreateTime = nowDaySeconds
|
mail.ModifyTime = nowDaySeconds
|
||||||
|
f5.GetApp().GetOrmDb(constant.MAIL_DB).Save(mail)
|
||||||
|
{
|
||||||
|
e := new(jccommon.MailEvent)
|
||||||
|
e.EventName = jccommon.EVENT_MAIL_UPDATE
|
||||||
|
e.Param1 = q5.ToString(mail.MailId)
|
||||||
|
e.CreateTime = nowDaySeconds
|
||||||
|
e.ModifyTime = nowDaySeconds
|
||||||
|
f5.GetApp().GetOrmDb(constant.MAIL_DB).Create(e)
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 0,
|
||||||
|
"message": "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MailApi) DelMail(c *gin.Context) {
|
||||||
|
mailid := q5.ToInt64(c.Param("mailid"))
|
||||||
|
|
||||||
|
var count int64 = 0
|
||||||
|
if f5.GetApp().GetOrmDb(constant.MAIL_DB).Table("t_mail").Where("mail_id = ?", mailid).Count(&count); count < 1 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 2,
|
||||||
|
"message": "mailid不存在",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||||
|
mail := new(system.Mail)
|
||||||
|
mail.MailId = mailid
|
||||||
|
mail.Deleted = 1
|
||||||
mail.ModifyTime = nowDaySeconds
|
mail.ModifyTime = nowDaySeconds
|
||||||
f5.GetApp().GetOrmDb(constant.MAIL_DB).Save(mail)
|
f5.GetApp().GetOrmDb(constant.MAIL_DB).Save(mail)
|
||||||
{
|
{
|
||||||
|
@ -23,22 +23,22 @@ Attachments:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
type Mail struct {
|
type Mail struct {
|
||||||
UniKey *string `gorm:"column:unikey;<-:create" json:"unikey"`
|
UniKey string `gorm:"column:unikey;<-:create" json:"unikey"`
|
||||||
MailId int64 `gorm:"primaryKey;column:mail_id;<-:create" json:"mail_id,string"`
|
MailId int64 `gorm:"primaryKey;column:mail_id;<-:create" json:"mail_id,string"`
|
||||||
MailType int32 `gorm:"column:mail_type;<-:create" json:"mail_type"`
|
MailType int32 `gorm:"column:mail_type;<-:create" 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"`
|
||||||
Recipients []string `gorm:"column:recipients;serializer:json" json:"recipients"`
|
Recipients []string `gorm:"column:recipients;serializer:json" json:"recipients"`
|
||||||
Attachments []common.Attachment `gorm:"column:attachments;serializer:json" json:"attachments"`
|
Attachments []common.Attachment `gorm:"column:attachments;serializer:json" json:"attachments"`
|
||||||
Deleted int32 `gorm:"column:deleted" json:"deleted"`
|
Deleted int32 `gorm:"column:deleted" json:"deleted"`
|
||||||
SendTime int32 `gorm:"column:sendtime" json:"sendtime"`
|
SendTime int32 `gorm:"column:sendtime" json:"sendtime"`
|
||||||
UserRegStartTime int32 `gorm:"column:user_reg_start_time" json:"user_reg_start_time"`
|
UserRegStartTime int32 `gorm:"column:user_reg_start_time" json:"user_reg_start_time"`
|
||||||
UserRegEndTime int32 `gorm:"column:user_reg_end_time" json:"user_reg_end_time"`
|
UserRegEndTime int32 `gorm:"column:user_reg_end_time" json:"user_reg_end_time"`
|
||||||
Tag1 int32 `gorm:"column:tag1;<-:create" json:"tag1"`
|
Tag1 int32 `gorm:"column:tag1;<-:create" json:"tag1"`
|
||||||
Tag2 int32 `gorm:"column:tag2;<-:create" json:"tag2"`
|
Tag2 int32 `gorm:"column:tag2;<-:create" json:"tag2"`
|
||||||
ExpireTime int32 `gorm:"column:expiretime" json:"expiretime"`
|
ExpireTime int32 `gorm:"column:expiretime" json:"expiretime"`
|
||||||
CreateTime int32 `gorm:"column:createtime;<-:create" json:"createtime"`
|
CreateTime int32 `gorm:"column:createtime;<-:create" json:"createtime"`
|
||||||
ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"`
|
ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Mail) TableName() string {
|
func (Mail) TableName() string {
|
||||||
|
@ -16,5 +16,6 @@ func (this *MailRoute) InitMailRouter(priRouter *gin.RouterGroup) {
|
|||||||
priUserRouter.POST("add", middleware.Permission("api/v1/mail/add", mailApi.AddMail))
|
priUserRouter.POST("add", middleware.Permission("api/v1/mail/add", mailApi.AddMail))
|
||||||
priUserRouter.POST("edit", middleware.Permission("api/v1/mail/edit", mailApi.EditMail))
|
priUserRouter.POST("edit", middleware.Permission("api/v1/mail/edit", mailApi.EditMail))
|
||||||
priUserRouter.GET("list", middleware.Permission("api/v1/mail/list", mailApi.ListMail))
|
priUserRouter.GET("list", middleware.Permission("api/v1/mail/list", mailApi.ListMail))
|
||||||
|
priUserRouter.GET("del/:mailid", middleware.Permission("api/v1/mail/del", mailApi.DelMail))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user