feat:完善信息
This commit is contained in:
111
app/api/enterprise/controller/technology/equipment.go
Normal file
111
app/api/enterprise/controller/technology/equipment.go
Normal file
@ -0,0 +1,111 @@
|
||||
package technology
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Equipment struct {
|
||||
*service.SessionEnterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type EquipmentHandle func(enterprise *service.SessionEnterprise, local string) *Equipment
|
||||
|
||||
type EquipmentParams struct {
|
||||
ID uint64
|
||||
Title, Research, Describe string
|
||||
}
|
||||
|
||||
type EquipmentInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.TechnologyEquipment
|
||||
}
|
||||
|
||||
// List 列表信息
|
||||
func (c *Equipment) List(title string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mTechnologyEquipment := model.NewTechnologyEquipment()
|
||||
|
||||
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
}, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("local", c.local),
|
||||
}}
|
||||
|
||||
if title != "" {
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereLike("title", title),
|
||||
})
|
||||
}
|
||||
out := make([]*model2.TechnologyEquipment, 0)
|
||||
|
||||
var count int64
|
||||
|
||||
if err := model2.Pages(mTechnologyEquipment.TechnologyEquipment, &out, page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*EquipmentInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &EquipmentInfo{
|
||||
ID: v.GetEncodeID(), TechnologyEquipment: v,
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
func (c *Equipment) Form(params *EquipmentParams) error {
|
||||
mTechnologyEquipment := model.NewTechnologyEquipment()
|
||||
|
||||
if params.ID > 0 {
|
||||
mTechnologyEquipment.ID = params.ID
|
||||
|
||||
isExist, err := model2.First(mTechnologyEquipment.TechnologyEquipment)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,设备信息不存在")
|
||||
} else if mTechnologyEquipment.Local.Local != c.local {
|
||||
return errors.New("无权限操作")
|
||||
}
|
||||
}
|
||||
mTechnologyEquipment.Title = params.Title
|
||||
mTechnologyEquipment.Research = params.Research
|
||||
mTechnologyEquipment.Describe = params.Describe
|
||||
|
||||
if mTechnologyEquipment.ID > 0 {
|
||||
return model2.Updates(mTechnologyEquipment.TechnologyEquipment, mTechnologyEquipment.TechnologyEquipment)
|
||||
}
|
||||
return model2.Create(mTechnologyEquipment.TechnologyEquipment)
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Equipment) Delete(id uint64) error {
|
||||
mTechnologyEquipment := model.NewTechnologyEquipment()
|
||||
mTechnologyEquipment.ID = id
|
||||
|
||||
isExist, err := model2.First(mTechnologyEquipment.TechnologyEquipment)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,设备信息不存在")
|
||||
} else if mTechnologyEquipment.Local.Local != c.local {
|
||||
return errors.New("无权限操作")
|
||||
}
|
||||
return model2.Delete(mTechnologyEquipment.TechnologyEquipment)
|
||||
}
|
||||
|
||||
func NewEquipment() EquipmentHandle {
|
||||
return func(enterprise *service.SessionEnterprise, local string) *Equipment {
|
||||
return &Equipment{
|
||||
SessionEnterprise: enterprise,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user