正在显示
19 个修改的文件
包含
163 行增加
和
50 行删除
| @@ -2,6 +2,7 @@ package dto | @@ -2,6 +2,7 @@ package dto | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 4 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
| 5 | "time" | 6 | "time" |
| 6 | ) | 7 | ) |
| 7 | 8 | ||
| @@ -46,13 +47,13 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i | @@ -46,13 +47,13 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i | ||
| 46 | d.ProductWorker = m.ProductWorker | 47 | d.ProductWorker = m.ProductWorker |
| 47 | d.WorkStation = m.WorkStation | 48 | d.WorkStation = m.WorkStation |
| 48 | if !m.SignIn.IsZero() { | 49 | if !m.SignIn.IsZero() { |
| 49 | - d.SignIn = m.SignIn.Format("15:04:05") | ||
| 50 | - d.SignDate = m.SignIn.Format("2006-01-02") | 50 | + d.SignIn = m.SignIn.Local().Format("15:04:05") |
| 51 | + d.SignDate = m.SignIn.Local().Format("2006-01-02") | ||
| 51 | } | 52 | } |
| 52 | if !m.SignOut.IsZero() { | 53 | if !m.SignOut.IsZero() { |
| 53 | - d.SignOut = m.SignOut.Format("15:04:05") | 54 | + d.SignOut = m.SignOut.Local().Format("15:04:05") |
| 54 | } | 55 | } |
| 55 | - d.WorkTimeBefore = m.WorkTimeBefore | 56 | + d.WorkTimeBefore = utils.Round(m.WorkTimeBefore, 1) |
| 56 | d.WorkTimeAfter = m.WorkTimeAfter | 57 | d.WorkTimeAfter = m.WorkTimeAfter |
| 57 | d.AttendanceStatus = m.AttendanceStatus | 58 | d.AttendanceStatus = m.AttendanceStatus |
| 58 | d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId) | 59 | d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId) |
| @@ -69,7 +70,7 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i | @@ -69,7 +70,7 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i | ||
| 69 | } | 70 | } |
| 70 | if m.Ext.AttendanceExt.ApproveAt > 0 { | 71 | if m.Ext.AttendanceExt.ApproveAt > 0 { |
| 71 | t := time.Unix(m.Ext.AttendanceExt.ApproveAt, 0) | 72 | t := time.Unix(m.Ext.AttendanceExt.ApproveAt, 0) |
| 72 | - d.ApproveAt = t.Format("2006-01-02 15:04:05") | 73 | + d.ApproveAt = t.Local().Format("2006-01-02 15:04:05") |
| 73 | } | 74 | } |
| 74 | } | 75 | } |
| 75 | } | 76 | } |
| @@ -2,6 +2,7 @@ package dto | @@ -2,6 +2,7 @@ package dto | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 4 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
| 5 | ) | 6 | ) |
| 6 | 7 | ||
| 7 | type EmployeeAttendanceRecordDto struct { | 8 | type EmployeeAttendanceRecordDto struct { |
| @@ -39,9 +40,9 @@ func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, | @@ -39,9 +40,9 @@ func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, | ||
| 39 | d.WorkStation = m.WorkStation | 40 | d.WorkStation = m.WorkStation |
| 40 | if !m.SignIn.IsZero() { | 41 | if !m.SignIn.IsZero() { |
| 41 | //d.SignIn = m.SignIn.Format("15:04:05") | 42 | //d.SignIn = m.SignIn.Format("15:04:05") |
| 42 | - d.SignDate = m.SignIn.Format("2006-01-02") | 43 | + d.SignDate = m.SignIn.Local().Format("2006-01-02") |
| 43 | } | 44 | } |
| 44 | - d.WorkTime = m.WorkTimeAfter | 45 | + d.WorkTime = utils.Round(m.WorkTimeAfter, 1) |
| 45 | //d.WorkTimeAfter = m.WorkTimeAfter | 46 | //d.WorkTimeAfter = m.WorkTimeAfter |
| 46 | d.AttendanceStatus = m.AttendanceStatus | 47 | d.AttendanceStatus = m.AttendanceStatus |
| 47 | d.AttendanceTypeDescription = domain.ParticipateTypeDescription(m.AttendanceType) | 48 | d.AttendanceTypeDescription = domain.ParticipateTypeDescription(m.AttendanceType) |
| @@ -2,6 +2,7 @@ package dto | @@ -2,6 +2,7 @@ package dto | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 4 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
| 5 | ) | 6 | ) |
| 6 | 7 | ||
| 7 | type WorkshopWorkTimeRecordDto struct { | 8 | type WorkshopWorkTimeRecordDto struct { |
| @@ -24,9 +25,13 @@ type WorkshopWorkTimeRecordDto struct { | @@ -24,9 +25,13 @@ type WorkshopWorkTimeRecordDto struct { | ||
| 24 | func (d *WorkshopWorkTimeRecordDto) LoadDto(m *domain.WorkshopWorkTimeRecord, orgId int) *WorkshopWorkTimeRecordDto { | 25 | func (d *WorkshopWorkTimeRecordDto) LoadDto(m *domain.WorkshopWorkTimeRecord, orgId int) *WorkshopWorkTimeRecordDto { |
| 25 | d.WorkshopWorkTimeRecordId = m.WorkshopWorkTimeRecordId | 26 | d.WorkshopWorkTimeRecordId = m.WorkshopWorkTimeRecordId |
| 26 | d.WorkStation = m.WorkStation | 27 | d.WorkStation = m.WorkStation |
| 27 | - d.WorkshopWorkTimeRecordInfo = m.WorkshopWorkTimeRecordInfo | 28 | + if m.WorkshopWorkTimeRecordInfo != nil { |
| 29 | + d.WorkshopWorkTimeRecordInfo.EPTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EPTWorkTime, 1) | ||
| 30 | + d.WorkshopWorkTimeRecordInfo.EDWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EDWorkTime, 1) | ||
| 31 | + d.WorkshopWorkTimeRecordInfo.EFTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EFTWorkTime, 1) | ||
| 32 | + } | ||
| 28 | d.WorkStation = m.WorkStation | 33 | d.WorkStation = m.WorkStation |
| 29 | - d.RecordDate = m.RecordDate.Format("2006-01-02") | 34 | + d.RecordDate = m.RecordDate.Local().Format("2006-01-02") |
| 30 | d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId) | 35 | d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId) |
| 31 | if m.Ext != nil { | 36 | if m.Ext != nil { |
| 32 | d.OrgName = m.Ext.OrgName | 37 | d.OrgName = m.Ext.OrgName |
| @@ -71,7 +71,7 @@ func (d *ProductGroupEmployeesDtos) LoadDto(groups ...*domain.ProductGroup) { | @@ -71,7 +71,7 @@ func (d *ProductGroupEmployeesDtos) LoadDto(groups ...*domain.ProductGroup) { | ||
| 71 | } | 71 | } |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | -func (d *ProductGroupEmployeesDtos) LoadDtoV2(list ...*domain.ProductAttendanceRecord) { | 74 | +func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRecord, mapGroupUser map[string]*domain.User, keyFunc func(int) string) { |
| 75 | var mapUser = make(map[int]int) | 75 | var mapUser = make(map[int]int) |
| 76 | for _, v := range list { | 76 | for _, v := range list { |
| 77 | item := &ProductGroupEmployeesDto{} | 77 | item := &ProductGroupEmployeesDto{} |
| @@ -79,6 +79,11 @@ func (d *ProductGroupEmployeesDtos) LoadDtoV2(list ...*domain.ProductAttendanceR | @@ -79,6 +79,11 @@ func (d *ProductGroupEmployeesDtos) LoadDtoV2(list ...*domain.ProductAttendanceR | ||
| 79 | item.UserName = v.ProductWorker.UserName | 79 | item.UserName = v.ProductWorker.UserName |
| 80 | item.ProductGroupId = 0 | 80 | item.ProductGroupId = 0 |
| 81 | item.GroupName = "" | 81 | item.GroupName = "" |
| 82 | + if v, ok := mapGroupUser[keyFunc(item.UserId)]; ok { | ||
| 83 | + item.GroupName = v.GroupName | ||
| 84 | + item.ProductGroupId = v.GroupId | ||
| 85 | + item.WorkOnDescription = domain.WorkOnDescriptions(v.WorkOn) | ||
| 86 | + } | ||
| 82 | if len(item.UserName) > 0 { | 87 | if len(item.UserName) > 0 { |
| 83 | item.UserNamePinyin = converter.ToPinYin(item.UserName, "") | 88 | item.UserNamePinyin = converter.ToPinYin(item.UserName, "") |
| 84 | } | 89 | } |
| @@ -444,8 +444,11 @@ func (productGroupService *ProductGroupService) SearchProductGroupEmployeesV2(op | @@ -444,8 +444,11 @@ func (productGroupService *ProductGroupService) SearchProductGroupEmployeesV2(op | ||
| 444 | if err != nil { | 444 | if err != nil { |
| 445 | return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 445 | return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 446 | } | 446 | } |
| 447 | + | ||
| 448 | + productGroupRepository, _, _ := factory.FastPgProductGroup(transactionContext, 0) | ||
| 449 | + mapUser, keyFunc := domainService.FindGroupMembers(productGroupRepository, cmd.CompanyId, cmd.OrgId, domain.WorkstationKey(cmd.WorkshopId, cmd.LineId, cmd.SectionId)) | ||
| 447 | var results = dto.NewProductGroupEmployeesDtos() | 450 | var results = dto.NewProductGroupEmployeesDtos() |
| 448 | - results.LoadDtoV2(productGroups...) | 451 | + results.LoadDtoV2(productGroups, mapUser, keyFunc) |
| 449 | sort.Stable(results) | 452 | sort.Stable(results) |
| 450 | if err := transactionContext.CommitTransaction(); err != nil { | 453 | if err := transactionContext.CommitTransaction(); err != nil { |
| 451 | return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 454 | return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| @@ -477,12 +480,23 @@ func (productGroupService *ProductGroupService) GetSignEmployee(cmd *query.GetSi | @@ -477,12 +480,23 @@ func (productGroupService *ProductGroupService) GetSignEmployee(cmd *query.GetSi | ||
| 477 | if err != nil || worker == nil || worker.UserId == 0 { | 480 | if err != nil || worker == nil || worker.UserId == 0 { |
| 478 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户不存在") | 481 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户不存在") |
| 479 | } | 482 | } |
| 483 | + result := map[string]interface{}{ | ||
| 484 | + "userId": worker.UserId, | ||
| 485 | + "userName": worker.UserName, | ||
| 486 | + } | ||
| 487 | + productGroupRepository, _, _ := factory.FastPgProductGroup(transactionContext, 0) | ||
| 488 | + mapUser, keyFunc := domainService.FindGroupMembers(productGroupRepository, cmd.CompanyId, cmd.OrgId, "") | ||
| 489 | + if v, ok := mapUser[keyFunc(worker.UserId)]; ok { | ||
| 490 | + result["productGroupId"] = v.GroupId | ||
| 491 | + result["groupName"] = v.GroupName | ||
| 492 | + result["workOn"] = domain.WorkOnDescriptions(v.WorkOn) | ||
| 493 | + } | ||
| 480 | 494 | ||
| 481 | if err := transactionContext.CommitTransaction(); err != nil { | 495 | if err := transactionContext.CommitTransaction(); err != nil { |
| 482 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 496 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 483 | } | 497 | } |
| 484 | return map[string]interface{}{ | 498 | return map[string]interface{}{ |
| 485 | - "employee": worker, | 499 | + "employee": result, |
| 486 | }, nil | 500 | }, nil |
| 487 | } | 501 | } |
| 488 | 502 |
| @@ -42,7 +42,7 @@ type ProductPlanDispatchRecordDto struct { | @@ -42,7 +42,7 @@ type ProductPlanDispatchRecordDto struct { | ||
| 42 | func (d *ProductPlanDispatchRecordDto) LoadDto(m *domain.ProductPlanDispatchRecord, orgId int) *ProductPlanDispatchRecordDto { | 42 | func (d *ProductPlanDispatchRecordDto) LoadDto(m *domain.ProductPlanDispatchRecord, orgId int) *ProductPlanDispatchRecordDto { |
| 43 | d.ProductPlanId = m.ProductPlanDispatchRecordId | 43 | d.ProductPlanId = m.ProductPlanDispatchRecordId |
| 44 | d.BatchNumber = m.BatchNumber | 44 | d.BatchNumber = m.BatchNumber |
| 45 | - d.ProductDate = m.ProductDate.Format("2006/01/02") | 45 | + d.ProductDate = m.ProductDate.Local().Format("2006-01-02") |
| 46 | d.WorkStation = m.WorkStation | 46 | d.WorkStation = m.WorkStation |
| 47 | d.WorkOn = m.PlanDispatchRecordExt.WorkOn | 47 | d.WorkOn = m.PlanDispatchRecordExt.WorkOn |
| 48 | d.PlanProductName = m.PlanDispatchRecordExt.PlanProductName | 48 | d.PlanProductName = m.PlanDispatchRecordExt.PlanProductName |
| @@ -47,13 +47,13 @@ func (d *ProductLevelTwoRecord) LoadDto(m *domain.ProductRecord, orgId int) *Pro | @@ -47,13 +47,13 @@ func (d *ProductLevelTwoRecord) LoadDto(m *domain.ProductRecord, orgId int) *Pro | ||
| 47 | d.WeighAfter = m.ProductRecordInfo.WeighAfter | 47 | d.WeighAfter = m.ProductRecordInfo.WeighAfter |
| 48 | d.ApproveStatus = m.ProductRecordInfo.ApproveStatus | 48 | d.ApproveStatus = m.ProductRecordInfo.ApproveStatus |
| 49 | if m.ProductRecordInfo.ApproveAt > 0 { | 49 | if m.ProductRecordInfo.ApproveAt > 0 { |
| 50 | - d.ApproveAt = time.Unix(m.ProductRecordInfo.ApproveAt, 0).Format("2006-01-02 15:04:05") | 50 | + d.ApproveAt = time.Unix(m.ProductRecordInfo.ApproveAt, 0).Local().Format("2006-01-02 15:04:05") |
| 51 | d.ApproveUser = m.ProductRecordInfo.ApproveUser | 51 | d.ApproveUser = m.ProductRecordInfo.ApproveUser |
| 52 | } | 52 | } |
| 53 | d.PlanProductName = m.ProductRecordInfo.PlanProductName | 53 | d.PlanProductName = m.ProductRecordInfo.PlanProductName |
| 54 | d.BatchNumber = m.ProductRecordInfo.BatchNumber | 54 | d.BatchNumber = m.ProductRecordInfo.BatchNumber |
| 55 | - d.CreatedDate = m.CreatedAt.Format("2006-01-02") | ||
| 56 | - d.CreatedAt = m.CreatedAt.Format("2006-01-02 15:04:05") | 55 | + d.CreatedDate = m.CreatedAt.Local().Format("2006-01-02") |
| 56 | + d.CreatedAt = m.CreatedAt.Local().Format("2006-01-02 15:04:05") | ||
| 57 | d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId) | 57 | d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId) |
| 58 | if m.Ext != nil { | 58 | if m.Ext != nil { |
| 59 | d.OrgName = m.Ext.OrgName | 59 | d.OrgName = m.Ext.OrgName |
| @@ -171,7 +171,13 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string | @@ -171,7 +171,13 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string | ||
| 171 | off := make([][]int, 0) | 171 | off := make([][]int, 0) |
| 172 | err := make([][]int, 0) | 172 | err := make([][]int, 0) |
| 173 | var begin, end int = 0, 0 | 173 | var begin, end int = 0, 0 |
| 174 | - var status = 1 // 1.故障:1 0 \ 0 0 2.正常:1 1 3.停机:0 1 | 174 | + /* |
| 175 | + 1.故障: 1 0 \ 0 0 | ||
| 176 | + 2.正常: 1 1 | ||
| 177 | + 3.停机:0 1 | ||
| 178 | + */ | ||
| 179 | + var status = 1 | ||
| 180 | + // 添加数据 | ||
| 175 | addToStatus := func(s []int, status int) { | 181 | addToStatus := func(s []int, status int) { |
| 176 | switch status { | 182 | switch status { |
| 177 | case 1: | 183 | case 1: |
| @@ -185,6 +191,7 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string | @@ -185,6 +191,7 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string | ||
| 185 | break | 191 | break |
| 186 | } | 192 | } |
| 187 | } | 193 | } |
| 194 | + // 计算当前状态 | ||
| 188 | computeStatus := func(up, com int, index int) int { | 195 | computeStatus := func(up, com int, index int) int { |
| 189 | var val = 0 | 196 | var val = 0 |
| 190 | if up&index > 0 { | 197 | if up&index > 0 { |
| @@ -199,6 +206,9 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string | @@ -199,6 +206,9 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string | ||
| 199 | if val == 3 { | 206 | if val == 3 { |
| 200 | return 2 //正常 | 207 | return 2 //正常 |
| 201 | } | 208 | } |
| 209 | + if val == 2 { | ||
| 210 | + return 3 //停机 | ||
| 211 | + } | ||
| 202 | return 3 // 停机 | 212 | return 3 // 停机 |
| 203 | } | 213 | } |
| 204 | 214 | ||
| @@ -223,7 +233,6 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string | @@ -223,7 +233,6 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string | ||
| 223 | curStatus := computeStatus(hds.Up, hds.Com, index) | 233 | curStatus := computeStatus(hds.Up, hds.Com, index) |
| 224 | if curStatus == status { | 234 | if curStatus == status { |
| 225 | end += 1 | 235 | end += 1 |
| 226 | - //continue | ||
| 227 | } else { | 236 | } else { |
| 228 | addToStatus([]int{begin, end}, status) | 237 | addToStatus([]int{begin, end}, status) |
| 229 | status = curStatus | 238 | status = curStatus |
| @@ -2,6 +2,7 @@ package domain | @@ -2,6 +2,7 @@ package domain | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "errors" | 4 | "errors" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
| 5 | "time" | 6 | "time" |
| 6 | ) | 7 | ) |
| 7 | 8 | ||
| @@ -74,7 +75,7 @@ func (productAttendanceRecord *ProductAttendanceRecord) ComputeWorkTimeBefore() | @@ -74,7 +75,7 @@ func (productAttendanceRecord *ProductAttendanceRecord) ComputeWorkTimeBefore() | ||
| 74 | if !productAttendanceRecord.SignOut.After(productAttendanceRecord.SignIn) { | 75 | if !productAttendanceRecord.SignOut.After(productAttendanceRecord.SignIn) { |
| 75 | return 0 | 76 | return 0 |
| 76 | } | 77 | } |
| 77 | - return productAttendanceRecord.SignOut.Sub(productAttendanceRecord.SignIn).Hours() | 78 | + return utils.Round(productAttendanceRecord.SignOut.Sub(productAttendanceRecord.SignIn).Hours(), 1) |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | func (productAttendanceRecord *ProductAttendanceRecord) Approve(approveUser *User, workTimeAfter float64, status int) error { | 81 | func (productAttendanceRecord *ProductAttendanceRecord) Approve(approveUser *User, workTimeAfter float64, status int) error { |
| @@ -33,7 +33,7 @@ func NewWorkStation(w *Workshop, l *ProductLine, s *ProductSection) *WorkStation | @@ -33,7 +33,7 @@ func NewWorkStation(w *Workshop, l *ProductLine, s *ProductSection) *WorkStation | ||
| 33 | //Principal: w.Principal, | 33 | //Principal: w.Principal, |
| 34 | } | 34 | } |
| 35 | if w != nil && l != nil && s != nil { | 35 | if w != nil && l != nil && s != nil { |
| 36 | - item.WorkStationId = fmt.Sprintf("%v.%v.%v", w.WorkshopId, l.LineId, s.SectionId) | 36 | + item.WorkStationId = WorkstationKey(w.WorkshopId, l.LineId, s.SectionId) |
| 37 | } | 37 | } |
| 38 | if w != nil { | 38 | if w != nil { |
| 39 | item.WorkshopId = w.WorkshopId | 39 | item.WorkshopId = w.WorkshopId |
| @@ -49,3 +49,7 @@ func NewWorkStation(w *Workshop, l *ProductLine, s *ProductSection) *WorkStation | @@ -49,3 +49,7 @@ func NewWorkStation(w *Workshop, l *ProductLine, s *ProductSection) *WorkStation | ||
| 49 | } | 49 | } |
| 50 | return item | 50 | return item |
| 51 | } | 51 | } |
| 52 | + | ||
| 53 | +func WorkstationKey(workshopId, lineId, sectionId int) string { | ||
| 54 | + return fmt.Sprintf("%v.%v.%v", workshopId, lineId, sectionId) | ||
| 55 | +} |
| @@ -2,6 +2,7 @@ package dao | @@ -2,6 +2,7 @@ package dao | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "github.com/go-pg/pg/v10/orm" | ||
| 5 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | 6 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" |
| 6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 7 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
| @@ -34,9 +35,15 @@ func (dao *AttendanceRecordDao) ProductWorkStationAttendanceRecord(companyId, or | @@ -34,9 +35,15 @@ func (dao *AttendanceRecordDao) ProductWorkStationAttendanceRecord(companyId, or | ||
| 34 | query.Where("org_id = ?", orgId) | 35 | query.Where("org_id = ?", orgId) |
| 35 | query.Where("work_station->>'workStationId' = ?", workStationId) | 36 | query.Where("work_station->>'workStationId' = ?", workStationId) |
| 36 | query.Where("sign_in <= ?", productTime) | 37 | query.Where("sign_in <= ?", productTime) |
| 37 | - query.Where("sign_out >= ?", productTime) | 38 | + query.WhereGroup(func(q *orm.Query) (*orm.Query, error) { |
| 39 | + query.WhereOr("sign_out >= ?", productTime) | ||
| 40 | + query.WhereOr("sign_out=?", time.Time{}) | ||
| 41 | + return q, nil | ||
| 42 | + }) | ||
| 43 | + query.DistinctOn("product_worker->>'userId',work_station->>'workStationId'") | ||
| 44 | + | ||
| 38 | query.SetOffsetAndLimit(domain.MaxQueryRow) | 45 | query.SetOffsetAndLimit(domain.MaxQueryRow) |
| 39 | - query.SetOrderDirect("product_attendance_id", "DESC") | 46 | + query.OrderExpr("product_worker->>'userId' asc ,work_station->>'workStationId' asc") |
| 40 | if count, err := query.SelectAndCount(); err != nil { | 47 | if count, err := query.SelectAndCount(); err != nil { |
| 41 | return 0, productAttendanceRecords, err | 48 | return 0, productAttendanceRecords, err |
| 42 | } else { | 49 | } else { |
| @@ -94,6 +101,9 @@ func (dao *AttendanceRecordDao) WorkerAttendanceRecords(companyId, orgId, worker | @@ -94,6 +101,9 @@ func (dao *AttendanceRecordDao) WorkerAttendanceRecords(companyId, orgId, worker | ||
| 94 | query.Where("sign_in >= ?", beginTime) | 101 | query.Where("sign_in >= ?", beginTime) |
| 95 | query.Where("sign_in <= ?", endTime) | 102 | query.Where("sign_in <= ?", endTime) |
| 96 | query.Where("attendance_status = ?", domain.AttendanceNotApprove) | 103 | query.Where("attendance_status = ?", domain.AttendanceNotApprove) |
| 104 | + if len(workStationId) > 0 { | ||
| 105 | + query.Where("work_station ->>'workStationId' = ?", workStationId) | ||
| 106 | + } | ||
| 97 | query.SetOffsetAndLimit(domain.MaxQueryRow) | 107 | query.SetOffsetAndLimit(domain.MaxQueryRow) |
| 98 | query.SetOrderDirect("product_attendance_id", "DESC") | 108 | query.SetOrderDirect("product_attendance_id", "DESC") |
| 99 | if count, err := query.SelectAndCount(); err != nil { | 109 | if count, err := query.SelectAndCount(); err != nil { |
| @@ -58,7 +58,8 @@ func (dao *EmployeeProductRecordDao) WorkerBestOutputRecord(companyId, orgId, pl | @@ -58,7 +58,8 @@ func (dao *EmployeeProductRecordDao) WorkerBestOutputRecord(companyId, orgId, pl | ||
| 58 | query.Where("org_id = ?", orgId) | 58 | query.Where("org_id = ?", orgId) |
| 59 | query.Where("product_worker ->>'userId' = '?'", workerId) | 59 | query.Where("product_worker ->>'userId' = '?'", workerId) |
| 60 | query.Where("product_record_info ->>'productPlanId' = '?'", planId) | 60 | query.Where("product_record_info ->>'productPlanId' = '?'", planId) |
| 61 | - query.Order("product_record_info ->>'outputWeight' DESC") | 61 | + query.OrderExpr("product_record_info ->>'outputWeight' DESC") |
| 62 | + query.Limit(1) | ||
| 62 | if err := query.First(); err != nil { | 63 | if err := query.First(); err != nil { |
| 63 | if err.Error() == "pg: no rows in result set" { | 64 | if err.Error() == "pg: no rows in result set" { |
| 64 | return nil, domain.ErrorNotFound | 65 | return nil, domain.ErrorNotFound |
| @@ -32,7 +32,7 @@ func (dao *WorkshopProductRecordDao) WorkshopProductRecord(companyId, orgId, pla | @@ -32,7 +32,7 @@ func (dao *WorkshopProductRecordDao) WorkshopProductRecord(companyId, orgId, pla | ||
| 32 | query := sqlbuilder.BuildQuery(tx.Model(employeeProductRecordModel), map[string]interface{}{}) | 32 | query := sqlbuilder.BuildQuery(tx.Model(employeeProductRecordModel), map[string]interface{}{}) |
| 33 | query.Where("company_id = ?", companyId) | 33 | query.Where("company_id = ?", companyId) |
| 34 | query.Where("org_id = ?", orgId) | 34 | query.Where("org_id = ?", orgId) |
| 35 | - query.Where("product_date = ?", productTime.Format("2006-01-02")) | 35 | + query.Where("product_date = ?", productTime.Local().Format("2006-01-02")) |
| 36 | query.Where("product_record_info ->>'productPlanId' = '?'", planId) | 36 | query.Where("product_record_info ->>'productPlanId' = '?'", planId) |
| 37 | if err := query.First(); err != nil { | 37 | if err := query.First(); err != nil { |
| 38 | if err.Error() == "pg: no rows in result set" { | 38 | if err.Error() == "pg: no rows in result set" { |
| 1 | package domainService | 1 | package domainService |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "errors" | ||
| 4 | "fmt" | 5 | "fmt" |
| 5 | "github.com/linmadan/egglib-go/core/application" | 6 | "github.com/linmadan/egglib-go/core/application" |
| 6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 7 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
| @@ -96,6 +97,12 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu | @@ -96,6 +97,12 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu | ||
| 96 | if productRecordType == domain.RecordTypeReceiveMaterial || productRecordType == domain.RecordTypeReturnMaterial { | 97 | if productRecordType == domain.RecordTypeReceiveMaterial || productRecordType == domain.RecordTypeReturnMaterial { |
| 97 | weight = (weight / uc.FromUnitQuantity.Quantity) * uc.ToUnitQuantity.Quantity | 98 | weight = (weight / uc.FromUnitQuantity.Quantity) * uc.ToUnitQuantity.Quantity |
| 98 | } | 99 | } |
| 100 | + // 退料、需要判断用户是否有领过料 | ||
| 101 | + if productRecordType == domain.RecordTypeReturnMaterial { | ||
| 102 | + if _, records, err := productRecordRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "employeeId": user.UserId, "productPlanId": plan.ProductPlanId, "productRecordType": domain.RecordTypeReceiveMaterial, "limit": 1}); err == nil && len(records) == 0 { | ||
| 103 | + return nil, errors.New("当前批次未进行领料,无法退料") | ||
| 104 | + } | ||
| 105 | + } | ||
| 99 | 106 | ||
| 100 | record := &domain.ProductRecord{ | 107 | record := &domain.ProductRecord{ |
| 101 | CompanyId: request.CompanyId, | 108 | CompanyId: request.CompanyId, |
| @@ -106,7 +113,7 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu | @@ -106,7 +113,7 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu | ||
| 106 | CreatedAt: time.Now(), | 113 | CreatedAt: time.Now(), |
| 107 | UpdatedAt: time.Now(), | 114 | UpdatedAt: time.Now(), |
| 108 | ProductRecordInfo: &domain.ProductRecordInfo{ | 115 | ProductRecordInfo: &domain.ProductRecordInfo{ |
| 109 | - ProductDate: plan.ProductDate.Format("2006-01-02"), | 116 | + ProductDate: plan.ProductDate.Local().Format("2006-01-02"), |
| 110 | Original: request.Weigh, | 117 | Original: request.Weigh, |
| 111 | Weigh: weight, | 118 | Weigh: weight, |
| 112 | WeighBefore: weight, | 119 | WeighBefore: weight, |
| @@ -16,6 +16,10 @@ const ( | @@ -16,6 +16,10 @@ const ( | ||
| 16 | ProductSection4 = "包装" | 16 | ProductSection4 = "包装" |
| 17 | ) | 17 | ) |
| 18 | 18 | ||
| 19 | +const ( | ||
| 20 | + DefaultCCJUnitQuantity = 0.2 //kg 穿串机默认的换算数量 1串/0.1千克 | ||
| 21 | +) | ||
| 22 | + | ||
| 19 | //EmployeeProductStatics 员工产能统计 | 23 | //EmployeeProductStatics 员工产能统计 |
| 20 | func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.ProductRecord) (interface{}, error) { | 24 | func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.ProductRecord) (interface{}, error) { |
| 21 | 25 | ||
| @@ -56,7 +60,10 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | @@ -56,7 +60,10 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | ||
| 56 | default: | 60 | default: |
| 57 | return nil, nil //ptr.personalProductStatics(productRecord) | 61 | return nil, nil //ptr.personalProductStatics(productRecord) |
| 58 | } | 62 | } |
| 59 | - | 63 | + if planId == 0 { |
| 64 | + log.Logger.Debug(fmt.Sprintf("工段:%v product_record 编号:%v 批次为0", productRecord.WorkStation.WorkStationId, productRecord.ProductRecordId)) | ||
| 65 | + return nil, nil | ||
| 66 | + } | ||
| 60 | productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId}) | 67 | productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId}) |
| 61 | if err != nil { | 68 | if err != nil { |
| 62 | return nil, err | 69 | return nil, err |
| @@ -66,7 +73,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | @@ -66,7 +73,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | ||
| 66 | // 1.查询员工 -》 员工打卡记录 工位+打卡日期 | 73 | // 1.查询员工 -》 员工打卡记录 工位+打卡日期 |
| 67 | // 2.打卡记录的时间区间 在生产记录上报的时间范围内 | 74 | // 2.打卡记录的时间区间 在生产记录上报的时间范围内 |
| 68 | attendanceRecordDao, _ := dao.NewAttendanceRecordDao(ptr.transactionContext) | 75 | attendanceRecordDao, _ := dao.NewAttendanceRecordDao(ptr.transactionContext) |
| 69 | - _, attendanceRecords, err := attendanceRecordDao.ProductWorkStationAttendanceRecord(cid, oid, productRecord.WorkStation.WorkStationId, productRecord.CreatedAt) | 76 | + _, attendanceRecords, err := attendanceRecordDao.ProductWorkStationAttendanceRecord(cid, oid, productRecord.WorkStation.WorkStationId, time.Now()) //, productRecord.CreatedAt |
| 70 | if err != nil || len(attendanceRecords) == 0 { | 77 | if err != nil || len(attendanceRecords) == 0 { |
| 71 | return nil, err | 78 | return nil, err |
| 72 | } | 79 | } |
| @@ -97,6 +104,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | @@ -97,6 +104,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | ||
| 97 | yesterdayOutputWeight float64 = 0 | 104 | yesterdayOutputWeight float64 = 0 |
| 98 | bestOutputWeight float64 = 0 | 105 | bestOutputWeight float64 = 0 |
| 99 | ) | 106 | ) |
| 107 | + if employeeProductRecord.ProductRecordInfo.BestOutputWeight > 0 { | ||
| 100 | if record, e := employeeProductRecordDao.WorkerProductRecord(cid, oid, planId, r.ProductWorker.UserId, productRecord.CreatedAt.AddDate(0, 0, -1)); e == nil && record != nil { | 108 | if record, e := employeeProductRecordDao.WorkerProductRecord(cid, oid, planId, r.ProductWorker.UserId, productRecord.CreatedAt.AddDate(0, 0, -1)); e == nil && record != nil { |
| 101 | yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight | 109 | yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight |
| 102 | bestOutputWeight = record.ProductRecordInfo.BestOutputWeight | 110 | bestOutputWeight = record.ProductRecordInfo.BestOutputWeight |
| @@ -106,6 +114,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | @@ -106,6 +114,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | ||
| 106 | yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight | 114 | yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight |
| 107 | } | 115 | } |
| 108 | } | 116 | } |
| 117 | + } | ||
| 109 | 118 | ||
| 110 | employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight) | 119 | employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight) |
| 111 | 120 | ||
| @@ -139,7 +148,7 @@ func newEmployeeProductRecord(productRecord *domain.ProductRecord, participateTy | @@ -139,7 +148,7 @@ func newEmployeeProductRecord(productRecord *domain.ProductRecord, participateTy | ||
| 139 | Ext: productPlan.Ext, | 148 | Ext: productPlan.Ext, |
| 140 | Version: 1, | 149 | Version: 1, |
| 141 | ProductRecordInfo: &domain.ProductRecordStaticInfo{ | 150 | ProductRecordInfo: &domain.ProductRecordStaticInfo{ |
| 142 | - ProductDate: productRecord.CreatedAt.Format("2006-01-02"), | 151 | + ProductDate: productRecord.CreatedAt.Local().Format("2006-01-02"), |
| 143 | ProductPlanId: productRecord.ProductRecordInfo.ProductPlanId, | 152 | ProductPlanId: productRecord.ProductRecordInfo.ProductPlanId, |
| 144 | PlanProductName: productRecord.ProductRecordInfo.PlanProductName, | 153 | PlanProductName: productRecord.ProductRecordInfo.PlanProductName, |
| 145 | BatchNumber: productRecord.ProductRecordInfo.BatchNumber, | 154 | BatchNumber: productRecord.ProductRecordInfo.BatchNumber, |
| @@ -191,6 +200,7 @@ func FindGroupMembers(productGroupRepository domain.ProductGroupRepository, comp | @@ -191,6 +200,7 @@ func FindGroupMembers(productGroupRepository domain.ProductGroupRepository, comp | ||
| 191 | u := groups[i].GroupMembers[j] | 200 | u := groups[i].GroupMembers[j] |
| 192 | u.GroupId = groups[i].ProductGroupId | 201 | u.GroupId = groups[i].ProductGroupId |
| 193 | u.GroupName = groups[i].GroupName | 202 | u.GroupName = groups[i].GroupName |
| 203 | + u.WorkOn = groups[i].WorkOn | ||
| 194 | result[keyFunc(u.UserId)] = u | 204 | result[keyFunc(u.UserId)] = u |
| 195 | } | 205 | } |
| 196 | } | 206 | } |
| @@ -247,10 +257,6 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. | @@ -247,10 +257,6 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. | ||
| 247 | } | 257 | } |
| 248 | } | 258 | } |
| 249 | } | 259 | } |
| 250 | - // 更新批次的产能 (只有包装要更新批次产能) | ||
| 251 | - //if productPlan.WorkStation.SectionName==ProductSection4{ | ||
| 252 | - // | ||
| 253 | - //} | ||
| 254 | 260 | ||
| 255 | employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight) | 261 | employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight) |
| 256 | 262 | ||
| @@ -277,7 +283,10 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain. | @@ -277,7 +283,10 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain. | ||
| 277 | productPlan *domain.ProductPlan | 283 | productPlan *domain.ProductPlan |
| 278 | err error | 284 | err error |
| 279 | ) | 285 | ) |
| 280 | - | 286 | + if planId == 0 { |
| 287 | + log.Logger.Debug(fmt.Sprintf("工段:%v product_record 编号:%v 批次为0", productRecord.WorkStation.WorkStationId, productRecord.ProductRecordId)) | ||
| 288 | + return nil, nil | ||
| 289 | + } | ||
| 281 | productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId}) | 290 | productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId}) |
| 282 | if err != nil { | 291 | if err != nil { |
| 283 | return nil, err | 292 | return nil, err |
| @@ -326,7 +335,7 @@ func newWorkshopProductRecord(productRecord *domain.ProductRecord, productPlan * | @@ -326,7 +335,7 @@ func newWorkshopProductRecord(productRecord *domain.ProductRecord, productPlan * | ||
| 326 | WorkStation: productRecord.WorkStation, | 335 | WorkStation: productRecord.WorkStation, |
| 327 | //WorkOn: productPlan.WorkOn, | 336 | //WorkOn: productPlan.WorkOn, |
| 328 | //ParticipateType: participateType, | 337 | //ParticipateType: participateType, |
| 329 | - ProductDate: productRecord.CreatedAt.Format("2006-01-02"), | 338 | + ProductDate: productRecord.CreatedAt.Local().Format("2006-01-02"), |
| 330 | ProductWeigh: 0, | 339 | ProductWeigh: 0, |
| 331 | SecondLevelWeigh: 0, | 340 | SecondLevelWeigh: 0, |
| 332 | CreatedAt: time.Now(), | 341 | CreatedAt: time.Now(), |
| @@ -334,7 +343,7 @@ func newWorkshopProductRecord(productRecord *domain.ProductRecord, productPlan * | @@ -334,7 +343,7 @@ func newWorkshopProductRecord(productRecord *domain.ProductRecord, productPlan * | ||
| 334 | Ext: productPlan.Ext, | 343 | Ext: productPlan.Ext, |
| 335 | Version: 1, | 344 | Version: 1, |
| 336 | ProductRecordInfo: &domain.ProductRecordStaticInfo{ | 345 | ProductRecordInfo: &domain.ProductRecordStaticInfo{ |
| 337 | - ProductDate: productRecord.CreatedAt.Format("2006-01-02"), | 346 | + ProductDate: productRecord.CreatedAt.Local().Format("2006-01-02"), |
| 338 | ProductPlanId: productRecord.ProductRecordInfo.ProductPlanId, | 347 | ProductPlanId: productRecord.ProductRecordInfo.ProductPlanId, |
| 339 | PlanProductName: productRecord.ProductRecordInfo.PlanProductName, | 348 | PlanProductName: productRecord.ProductRecordInfo.PlanProductName, |
| 340 | BatchNumber: productRecord.ProductRecordInfo.BatchNumber, | 349 | BatchNumber: productRecord.ProductRecordInfo.BatchNumber, |
| @@ -23,7 +23,7 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | @@ -23,7 +23,7 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | ||
| 23 | attendanceRecordRepository, _ = repository.NewProductAttendanceRecordRepository(ptr.transactionContext) | 23 | attendanceRecordRepository, _ = repository.NewProductAttendanceRecordRepository(ptr.transactionContext) |
| 24 | isSignIn = true | 24 | isSignIn = true |
| 25 | record *domain.ProductAttendanceRecord | 25 | record *domain.ProductAttendanceRecord |
| 26 | - workStationId string //具体工位 | 26 | + //workStationId string //具体工位 |
| 27 | workStation *domain.WorkStation | 27 | workStation *domain.WorkStation |
| 28 | attendanceType int = domain.ParticipateNormal | 28 | attendanceType int = domain.ParticipateNormal |
| 29 | worker *domain.User | 29 | worker *domain.User |
| @@ -68,9 +68,32 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | @@ -68,9 +68,32 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | ||
| 68 | 68 | ||
| 69 | beginTime := utils.GetZeroTime(report.ActionTime) | 69 | beginTime := utils.GetZeroTime(report.ActionTime) |
| 70 | endTime := report.ActionTime | 70 | endTime := report.ActionTime |
| 71 | - _, records, _ := attendanceRecordDao.WorkerAttendanceRecords(cid, oid, worker.UserId, workStationId, beginTime, endTime) | 71 | + _, records, _ := attendanceRecordDao.WorkerAttendanceRecords(cid, oid, worker.UserId, "", beginTime, endTime) |
| 72 | for i := 0; i < len(records); i++ { | 72 | for i := 0; i < len(records); i++ { |
| 73 | r := records[i] | 73 | r := records[i] |
| 74 | + if workStation.WorkStationId == r.WorkStation.WorkStationId { | ||
| 75 | + continue | ||
| 76 | + } | ||
| 77 | + if !utils.TimeIsZero(r.SignIn) && utils.TimeIsZero(r.SignOut) { | ||
| 78 | + if utils.TimeAfterEqual(report.ActionTime, r.SignIn) { | ||
| 79 | + r.SignOut = report.ActionTime | ||
| 80 | + r.WorkTimeBefore = r.ComputeWorkTimeBefore() | ||
| 81 | + log.Logger.Debug(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 在其他工段打卡 下线当前工段:%v 签退 %v", worker.UserName, worker.UserId, r.WorkStation.SectionName, report)) | ||
| 82 | + if _, err = attendanceRecordRepository.Save(r); err != nil { | ||
| 83 | + return nil, err | ||
| 84 | + } | ||
| 85 | + } else { | ||
| 86 | + log.Logger.Debug(fmt.Sprintf("【考勤汇报】 考勤记录不合法,操作时间小于签到时间 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime)) | ||
| 87 | + return struct{}{}, nil | ||
| 88 | + } | ||
| 89 | + break | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | + for i := 0; i < len(records); i++ { | ||
| 93 | + r := records[i] | ||
| 94 | + if workStation.WorkStationId != r.WorkStation.WorkStationId { | ||
| 95 | + continue | ||
| 96 | + } | ||
| 74 | // 操作时间 < 签到时间 | 97 | // 操作时间 < 签到时间 |
| 75 | if utils.TimeAfterEqual(r.SignIn, report.ActionTime) { | 98 | if utils.TimeAfterEqual(r.SignIn, report.ActionTime) { |
| 76 | log.Logger.Debug(fmt.Sprintf("【考勤汇报】 考勤记录不合法,操作时间小于签到时间 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime)) | 99 | log.Logger.Debug(fmt.Sprintf("【考勤汇报】 考勤记录不合法,操作时间小于签到时间 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime)) |
| @@ -88,6 +111,11 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | @@ -88,6 +111,11 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | ||
| 88 | // 存在未结束的打卡记录 | 111 | // 存在未结束的打卡记录 |
| 89 | // 1.满足条件-签退 | 112 | // 1.满足条件-签退 |
| 90 | if !utils.TimeIsZero(r.SignIn) && utils.TimeIsZero(r.SignOut) { | 113 | if !utils.TimeIsZero(r.SignIn) && utils.TimeIsZero(r.SignOut) { |
| 114 | + // 五分钟内重复打卡不算数 | ||
| 115 | + if r.SignIn.Add(time.Minute * 5).After(report.ActionTime) { | ||
| 116 | + log.Logger.Debug(fmt.Sprintf("【考勤汇报】 打卡未满五分钟 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime)) | ||
| 117 | + return struct{}{}, nil | ||
| 118 | + } | ||
| 91 | if utils.TimeBeforeEqual(r.SignIn, report.ActionTime) { | 119 | if utils.TimeBeforeEqual(r.SignIn, report.ActionTime) { |
| 92 | isSignIn = false | 120 | isSignIn = false |
| 93 | record = r | 121 | record = r |
| @@ -65,9 +65,9 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | @@ -65,9 +65,9 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | ||
| 65 | } | 65 | } |
| 66 | workStation = device.WorkStation | 66 | workStation = device.WorkStation |
| 67 | // 封箱机、串串机需要定位到批次 | 67 | // 封箱机、串串机需要定位到批次 |
| 68 | - if record.DeviceType == domain.DeviceTypeFengXiangJi && record.DeviceType == domain.DeviceTypeChuanChuanJi { | 68 | + if record.DeviceType == domain.DeviceTypeFengXiangJi || record.DeviceType == domain.DeviceTypeChuanChuanJi { |
| 69 | datetime, _ = time.Parse("2006-01-02", deviceRunningData.Date) | 69 | datetime, _ = time.Parse("2006-01-02", deviceRunningData.Date) |
| 70 | - if plan, err = ptr.findDeviceProductPlan(companyId, orgId, workStation.WorkStationId, datetime, deviceRunningData.DeviceCode); err != nil { | 70 | + if plan, err = ptr.findDeviceProductPlan(companyId, orgId, workStation.WorkStationId, datetime, deviceRunningData.ProductType); err != nil { |
| 71 | log.Logger.Error(err.Error()) | 71 | log.Logger.Error(err.Error()) |
| 72 | } else { | 72 | } else { |
| 73 | planId = plan.PlanDispatchRecordExt.ProductPlanId | 73 | planId = plan.PlanDispatchRecordExt.ProductPlanId |
| @@ -90,6 +90,13 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | @@ -90,6 +90,13 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | ||
| 90 | return nil, err | 90 | return nil, err |
| 91 | } | 91 | } |
| 92 | // 2.保存设备生产记录 | 92 | // 2.保存设备生产记录 |
| 93 | + if record.DeviceType == domain.DeviceTypeChuanChuanJi { | ||
| 94 | + productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, planId) | ||
| 95 | + //if _, err = deviceRunningRecordRepository.Save(deviceRunningRecord); err != nil { | ||
| 96 | + // return nil, err | ||
| 97 | + //} | ||
| 98 | + SendProductRecordStaticsJob(productRecord) | ||
| 99 | + } | ||
| 93 | 100 | ||
| 94 | // 3.更新 设备每日运行记录(汇总) - redis更新 十分钟异步刷库 | 101 | // 3.更新 设备每日运行记录(汇总) - redis更新 十分钟异步刷库 |
| 95 | deviceDailyRecord.AddDeviceRunningData(deviceRunningData.CollectionTime, deviceRunningData) | 102 | deviceDailyRecord.AddDeviceRunningData(deviceRunningData.CollectionTime, deviceRunningData) |
| @@ -101,7 +108,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | @@ -101,7 +108,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | ||
| 101 | 108 | ||
| 102 | func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.DeviceCollection) (*domain.DeviceRunningData, error) { | 109 | func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.DeviceCollection) (*domain.DeviceRunningData, error) { |
| 103 | var err error | 110 | var err error |
| 104 | - var unitQuantity float64 = 1 // 单位数量 | 111 | + var unitQuantity float64 = DefaultCCJUnitQuantity // 单位数量 |
| 105 | var data = &domain.DeviceRunningData{ | 112 | var data = &domain.DeviceRunningData{ |
| 106 | DeviceCollectionId: record.DeviceCollectionId, | 113 | DeviceCollectionId: record.DeviceCollectionId, |
| 107 | WorkShopName: record.WorkShopName, | 114 | WorkShopName: record.WorkShopName, |
| @@ -121,7 +128,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev | @@ -121,7 +128,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev | ||
| 121 | md, _ := strconv.Atoi(m) | 128 | md, _ := strconv.Atoi(m) |
| 122 | dd, _ := strconv.Atoi(d) | 129 | dd, _ := strconv.Atoi(d) |
| 123 | t := time.Date(yd, time.Month(md), dd, 0, 0, 0, 0, time.Local) | 130 | t := time.Date(yd, time.Month(md), dd, 0, 0, 0, 0, time.Local) |
| 124 | - return t.Format("2006-01-02"), nil | 131 | + return t.Local().Format("2006-01-02"), nil |
| 125 | } | 132 | } |
| 126 | switch record.DeviceType { | 133 | switch record.DeviceType { |
| 127 | //包馅机 | 134 | //包馅机 |
| @@ -210,25 +217,29 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId | @@ -210,25 +217,29 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId | ||
| 210 | }, nil | 217 | }, nil |
| 211 | } | 218 | } |
| 212 | 219 | ||
| 213 | -func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, org *domain.Org, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData, planId int) (*domain.ProductRecord, error) { | ||
| 214 | - return &domain.ProductRecord{ | 220 | +func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId int, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData, planId int) (*domain.ProductRecord, error) { |
| 221 | + result := &domain.ProductRecord{ | ||
| 215 | CompanyId: companyId, | 222 | CompanyId: companyId, |
| 216 | - OrgId: org.OrgId, | 223 | + OrgId: orgId, |
| 217 | WorkStation: workStation, | 224 | WorkStation: workStation, |
| 218 | ProductRecordType: domain.RecordTypeWeigh, | 225 | ProductRecordType: domain.RecordTypeWeigh, |
| 219 | ProductWorker: &domain.User{}, | 226 | ProductWorker: &domain.User{}, |
| 220 | - CreatedAt: time.Now(), | 227 | + CreatedAt: data.CollectionTime, |
| 221 | UpdatedAt: time.Now(), | 228 | UpdatedAt: time.Now(), |
| 222 | ProductRecordInfo: &domain.ProductRecordInfo{ | 229 | ProductRecordInfo: &domain.ProductRecordInfo{ |
| 223 | - ProductDate: data.CollectionTime.Format("2006-01-02"), | 230 | + ProductDate: data.CollectionTime.Local().Format("2006-01-02"), |
| 224 | Original: float64(data.Count), | 231 | Original: float64(data.Count), |
| 225 | - Weigh: float64(data.Count), | ||
| 226 | - WeighBefore: float64(data.Count), | 232 | + Weigh: float64(data.Count) * DefaultCCJUnitQuantity, |
| 233 | + WeighBefore: float64(data.Count) * DefaultCCJUnitQuantity, | ||
| 227 | ApproveStatus: domain.AttendanceNotApprove, | 234 | ApproveStatus: domain.AttendanceNotApprove, |
| 228 | ProductPlanId: planId, | 235 | ProductPlanId: planId, |
| 229 | }, | 236 | }, |
| 230 | - Ext: domain.NewExt(org.OrgName), | ||
| 231 | - }, nil | 237 | + Ext: domain.NewExt(""), |
| 238 | + } | ||
| 239 | + if device.Ext != nil { | ||
| 240 | + result.Ext = domain.NewExt(device.Ext.OrgName) | ||
| 241 | + } | ||
| 242 | + return result, nil | ||
| 232 | } | 243 | } |
| 233 | 244 | ||
| 234 | func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId, orgId int, workStation *domain.WorkStation, device *domain.Device, planId int, data *domain.DeviceRunningData) (*domain.DeviceDailyRunningRecord, error) { | 245 | func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId, orgId int, workStation *domain.WorkStation, device *domain.Device, planId int, data *domain.DeviceRunningData) (*domain.DeviceDailyRunningRecord, error) { |
| @@ -174,6 +174,12 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac | @@ -174,6 +174,12 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac | ||
| 174 | if v, ok := queryOptions["batchNumber"]; ok && len(v.(string)) > 0 { | 174 | if v, ok := queryOptions["batchNumber"]; ok && len(v.(string)) > 0 { |
| 175 | query.Where(fmt.Sprintf(`product_record_info->>'batchNumber' like '%%%v%%'`, v)) | 175 | query.Where(fmt.Sprintf(`product_record_info->>'batchNumber' like '%%%v%%'`, v)) |
| 176 | } | 176 | } |
| 177 | + if v, ok := queryOptions["employeeId"]; ok && v.(int) > 0 { | ||
| 178 | + query.Where(fmt.Sprintf(`product_worker->>'userId' = '%v'`, v)) | ||
| 179 | + } | ||
| 180 | + if v, ok := queryOptions["productPlanId"]; ok && v.(int) > 0 { | ||
| 181 | + query.Where(fmt.Sprintf(`product_record_info->>'productPlanId' = '%v'`, v)) | ||
| 182 | + } | ||
| 177 | query.SetOffsetAndLimit(domain.MaxQueryRow) | 183 | query.SetOffsetAndLimit(domain.MaxQueryRow) |
| 178 | query.SetOrderDirect("product_record_id", "DESC") | 184 | query.SetOrderDirect("product_record_id", "DESC") |
| 179 | if count, err := query.SelectAndCount(); err != nil { | 185 | if count, err := query.SelectAndCount(); err != nil { |
-
请 注册 或 登录 后发表评论