feat:完善项目
This commit is contained in:
@ -35,6 +35,6 @@ func (m *ManageMaterialSupplier) Basic(where ...*model.ModelWhere) ([]*ManageMat
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewManageMaterSupplier() *ManageMaterialSupplier {
|
||||
func NewManageMaterialSupplier() *ManageMaterialSupplier {
|
||||
return &ManageMaterialSupplier{}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package model
|
||||
import (
|
||||
"ArmedPolice/app/common/model"
|
||||
"ArmedPolice/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SysTenant struct {
|
||||
@ -25,16 +26,16 @@ 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
|
||||
sql := `SELECT T2.id, T2.name FROM
|
||||
(SELECT @r AS _id, (SELECT @r := parent_id FROM %s WHERE id = _id) AS parent_id,
|
||||
@l := @l + 1 AS lvl
|
||||
FROM (SELECT @r := %d, @l := 0 ) vars, %s h WHERE @r <> 0) T1
|
||||
JOIN %s 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
|
||||
err := orm.GetDB().Raw(fmt.Sprintf(sql, m.TableName(), tenantID, m.TableName(), m.TableName())).Scan(&out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
@ -14,15 +14,17 @@ type WorkInstance struct {
|
||||
|
||||
// WorkInstanceInfo 基本信息
|
||||
type WorkInstanceInfo struct {
|
||||
ID uint64 `json:"-"`
|
||||
Title string `json:"title"`
|
||||
EquipmentCode string `json:"equipment_code"`
|
||||
EquipmentTitle string `json:"equipment_title"`
|
||||
BreakdownTitle string `json:"breakdown_title"`
|
||||
ScheduleTitle string `json:"schedule_title"`
|
||||
Priority int `json:"priority"`
|
||||
Status int `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ID uint64 `json:"-"`
|
||||
Title string `json:"title"`
|
||||
Kind model.WorkInstanceKind `json:"kind"`
|
||||
EquipmentCode string `json:"equipment_code"`
|
||||
EquipmentTitle string `json:"equipment_title"`
|
||||
BreakdownTitle string `json:"breakdown_title"`
|
||||
ScheduleTitle string `json:"schedule_title"`
|
||||
Priority int `json:"priority"`
|
||||
Distribution string `json:"distribution"`
|
||||
Status int `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// WorkbenchCondition 工作台条件
|
||||
@ -31,6 +33,24 @@ type WorkbenchCondition struct {
|
||||
RoleIDs []string
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (m *WorkInstance) Detail(id uint64) (*WorkInstanceInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
Select("w.id", "w.kind", "w.title", "e.code AS equipment_code", "e.title AS equipment_title", "w.priority",
|
||||
"(SELECT GROUP_CONCAT(s_b.title) FROM ( SELECT id, title FROM sys_breakdown) AS s_b WHERE FIND_IN_SET( s_b.id, w.breakdown )) AS breakdown_title",
|
||||
"s.title AS schedule_title", "w.distribution", "w.status", "w.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS e ON w.equipment_id = e.id", model.NewManageEquipment().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON w.schedule = s.id", model.NewWorkSchedule().TableName())).
|
||||
Where("w.id = ?", id)
|
||||
|
||||
out := new(WorkInstanceInfo)
|
||||
|
||||
if err := db.Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Instances 基本信息
|
||||
func (m *WorkInstance) Instances(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
|
42
app/model/work_material.go
Normal file
42
app/model/work_material.go
Normal file
@ -0,0 +1,42 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/common/model"
|
||||
"ArmedPolice/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type WorkMaterial struct {
|
||||
*model.WorkMaterial
|
||||
}
|
||||
|
||||
// WorkMaterialInfo 器材信息
|
||||
type WorkMaterialInfo struct {
|
||||
ID uint64 `json:"-"`
|
||||
MaterialNumber float64 `json:"material_number"`
|
||||
MaterialCode string `json:"material_code"`
|
||||
MaterialTitle string `json:"material_title"`
|
||||
MaterialPrice float64 `json:"material_price"`
|
||||
SupplierName string `json:"supplier_name"`
|
||||
}
|
||||
|
||||
// Materials 器材信息
|
||||
func (m *WorkMaterial) Materials(workID uint64) ([]*WorkMaterialInfo, error) {
|
||||
out := make([]*WorkMaterialInfo, 0)
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" w").
|
||||
Select("w.id", "w.material_number", "m.code AS material_code", "m.title AS material_title",
|
||||
"m.price AS material_price", "s.name AS supplier_name").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS m ON w.material_id = m.id", model.NewManageMaterial().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON w.material_supplier_id = s.id", model.NewManageSupplier().TableName())).
|
||||
Where("w.work_id = ?", workID)
|
||||
|
||||
if err := db.Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewWorkMaterial() *WorkMaterial {
|
||||
return &WorkMaterial{model.NewWorkMaterial()}
|
||||
}
|
Reference in New Issue
Block a user