feat:完善活动信息
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@ -7,4 +7,5 @@ SciencesServer
|
|||||||
*.test
|
*.test
|
||||||
*.prof
|
*.prof
|
||||||
upload/*
|
upload/*
|
||||||
log/*
|
log/*
|
||||||
|
cmd/ctl/ctl
|
98
app/api/enterprise/api/activity.go
Normal file
98
app/api/enterprise/api/activity.go
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/app/api/enterprise/controller/activity"
|
||||||
|
"SciencesServer/app/basic/api"
|
||||||
|
"SciencesServer/app/session"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Activity struct{}
|
||||||
|
|
||||||
|
func (*Activity) Applys(c *gin.Context) {
|
||||||
|
form := &struct {
|
||||||
|
Title string `json:"title" form:"title"`
|
||||||
|
api.PageForm
|
||||||
|
}{}
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := activity.NewApply()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||||
|
List(form.Title, form.Page, form.PageSize)
|
||||||
|
api.APIResponse(err, data)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Activity) ApplyLaunch(c *gin.Context) {
|
||||||
|
form := &struct {
|
||||||
|
Mode int `json:"mode" form:"mode" binding:"required"`
|
||||||
|
Title string `json:"title" form:"title" binding:"required"`
|
||||||
|
Content string `json:"content" form:"content"`
|
||||||
|
MaxNumber int `json:"max_number" form:"max_number"`
|
||||||
|
BeginAt string `json:"begin_at" form:"begin_at" binding:"required"`
|
||||||
|
FinishAt string `json:"finish_at" form:"finish_at" binding:"required"`
|
||||||
|
JoinDeadline string `json:"join_deadline" form:"join_deadline" binding:"required"`
|
||||||
|
api.PageForm
|
||||||
|
}{}
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := activity.NewApply()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||||
|
Launch(&activity.ApplyLaunchParams{
|
||||||
|
Mode: form.Mode, MaxNUmber: form.MaxNumber, Title: form.Title, Content: form.Content,
|
||||||
|
BeginAt: form.BeginAt, FinishAt: form.FinishAt, JoinDeadline: form.JoinDeadline,
|
||||||
|
})
|
||||||
|
api.APIResponse(err)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Activity) ApplyRevoke(c *gin.Context) {
|
||||||
|
form := new(api.IDStringForm)
|
||||||
|
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := activity.NewApply()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||||
|
Revoke(form.Convert())
|
||||||
|
api.APIResponse(err)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Activity) ApplyDelete(c *gin.Context) {
|
||||||
|
form := new(api.IDStringForm)
|
||||||
|
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := activity.NewApply()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||||
|
Delete(form.Convert())
|
||||||
|
api.APIResponse(err)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Activity) Joins(c *gin.Context) {
|
||||||
|
form := &struct {
|
||||||
|
Title string `json:"title" form:"title"`
|
||||||
|
Status int `json:"status" form:"status"` // 1:未开始,2:进行中,3:已结束
|
||||||
|
api.PageForm
|
||||||
|
}{}
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := activity.NewInstance()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||||
|
Joins(form.Title, form.Status, form.Page, form.PageSize)
|
||||||
|
api.APIResponse(err, data)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Activity) JoinDelete(c *gin.Context) {
|
||||||
|
form := new(api.IDStringForm)
|
||||||
|
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := activity.NewInstance()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||||
|
JoinDelete(form.Convert())
|
||||||
|
api.APIResponse(err)(c)
|
||||||
|
}
|
110
app/api/enterprise/controller/activity/apply.go
Normal file
110
app/api/enterprise/controller/activity/apply.go
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
package activity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/app/api/enterprise/model"
|
||||||
|
"SciencesServer/app/basic/controller"
|
||||||
|
model2 "SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/app/session"
|
||||||
|
"SciencesServer/utils"
|
||||||
|
"errors"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Apply struct {
|
||||||
|
*session.Enterprise
|
||||||
|
local string
|
||||||
|
}
|
||||||
|
|
||||||
|
type ApplyHandle func(session *session.Enterprise, local string) *Apply
|
||||||
|
|
||||||
|
type (
|
||||||
|
// ApplyLaunchParams 参数信息
|
||||||
|
ApplyLaunchParams struct {
|
||||||
|
Mode, MaxNUmber int
|
||||||
|
Title, Content string
|
||||||
|
BeginAt, FinishAt, JoinDeadline string
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// List 列表信息
|
||||||
|
func (c *Apply) List(title string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||||
|
mActivityApply := model.NewActivityApply()
|
||||||
|
|
||||||
|
out := make([]*model2.ActivityApply, 0)
|
||||||
|
|
||||||
|
where := []*model2.ModelWhereOrder{
|
||||||
|
&model2.ModelWhereOrder{
|
||||||
|
Where: model2.NewWhere("local", c.local),
|
||||||
|
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||||
|
},
|
||||||
|
&model2.ModelWhereOrder{
|
||||||
|
Where: model2.NewWhere("m_uid", c.UID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if title != "" {
|
||||||
|
where = append(where, &model2.ModelWhereOrder{
|
||||||
|
Where: model2.NewWhereLike("title", title),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
//if status > 0 {
|
||||||
|
// where = append(where, &model2.ModelWhereOrder{
|
||||||
|
// Where: model2.NewWhere("status", status),
|
||||||
|
// })
|
||||||
|
//}
|
||||||
|
var count int64
|
||||||
|
|
||||||
|
if err := model2.Pages(mActivityApply.ActivityApply, &out, page, pageSize, &count, where...); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &controller.ReturnPages{Data: out, Count: count}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Launch 发起操作
|
||||||
|
func (c *Apply) Launch(params *ApplyLaunchParams) error {
|
||||||
|
mActivityApply := model.NewActivityApply()
|
||||||
|
mActivityApply.Local.Local = c.local
|
||||||
|
mActivityApply.MUid = c.ManageUID
|
||||||
|
mActivityApply.Mode = model2.ActivityInstanceMode(params.Mode)
|
||||||
|
mActivityApply.Title = params.Title
|
||||||
|
mActivityApply.Content = params.Content
|
||||||
|
mActivityApply.MaxNumber = params.MaxNUmber
|
||||||
|
mActivityApply.BeginAt = utils.DateTimeToTime(params.BeginAt)
|
||||||
|
mActivityApply.FinishAt = utils.DateTimeToTime(params.FinishAt)
|
||||||
|
mActivityApply.JoinDeadline = utils.DateTimeToTime(params.JoinDeadline)
|
||||||
|
return model2.Create(mActivityApply.ActivityApply)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Revoke 撤销操作
|
||||||
|
func (c *Apply) Revoke(id uint64) error {
|
||||||
|
mActivityApply := model.NewActivityApply()
|
||||||
|
mActivityApply.ID = id
|
||||||
|
|
||||||
|
isExist, err := model2.FirstField(mActivityApply.ActivityApply, []string{"id", "status"})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if !isExist {
|
||||||
|
return errors.New("操作错误,活动信息不存在或已被删除")
|
||||||
|
} else if mActivityApply.Status != model2.ActivityApplyStatusForExamining {
|
||||||
|
return errors.New("操作错误,当前活动状态易发生变化,不可撤销")
|
||||||
|
}
|
||||||
|
return model2.Updates(mActivityApply.ActivityApply, map[string]interface{}{
|
||||||
|
"status": model2.ActivityApplyStatusForRevoke, "updated_at": time.Now(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete 删除操作
|
||||||
|
func (c *Apply) Delete(id uint64) error {
|
||||||
|
mActivityApply := model.NewActivityApply()
|
||||||
|
mActivityApply.ID = id
|
||||||
|
return model2.Delete(mActivityApply.ActivityApply)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewApply() ApplyHandle {
|
||||||
|
return func(session *session.Enterprise, local string) *Apply {
|
||||||
|
return &Apply{
|
||||||
|
Enterprise: session,
|
||||||
|
local: local,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
79
app/api/enterprise/controller/activity/instance.go
Normal file
79
app/api/enterprise/controller/activity/instance.go
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
package activity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/app/api/enterprise/model"
|
||||||
|
"SciencesServer/app/basic/controller"
|
||||||
|
model2 "SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/app/session"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Instance struct {
|
||||||
|
*session.Enterprise
|
||||||
|
local string
|
||||||
|
}
|
||||||
|
|
||||||
|
type InstanceHandle func(session *session.Enterprise, local string) *Instance
|
||||||
|
|
||||||
|
type InstanceForJoin struct {
|
||||||
|
*model.ActivityInstanceJoinInfo
|
||||||
|
ID string `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Joins 活动参加信息
|
||||||
|
func (c *Instance) Joins(title string, status, page, pageSize int) (*controller.ReturnPages, error) {
|
||||||
|
mActivityInstance := model.NewActivityInstance()
|
||||||
|
|
||||||
|
where := []*model2.ModelWhere{
|
||||||
|
model2.NewWhere("a.local", c.local),
|
||||||
|
model2.NewWhere("a.identity", c.Identity),
|
||||||
|
model2.NewWhere("j.m_uid", c.UID),
|
||||||
|
}
|
||||||
|
|
||||||
|
if title != "" {
|
||||||
|
where = append(where, model2.NewWhereLike("a.title", title))
|
||||||
|
}
|
||||||
|
if status > 0 {
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
if status == 1 { // 未开始
|
||||||
|
where = append(where, model2.NewWhereCondition("a.begin_at", ">", now))
|
||||||
|
} else if status == 2 { // 进行中
|
||||||
|
where = append(where, model2.NewWhereCondition("a.begin_at", "<=", now),
|
||||||
|
model2.NewWhereCondition("a.finish_at", ">=", now))
|
||||||
|
} else { // 已结束
|
||||||
|
where = append(where, model2.NewWhereCondition("a.finish_at", "<", now))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var count int64
|
||||||
|
|
||||||
|
out, err := mActivityInstance.Joins(page, pageSize, &count, where...)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
list := make([]*InstanceForJoin, 0)
|
||||||
|
|
||||||
|
for _, v := range out {
|
||||||
|
mActivityInstance.SetID(v.ID)
|
||||||
|
|
||||||
|
list = append(list, &InstanceForJoin{
|
||||||
|
ID: mActivityInstance.GetEncodeID(),
|
||||||
|
ActivityInstanceJoinInfo: v,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &controller.ReturnPages{Data: out, Count: count}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// JoinDelete 活动参加信息删除
|
||||||
|
func (c *Instance) JoinDelete(id uint64) error {
|
||||||
|
mActivityJoin := model.NewActivityJoin()
|
||||||
|
mActivityJoin.ID = id
|
||||||
|
return model2.Delete(mActivityJoin.ActivityJoin)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewInstance() InstanceHandle {
|
||||||
|
return func(session *session.Enterprise, local string) *Instance {
|
||||||
|
return &Instance{Enterprise: session, local: local}
|
||||||
|
}
|
||||||
|
}
|
11
app/api/enterprise/model/activity_apply.go
Normal file
11
app/api/enterprise/model/activity_apply.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "SciencesServer/app/common/model"
|
||||||
|
|
||||||
|
type ActivityApply struct {
|
||||||
|
*model.ActivityApply
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewActivityApply() *ActivityApply {
|
||||||
|
return &ActivityApply{model.NewActivityApply()}
|
||||||
|
}
|
47
app/api/enterprise/model/activity_instance.go
Normal file
47
app/api/enterprise/model/activity_instance.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/serve/orm"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ActivityInstance struct {
|
||||||
|
*model.ActivityInstance
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActivityInstanceJoinInfo 活动报名信息
|
||||||
|
type ActivityInstanceJoinInfo struct {
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
*model.ActivityInstanceBasic
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Joins 活动参加信息
|
||||||
|
func (m *ActivityInstance) Joins(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ActivityInstanceJoinInfo, error) {
|
||||||
|
db := orm.GetDB().Table(model.NewActivityJoin().TableName()+" AS j").
|
||||||
|
Select("j.id", "a.title", "a.begin_at", "a.finish_at", "a.join_deadline", "j.created_at").
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS a ON j.activity_id = a.id", m.TableName())).
|
||||||
|
Where("j.is_deleted = ?", model.DeleteStatusForNot).
|
||||||
|
Where("j.status = ?", model.ActivityJoinStatusForSuccess)
|
||||||
|
|
||||||
|
if len(where) > 0 {
|
||||||
|
for _, v := range where {
|
||||||
|
db = db.Where(v.Condition, v.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out := make([]*ActivityInstanceJoinInfo, 0)
|
||||||
|
|
||||||
|
if err := db.Count(count).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := db.Order("j.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewActivityInstance() *ActivityInstance {
|
||||||
|
return &ActivityInstance{model.NewActivityInstance()}
|
||||||
|
}
|
13
app/api/enterprise/model/activity_join.go
Normal file
13
app/api/enterprise/model/activity_join.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/app/common/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ActivityJoin struct {
|
||||||
|
*model.ActivityJoin
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewActivityJoin() *ActivityJoin {
|
||||||
|
return &ActivityJoin{model.NewActivityJoin()}
|
||||||
|
}
|
@ -157,6 +157,7 @@ func (c *Examine) Launch(id uint64, identity, status int) error {
|
|||||||
}
|
}
|
||||||
if !isExist {
|
if !isExist {
|
||||||
mUserManage.TenantID = data.TenantID
|
mUserManage.TenantID = data.TenantID
|
||||||
|
mUserManage.ManageID = data.IModel.GetID()
|
||||||
mUserManage.UID = data.UID
|
mUserManage.UID = data.UID
|
||||||
mUserManage.Identity = identity
|
mUserManage.Identity = identity
|
||||||
mUserManage.IdentityInfo = utils.AnyToJSON(data.IdentityInfo)
|
mUserManage.IdentityInfo = utils.AnyToJSON(data.IdentityInfo)
|
||||||
|
7
app/basic/controller/basic.go
Normal file
7
app/basic/controller/basic.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
// ReturnPages 分页数据
|
||||||
|
type ReturnPages struct {
|
||||||
|
Data interface{} `json:"data"`
|
||||||
|
Count int64 `json:"count"`
|
||||||
|
}
|
@ -11,8 +11,9 @@ import (
|
|||||||
type UserManage struct {
|
type UserManage struct {
|
||||||
Model
|
Model
|
||||||
ModelTenant
|
ModelTenant
|
||||||
UID uint64 `gorm:"column:uid;index:idx_user_manage_uid;type:int;default:0;comment:用户表UUID" json:"-"`
|
|
||||||
UUID uint64 `gorm:"column:uuid;uniqueIndex:idx_user_manage_uuid;type:int;default:0;comment:用户唯一UUID" json:"-"`
|
UUID uint64 `gorm:"column:uuid;uniqueIndex:idx_user_manage_uuid;type:int;default:0;comment:用户唯一UUID" json:"-"`
|
||||||
|
ManageID uint64 `gorm:"column:manage_id;type:int(11);default:0;comment:信息管理ID,根据所在身份,对应不同数据表" json:"-"`
|
||||||
|
UID uint64 `gorm:"column:uid;index:idx_user_manage_uid;type:int;default:0;comment:用户表UUID" json:"-"`
|
||||||
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
|
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
|
||||||
Email string `gorm:"column:email;type:varchar(50);default:null;comment:邮箱" json:"email"`
|
Email string `gorm:"column:email;type:varchar(50);default:null;comment:邮箱" json:"email"`
|
||||||
Job string `gorm:"column:job;type:varchar(50);default:null;comment:职务" json:"job"`
|
Job string `gorm:"column:job;type:varchar(50);default:null;comment:职务" json:"job"`
|
||||||
|
73
cmd/ctl/command/controller/file.go
Normal file
73
cmd/ctl/command/controller/file.go
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/utils"
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"go/format"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
const ControllerTemplate = `package {{.Name}}
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ArmedPolice/app/controller/basic"
|
||||||
|
"ArmedPolice/app/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
type {{.StrutName}} struct{ *service.Session }
|
||||||
|
|
||||||
|
type {{.StrutName}}Handle func(session *service.Session) *{{.StrutName}}
|
||||||
|
|
||||||
|
func (c *{{.StrutName}}) List() (*basic.PageDataResponse, error) {
|
||||||
|
return &basic.PageDataResponse{Data: nil, Count: 0}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *{{.StrutName}}) Form() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *{{.StrutName}}) Delete(id uint64) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func New{{.StrutName}}() {{.StrutName}}Handle {
|
||||||
|
return func(session *service.Session) *{{.StrutName}} {
|
||||||
|
return &{{.StrutName}}{session}
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
|
||||||
|
type ControllerFile struct {
|
||||||
|
// Name is the plugin name. Snack style.
|
||||||
|
Name string
|
||||||
|
// StrutName is the struct name.
|
||||||
|
StrutName string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *ControllerFile) Execute(file, tmplName, tmpl string) error {
|
||||||
|
fmt.Println(file)
|
||||||
|
f, err := utils.Open(file)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
temp := new(template.Template)
|
||||||
|
|
||||||
|
if temp, err = template.New(tmplName).Parse(tmpl); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
|
||||||
|
if err = temp.Execute(buf, v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out := make([]byte, 0)
|
||||||
|
|
||||||
|
if out, err = format.Source(buf.Bytes()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = f.Write(out)
|
||||||
|
return err
|
||||||
|
}
|
75
cmd/ctl/command/controller/model.go
Normal file
75
cmd/ctl/command/controller/model.go
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/config"
|
||||||
|
"SciencesServer/serve/logger"
|
||||||
|
"SciencesServer/utils"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ControllerCommand = &cobra.Command{
|
||||||
|
Use: "make:controller",
|
||||||
|
Short: "quick make controller",
|
||||||
|
Example: "ctl make:controller -f sys_user -t sys_user",
|
||||||
|
Version: *config.Version,
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
file string
|
||||||
|
address string
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
ControllerCommand.Flags().StringVarP(&file, "file", "f", "", "The file name.")
|
||||||
|
ControllerCommand.Flags().StringVarP(&address, "address", "a", "", "The file controller address")
|
||||||
|
ControllerCommand.Run = func(cmd *cobra.Command, args []string) {
|
||||||
|
utils.TryCatch(func() {
|
||||||
|
if file == "" {
|
||||||
|
logger.ErrorF("Filename Not Nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
output := "../../app/controller"
|
||||||
|
|
||||||
|
if address == "" {
|
||||||
|
logger.ErrorF("Address Not Nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 解析文件地址
|
||||||
|
address = strings.Replace(address, "/", "", -1)
|
||||||
|
addresss := strings.Split(address, "/")
|
||||||
|
|
||||||
|
file := strings.ToLower(file)
|
||||||
|
|
||||||
|
dir, err := os.Getwd()
|
||||||
|
|
||||||
|
output = path.Join(dir, output+"/"+address)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logger.ErrorF("Make Controller Error:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = utils.PrepareOutput(output); err != nil {
|
||||||
|
logger.ErrorF("Make Controller Error:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println(output)
|
||||||
|
|
||||||
|
modelFile := &ControllerFile{
|
||||||
|
Name: addresss[len(addresss)-1],
|
||||||
|
StrutName: utils.ToSnake(file, "_"),
|
||||||
|
}
|
||||||
|
err = modelFile.Execute(path.Join(output, file+".go"), "controller", ControllerTemplate)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logger.ErrorF("Make Controller Error:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -42,7 +42,7 @@ func init() {
|
|||||||
|
|
||||||
dir, err := os.Getwd()
|
dir, err := os.Getwd()
|
||||||
|
|
||||||
output := "/app/common/model"
|
output := "../../app/common/model"
|
||||||
|
|
||||||
output = path.Join(dir, output)
|
output = path.Join(dir, output)
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"SciencesServer/cmd/ctl/command/controller"
|
||||||
"SciencesServer/cmd/ctl/command/model"
|
"SciencesServer/cmd/ctl/command/model"
|
||||||
"SciencesServer/config"
|
"SciencesServer/config"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,6 +14,7 @@ var rootCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
rootCmd.AddCommand(controller.ControllerCommand)
|
||||||
rootCmd.AddCommand(model.ModelCommand)
|
rootCmd.AddCommand(model.ModelCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,45 +126,69 @@ func registerManageAPI(app *gin.Engine) {
|
|||||||
func registerEnterpriseAPI(app *gin.Engine) {
|
func registerEnterpriseAPI(app *gin.Engine) {
|
||||||
apiPrefix := "/enterprise"
|
apiPrefix := "/enterprise"
|
||||||
g := app.Group(apiPrefix)
|
g := app.Group(apiPrefix)
|
||||||
|
|
||||||
|
g.Use(NeedLogin(session.NewManage(), AddSkipperURL([]string{}...)))
|
||||||
|
|
||||||
|
v1 := g.Group("/v1")
|
||||||
|
|
||||||
// Upload 上传管理
|
// Upload 上传管理
|
||||||
g.POST("/upload", new(api3.Upload).Upload)
|
v1.POST("/upload", new(api3.Upload).Upload)
|
||||||
// Config 配置管理
|
// Config 配置管理
|
||||||
config := g.Group("/config")
|
configV1 := v1.Group("/config")
|
||||||
{
|
{
|
||||||
_api := new(api2.Config)
|
_api := new(api2.Config)
|
||||||
config.GET("/area", _api.Area)
|
configV1.GET("/area", _api.Area)
|
||||||
|
}
|
||||||
|
// Account 账号管理
|
||||||
|
accountV1 := v1.Group("/account")
|
||||||
|
{
|
||||||
|
_api := new(api2.Account)
|
||||||
|
accountV1.POST("/login", _api.Login)
|
||||||
|
accountV1.POST("/register", _api.Register)
|
||||||
|
accountV1.POST("/authorize", _api.Authorize)
|
||||||
|
accountV1.POST("/logout", _api.Logout)
|
||||||
}
|
}
|
||||||
// Technology 技术管理
|
// Technology 技术管理
|
||||||
technology := g.Group("/technology")
|
technologyV1 := g.Group("/technology")
|
||||||
{
|
{
|
||||||
_api := new(api2.Technology)
|
_api := new(api2.Technology)
|
||||||
technology.POST("/paper", _api.Paper)
|
technologyV1.POST("/paper", _api.Paper)
|
||||||
technology.POST("/paper/add", _api.PaperAdd)
|
technologyV1.POST("/paper/add", _api.PaperAdd)
|
||||||
technology.POST("/paper/edit", _api.PaperEdit)
|
technologyV1.POST("/paper/edit", _api.PaperEdit)
|
||||||
technology.POST("/paper/delete", _api.PaperDelete)
|
technologyV1.POST("/paper/delete", _api.PaperDelete)
|
||||||
technology.POST("/patent", _api.Patent)
|
technologyV1.POST("/patent", _api.Patent)
|
||||||
technology.POST("/patent/detail", _api.PatentDetail)
|
technologyV1.POST("/patent/detail", _api.PatentDetail)
|
||||||
technology.POST("/patent/add", _api.PatentAdd)
|
technologyV1.POST("/patent/add", _api.PatentAdd)
|
||||||
technology.POST("/patent/edit", _api.PatentEdit)
|
technologyV1.POST("/patent/edit", _api.PatentEdit)
|
||||||
technology.POST("/patent/delete", _api.PatentDelete)
|
technologyV1.POST("/patent/delete", _api.PatentDelete)
|
||||||
technology.POST("/demand", _api.Demand)
|
technologyV1.POST("/demand", _api.Demand)
|
||||||
technology.POST("/demand/detail", _api.DemandDetail)
|
technologyV1.POST("/demand/detail", _api.DemandDetail)
|
||||||
technology.POST("/demand/add", _api.DemandAdd)
|
technologyV1.POST("/demand/add", _api.DemandAdd)
|
||||||
technology.POST("/demand/edit", _api.DemandEdit)
|
technologyV1.POST("/demand/edit", _api.DemandEdit)
|
||||||
technology.POST("/demand/delete", _api.DemandDelete)
|
technologyV1.POST("/demand/delete", _api.DemandDelete)
|
||||||
technology.POST("/topic", _api.Topic)
|
technologyV1.POST("/topic", _api.Topic)
|
||||||
technology.POST("/topic/add", _api.TopicAdd)
|
technologyV1.POST("/topic/add", _api.TopicAdd)
|
||||||
technology.POST("/topic/edit", _api.TopicEdit)
|
technologyV1.POST("/topic/edit", _api.TopicEdit)
|
||||||
technology.POST("/topic/delete", _api.TopicDelete)
|
technologyV1.POST("/topic/delete", _api.TopicDelete)
|
||||||
technology.POST("/equipment", _api.Equipment)
|
technologyV1.POST("/equipment", _api.Equipment)
|
||||||
technology.POST("/equipment/add", _api.EquipmentAdd)
|
technologyV1.POST("/equipment/add", _api.EquipmentAdd)
|
||||||
technology.POST("/equipment/edit", _api.EquipmentEdit)
|
technologyV1.POST("/equipment/edit", _api.EquipmentEdit)
|
||||||
technology.POST("/equipment/delete", _api.EquipmentDelete)
|
technologyV1.POST("/equipment/delete", _api.EquipmentDelete)
|
||||||
}
|
}
|
||||||
// Identity 身份信息
|
// Identity 身份信息
|
||||||
identity := g.Group("/config")
|
identityV1 := v1.Group("/config")
|
||||||
{
|
{
|
||||||
_api := new(api2.Identity)
|
_api := new(api2.Identity)
|
||||||
identity.POST("/expert", _api.Expert)
|
identityV1.POST("/expert", _api.Expert)
|
||||||
|
}
|
||||||
|
// Activity 活动信息
|
||||||
|
activityV1 := v1.Group("/activity")
|
||||||
|
{
|
||||||
|
_api := new(api2.Activity)
|
||||||
|
activityV1.POST("/apply", _api.Applys)
|
||||||
|
activityV1.POST("/apply/revoke", _api.ApplyRevoke)
|
||||||
|
activityV1.POST("/apply/delete", _api.ApplyDelete)
|
||||||
|
activityV1.POST("/joins", _api.Joins)
|
||||||
|
activityV1.POST("/join/delete", _api.JoinDelete)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ func HashCompare(src, compare []byte) bool {
|
|||||||
func HASHIDEncode(src int) string {
|
func HASHIDEncode(src int) string {
|
||||||
hd := hashids.NewData()
|
hd := hashids.NewData()
|
||||||
hd.Salt = salt
|
hd.Salt = salt
|
||||||
hd.MinLength = 6
|
hd.MinLength = 8
|
||||||
h := hashids.NewWithData(hd)
|
h := hashids.NewWithData(hd)
|
||||||
e, _ := h.Encode([]int{src})
|
e, _ := h.Encode([]int{src})
|
||||||
return e
|
return e
|
||||||
|
Reference in New Issue
Block a user