feat:完善项目
This commit is contained in:
@ -24,6 +24,7 @@ type (
|
||||
// EquipmentInfo 装备信息
|
||||
EquipmentInfo struct {
|
||||
basic.CommonIDString
|
||||
ParentID string `json:"parent_id"`
|
||||
Code string `json:"code"`
|
||||
Title string `json:"title"`
|
||||
Image string `json:"image"`
|
||||
@ -39,7 +40,7 @@ type (
|
||||
}
|
||||
// EquipmentMaterialDetail 装备器材信息
|
||||
EquipmentMaterialDetail struct {
|
||||
*model.ManageEquipmentMaterialInfo
|
||||
*model.ManageMaterialBasic
|
||||
ID string `json:"id"`
|
||||
}
|
||||
// EquipmentParams 装备参数信息
|
||||
@ -63,8 +64,15 @@ func (c *Equipment) tree(iModel model2.IModel, src []*model2.ManageEquipment, pa
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
parentID := ""
|
||||
|
||||
if v.ParentID > 0 {
|
||||
iModel.SetID(v.ParentID)
|
||||
parentID = iModel.GetEncodeID()
|
||||
}
|
||||
out = append(out, &EquipmentInfo{
|
||||
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
|
||||
ParentID: parentID,
|
||||
Code: v.Code,
|
||||
Title: v.Title,
|
||||
Image: v.Analysis(config.SettingInfo.Domain),
|
||||
@ -95,23 +103,26 @@ func (c *Equipment) List(parentID uint64, title string, page, pageSize int) (*ba
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := model2.PagesFields(mManageEquipment.ManageEquipment, &out, []string{"id", "code", "title", "image", "created_at"},
|
||||
if err := model2.PagesFields(mManageEquipment.ManageEquipment, &out, []string{"id", "parent_id", "code", "title", "image", "created_at"},
|
||||
page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &basic.PageDataResponse{
|
||||
Data: c.tree(mManageEquipment.ManageEquipment, out, 0),
|
||||
Data: c.tree(mManageEquipment.ManageEquipment, out, parentID),
|
||||
Count: count,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Select 筛选信息
|
||||
func (c *Equipment) Select() ([]*EquipmentBasic, error) {
|
||||
func (c *Equipment) Select(parentID uint64) ([]*EquipmentBasic, error) {
|
||||
mManageEquipment := model.NewManageEquipment()
|
||||
|
||||
out := make([]*model2.ManageEquipment, 0)
|
||||
|
||||
if err := model2.ScanFields(mManageEquipment.ManageEquipment, &out, []string{"id", "code", "title"}); err != nil {
|
||||
where := []*model2.ModelWhereOrder{
|
||||
&model2.ModelWhereOrder{Where: model2.NewWhere("parent_id", parentID)},
|
||||
}
|
||||
if err := model2.ScanFields(mManageEquipment.ManageEquipment, &out, []string{"id", "code", "title"}, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*EquipmentBasic, 0)
|
||||
@ -119,8 +130,7 @@ func (c *Equipment) Select() ([]*EquipmentBasic, error) {
|
||||
for _, v := range out {
|
||||
list = append(list, &EquipmentBasic{
|
||||
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
|
||||
Code: v.Code,
|
||||
Title: v.Title,
|
||||
Code: v.Code, Title: v.Title,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
@ -146,7 +156,7 @@ func (c *Equipment) Detail(id uint64) (*EquipmentDetail, error) {
|
||||
}
|
||||
mManageEquipmentMaterial := model.NewManageEquipmentMaterial()
|
||||
|
||||
materials := make([]*model.ManageEquipmentMaterialInfo, 0)
|
||||
materials := make([]*model.ManageMaterialBasic, 0)
|
||||
|
||||
if materials, err = mManageEquipmentMaterial.Materials(id); err != nil {
|
||||
return nil, err
|
||||
@ -156,8 +166,8 @@ func (c *Equipment) Detail(id uint64) (*EquipmentDetail, error) {
|
||||
mManageEquipmentMaterial.ID = v.ID
|
||||
|
||||
out.Materials = append(out.Materials, &EquipmentMaterialDetail{
|
||||
ManageEquipmentMaterialInfo: v,
|
||||
ID: mManageEquipmentMaterial.GetEncodeID(),
|
||||
ManageMaterialBasic: v,
|
||||
ID: mManageEquipmentMaterial.GetEncodeID(),
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
|
86
app/controller/manage/equipment_material.go
Normal file
86
app/controller/manage/equipment_material.go
Normal file
@ -0,0 +1,86 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
model2 "ArmedPolice/app/common/model"
|
||||
"ArmedPolice/app/controller/basic"
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"ArmedPolice/serve/orm"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type EquipmentMaterial struct{ *service.Session }
|
||||
|
||||
type EquipmentMaterialHandle func(session *service.Session) *EquipmentMaterial
|
||||
|
||||
type (
|
||||
// EquipmentMaterialInfo 装备器材信息
|
||||
EquipmentMaterialInfo struct {
|
||||
*model.ManageMaterialBasic
|
||||
basic.CommonIDString
|
||||
}
|
||||
EquipmentMaterialBindParams struct {
|
||||
EquipmentID uint64
|
||||
MaterialIDs []uint64
|
||||
}
|
||||
)
|
||||
|
||||
// List 列表信息
|
||||
func (c *EquipmentMaterial) List(equipmentID uint64) ([]*EquipmentMaterialInfo, error) {
|
||||
mManageEquipmentMaterial := model.NewManageEquipmentMaterial()
|
||||
|
||||
out, err := mManageEquipmentMaterial.Materials(equipmentID)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*EquipmentMaterialInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
mManageEquipmentMaterial.ID = v.ID
|
||||
|
||||
list = append(list, &EquipmentMaterialInfo{
|
||||
CommonIDString: basic.CommonIDString{ID: mManageEquipmentMaterial.GetEncodeID()},
|
||||
ManageMaterialBasic: v,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// Bind 绑定操作
|
||||
func (c *EquipmentMaterial) Bind(params *EquipmentMaterialBindParams) error {
|
||||
mManageEquipmentMaterial := model.NewManageEquipmentMaterial()
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
err := model2.DeleteWhere(mManageEquipmentMaterial.ManageEquipmentMaterial, []*model2.ModelWhere{
|
||||
model2.NewWhere("equipment_id", params.EquipmentID),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
list := make([]*model2.ManageEquipmentMaterial, 0)
|
||||
|
||||
for _, v := range params.MaterialIDs {
|
||||
list = append(list, &model2.ManageEquipmentMaterial{
|
||||
EquipmentID: params.EquipmentID,
|
||||
MaterialID: v,
|
||||
})
|
||||
}
|
||||
if len(list) > 0 {
|
||||
return model2.Creates(mManageEquipmentMaterial.ManageEquipmentMaterial, list)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (c *EquipmentMaterial) Delete(id uint64) error {
|
||||
mManageEquipmentMaterial := model.NewManageEquipmentMaterial()
|
||||
mManageEquipmentMaterial.ID = id
|
||||
return model2.Delete(mManageEquipmentMaterial.ManageEquipmentMaterial)
|
||||
}
|
||||
|
||||
func NewEquipmentMaterial() EquipmentMaterialHandle {
|
||||
return func(session *service.Session) *EquipmentMaterial {
|
||||
return &EquipmentMaterial{session}
|
||||
}
|
||||
}
|
@ -19,17 +19,26 @@ type NoticeInfo struct {
|
||||
}
|
||||
|
||||
// List 列表信息
|
||||
func (c *Notice) List(page, pageSize int) (*basic.PageDataResponse, error) {
|
||||
func (c *Notice) List(title string, page, pageSize int) (*basic.PageDataResponse, error) {
|
||||
mManageNotice := model.NewManageNotice()
|
||||
|
||||
out := make([]*model2.ManageNotice, 0)
|
||||
|
||||
var count int64
|
||||
|
||||
if err := model2.Pages(mManageNotice.ManageNotice, &out, page, pageSize, &count, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
}); err != nil {
|
||||
where := []*model2.ModelWhereOrder{
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
},
|
||||
}
|
||||
|
||||
if title != "" {
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereLike("title", title),
|
||||
})
|
||||
}
|
||||
if err := model2.Pages(mManageNotice.ManageNotice, &out, page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*NoticeInfo, 0)
|
||||
@ -69,6 +78,7 @@ func (c *Notice) Form(id uint64, title, content string) error {
|
||||
"title": title, "content": content, "updated_at": time.Now(),
|
||||
})
|
||||
}
|
||||
mManageNotice.TenantID = c.TenantID
|
||||
mManageNotice.Title = title
|
||||
mManageNotice.Content = content
|
||||
return model2.Create(mManageNotice)
|
||||
|
Reference in New Issue
Block a user