feat:完善项目
This commit is contained in:
@ -1,11 +1,3 @@
|
||||
name:
|
||||
# domain 域名
|
||||
domain: http://127.0.0.1:8000
|
||||
# token有效时间(秒)
|
||||
token_effect_time: 604800
|
||||
# multiple_login 多地登录
|
||||
multiple_login: true
|
||||
|
||||
server:
|
||||
port: 8000
|
||||
read_timeout: 5
|
||||
|
@ -165,3 +165,39 @@ func (*Technology) PaperDelete(c *gin.Context) {
|
||||
err := technology.NewPaper()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) Product(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
Title string `json:"title" form:"title"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology.NewProduct()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert(), form.Title, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Technology) ProductDetail(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology.NewProduct()(api.GetSession()(c).(*session.Admin)).Detail(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Technology) ProductDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology.NewProduct()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
101
app/api/admin/controller/technology/product.go
Normal file
101
app/api/admin/controller/technology/product.go
Normal file
@ -0,0 +1,101 @@
|
||||
package technology
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Product struct {
|
||||
*session.Admin
|
||||
}
|
||||
|
||||
type ProductHandle func(session *session.Admin) *Product
|
||||
|
||||
type (
|
||||
// ProductInfo 产品信息
|
||||
ProductInfo struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
// ProductDetailInfo 产品详细信息
|
||||
ProductDetailInfo struct {
|
||||
ID string `json:"id"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
*model2.TechnologyProduct
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Product) Instance(tenantID uint64, title string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mTechnologyProduct := model.NewTechnologyProduct()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if c.TenantID > 0 {
|
||||
where = append(where, model2.NewWhere("p.tenant_id", c.TenantID))
|
||||
}
|
||||
if tenantID > 0 {
|
||||
where = append(where, model2.NewWhere("p.tenant_id", tenantID))
|
||||
}
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("p.title", title))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mTechnologyProduct.Product(page, pageSize, &count)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*ProductInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &ProductInfo{ID: v.GetEncodeID()})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, err
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *Product) Detail(id uint64) (*ProductDetailInfo, error) {
|
||||
mTechnologyProduct := model.NewTechnologyProduct()
|
||||
mTechnologyProduct.ID = id
|
||||
|
||||
isExist, err := model2.First(mTechnologyProduct.TechnologyProduct)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,产品信息不存在或已被删除")
|
||||
}
|
||||
return &ProductDetailInfo{
|
||||
ID: mTechnologyProduct.GetEncodeID(),
|
||||
TenantID: mTechnologyProduct.GetEncodeTenantID(),
|
||||
TechnologyProduct: mTechnologyProduct.TechnologyProduct,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Product) Form() {
|
||||
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Product) Delete(id uint64) error {
|
||||
mTechnologyProduct := model.NewTechnologyProduct()
|
||||
mTechnologyProduct.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mTechnologyProduct.TechnologyProduct, []string{"id", "tenant_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,产品信息不存在或已被删除")
|
||||
}
|
||||
return model2.Delete(mTechnologyProduct.TechnologyProduct)
|
||||
}
|
||||
|
||||
func NewProduct() ProductHandle {
|
||||
return func(session *session.Admin) *Product {
|
||||
return &Product{session}
|
||||
}
|
||||
}
|
42
app/api/admin/model/technology_product.go
Normal file
42
app/api/admin/model/technology_product.go
Normal file
@ -0,0 +1,42 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type TechnologyProduct struct {
|
||||
*model.TechnologyProduct
|
||||
}
|
||||
|
||||
type TechnologyProductInfo struct {
|
||||
model.Model
|
||||
model.Area
|
||||
}
|
||||
|
||||
// Product 产品信息
|
||||
func (m *TechnologyProduct) Product(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyProductInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName() + " AS p").
|
||||
Select("p.id").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON p.tenant_id = t.id", model.NewSysTenant().TableName()))
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*TechnologyProductInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("p.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewTechnologyProduct() *TechnologyProduct {
|
||||
return &TechnologyProduct{model.NewTechnologyProduct()}
|
||||
}
|
@ -319,6 +319,9 @@ func registerAdminAPI(app *gin.Engine) {
|
||||
technology.POST("/paper", _api.Paper)
|
||||
technology.POST("/paper/detail", _api.PaperDetail)
|
||||
technology.POST("/paper/delete", _api.PaperDelete)
|
||||
technology.POST("/product", _api.Product)
|
||||
technology.POST("/product/detail", _api.ProductDetail)
|
||||
technology.POST("/product/delete", _api.ProductDelete)
|
||||
}
|
||||
// Activity 活动管理
|
||||
activity := v1.Group("/activity")
|
||||
|
@ -37,10 +37,13 @@ func (this *Router) Init() *gin.Engine {
|
||||
if this.IsCors {
|
||||
app.Use(Cors())
|
||||
}
|
||||
app.LoadHTMLFiles("./dist/*") // 添加资源路径
|
||||
//app.LoadHTMLFiles("./dist/*") // 添加资源路径
|
||||
app.LoadHTMLGlob("./dist/index.html") // 添加资源路径
|
||||
app.StaticFS("/static", http.Dir("./dist/static"))
|
||||
app.StaticFile("/", "dist/index.html") //前端接口
|
||||
|
||||
app.GET("", func(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "index.html", nil)
|
||||
})
|
||||
//app.NoRoute(NoRouteHandler())
|
||||
app.NoMethod(NoMethodHandler())
|
||||
app.Use(LoggerHandle("log/gin.log", 3))
|
||||
|
Reference in New Issue
Block a user