|
...
|
...
|
@@ -22,6 +22,8 @@ const ( |
|
|
|
WorkshopProductionEfficiencyStatistics = "WorkshopProductionEfficiencyStatistics"
|
|
|
|
// 设备运行统计
|
|
|
|
DeviceRunningStatistics = "DeviceRunningStatistics"
|
|
|
|
// 设备运行信息
|
|
|
|
DeviceRunningInfo = "DeviceRunningInfo"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
...
|
...
|
@@ -51,6 +53,9 @@ func (ptr *PGCommonStatisticsService) CommonStatistics(actionType string, queryO |
|
|
|
case DeviceRunningStatistics:
|
|
|
|
result, err = ptr.DeviceRunningStatistics(queryOptions)
|
|
|
|
break
|
|
|
|
case DeviceRunningInfo:
|
|
|
|
result, err = ptr.DeviceRunningInfo(queryOptions)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
return result, err
|
|
|
|
}
|
|
...
|
...
|
@@ -331,6 +336,80 @@ type DeviceRunningStatisticRequest struct { |
|
|
|
Date string `json:"date"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// 设备运行统计
|
|
|
|
func (ptr *PGCommonStatisticsService) DeviceRunningInfo(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
|
var request = &DeviceRunningStatisticRequest{}
|
|
|
|
if err := utils.LoadQueryObject(queryOptions, request); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
deviceDailyRunningRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext)
|
|
|
|
var response = make([]*DeviceInfo, 0)
|
|
|
|
deviceDailyRunningRecordDao.DeviceRunningInfo(request.CompanyId, request.OrgId, "CCJ1", &response)
|
|
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
|
"devices": response,
|
|
|
|
"device_summary": ptr.DeviceSummary(response),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ptr *PGCommonStatisticsService) DeviceSummary(deviceInfos []*DeviceInfo) interface{} {
|
|
|
|
var result = make(map[string]interface{})
|
|
|
|
total := len(deviceInfos)
|
|
|
|
var (
|
|
|
|
deviceRunning = 0
|
|
|
|
deviceOff = 0
|
|
|
|
deviceErr = 0
|
|
|
|
)
|
|
|
|
|
|
|
|
for _, v := range deviceInfos {
|
|
|
|
if v.TStatus == "待机中" {
|
|
|
|
deviceOff += 1
|
|
|
|
} else if v.TStatus == "故障中" {
|
|
|
|
deviceErr += 1
|
|
|
|
} else if v.TStatus == "运行中" {
|
|
|
|
deviceRunning += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deviceSummary := func(t, num int) interface{} {
|
|
|
|
var rate float64
|
|
|
|
if t == 0 || num == 0 {
|
|
|
|
rate = 0
|
|
|
|
} else {
|
|
|
|
rate = utils.Round(float64(num*100.0/t), 0)
|
|
|
|
}
|
|
|
|
return map[string]interface{}{
|
|
|
|
"device_number": num,
|
|
|
|
"rate": rate,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = map[string]interface{}{
|
|
|
|
"total": total,
|
|
|
|
"off": deviceSummary(total, deviceOff),
|
|
|
|
"on": deviceSummary(total, deviceRunning),
|
|
|
|
"err": deviceSummary(total, deviceRunning),
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
type DeviceRunningInfoRequest struct {
|
|
|
|
CompanyId int `json:"companyId" valid:"Required"`
|
|
|
|
OrgId int `json:"orgId" valid:"Required"`
|
|
|
|
WorkshopId int `json:"workshopId"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type DeviceInfo struct {
|
|
|
|
TDeviceName string `json:"t_device_name"`
|
|
|
|
TDeviceCode string `json:"t_device_code"`
|
|
|
|
TStatus string `json:"t_status"`
|
|
|
|
TTemperature float64 `json:"t_temperature"`
|
|
|
|
TTemperature1 float64 `json:"t_temperature1"`
|
|
|
|
TDeviceType string `json:"t_device_type"`
|
|
|
|
TTotal float64 `json:"t_total"`
|
|
|
|
TUptime int `json:"t_uptime"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPGCommonStatisticsService(transactionContext *pgTransaction.TransactionContext) (*PGCommonStatisticsService, error) {
|
|
|
|
if transactionContext == nil {
|
|
|
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|
...
|
...
|
|