feat:完善项目信息
This commit is contained in:
56
app/api/admin/api/sys.go
Normal file
56
app/api/admin/api/sys.go
Normal file
@ -0,0 +1,56 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller/sys"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/session"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Sys struct{}
|
||||
|
||||
func (*Sys) Navigation(c *gin.Context) {
|
||||
form := new(api.TenantIDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := sys.NewNavigation()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Sys) NavigationForm(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
api.TenantIDStringForm
|
||||
ParentID string `json:"parent_id" form:"parent_id"`
|
||||
Title string `json:"title" form:"title"`
|
||||
Link string `json:"link" form:"link"`
|
||||
IsTarget int `json:"is_target" form:"is_target"`
|
||||
Sort int `json:"sort" form:"sort"`
|
||||
Status int `json:"status" form:"status"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := sys.NewNavigation()(api.GetSession()(c).(*session.Admin)).Form(&sys.NavigationParams{
|
||||
ID: form.IDStringForm.Convert(),
|
||||
TenantID: form.TenantIDStringForm.Convert(),
|
||||
PatentID: (&api.IDStringForm{ID: form.ParentID}).Convert(),
|
||||
Title: form.Title, Link: form.Link, IsTarget: form.IsTarget, Sort: form.Sort, Status: form.Status,
|
||||
})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Sys) NavigationDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := sys.NewNavigation()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
@ -6,7 +6,6 @@ import (
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
@ -189,11 +188,8 @@ func (c *Examine) Launch(id uint64, identity, status int) error {
|
||||
|
||||
now := time.Now()
|
||||
|
||||
snowflake, _ := utils.NewSnowflake(1)
|
||||
|
||||
for _, v := range users {
|
||||
identitys = append(identitys, &model2.UserIdentity{
|
||||
UUID: uint64(snowflake.GetID()),
|
||||
UID: v.UUID,
|
||||
Identity: identity,
|
||||
ModelAt: model2.ModelAt{
|
||||
|
130
app/api/admin/controller/sys/navigation.go
Normal file
130
app/api/admin/controller/sys/navigation.go
Normal file
@ -0,0 +1,130 @@
|
||||
package sys
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Navigation struct {
|
||||
*session.Admin
|
||||
}
|
||||
|
||||
type NavigationHandle func(session *session.Admin) *Navigation
|
||||
|
||||
type (
|
||||
// NavigationInfo 导航信息
|
||||
NavigationInfo struct {
|
||||
ID string `json:"id"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
ParentID string `json:"parent_id"`
|
||||
*model2.SysNavigation
|
||||
Children []*NavigationInfo `json:"children"`
|
||||
}
|
||||
// NavigationParams 导航参数信息
|
||||
NavigationParams struct {
|
||||
ID, TenantID, PatentID uint64
|
||||
Title, Link string
|
||||
IsTarget, Sort, Status int
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Navigation) tree(src []*model.SysNavigationInfo, parentID uint64) []*NavigationInfo {
|
||||
out := make([]*NavigationInfo, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &NavigationInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
TenantID: v.GetEncodeTenantID(),
|
||||
ParentID: (&model2.Model{ID: parentID}).GetEncodeID(),
|
||||
SysNavigation: v.SysNavigation,
|
||||
Children: c.tree(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *Navigation) Instance(TenantID uint64) ([]*NavigationInfo, error) {
|
||||
mSysNavigation := model.NewSysNavigation()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if c.TenantID > 0 {
|
||||
where = append(where, model2.NewWhere("n.tenant_id", c.TenantID))
|
||||
}
|
||||
if TenantID > 0 {
|
||||
where = append(where, model2.NewWhere("n.tenant_id", TenantID))
|
||||
}
|
||||
|
||||
out, err := mSysNavigation.Navigation(where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.tree(out, 0), nil
|
||||
}
|
||||
|
||||
// Form 数据操作
|
||||
func (c *Navigation) Form(params *NavigationParams) error {
|
||||
mSysNavigation := model.NewSysNavigation()
|
||||
|
||||
if params.ID > 0 {
|
||||
mSysNavigation.ID = params.ID
|
||||
|
||||
if isExist, err := model2.First(mSysNavigation.SysNavigation); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,导航信息不存在或已被删除")
|
||||
}
|
||||
if c.TenantID > 0 && mSysNavigation.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
}
|
||||
mSysNavigation.ParentID = params.PatentID
|
||||
mSysNavigation.Title = params.Title
|
||||
mSysNavigation.Link = params.Link
|
||||
mSysNavigation.IsTarget = params.IsTarget
|
||||
mSysNavigation.Sort = params.Sort
|
||||
mSysNavigation.Status = model2.SysNavigationStatus(params.Status)
|
||||
|
||||
if mSysNavigation.ID > 0 {
|
||||
if c.TenantID <= 0 {
|
||||
mSysNavigation.TenantID = params.TenantID
|
||||
}
|
||||
return model2.Updates(mSysNavigation.SysNavigation, mSysNavigation.SysNavigation)
|
||||
}
|
||||
mSysNavigation.TenantID = params.TenantID
|
||||
|
||||
if c.TenantID > 0 {
|
||||
mSysNavigation.TenantID = c.TenantID
|
||||
}
|
||||
return model2.Create(mSysNavigation.SysNavigation)
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Navigation) Delete(id uint64) error {
|
||||
mSysNavigation := model.NewSysNavigation()
|
||||
mSysNavigation.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysNavigation.SysNavigation, []string{"id", "tenant_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,导航信息不存在或已被删除")
|
||||
}
|
||||
if c.TenantID > 0 && mSysNavigation.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
return model2.Delete(mSysNavigation.SysNavigation)
|
||||
}
|
||||
|
||||
func NewNavigation() NavigationHandle {
|
||||
return func(session *session.Admin) *Navigation {
|
||||
return &Navigation{session}
|
||||
}
|
||||
}
|
@ -26,11 +26,11 @@ type (
|
||||
// Apply 申请信息
|
||||
func (m *ActivityApply) Apply(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ActivityApplyInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS a").
|
||||
Select("a.id", "a.tenant_id", "a.image", "a.title", "a.contact", "a.contact_mobile", "a.begin_at",
|
||||
Select("a.id", "a.tenant_id", "a.identity", "a.image", "a.title", "a.contact", "a.contact_mobile", "a.begin_at",
|
||||
"a.finish_at", "a.amount", "a.max_number", "a.status", "a.created_at",
|
||||
"t.province", "t.city", "l.name AS handle_name", "l.remark AS handle_remark", "l.created_at AS handle_created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON a.uid = u.uuid", model.NewUserInstance().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON i.tenant_id = t.id", model.NewSysTenant().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON a.tenant_id = t.id", model.NewSysTenant().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT a.apply_id, MAX(a.id) AS id, MAX(a.created_at) AS created_at, MAX(a.remark) AS remark "+
|
||||
"MAX(u.`name`) AS name FROM %s AS a LEFT JOIN %s ON a.uid = u.uuid WHERE a.is_deleted = %d GROUP BY a.apply_id) AS l ON a.id = l.apply_id",
|
||||
model.NewActivityApplyLog().TableName(), model.NewSysUser().TableName(), model.DeleteStatusForNot)).
|
||||
|
@ -22,9 +22,9 @@ func (m *ActivityInstance) Activity(page, pageSize int, count *int64, where ...*
|
||||
Select("a.id", "a.tenant_id", "a.image", "a.title", "a.contact", "a.contact_mobile", "a.begin_at",
|
||||
"a.finish_at", "a.join_deadline", "a.amount", "a.max_number", "a.status", "a.created_at", "j.count AS join_count",
|
||||
"t.province", "t.city").
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT activity_id, COUNT(id) AS count FROM %s WHERE is_delete = %d AND status = %d GROUP BY activity_id) AS j ON a.id = j.activity_id",
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT activity_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d AND status = %d GROUP BY activity_id) AS j ON a.id = j.activity_id",
|
||||
model.NewActivityJoin().TableName(), model.DeleteStatusForNot, model.ActivityJoinStatusForSuccess)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON i.tenant_id = t.id", model.NewSysTenant().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON a.tenant_id = t.id", model.NewSysTenant().TableName())).
|
||||
Where("a.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
|
@ -13,13 +13,16 @@ type ActivityJoin struct {
|
||||
|
||||
type ActivityJoinInfo struct {
|
||||
model.Model
|
||||
Identity int `json:"identity"`
|
||||
Name string `json:"name"`
|
||||
Mobile string `json:"mobile"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (m *ActivityJoin) Join(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ActivityJoinInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS j").
|
||||
Select("j.id", "u.name", "j.created_at").
|
||||
Select("j.id", "j.identity", "u_i.name", "u.mobile", "j.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u_i ON j.uid = u_i.uuid AND j.identity = u_i.identity", model.NewUserIdentity().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON j.uid = u.uuid", model.NewUserInstance().TableName())).
|
||||
Where("j.is_deleted = ?", model.DeleteStatusForNot).
|
||||
Where("j.status = ?", model.ActivityJoinStatusForSuccess)
|
||||
|
40
app/api/admin/model/sys_navigation.go
Normal file
40
app/api/admin/model/sys_navigation.go
Normal file
@ -0,0 +1,40 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SysNavigation struct {
|
||||
*model.SysNavigation
|
||||
}
|
||||
|
||||
type SysNavigationInfo struct {
|
||||
*model.SysNavigation
|
||||
model.Area
|
||||
}
|
||||
|
||||
func (m *SysNavigation) Navigation(where ...*model.ModelWhere) ([]*SysNavigationInfo, error) {
|
||||
out := make([]*SysNavigationInfo, 0)
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS n").
|
||||
Select("n.*", "t.province", "t.city").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON n.tenant_id = t.id", model.NewSysTenant().TableName())).
|
||||
Where("n.is_deleted = ?", model.DeleteStatusForNot).
|
||||
Order("n.sort " + model.OrderModeToAsc).Order("n.parent_id " + model.OrderModeToAsc).
|
||||
Order("n.id " + model.OrderModeToDesc)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
err := db.Scan(&out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
func NewSysNavigation() *SysNavigation {
|
||||
return &SysNavigation{model.NewSysNavigation()}
|
||||
}
|
Reference in New Issue
Block a user