feat:完善项目
This commit is contained in:
@ -18,16 +18,23 @@ type (
|
||||
// EquipmentInfo 装备信息
|
||||
EquipmentInfo struct {
|
||||
basic.CommonIDString
|
||||
Code string `json:"code"`
|
||||
Title string `json:"title"`
|
||||
Image string `json:"image"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Code string `json:"code"`
|
||||
Title string `json:"title"`
|
||||
Image string `json:"image"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Children []*EquipmentInfo `json:"children"`
|
||||
}
|
||||
// EquipmentDetail 装备详细信息
|
||||
EquipmentDetail struct {
|
||||
basic.CommonIDString
|
||||
*model2.ManageEquipment
|
||||
Image string `json:"image"`
|
||||
Image string `json:"image"`
|
||||
Materials []*EquipmentMaterialDetail `json:"materials"`
|
||||
}
|
||||
// EquipmentMaterialDetail 装备器材信息
|
||||
EquipmentMaterialDetail struct {
|
||||
*model.ManageEquipmentMaterialInfo
|
||||
ID string `json:"id"`
|
||||
}
|
||||
// EquipmentParams 装备参数信息
|
||||
EquipmentParams struct {
|
||||
@ -45,8 +52,26 @@ func (c *EquipmentParams) isExist(iModel model2.IModel) (bool, error) {
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func (c *Equipment) tree(src []*model2.ManageEquipment, parentID uint64) []*EquipmentInfo {
|
||||
out := make([]*EquipmentInfo, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &EquipmentInfo{
|
||||
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
|
||||
Code: v.Code,
|
||||
Title: v.Title,
|
||||
Image: v.Analysis(config.SettingInfo.Domain),
|
||||
CreatedAt: v.CreatedAt,
|
||||
Children: c.tree(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// List 列表信息
|
||||
func (c *Equipment) List(title string, page, pageSize int) (*basic.PageDataResponse, error) {
|
||||
func (c *Equipment) List(title string, page, pageSize int) ([]*EquipmentInfo, error) {
|
||||
mManageEquipment := model.NewManageEquipment()
|
||||
|
||||
out := make([]*model2.ManageEquipment, 0)
|
||||
@ -61,23 +86,12 @@ func (c *Equipment) List(title string, page, pageSize int) (*basic.PageDataRespo
|
||||
Where: model2.NewWhereLike("title", title),
|
||||
})
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := model2.PagesFields(mManageEquipment.ManageEquipment, &out, []string{"id", "code", "title", "image", "created_at"},
|
||||
page, pageSize, &count, where...); err != nil {
|
||||
if err := model2.ScanFields(mManageEquipment.ManageEquipment, &out, []string{"id", "code", "title", "image", "created_at"},
|
||||
where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*EquipmentInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &EquipmentInfo{
|
||||
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
|
||||
Code: v.Code, Title: v.Title,
|
||||
Image: v.Image.Analysis(config.SettingInfo.Domain),
|
||||
CreatedAt: v.CreatedAt,
|
||||
})
|
||||
}
|
||||
return &basic.PageDataResponse{Data: list, Count: count}, nil
|
||||
return c.tree(out, 0), nil
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
@ -85,16 +99,35 @@ func (c *Equipment) Detail(id uint64) (*EquipmentDetail, error) {
|
||||
mManageEquipment := model.NewManageEquipment()
|
||||
mManageEquipment.ID = id
|
||||
|
||||
if isExist, err := model2.FirstWhere(mManageEquipment.ManageEquipment); err != nil {
|
||||
isExist, err := model2.FirstWhere(mManageEquipment.ManageEquipment)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("")
|
||||
return nil, errors.New("操作错误,数据不存在")
|
||||
}
|
||||
return &EquipmentDetail{
|
||||
out := &EquipmentDetail{
|
||||
CommonIDString: basic.CommonIDString{ID: mManageEquipment.GetEncodeID()},
|
||||
ManageEquipment: mManageEquipment.ManageEquipment,
|
||||
Image: mManageEquipment.Analysis(config.SettingInfo.Domain),
|
||||
}, nil
|
||||
Materials: make([]*EquipmentMaterialDetail, 0),
|
||||
}
|
||||
mManageEquipmentMaterial := model.NewManageEquipmentMaterial()
|
||||
|
||||
materials := make([]*model.ManageEquipmentMaterialInfo, 0)
|
||||
|
||||
if materials, err = mManageEquipmentMaterial.Materials(id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range materials {
|
||||
mManageEquipmentMaterial.ID = v.ID
|
||||
|
||||
out.Materials = append(out.Materials, &EquipmentMaterialDetail{
|
||||
ManageEquipmentMaterialInfo: v,
|
||||
ID: mManageEquipmentMaterial.GetEncodeID(),
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Form 数据处理
|
||||
|
Reference in New Issue
Block a user