feat:完善项目信息
This commit is contained in:
105
app/api/admin/controller/service/message.go
Normal file
105
app/api/admin/controller/service/message.go
Normal file
@ -0,0 +1,105 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
*session.Admin
|
||||
}
|
||||
|
||||
type MessageHandle func(session *session.Admin) *Message
|
||||
|
||||
type MessageInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model.ServiceMessageInfo
|
||||
Area string `json:"area"`
|
||||
}
|
||||
|
||||
// Instance 列表信息
|
||||
func (c *Message) Instance(tenantID uint64, name string, status int, content string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mServiceMessage := model.NewServiceMessage()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if c.TenantID > 0 {
|
||||
where = append(where, model2.NewWhere("m.tenant_id", c.TenantID))
|
||||
}
|
||||
if tenantID > 0 {
|
||||
where = append(where, model2.NewWhere("m.tenant_id", tenantID))
|
||||
}
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("m.name", name))
|
||||
}
|
||||
if status > 0 {
|
||||
where = append(where, model2.NewWhere("m.status", status))
|
||||
}
|
||||
if content != "" {
|
||||
where = append(where, model2.NewWhereLike("m.content", content))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mServiceMessage.Message(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*MessageInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &MessageInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
ServiceMessageInfo: v,
|
||||
Area: v.FormatBasic(),
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, err
|
||||
}
|
||||
|
||||
// Handle 处理操作
|
||||
func (c *Message) Handle(id uint64, content string) error {
|
||||
mServiceMessage := model.NewServiceMessage()
|
||||
mServiceMessage.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mServiceMessage.ServiceMessage, []string{"id", "tenant_id", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,留言信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mServiceMessage.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
if mServiceMessage.Status != model2.ServiceMessageStatusForProcessing {
|
||||
return errors.New("操作错误,当前留言信息已处理")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Updates(mServiceMessage.ServiceMessage, map[string]interface{}{
|
||||
"status": model2.ServiceMessageStatusForProcessed, "updated_at": time.Now(),
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mServiceMessageLog := model.NewServiceMessageLog()
|
||||
mServiceMessageLog.UID = c.UID
|
||||
mServiceMessageLog.MessageID = id
|
||||
mServiceMessageLog.Content = content
|
||||
|
||||
if err = model2.Create(mServiceMessage.ServiceMessage); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func NewMessage() MessageHandle {
|
||||
return func(session *session.Admin) *Message {
|
||||
return &Message{session}
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import (
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
config2 "SciencesServer/config"
|
||||
"errors"
|
||||
)
|
||||
|
||||
@ -25,11 +26,12 @@ type (
|
||||
SolutionCaseDetailInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.ServiceSolutionCase
|
||||
KindID string `json:"kind_id"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
KindID string `json:"kind_id"`
|
||||
}
|
||||
// SolutionCaseParams 案例参数信息
|
||||
SolutionCaseParams struct {
|
||||
ID, KindID uint64
|
||||
ID, TenantID, KindID uint64
|
||||
Title, Image, Description, Content string
|
||||
Sort int
|
||||
}
|
||||
@ -37,7 +39,8 @@ type (
|
||||
SolutionCaseKindInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.ServiceSolutionCaseKind
|
||||
Area string `json:"area"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
Area string `json:"area"`
|
||||
}
|
||||
// SolutionCaseKindSelectInfo 案例分类筛选信息
|
||||
SolutionCaseKindSelectInfo struct {
|
||||
@ -47,7 +50,7 @@ type (
|
||||
}
|
||||
// SolutionCaseKindParams 案例分类参数信息
|
||||
SolutionCaseKindParams struct {
|
||||
ID uint64
|
||||
ID, TenantID uint64
|
||||
Mode int
|
||||
Title, Image string
|
||||
Sort int
|
||||
@ -82,7 +85,7 @@ func (c *SolutionCase) Instance(tenantID uint64, title string, kindID uint64, pa
|
||||
list := make([]*SolutionCaseInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
v.Image.Image = v.Image.Analysis("")
|
||||
v.Image.Image = v.Image.Analysis(config2.SettingInfo.Domain)
|
||||
|
||||
list = append(list, &SolutionCaseInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
@ -105,11 +108,12 @@ func (c *SolutionCase) Detail(id uint64) (*SolutionCaseDetailInfo, error) {
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,案例信息不存在或已被删除")
|
||||
}
|
||||
mServiceSolutionCase.Image.Image = mServiceSolutionCase.Image.Analysis("")
|
||||
mServiceSolutionCase.Image.Image = mServiceSolutionCase.Image.Analysis(config2.SettingInfo.Domain)
|
||||
|
||||
return &SolutionCaseDetailInfo{
|
||||
ID: mServiceSolutionCase.GetEncodeID(),
|
||||
ServiceSolutionCase: mServiceSolutionCase.ServiceSolutionCase,
|
||||
TenantID: mServiceSolutionCase.GetEncodeTenantID(),
|
||||
KindID: (&model2.Model{ID: mServiceSolutionCase.KindID}).GetEncodeID(),
|
||||
}, nil
|
||||
}
|
||||
@ -140,10 +144,16 @@ func (c *SolutionCase) Form(params *SolutionCaseParams) error {
|
||||
mServiceSolutionCase.Sort = params.Sort
|
||||
|
||||
if mServiceSolutionCase.ID > 0 {
|
||||
if c.TenantID <= 0 {
|
||||
mServiceSolutionCase.TenantID = params.TenantID
|
||||
}
|
||||
return model2.Updates(mServiceSolutionCase.ServiceSolutionCase, mServiceSolutionCase.ServiceSolutionCase)
|
||||
}
|
||||
mServiceSolutionCase.TenantID = c.TenantID
|
||||
mServiceSolutionCase.TenantID = params.TenantID
|
||||
|
||||
if c.TenantID > 0 {
|
||||
mServiceSolutionCase.TenantID = c.TenantID
|
||||
}
|
||||
return model2.Create(mServiceSolutionCase.ServiceSolutionCase)
|
||||
}
|
||||
|
||||
@ -193,9 +203,12 @@ func (c *SolutionCase) Kind(tenantID uint64, mode int, title string, page, pageS
|
||||
list := make([]*SolutionCaseKindInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
v.Image.Image = v.Image.Analysis(config2.SettingInfo.Domain)
|
||||
|
||||
list = append(list, &SolutionCaseKindInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
ServiceSolutionCaseKind: v.ServiceSolutionCaseKind,
|
||||
TenantID: v.GetEncodeTenantID(),
|
||||
Area: v.FormatBasic(),
|
||||
})
|
||||
}
|
||||
@ -259,10 +272,16 @@ func (c *SolutionCase) KindForm(params *SolutionCaseKindParams) error {
|
||||
mServiceSolutionCaseKind.Sort = params.Sort
|
||||
|
||||
if mServiceSolutionCaseKind.ID > 0 {
|
||||
if c.TenantID <= 0 {
|
||||
mServiceSolutionCaseKind.TenantID = params.TenantID
|
||||
}
|
||||
return model2.Updates(mServiceSolutionCaseKind.ServiceSolutionCaseKind, mServiceSolutionCaseKind.ServiceSolutionCaseKind)
|
||||
}
|
||||
mServiceSolutionCaseKind.TenantID = c.TenantID
|
||||
mServiceSolutionCaseKind.TenantID = params.TenantID
|
||||
|
||||
if c.TenantID > 0 {
|
||||
mServiceSolutionCaseKind.TenantID = c.TenantID
|
||||
}
|
||||
return model2.Create(mServiceSolutionCaseKind.ServiceSolutionCaseKind)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user