1
This commit is contained in:
commit
78d2218a2e
@ -2,21 +2,22 @@ package system
|
||||
|
||||
import (
|
||||
"f5"
|
||||
"github.com/gin-gonic/gin"
|
||||
"jccommon"
|
||||
"main/common"
|
||||
"main/constant"
|
||||
"main/model/system"
|
||||
"net/http"
|
||||
"q5"
|
||||
"jccommon"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type MailApi struct {
|
||||
}
|
||||
|
||||
func (this *MailApi) ListMail(c *gin.Context) {
|
||||
var pageSize int32 = 100
|
||||
var cursor int64 = 0
|
||||
var pageSize = q5.SafeToInt32(c.DefaultQuery("pagesize", ""))
|
||||
var cursor = q5.SafeToInt64(c.DefaultQuery("cursor", ""))
|
||||
orderBy := ""
|
||||
sql := "SELECT * FROM t_mail WHERE 1=1 and unikey is not null "
|
||||
subFilters := []f5.DbQueryFilter{}
|
||||
@ -24,30 +25,35 @@ func (this *MailApi) ListMail(c *gin.Context) {
|
||||
inSub := `tag1 IN (` + q5.ToString(jccommon.MAIL_TAG1_CUSTOM)
|
||||
inSub += ")"
|
||||
//q5.AppendSlice(&subFilters, f5.GetDbFilter().Custom(inSub).And())
|
||||
f5.GetDbFilter().Custom("deleted = 0").And()
|
||||
}
|
||||
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(
|
||||
constant.MAIL_DB,
|
||||
pageSize,
|
||||
cursor,
|
||||
sql,
|
||||
[]string{
|
||||
},
|
||||
[]string{},
|
||||
f5.GetDbFilter().Comp(subFilters...),
|
||||
orderBy,
|
||||
func (err error, pagination *f5.StreamPagination) {
|
||||
//rspObj.Page.FillPage(pagination)
|
||||
func(err error, pagination *f5.StreamPagination) {
|
||||
rspObj.Cursor = pagination.NextCursor
|
||||
rspObj.Remaining = pagination.Remaining
|
||||
},
|
||||
func (ds *f5.DataSet) {
|
||||
func(ds *f5.DataSet) {
|
||||
p := new(system.Mail)
|
||||
f5.UnmarshalModel(ds, p)
|
||||
q5.AppendSlice(&mails, p)
|
||||
})
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": "",
|
||||
"data": mails,
|
||||
})
|
||||
rspObj.Data = mails
|
||||
c.JSON(http.StatusOK, rspObj)
|
||||
}
|
||||
|
||||
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")
|
||||
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())
|
||||
mail := new(system.Mail)
|
||||
mail.MailId = f5.GetApp().NewLockNodeUuid()
|
||||
mail.MailType = reqJson.MailType
|
||||
mail.UniKey = reqJson.UniKey
|
||||
mail.SendTime = reqJson.SendTime
|
||||
mail.ExpireTime = reqJson.ExpireTime
|
||||
mail.UserRegStartTime = reqJson.UserRegStartTime
|
||||
@ -97,8 +114,11 @@ func (this *MailApi) AddMail(c *gin.Context) {
|
||||
mail.Tag2 = jccommon.MAIL_TAG2_CUSTOM_NORMAL
|
||||
mail.CreateTime = nowDaySeconds
|
||||
mail.ModifyTime = nowDaySeconds
|
||||
if f5.GetApp().GetOrmDb(constant.MAIL_DB).Create(mail).Error == nil {
|
||||
f5.RspErr2(c, 500, "server internal error")
|
||||
if f5.GetApp().GetOrmDb(constant.MAIL_DB).Create(mail).Error != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 500,
|
||||
"message": "",
|
||||
})
|
||||
return
|
||||
}
|
||||
{
|
||||
@ -142,6 +162,16 @@ func (this *MailApi) EditMail(c *gin.Context) {
|
||||
})
|
||||
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())
|
||||
mail := new(system.Mail)
|
||||
mail.MailId = reqJson.MailId
|
||||
@ -154,7 +184,38 @@ func (this *MailApi) EditMail(c *gin.Context) {
|
||||
mail.Content = reqJson.Content
|
||||
mail.Attachments = reqJson.Attachments
|
||||
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
|
||||
f5.GetApp().GetOrmDb(constant.MAIL_DB).Save(mail)
|
||||
{
|
||||
|
@ -23,22 +23,22 @@ Attachments:
|
||||
*/
|
||||
|
||||
type Mail struct {
|
||||
UniKey *string `gorm:"column:unikey;<-:create" json:"unikey"`
|
||||
MailId int64 `gorm:"primaryKey;column:mail_id;<-:create" json:"mail_id,string"`
|
||||
MailType int32 `gorm:"column:mail_type;<-:create" json:"mail_type"`
|
||||
Subject string `gorm:"column:subject" json:"subject"`
|
||||
Content string `gorm:"column:content" json:"content"`
|
||||
Recipients []string `gorm:"column:recipients;serializer:json" json:"recipients"`
|
||||
Attachments []common.Attachment `gorm:"column:attachments;serializer:json" json:"attachments"`
|
||||
Deleted int32 `gorm:"column:deleted" json:"deleted"`
|
||||
SendTime int32 `gorm:"column:sendtime" json:"sendtime"`
|
||||
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"`
|
||||
Tag1 int32 `gorm:"column:tag1;<-:create" json:"tag1"`
|
||||
Tag2 int32 `gorm:"column:tag2;<-:create" json:"tag2"`
|
||||
ExpireTime int32 `gorm:"column:expiretime" json:"expiretime"`
|
||||
CreateTime int32 `gorm:"column:createtime;<-:create" json:"createtime"`
|
||||
ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"`
|
||||
UniKey string `gorm:"column:unikey;<-:create" json:"unikey"`
|
||||
MailId int64 `gorm:"primaryKey;column:mail_id;<-:create" json:"mail_id,string"`
|
||||
MailType int32 `gorm:"column:mail_type;<-:create" json:"mail_type"`
|
||||
Subject string `gorm:"column:subject" json:"subject"`
|
||||
Content string `gorm:"column:content" json:"content"`
|
||||
Recipients []string `gorm:"column:recipients;serializer:json" json:"recipients"`
|
||||
Attachments []common.Attachment `gorm:"column:attachments;serializer:json" json:"attachments"`
|
||||
Deleted int32 `gorm:"column:deleted" json:"deleted"`
|
||||
SendTime int32 `gorm:"column:sendtime" json:"sendtime"`
|
||||
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"`
|
||||
Tag1 int32 `gorm:"column:tag1;<-:create" json:"tag1"`
|
||||
Tag2 int32 `gorm:"column:tag2;<-:create" json:"tag2"`
|
||||
ExpireTime int32 `gorm:"column:expiretime" json:"expiretime"`
|
||||
CreateTime int32 `gorm:"column:createtime;<-:create" json:"createtime"`
|
||||
ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"`
|
||||
}
|
||||
|
||||
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("edit", middleware.Permission("api/v1/mail/edit", mailApi.EditMail))
|
||||
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