|
@@ -0,0 +1,112 @@
|
|
|
+package edb_inspection
|
|
|
+
|
|
|
+import (
|
|
|
+ "eta/eta_api/global"
|
|
|
+ "eta/eta_api/utils"
|
|
|
+ "time"
|
|
|
+
|
|
|
+ "gorm.io/gorm"
|
|
|
+)
|
|
|
+
|
|
|
+// EdbInspectionDashboard
|
|
|
+// @Description: 巡检看板表
|
|
|
+type EdbInspectionDashboard struct {
|
|
|
+ DashboardId int64 `gorm:"column:dashboard_id;primaryKey;autoIncrement" description:"巡检看板ID"`
|
|
|
+ Source int `gorm:"column:source" description:"数据源ID"`
|
|
|
+ TerminalCode string `gorm:"column:terminal_code" description:"终端编码"`
|
|
|
+ InspectionRecordId int64 `gorm:"column:inspection_record_id" description:"巡检记录ID"`
|
|
|
+ InspectionTime time.Time `gorm:"column:inspection_time" description:"巡检时间"`
|
|
|
+ InspectionResult int8 `gorm:"column:inspection_result" description:"巡检结果(1:成功,2:失败)"`
|
|
|
+ ErrorReason string `gorm:"column:error_reason" description:"错误原因"`
|
|
|
+ CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
|
|
|
+ ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
|
|
|
+}
|
|
|
+
|
|
|
+// Add
|
|
|
+// @Description: 添加巡检看板记录
|
|
|
+// @receiver m
|
|
|
+// @return err error
|
|
|
+func (m *EdbInspectionDashboard) Add() (err error) {
|
|
|
+ m.CreateTime = time.Now()
|
|
|
+ m.ModifyTime = time.Now()
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Create(m).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// Update
|
|
|
+// @Description: 更新巡检看板记录
|
|
|
+// @receiver m
|
|
|
+// @param cols []string
|
|
|
+// @return err error
|
|
|
+func (m *EdbInspectionDashboard) Update(cols []string) (err error) {
|
|
|
+ m.ModifyTime = time.Now()
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Select(cols).Updates(m).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetById
|
|
|
+// @Description: 根据ID获取巡检看板记录
|
|
|
+// @param dashboardId int64
|
|
|
+// @return item *EdbInspectionDashboard
|
|
|
+// @return err error
|
|
|
+func GetDashboardById(dashboardId int64) (item *EdbInspectionDashboard, err error) {
|
|
|
+ sql := `SELECT * FROM edb_inspection_dashboard WHERE dashboard_id = ?`
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, dashboardId).First(&item).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetListByTerminalCode
|
|
|
+// @Description: 根据终端编码获取巡检看板记录列表
|
|
|
+// @param terminalCode string
|
|
|
+// @return list []*EdbInspectionDashboard
|
|
|
+// @return err error
|
|
|
+func GetDashboardListByTerminalCode(terminalCode string) (list []*EdbInspectionDashboard, err error) {
|
|
|
+ sql := `SELECT * FROM edb_inspection_dashboard WHERE terminal_code = ? ORDER BY inspection_time DESC`
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, terminalCode).Find(&list).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetListByInspectionRecordId
|
|
|
+// @Description: 根据巡检记录ID获取巡检看板记录列表
|
|
|
+// @param inspectionRecordId int64
|
|
|
+// @return list []*EdbInspectionDashboard
|
|
|
+// @return err error
|
|
|
+func GetDashboardListByInspectionRecordId(inspectionRecordId int64) (list []*EdbInspectionDashboard, err error) {
|
|
|
+ sql := `SELECT * FROM edb_inspection_dashboard WHERE inspection_record_id = ? ORDER BY inspection_time DESC`
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, inspectionRecordId).Find(&list).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetDashboardBySourceAndTerminalCode
|
|
|
+// @Description: 根据源和终端编码获取巡检看板记录
|
|
|
+// @param source int
|
|
|
+// @param terminalCode string
|
|
|
+// @return item *EdbInspectionDashboard
|
|
|
+// @return err error
|
|
|
+func GetDashboardBySourceAndTerminalCode(source int, terminalCode string) (item *EdbInspectionDashboard, err error) {
|
|
|
+ sql := `SELECT * FROM edb_inspection_dashboard WHERE source = ? AND terminal_code = ?`
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, source, terminalCode).First(&item).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+type DashboardList struct {
|
|
|
+ DashboardId int64 `gorm:"column:dashboard_id;primaryKey;autoIncrement"`
|
|
|
+ Source int `gorm:"column:source"`
|
|
|
+ TerminalCode string `gorm:"column:terminal_code"`
|
|
|
+ TerminalName string `gorm:"column:terminal_name"`
|
|
|
+ InspectionRecordId int64 `gorm:"column:inspection_record_id"`
|
|
|
+ InspectionTime string `gorm:"column:inspection_time"`
|
|
|
+ InspectionResult int8 `gorm:"column:inspection_result"`
|
|
|
+ ErrorReason string `gorm:"column:error_reason"`
|
|
|
+}
|
|
|
+
|
|
|
+// 查询列表,安装状态排序,失败的排在前面,状态相同,按照source排序,查询终端名称
|
|
|
+func GetDashboardList() (list []*DashboardList, err error) {
|
|
|
+ sql := `SELECT edb_inspection_dashboard.*, edb_terminal.name as terminal_name FROM edb_inspection_dashboard left join edb_terminal on edb_inspection_dashboard.terminal_code = edb_terminal.terminal_code ORDER BY inspection_result DESC, source ASC`
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql).Find(&list).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+func (m *DashboardList) AfterFind(scope *gorm.DB) (err error) {
|
|
|
+ m.InspectionTime = utils.GormDateStrToDateTimeStr(m.InspectionTime)
|
|
|
+ return
|
|
|
+}
|