feat:完善项目
This commit is contained in:
@ -106,6 +106,7 @@ func (c *Equipment) Detail(id uint64) (*EquipmentDetail, error) {
|
|||||||
} else if !isExist {
|
} else if !isExist {
|
||||||
return nil, errors.New("操作错误,数据不存在")
|
return nil, errors.New("操作错误,数据不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
out := &EquipmentDetail{
|
out := &EquipmentDetail{
|
||||||
CommonIDString: basic.CommonIDString{ID: mManageEquipment.GetEncodeID()},
|
CommonIDString: basic.CommonIDString{ID: mManageEquipment.GetEncodeID()},
|
||||||
ManageEquipment: mManageEquipment.ManageEquipment,
|
ManageEquipment: mManageEquipment.ManageEquipment,
|
||||||
@ -119,6 +120,7 @@ func (c *Equipment) Detail(id uint64) (*EquipmentDetail, error) {
|
|||||||
if materials, err = mManageEquipmentMaterial.Materials(id); err != nil {
|
if materials, err = mManageEquipmentMaterial.Materials(id); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range materials {
|
for _, v := range materials {
|
||||||
mManageEquipmentMaterial.ID = v.ID
|
mManageEquipmentMaterial.ID = v.ID
|
||||||
|
|
||||||
|
@ -43,8 +43,19 @@ func (c *Supplier) List(name, mobile string, kind model2.ManageSupplierKind, pag
|
|||||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||||
}}
|
}}
|
||||||
if c.TenantID > 0 {
|
if c.TenantID > 0 {
|
||||||
|
// 根据单位由下往上查看信息
|
||||||
|
tenantInfo, err := model.NewSysTenant().Parent(c.TenantID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
tenantIDs := make([]uint64, 0)
|
||||||
|
|
||||||
|
for _, v := range tenantInfo {
|
||||||
|
tenantIDs = append(tenantIDs, v.ID)
|
||||||
|
}
|
||||||
where = append(where, &model2.ModelWhereOrder{
|
where = append(where, &model2.ModelWhereOrder{
|
||||||
Where: model2.NewWhereLike("tenant_id", c.TenantID),
|
Where: model2.NewWhereIn("tenant_id", tenantIDs),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if name != "" {
|
if name != "" {
|
||||||
@ -67,6 +78,7 @@ func (c *Supplier) List(name, mobile string, kind model2.ManageSupplierKind, pag
|
|||||||
if err := model2.Pages(mManageSupplier.ManageSupplier, &out, page, pageSize, &count, where...); err != nil {
|
if err := model2.Pages(mManageSupplier.ManageSupplier, &out, page, pageSize, &count, where...); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
list := make([]*SupplierInfo, 0)
|
list := make([]*SupplierInfo, 0)
|
||||||
|
|
||||||
for _, v := range out {
|
for _, v := range out {
|
||||||
@ -84,6 +96,8 @@ func (c *Supplier) Select(kind int) ([]*SupplierBasic, error) {
|
|||||||
if err := model2.ScanFields(model.NewManageSupplier().ManageSupplier, &out, []string{"id", "name"},
|
if err := model2.ScanFields(model.NewManageSupplier().ManageSupplier, &out, []string{"id", "name"},
|
||||||
&model2.ModelWhereOrder{
|
&model2.ModelWhereOrder{
|
||||||
Where: model2.NewWhere("kind", kind),
|
Where: model2.NewWhere("kind", kind),
|
||||||
|
}, &model2.ModelWhereOrder{
|
||||||
|
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,21 @@ type (
|
|||||||
}
|
}
|
||||||
ManageMaterialInfo struct {
|
ManageMaterialInfo struct {
|
||||||
*model.ManageMaterial
|
*model.ManageMaterial
|
||||||
|
ManufacturerName string `json:"manufacturer_name"`
|
||||||
SupplierName string `json:"supplier_name"`
|
SupplierName string `json:"supplier_name"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Materials 器材信息
|
||||||
func (m *ManageMaterial) Materials(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageMaterialInfo, error) {
|
func (m *ManageMaterial) Materials(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageMaterialInfo, error) {
|
||||||
|
mManageSupplier := model.NewManageSupplier()
|
||||||
|
|
||||||
db := orm.GetDB().Table(m.TableName()+" AS m").
|
db := orm.GetDB().Table(m.TableName()+" AS m").
|
||||||
Select("m.*", "s.name AS supplier_name").
|
Select("m.*", "manufacturer.name AS manufacturer_name", "s.name AS supplier_name").
|
||||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON m.supplier_id = s.id", model.NewManageSupplier().TableName()))
|
Joins(fmt.Sprintf("LEFT JOIN %s AS manufacturer ON m.manufacturer_id = manufacturer.id", mManageSupplier.TableName())).
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS m_d ON m.id = m_d.material_id AND m_d.is_deleted = %d",
|
||||||
|
model.NewManageEquipmentMaterial().TableName(), model.DeleteStatusForNot)).
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON m_d.supplier_id = s.id", mManageSupplier.TableName()))
|
||||||
|
|
||||||
if len(where) > 0 {
|
if len(where) > 0 {
|
||||||
for _, wo := range where {
|
for _, wo := range where {
|
||||||
|
@ -2,6 +2,7 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"ArmedPolice/app/common/model"
|
"ArmedPolice/app/common/model"
|
||||||
|
"ArmedPolice/serve/orm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SysTenant struct {
|
type SysTenant struct {
|
||||||
@ -11,6 +12,8 @@ type SysTenant struct {
|
|||||||
type (
|
type (
|
||||||
// SysTenantBasic 租户基本信息
|
// SysTenantBasic 租户基本信息
|
||||||
SysTenantBasic struct {
|
SysTenantBasic struct {
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
// SysTenantInfo 租户信息
|
// SysTenantInfo 租户信息
|
||||||
SysTenantInfo struct {
|
SysTenantInfo struct {
|
||||||
@ -20,6 +23,22 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Parent 父集元素,包含自己
|
||||||
|
func (m *SysTenant) Parent(tenantID uint64) ([]*SysTenantBasic, error) {
|
||||||
|
sql := `SELECT T2.id, T2.name FROM
|
||||||
|
(SELECT @r AS _id, (SELECT @r := parent_id FROM ? WHERE id = _id) AS parent_id,
|
||||||
|
@l := @l + 1 AS lvl
|
||||||
|
FROM (SELECT @r := ?, @l := 0 ) vars, ? h WHERE @r <> 0) T1
|
||||||
|
JOIN ? T2 ON T1._id = T2.id
|
||||||
|
ORDER BY T1.lvl DESC`
|
||||||
|
|
||||||
|
out := make([]*SysTenantBasic, 0)
|
||||||
|
|
||||||
|
err := orm.GetDB().Raw(sql, m.TableName(), tenantID, m.TableName(), m.TableName()).Scan(&out).Error
|
||||||
|
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
func NewSysTenant() *SysTenant {
|
func NewSysTenant() *SysTenant {
|
||||||
return &SysTenant{SysTenant: model.NewSysTenant()}
|
return &SysTenant{SysTenant: model.NewSysTenant()}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user