feat:完善网站信息,增加案例解决方案数据管理

This commit is contained in:
henry
2021-12-17 17:33:20 +08:00
parent c6ba000829
commit cb5ab0ae37
11 changed files with 347 additions and 2 deletions

View File

@ -0,0 +1,38 @@
package api
import (
"SciencesServer/app/api/website/controller"
"SciencesServer/app/basic/api"
"github.com/gin-gonic/gin"
)
type Service struct{}
func (*Service) SolutionCase(c *gin.Context) {
data, err := controller.NewService()(nil, "").SolutionCase()
api.APIResponse(err, data)(c)
}
func (*Service) SolutionCaseList(c *gin.Context) {
form := &struct {
api.IDStringForm
api.PageForm
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := controller.NewService()(nil, "").SolutionCaseList(form.Convert(), form.Page, form.PageSize)
api.APIResponse(err, data)(c)
}
func (*Service) SolutionCaseDetail(c *gin.Context) {
form := new(api.IDStringForm)
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := controller.NewService()(nil, "").SolutionCaseDetail(form.Convert())
api.APIResponse(err, data)(c)
}

View File

@ -0,0 +1,152 @@
package controller
import (
"SciencesServer/app/api/manage/controller"
"SciencesServer/app/api/website/model"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/session"
"SciencesServer/config"
"errors"
"gorm.io/gorm"
"time"
)
type Service struct {
*session.Enterprise
local string
}
type ServiceHandle func(session *session.Enterprise, local string) *Service
type (
// ServiceSolutionCase 服务解决方案案例信息
ServiceSolutionCase struct {
ID string `json:"id"`
MarkID uint64 `json:"-"`
Kind model2.ServiceSolutionCaseKind `json:"kind"`
Title string `json:"title"`
Image string `json:"image"`
Children []*ServiceSolutionCaseInfo `json:"children"`
}
// ServiceSolutionCaseInfo 基本信息
ServiceSolutionCaseInfo struct {
ID string `json:"id"`
Title string `json:"title"`
Image string `json:"image"`
Description string `json:"description"`
}
// ServiceSolutionCaseDetail 详细信息
ServiceSolutionCaseDetail struct {
ServiceSolutionCaseInfo
Visits int `json:"visits"`
Content string `json:"content"`
CreatedAt time.Time `json:"created_at"`
}
)
// SolutionCase 服务解决方案案例
func (c *Service) SolutionCase() ([]*ServiceSolutionCase, error) {
mServiceSolutionCase := model.NewServiceSolutionCase()
out, err := mServiceSolutionCase.SolutionCase(2)
if err != nil {
return nil, err
}
ret := make([]*ServiceSolutionCase, 0)
for _, v := range out {
isExist := false
detail := &ServiceSolutionCaseInfo{
ID: (&model2.Model{ID: v.DetailID}).GetEncodeID(), Title: v.DetailTitle,
Image: (&model2.Image{Image: v.DetailImage}).Analysis(config.SettingInfo.Domain),
Description: v.DetailDescription,
}
for _, val := range ret {
if v.ID == val.MarkID {
val.Children = append(val.Children, detail)
isExist = true
break
}
}
if !isExist {
ret = append(ret, &ServiceSolutionCase{
ID: v.GetEncodeID(),
MarkID: v.ID,
Kind: v.Kind,
Title: v.Title,
Image: v.Image.Analysis(config.SettingInfo.Domain),
Children: []*ServiceSolutionCaseInfo{detail},
})
}
}
return ret, nil
}
// SolutionCaseList 列表信息
func (c *Service) SolutionCaseList(id uint64, page, pageSize int) (*controller.ReturnPages, error) {
mServiceSolutionCaseDetail := model.NewServiceSolutionCaseDetail()
out := make([]*model2.ServiceSolutionCaseDetail, 0)
var count int64
err := model2.PagesFields(mServiceSolutionCaseDetail.ServiceSolutionCaseDetail, &out, []string{"id", "title",
"image", "description"}, page, pageSize, &count,
&model2.ModelWhereOrder{
Where: model2.NewWhere("solution_case_id", id),
Order: model2.NewOrder("sort", model2.OrderModeToDesc),
}, &model2.ModelWhereOrder{
Order: model2.NewOrder("id", model2.OrderModeToDesc),
})
if err != nil {
return nil, err
}
list := make([]*ServiceSolutionCaseInfo, 0)
for _, v := range out {
list = append(list, &ServiceSolutionCaseInfo{
ID: v.GetEncodeID(),
Title: v.Title,
Image: v.Image.Analysis(config.SettingInfo.Domain),
Description: v.Description,
})
}
return &controller.ReturnPages{Data: list, Count: count}, nil
}
// SolutionCaseDetail 详细信息
func (c *Service) SolutionCaseDetail(id uint64) (*ServiceSolutionCaseDetail, error) {
mServiceSolutionCaseDetail := model.NewServiceSolutionCaseDetail()
mServiceSolutionCaseDetail.ID = id
if isExist, err := model2.FirstField(mServiceSolutionCaseDetail.ServiceSolutionCaseDetail, []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{}{
"visits": gorm.Expr("visits + ?", 1), "updated_at": time.Now(),
})
return &ServiceSolutionCaseDetail{
ServiceSolutionCaseInfo: ServiceSolutionCaseInfo{
ID: mServiceSolutionCaseDetail.GetEncodeID(),
Title: mServiceSolutionCaseDetail.Title,
Image: mServiceSolutionCaseDetail.Image.Analysis(config.SettingInfo.Domain),
Description: mServiceSolutionCaseDetail.Description,
},
Visits: mServiceSolutionCaseDetail.Visits,
Content: mServiceSolutionCaseDetail.Content,
CreatedAt: mServiceSolutionCaseDetail.CreatedAt,
}, nil
}
func NewService() ServiceHandle {
return func(session *session.Enterprise, local string) *Service {
return &Service{
Enterprise: session,
local: local,
}
}
}

View File

@ -0,0 +1,48 @@
package model
import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
"fmt"
)
type ServiceSolutionCase struct {
*model.ServiceSolutionCase
}
// ServiceSolutionCaseInfo 解决方案案例信息
type ServiceSolutionCaseInfo struct {
model.Model
Kind model.ServiceSolutionCaseKind `json:"kind"`
Title string `json:"title"`
model.Image
DetailID uint64 `json:"detail_id"`
DetailTitle string `json:"detail_title"`
DetailImage string `json:"detail_image"`
DetailDescription string `json:"detail_description"`
}
// SolutionCase 解决方案案例信息
func (m *ServiceSolutionCase) SolutionCase(limit int) ([]*ServiceSolutionCaseInfo, error) {
mServiceSolutionCaseDetail := model.NewServiceSolutionCaseDetail()
db := orm.GetDB().Table(m.TableName()+" AS s").
Select("s.id", "s.kind", "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`,
mServiceSolutionCaseDetail.TableName(), mServiceSolutionCaseDetail.TableName(), model.DeleteStatusForNot, limit, model.DeleteStatusForNot)).
Where("s.is_deleted = ?", model.DeleteStatusForNot).
Order("s.sort " + model.OrderModeToDesc)
out := make([]*ServiceSolutionCaseInfo, 0)
err := db.Scan(&out).Error
return out, err
}
func NewServiceSolutionCase() *ServiceSolutionCase {
return &ServiceSolutionCase{model.NewServiceSolutionCase()}
}

View File

@ -0,0 +1,11 @@
package model
import "SciencesServer/app/common/model"
type ServiceSolutionCaseDetail struct {
*model.ServiceSolutionCaseDetail
}
func NewServiceSolutionCaseDetail() *ServiceSolutionCaseDetail {
return &ServiceSolutionCaseDetail{model.NewServiceSolutionCaseDetail()}
}

View File

@ -0,0 +1,11 @@
package model
import "SciencesServer/app/common/model"
type SysBanner struct {
*model.SysBanner
}
func NewSysBanner() *SysBanner {
return &SysBanner{model.NewSysBanner()}
}

View File

@ -130,7 +130,8 @@ func initModel() {
&synchronized{iModel: model.NewTechnologyAchievement()}, &synchronized{iModel: model.NewTechnologyDemand()},
&synchronized{iModel: model.NewTechnologyPaper()}, &synchronized{iModel: model.NewTechnologyProduct()},
&synchronized{iModel: model.NewTechnologyProject()}, &synchronized{iModel: model.NewTechnologyTopic()},
&synchronized{iModel: model.NewServiceDocking()},
&synchronized{iModel: model.NewServiceDocking()}, &synchronized{iModel: model.NewServiceMessage()},
&synchronized{iModel: model.NewServiceSolutionCase()}, &synchronized{iModel: model.NewServiceSolutionCaseDetail()},
// 活动管理
&synchronized{iModel: model.NewActivityInstance()}, &synchronized{iModel: model.NewActivityApply()},
&synchronized{iModel: model.NewActivityExamine()}, &synchronized{iModel: model.NewActivityJoin()},

View File

@ -0,0 +1,34 @@
package model
// ServiceSolutionCase 服务解决案例数据模型
type ServiceSolutionCase struct {
Model
Kind ServiceSolutionCaseKind `gorm:"column:kind;type:tinyint(3);default:0;comment:类型" json:"kind"`
Title string `gorm:"column:title;type:varchar(20);default:'';comment:标题" json:"title"`
Image
Sort int `gorm:"column:sort;type:tinyint(3);default:0;comment:排序,数值越大,优先排序" json:"sort"`
ModelDeleted
ModelAt
}
// ServiceSolutionCaseKind 服务解决方案类型
type ServiceSolutionCaseKind int
const (
// ServiceSolutionCaseKindForSmallCompany 中小型企业
ServiceSolutionCaseKindForSmallCompany ServiceSolutionCaseKind = iota + 101
// ServiceSolutionCaseKindForBigCompany 大型企业
ServiceSolutionCaseKindForBigCompany
// ServiceSolutionCaseKindForGovernment 政府单位
ServiceSolutionCaseKindForGovernment
// ServiceSolutionCaseKindForResearch 科研机构
ServiceSolutionCaseKindForResearch
)
func (m *ServiceSolutionCase) TableName() string {
return "service_solution_case"
}
func NewServiceSolutionCase() *ServiceSolutionCase {
return &ServiceSolutionCase{}
}

View File

@ -0,0 +1,23 @@
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{}
}

View File

@ -0,0 +1,15 @@
package model
type SysBanner struct {
Model
ModelDeleted
ModelAt
}
func (m *SysBanner) TableName() string {
return "sys_banner"
}
func NewSysBanner() *SysBanner {
return &SysBanner{}
}

View File

@ -48,6 +48,14 @@ func registerAPI(app *gin.Engine) {
_api := new(api2.Message)
messageV1.POST("/launch", _api.Launch)
}
// ServiceV1 服务信息管理
serviceV1 := v1.Group("/service")
{
_api := new(api2.Service)
serviceV1.GET("/solution_case", _api.SolutionCase)
serviceV1.POST("/solution_case/list", _api.SolutionCaseList)
serviceV1.POST("/solution_case/detail", _api.SolutionCaseDetail)
}
}
// registerAdminAPI 注册API

View File

@ -70,6 +70,10 @@ func HASHIDDecode(src string) int {
hd := hashids.NewData()
hd.Salt = salt
h := hashids.NewWithData(hd)
e, _ := h.DecodeWithError(src)
e, err := h.DecodeWithError(src)
if err != nil {
return 0
}
return e[0]
}