正在显示
8 个修改的文件
包含
56 行增加
和
29 行删除
@@ -26,6 +26,7 @@ func (d *WorkshopWorkTimeRecordDto) LoadDto(m *domain.WorkshopWorkTimeRecord, or | @@ -26,6 +26,7 @@ func (d *WorkshopWorkTimeRecordDto) LoadDto(m *domain.WorkshopWorkTimeRecord, or | ||
26 | d.WorkshopWorkTimeRecordId = m.WorkshopWorkTimeRecordId | 26 | d.WorkshopWorkTimeRecordId = m.WorkshopWorkTimeRecordId |
27 | d.WorkStation = m.WorkStation | 27 | d.WorkStation = m.WorkStation |
28 | if m.WorkshopWorkTimeRecordInfo != nil { | 28 | if m.WorkshopWorkTimeRecordInfo != nil { |
29 | + d.WorkshopWorkTimeRecordInfo = &domain.WorkshopWorkTimeRecordInfo{} | ||
29 | d.WorkshopWorkTimeRecordInfo.EPTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EPTWorkTime, 1) | 30 | d.WorkshopWorkTimeRecordInfo.EPTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EPTWorkTime, 1) |
30 | d.WorkshopWorkTimeRecordInfo.EDWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EDWorkTime, 1) | 31 | d.WorkshopWorkTimeRecordInfo.EDWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EDWorkTime, 1) |
31 | d.WorkshopWorkTimeRecordInfo.EFTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EFTWorkTime, 1) | 32 | d.WorkshopWorkTimeRecordInfo.EFTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EFTWorkTime, 1) |
@@ -15,9 +15,9 @@ type ProductLevelTwoRecord struct { | @@ -15,9 +15,9 @@ type ProductLevelTwoRecord struct { | ||
15 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 | 15 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 |
16 | WorkOn int `json:"workOn"` | 16 | WorkOn int `json:"workOn"` |
17 | // 产能 - 审核前 | 17 | // 产能 - 审核前 |
18 | - WeighBefore float64 `json:"weighBefore"` | 18 | + WeighBefore float64 `json:"weightBefore"` |
19 | // 产能-审核后 | 19 | // 产能-审核后 |
20 | - WeighAfter float64 `json:"weighAfter"` | 20 | + WeighAfter float64 `json:"weightAfter"` |
21 | // 审核状态 1:未审核 2:已审核 | 21 | // 审核状态 1:未审核 2:已审核 |
22 | ApproveStatus int `json:"approveStatus"` | 22 | ApproveStatus int `json:"approveStatus"` |
23 | // 审核人 | 23 | // 审核人 |
@@ -86,6 +86,9 @@ func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh flo | @@ -86,6 +86,9 @@ 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 | + if productRecordType == RecordTypeWeigh { | ||
90 | + employeeProductRecord.ProductWeigh += weigh | ||
91 | + } | ||
89 | employeeProductRecord.ProductRecordInfo.PreStatistics(employeeProductRecord.ProductWeigh, employeeProductRecord.SecondLevelWeigh, yesterdayWeight, bestWeight) | 92 | employeeProductRecord.ProductRecordInfo.PreStatistics(employeeProductRecord.ProductWeigh, employeeProductRecord.SecondLevelWeigh, yesterdayWeight, bestWeight) |
90 | employeeProductRecord.UpdatedAt = time.Now() | 93 | employeeProductRecord.UpdatedAt = time.Now() |
91 | employeeProductRecord.Version += 1 | 94 | employeeProductRecord.Version += 1 |
@@ -68,6 +68,9 @@ func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(weigh flo | @@ -68,6 +68,9 @@ func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(weigh flo | ||
68 | if productRecordType == RecordTypeReturnMaterial { | 68 | if productRecordType == RecordTypeReturnMaterial { |
69 | employeeProductRecord.ProductWeigh -= weigh | 69 | employeeProductRecord.ProductWeigh -= weigh |
70 | } | 70 | } |
71 | + if productRecordType == RecordTypeWeigh { | ||
72 | + employeeProductRecord.ProductWeigh += weigh | ||
73 | + } | ||
71 | employeeProductRecord.ProductRecordInfo.PreStatistics(employeeProductRecord.ProductWeigh, employeeProductRecord.SecondLevelWeigh, 0, 0) | 74 | employeeProductRecord.ProductRecordInfo.PreStatistics(employeeProductRecord.ProductWeigh, employeeProductRecord.SecondLevelWeigh, 0, 0) |
72 | employeeProductRecord.UpdatedAt = time.Now() | 75 | employeeProductRecord.UpdatedAt = time.Now() |
73 | employeeProductRecord.Version += 1 | 76 | employeeProductRecord.Version += 1 |
@@ -261,22 +261,24 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s | @@ -261,22 +261,24 @@ 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) | ||
265 | deviceRepository, _ := repository.NewDeviceRepository(ptr.transactionContext) | 264 | deviceRepository, _ := repository.NewDeviceRepository(ptr.transactionContext) |
266 | deviceRunningRecordRepository, _ := repository.NewDeviceDailyRunningRecordRepository(ptr.transactionContext) | 265 | deviceRunningRecordRepository, _ := repository.NewDeviceDailyRunningRecordRepository(ptr.transactionContext) |
267 | 266 | ||
268 | - //workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId}) | ||
269 | - //if err != nil || workshop == nil { | ||
270 | - // return nil, nil | ||
271 | - //} | ||
272 | - | 267 | + var t time.Time |
268 | + var err error | ||
269 | + if len(request.Date) > 0 { | ||
270 | + t, err = time.ParseInLocation("2006-01-02", request.Date, time.Local) | ||
271 | + if err != nil { | ||
272 | + log.Logger.Error(err.Error()) | ||
273 | + } | ||
274 | + } | ||
273 | _, devices, err := deviceRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "workshopId": request.WorkshopId, "lineId": request.LineId}) | 275 | _, devices, err := deviceRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "workshopId": request.WorkshopId, "lineId": request.LineId}) |
274 | if err != nil { | 276 | if err != nil { |
275 | return nil, err | 277 | return nil, err |
276 | } | 278 | } |
277 | 279 | ||
278 | var response = make([]interface{}, 0) | 280 | var response = make([]interface{}, 0) |
279 | - _, dailyRecords, err := deviceRunningRecordRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "productDate": request.Date}) | 281 | + _, dailyRecords, err := deviceRunningRecordRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "productDate": t}) |
280 | for i := 0; i < len(devices); i++ { | 282 | for i := 0; i < len(devices); i++ { |
281 | d := devices[i] | 283 | d := devices[i] |
282 | if d.Ext == nil || d.Ext.DeviceExt == nil || d.Ext.DeviceExt.IsProductDevice == 0 { | 284 | if d.Ext == nil || d.Ext.DeviceExt == nil || d.Ext.DeviceExt.IsProductDevice == 0 { |
@@ -301,7 +303,10 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s | @@ -301,7 +303,10 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s | ||
301 | } | 303 | } |
302 | } | 304 | } |
303 | if r != nil { | 305 | if r != nil { |
304 | - m := r.UpdatedAt.Hour()*60 + r.UpdatedAt.Minute() | 306 | + m := r.UpdatedAt.Local().Hour()*60 + r.UpdatedAt.Minute() |
307 | + if r.UpdatedAt.Before(utils.GetZeroTime(time.Now())) { | ||
308 | + m = 60 * 24 | ||
309 | + } | ||
305 | item["status"] = r.DeviceRunningRecordInfo.HourDeviceStatusDetail(m) | 310 | item["status"] = r.DeviceRunningRecordInfo.HourDeviceStatusDetail(m) |
306 | item["status_info"] = r.DeviceRunningRecordInfo.TimeLineDeviceStatus | 311 | item["status_info"] = r.DeviceRunningRecordInfo.TimeLineDeviceStatus |
307 | } | 312 | } |
@@ -48,6 +48,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | @@ -48,6 +48,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | ||
48 | if err != nil { | 48 | if err != nil { |
49 | return nil, err | 49 | return nil, err |
50 | } | 50 | } |
51 | + | ||
51 | if deviceDailyRecord != nil { | 52 | if deviceDailyRecord != nil { |
52 | workStation = deviceDailyRecord.WorkStation | 53 | workStation = deviceDailyRecord.WorkStation |
53 | planId = deviceDailyRecord.DeviceRunningRecordInfo.ProductPlanId | 54 | planId = deviceDailyRecord.DeviceRunningRecordInfo.ProductPlanId |
@@ -64,15 +65,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | @@ -64,15 +65,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | ||
64 | return nil, nil | 65 | return nil, nil |
65 | } | 66 | } |
66 | workStation = device.WorkStation | 67 | workStation = device.WorkStation |
67 | - // 封箱机、串串机需要定位到批次 | ||
68 | - if record.DeviceType == domain.DeviceTypeFengXiangJi || record.DeviceType == domain.DeviceTypeChuanChuanJi { | ||
69 | - datetime, _ = time.Parse("2006-01-02", deviceRunningData.Date) | ||
70 | - if plan, err = ptr.findDeviceProductPlan(companyId, orgId, workStation.WorkStationId, datetime, deviceRunningData.ProductType); err != nil { | ||
71 | - log.Logger.Error(err.Error()) | ||
72 | - } else { | ||
73 | - planId = plan.PlanDispatchRecordExt.ProductPlanId | ||
74 | - } | ||
75 | - } | 68 | + |
76 | var saveErr error | 69 | var saveErr error |
77 | if deviceDailyRecord, saveErr = ptr.saveDeviceDailyRunningRecord(companyId, orgId, workStation, device, planId, deviceRunningData); err != nil { | 70 | if deviceDailyRecord, saveErr = ptr.saveDeviceDailyRunningRecord(companyId, orgId, workStation, device, planId, deviceRunningData); err != nil { |
78 | return nil, err | 71 | return nil, err |
@@ -84,14 +77,25 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | @@ -84,14 +77,25 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | ||
84 | }() | 77 | }() |
85 | } | 78 | } |
86 | 79 | ||
80 | + // 封箱机、串串机需要定位到批次 | ||
81 | + if record.DeviceType == domain.DeviceTypeFengXiangJi || record.DeviceType == domain.DeviceTypeChuanChuanJi { | ||
82 | + datetime, _ = time.Parse("2006-01-02", deviceRunningData.Date) | ||
83 | + if plan, err = ptr.findDeviceProductPlan(companyId, orgId, workStation.WorkStationId, datetime, deviceRunningData.ProductType); err != nil { | ||
84 | + log.Logger.Error(err.Error()) | ||
85 | + } else { | ||
86 | + planId = plan.PlanDispatchRecordExt.ProductPlanId | ||
87 | + } | ||
88 | + } | ||
89 | + | ||
87 | // 1.保存设备运行记录 | 90 | // 1.保存设备运行记录 |
88 | deviceRunningRecord, _ = ptr.newDeviceRunningRecord(companyId, orgId, workStation, device, deviceRunningData) | 91 | deviceRunningRecord, _ = ptr.newDeviceRunningRecord(companyId, orgId, workStation, device, deviceRunningData) |
89 | if _, err = deviceRunningRecordRepository.Save(deviceRunningRecord); err != nil { | 92 | if _, err = deviceRunningRecordRepository.Save(deviceRunningRecord); err != nil { |
90 | return nil, err | 93 | return nil, err |
91 | } | 94 | } |
92 | // 2.保存设备生产记录 | 95 | // 2.保存设备生产记录 |
93 | - if record.DeviceType == domain.DeviceTypeChuanChuanJi { | ||
94 | - productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, planId) | 96 | + if record.DeviceType == domain.DeviceTypeChuanChuanJi && plan != nil { |
97 | + | ||
98 | + productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, plan) | ||
95 | //if _, err = deviceRunningRecordRepository.Save(deviceRunningRecord); err != nil { | 99 | //if _, err = deviceRunningRecordRepository.Save(deviceRunningRecord); err != nil { |
96 | // return nil, err | 100 | // return nil, err |
97 | //} | 101 | //} |
@@ -217,7 +221,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId | @@ -217,7 +221,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId | ||
217 | }, nil | 221 | }, nil |
218 | } | 222 | } |
219 | 223 | ||
220 | -func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId int, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData, planId int) (*domain.ProductRecord, error) { | 224 | +func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId int, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData, plan *domain.ProductPlanDispatchRecord) (*domain.ProductRecord, error) { |
221 | result := &domain.ProductRecord{ | 225 | result := &domain.ProductRecord{ |
222 | CompanyId: companyId, | 226 | CompanyId: companyId, |
223 | OrgId: orgId, | 227 | OrgId: orgId, |
@@ -227,12 +231,14 @@ func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId i | @@ -227,12 +231,14 @@ func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId i | ||
227 | CreatedAt: data.CollectionTime, | 231 | CreatedAt: data.CollectionTime, |
228 | UpdatedAt: time.Now(), | 232 | UpdatedAt: time.Now(), |
229 | ProductRecordInfo: &domain.ProductRecordInfo{ | 233 | ProductRecordInfo: &domain.ProductRecordInfo{ |
230 | - ProductDate: data.CollectionTime.Local().Format("2006-01-02"), | ||
231 | - Original: float64(data.Count), | ||
232 | - Weigh: float64(data.Count) * DefaultCCJUnitQuantity, | ||
233 | - WeighBefore: float64(data.Count) * DefaultCCJUnitQuantity, | ||
234 | - ApproveStatus: domain.AttendanceNotApprove, | ||
235 | - ProductPlanId: planId, | 234 | + ProductDate: data.CollectionTime.Local().Format("2006-01-02"), |
235 | + Original: float64(data.Count), | ||
236 | + Weigh: float64(data.Count) * DefaultCCJUnitQuantity, | ||
237 | + WeighBefore: float64(data.Count) * DefaultCCJUnitQuantity, | ||
238 | + ApproveStatus: domain.AttendanceNotApprove, | ||
239 | + ProductPlanId: plan.PlanDispatchRecordExt.ProductPlanId, | ||
240 | + PlanProductName: plan.PlanDispatchRecordExt.PlanProductName, | ||
241 | + BatchNumber: plan.BatchNumber, | ||
236 | }, | 242 | }, |
237 | Ext: domain.NewExt(""), | 243 | Ext: domain.NewExt(""), |
238 | } | 244 | } |
@@ -3,6 +3,7 @@ package repository | @@ -3,6 +3,7 @@ package repository | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | "github.com/go-pg/pg/v10" | 5 | "github.com/go-pg/pg/v10" |
6 | + "time" | ||
6 | 7 | ||
7 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | 8 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" |
8 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 9 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
@@ -145,7 +146,7 @@ func (repository *DeviceDailyRunningRecordRepository) Find(queryOptions map[stri | @@ -145,7 +146,7 @@ func (repository *DeviceDailyRunningRecordRepository) Find(queryOptions map[stri | ||
145 | query := sqlbuilder.BuildQuery(tx.Model(&deviceDailyRunningRecordModels), queryOptions) | 146 | query := sqlbuilder.BuildQuery(tx.Model(&deviceDailyRunningRecordModels), queryOptions) |
146 | query.SetWhereByQueryOption("company_id = ?", "companyId") | 147 | query.SetWhereByQueryOption("company_id = ?", "companyId") |
147 | query.SetWhereByQueryOption("org_id = ?", "orgId") | 148 | query.SetWhereByQueryOption("org_id = ?", "orgId") |
148 | - if v, ok := queryOptions["productDate"]; ok && len(v.(string)) > 0 { | 149 | + if v, ok := queryOptions["productDate"]; ok && !(v.(time.Time)).IsZero() { |
149 | query.Where(`product_date = ?`, v) | 150 | query.Where(`product_date = ?`, v) |
150 | } | 151 | } |
151 | query.SetOffsetAndLimit(20) | 152 | query.SetOffsetAndLimit(20) |
@@ -107,6 +107,14 @@ func (repository *WorkshopWorkTimeRecordRepository) FindOne(queryOptions map[str | @@ -107,6 +107,14 @@ func (repository *WorkshopWorkTimeRecordRepository) FindOne(queryOptions map[str | ||
107 | tx := repository.transactionContext.PgTx | 107 | tx := repository.transactionContext.PgTx |
108 | workshopWorkTimeRecordModel := new(models.WorkshopWorkTimeRecord) | 108 | workshopWorkTimeRecordModel := new(models.WorkshopWorkTimeRecord) |
109 | query := sqlbuilder.BuildQuery(tx.Model(workshopWorkTimeRecordModel), queryOptions) | 109 | query := sqlbuilder.BuildQuery(tx.Model(workshopWorkTimeRecordModel), queryOptions) |
110 | + query.SetWhereByQueryOption("company_id = ?", "companyId") | ||
111 | + query.SetWhereByQueryOption("org_id = ?", "orgId") | ||
112 | + if v, ok := queryOptions["workStationId"]; ok && len(v.(string)) > 0 { | ||
113 | + query.Where(`work_station->>'workStationId' = ?`, v) | ||
114 | + } | ||
115 | + if v, ok := queryOptions["recordDate"]; ok { | ||
116 | + query.Where("record_date=?", v) | ||
117 | + } | ||
110 | query.SetWhereByQueryOption("workshop_work_time_record.workshop_work_time_record_id = ?", "workshopWorkTimeRecordId") | 118 | query.SetWhereByQueryOption("workshop_work_time_record.workshop_work_time_record_id = ?", "workshopWorkTimeRecordId") |
111 | if err := query.First(); err != nil { | 119 | if err := query.First(); err != nil { |
112 | if err.Error() == "pg: no rows in result set" { | 120 | if err.Error() == "pg: no rows in result set" { |
-
请 注册 或 登录 后发表评论