2023-08-04 11:13:41 +08:00
|
|
|
package worker
|
2023-08-04 18:27:37 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"enterprise/common/dao"
|
2024-04-03 13:53:48 +08:00
|
|
|
"enterprise/common/global"
|
2023-08-04 18:27:37 +08:00
|
|
|
"enterprise/common/model"
|
2025-03-06 17:45:28 +08:00
|
|
|
"enterprise/service"
|
2024-04-03 13:53:48 +08:00
|
|
|
"fmt"
|
2023-08-04 18:27:37 +08:00
|
|
|
log "github.com/sirupsen/logrus"
|
2024-01-07 17:17:33 +08:00
|
|
|
"github.com/smbrave/goutil"
|
2024-04-03 13:53:48 +08:00
|
|
|
"strings"
|
2023-10-23 18:07:03 +08:00
|
|
|
"time"
|
2023-08-04 18:27:37 +08:00
|
|
|
)
|
|
|
|
|
2024-01-07 18:53:21 +08:00
|
|
|
type Checkin struct {
|
2025-01-10 20:00:54 +08:00
|
|
|
corp *model.Corp
|
|
|
|
corpConfig *model.CorpConfig
|
2024-01-07 17:17:33 +08:00
|
|
|
}
|
|
|
|
|
2025-03-04 23:14:09 +08:00
|
|
|
func NewCheckin(corpId int64) *Checkin {
|
|
|
|
corp, _ := dao.NewCorpDao().Get(corpId)
|
2025-01-10 20:00:54 +08:00
|
|
|
return &Checkin{
|
|
|
|
corp: corp,
|
|
|
|
corpConfig: corp.GetConfig(),
|
|
|
|
}
|
|
|
|
}
|
2025-03-06 17:45:28 +08:00
|
|
|
|
|
|
|
func (c *Checkin) SyncCheckinMonth(month string) {
|
2024-01-07 17:17:33 +08:00
|
|
|
if month == "" {
|
|
|
|
month = time.Now().AddDate(0, -1, 0).Format("200601")
|
|
|
|
}
|
2025-03-04 23:14:09 +08:00
|
|
|
|
2024-01-07 17:17:33 +08:00
|
|
|
startTime, _ := time.ParseInLocation("20060102", month+"01", time.Local)
|
|
|
|
endDay := startTime.AddDate(0, 1, -1).Format("2006-01-02")
|
|
|
|
startDay := startTime.Format("2006-01-02")
|
|
|
|
|
2025-03-06 17:45:28 +08:00
|
|
|
new(service.Checkin).SyncCheckin(c.corp.Id, startDay, endDay)
|
2023-08-04 18:27:37 +08:00
|
|
|
|
2024-01-07 17:17:33 +08:00
|
|
|
}
|
2024-04-03 13:53:48 +08:00
|
|
|
|
2025-03-06 17:45:28 +08:00
|
|
|
func (c *Checkin) SyncCheckinDay(day string) {
|
2024-01-07 17:17:33 +08:00
|
|
|
if day == "" {
|
|
|
|
day = time.Now().AddDate(0, 0, -1).Format("2006-01-02")
|
|
|
|
}
|
2025-03-06 17:45:28 +08:00
|
|
|
new(service.Checkin).SyncCheckin(c.corp.Id, day, day)
|
2024-01-07 17:17:33 +08:00
|
|
|
|
|
|
|
}
|
2024-04-03 13:53:48 +08:00
|
|
|
|
2025-03-06 17:45:28 +08:00
|
|
|
func (c *Checkin) MonitorCheckinDay(day string) {
|
2024-04-03 13:53:48 +08:00
|
|
|
if day == "" {
|
|
|
|
day = time.Now().AddDate(0, 0, -1).Format("2006-01-02")
|
|
|
|
}
|
2025-03-06 17:45:28 +08:00
|
|
|
checkins, err := dao.NewCheckinDao().QueryDay(c.corp.Id, day)
|
2024-04-03 13:53:48 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("db error :%s", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, checkin := range checkins {
|
|
|
|
if checkin.Exception == "" {
|
|
|
|
continue
|
|
|
|
}
|
2025-03-06 17:45:28 +08:00
|
|
|
approvals, err := dao.NewApprovalVacationDao().GetByUsername(c.corp.Id, checkin.Username, "", checkin.Day)
|
2024-04-25 12:23:19 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("db error :%s", err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if len(approvals) > 0 {
|
|
|
|
continue
|
|
|
|
}
|
2024-04-03 13:53:48 +08:00
|
|
|
message := make([]string, 0)
|
|
|
|
message = append(message, fmt.Sprintf("【考勤异常】%s", checkin.Username))
|
|
|
|
message = append(message, fmt.Sprintf("考勤日期:%s", checkin.Day))
|
2024-04-12 11:35:47 +08:00
|
|
|
message = append(message, fmt.Sprintf("上班时间:%s", goutil.TimeToDateTime(checkin.StartTime)))
|
|
|
|
message = append(message, fmt.Sprintf("下班时间:%s", goutil.TimeToDateTime(checkin.EndTime)))
|
|
|
|
message = append(message, fmt.Sprintf("异常原因:%s", checkin.Exception))
|
2024-04-25 12:23:19 +08:00
|
|
|
global.SendMessage([]string{"jiangyong", checkin.Username}, strings.Join(message, "\n"))
|
2024-04-03 13:53:48 +08:00
|
|
|
}
|
|
|
|
}
|