作者 yangfu

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

@@ -31,6 +31,10 @@ type AttendanceRecordDto struct { @@ -31,6 +31,10 @@ type AttendanceRecordDto struct {
31 SignOut string `json:"signOut"` 31 SignOut string `json:"signOut"`
32 // 考勤状态 1.未审核 2:已审核 3.自动审核 32 // 考勤状态 1.未审核 2:已审核 3.自动审核
33 AttendanceStatus int `json:"attendanceStatus"` 33 AttendanceStatus int `json:"attendanceStatus"`
  34 + // 打卡工时
  35 + WorkTime float64 `json:"workTime"`
  36 + // 休息工时
  37 + BreakTime float64 `json:"breakTime"`
34 // 工时(审核前) 38 // 工时(审核前)
35 WorkTimeBefore float64 `json:"workTimeBefore"` 39 WorkTimeBefore float64 `json:"workTimeBefore"`
36 // 工时(审核后) 40 // 工时(审核后)
@@ -50,7 +54,7 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i @@ -50,7 +54,7 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i
50 d.WorkStation = m.WorkStation 54 d.WorkStation = m.WorkStation
51 if !m.SignIn.IsZero() { 55 if !m.SignIn.IsZero() {
52 d.SignIn = m.SignIn.Local().Format("15:04:05") 56 d.SignIn = m.SignIn.Local().Format("15:04:05")
53 - d.SignDate = m.ProductTime().Format("2006-01-02") 57 + d.SignDate = m.ProductTime().Local().Format("2006-01-02")
54 } 58 }
55 if !m.SignOut.IsZero() { 59 if !m.SignOut.IsZero() {
56 d.SignOut = m.SignOut.Local().Format("15:04:05") 60 d.SignOut = m.SignOut.Local().Format("15:04:05")
@@ -67,6 +71,8 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i @@ -67,6 +71,8 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i
67 t := time.Unix(m.Ext.AttendanceExt.ApproveAt, 0) 71 t := time.Unix(m.Ext.AttendanceExt.ApproveAt, 0)
68 d.ApproveAt = t.Local().Format("2006-01-02 15:04:05") 72 d.ApproveAt = t.Local().Format("2006-01-02 15:04:05")
69 } 73 }
  74 + d.WorkTime = m.WorkTimeBefore + m.Ext.AttendanceExt.BreakTime
  75 + d.BreakTime = m.Ext.AttendanceExt.BreakTime
70 } 76 }
71 return d 77 return d
72 } 78 }
@@ -105,10 +105,10 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain @@ -105,10 +105,10 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain
105 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 105 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
106 } 106 }
107 107
108 - var workTime float64 = 0  
109 - if cmd.WorkTime-cmd.BreakTime > 0 {  
110 - workTime = cmd.WorkTime - cmd.BreakTime  
111 - } 108 + //var workTime float64 = 0
  109 + //if cmd.WorkTime-cmd.BreakTime > 0 {
  110 + // workTime = cmd.WorkTime - cmd.BreakTime
  111 + //}
112 signIn, err := xtime.ParseInLocation(time.Local, fmt.Sprintf("%v %v:00", cmd.ProductDate, cmd.SignIn)) 112 signIn, err := xtime.ParseInLocation(time.Local, fmt.Sprintf("%v %v:00", cmd.ProductDate, cmd.SignIn))
113 if err != nil { 113 if err != nil {
114 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 114 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -121,6 +121,9 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain @@ -121,6 +121,9 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain
121 if err != nil { 121 if err != nil {
122 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 122 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
123 } 123 }
  124 + if !xtime.BeforeEqual(productDate, time.Now()) {
  125 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("日期需要小于等于%v", time.Now().Format("2006-01-02")))
  126 + }
124 newAttendance := &domain.ProductAttendanceRecord{ 127 newAttendance := &domain.ProductAttendanceRecord{
125 //ProductAttendanceId: cmd.ProductAttendanceId, 128 //ProductAttendanceId: cmd.ProductAttendanceId,
126 CompanyId: operateInfo.CompanyId, 129 CompanyId: operateInfo.CompanyId,
@@ -131,20 +134,21 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain @@ -131,20 +134,21 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain
131 SignIn: signIn, 134 SignIn: signIn,
132 SignOut: signOut, 135 SignOut: signOut,
133 AttendanceStatus: cmd.AttendanceStatus, 136 AttendanceStatus: cmd.AttendanceStatus,
134 - WorkTimeBefore: workTime, 137 + WorkTimeBefore: cmd.WorkTime,
135 WorkTimeAfter: 0, 138 WorkTimeAfter: 0,
136 CreatedAt: time.Now(), 139 CreatedAt: time.Now(),
137 UpdatedAt: time.Now(), 140 UpdatedAt: time.Now(),
138 Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{ 141 Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{
139 GroupName: productGroup.GroupName, 142 GroupName: productGroup.GroupName,
140 ProductGroupId: productGroup.ProductGroupId, 143 ProductGroupId: productGroup.ProductGroupId,
  144 + BreakTime: cmd.BreakTime,
141 }), 145 }),
142 ProductDate: productDate, 146 ProductDate: productDate,
143 } 147 }
144 148
145 if cmd.AttendanceStatus == domain.AttendanceApproved { 149 if cmd.AttendanceStatus == domain.AttendanceApproved {
146 newAttendance.WorkTimeAfter = domain.AttendanceApproved 150 newAttendance.WorkTimeAfter = domain.AttendanceApproved
147 - newAttendance.WorkTimeAfter = workTime 151 + newAttendance.WorkTimeAfter = cmd.WorkTime
148 } 152 }
149 var ( 153 var (
150 attendanceRepository domain.ProductAttendanceRecordRepository 154 attendanceRepository domain.ProductAttendanceRecordRepository
@@ -159,7 +163,10 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain @@ -159,7 +163,10 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain
159 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 163 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
160 } 164 }
161 if count > 0 { 165 if count > 0 {
162 - return nil, &application.ServiceError{Code: 10050001, Message: fmt.Sprintf("已存在员工%v的工时记录,是否继续新增", user.UserName)} 166 + return map[string]interface{}{
  167 + "message": fmt.Sprintf("已存在员工%v的工时记录,是否继续新增", user.UserName),
  168 + "needConfirm": true,
  169 + }, nil
163 } 170 }
164 } 171 }
165 if attendance, err := attendanceRepository.Save(newAttendance); err != nil { 172 if attendance, err := attendanceRepository.Save(newAttendance); err != nil {
@@ -132,20 +132,20 @@ func (productAttendanceRecord *ProductAttendanceRecord) ProductTime() time.Time @@ -132,20 +132,20 @@ func (productAttendanceRecord *ProductAttendanceRecord) ProductTime() time.Time
132 } 132 }
133 133
134 func (productAttendanceRecord *ProductAttendanceRecord) GroupName() string { 134 func (productAttendanceRecord *ProductAttendanceRecord) GroupName() string {
135 - if productAttendanceRecord.Ext != nil { 135 + if productAttendanceRecord.Ext == nil {
136 return "" 136 return ""
137 } 137 }
138 - if productAttendanceRecord.Ext.AttendanceExt != nil { 138 + if productAttendanceRecord.Ext.AttendanceExt == nil {
139 return "" 139 return ""
140 } 140 }
141 return productAttendanceRecord.Ext.AttendanceExt.GroupName 141 return productAttendanceRecord.Ext.AttendanceExt.GroupName
142 } 142 }
143 143
144 func (productAttendanceRecord *ProductAttendanceRecord) ApproveUser() *User { 144 func (productAttendanceRecord *ProductAttendanceRecord) ApproveUser() *User {
145 - if productAttendanceRecord.Ext != nil { 145 + if productAttendanceRecord.Ext == nil {
146 return nil 146 return nil
147 } 147 }
148 - if productAttendanceRecord.Ext.AttendanceExt != nil { 148 + if productAttendanceRecord.Ext.AttendanceExt == nil {
149 return nil 149 return nil
150 } 150 }
151 if productAttendanceRecord.Ext.AttendanceExt.ApproveUserId == 0 { 151 if productAttendanceRecord.Ext.AttendanceExt.ApproveUserId == 0 {
@@ -185,5 +185,6 @@ func (productAttendanceRecord *ProductAttendanceRecord) AttendanceBreakTime(prod @@ -185,5 +185,6 @@ func (productAttendanceRecord *ProductAttendanceRecord) AttendanceBreakTime(prod
185 bt += v.BreakTime 185 bt += v.BreakTime
186 } 186 }
187 } 187 }
  188 + productAttendanceRecord.Ext.AttendanceExt.BreakTime = bt
188 return bt 189 return bt
189 } 190 }
@@ -14,4 +14,6 @@ type ProductAttendanceRecordExt struct { @@ -14,4 +14,6 @@ type ProductAttendanceRecordExt struct {
14 ApproveUserName string `json:"approveUserName,omitempty"` 14 ApproveUserName string `json:"approveUserName,omitempty"`
15 // 审核时间 15 // 审核时间
16 ApproveAt int64 `json:"approveAt,omitempty"` 16 ApproveAt int64 `json:"approveAt,omitempty"`
  17 + // 休息时间
  18 + BreakTime float64 `json:"breakTime"`
17 } 19 }
@@ -30,13 +30,14 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { @@ -30,13 +30,14 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
30 } 30 }
31 if workShop, ok := payload["WorkShop"]; ok { 31 if workShop, ok := payload["WorkShop"]; ok {
32 32
33 - if t, ok := payload["UpTime"]; ok {  
34 - collectionTime, _ = time.ParseInLocation("2006-01-02 - 15:04:05", t.(string), time.Local)  
35 - }  
36 - if collectionTime.IsZero() {  
37 - log.Logger.Error(fmt.Sprintf("采集时间有误:%v ", collectionTime), map[string]interface{}{"data": message})  
38 - return  
39 - } 33 + //if t, ok := payload["UpTime"]; ok {
  34 + // collectionTime, _ = time.ParseInLocation("2006-01-02 - 15:04:05", t.(string), time.Local)
  35 + //}
  36 + //if collectionTime.IsZero() {
  37 + // log.Logger.Error(fmt.Sprintf("采集时间有误:%v ", collectionTime), map[string]interface{}{"data": message})
  38 + // return
  39 + //}
  40 + collectionTime = time.Now()
40 var mBytes []byte 41 var mBytes []byte
41 for key, item := range payload { 42 for key, item := range payload {
42 if key == "WorkShop" || key == "UpTime" { 43 if key == "WorkShop" || key == "UpTime" {