作者 yangfu

fix: 打卡工时修改,设备采集时间使用服务器当前时间

... ... @@ -31,6 +31,10 @@ type AttendanceRecordDto struct {
SignOut string `json:"signOut"`
// 考勤状态 1.未审核 2:已审核 3.自动审核
AttendanceStatus int `json:"attendanceStatus"`
// 打卡工时
WorkTime float64 `json:"workTime"`
// 休息工时
BreakTime float64 `json:"breakTime"`
// 工时(审核前)
WorkTimeBefore float64 `json:"workTimeBefore"`
// 工时(审核后)
... ... @@ -50,7 +54,7 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i
d.WorkStation = m.WorkStation
if !m.SignIn.IsZero() {
d.SignIn = m.SignIn.Local().Format("15:04:05")
d.SignDate = m.ProductTime().Format("2006-01-02")
d.SignDate = m.ProductTime().Local().Format("2006-01-02")
}
if !m.SignOut.IsZero() {
d.SignOut = m.SignOut.Local().Format("15:04:05")
... ... @@ -67,6 +71,8 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i
t := time.Unix(m.Ext.AttendanceExt.ApproveAt, 0)
d.ApproveAt = t.Local().Format("2006-01-02 15:04:05")
}
d.WorkTime = m.WorkTimeBefore + m.Ext.AttendanceExt.BreakTime
d.BreakTime = m.Ext.AttendanceExt.BreakTime
}
return d
}
... ...
... ... @@ -105,10 +105,10 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var workTime float64 = 0
if cmd.WorkTime-cmd.BreakTime > 0 {
workTime = cmd.WorkTime - cmd.BreakTime
}
//var workTime float64 = 0
//if cmd.WorkTime-cmd.BreakTime > 0 {
// workTime = cmd.WorkTime - cmd.BreakTime
//}
signIn, err := xtime.ParseInLocation(time.Local, fmt.Sprintf("%v %v:00", cmd.ProductDate, cmd.SignIn))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -121,6 +121,9 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if !xtime.BeforeEqual(productDate, time.Now()) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("日期需要小于等于%v", time.Now().Format("2006-01-02")))
}
newAttendance := &domain.ProductAttendanceRecord{
//ProductAttendanceId: cmd.ProductAttendanceId,
CompanyId: operateInfo.CompanyId,
... ... @@ -131,20 +134,21 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain
SignIn: signIn,
SignOut: signOut,
AttendanceStatus: cmd.AttendanceStatus,
WorkTimeBefore: workTime,
WorkTimeBefore: cmd.WorkTime,
WorkTimeAfter: 0,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{
GroupName: productGroup.GroupName,
ProductGroupId: productGroup.ProductGroupId,
BreakTime: cmd.BreakTime,
}),
ProductDate: productDate,
}
if cmd.AttendanceStatus == domain.AttendanceApproved {
newAttendance.WorkTimeAfter = domain.AttendanceApproved
newAttendance.WorkTimeAfter = workTime
newAttendance.WorkTimeAfter = cmd.WorkTime
}
var (
attendanceRepository domain.ProductAttendanceRecordRepository
... ... @@ -159,7 +163,10 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if count > 0 {
return nil, &application.ServiceError{Code: 10050001, Message: fmt.Sprintf("已存在员工%v的工时记录,是否继续新增", user.UserName)}
return map[string]interface{}{
"message": fmt.Sprintf("已存在员工%v的工时记录,是否继续新增", user.UserName),
"needConfirm": true,
}, nil
}
}
if attendance, err := attendanceRepository.Save(newAttendance); err != nil {
... ...
... ... @@ -132,20 +132,20 @@ func (productAttendanceRecord *ProductAttendanceRecord) ProductTime() time.Time
}
func (productAttendanceRecord *ProductAttendanceRecord) GroupName() string {
if productAttendanceRecord.Ext != nil {
if productAttendanceRecord.Ext == nil {
return ""
}
if productAttendanceRecord.Ext.AttendanceExt != nil {
if productAttendanceRecord.Ext.AttendanceExt == nil {
return ""
}
return productAttendanceRecord.Ext.AttendanceExt.GroupName
}
func (productAttendanceRecord *ProductAttendanceRecord) ApproveUser() *User {
if productAttendanceRecord.Ext != nil {
if productAttendanceRecord.Ext == nil {
return nil
}
if productAttendanceRecord.Ext.AttendanceExt != nil {
if productAttendanceRecord.Ext.AttendanceExt == nil {
return nil
}
if productAttendanceRecord.Ext.AttendanceExt.ApproveUserId == 0 {
... ... @@ -185,5 +185,6 @@ func (productAttendanceRecord *ProductAttendanceRecord) AttendanceBreakTime(prod
bt += v.BreakTime
}
}
productAttendanceRecord.Ext.AttendanceExt.BreakTime = bt
return bt
}
... ...
... ... @@ -14,4 +14,6 @@ type ProductAttendanceRecordExt struct {
ApproveUserName string `json:"approveUserName,omitempty"`
// 审核时间
ApproveAt int64 `json:"approveAt,omitempty"`
// 休息时间
BreakTime float64 `json:"breakTime"`
}
... ...
... ... @@ -30,13 +30,14 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
}
if workShop, ok := payload["WorkShop"]; ok {
if t, ok := payload["UpTime"]; ok {
collectionTime, _ = time.ParseInLocation("2006-01-02 - 15:04:05", t.(string), time.Local)
}
if collectionTime.IsZero() {
log.Logger.Error(fmt.Sprintf("采集时间有误:%v ", collectionTime), map[string]interface{}{"data": message})
return
}
//if t, ok := payload["UpTime"]; ok {
// collectionTime, _ = time.ParseInLocation("2006-01-02 - 15:04:05", t.(string), time.Local)
//}
//if collectionTime.IsZero() {
// log.Logger.Error(fmt.Sprintf("采集时间有误:%v ", collectionTime), map[string]interface{}{"data": message})
// return
//}
collectionTime = time.Now()
var mBytes []byte
for key, item := range payload {
if key == "WorkShop" || key == "UpTime" {
... ...