...
|
...
|
@@ -21,6 +21,8 @@ const ( |
|
|
ProportionOfSecondLevelStatistics = "ProportionOfSecondLevelStatistics"
|
|
|
// 车间生产效率
|
|
|
WorkshopProductionEfficiencyStatistics = "WorkshopProductionEfficiencyStatistics"
|
|
|
// 设备生产效率
|
|
|
DeviceProductionEfficiencyStatistics = "DeviceProductionEfficiencyStatistics"
|
|
|
// 设备运行统计
|
|
|
DeviceRunningStatistics = "DeviceRunningStatistics"
|
|
|
// 设备运行信息
|
...
|
...
|
@@ -51,6 +53,9 @@ func (ptr *PGCommonStatisticsService) CommonStatistics(actionType string, queryO |
|
|
case WorkshopProductionEfficiencyStatistics:
|
|
|
result, err = ptr.WorkshopProductionEfficiencyStatistics(queryOptions)
|
|
|
break
|
|
|
case DeviceProductionEfficiencyStatistics:
|
|
|
result, err = ptr.DeviceProductionEfficiencyStatistics(queryOptions)
|
|
|
break
|
|
|
case DeviceRunningStatistics:
|
|
|
result, err = ptr.DeviceRunningStatistics(queryOptions)
|
|
|
break
|
...
|
...
|
@@ -415,6 +420,105 @@ type DeviceInfo struct { |
|
|
TUptime int `json:"t_uptime"`
|
|
|
}
|
|
|
|
|
|
// 设备生产效率统计
|
|
|
func (ptr *PGCommonStatisticsService) DeviceProductionEfficiencyStatistics(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
var request = &HourProductiveStatisticsRequest{}
|
|
|
if err := utils.LoadQueryObject(queryOptions, request); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if request.WorkshopId == 0 {
|
|
|
request.WorkshopId = constant.MANUFACTURE_DEFAULT_WORKSHOPID
|
|
|
}
|
|
|
|
|
|
deviceRepository, _ := repository.NewDeviceRepository(ptr.transactionContext)
|
|
|
deviceDailyRunningRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext)
|
|
|
/*
|
|
|
1.生产设备
|
|
|
2.设备本月运行数据
|
|
|
*/
|
|
|
_, devices, err := deviceRepository.Find(map[string]interface{}{
|
|
|
"companyId": request.CompanyId,
|
|
|
"orgId": request.OrgId,
|
|
|
"workshopId": request.WorkshopId,
|
|
|
"orderBy": "device_name asc"})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
type record struct {
|
|
|
Oee float64 `json:"oee"`
|
|
|
Pu float64 `json:"pu"`
|
|
|
Tu float64 `json:"tu"`
|
|
|
Qu float64 `json:"qu"`
|
|
|
UpTime int `json:"up_time"`
|
|
|
T int `json:"t"`
|
|
|
DeviceId int `json:"device_id"`
|
|
|
DeviceCode string `json:"device_code"`
|
|
|
DeviceName string `json:"device_name"`
|
|
|
// 生产单个产品的时间(单位:秒)
|
|
|
UnitProductionSecTime float64 `json:"unit_time"`
|
|
|
// 投入量
|
|
|
InputWeight float64 `json:"input_weight"`
|
|
|
// 二级品
|
|
|
SecondLevelWeight float64 `json:"second_level_weight"`
|
|
|
}
|
|
|
var records = make([]*record, 0)
|
|
|
if err := deviceDailyRunningRecordDao.DeviceProductionEfficiencyStatistics(request.CompanyId,
|
|
|
request.OrgId,
|
|
|
request.WorkshopId,
|
|
|
utils.GetCurrentMonthFirstDay(time.Now()), &records); err != nil {
|
|
|
log.Logger.Error(err.Error())
|
|
|
return nil, err
|
|
|
}
|
|
|
type production struct {
|
|
|
WorkStationId string `json:"work_station_id"`
|
|
|
InputWeight float64 `json:"input_weight"`
|
|
|
SecondLevelWeight float64 `json:"second_level_weight"`
|
|
|
}
|
|
|
var productions = make([]*production, 0)
|
|
|
workshopProductRecordDao, _ := dao.NewWorkshopProductRecordDao(ptr.transactionContext)
|
|
|
if err := workshopProductRecordDao.WorkStationProductionStatistics(request.CompanyId,
|
|
|
request.OrgId,
|
|
|
request.WorkshopId,
|
|
|
utils.GetCurrentMonthFirstDay(time.Now()), &productions); err != nil {
|
|
|
log.Logger.Error(err.Error())
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
var response = make([]interface{}, 0)
|
|
|
|
|
|
for i := 0; i < len(devices); i++ {
|
|
|
d := devices[i]
|
|
|
if d.Ext == nil || d.Ext.DeviceExt == nil || d.Ext.DeviceExt.IsProductDevice == 0 {
|
|
|
continue
|
|
|
}
|
|
|
var r *record
|
|
|
for j := 0; j < len(records); j++ {
|
|
|
if d.DeviceCode == records[j].DeviceCode {
|
|
|
r = records[j]
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
if r != nil {
|
|
|
r.DeviceName = d.DeviceName
|
|
|
if d.Ext.DeviceExt != nil {
|
|
|
r.UnitProductionSecTime = d.Ext.DeviceExt.UnitProductionSecTime
|
|
|
}
|
|
|
for k := 0; k < len(productions); k++ {
|
|
|
if productions[k].WorkStationId == d.WorkStation.WorkStationId {
|
|
|
r.InputWeight = productions[k].InputWeight
|
|
|
r.SecondLevelWeight = productions[k].SecondLevelWeight
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
response = append(response, r)
|
|
|
}
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"devices": response,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
func NewPGCommonStatisticsService(transactionContext *pgTransaction.TransactionContext) (*PGCommonStatisticsService, error) {
|
|
|
if transactionContext == nil {
|
|
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|
...
|
...
|
|