attendance_record_dto.go 2.5 KB
package dto

import (
	"time"

	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
)

type AttendanceRecordDto struct {
	// 考勤记录ID
	ProductAttendanceId int `json:"productAttendanceId"`
	// 企业id
	//CompanyId int `json:"companyId,omitempty"`
	// 组织ID
	//OrgId int `json:"orgId,omitempty"`
	// 考勤类型 1.正常 2.支援
	AttendanceType int `json:"attendanceType,omitempty"`
	// 班组名称
	GroupName string `json:"groupName"`
	// 生产工人
	ProductWorker *domain.User `json:"productWorker,omitempty"`
	// 审核人
	ApproveUser *domain.User `json:"approveUser"`
	//*domain.ProductAttendanceRecordExt
	ApproveAt string `json:"approveAt"`
	// 工作位置
	*domain.WorkStation
	// 签到
	SignIn string `json:"signIn"`
	// 签退
	SignOut string `json:"signOut"`
	// 考勤状态 1.未审核 2:已审核 3.自动审核
	AttendanceStatus int `json:"attendanceStatus"`
	// 打卡工时
	WorkTime float64 `json:"workTime"`
	// 休息工时
	BreakTime float64 `json:"breakTime"`
	// 工时(审核前)
	WorkTimeBefore float64 `json:"workTimeBefore"`
	// 工时(审核后)
	WorkTimeAfter float64 `json:"workTimeAfter"`
	// 签到日期
	SignDate string `json:"signDate"`
	// 组织名称
	OrgName string `json:"orgName"`
	// 权限标识 (当前登录组织匹配为true,否则false)
	AuthFlag bool `json:"authFlag"`
}

func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId int) *AttendanceRecordDto {
	d.ProductAttendanceId = m.ProductAttendanceId
	d.AttendanceType = m.AttendanceType
	d.ProductWorker = m.ProductWorker
	d.WorkStation = m.WorkStation
	if !m.SignIn.IsZero() {
		d.SignIn = m.SignIn.Local().Format("15:04:05")
		d.SignDate = m.ProductTime().Local().Format("2006-01-02")
	}
	if !m.SignOut.IsZero() {
		d.SignOut = m.SignOut.Local().Format("15:04:05")
	}
	d.WorkTimeBefore = utils.Round(m.WorkTimeBefore, 1)
	d.WorkTimeAfter = m.WorkTimeAfter
	d.AttendanceStatus = m.AttendanceStatus
	d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
	if m.Ext != nil {
		d.OrgName = m.Ext.OrgName
	}
	d.ApproveUser = m.ApproveUser()
	d.GroupName = m.GroupName()
	if m.Ext != nil && m.Ext.AttendanceExt != nil {
		if m.Ext.AttendanceExt.ApproveAt > 0 {
			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
}