feat:完善项目
This commit is contained in:
@ -184,24 +184,18 @@ func (c *Examine) Launch(id uint64, identity, status int) error {
|
||||
users := make([]*model2.UserInstance, 0)
|
||||
|
||||
if err = model2.ScanFields(mUserInstance.UserInstance, &users, []string{"id", "uuid", "identity"},
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereIn("uuid", data.UIDs),
|
||||
}); err != nil {
|
||||
&model2.ModelWhereOrder{Where: model2.NewWhereIn("uuid", data.UIDs)}); err != nil {
|
||||
return err
|
||||
}
|
||||
mUserIdentity := model.NewUserIdentity()
|
||||
|
||||
identitys := make([]*model2.UserIdentity, 0)
|
||||
userIdentitys := make([]*model2.UserIdentity, 0)
|
||||
|
||||
now := time.Now()
|
||||
|
||||
for _, v := range users {
|
||||
identitys = append(identitys, &model2.UserIdentity{
|
||||
userIdentitys = append(userIdentitys, &model2.UserIdentity{
|
||||
UID: v.UUID,
|
||||
Identity: identity,
|
||||
ModelAt: model2.ModelAt{
|
||||
CreatedAt: now, UpdatedAt: now,
|
||||
},
|
||||
ModelAt: model2.ModelAt{CreatedAt: now, UpdatedAt: now},
|
||||
})
|
||||
if err = model2.UpdatesWhere(mUserInstance.UserInstance, map[string]interface{}{
|
||||
"identity": mUserInstance.Identity | identity, "updated_at": now,
|
||||
@ -211,8 +205,8 @@ func (c *Examine) Launch(id uint64, identity, status int) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(identitys) > 0 {
|
||||
if err = model2.Creates(mUserIdentity.UserIdentity, identity, tx); err != nil {
|
||||
if len(userIdentitys) > 0 {
|
||||
if err = model2.Creates(model.NewUserIdentity().UserIdentity, userIdentitys, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -11,14 +11,13 @@ type Activity struct{}
|
||||
func (*Activity) Instance(c *gin.Context) {
|
||||
form := &struct {
|
||||
Title string `json:"title" form:"title"`
|
||||
Mode int `json:"mode" form:"mode"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewActivity()(getSession(c), api.GetTenantID()(c).(uint64)).Instance(form.Title, form.Mode, form.Page, form.PageSize)
|
||||
data, err := controller.NewActivity()(getSession(c), api.GetTenantID()(c).(uint64)).Instance(form.Title, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
|
@ -10,12 +10,13 @@ type Config struct{}
|
||||
|
||||
func (*Config) Index(c *gin.Context) {
|
||||
form := &struct {
|
||||
Kind int `json:"kind" form:"kind" binding:"required"`
|
||||
Kind int `json:"kind" form:"kind"`
|
||||
Key string `json:"key" form:"key" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewConfig()(nil).Instance(form.Kind)
|
||||
data, err := controller.NewConfig()(nil).Instance(form.Kind, form.Key)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
@ -3,13 +3,22 @@ package api
|
||||
import (
|
||||
"SciencesServer/app/api/website/controller/service"
|
||||
"SciencesServer/app/basic/api"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Service struct{}
|
||||
|
||||
func (*Service) SolutionCase(c *gin.Context) {
|
||||
data, err := service.NewSolutionCase()(getSession(c), api.GetTenantID()(c).(uint64)).Instance()
|
||||
form := &struct {
|
||||
Mode int `json:"mode" form:"mode"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
fmt.Println(form.Mode)
|
||||
data, err := service.NewSolutionCase()(getSession(c), api.GetTenantID()(c).(uint64)).Instance(form.Mode)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/controller"
|
||||
"SciencesServer/app/api/website/controller/sys"
|
||||
"SciencesServer/app/basic/api"
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -10,7 +9,7 @@ import (
|
||||
type Sys struct{}
|
||||
|
||||
func (*Sys) Platform(c *gin.Context) {
|
||||
data, err := controller.NewPlatform()().Instance()
|
||||
data, err := sys.NewPlatform()().Instance()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
@ -19,6 +18,18 @@ func (*Sys) Navigation(c *gin.Context) {
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Sys) Banner(c *gin.Context) {
|
||||
form := &struct {
|
||||
Key string `json:"key" form:"key" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := sys.NewBanner()(api.GetTenantID()(c).(uint64)).Instance(form.Key)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Sys) About(c *gin.Context) {
|
||||
form := &struct {
|
||||
NavigationID string `json:"navigation_id" form:"navigation_id"`
|
||||
|
@ -33,7 +33,7 @@ type (
|
||||
)
|
||||
|
||||
// Instance 活动信息
|
||||
func (c *Activity) Instance(title string, mode, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
func (c *Activity) Instance(title string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mActivityInstance := model.NewActivityInstance()
|
||||
|
||||
var count int64
|
||||
@ -43,10 +43,8 @@ func (c *Activity) Instance(title string, mode, page, pageSize int) (*controller
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("a.title", title))
|
||||
}
|
||||
if mode > 0 {
|
||||
where = append(where, model2.NewWhere("a.mode", mode))
|
||||
}
|
||||
out, err := mActivityInstance.Activity(c.UID, c.SelectIdentity, page, pageSize, &count)
|
||||
|
||||
out, err := mActivityInstance.Activity(c.UID, c.SelectIdentity, page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -71,6 +69,8 @@ func (c *Activity) Detail(id uint64) (*ActivityDetail, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mActivityInstance.Image.Image = mActivityInstance.Image.Analysis(config.SettingInfo.Domain)
|
||||
|
||||
return &ActivityDetail{
|
||||
ID: out.GetEncodeID(),
|
||||
ActivityInstanceDetail: out,
|
||||
@ -82,7 +82,7 @@ func (c *Activity) Detail(id uint64) (*ActivityDetail, error) {
|
||||
func (c *Activity) Join(id uint64) error {
|
||||
mActivityInstance := model.NewActivityInstance()
|
||||
|
||||
isExist, err := model2.FirstField(mActivityInstance.ActivityInstance, []string{"id", "mode", "join_deadline"},
|
||||
isExist, err := model2.FirstField(mActivityInstance.ActivityInstance, []string{"id", "amount", "join_deadline"},
|
||||
model2.NewWhere("id", id), model2.NewWhere("tenant_id", c.tenantID),
|
||||
model2.NewWhere("status", model2.ActivityInstanceStatusForShow))
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Config struct{ *session.Enterprise }
|
||||
@ -11,24 +12,29 @@ type Config struct{ *session.Enterprise }
|
||||
type ConfigHandle func(session *session.Enterprise) *Config
|
||||
|
||||
type (
|
||||
// ConfigInfo 配置信息
|
||||
ConfigInfo struct {
|
||||
Kind int `json:"kind"`
|
||||
Name string `json:"name"`
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Config) Instance(kind int) ([]*ConfigInfo, error) {
|
||||
func (c *Config) Instance(kind int, key string) (*ConfigInfo, error) {
|
||||
mSysConfig := model.NewSysConfig()
|
||||
|
||||
out := make([]*ConfigInfo, 0)
|
||||
where := []*model2.ModelWhere{model2.NewWhere("`key`", key)}
|
||||
|
||||
if err := model2.ScanFields(mSysConfig.SysConfig, &out, []string{"kind", "name", "`key`", "`value`"},
|
||||
&model2.ModelWhereOrder{Where: model2.NewWhere("kind", kind)}); err != nil {
|
||||
return nil, err
|
||||
if kind > 0 {
|
||||
where = append(where, model2.NewWhere("kind", kind))
|
||||
}
|
||||
return out, nil
|
||||
isExist, err := model2.FirstField(mSysConfig.SysConfig, []string{"id", "name", "`value`"}, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,数据不存在或已被删除")
|
||||
}
|
||||
return &ConfigInfo{Name: mSysConfig.Name, Value: mSysConfig.Value}, nil
|
||||
}
|
||||
|
||||
func NewConfig() ConfigHandle {
|
||||
|
@ -309,43 +309,7 @@ func (c *Index) DistributionCompany(province, city string) (map[string]*Instance
|
||||
}
|
||||
_out := c.distribution(out)
|
||||
c.filter(_out)
|
||||
_out["230000"] = &InstanceDistributionDetailInfo{
|
||||
Code: "230000",
|
||||
Name: "黑龙江",
|
||||
Count: 6000,
|
||||
Industry: nil,
|
||||
Children: map[string]*InstanceDistributionDetailInfo{
|
||||
"230100": &InstanceDistributionDetailInfo{
|
||||
Code: "230100",
|
||||
Name: "哈尔滨市",
|
||||
Count: 3000,
|
||||
Industry: nil,
|
||||
Children: nil,
|
||||
},
|
||||
"230200": &InstanceDistributionDetailInfo{
|
||||
Code: "230200",
|
||||
Name: "齐齐哈尔市",
|
||||
Count: 3000,
|
||||
Industry: nil,
|
||||
Children: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
_out["330000"] = &InstanceDistributionDetailInfo{
|
||||
Code: "330000",
|
||||
Name: "浙江省",
|
||||
Count: 5000,
|
||||
Industry: nil,
|
||||
Children: map[string]*InstanceDistributionDetailInfo{
|
||||
"330100": &InstanceDistributionDetailInfo{
|
||||
Code: "330100",
|
||||
Name: "杭州市",
|
||||
Count: 5000,
|
||||
Industry: nil,
|
||||
Children: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return _out, nil
|
||||
}
|
||||
|
||||
|
@ -22,12 +22,13 @@ type SolutionCaseHandle func(session *session.Enterprise, tenantID uint64) *Solu
|
||||
type (
|
||||
// SolutionCaseInfo 基本信息
|
||||
SolutionCaseInfo struct {
|
||||
ID string `json:"id"`
|
||||
MarkID uint64 `json:"-"`
|
||||
Mode model2.ServiceSolutionCaseMode `json:"mode"`
|
||||
Title string `json:"title"`
|
||||
Image string `json:"image"`
|
||||
Children []*SolutionCaseBasic `json:"children"`
|
||||
ID string `json:"id"`
|
||||
MarkID uint64 `json:"-"`
|
||||
Mode model2.ServiceSolutionCaseMode `json:"mode"`
|
||||
Title string `json:"title"`
|
||||
Image string `json:"image"`
|
||||
Description string `json:"description"`
|
||||
Children []*SolutionCaseBasic `json:"children"`
|
||||
}
|
||||
// SolutionCaseBasic 基本信息
|
||||
SolutionCaseBasic struct {
|
||||
@ -46,9 +47,12 @@ type (
|
||||
)
|
||||
|
||||
// Instance 服务解决方案案例
|
||||
func (c *SolutionCase) Instance() ([]*SolutionCaseInfo, error) {
|
||||
func (c *SolutionCase) Instance(mode int) ([]*SolutionCaseInfo, error) {
|
||||
mServiceSolutionCase := model.NewServiceSolutionCase()
|
||||
out, err := mServiceSolutionCase.SolutionCase(6)
|
||||
|
||||
where := []*model2.ModelWhere{model2.NewWhere("k.mode", mode)} //model2.NewWhere("k.tenant_id", c.tenantID),
|
||||
|
||||
out, err := mServiceSolutionCase.SolutionCase(6, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -73,8 +77,9 @@ func (c *SolutionCase) Instance() ([]*SolutionCaseInfo, error) {
|
||||
if !isExist {
|
||||
ret = append(ret, &SolutionCaseInfo{
|
||||
ID: v.GetEncodeID(), MarkID: v.ID, Mode: v.Mode, Title: v.Title,
|
||||
Image: v.Image.Analysis(config.SettingInfo.Domain),
|
||||
Children: []*SolutionCaseBasic{detail},
|
||||
Image: v.Image.Analysis(config.SettingInfo.Domain),
|
||||
Description: v.Description,
|
||||
Children: []*SolutionCaseBasic{detail},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
40
app/api/website/controller/sys/banner.go
Normal file
40
app/api/website/controller/sys/banner.go
Normal file
@ -0,0 +1,40 @@
|
||||
package sys
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/model"
|
||||
"SciencesServer/config"
|
||||
)
|
||||
|
||||
type Banner struct {
|
||||
tenantID uint64
|
||||
}
|
||||
|
||||
type BannerHandle func(tenantID uint64) *Banner
|
||||
|
||||
type BannerInfo struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
IsMultiple int `json:"is_multiple"`
|
||||
Images string `json:"images"`
|
||||
}
|
||||
|
||||
func (c *Banner) Instance(key string) (*BannerInfo, error) {
|
||||
mSysBanner := model.NewSysBanner()
|
||||
if err := mSysBanner.Get(c.tenantID, map[string]interface{}{
|
||||
"key": key, "local": key,
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &BannerInfo{
|
||||
ID: mSysBanner.GetEncodeID(),
|
||||
Title: mSysBanner.Title,
|
||||
IsMultiple: mSysBanner.IsMultiple,
|
||||
Images: mSysBanner.Images.AnalysisSlice(config.SettingInfo.Domain),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewBanner() BannerHandle {
|
||||
return func(tenantID uint64) *Banner {
|
||||
return &Banner{tenantID: tenantID}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package controller
|
||||
package sys
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/model"
|
@ -63,8 +63,7 @@ func (m *ActivityInstance) Detail(id, uid uint64, identity int) (*ActivityInstan
|
||||
mActivityJoin := model.NewActivityJoin()
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS a").
|
||||
Select("a.id", "a.title", "a.image", "a.begin_at", "a.finish_at", "a.join_deadline",
|
||||
"IFNULL(u.id, 0) AS join_id", "j.count AS join_count").
|
||||
Select("a.*", "IFNULL(u.id, 0) AS join_id", "j.count AS join_count").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s u ON a.id = u.activity_id AND u.uid = %d AND u.identity = %d AND u.status = %d AND u.is_deleted = %d",
|
||||
mActivityJoin.TableName(), uid, identity, model.ActivityJoinStatusForSuccess, model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT activity_id, COUNT(id) AS count FROM %s WHERE status = %d AND is_deleted = %d GROUP BY activity_id) AS j ON a.id = j.activity_id",
|
||||
|
@ -13,8 +13,9 @@ type ServiceSolutionCase struct {
|
||||
// ServiceSolutionCaseInfo 解决方案案例信息
|
||||
type ServiceSolutionCaseInfo struct {
|
||||
model.Model
|
||||
Mode model.ServiceSolutionCaseMode `json:"mode"`
|
||||
Title string `json:"title"`
|
||||
Mode model.ServiceSolutionCaseMode `json:"mode"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
model.Image
|
||||
DetailID uint64 `json:"detail_id"`
|
||||
DetailTitle string `json:"detail_title"`
|
||||
@ -37,7 +38,7 @@ func (m *ServiceSolutionCase) SolutionCase(limit int, where ...*model.ModelWhere
|
||||
// Order("s.sort " + model.OrderModeToDesc)
|
||||
|
||||
db := orm.GetDB().Table(model.NewServiceSolutionCaseKind().TableName()+" AS k").
|
||||
Select("k.id AS id", "k.mode", "k.image AS image",
|
||||
Select("k.id AS id", "k.mode", "k.title", "k.image AS image", "k.description",
|
||||
"d.id AS detail_id", "d.title AS detail_title", "d.image AS detail_image", "d.description AS detail_description").
|
||||
Joins(fmt.Sprintf(`LEFT JOIN (SELECT id, kind_id, title, image, description, sort FROM %s AS a WHERE
|
||||
(SELECT count( b.id ) FROM %s AS b WHERE a.kind_id = b.kind_id AND a.id < b.id AND b.is_deleted = %d) < %d
|
||||
|
@ -1,11 +1,24 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SysBanner struct {
|
||||
*model.SysBanner
|
||||
}
|
||||
|
||||
func (m *SysBanner) Get(tenantID uint64, condition map[string]interface{}) error {
|
||||
db := orm.GetDB().Table(m.TableName())
|
||||
|
||||
for k, v := range condition {
|
||||
db = db.Or(fmt.Sprintf("`%s` = '%v' AND is_deleted = %d AND tenant_id = %d", k, v, model.DeleteStatusForNot, tenantID))
|
||||
}
|
||||
return db.Scan(m.SysBanner).Error
|
||||
}
|
||||
|
||||
func NewSysBanner() *SysBanner {
|
||||
return &SysBanner{model.NewSysBanner()}
|
||||
}
|
||||
|
@ -27,6 +27,10 @@ func (this *Admin) TenantIDFormat() string {
|
||||
return fmt.Sprintf("%d", this.TenantID)
|
||||
}
|
||||
|
||||
func (this *Admin) UIDFormat() string {
|
||||
return fmt.Sprintf("%d", this.UID)
|
||||
}
|
||||
|
||||
func (this *Admin) MarshalBinary() ([]byte, error) {
|
||||
return json.Marshal(this)
|
||||
}
|
||||
|
@ -50,7 +50,12 @@ func registerAPI(app *gin.Engine) {
|
||||
userV1.POST("/collect/launch", _api.Collect)
|
||||
}
|
||||
// Activity 活动信息管理
|
||||
activityV1 := v1.Group("/activity")
|
||||
activityV1 := v1.Group("/activity").Use(NeedLogin(config.RedisKeyForAccountEnterprise,
|
||||
session.NewEnterprise(), AddSkipperURL([]string{
|
||||
apiPrefix + "/v1/activity",
|
||||
apiPrefix + "/v1/activity/detail",
|
||||
apiPrefix + "/v1/account",
|
||||
}...)))
|
||||
{
|
||||
_api := new(api2.Activity)
|
||||
activityV1.POST("", _api.Instance)
|
||||
@ -62,6 +67,7 @@ func registerAPI(app *gin.Engine) {
|
||||
{
|
||||
_api := new(api2.Sys)
|
||||
sysV1.GET("/platform", _api.Platform)
|
||||
sysV1.GET("/banner", _api.Banner)
|
||||
sysV1.GET("/navigation", _api.Navigation)
|
||||
sysV1.GET("/agreement", _api.Agreement)
|
||||
sysV1.GET("/agreement/detail", _api.AgreementDetail)
|
||||
@ -84,7 +90,7 @@ func registerAPI(app *gin.Engine) {
|
||||
serviceV1 := v1.Group("/service")
|
||||
{
|
||||
_api := new(api2.Service)
|
||||
serviceV1.GET("/solution_case", _api.SolutionCase)
|
||||
serviceV1.POST("/solution_case", _api.SolutionCase)
|
||||
serviceV1.POST("/solution_case/list", _api.SolutionCaseList)
|
||||
serviceV1.POST("/solution_case/detail", _api.SolutionCaseDetail)
|
||||
serviceV1.POST("/innovate", _api.Innovate)
|
||||
@ -141,11 +147,11 @@ func registerAdminAPI(app *gin.Engine) {
|
||||
apiPrefix + "/v1/account/logout",
|
||||
}...)))
|
||||
// 权限验证
|
||||
//g.Use(NeedPermission(AddSkipperURL([]string{
|
||||
// apiPrefix + "/captcha",
|
||||
// apiPrefix + "/account/login",
|
||||
// apiPrefix + "/account/logout",
|
||||
//}...)))
|
||||
v1.Use(NeedPermission(AddSkipperURL([]string{
|
||||
apiPrefix + "/v1/captcha",
|
||||
apiPrefix + "/v1/account/login",
|
||||
apiPrefix + "/v1/account/logout",
|
||||
}...)))
|
||||
// Captcha 验证码
|
||||
v1.GET("/captcha", new(api1.Captcha).Captcha)
|
||||
// Upload 上传管理
|
||||
@ -347,6 +353,8 @@ func registerEnterpriseAPI(app *gin.Engine) {
|
||||
apiPrefix + "/v1/account/authorize",
|
||||
}...)))
|
||||
|
||||
v1.Use(NeedAuthIdentity())
|
||||
|
||||
// Upload 上传管理
|
||||
v1.POST("/upload", new(api.Upload).Upload)
|
||||
// Config 配置管理
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/utils"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
@ -27,6 +28,7 @@ func AddSkipperURL(url ...string) SkipperURL {
|
||||
// NeedLogin 需要登录
|
||||
func NeedLogin(key string, session logic.ISession, skipperURL ...SkipperURL) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
fmt.Println(c.Request.URL.Path)
|
||||
if len(skipperURL) > 0 && skipperURL[0](c) {
|
||||
c.Next()
|
||||
return
|
||||
@ -50,41 +52,48 @@ func NeedLogin(key string, session logic.ISession, skipperURL ...SkipperURL) gin
|
||||
}
|
||||
}
|
||||
|
||||
func NeedHaveIdentity() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// NeedPermission 需要权限验证
|
||||
func NeedPermission(skipperURL ...SkipperURL) PermissionHandle {
|
||||
return func(key string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if len(skipperURL) > 0 && skipperURL[0](c) {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
value, _ := c.Get(config.TokenForSession)
|
||||
_session := value.(*session.Admin)
|
||||
|
||||
if !_session.IsAdmin {
|
||||
if _session.TenantID > 0 {
|
||||
//if isExist, _ := cache.Cache.SIsMember(config.RedisKeyForTenant, _session.TenantKey); !isExist {
|
||||
// c.JSON(http.StatusForbidden, gin.H{"message": "租户/公司信息协议已到期或已被禁用,无权限访问!"})
|
||||
// c.Abort()
|
||||
// return
|
||||
//}
|
||||
}
|
||||
//if pass, _ := service.NewPermission(nil, &service.AuthRequest{
|
||||
// Url: key,
|
||||
// Method: c.Request.Method,
|
||||
//})(_session.TenantKey, fmt.Sprintf("%d", _session.UID)).Enforce(); !pass {
|
||||
// c.JSON(http.StatusOK, gin.H{"code": http.StatusForbidden, "msg": "无权限访问!"})
|
||||
// c.Abort()
|
||||
// return
|
||||
//}
|
||||
}
|
||||
func NeedPermission(skipperURL ...SkipperURL) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if len(skipperURL) > 0 && skipperURL[0](c) {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
value, _ := c.Get(config.TokenForSession)
|
||||
_session := value.(*session.Admin)
|
||||
|
||||
if _session.IsAdmin && _session.TenantID <= 0 {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
pass, err := service.NewPermission(
|
||||
service.WithAuthTenant(_session.TenantIDFormat()),
|
||||
service.WithAuthUser(_session.UIDFormat()),
|
||||
service.WithAuthRequest([]*service.AuthRequest{
|
||||
&service.AuthRequest{
|
||||
Url: c.Request.URL.Path,
|
||||
Method: c.Request.Method,
|
||||
},
|
||||
}),
|
||||
).Enforce()
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": fmt.Sprintf("权限验证错误【%v】,请联系管理员!", err),
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
} else if !pass {
|
||||
c.JSON(http.StatusForbidden, gin.H{"message": "无权限访问!"})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
func NeedAuthIdentity() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/serve/logger"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@ -86,7 +85,7 @@ func RecoveryHandler() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
fmt.Printf("Recover:request【%s】 error:【%v】\n", c.Request.URL, err)
|
||||
//fmt.Printf("Recover:request【%s】 error:【%v】\n", c.Request.URL, err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": "Internal Server Error!",
|
||||
})
|
||||
|
Reference in New Issue
Block a user