feat:完善项目
This commit is contained in:
@ -21,8 +21,10 @@ type (
|
||||
}
|
||||
ManageMaterialInfo struct {
|
||||
*model.ManageMaterial
|
||||
ManufacturerName string `json:"manufacturer_name"` // 制造商
|
||||
SupplierName string `json:"supplier_name"` // 合作商
|
||||
Stock float64 `json:"stock"`
|
||||
FrozenStock float64 `json:"frozen_stock"`
|
||||
ManufacturerName string `json:"manufacturer_name"` // 制造商
|
||||
SupplierName string `json:"supplier_name"` // 合作商
|
||||
}
|
||||
)
|
||||
|
||||
@ -53,11 +55,12 @@ func (m *ManageMaterial) Materials(page, pageSize int, count *int64, where ...*m
|
||||
mManageSupplier := model.NewManageSupplier()
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS m").
|
||||
Select("m.*", "manufacturer.name AS manufacturer_name", "s.name AS supplier_name").
|
||||
Select("m.*", "manufacturer.name AS manufacturer_name", "s.name AS supplier_name", "m_s.stock", "m_s.frozen_stock").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS manufacturer ON m.manufacturer_id = manufacturer.id", mManageSupplier.TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS m_s ON m.id = m_s.material_id AND m_s.is_deleted = %d",
|
||||
model.NewManageMaterialSupplier().TableName(), model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON m_s.supplier_id = s.id", mManageSupplier.TableName()))
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON m_s.supplier_id = s.id", mManageSupplier.TableName())).
|
||||
Where("m.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
@ -69,7 +72,7 @@ func (m *ManageMaterial) Materials(page, pageSize int, count *int64, where ...*m
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("p.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
if err := db.Order("m.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
|
@ -36,5 +36,5 @@ func (m *ManageMaterialSupplier) Basic(where ...*model.ModelWhere) ([]*ManageMat
|
||||
}
|
||||
|
||||
func NewManageMaterialSupplier() *ManageMaterialSupplier {
|
||||
return &ManageMaterialSupplier{}
|
||||
return &ManageMaterialSupplier{model.NewManageMaterialSupplier()}
|
||||
}
|
||||
|
@ -12,20 +12,29 @@ type WorkInstance struct {
|
||||
*model.WorkInstance
|
||||
}
|
||||
|
||||
// WorkInstanceInfo 基本信息
|
||||
type WorkInstanceInfo struct {
|
||||
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"`
|
||||
}
|
||||
type (
|
||||
// WorkInstanceInfo 基本信息
|
||||
WorkInstanceInfo struct {
|
||||
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"`
|
||||
Username string `json:"username"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
// WorkInstanceStaticInfo 基本统计信息
|
||||
WorkInstanceStaticInfo struct {
|
||||
Count int64 `json:"count"`
|
||||
Amount float64 `json:"amount"`
|
||||
Date string `json:"date"`
|
||||
}
|
||||
)
|
||||
|
||||
// WorkbenchCondition 工作台条件
|
||||
type WorkbenchCondition struct {
|
||||
@ -33,6 +42,13 @@ type WorkbenchCondition struct {
|
||||
RoleIDs []string
|
||||
}
|
||||
|
||||
func (m *WorkbenchCondition) roleInfo() string {
|
||||
if len(m.RoleIDs) <= 0 {
|
||||
return "''"
|
||||
}
|
||||
return strings.Join(m.RoleIDs, ",")
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (m *WorkInstance) Detail(id uint64) (*WorkInstanceInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
@ -56,9 +72,10 @@ func (m *WorkInstance) Instances(page, pageSize int, count *int64, where ...*mod
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
Select("w.id", "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.status", "w.created_at").
|
||||
"s.title AS schedule_title", "w.status", "u.name AS username", "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())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON w.uid = u.uuid", model.NewSysUser().TableName())).
|
||||
Where("w.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
@ -79,20 +96,15 @@ func (m *WorkInstance) Instances(page, pageSize int, count *int64, where ...*mod
|
||||
}
|
||||
|
||||
// Persons 个人信息
|
||||
func (m *WorkInstance) Persons(uid uint64, kind model.WorkScheduleKind, page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) {
|
||||
mWorkSchedule := model.NewWorkSchedule()
|
||||
func (m *WorkInstance) Persons(uid uint64, page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) {
|
||||
|
||||
db := orm.GetDB().Table(model.NewWorkProgress().TableName()+" AS p").
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
Select("w.id", "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.status", "w.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS w ON p.work_id = w.id", m.TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS e ON w.equipment_id = e.id", model.NewManageEquipment().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT id, title FROM %s WHERE kind = %d ORDER BY stage ASC, step ASC limit 1) AS s ON p.schedule_id = s.id",
|
||||
mWorkSchedule.TableName(), kind)).
|
||||
Where("p.is_deleted = ? AND w.is_deleted = ?", model.DeleteStatusForNot, model.DeleteStatusForNot).
|
||||
Where("p.uid = ?", uid).
|
||||
Where("s.id > ?", 0)
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON w.schedule = s.id", model.NewWorkSchedule().TableName())).
|
||||
Where("w.uid = ? AND w.is_deleted = ?", uid, model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
@ -111,7 +123,7 @@ func (m *WorkInstance) Persons(uid uint64, kind model.WorkScheduleKind, page, pa
|
||||
}
|
||||
|
||||
// Workbench 个人信息
|
||||
func (m *WorkInstance) Workbench(condition *WorkbenchCondition, page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) {
|
||||
func (m *WorkInstance) Workbench(condition *WorkbenchCondition, limit int, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) {
|
||||
mWorkSchedule := model.NewWorkSchedule()
|
||||
|
||||
_condition := fmt.Sprintf(`CASE %s
|
||||
@ -123,7 +135,44 @@ ELSE "" END`, "s.target",
|
||||
model.WorkScheduleTargetForPerson,
|
||||
mWorkSchedule.TableName(), model.WorkScheduleTargetForPerson, condition.UID,
|
||||
model.WorkScheduleTargetForRole,
|
||||
mWorkSchedule.TableName(), model.WorkScheduleTargetForRole, strings.Join(condition.RoleIDs, ","))
|
||||
mWorkSchedule.TableName(), model.WorkScheduleTargetForRole, condition.roleInfo())
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
Select("w.id", "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.status", "u.name AS username", "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", mWorkSchedule.TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON w.uid = u.uuid", model.NewSysUser().TableName())).
|
||||
Where("w.is_deleted = ?", model.DeleteStatusForNot).
|
||||
Where(fmt.Sprintf("FIND_IN_SET(w.schedule, %s)", _condition))
|
||||
|
||||
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).Limit(limit).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (m *WorkInstance) Workbenchs(condition *WorkbenchCondition, page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkInstanceInfo, error) {
|
||||
mWorkSchedule := model.NewWorkSchedule()
|
||||
|
||||
_condition := fmt.Sprintf(`CASE %s
|
||||
WHEN %d THEN
|
||||
(SELECT GROUP_CONCAT(a.id) FROM (SELECT id FROM %s WHERE target = %d AND target_value IN (%s)) AS a)
|
||||
WHEN %d THEN
|
||||
(SELECT GROUP_CONCAT(a.id) FROM (SELECT id FROM %s WHERE target = %d AND target_value IN (%s)) AS a)
|
||||
ELSE "" END`, "s.target",
|
||||
model.WorkScheduleTargetForPerson,
|
||||
mWorkSchedule.TableName(), model.WorkScheduleTargetForPerson, condition.UID,
|
||||
model.WorkScheduleTargetForRole,
|
||||
mWorkSchedule.TableName(), model.WorkScheduleTargetForRole, condition.roleInfo())
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
Select("w.id", "w.title", "e.code AS equipment_code", "e.title AS equipment_title", "w.priority",
|
||||
@ -150,6 +199,27 @@ ELSE "" END`, "s.target",
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (m *WorkInstance) Static(where ...*model.ModelWhere) ([]*WorkInstanceStaticInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
Select("COUNT(w.id) AS count", "SUM(m.price * w_m.material_number) AS amount",
|
||||
"SUBSTRING(w.created_at, 1, 10) AS date").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS w_m ON w.id = w_m.work_id", model.NewWorkMaterial().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS m ON w_m.material_id = m.id", model.NewManageMaterial().TableName())).
|
||||
Where("w.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*WorkInstanceStaticInfo, 0)
|
||||
|
||||
if err := db.Group("SUBSTRING(w.created_at, 1, 10)").Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewWorkInstance() *WorkInstance {
|
||||
return &WorkInstance{model.NewWorkInstance()}
|
||||
}
|
||||
|
Reference in New Issue
Block a user