...
|
...
|
@@ -2,9 +2,11 @@ package domainService |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
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/repository"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
|
|
|
"time"
|
...
|
...
|
@@ -17,42 +19,85 @@ type PGWorkerAttendanceReportService struct { |
|
|
// 考勤汇报
|
|
|
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
|
|
|
attendanceRecordDao, _ = dao.NewAttendanceRecordDao(ptr.transactionContext)
|
|
|
attendanceRecordRepository, _ = repository.NewProductAttendanceRecordRepository(ptr.transactionContext)
|
|
|
isSignIn = true
|
|
|
record *domain.ProductAttendanceRecord
|
|
|
workStationId string //具体工位
|
|
|
workStation *domain.WorkStation
|
|
|
attendanceType int = domain.ParticipateNormal
|
|
|
worker *domain.User
|
|
|
org *domain.Org
|
|
|
)
|
|
|
|
|
|
beginTime := utils.GetZeroTime(time.Now())
|
|
|
_, records, _ := attendanceRecordDao.WorkerAttendanceRecords(cid, oid, worker.UserId, workStationId, beginTime, time.Now())
|
|
|
if err := report.Valid(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
var (
|
|
|
device *domain.Device
|
|
|
err error
|
|
|
productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext)
|
|
|
groupId = 0
|
|
|
groupName = ""
|
|
|
)
|
|
|
deviceRepository, _ := dao.NewDeviceDao(ptr.transactionContext)
|
|
|
if device, err = deviceRepository.FindDeviceByDeviceCode(cid, oid, report.Sn); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
workStation = device.WorkStation
|
|
|
|
|
|
var userService = NewUserService()
|
|
|
org, err = userService.Organization(oid)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
worker, err = userService.UserByCode(cid, oid, report.UserNo)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
groupMembers, groupMembersKeyFunc := FindGroupMembers(productGroupRepository, cid, oid, workStation.WorkStationId)
|
|
|
if v, ok := groupMembers[groupMembersKeyFunc(worker.UserId)]; !ok {
|
|
|
attendanceType = domain.ParticipateSupport
|
|
|
} else {
|
|
|
groupId = v.GroupId
|
|
|
groupName = v.GroupName
|
|
|
}
|
|
|
|
|
|
beginTime := utils.GetZeroTime(report.ActionTime)
|
|
|
endTime := report.ActionTime
|
|
|
_, records, _ := attendanceRecordDao.WorkerAttendanceRecords(cid, oid, worker.UserId, workStationId, beginTime, endTime)
|
|
|
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 utils.TimeAfterEqual(r.SignIn, report.ActionTime) {
|
|
|
log.Logger.Info(fmt.Sprintf("【考勤汇报】 考勤记录不合法,操作时间小于签到时间 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime))
|
|
|
return struct{}{}, nil
|
|
|
}
|
|
|
|
|
|
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))
|
|
|
// 存在完整打卡记录
|
|
|
// 1. 如果在区间内,退出
|
|
|
if !utils.TimeIsZero(r.SignIn) && !utils.TimeIsZero(r.SignOut) {
|
|
|
if utils.TimeBeforeEqual(r.SignIn, report.ActionTime) && utils.TimeAfterEqual(r.SignOut, 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
|
|
|
// 存在未结束的打卡记录
|
|
|
// 1.满足条件-签退
|
|
|
if !utils.TimeIsZero(r.SignIn) && utils.TimeIsZero(r.SignOut) {
|
|
|
if utils.TimeBeforeEqual(r.SignIn, report.ActionTime) {
|
|
|
isSignIn = false
|
|
|
record = r
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if isSignIn {
|
|
|
if isSignIn || record == nil {
|
|
|
record = &domain.ProductAttendanceRecord{
|
|
|
//ProductAttendanceId: cmd.ProductAttendanceId,
|
|
|
CompanyId: cid,
|
|
|
OrgId: oid,
|
|
|
AttendanceType: attendanceType,
|
...
|
...
|
@@ -65,13 +110,20 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. |
|
|
WorkTimeAfter: 0,
|
|
|
CreatedAt: time.Now(),
|
|
|
UpdatedAt: time.Now(),
|
|
|
Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{
|
|
|
//GroupName: productGroup.GroupName,
|
|
|
//ProductGroupId: productGroup.ProductGroupId,
|
|
|
Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{
|
|
|
GroupName: groupName,
|
|
|
ProductGroupId: groupId,
|
|
|
}),
|
|
|
}
|
|
|
log.Logger.Info(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签到 %v", worker.UserName, worker.UserId, report))
|
|
|
} else {
|
|
|
record.SignOut = report.ActionTime
|
|
|
record.WorkTimeBefore = record.ComputeWorkTimeBefore()
|
|
|
log.Logger.Info(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签退 %v", worker.UserName, worker.UserId, report))
|
|
|
}
|
|
|
|
|
|
if _, err = attendanceRecordRepository.Save(record); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
return struct{}{}, nil
|
...
|
...
|
|