pg_worker_attendance_report.go
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package domainService
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
)
type PGWorkerAttendanceReportService struct {
transactionContext *pgTransaction.TransactionContext
}
// 考勤汇报
func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain.DeviceZkTeco) (interface{}, error) {
var (
attendanceRecordDao, _ = dao.NewAttendanceRecordDao(ptr.transactionContext)
isSignIn = true
record *domain.ProductAttendanceRecord
workStationId string //具体工位
workStation *domain.WorkStation
attendanceType int
worker *domain.User
org *domain.Org
)
beginTime := utils.GetZeroTime(time.Now())
_, records, _ := attendanceRecordDao.WorkerAttendanceRecords(cid, oid, worker.UserId, workStationId, beginTime, time.Now())
for i := 0; i < len(records); i++ {
r := records[i]
// 操作时间 < 签到时间 签退时间 < 操作时间
if (!r.SignIn.IsZero() && r.SignIn.After(report.ActionTime)) || (!r.SignOut.IsZero() && r.SignOut.Before(report.ActionTime)) {
continue
}
if !r.SignIn.IsZero() && !r.SignOut.IsZero() {
if r.SignIn.Before(report.ActionTime) && r.SignOut.After(report.ActionTime) {
log.Logger.Info(fmt.Sprintf("【考勤汇报】 已存在同一时间段的考勤记录 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime))
return struct{}{}, nil
}
continue
}
if !r.SignIn.IsZero() && r.SignOut.IsZero() && r.SignIn.Before(report.ActionTime) {
isSignIn = false
record = r
break
}
}
if isSignIn {
record = &domain.ProductAttendanceRecord{
//ProductAttendanceId: cmd.ProductAttendanceId,
CompanyId: cid,
OrgId: oid,
AttendanceType: attendanceType,
ProductWorker: worker,
WorkStation: workStation,
SignIn: report.ActionTime,
//SignOut: cmd.SignOut,
AttendanceStatus: domain.AttendanceNotApprove,
WorkTimeBefore: 0,
WorkTimeAfter: 0,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{
//GroupName: productGroup.GroupName,
//ProductGroupId: productGroup.ProductGroupId,
}),
}
} else {
record.WorkTimeBefore = record.ComputeWorkTimeBefore()
}
return struct{}{}, nil
}
func NewPGWorkerAttendanceReportService(transactionContext *pgTransaction.TransactionContext) (*PGWorkerAttendanceReportService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &PGWorkerAttendanceReportService{
transactionContext: transactionContext,
}, nil
}
}