This commit is contained in:
yangduo 2024-08-08 10:34:10 +08:00
parent f3ddc24fab
commit 4432b1832d
3 changed files with 98 additions and 32 deletions

View File

@ -2,47 +2,55 @@ 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" sql := "SELECT * FROM t_mail"
subFilters := []f5.DbQueryFilter{} subFilters := []f5.DbQueryFilter{}
{
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) {
@ -72,10 +80,21 @@ func (this *MailApi) AddMail(c *gin.Context) {
}) })
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
@ -88,8 +107,12 @@ 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 {
c.JSON(http.StatusOK, gin.H{
"code": 500,
"message": "",
})
return
} }
{ {
e := new(jccommon.MailEvent) e := new(jccommon.MailEvent)
@ -132,6 +155,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
@ -144,7 +177,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)
{ {

View File

@ -23,21 +23,22 @@ Attachments:
*/ */
type Mail struct { type Mail struct {
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"` UniKey string `gorm:"uniqueIndex;column:unikey;<-:create" json:"unikey"`
Content string `gorm:"column:content" json:"content"` Subject string `gorm:"column:subject" json:"subject"`
Recipients []string `gorm:"column:recipients;serializer:json" json:"recipients"` Content string `gorm:"column:content" json:"content"`
Attachments []common.Attachment `gorm:"column:attachments;serializer:json" json:"attachments"` Recipients []string `gorm:"column:recipients;serializer:json" json:"recipients"`
Deleted int32 `gorm:"column:deleted" json:"deleted"` Attachments []common.Attachment `gorm:"column:attachments;serializer:json" json:"attachments"`
SendTime int32 `gorm:"column:sendtime" json:"sendtime"` Deleted int32 `gorm:"column:deleted" json:"deleted"`
UserRegStartTime int32 `gorm:"column:user_reg_start_time" json:"user_reg_start_time"` SendTime int32 `gorm:"column:sendtime" json:"sendtime"`
UserRegEndTime int32 `gorm:"column:user_reg_end_time" json:"user_reg_end_time"` UserRegStartTime int32 `gorm:"column:user_reg_start_time" json:"user_reg_start_time"`
Tag1 int32 `gorm:"column:tag1" json:"tag1"` UserRegEndTime int32 `gorm:"column:user_reg_end_time" json:"user_reg_end_time"`
Tag2 int32 `gorm:"column:tag2;" json:"tag2"` Tag1 int32 `gorm:"column:tag1" json:"tag1"`
ExpireTime int32 `gorm:"column:expiretime" json:"expiretime"` Tag2 int32 `gorm:"column:tag2;" json:"tag2"`
CreateTime int32 `gorm:"column:createtime;<-:create" json:"createtime"` ExpireTime int32 `gorm:"column:expiretime" json:"expiretime"`
ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"` CreateTime int32 `gorm:"column:createtime;<-:create" json:"createtime"`
ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"`
} }
func (Mail) TableName() string { func (Mail) TableName() string {

View File

@ -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))
} }
} }