正在显示
16 个修改的文件
包含
374 行增加
和
24 行删除
@@ -97,4 +97,20 @@ spec: | @@ -97,4 +97,20 @@ spec: | ||
97 | - name: HTTP_PORT | 97 | - name: HTTP_PORT |
98 | value: "8082" | 98 | value: "8082" |
99 | - name: SERVICE_ENV | 99 | - name: SERVICE_ENV |
100 | - value: "dev" | ||
100 | + value: "dev" | ||
101 | + - name: SUPLUS_ADMIN_BASE_HOST | ||
102 | + value: "http://suplus-admin-base-dev.fjmaimaimai.com" | ||
103 | + - name: ALLIED_CREATION_GATEWAY_HOST | ||
104 | + value: "https://allied-creation-gateway-test.fjmaimaimai.com" | ||
105 | + - name: ALLIED_CREATION_USER_HOST | ||
106 | + value: "https://allied-creation-user-test.fjmaimaimai.com" | ||
107 | + - name: ALLIED_CREATION_COOPERATION_HOST | ||
108 | + value: "https://allied-creation-cooperation-test.fjmaimaimai.com" | ||
109 | + - name: ALLIED_CREATION_BASIC_HOST | ||
110 | + value: "https://allied-creation-basic-test.fjmaimaimai.com" | ||
111 | + - name: ALLIED_CREATION_MANUFACTURE_HOST | ||
112 | + value: "http://allied-creation-manufacture-test.fjmaimaimai.com" | ||
113 | + - name: SMS_SERVE_HOST | ||
114 | + value: "https://sms.fjmaimaimai.com:9897" | ||
115 | + - name: SUPLUS_SALE_APP | ||
116 | + value: "http://suplus-sale-app-gateway-test.fjmaimaimai.com" |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/beego/beego/v2/core/validation" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
7 | + "reflect" | ||
8 | + "strings" | ||
9 | +) | ||
10 | + | ||
11 | +type WorkerAttendanceReportCommand struct { | ||
12 | + *domain.DeviceZkTeco | ||
13 | +} | ||
14 | + | ||
15 | +func (removeProductRecordCommand *WorkerAttendanceReportCommand) Valid(validation *validation.Validation) { | ||
16 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
17 | +} | ||
18 | + | ||
19 | +func (removeProductRecordCommand *WorkerAttendanceReportCommand) ValidateCommand() error { | ||
20 | + valid := validation.Validation{} | ||
21 | + b, err := valid.Valid(removeProductRecordCommand) | ||
22 | + if err != nil { | ||
23 | + return err | ||
24 | + } | ||
25 | + if !b { | ||
26 | + elem := reflect.TypeOf(removeProductRecordCommand).Elem() | ||
27 | + for _, validErr := range valid.Errors { | ||
28 | + field, isExist := elem.FieldByName(validErr.Field) | ||
29 | + if isExist { | ||
30 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
31 | + } else { | ||
32 | + return fmt.Errorf(validErr.Message) | ||
33 | + } | ||
34 | + } | ||
35 | + } | ||
36 | + return nil | ||
37 | +} |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" | ||
7 | +) | ||
8 | + | ||
9 | +func (attendanceService *AttendanceService) WorkerAttendanceReport(cmd *command.WorkerAttendanceReportCommand) (interface{}, error) { | ||
10 | + if err := cmd.ValidateCommand(); err != nil { | ||
11 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
12 | + } | ||
13 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
14 | + if err != nil { | ||
15 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
16 | + } | ||
17 | + if err := transactionContext.StartTransaction(); err != nil { | ||
18 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
19 | + } | ||
20 | + defer func() { | ||
21 | + transactionContext.RollbackTransaction() | ||
22 | + }() | ||
23 | + | ||
24 | + //svr, _ := domainService.NewPGWorkshopWorkTimeStaticService(transactionContext.(*pgTransaction.TransactionContext)) | ||
25 | + //if _, err := svr.WorkshopWorkTimeStatic(cmd.ProductAttendanceRecord); err != nil { | ||
26 | + // log.Logger.Error(err.Error()) | ||
27 | + // return nil, err | ||
28 | + //} | ||
29 | + | ||
30 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
31 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
32 | + } | ||
33 | + return struct{}{}, nil | ||
34 | +} |
@@ -350,7 +350,7 @@ func (deviceService *DeviceService) SearchDevice(operateInfo *domain.OperateInfo | @@ -350,7 +350,7 @@ func (deviceService *DeviceService) SearchDevice(operateInfo *domain.OperateInfo | ||
350 | for i := range devices { | 350 | for i := range devices { |
351 | item := devices[i] | 351 | item := devices[i] |
352 | newJobDto := &dto.DeviceDto{} | 352 | newJobDto := &dto.DeviceDto{} |
353 | - item.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId) | 353 | + newJobDto.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId) |
354 | newJobDto.LoadDto(item, operateInfo.OrgId) | 354 | newJobDto.LoadDto(item, operateInfo.OrgId) |
355 | result = append(result, newJobDto) | 355 | result = append(result, newJobDto) |
356 | } | 356 | } |
@@ -328,8 +328,8 @@ func (productCalendarService *ProductCalendarService) UpdateProductCalendar(cmd | @@ -328,8 +328,8 @@ func (productCalendarService *ProductCalendarService) UpdateProductCalendar(cmd | ||
328 | } | 328 | } |
329 | 329 | ||
330 | // 返回工厂日历服务列表 | 330 | // 返回工厂日历服务列表 |
331 | -func (productCalendarService *ProductCalendarService) SearchProductCalendar(operateInfo *domain.OperateInfo, listProductCalendarQuery *query.SearchProductCalendarQuery) (int64, interface{}, error) { | ||
332 | - if err := listProductCalendarQuery.ValidateQuery(); err != nil { | 331 | +func (productCalendarService *ProductCalendarService) SearchProductCalendar(operateInfo *domain.OperateInfo, cmd *query.SearchProductCalendarQuery) (int64, interface{}, error) { |
332 | + if err := cmd.ValidateQuery(); err != nil { | ||
333 | return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 333 | return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
334 | } | 334 | } |
335 | transactionContext, err := factory.CreateTransactionContext(nil) | 335 | transactionContext, err := factory.CreateTransactionContext(nil) |
@@ -345,7 +345,12 @@ func (productCalendarService *ProductCalendarService) SearchProductCalendar(oper | @@ -345,7 +345,12 @@ func (productCalendarService *ProductCalendarService) SearchProductCalendar(oper | ||
345 | var productCalendarRepository domain.ProductCalendarRepository | 345 | var productCalendarRepository domain.ProductCalendarRepository |
346 | productCalendarRepository, _, _ = factory.FastPgProductCalendar(transactionContext, 0) | 346 | productCalendarRepository, _, _ = factory.FastPgProductCalendar(transactionContext, 0) |
347 | 347 | ||
348 | - count, productCalendars, err := productCalendarRepository.Find(utils.ObjectToMap(listProductCalendarQuery)) | 348 | + workshops, _ := factory.FastPgWorkshops(transactionContext, operateInfo.CompanyId) |
349 | + queryOptions := utils.ObjectToMap(cmd) | ||
350 | + delete(queryOptions, "workshopName") | ||
351 | + queryOptions = workshops.FindByNameWithQuery(queryOptions, cmd.WorkshopName, "", "") | ||
352 | + | ||
353 | + count, productCalendars, err := productCalendarRepository.Find(queryOptions) | ||
349 | if err != nil { | 354 | if err != nil { |
350 | return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 355 | return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
351 | } | 356 | } |
@@ -358,6 +363,7 @@ func (productCalendarService *ProductCalendarService) SearchProductCalendar(oper | @@ -358,6 +363,7 @@ func (productCalendarService *ProductCalendarService) SearchProductCalendar(oper | ||
358 | item := productCalendars[i] | 363 | item := productCalendars[i] |
359 | newJobDto := &dto.ProductCalendarDto{} | 364 | newJobDto := &dto.ProductCalendarDto{} |
360 | newJobDto.LoadDto(item, operateInfo.OrgId) | 365 | newJobDto.LoadDto(item, operateInfo.OrgId) |
366 | + newJobDto.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId) | ||
361 | result = append(result, newJobDto) | 367 | result = append(result, newJobDto) |
362 | } | 368 | } |
363 | 369 |
@@ -359,7 +359,7 @@ func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo * | @@ -359,7 +359,7 @@ func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo * | ||
359 | item := productGroups[i] | 359 | item := productGroups[i] |
360 | newItem := &dto.ProductGroupDto{} | 360 | newItem := &dto.ProductGroupDto{} |
361 | newItem.LoadDto(productGroups[i], operateInfo.OrgId) | 361 | newItem.LoadDto(productGroups[i], operateInfo.OrgId) |
362 | - item.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId) | 362 | + newItem.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId) |
363 | results = append(results, newItem) | 363 | results = append(results, newItem) |
364 | } | 364 | } |
365 | if err := transactionContext.CommitTransaction(); err != nil { | 365 | if err := transactionContext.CommitTransaction(); err != nil { |
pkg/constant/manufacture.go
0 → 100644
1 | +package constant | ||
2 | + | ||
3 | +import ( | ||
4 | + "os" | ||
5 | + "strconv" | ||
6 | +) | ||
7 | + | ||
8 | +var ( | ||
9 | + // 生产制造 - 称重系统 - 默认公司 | ||
10 | + MANUFACTURE_WEIGH_DEFAULT_COMPANYID = 1 | ||
11 | + // 生产制造 - 称重系统 - 默认组织 | ||
12 | + MANUFACTURE_WEIGH_DEFAULT_ORGID = 1 | ||
13 | +) | ||
14 | + | ||
15 | +func init() { | ||
16 | + if os.Getenv("MANUFACTURE_WEIGH_DEFAULT_COMPANY_ID") != "" { | ||
17 | + MANUFACTURE_WEIGH_DEFAULT_COMPANYID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_WEIGH_DEFAULT_COMPANYID")) | ||
18 | + } | ||
19 | + if os.Getenv("MANUFACTURE_WEIGH_DEFAULT_ORGID") != "" { | ||
20 | + MANUFACTURE_WEIGH_DEFAULT_ORGID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_WEIGH_DEFAULT_ORGID")) | ||
21 | + } | ||
22 | +} |
@@ -67,7 +67,7 @@ func (employeeProductRecord *EmployeeProductRecord) Update(data map[string]inter | @@ -67,7 +67,7 @@ func (employeeProductRecord *EmployeeProductRecord) Update(data map[string]inter | ||
67 | } | 67 | } |
68 | 68 | ||
69 | // 更新生产量 | 69 | // 更新生产量 |
70 | -func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh float64, productRecordType int, sectionName string) { | 70 | +func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh float64, productRecordType int, sectionName string, yesterdayWeight float64, bestWeight float64) { |
71 | if employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh == nil { | 71 | if employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh == nil { |
72 | employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh = make(map[string]float64) | 72 | employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh = make(map[string]float64) |
73 | } | 73 | } |
@@ -77,13 +77,8 @@ func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh flo | @@ -77,13 +77,8 @@ func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh flo | ||
77 | employeeProductRecord.SecondLevelWeigh += weigh | 77 | employeeProductRecord.SecondLevelWeigh += weigh |
78 | } else { | 78 | } else { |
79 | // 其他工段的二级品 | 79 | // 其他工段的二级品 |
80 | - if _, ok := employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName]; ok { | ||
81 | - employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName] += weigh //存关联级的二级品 | ||
82 | - } else { | ||
83 | - employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName] = weigh | ||
84 | - } | 80 | + employeeProductRecord.ProductRecordInfo.AddSectionWeight(sectionName, weigh) |
85 | } | 81 | } |
86 | - employeeProductRecord.ProductRecordInfo.TotalOtherSecondLevelWeigh = employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh() // 预先统计其他二级品占比 | ||
87 | } | 82 | } |
88 | if productRecordType == RecordTypeReceiveMaterial { | 83 | if productRecordType == RecordTypeReceiveMaterial { |
89 | employeeProductRecord.ProductWeigh += weigh | 84 | employeeProductRecord.ProductWeigh += weigh |
@@ -91,6 +86,7 @@ func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh flo | @@ -91,6 +86,7 @@ func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh flo | ||
91 | if productRecordType == RecordTypeReturnMaterial { | 86 | if productRecordType == RecordTypeReturnMaterial { |
92 | employeeProductRecord.ProductWeigh -= weigh | 87 | employeeProductRecord.ProductWeigh -= weigh |
93 | } | 88 | } |
89 | + employeeProductRecord.ProductRecordInfo.PreStatistics(employeeProductRecord.ProductWeigh, employeeProductRecord.SecondLevelWeigh, 0, 0) | ||
94 | employeeProductRecord.UpdatedAt = time.Now() | 90 | employeeProductRecord.UpdatedAt = time.Now() |
95 | employeeProductRecord.Version += 1 | 91 | employeeProductRecord.Version += 1 |
96 | } | 92 | } |
@@ -9,9 +9,22 @@ type ProductRecordStaticInfo struct { | @@ -9,9 +9,22 @@ type ProductRecordStaticInfo struct { | ||
9 | PlanProductName string `json:"planProductName,omitempty"` | 9 | PlanProductName string `json:"planProductName,omitempty"` |
10 | // 批号 | 10 | // 批号 |
11 | BatchNumber string `json:"batchNumber,omitempty"` | 11 | BatchNumber string `json:"batchNumber,omitempty"` |
12 | - | ||
13 | // 生产小组ID | 12 | // 生产小组ID |
14 | ProductGroupId int `json:"productGroupId,omitempty"` | 13 | ProductGroupId int `json:"productGroupId,omitempty"` |
14 | + | ||
15 | + // 投入量 | ||
16 | + InputWeight float64 `json:"inputWeight,omitempty"` | ||
17 | + // 产出量 | ||
18 | + OutputWeight float64 `json:"outputWeight,omitempty"` | ||
19 | + // 二级品重量 | ||
20 | + SecondLevelWeight float64 `json:"secondLevelWeight"` | ||
21 | + // 昨天产出量 | ||
22 | + YesterdayOutputWeight float64 `json:"yesterdayOutputWeight"` | ||
23 | + // 历史最好产出量 | ||
24 | + BestOutputWeight float64 `json:"bestOutputWeight"` | ||
25 | + // 合格率 | ||
26 | + QualificationRate int `json:"qualificationRate"` | ||
27 | + | ||
15 | // 其他工段二级品的重量合计 | 28 | // 其他工段二级品的重量合计 |
16 | TotalOtherSecondLevelWeigh float64 `json:"totalOtherSecondLevelWeigh"` | 29 | TotalOtherSecondLevelWeigh float64 `json:"totalOtherSecondLevelWeigh"` |
17 | // 保存其他工段二级品的重量 | 30 | // 保存其他工段二级品的重量 |
@@ -25,3 +38,31 @@ func (info *ProductRecordStaticInfo) OtherSecondLevelWeigh() float64 { | @@ -25,3 +38,31 @@ func (info *ProductRecordStaticInfo) OtherSecondLevelWeigh() float64 { | ||
25 | } | 38 | } |
26 | return result | 39 | return result |
27 | } | 40 | } |
41 | + | ||
42 | +// AddSectionWeight 添加工段的二级品 | ||
43 | +func (info *ProductRecordStaticInfo) AddSectionWeight(section string, weight float64) { | ||
44 | + if _, ok := info.OtherSectionSecondLevelWeigh[section]; ok { | ||
45 | + info.OtherSectionSecondLevelWeigh[section] += weight //存关联级的二级品 | ||
46 | + } else { | ||
47 | + info.OtherSectionSecondLevelWeigh[section] = weight | ||
48 | + } | ||
49 | +} | ||
50 | + | ||
51 | +// 预统计 | ||
52 | +// productWeight 初始产能 | ||
53 | +// secondWeight 二级品重量 | ||
54 | +// yesterdayWeight 昨天产能 | ||
55 | +// bestWeight 最佳产能 | ||
56 | +func (info *ProductRecordStaticInfo) PreStatistics(productWeight float64, secondWeight float64, yesterdayWeight float64, bestWeight float64) { | ||
57 | + totalOtherSecondLevelWeigh := info.OtherSecondLevelWeigh() | ||
58 | + info.InputWeight = productWeight - totalOtherSecondLevelWeigh | ||
59 | + info.OutputWeight = info.InputWeight - secondWeight | ||
60 | + info.SecondLevelWeight = secondWeight | ||
61 | + info.YesterdayOutputWeight = yesterdayWeight | ||
62 | + info.BestOutputWeight = bestWeight | ||
63 | + if bestWeight <= info.InputWeight { | ||
64 | + info.BestOutputWeight = info.OutputWeight | ||
65 | + } | ||
66 | + info.TotalOtherSecondLevelWeigh = totalOtherSecondLevelWeigh | ||
67 | + info.QualificationRate = int(info.OutputWeight / info.InputWeight * 100) | ||
68 | +} |
@@ -58,12 +58,8 @@ func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(weigh flo | @@ -58,12 +58,8 @@ func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(weigh flo | ||
58 | if employeeProductRecord.WorkStation.SectionName == sectionName { | 58 | if employeeProductRecord.WorkStation.SectionName == sectionName { |
59 | employeeProductRecord.SecondLevelWeigh += weigh | 59 | employeeProductRecord.SecondLevelWeigh += weigh |
60 | } else { | 60 | } else { |
61 | - if _, ok := employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName]; ok { | ||
62 | - employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName] += weigh //存关联级的二级品 | ||
63 | - } else { | ||
64 | - employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName] = weigh | ||
65 | - } | ||
66 | - employeeProductRecord.ProductRecordInfo.TotalOtherSecondLevelWeigh = employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh() // 预先统计其他二级品占比 | 61 | + // 其他工段的二级品 |
62 | + employeeProductRecord.ProductRecordInfo.AddSectionWeight(sectionName, weigh) | ||
67 | } | 63 | } |
68 | } | 64 | } |
69 | if productRecordType == RecordTypeReceiveMaterial { | 65 | if productRecordType == RecordTypeReceiveMaterial { |
@@ -72,6 +68,7 @@ func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(weigh flo | @@ -72,6 +68,7 @@ func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(weigh flo | ||
72 | if productRecordType == RecordTypeReturnMaterial { | 68 | if productRecordType == RecordTypeReturnMaterial { |
73 | employeeProductRecord.ProductWeigh -= weigh | 69 | employeeProductRecord.ProductWeigh -= weigh |
74 | } | 70 | } |
71 | + employeeProductRecord.ProductRecordInfo.PreStatistics(employeeProductRecord.ProductWeigh, employeeProductRecord.SecondLevelWeigh, 0, 0) | ||
75 | employeeProductRecord.UpdatedAt = time.Now() | 72 | employeeProductRecord.UpdatedAt = time.Now() |
76 | employeeProductRecord.Version += 1 | 73 | employeeProductRecord.Version += 1 |
77 | } | 74 | } |
@@ -80,3 +80,32 @@ func (dao *AttendanceRecordDao) RecentUnApprovedAttendanceRecord(fromLastHour in | @@ -80,3 +80,32 @@ func (dao *AttendanceRecordDao) RecentUnApprovedAttendanceRecord(fromLastHour in | ||
80 | return int64(count), productAttendanceRecords, nil | 80 | return int64(count), productAttendanceRecords, nil |
81 | } | 81 | } |
82 | } | 82 | } |
83 | + | ||
84 | +func (dao *AttendanceRecordDao) WorkerAttendanceRecords(companyId, orgId, workerId int, workStationId string, beginTime, endTime time.Time) (int64, []*domain.ProductAttendanceRecord, error) { | ||
85 | + tx := dao.transactionContext.PgTx | ||
86 | + //endTime := time.Now() | ||
87 | + //beginTime := endTime.Add(-(time.Hour * time.Duration(recentDay*24))) | ||
88 | + var productAttendanceRecordModels []*models.ProductAttendanceRecord | ||
89 | + productAttendanceRecords := make([]*domain.ProductAttendanceRecord, 0) | ||
90 | + query := sqlbuilder.BuildQuery(tx.Model(&productAttendanceRecordModels), map[string]interface{}{}) | ||
91 | + query.Where("company_id =?", companyId) | ||
92 | + query.Where("org_id =?", orgId) | ||
93 | + query.Where("product_worker ->>'userId' = '?'", workerId) | ||
94 | + query.Where("sign_in <= ?", endTime) | ||
95 | + query.Where("sign_in >= ?", beginTime) | ||
96 | + query.Where("attendance_status = ?", domain.AttendanceNotApprove) | ||
97 | + query.SetOffsetAndLimit(domain.MaxQueryRow) | ||
98 | + query.SetOrderDirect("product_attendance_id", "DESC") | ||
99 | + if count, err := query.SelectAndCount(); err != nil { | ||
100 | + return 0, productAttendanceRecords, err | ||
101 | + } else { | ||
102 | + for _, productAttendanceRecordModel := range productAttendanceRecordModels { | ||
103 | + if productAttendanceRecord, err := transform.TransformToProductAttendanceRecordDomainModelFromPgModels(productAttendanceRecordModel); err != nil { | ||
104 | + return 0, productAttendanceRecords, err | ||
105 | + } else { | ||
106 | + productAttendanceRecords = append(productAttendanceRecords, productAttendanceRecord) | ||
107 | + } | ||
108 | + } | ||
109 | + return int64(count), productAttendanceRecords, nil | ||
110 | + } | ||
111 | +} |
@@ -49,6 +49,30 @@ func (dao *EmployeeProductRecordDao) WorkerProductRecord(companyId, orgId, planI | @@ -49,6 +49,30 @@ func (dao *EmployeeProductRecordDao) WorkerProductRecord(companyId, orgId, planI | ||
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | +// 员工对应批次 最好生产记录 | ||
53 | +func (dao *EmployeeProductRecordDao) WorkerBestOutputRecord(companyId, orgId, planId, workerId int) (*domain.EmployeeProductRecord, error) { | ||
54 | + tx := dao.transactionContext.PgTx | ||
55 | + employeeProductRecordModel := new(models.EmployeeProductRecord) | ||
56 | + query := sqlbuilder.BuildQuery(tx.Model(employeeProductRecordModel), map[string]interface{}{}) | ||
57 | + query.Where("company_id = ?", companyId) | ||
58 | + query.Where("org_id = ?", orgId) | ||
59 | + query.Where("product_worker ->>'userId' = '?'", workerId) | ||
60 | + query.Where("product_record_info ->>'productPlanId' = '?'", planId) | ||
61 | + query.Order("product_record_info ->>'outputWeight' DESC") | ||
62 | + if err := query.First(); err != nil { | ||
63 | + if err.Error() == "pg: no rows in result set" { | ||
64 | + return nil, domain.ErrorNotFound | ||
65 | + } else { | ||
66 | + return nil, err | ||
67 | + } | ||
68 | + } | ||
69 | + if employeeProductRecordModel.EmployeeProductRecordId == 0 { | ||
70 | + return nil, domain.ErrorNotFound | ||
71 | + } else { | ||
72 | + return transform.TransformToEmployeeProductRecordDomainModelFromPgModels(employeeProductRecordModel) | ||
73 | + } | ||
74 | +} | ||
75 | + | ||
52 | func (dao *EmployeeProductRecordDao) SearchEmployeeProductRecord(queryOptions map[string]interface{}) (int64, []*domain.EmployeeProductRecord, error) { | 76 | func (dao *EmployeeProductRecordDao) SearchEmployeeProductRecord(queryOptions map[string]interface{}) (int64, []*domain.EmployeeProductRecord, error) { |
53 | tx := dao.transactionContext.PgTx | 77 | tx := dao.transactionContext.PgTx |
54 | var employeeProductRecordModels []*models.EmployeeProductRecord | 78 | var employeeProductRecordModels []*models.EmployeeProductRecord |
@@ -80,6 +80,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | @@ -80,6 +80,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | ||
80 | if _, ok := groupMembers[groupMembersKeyFunc(r.ProductWorker.UserId)]; !ok { | 80 | if _, ok := groupMembers[groupMembersKeyFunc(r.ProductWorker.UserId)]; !ok { |
81 | participateType = domain.ParticipateSupport | 81 | participateType = domain.ParticipateSupport |
82 | } | 82 | } |
83 | + | ||
83 | var employeeProductRecord *domain.EmployeeProductRecord | 84 | var employeeProductRecord *domain.EmployeeProductRecord |
84 | employeeProductRecord, err = employeeProductRecordDao.WorkerProductRecord(cid, oid, productRecord.ProductRecordInfo.ProductPlanId, r.ProductWorker.UserId, productRecord.CreatedAt) | 85 | employeeProductRecord, err = employeeProductRecordDao.WorkerProductRecord(cid, oid, productRecord.ProductRecordInfo.ProductPlanId, r.ProductWorker.UserId, productRecord.CreatedAt) |
85 | if err == domain.ErrorNotFound { | 86 | if err == domain.ErrorNotFound { |
@@ -90,7 +91,23 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | @@ -90,7 +91,23 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | ||
90 | continue | 91 | continue |
91 | } | 92 | } |
92 | } | 93 | } |
93 | - employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName) | 94 | + |
95 | + // 查询当前员工 昨日产能 、历史最好产能 | ||
96 | + var ( | ||
97 | + yesterdayOutputWeight float64 = 0 | ||
98 | + bestOutputWeight float64 = 0 | ||
99 | + ) | ||
100 | + 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 | ||
102 | + bestOutputWeight = record.ProductRecordInfo.BestOutputWeight | ||
103 | + | ||
104 | + } else { | ||
105 | + if record, e := employeeProductRecordDao.WorkerBestOutputRecord(cid, oid, planId, r.ProductWorker.UserId); e == nil && record != nil { | ||
106 | + yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight | ||
107 | + } | ||
108 | + } | ||
109 | + | ||
110 | + employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight) | ||
94 | 111 | ||
95 | if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil { | 112 | if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil { |
96 | // TODO:异常处理 | 113 | // TODO:异常处理 |
@@ -211,7 +228,23 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. | @@ -211,7 +228,23 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. | ||
211 | if err == domain.ErrorNotFound { | 228 | if err == domain.ErrorNotFound { |
212 | employeeProductRecord = newEmployeeProductRecord(productRecord, participateType, productPlan, productRecord.ProductWorker) | 229 | employeeProductRecord = newEmployeeProductRecord(productRecord, participateType, productPlan, productRecord.ProductWorker) |
213 | } | 230 | } |
214 | - employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName) | 231 | + |
232 | + // 查询当前员工 昨日产能 、历史最好产能 | ||
233 | + var ( | ||
234 | + yesterdayOutputWeight float64 = 0 | ||
235 | + bestOutputWeight float64 = 0 | ||
236 | + ) | ||
237 | + if record, e := employeeProductRecordDao.WorkerProductRecord(cid, oid, planId, productRecord.ProductWorker.UserId, productRecord.CreatedAt.AddDate(0, 0, -1)); e == nil && record != nil { | ||
238 | + yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight | ||
239 | + bestOutputWeight = record.ProductRecordInfo.BestOutputWeight | ||
240 | + | ||
241 | + } else { | ||
242 | + if record, e := employeeProductRecordDao.WorkerBestOutputRecord(cid, oid, planId, productRecord.ProductWorker.UserId); e == nil && record != nil { | ||
243 | + yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight | ||
244 | + } | ||
245 | + } | ||
246 | + | ||
247 | + employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight) | ||
215 | 248 | ||
216 | if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil { | 249 | if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil { |
217 | // TODO:异常处理 | 250 | // TODO:异常处理 |
1 | +package domainService | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | ||
10 | + "time" | ||
11 | +) | ||
12 | + | ||
13 | +type PGWorkerAttendanceReportService struct { | ||
14 | + transactionContext *pgTransaction.TransactionContext | ||
15 | +} | ||
16 | + | ||
17 | +// 考勤汇报 | ||
18 | +func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain.DeviceZkTeco) (interface{}, error) { | ||
19 | + var ( | ||
20 | + attendanceRecordDao, _ = dao.NewAttendanceRecordDao(ptr.transactionContext) | ||
21 | + isSignIn = true | ||
22 | + record *domain.ProductAttendanceRecord | ||
23 | + workStationId string //具体工位 | ||
24 | + workStation *domain.WorkStation | ||
25 | + attendanceType int | ||
26 | + worker *domain.User | ||
27 | + org *domain.Org | ||
28 | + ) | ||
29 | + | ||
30 | + beginTime := utils.GetZeroTime(time.Now()) | ||
31 | + _, records, _ := attendanceRecordDao.WorkerAttendanceRecords(cid, oid, worker.UserId, workStationId, beginTime, time.Now()) | ||
32 | + for i := 0; i < len(records); i++ { | ||
33 | + r := records[i] | ||
34 | + // 操作时间 < 签到时间 签退时间 < 操作时间 | ||
35 | + if (!r.SignIn.IsZero() && r.SignIn.After(report.ActionTime)) || (!r.SignOut.IsZero() && r.SignOut.Before(report.ActionTime)) { | ||
36 | + continue | ||
37 | + } | ||
38 | + | ||
39 | + if !r.SignIn.IsZero() && !r.SignOut.IsZero() { | ||
40 | + if r.SignIn.Before(report.ActionTime) && r.SignOut.After(report.ActionTime) { | ||
41 | + log.Logger.Info(fmt.Sprintf("【考勤汇报】 已存在同一时间段的考勤记录 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime)) | ||
42 | + return struct{}{}, nil | ||
43 | + } | ||
44 | + continue | ||
45 | + } | ||
46 | + if !r.SignIn.IsZero() && r.SignOut.IsZero() && r.SignIn.Before(report.ActionTime) { | ||
47 | + isSignIn = false | ||
48 | + record = r | ||
49 | + break | ||
50 | + } | ||
51 | + } | ||
52 | + | ||
53 | + if isSignIn { | ||
54 | + record = &domain.ProductAttendanceRecord{ | ||
55 | + //ProductAttendanceId: cmd.ProductAttendanceId, | ||
56 | + CompanyId: cid, | ||
57 | + OrgId: oid, | ||
58 | + AttendanceType: attendanceType, | ||
59 | + ProductWorker: worker, | ||
60 | + WorkStation: workStation, | ||
61 | + SignIn: report.ActionTime, | ||
62 | + //SignOut: cmd.SignOut, | ||
63 | + AttendanceStatus: domain.AttendanceNotApprove, | ||
64 | + WorkTimeBefore: 0, | ||
65 | + WorkTimeAfter: 0, | ||
66 | + CreatedAt: time.Now(), | ||
67 | + UpdatedAt: time.Now(), | ||
68 | + Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{ | ||
69 | + //GroupName: productGroup.GroupName, | ||
70 | + //ProductGroupId: productGroup.ProductGroupId, | ||
71 | + }), | ||
72 | + } | ||
73 | + } else { | ||
74 | + record.WorkTimeBefore = record.ComputeWorkTimeBefore() | ||
75 | + } | ||
76 | + | ||
77 | + return struct{}{}, nil | ||
78 | +} | ||
79 | + | ||
80 | +func NewPGWorkerAttendanceReportService(transactionContext *pgTransaction.TransactionContext) (*PGWorkerAttendanceReportService, error) { | ||
81 | + if transactionContext == nil { | ||
82 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
83 | + } else { | ||
84 | + return &PGWorkerAttendanceReportService{ | ||
85 | + transactionContext: transactionContext, | ||
86 | + }, nil | ||
87 | + } | ||
88 | +} |
@@ -6,6 +6,7 @@ import ( | @@ -6,6 +6,7 @@ import ( | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" |
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform" |
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
9 | 10 | ||
10 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | 11 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" |
11 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 12 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
@@ -161,8 +162,8 @@ func (repository *ProductCalendarRepository) Find(queryOptions map[string]interf | @@ -161,8 +162,8 @@ func (repository *ProductCalendarRepository) Find(queryOptions map[string]interf | ||
161 | } | 162 | } |
162 | query.SetWhereByQueryOption("work_station->>'workStationId'=?", "workStationId") | 163 | query.SetWhereByQueryOption("work_station->>'workStationId'=?", "workStationId") |
163 | query.SetWhereByQueryOption("work_on & ? >0", "workOn") | 164 | query.SetWhereByQueryOption("work_on & ? >0", "workOn") |
164 | - if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 { | ||
165 | - query.Where(fmt.Sprintf(`work_station->>'workshopName' like '%%%v%%'`, v)) | 165 | + if v, ok := queryOptions["inWorkshopIds"]; ok && len(v.([]int)) > 0 { |
166 | + query.Where(`work_station->>'workshopId' in (?)`, pg.In(utils.ToArrayString(v.([]int)))) | ||
166 | } | 167 | } |
167 | query.SetOffsetAndLimit(domain.MaxQueryRow) | 168 | query.SetOffsetAndLimit(domain.MaxQueryRow) |
168 | query.SetOrderDirect("product_calendar_id", "DESC") | 169 | query.SetOrderDirect("product_calendar_id", "DESC") |
pkg/port/task/task_worker_attendance.go
0 → 100644
1 | +package task | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "encoding/json" | ||
6 | + "fmt" | ||
7 | + "github.com/hibiken/asynq" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/service" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | ||
11 | +) | ||
12 | + | ||
13 | +// 员工工时汇报 | ||
14 | +func WorkerAttendanceReport(c context.Context, t *asynq.Task) error { | ||
15 | + svr := service.NewAttendanceService(nil) | ||
16 | + cmd := &command.WorkerAttendanceReportCommand{} | ||
17 | + if err := json.Unmarshal(t.Payload(), cmd); err != nil { | ||
18 | + return err | ||
19 | + } | ||
20 | + log.Logger.Debug(fmt.Sprintf("【员工考勤记录汇报】 消费 设备:%v 用户编号:%v 时间:%v ", cmd.Sn, cmd.UserNo, cmd.DeviceZkTeco)) | ||
21 | + _, err := svr.WorkerAttendanceReport(cmd) | ||
22 | + if err != nil { | ||
23 | + log.Logger.Error(err.Error()) | ||
24 | + } | ||
25 | + return nil | ||
26 | +} |
-
请 注册 或 登录 后发表评论