feat:完善项目
This commit is contained in:
11
app/model/sys_breakdown.go
Normal file
11
app/model/sys_breakdown.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "ArmedPolice/app/common/model"
|
||||
|
||||
type SysBreakdown struct {
|
||||
*model.SysBreakdown
|
||||
}
|
||||
|
||||
func NewSysBreakdown() *SysBreakdown {
|
||||
return &SysBreakdown{}
|
||||
}
|
54
app/model/work_instance.go
Normal file
54
app/model/work_instance.go
Normal file
@ -0,0 +1,54 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/common/model"
|
||||
"ArmedPolice/serve/orm"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type WorkInstance struct {
|
||||
*model.WorkInstance
|
||||
}
|
||||
|
||||
// WorkInstanceInfo 基本信息
|
||||
type WorkInstanceInfo struct {
|
||||
ID uint64 `json:"-"`
|
||||
Title string `json:"title"`
|
||||
MaterialCode string `json:"material_code"`
|
||||
MaterialTitle string `json:"material_title"`
|
||||
BreakdownTitle string `json:"breakdown_title"`
|
||||
Priority int `json:"priority"`
|
||||
Status int `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// Instances 基本信息
|
||||
func (m *WorkInstance) Instances(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
Select("w.id", "w.title", "m.code AS material_code", "m.title AS material_title", "w.priority",
|
||||
"GROUP_CONCAT(b.title) AS breakdown_title", "w.status", "w.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS m ON w.material_id = m.id", model.NewManageMaterial().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS b ON FIND_IN_SET(b.id, w.breakdown)", model.NewSysBreakdown().TableName())).
|
||||
Where("w.is_deleted = ?", model.DeleteStatusForNot).
|
||||
Group("w.id")
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*WorkInstanceInfo, 0)
|
||||
|
||||
if err := db.Order("w.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewWorkInstance() *WorkInstance {
|
||||
return &WorkInstance{model.NewWorkInstance()}
|
||||
}
|
Reference in New Issue
Block a user