正在显示
9 个修改的文件
包含
78 行增加
和
13 行删除
| @@ -32,4 +32,8 @@ type DeviceRunningData struct { | @@ -32,4 +32,8 @@ type DeviceRunningData struct { | ||
| 32 | ProductType string `json:"productType"` | 32 | ProductType string `json:"productType"` |
| 33 | // 日期 | 33 | // 日期 |
| 34 | Date string `json:"date"` | 34 | Date string `json:"date"` |
| 35 | + | ||
| 36 | + // 额外数据 | ||
| 37 | + // 单位数据 比如:1串/0.1kg weight = count * unitQuantity | ||
| 38 | + UnitQuantity float64 `json:"unitQuantity"` | ||
| 35 | } | 39 | } |
| @@ -86,7 +86,7 @@ func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh flo | @@ -86,7 +86,7 @@ func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh flo | ||
| 86 | if productRecordType == RecordTypeReturnMaterial { | 86 | if productRecordType == RecordTypeReturnMaterial { |
| 87 | employeeProductRecord.ProductWeigh -= weigh | 87 | employeeProductRecord.ProductWeigh -= weigh |
| 88 | } | 88 | } |
| 89 | - employeeProductRecord.ProductRecordInfo.PreStatistics(employeeProductRecord.ProductWeigh, employeeProductRecord.SecondLevelWeigh, 0, 0) | 89 | + employeeProductRecord.ProductRecordInfo.PreStatistics(employeeProductRecord.ProductWeigh, employeeProductRecord.SecondLevelWeigh, yesterdayWeight, bestWeight) |
| 90 | employeeProductRecord.UpdatedAt = time.Now() | 90 | employeeProductRecord.UpdatedAt = time.Now() |
| 91 | employeeProductRecord.Version += 1 | 91 | employeeProductRecord.Version += 1 |
| 92 | } | 92 | } |
| @@ -58,8 +58,10 @@ func (info *ProductRecordStaticInfo) PreStatistics(productWeight float64, second | @@ -58,8 +58,10 @@ func (info *ProductRecordStaticInfo) PreStatistics(productWeight float64, second | ||
| 58 | info.InputWeight = productWeight - totalOtherSecondLevelWeigh | 58 | info.InputWeight = productWeight - totalOtherSecondLevelWeigh |
| 59 | info.OutputWeight = info.InputWeight - secondWeight | 59 | info.OutputWeight = info.InputWeight - secondWeight |
| 60 | info.SecondLevelWeight = secondWeight | 60 | info.SecondLevelWeight = secondWeight |
| 61 | + if info.YesterdayOutputWeight == 0 && info.BestOutputWeight == 0 { | ||
| 61 | info.YesterdayOutputWeight = yesterdayWeight | 62 | info.YesterdayOutputWeight = yesterdayWeight |
| 62 | info.BestOutputWeight = bestWeight | 63 | info.BestOutputWeight = bestWeight |
| 64 | + } | ||
| 63 | if bestWeight <= info.InputWeight { | 65 | if bestWeight <= info.InputWeight { |
| 64 | info.BestOutputWeight = info.OutputWeight | 66 | info.BestOutputWeight = info.OutputWeight |
| 65 | } | 67 | } |
| @@ -83,3 +83,47 @@ select round(avg(oee),1) oee,round(avg(tu),1) tu,round(avg(pu),1)pu, round(avg(q | @@ -83,3 +83,47 @@ select round(avg(oee),1) oee,round(avg(tu),1) tu,round(avg(pu),1)pu, round(avg(q | ||
| 83 | } | 83 | } |
| 84 | return nil | 84 | return nil |
| 85 | } | 85 | } |
| 86 | + | ||
| 87 | +// 时段产能 | ||
| 88 | +func (dao *DeviceDailyRunningRecordDao) TimeSectionProductRecord(companyId, orgId, workshopId int, lineId int, sectionName string, beginTime time.Time, result interface{}) error { | ||
| 89 | + | ||
| 90 | + tx := dao.transactionContext.PgTx | ||
| 91 | + sql := fmt.Sprintf(` | ||
| 92 | +WITH ts_product as( | ||
| 93 | + select sum(a.weight) total,a.ts from ( | ||
| 94 | + select | ||
| 95 | + cast(device_running_record_info->>'count' as DECIMAL) weight, | ||
| 96 | + "replace"(to_char(created_at at time ZONE 'Asia/shanghai', 'HH24:') || cast(date_part('minute',created_at) as integer)/30*30, ':0', ':00') ts | ||
| 97 | + from manufacture.device_running_record | ||
| 98 | + where | ||
| 99 | + company_id = ? | ||
| 100 | + and org_id = ? | ||
| 101 | + and work_station->>'workshopId'='?' | ||
| 102 | + and work_station->>'lineId'='?' | ||
| 103 | + and work_station->>'sectionName'=? | ||
| 104 | + and device_running_record_info->>'deviceType'='CCJ' | ||
| 105 | + and created_at >? | ||
| 106 | + ) a | ||
| 107 | + group by a.ts | ||
| 108 | + order by ts | ||
| 109 | +) | ||
| 110 | +-- select * from ts_product | ||
| 111 | +, ts_product_list as ( | ||
| 112 | + select d.ts,ts_product.total from ( | ||
| 113 | + select to_char(c.ts::timestamp,'HH24:MI') ts from ( | ||
| 114 | + select generate_series(a.end - interval '5 hour', | ||
| 115 | + "replace"(to_char(a.end, 'yyyy-mm-dd HH24:') || cast(date_part('minute',a.end) as integer)/30*30+30, ':0', ':00')::timestamp, | ||
| 116 | + '30 minute') ts from ( | ||
| 117 | + select to_timestamp(to_char(now() at time ZONE 'Asia/shanghai','yyyy-mm-dd HH24'),'yyyy-mm-dd HH24') as end | ||
| 118 | + ) a | ||
| 119 | + ) c | ||
| 120 | + ) d left join ts_product on d.ts = ts_product.ts | ||
| 121 | +) | ||
| 122 | +SELECT ts, coalesce(total,0) total | ||
| 123 | +from ts_product_list | ||
| 124 | +`) | ||
| 125 | + if _, err := tx.Query(result, sql, companyId, orgId, workshopId, lineId, sectionName, beginTime); err != nil { | ||
| 126 | + return err | ||
| 127 | + } | ||
| 128 | + return nil | ||
| 129 | +} |
| @@ -72,7 +72,7 @@ func (ptr *PGCommonStatisticsService) HourProductiveStatistics(queryOptions map[ | @@ -72,7 +72,7 @@ func (ptr *PGCommonStatisticsService) HourProductiveStatistics(queryOptions map[ | ||
| 72 | if err != nil || workshop == nil { | 72 | if err != nil || workshop == nil { |
| 73 | return nil, nil | 73 | return nil, nil |
| 74 | } | 74 | } |
| 75 | - productRecordDao, _ := dao.NewProductRecordDao(ptr.transactionContext) | 75 | + productRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext) |
| 76 | 76 | ||
| 77 | var response = make([]interface{}, 0) | 77 | var response = make([]interface{}, 0) |
| 78 | var tmpXData = make([]string, 0) | 78 | var tmpXData = make([]string, 0) |
| @@ -243,7 +243,7 @@ func (ptr *PGCommonStatisticsService) WorkshopProductionEfficiencyStatistics(que | @@ -243,7 +243,7 @@ func (ptr *PGCommonStatisticsService) WorkshopProductionEfficiencyStatistics(que | ||
| 243 | 243 | ||
| 244 | var response = make(map[string]interface{}) | 244 | var response = make(map[string]interface{}) |
| 245 | for _, v := range input { | 245 | for _, v := range input { |
| 246 | - var result = make([]*record, 0) | 246 | + var result = record{} |
| 247 | if err := productRecordDao.WorkshopProductionEfficiencyStatistics(request.CompanyId, request.OrgId, request.WorkshopId, v.t, &result); err != nil { | 247 | if err := productRecordDao.WorkshopProductionEfficiencyStatistics(request.CompanyId, request.OrgId, request.WorkshopId, v.t, &result); err != nil { |
| 248 | log.Logger.Error(err.Error()) | 248 | log.Logger.Error(err.Error()) |
| 249 | return nil, err | 249 | return nil, err |
| @@ -261,14 +261,14 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s | @@ -261,14 +261,14 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s | ||
| 261 | return nil, err | 261 | return nil, err |
| 262 | } | 262 | } |
| 263 | 263 | ||
| 264 | - workshopRepository, _ := repository.NewWorkshopRepository(ptr.transactionContext) | 264 | + //workshopRepository, _ := repository.NewWorkshopRepository(ptr.transactionContext) |
| 265 | deviceRepository, _ := repository.NewDeviceRepository(ptr.transactionContext) | 265 | deviceRepository, _ := repository.NewDeviceRepository(ptr.transactionContext) |
| 266 | deviceRunningRecordRepository, _ := repository.NewDeviceDailyRunningRecordRepository(ptr.transactionContext) | 266 | deviceRunningRecordRepository, _ := repository.NewDeviceDailyRunningRecordRepository(ptr.transactionContext) |
| 267 | 267 | ||
| 268 | - workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId}) | ||
| 269 | - if err != nil || workshop == nil { | ||
| 270 | - return nil, nil | ||
| 271 | - } | 268 | + //workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId}) |
| 269 | + //if err != nil || workshop == nil { | ||
| 270 | + // return nil, nil | ||
| 271 | + //} | ||
| 272 | 272 | ||
| 273 | _, devices, err := deviceRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "workshopId": request.WorkshopId, "lineId": request.LineId}) | 273 | _, devices, err := deviceRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "workshopId": request.WorkshopId, "lineId": request.LineId}) |
| 274 | if err != nil { | 274 | if err != nil { |
| @@ -312,7 +312,7 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s | @@ -312,7 +312,7 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s | ||
| 312 | type DeviceRunningStatisticRequest struct { | 312 | type DeviceRunningStatisticRequest struct { |
| 313 | CompanyId int `json:"companyId" valid:"Required"` | 313 | CompanyId int `json:"companyId" valid:"Required"` |
| 314 | OrgId int `json:"orgId" valid:"Required"` | 314 | OrgId int `json:"orgId" valid:"Required"` |
| 315 | - WorkshopId int `json:"workshopId" valid:"Required"` | 315 | + WorkshopId int `json:"workshopId"` |
| 316 | LineId int `json:"lineId""` | 316 | LineId int `json:"lineId""` |
| 317 | Date string `json:"date"` | 317 | Date string `json:"date"` |
| 318 | } | 318 | } |
| @@ -236,6 +236,7 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. | @@ -236,6 +236,7 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. | ||
| 236 | yesterdayOutputWeight float64 = 0 | 236 | yesterdayOutputWeight float64 = 0 |
| 237 | bestOutputWeight float64 = 0 | 237 | bestOutputWeight float64 = 0 |
| 238 | ) | 238 | ) |
| 239 | + if employeeProductRecord.ProductRecordInfo.BestOutputWeight == 0 { | ||
| 239 | if record, e := employeeProductRecordDao.WorkerProductRecord(cid, oid, planId, productRecord.ProductWorker.UserId, productRecord.CreatedAt.AddDate(0, 0, -1)); e == nil && record != nil { | 240 | if record, e := employeeProductRecordDao.WorkerProductRecord(cid, oid, planId, productRecord.ProductWorker.UserId, productRecord.CreatedAt.AddDate(0, 0, -1)); e == nil && record != nil { |
| 240 | yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight | 241 | yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight |
| 241 | bestOutputWeight = record.ProductRecordInfo.BestOutputWeight | 242 | bestOutputWeight = record.ProductRecordInfo.BestOutputWeight |
| @@ -245,6 +246,11 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. | @@ -245,6 +246,11 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. | ||
| 245 | yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight | 246 | yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight |
| 246 | } | 247 | } |
| 247 | } | 248 | } |
| 249 | + } | ||
| 250 | + // 更新批次的产能 (只有包装要更新批次产能) | ||
| 251 | + //if productPlan.WorkStation.SectionName==ProductSection4{ | ||
| 252 | + // | ||
| 253 | + //} | ||
| 248 | 254 | ||
| 249 | employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight) | 255 | employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight) |
| 250 | 256 |
| @@ -73,14 +73,14 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | @@ -73,14 +73,14 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | ||
| 73 | r := records[i] | 73 | r := records[i] |
| 74 | // 操作时间 < 签到时间 | 74 | // 操作时间 < 签到时间 |
| 75 | if utils.TimeAfterEqual(r.SignIn, report.ActionTime) { | 75 | if utils.TimeAfterEqual(r.SignIn, report.ActionTime) { |
| 76 | - log.Logger.Info(fmt.Sprintf("【考勤汇报】 考勤记录不合法,操作时间小于签到时间 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime)) | 76 | + log.Logger.Debug(fmt.Sprintf("【考勤汇报】 考勤记录不合法,操作时间小于签到时间 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime)) |
| 77 | return struct{}{}, nil | 77 | return struct{}{}, nil |
| 78 | } | 78 | } |
| 79 | // 存在完整打卡记录 | 79 | // 存在完整打卡记录 |
| 80 | // 1. 如果在区间内,退出 | 80 | // 1. 如果在区间内,退出 |
| 81 | if !utils.TimeIsZero(r.SignIn) && !utils.TimeIsZero(r.SignOut) { | 81 | if !utils.TimeIsZero(r.SignIn) && !utils.TimeIsZero(r.SignOut) { |
| 82 | if utils.TimeBeforeEqual(r.SignIn, report.ActionTime) && utils.TimeAfterEqual(r.SignOut, report.ActionTime) { | 82 | if utils.TimeBeforeEqual(r.SignIn, report.ActionTime) && utils.TimeAfterEqual(r.SignOut, report.ActionTime) { |
| 83 | - log.Logger.Info(fmt.Sprintf("【考勤汇报】 已存在同一时间段的考勤记录 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime)) | 83 | + log.Logger.Debug(fmt.Sprintf("【考勤汇报】 已存在同一时间段的考勤记录 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime)) |
| 84 | return struct{}{}, nil | 84 | return struct{}{}, nil |
| 85 | } | 85 | } |
| 86 | continue | 86 | continue |
| @@ -115,11 +115,11 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | @@ -115,11 +115,11 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | ||
| 115 | ProductGroupId: groupId, | 115 | ProductGroupId: groupId, |
| 116 | }), | 116 | }), |
| 117 | } | 117 | } |
| 118 | - log.Logger.Info(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签到 %v", worker.UserName, worker.UserId, report)) | 118 | + log.Logger.Debug(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签到 %v", worker.UserName, worker.UserId, report)) |
| 119 | } else { | 119 | } else { |
| 120 | record.SignOut = report.ActionTime | 120 | record.SignOut = report.ActionTime |
| 121 | record.WorkTimeBefore = record.ComputeWorkTimeBefore() | 121 | record.WorkTimeBefore = record.ComputeWorkTimeBefore() |
| 122 | - log.Logger.Info(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签退 %v", worker.UserName, worker.UserId, report)) | 122 | + log.Logger.Debug(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签退 %v", worker.UserName, worker.UserId, report)) |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | if _, err = attendanceRecordRepository.Save(record); err != nil { | 125 | if _, err = attendanceRecordRepository.Save(record); err != nil { |
| @@ -101,6 +101,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | @@ -101,6 +101,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | ||
| 101 | 101 | ||
| 102 | func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.DeviceCollection) (*domain.DeviceRunningData, error) { | 102 | func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.DeviceCollection) (*domain.DeviceRunningData, error) { |
| 103 | var err error | 103 | var err error |
| 104 | + var unitQuantity float64 = 1 // 单位数量 | ||
| 104 | var data = &domain.DeviceRunningData{ | 105 | var data = &domain.DeviceRunningData{ |
| 105 | DeviceCollectionId: record.DeviceCollectionId, | 106 | DeviceCollectionId: record.DeviceCollectionId, |
| 106 | WorkShopName: record.WorkShopName, | 107 | WorkShopName: record.WorkShopName, |
| @@ -109,6 +110,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev | @@ -109,6 +110,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev | ||
| 109 | DeviceType: record.DeviceType, | 110 | DeviceType: record.DeviceType, |
| 110 | StartupStatus: int(record.StartupStatus), | 111 | StartupStatus: int(record.StartupStatus), |
| 111 | ComStatus: int(record.ComStatus), | 112 | ComStatus: int(record.ComStatus), |
| 113 | + //UnitQuantity: unitQuantity, | ||
| 112 | } | 114 | } |
| 113 | var mBytes []byte | 115 | var mBytes []byte |
| 114 | if mBytes, err = json.Marshal(record.Values); err != nil { | 116 | if mBytes, err = json.Marshal(record.Values); err != nil { |
| @@ -152,6 +154,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev | @@ -152,6 +154,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev | ||
| 152 | if data.Date, err = formatDate(deviceChuanChuanJi.Year, deviceChuanChuanJi.Month, deviceChuanChuanJi.Day); err != nil { | 154 | if data.Date, err = formatDate(deviceChuanChuanJi.Year, deviceChuanChuanJi.Month, deviceChuanChuanJi.Day); err != nil { |
| 153 | return nil, err | 155 | return nil, err |
| 154 | } | 156 | } |
| 157 | + data.UnitQuantity = unitQuantity | ||
| 155 | break | 158 | break |
| 156 | //速冻线 | 159 | //速冻线 |
| 157 | case domain.DeviceTypeSuDongXian: | 160 | case domain.DeviceTypeSuDongXian: |
| @@ -174,6 +174,12 @@ func (repository *DeviceRepository) Find(queryOptions map[string]interface{}) (i | @@ -174,6 +174,12 @@ func (repository *DeviceRepository) Find(queryOptions map[string]interface{}) (i | ||
| 174 | if v, ok := queryOptions["inDeviceId"]; ok && len(v.([]int)) > 0 { | 174 | if v, ok := queryOptions["inDeviceId"]; ok && len(v.([]int)) > 0 { |
| 175 | query.Where(`device_id in (?)`, pg.In(v)) | 175 | query.Where(`device_id in (?)`, pg.In(v)) |
| 176 | } | 176 | } |
| 177 | + if v, ok := queryOptions["workshopId"]; ok && (v.(int)) > 0 { | ||
| 178 | + query.Where(`work_station->>'workshopId'='?'`, v) | ||
| 179 | + } | ||
| 180 | + if v, ok := queryOptions["lineId"]; ok && (v.(int)) > 0 { | ||
| 181 | + query.Where(`work_station->>'lineId'='?'`, v) | ||
| 182 | + } | ||
| 177 | query.SetWhereByQueryOption("device_code = ?", "deviceCode") | 183 | query.SetWhereByQueryOption("device_code = ?", "deviceCode") |
| 178 | query.SetWhereByQueryOption("device_status = ?", "deviceStatus") | 184 | query.SetWhereByQueryOption("device_status = ?", "deviceStatus") |
| 179 | if v, ok := queryOptions["deviceName"]; ok && len(v.(string)) > 0 { | 185 | if v, ok := queryOptions["deviceName"]; ok && len(v.(string)) > 0 { |
-
请 注册 或 登录 后发表评论