From 7cab0fb354cd6d1b4b4c0344bdb099198b06d471 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 11 Jan 2022 10:41:46 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=AE=8C=E5=96=84=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +- app/api/admin/api/manage.go | 3 +- app/api/admin/controller/manage/instance.go | 12 ++-- app/api/admin/controller/service/innovate.go | 2 +- app/api/admin/controller/tenant/instance.go | 2 + app/api/admin/controller/user/instance.go | 13 ++-- app/api/admin/model/service_innovate.go | 3 +- app/api/website/api/basic.go | 3 + app/api/website/api/service.go | 22 ++++--- app/api/website/controller/index.go | 63 +++++++++++++++++-- .../website/controller/service/innovate.go | 10 +-- .../controller/service/solution_case.go | 47 +++++++------- .../website/model/service_solution_case.go | 40 ++++++++---- .../model/service_solution_case_detail.go | 11 ---- .../model/service_solution_case_kind.go | 11 ++++ app/basic/api/base.go | 6 +- app/common/migrate/instance.go | 2 +- .../model/service_solution_case_detail.go | 23 ------- app/service/{authToken.go => auth_token.go} | 0 app/service/session.go | 54 ---------------- app/session/tenant.go | 5 ++ cmd/serve/init.go | 12 +++- router/auth.go | 5 +- router/router.go | 2 +- 24 files changed, 188 insertions(+), 169 deletions(-) create mode 100644 app/api/website/api/basic.go delete mode 100644 app/api/website/model/service_solution_case_detail.go create mode 100644 app/api/website/model/service_solution_case_kind.go delete mode 100644 app/common/model/service_solution_case_detail.go rename app/service/{authToken.go => auth_token.go} (100%) delete mode 100644 app/service/session.go diff --git a/README.md b/README.md index 3eeab4d..5a48d51 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # SciencesServer -中科元系统管理 \ No newline at end of file +中科元系统管理 + +### 迁移数据 + +./SciencesServer init -H 192.168.0.188 -P 3306 -d sciences -u appuser -p ABCabc01 \ No newline at end of file diff --git a/app/api/admin/api/manage.go b/app/api/admin/api/manage.go index bff8bf4..94b9316 100644 --- a/app/api/admin/api/manage.go +++ b/app/api/admin/api/manage.go @@ -4,7 +4,6 @@ import ( "SciencesServer/app/api/admin/controller/manage" "SciencesServer/app/basic/api" "SciencesServer/app/basic/config" - "SciencesServer/app/service" "SciencesServer/app/session" "github.com/gin-gonic/gin" ) @@ -51,7 +50,7 @@ func (*Manage) Expert(c *gin.Context) { api.APIFailure(err.(error))(c) return } - data, err := manage.NewInstance()(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string)). + data, err := manage.NewInstance()(api.GetSession()(c).(*session.Admin), api.GetTenantID()(c).(string)). Expert(form.Name, form.Status, form.Page, form.PageSize) api.APIResponse(err, data) } diff --git a/app/api/admin/controller/manage/instance.go b/app/api/admin/controller/manage/instance.go index 1b0af92..8f7b028 100644 --- a/app/api/admin/controller/manage/instance.go +++ b/app/api/admin/controller/manage/instance.go @@ -5,19 +5,19 @@ import ( "SciencesServer/app/basic/config" "SciencesServer/app/basic/controller" model2 "SciencesServer/app/common/model" - "SciencesServer/app/service" + "SciencesServer/app/session" "gorm.io/gorm" "strings" "time" ) type Instance struct { - *service.Session + *session.Admin gorm.Model local string } -type InstanceHandle func(session *service.Session, local string) *Instance +type InstanceHandle func(session *session.Admin, local string) *Instance type ( // InstanceForExpert 专家信息 @@ -87,10 +87,10 @@ func (c *Instance) Expert(name string, status int, page, pageSize int) (*control } func NewInstance() InstanceHandle { - return func(session *service.Session, local string) *Instance { + return func(session *session.Admin, local string) *Instance { return &Instance{ - Session: session, - local: local, + Admin: session, + local: local, } } } diff --git a/app/api/admin/controller/service/innovate.go b/app/api/admin/controller/service/innovate.go index 3b15ec4..4f001de 100644 --- a/app/api/admin/controller/service/innovate.go +++ b/app/api/admin/controller/service/innovate.go @@ -266,6 +266,6 @@ func (c *Innovate) KindDelete(id uint64) error { func NewInnovate() InnovateHandle { return func(admin *session.Admin) *Innovate { - return &Innovate{} + return &Innovate{admin} } } diff --git a/app/api/admin/controller/tenant/instance.go b/app/api/admin/controller/tenant/instance.go index d7b6681..000261d 100644 --- a/app/api/admin/controller/tenant/instance.go +++ b/app/api/admin/controller/tenant/instance.go @@ -27,6 +27,7 @@ type ( InstanceInfo struct { ID string `json:"id"` *model2.SysTenant + Area string `json:"area"` } // InstanceSelectInfo 租户筛选信息 InstanceSelectInfo struct { @@ -66,6 +67,7 @@ func (c *Instance) Index(name string, page, pageSize int) (*controller.ReturnPag list = append(list, &InstanceInfo{ ID: v.GetEncodeID(), SysTenant: v, + Area: v.FormatBasic(), }) } return &controller.ReturnPages{Data: list, Count: count}, nil diff --git a/app/api/admin/controller/user/instance.go b/app/api/admin/controller/user/instance.go index 56c04f8..58c3545 100644 --- a/app/api/admin/controller/user/instance.go +++ b/app/api/admin/controller/user/instance.go @@ -38,11 +38,12 @@ type ( } // InstanceUserInfo 用户信息 InstanceUserInfo struct { - UID string `json:"uid"` - Avatar string `json:"avatar"` - Name string `json:"name"` - Email string `json:"email"` - Mobile string `json:"mobile"` + UID string `json:"uid"` + Avatar string `json:"avatar"` + Name string `json:"name"` + Email string `json:"email"` + Mobile string `json:"mobile"` + IsSuper bool `json:"is_super"` // 总后台 } // InstanceDepartmentInfo 部门信息 InstanceDepartmentInfo struct { @@ -136,7 +137,7 @@ func (c *Instance) Info() (*InstanceUserInfo, error) { } return &InstanceUserInfo{ UID: mSysUser.UUIDString(), Avatar: mSysUser.Avatar, Name: mSysUser.Name, - Email: mSysUser.Email, Mobile: mSysUser.Mobile, + Email: mSysUser.Email, Mobile: mSysUser.Mobile, IsSuper: c.TenantID <= 0, }, nil } diff --git a/app/api/admin/model/service_innovate.go b/app/api/admin/model/service_innovate.go index 32abb70..7610cd4 100644 --- a/app/api/admin/model/service_innovate.go +++ b/app/api/admin/model/service_innovate.go @@ -17,12 +17,13 @@ type ServiceInnovateInfo struct { Title string `json:"title"` TenantName string `json:"tenant_name"` KindTitle string `json:"kind_title"` + Sort int `json:"sort"` CreatedAt time.Time `json:"created_at"` } func (m *ServiceInnovate) Innovate(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ServiceInnovateInfo, error) { db := orm.GetDB().Table(m.TableName()+" AS i"). - Select("i.id", "i.title", "t.name AS tenant_name", "k.title AS kind_title", "i.created_at", + Select("i.id", "i.title", "t.name AS tenant_name", "k.title AS kind_title", "i.sort", "i.created_at", "t.province", "t.city"). Joins(fmt.Sprintf("LEFT JOIN %s AS t ON i.tenant_id = t.id", model.NewSysTenant().TableName())). Joins(fmt.Sprintf("LEFT JOIN %s AS k ON i.kind = k.id", model.NewServiceInnovateKind().TableName())). diff --git a/app/api/website/api/basic.go b/app/api/website/api/basic.go new file mode 100644 index 0000000..bb4d16f --- /dev/null +++ b/app/api/website/api/basic.go @@ -0,0 +1,3 @@ +package api + +type basic struct{} diff --git a/app/api/website/api/service.go b/app/api/website/api/service.go index 69a1a59..fd9b797 100644 --- a/app/api/website/api/service.go +++ b/app/api/website/api/service.go @@ -3,26 +3,28 @@ package api import ( "SciencesServer/app/api/website/controller/service" "SciencesServer/app/basic/api" + "SciencesServer/app/session" "github.com/gin-gonic/gin" ) type Service struct{} func (*Service) SolutionCase(c *gin.Context) { - data, err := service.NewSolutionCase()(nil, "").Instance() + data, err := service.NewSolutionCase()(nil, 0).Instance() api.APIResponse(err, data)(c) } func (*Service) SolutionCaseList(c *gin.Context) { form := &struct { - api.IDStringForm + KindID string `json:"kind_id" form:"kind_id"` api.PageForm }{} if err := api.Bind(form)(c); err != nil { api.APIFailure(err.(error))(c) return } - data, err := service.NewSolutionCase()(nil, "").List(form.Convert(), form.Page, form.PageSize) + data, err := service.NewSolutionCase()(nil, 0).List((&api.IDStringForm{ID: form.KindID}).Convert(), + form.Page, form.PageSize) api.APIResponse(err, data)(c) } @@ -33,26 +35,28 @@ func (*Service) SolutionCaseDetail(c *gin.Context) { api.APIFailure(err.(error))(c) return } - data, err := service.NewSolutionCase()(nil, "").Detail(form.Convert()) + data, err := service.NewSolutionCase()(api.GetSession()(c).(*session.Enterprise), + api.GetTenantID()(c).(uint64)).Detail(form.Convert()) api.APIResponse(err, data)(c) } func (*Service) Innovate(c *gin.Context) { form := &struct { - Kind int `json:"kind" form:"kind"` - Title string `json:"title" form:"title"` + KindID string `json:"kind_id" form:"kind_id"` + Title string `json:"title" form:"title"` api.PageForm }{} if err := api.Bind(form)(c); err != nil { api.APIFailure(err.(error))(c) return } - data, err := service.NewInnovate()(nil, "").Instance(form.Kind, form.Title, form.Page, form.PageSize) + data, err := service.NewInnovate()(nil, 0).Instance((&api.IDStringForm{ID: form.KindID}).Convert(), + form.Title, form.Page, form.PageSize) api.APIResponse(err, data)(c) } func (*Service) InnovateKind(c *gin.Context) { - data, err := service.NewInnovate()(nil, "").Kind() + data, err := service.NewInnovate()(nil, 0).Kind() api.APIResponse(err, data)(c) } @@ -63,6 +67,6 @@ func (*Service) InnovateDetail(c *gin.Context) { api.APIFailure(err.(error))(c) return } - data, err := service.NewInnovate()(nil, "").Detail(form.Convert()) + data, err := service.NewInnovate()(nil, 0).Detail(form.Convert()) api.APIResponse(err, data)(c) } diff --git a/app/api/website/controller/index.go b/app/api/website/controller/index.go index 1c6c4ce..2f9843c 100644 --- a/app/api/website/controller/index.go +++ b/app/api/website/controller/index.go @@ -4,17 +4,17 @@ import ( "SciencesServer/app/api/website/model" config2 "SciencesServer/app/basic/config" model2 "SciencesServer/app/common/model" - "SciencesServer/app/service" + "SciencesServer/app/session" "SciencesServer/config" "SciencesServer/utils" "strings" ) type Index struct { - *service.Session + *session.Enterprise } -type IndexHandle func(session *service.Session) *Index +type IndexHandle func(session *session.Enterprise) *Index type ( // InstanceInfo 首页信息 @@ -218,7 +218,58 @@ func (c *Index) DistributionExpert(province, city string) (map[string]*InstanceD }, }, } - + _out["630000"] = &InstanceDistributionDetailInfo{ + Code: "630000", + Name: "青海省", + Count: 1200, + Industry: nil, + Children: map[string]*InstanceDistributionDetailInfo{ + "630200": &InstanceDistributionDetailInfo{ + Code: "630200", + Name: "海东市", + Count: 1200, + Industry: nil, + Children: nil, + }, + }, + } + _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 } @@ -293,9 +344,9 @@ func (c *Index) Instance() (*InstanceInfo, error) { } func NewIndex() IndexHandle { - return func(session *service.Session) *Index { + return func(session *session.Enterprise) *Index { return &Index{ - Session: session, + session, } } } diff --git a/app/api/website/controller/service/innovate.go b/app/api/website/controller/service/innovate.go index 3504fee..3683c61 100644 --- a/app/api/website/controller/service/innovate.go +++ b/app/api/website/controller/service/innovate.go @@ -12,10 +12,10 @@ import ( // Innovate 创新服务 type Innovate struct { *session.Enterprise - local string + tenantID uint64 } -type InnovateHandle func(session *session.Enterprise, local string) *Innovate +type InnovateHandle func(session *session.Enterprise, tenantID uint64) *Innovate type ( // InnovateInfo 创新服务信息 @@ -39,7 +39,7 @@ type ( ) // Instance 首页信息 -func (c *Innovate) Instance(kind int, title string, page, pageSize int) (*controller.ReturnPages, error) { +func (c *Innovate) Instance(kind uint64, title string, page, pageSize int) (*controller.ReturnPages, error) { mServiceInnovate := model.NewServiceInnovate() out := make([]*model2.ServiceInnovate, 0) @@ -109,10 +109,10 @@ func (c *Innovate) Detail(id uint64) (*InnovateDetailInfo, error) { } func NewInnovate() InnovateHandle { - return func(session *session.Enterprise, local string) *Innovate { + return func(session *session.Enterprise, tenantID uint64) *Innovate { return &Innovate{ Enterprise: session, - local: local, + tenantID: tenantID, } } } diff --git a/app/api/website/controller/service/solution_case.go b/app/api/website/controller/service/solution_case.go index e1d5af0..0dca655 100644 --- a/app/api/website/controller/service/solution_case.go +++ b/app/api/website/controller/service/solution_case.go @@ -14,17 +14,17 @@ import ( // SolutionCase 解决方案案例 type SolutionCase struct { *session.Enterprise - local string + tenantID uint64 } -type SolutionCaseHandle func(session *session.Enterprise, local string) *SolutionCase +type SolutionCaseHandle func(session *session.Enterprise, tenantID uint64) *SolutionCase type ( // SolutionCaseInfo 基本信息 SolutionCaseInfo struct { ID string `json:"id"` MarkID uint64 `json:"-"` - Kind model2.ServiceSolutionCaseKind `json:"kind"` + Mode model2.ServiceSolutionCaseMode `json:"mode"` Title string `json:"title"` Image string `json:"image"` Children []*SolutionCaseBasic `json:"children"` @@ -48,7 +48,7 @@ type ( // Instance 服务解决方案案例 func (c *SolutionCase) Instance() ([]*SolutionCaseInfo, error) { mServiceSolutionCase := model.NewServiceSolutionCase() - out, err := mServiceSolutionCase.SolutionCase(2) + out, err := mServiceSolutionCase.SolutionCase(6) if err != nil { return nil, err @@ -72,7 +72,7 @@ func (c *SolutionCase) Instance() ([]*SolutionCaseInfo, error) { } if !isExist { ret = append(ret, &SolutionCaseInfo{ - ID: v.GetEncodeID(), MarkID: v.ID, Kind: v.Kind, Title: v.Title, + ID: v.GetEncodeID(), MarkID: v.ID, Mode: v.Mode, Title: v.Title, Image: v.Image.Analysis(config.SettingInfo.Domain), Children: []*SolutionCaseBasic{detail}, }) @@ -82,17 +82,17 @@ func (c *SolutionCase) Instance() ([]*SolutionCaseInfo, error) { } // List 列表信息 -func (c *SolutionCase) List(id uint64, page, pageSize int) (*controller.ReturnPages, error) { - mServiceSolutionCaseDetail := model.NewServiceSolutionCaseDetail() +func (c *SolutionCase) List(kindID uint64, page, pageSize int) (*controller.ReturnPages, error) { + mServiceSolutionCase := model.NewServiceSolutionCase() - out := make([]*model2.ServiceSolutionCaseDetail, 0) + out := make([]*model2.ServiceSolutionCase, 0) var count int64 - err := model2.PagesFields(mServiceSolutionCaseDetail.ServiceSolutionCaseDetail, &out, []string{"id", "title", + err := model2.PagesFields(mServiceSolutionCase.ServiceSolutionCase, &out, []string{"id", "title", "image", "description"}, page, pageSize, &count, &model2.ModelWhereOrder{ - Where: model2.NewWhere("solution_case_id", id), + Where: model2.NewWhere("kind_id", kindID), Order: model2.NewOrder("sort", model2.OrderModeToDesc), }, &model2.ModelWhereOrder{ Order: model2.NewOrder("id", model2.OrderModeToDesc), @@ -114,36 +114,37 @@ func (c *SolutionCase) List(id uint64, page, pageSize int) (*controller.ReturnPa // Detail 详细信息 func (c *SolutionCase) Detail(id uint64) (*SolutionCaseDetail, error) { - mServiceSolutionCaseDetail := model.NewServiceSolutionCaseDetail() - mServiceSolutionCaseDetail.ID = id + mServiceSolutionCase := model.NewServiceSolutionCase() + mServiceSolutionCase.ID = id - if isExist, err := model2.FirstField(mServiceSolutionCaseDetail.ServiceSolutionCaseDetail, []string{"id", "title", + if isExist, err := model2.FirstField(mServiceSolutionCase.ServiceSolutionCase, []string{"id", "title", "image", "description", "content", "visits", "created_at"}); err != nil { return nil, err } else if !isExist { return nil, errors.New("操作错误,案例信息不存在或已被删除") } - _ = model2.Updates(mServiceSolutionCaseDetail.ServiceSolutionCaseDetail, map[string]interface{}{ + + _ = model2.Updates(mServiceSolutionCase.ServiceSolutionCase, map[string]interface{}{ "visits": gorm.Expr("visits + ?", 1), "updated_at": time.Now(), }) return &SolutionCaseDetail{ SolutionCaseBasic: SolutionCaseBasic{ - ID: mServiceSolutionCaseDetail.GetEncodeID(), - Title: mServiceSolutionCaseDetail.Title, - Image: mServiceSolutionCaseDetail.Image.Analysis(config.SettingInfo.Domain), - Description: mServiceSolutionCaseDetail.Description, + ID: mServiceSolutionCase.GetEncodeID(), + Title: mServiceSolutionCase.Title, + Image: mServiceSolutionCase.Image.Analysis(config.SettingInfo.Domain), + Description: mServiceSolutionCase.Description, }, - Visits: mServiceSolutionCaseDetail.Visits, - Content: mServiceSolutionCaseDetail.Content, - CreatedAt: mServiceSolutionCaseDetail.CreatedAt, + Visits: mServiceSolutionCase.Visits, + Content: mServiceSolutionCase.Content, + CreatedAt: mServiceSolutionCase.CreatedAt, }, nil } func NewSolutionCase() SolutionCaseHandle { - return func(session *session.Enterprise, local string) *SolutionCase { + return func(session *session.Enterprise, tenantID uint64) *SolutionCase { return &SolutionCase{ Enterprise: session, - local: local, + tenantID: tenantID, } } } diff --git a/app/api/website/model/service_solution_case.go b/app/api/website/model/service_solution_case.go index 4e0cffc..14cf58b 100644 --- a/app/api/website/model/service_solution_case.go +++ b/app/api/website/model/service_solution_case.go @@ -13,7 +13,7 @@ type ServiceSolutionCase struct { // ServiceSolutionCaseInfo 解决方案案例信息 type ServiceSolutionCaseInfo struct { model.Model - Kind model.ServiceSolutionCaseKind `json:"kind"` + Mode model.ServiceSolutionCaseMode `json:"mode"` Title string `json:"title"` model.Image DetailID uint64 `json:"detail_id"` @@ -23,19 +23,37 @@ type ServiceSolutionCaseInfo struct { } // SolutionCase 解决方案案例信息 -func (m *ServiceSolutionCase) SolutionCase(limit int) ([]*ServiceSolutionCaseInfo, error) { - mServiceSolutionCaseDetail := model.NewServiceSolutionCaseDetail() +func (m *ServiceSolutionCase) SolutionCase(limit int, where ...*model.ModelWhere) ([]*ServiceSolutionCaseInfo, error) { + //mServiceSolutionCaseKind := model.NewServiceSolutionCaseKind() - db := orm.GetDB().Table(m.TableName()+" AS s"). - Select("s.id", "s.kind", "s.image", + // db := orm.GetDB().Table(m.TableName()+" AS s"). + // Select("s.id", "s.mode", "s.image", + // "d.id AS detail_id", "d.title AS detail_title", "d.image AS detail_image", "d.description AS detail_description"). + // Joins(fmt.Sprintf(`INNER JOIN (SELECT id, solution_case_id, title, image, description FROM %s AS a WHERE + //(SELECT count( b.id ) FROM %s AS b WHERE a.solution_case_id = b.solution_case_id AND a.id < b.id AND b.is_deleted = %d) < %d + //AND a.is_deleted = %d ORDER BY a.sort DESC, a.id DESC) AS d ON s.id = d.solution_case_id`, + // mServiceSolutionCaseKind.TableName(), mServiceSolutionCaseKind.TableName(), model.DeleteStatusForNot, limit, model.DeleteStatusForNot)). + // Where("s.is_deleted = ?", model.DeleteStatusForNot). + // 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", "d.id AS detail_id", "d.title AS detail_title", "d.image AS detail_image", "d.description AS detail_description"). - Joins(fmt.Sprintf(`INNER JOIN (SELECT id, solution_case_id, title, image, description FROM %s AS a WHERE -(SELECT count( b.id ) FROM %s AS b WHERE a.solution_case_id = b.solution_case_id AND a.id < b.id AND b.is_deleted = %d) < %d -AND a.is_deleted = %d ORDER BY a.sort DESC, a.id DESC) AS d ON s.id = d.solution_case_id`, - mServiceSolutionCaseDetail.TableName(), mServiceSolutionCaseDetail.TableName(), model.DeleteStatusForNot, limit, model.DeleteStatusForNot)). - Where("s.is_deleted = ?", model.DeleteStatusForNot). - Order("s.sort " + model.OrderModeToDesc) + 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 +AND a.is_deleted = %d ORDER BY a.sort ASC, a.id DESC) AS d ON k.id = d.kind_id`, + m.TableName(), m.TableName(), model.DeleteStatusForNot, limit, model.DeleteStatusForNot)). + Where("k.is_deleted = ?", model.DeleteStatusForNot). + Order("k.mode " + model.OrderModeToAsc). + Order("k.sort " + model.OrderModeToAsc). + Order("k.id " + model.OrderModeToDesc). + Order("d.sort " + model.OrderModeToAsc) + if len(where) > 0 { + for _, v := range where { + db = db.Where(v.Condition, v.Value) + } + } out := make([]*ServiceSolutionCaseInfo, 0) err := db.Scan(&out).Error diff --git a/app/api/website/model/service_solution_case_detail.go b/app/api/website/model/service_solution_case_detail.go deleted file mode 100644 index 3675ef3..0000000 --- a/app/api/website/model/service_solution_case_detail.go +++ /dev/null @@ -1,11 +0,0 @@ -package model - -import "SciencesServer/app/common/model" - -type ServiceSolutionCaseDetail struct { - *model.ServiceSolutionCaseDetail -} - -func NewServiceSolutionCaseDetail() *ServiceSolutionCaseDetail { - return &ServiceSolutionCaseDetail{model.NewServiceSolutionCaseDetail()} -} diff --git a/app/api/website/model/service_solution_case_kind.go b/app/api/website/model/service_solution_case_kind.go new file mode 100644 index 0000000..76027f8 --- /dev/null +++ b/app/api/website/model/service_solution_case_kind.go @@ -0,0 +1,11 @@ +package model + +import "SciencesServer/app/common/model" + +type ServiceSolutionCaseKind struct { + *model.ServiceSolutionCaseKind +} + +func NewServiceSolutionCaseKind() *ServiceSolutionCaseKind { + return &ServiceSolutionCaseKind{model.NewServiceSolutionCaseKind()} +} diff --git a/app/basic/api/base.go b/app/basic/api/base.go index deeff07..9aaa381 100644 --- a/app/basic/api/base.go +++ b/app/basic/api/base.go @@ -32,12 +32,12 @@ func GetSession() ApiHandle { func GetTenantID() ApiHandle { return func(c *gin.Context) interface{} { - _, isExist := c.Get(config.ContentForTenantID) - //value + value, isExist := c.Get(config.ContentForTenantID) + if !isExist { return 0 } - return uint64(0) + return utils.StringToUnit64(value.(string)) } } diff --git a/app/common/migrate/instance.go b/app/common/migrate/instance.go index 4efe852..dc00345 100644 --- a/app/common/migrate/instance.go +++ b/app/common/migrate/instance.go @@ -137,7 +137,7 @@ func (this *Instance) Handle() { &synchronized{iModel: model.NewTechnologyPaper()}, &synchronized{iModel: model.NewTechnologyProduct()}, &synchronized{iModel: model.NewTechnologyProject()}, &synchronized{iModel: model.NewTechnologyTopic()}, &synchronized{iModel: model.NewServiceDocking()}, &synchronized{iModel: model.NewServiceMessage()}, - &synchronized{iModel: model.NewServiceSolutionCase()}, &synchronized{iModel: model.NewServiceSolutionCaseDetail()}, + &synchronized{iModel: model.NewServiceSolutionCase()}, &synchronized{iModel: model.NewServiceSolutionCaseKind()}, &synchronized{iModel: model.NewServiceInnovate()}, &synchronized{iModel: model.NewServiceInnovateKind()}, // 活动管理 &synchronized{iModel: model.NewActivityInstance()}, &synchronized{iModel: model.NewActivityApply()}, diff --git a/app/common/model/service_solution_case_detail.go b/app/common/model/service_solution_case_detail.go deleted file mode 100644 index 0d6e445..0000000 --- a/app/common/model/service_solution_case_detail.go +++ /dev/null @@ -1,23 +0,0 @@ -package model - -// ServiceSolutionCaseDetail 服务解决案例数据模型 -type ServiceSolutionCaseDetail struct { - Model - SolutionCaseID uint64 `json:"solution_case_id"` - Title string `gorm:"column:title;type:varchar(100);default:'';comment:标题" json:"title"` - Image - Description string `gorm:"column:description;type:varchar(255);comment:描述" json:"description"` - Content string `gorm:"column:content;type:text;comment:内容" json:"content"` - Visits int `gorm:"column:visits;type:int(6);default:0;comment:浏览数" json:"visits"` - Sort int `gorm:"column:sort;type:tinyint(3);default:0;comment:排序,数值越大,优先排序" json:"sort"` - ModelDeleted - ModelAt -} - -func (m *ServiceSolutionCaseDetail) TableName() string { - return "service_solution_case_detail" -} - -func NewServiceSolutionCaseDetail() *ServiceSolutionCaseDetail { - return &ServiceSolutionCaseDetail{} -} diff --git a/app/service/authToken.go b/app/service/auth_token.go similarity index 100% rename from app/service/authToken.go rename to app/service/auth_token.go diff --git a/app/service/session.go b/app/service/session.go deleted file mode 100644 index 0a0adad..0000000 --- a/app/service/session.go +++ /dev/null @@ -1,54 +0,0 @@ -package service - -import ( - "SciencesServer/utils" - "encoding/json" -) - -type Session struct { - Token string `json:"token"` // token - UID uint64 `json:"uid"` // 唯一标识ID - TenantID uint64 `json:"tenant_id"` // 租户ID - Name string `json:"name"` // 名称 - Mobile string `json:"mobile"` // 手机号码 - IsAdmin bool `json:"is_admin"` // 是否超管 -} - -func (this *Session) MarshalBinary() ([]byte, error) { - return json.Marshal(this) -} - -func (this *Session) UnmarshalBinary(data []byte) error { - return utils.FromJSONBytes(data, this) -} - -func NewSession() *Session { - return &Session{} -} - -// SessionEnterprise 企业用户 -type SessionEnterprise struct { - UID uint64 `json:"uid"` // 唯一标识ID - TenantID uint64 `json:"tenant_id"` // 租户ID - Token string `json:"token"` // token - Name string `json:"name"` // 名称 - Mobile string `json:"mobile"` // 手机号码 - Identity int `json:"identity"` // 总身份信息 - SelectIdentity int `json:"select_identity"` // 选中身份信息 -} - -func (this *SessionEnterprise) UIDToString() string { - return utils.UintToString(this.UID) -} - -func (this *SessionEnterprise) MarshalBinary() ([]byte, error) { - return json.Marshal(this) -} - -func (this *SessionEnterprise) UnmarshalBinary(data []byte) error { - return utils.FromJSONBytes(data, this) -} - -func NewSessionEnterprise() *SessionEnterprise { - return &SessionEnterprise{} -} diff --git a/app/session/tenant.go b/app/session/tenant.go index e3deea9..07f72fc 100644 --- a/app/session/tenant.go +++ b/app/session/tenant.go @@ -3,6 +3,7 @@ package session import ( "SciencesServer/utils" "encoding/json" + "fmt" ) // Tenant 租户数据信息 @@ -12,6 +13,10 @@ type Tenant struct { Domain string `json:"domain"` } +func (this *Tenant) IDToString() string { + return fmt.Sprintf("%d", this.ID) +} + func (this *Tenant) MarshalBinary() ([]byte, error) { return json.Marshal(this) } diff --git a/cmd/serve/init.go b/cmd/serve/init.go index ba45268..c8f5134 100644 --- a/cmd/serve/init.go +++ b/cmd/serve/init.go @@ -2,6 +2,7 @@ package serve import ( "SciencesServer/app" + "SciencesServer/app/session" "SciencesServer/config" "SciencesServer/cron" "SciencesServer/router" @@ -81,13 +82,18 @@ func run() { }, }).Init()), web.WithFunction(func(src string) (bool, func(r *http.Request)) { - value, _ := cache.Cache.HGet(config.RedisKeyForTenant, src) + // 安全域名 + _cache, _ := cache.Cache.HGet(config.RedisKeyForTenant, src) - if value == "" { + if _cache == "" { return true, nil } + // 解析信息 + out := new(session.Tenant) + _ = out.UnmarshalBinary([]byte(_cache)) + return true, func(r *http.Request) { - r.Header.Set("", value) + r.Header.Set(config.ContentForTenantID, out.IDToString()) } }), ).Run() diff --git a/router/auth.go b/router/auth.go index d5840b3..7cc9abf 100644 --- a/router/auth.go +++ b/router/auth.go @@ -3,6 +3,7 @@ package router import ( "SciencesServer/app/logic" "SciencesServer/app/service" + "SciencesServer/app/session" "SciencesServer/config" "SciencesServer/utils" "github.com/gin-gonic/gin" @@ -63,8 +64,8 @@ func NeedPermission(skipperURL ...SkipperURL) PermissionHandle { c.Next() return } - session, _ := c.Get(config.TokenForSession) - _session := session.(*service.Session) + value, _ := c.Get(config.TokenForSession) + _session := value.(*session.Admin) if !_session.IsAdmin { if _session.TenantID > 0 { diff --git a/router/router.go b/router/router.go index 7491a9d..a4761aa 100644 --- a/router/router.go +++ b/router/router.go @@ -41,7 +41,7 @@ func (this *Router) Init() *gin.Engine { app.NoMethod(NoMethodHandler()) app.Use(LoggerHandle("log/gin.log", 3)) app.Use(TimeoutHandle(time.Second * 30)) - app.Use(RecoveryHandler()) + //app.Use(RecoveryHandler()) app.Use(ContentAnalysisHandler()) if this.RateLimitConfig != nil {