This commit is contained in:
jiangyong27 2025-03-06 17:45:28 +08:00
parent f2745bf156
commit 391b861a87
18 changed files with 581 additions and 108 deletions

View File

@ -7,9 +7,14 @@ var (
// 系统错误码 // 系统错误码
ErrOK = errors.T(0, "操作成功") ErrOK = errors.T(0, "操作成功")
ErrPriv = errors.T(196, "没有权限") ErrPriv = errors.T(196, "没有权限")
ErrDb = errors.T(197, "数据库错误") ErrDb = errors.T(197, "数据库错误")
ErrRemote = errors.T(198, "第三方错误") ErrRemote = errors.T(198, "第三方错误")
ErrInternal = errors.T(199, "内部错误") ErrInternal = errors.T(199, "内部错误")
ErrParam = errors.T(400, "参数错误") ErrParam = errors.T(400, "参数错误")
ErrNoData = errors.T(401, "没有数据")
ErrTokenExpire = errors.T(402, "登录过期") //客户端有特殊逻辑勿动,跳转登录页
ErrTokenInvaild = errors.T(403, "TOKEN无效") //客户端有特殊逻辑勿动,跳转登录页
ErrNoToken = errors.T(404, "没有TOKEN") //客户端有特殊逻辑勿动,跳转登录页
ErrNoPerm = errors.T(405, "没有权限")
) )

View File

@ -110,3 +110,27 @@ func (d *CheckinDao) QueryDay(corpId int64, day string) ([]*model.Checkin, error
} }
return u, nil return u, nil
} }
func (d *CheckinDao) QueryAdmin(page, size int, corpId int64, username, startDay, endDay string) ([]*model.Checkin, int64, error) {
tx := GetDB().Table(d.TableName())
tx = tx.Where("corp_id = ?", corpId)
if startDay != "" {
tx = tx.Where("day >= ?", startDay)
}
if endDay != "" {
tx = tx.Where("day <= ?", endDay)
}
if username != "" {
tx = tx.Where("username = ?", username)
}
var count int64
tx.Count(&count)
tx.Offset((page - 1) * size).Limit(size)
var u []*model.Checkin
tx = tx.Find(&u)
if tx.Error != nil {
return nil, 0, tx.Error
}
return u, count, nil
}

81
common/dao/staff_token.go Normal file
View File

@ -0,0 +1,81 @@
package dao
import (
"enterprise/common/model"
"github.com/smbrave/goutil"
"gorm.io/gorm"
"time"
)
type StaffTokenDao struct {
}
func NewStaffTokenDao() *StaffTokenDao {
return &StaffTokenDao{}
}
func (d *StaffTokenDao) TableName() string {
return "staff_token"
}
func (d *StaffTokenDao) Create(o *model.StaffToken) (int64, error) {
o.CreateTime = time.Now().Unix()
res := GetDB().Table(d.TableName()).Create(o)
return o.Id, res.Error
}
func (d *StaffTokenDao) Update(o *model.StaffToken, fields ...string) error {
tx := GetDB().Table(d.TableName())
tx.Where("id = ?", o.Id)
if len(fields) == 0 {
res := tx.Save(o)
return res.Error
}
dat := goutil.ModelFieldValue(o, fields...)
return tx.Updates(dat).Error
}
func (d *StaffTokenDao) Delete(id int64) error {
res := GetDB().Table(d.TableName()).Delete(&model.StaffToken{}, id)
return res.Error
}
func (d *StaffTokenDao) Get(id int64) (*model.StaffToken, error) {
var u model.StaffToken
tx := GetDB().Table(d.TableName())
tx = tx.Where("id = ?", id)
res := tx.First(&u)
if res.Error == gorm.ErrRecordNotFound {
return nil, nil
}
if res.Error != nil {
return nil, res.Error
}
return &u, nil
}
func (d *StaffTokenDao) GetByToken(token string) (*model.StaffToken, error) {
var o model.StaffToken
tx := GetDB().Table(d.TableName())
tx = tx.Where("token = ?", token)
res := tx.First(&o)
if res.Error == gorm.ErrRecordNotFound {
return nil, nil
}
if res.Error != nil {
return nil, res.Error
}
return &o, nil
}
func (d *StaffTokenDao) DeleteHistory(lastDay int) (int64, error) {
tx := GetDB().Table(d.TableName())
deleteTime := time.Now().AddDate(0, 0, 0-lastDay).Unix()
tx.Where("expire_time <= ?", deleteTime)
tx.Delete(&model.StaffToken{})
return tx.RowsAffected, tx.Error
}

View File

@ -12,7 +12,7 @@ type StaffSalary struct {
Id int64 Id int64
CorpId int64 CorpId int64
UserId int64 UserId int64
UserName string Username string
Month string Month string
Salary float64 Salary float64
AttendSalary float64 AttendSalary float64

View File

@ -0,0 +1,9 @@
package model
type StaffToken struct {
Id int64
UserId int64
Token string
CreateTime int64
ExpireTime int64
}

111
common/session/base.go Normal file
View File

@ -0,0 +1,111 @@
package session
import (
"encoding/json"
"enterprise/common/config"
"github.com/smbrave/goutil"
"reflect"
)
type BaseResponse struct {
Code int `json:"code"`
Message string `json:"message"`
}
type CommonResponse struct {
BaseResponse
Data interface{} `json:"data"`
}
type RawResponse struct {
BaseResponse
Data json.RawMessage `json:"data"`
}
type ListResponse struct {
BaseResponse
Data struct {
Total int64 `json:"total"`
TotalAmount string `json:"total_amount,omitempty"`
TotalSize string `json:"total_size,omitempty"`
Items interface{} `json:"items"`
} `json:"data,omitempty"`
}
var (
rspOk *BaseResponse
)
func init() {
rspOk = new(BaseResponse)
rspOk.Message = "OK"
rspOk.Code = 0
}
func NewRspOk() *BaseResponse {
return rspOk
}
func NewRawRsp(raw []byte) *RawResponse {
rsp := &RawResponse{
BaseResponse: BaseResponse{
Code: rspOk.Code,
Message: rspOk.Message,
},
}
rsp.Data = raw
return rsp
}
func NewListRsp(total int64, items interface{}) *ListResponse {
rsp := &ListResponse{
BaseResponse: BaseResponse{
Code: rspOk.Code,
Message: rspOk.Message,
},
}
rsp.Data.Total = total
rsp.Data.Items = items
return rsp
}
func NewListSizeRsp(total int64, totalSize int64, items interface{}) *ListResponse {
rsp := &ListResponse{
BaseResponse: BaseResponse{
Code: rspOk.Code,
Message: rspOk.Message,
},
}
rsp.Data.Total = total
rsp.Data.TotalSize = goutil.FormatBytes(totalSize)
rsp.Data.Items = items
return rsp
}
func NewRsp(data interface{}) *CommonResponse {
return &CommonResponse{
BaseResponse: BaseResponse{
Code: rspOk.Code,
Message: rspOk.Message,
},
Data: data,
}
}
func CheckDBError(err error) {
if err != nil {
panic(config.ErrDb.New().Append(err))
}
}
func CheckParamError(err error) {
if err != nil {
panic(config.ErrParam.New().Append(err))
}
}
func CheckNilError(data interface{}, args ...string) {
val := reflect.ValueOf(data)
if val.IsNil() {
panic(config.ErrNoData.New().Append(args))
}
}

50
common/session/session.go Normal file
View File

@ -0,0 +1,50 @@
package session
import (
"enterprise/common/model"
)
var (
ContextSession = "session"
ContextRequest = "request"
ContextResponse = "response"
ContextHeader = "header"
ContextWriteEvent = "write_event"
ContextRefreshToken = "refresh_token"
)
type AdminHeader struct {
Token string `header:"x-token" json:"-"`
RemoteIp string `header:"x-remote-ip" json:"public_ip"`
}
type AdminSession struct {
adminHeader *AdminHeader
adminUser *model.StaffUser
}
func NewAdminSession(header *AdminHeader, user *model.StaffUser) *AdminSession {
return &AdminSession{
adminHeader: header,
adminUser: user,
}
}
func (s *AdminSession) GetHeader() *AdminHeader {
return s.adminHeader
}
func (s *AdminSession) GetAdmin() *model.StaffUser {
return s.adminUser
}
func (s *AdminSession) GetCorpId() int64 {
return s.adminUser.CorpId
}
func (s *AdminSession) GetUsername() string {
if s.adminUser != nil {
return s.adminUser.Username
}
return ""
}

57
server/api/checkin.go Normal file
View File

@ -0,0 +1,57 @@
package api
import (
"enterprise/common/model"
"github.com/smbrave/goutil"
"github.com/spf13/cast"
)
type BaseRequest struct {
Page int `form:"page"`
Size int `form:"size"`
}
func (b *BaseRequest) Default() {
if b.Page <= 0 {
b.Page = 1
}
if b.Size <= 0 {
b.Size = 10
}
}
type ListCheckin struct {
BaseRequest
Username string `form:"username"`
StartDay string `form:"start_day"`
EndDay string `form:"end_day"`
}
type SyncCheckin struct {
StartDay string `form:"start_day"`
EndDay string `form:"end_day"`
}
type Checkin struct {
Id string
Username string
Day string
Month string
Exception string
Rawdata string
StartTime string
EndTime string
CreateTime string
}
func (c *Checkin) From(m *model.Checkin) {
c.Id = cast.ToString(m.Id)
c.Username = m.Username
c.Day = m.Day
c.Month = m.Month
c.StartTime = goutil.TimeToDateTime(m.StartTime)
c.StartTime = goutil.TimeToDateTime(m.EndTime)
c.CreateTime = goutil.TimeToDateTime(m.CreateTime)
c.Exception = m.Exception
c.Rawdata = m.Rawdata
}

View File

@ -2,6 +2,9 @@ package controller
import ( import (
"enterprise/common/config" "enterprise/common/config"
"enterprise/common/dao"
"enterprise/common/model"
"enterprise/common/session"
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gogap/errors" "github.com/gogap/errors"
@ -21,6 +24,54 @@ type Response struct {
type Base struct { type Base struct {
} }
// 所有请求都必须走的逻辑用于创建session
func (c *Base) Before(ctx *gin.Context) {
if ctx.Keys == nil {
ctx.Keys = make(map[string]interface{})
}
// 获取头部参数
var header session.AdminHeader
if err := ctx.BindHeader(&header); err != nil {
panic(config.ErrParam.New().Append(err))
}
if header.Token == "" { // 新用户没有extra所以extra中的配置不能对新用户生效
return
}
var tk *model.StaffToken = nil
tk, err := dao.NewStaffTokenDao().GetByToken(header.Token)
if err != nil {
panic(config.ErrDb.New().Append(err))
}
if tk == nil {
panic(config.ErrTokenInvaild.New())
}
if time.Now().Unix() > tk.ExpireTime {
panic(config.ErrTokenExpire.New())
}
staffUser, err := dao.NewStaffUserDao().Get(tk.UserId)
if err != nil {
panic(config.ErrDb.New().Append(err))
}
if staffUser == nil {
panic(config.ErrTokenInvaild.New())
}
ctx.Keys[session.ContextSession] = session.NewAdminSession(&header, staffUser)
}
func (c *Base) Token(ctx *gin.Context) {
// 只有需要传token的接口需要强制校验token
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
if sess.GetHeader().Token == "" {
panic(config.ErrNoToken.New())
}
}
func (c *Base) Recovery(ctx *gin.Context) { func (c *Base) Recovery(ctx *gin.Context) {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {

View File

@ -0,0 +1,41 @@
package controller
import (
"enterprise/common/config"
"enterprise/common/dao"
"enterprise/common/session"
"enterprise/server/api"
"enterprise/server/service"
"github.com/gin-gonic/gin"
"github.com/spf13/cast"
"net/http"
)
type StaffCheckin struct {
}
func (s *StaffCheckin) List(ctx *gin.Context) {
var req api.ListCheckin
if err := ctx.ShouldBind(&req); err != nil {
panic(config.ErrParam.New().Append(err))
}
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
total, items := new(service.Checkin).List(sess, &req)
ctx.JSON(http.StatusOK, session.NewListRsp(total, items))
}
func (s *StaffCheckin) Sync(ctx *gin.Context) {
var req api.SyncCheckin
if err := ctx.ShouldBind(&req); err != nil {
panic(config.ErrParam.New().Append(err))
}
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
new(service.Checkin).Sync(sess, &req)
ctx.JSON(http.StatusOK, session.NewRspOk())
}
func (s *StaffCheckin) Delete(ctx *gin.Context) {
id := cast.ToInt64(ctx.Query("id"))
dao.NewCheckinDao().Delete(id)
ctx.JSON(http.StatusOK, session.NewRspOk())
}

View File

@ -0,0 +1 @@
package controller

View File

@ -10,18 +10,28 @@ func initRoutge(engine *gin.Engine) {
qyweixin := new(controller.QyWeixin) qyweixin := new(controller.QyWeixin)
staff := new(controller.Staff) staff := new(controller.Staff)
base := new(controller.Base) base := new(controller.Base)
checkin := new(controller.StaffCheckin)
apiGroup := engine.Group("/api") apiGroup := engine.Group("/api")
noTokenGroup := engine.Group("/api")
apiGroup.Use(base.Before).Use(base.Token)
group := engine.Group("/") group := engine.Group("/")
apiGroup.Use(base.Recovery) apiGroup.Use(base.Recovery)
group.Use(base.Recovery) group.Use(base.Recovery)
apiGroup.Any("/qyweixin/approve/:cid", qyweixin.Approve)
apiGroup.Any("/qyweixin/pay/:cid", qyweixin.Pay) noTokenGroup.Any("/qyweixin/approve/:cid", qyweixin.Approve)
apiGroup.Any("/qyweixin/handle/refund", qyweixin.HandleRefund) noTokenGroup.Any("/qyweixin/pay/:cid", qyweixin.Pay)
noTokenGroup.Any("/qyweixin/handle/refund", qyweixin.HandleRefund)
group.GET("/staff/salary", staff.Salary) group.GET("/staff/salary", staff.Salary)
group.GET("/staff/sync/salary", staff.SyncStaffSalary) group.GET("/staff/sync/salary", staff.SyncStaffSalary)
apiGroup.GET("/checkin", checkin.List)
apiGroup.DELETE("/checkin", checkin.Delete)
apiGroup.Any("/checkin/sync", checkin.Sync)
engine.LoadHTMLGlob("conf/template/*") engine.LoadHTMLGlob("conf/template/*")
} }
func Start() error { func Start() error {

34
server/service/checkin.go Normal file
View File

@ -0,0 +1,34 @@
package service
import (
"enterprise/common/config"
"enterprise/common/dao"
"enterprise/common/session"
"enterprise/server/api"
CS "enterprise/service"
)
type Checkin struct {
}
func (c *Checkin) List(sess *session.AdminSession, req *api.ListCheckin) (int64, interface{}) {
checkts, total, err := dao.NewCheckinDao().QueryAdmin(req.Page, req.Size, sess.GetCorpId(), req.Username, req.StartDay, req.EndDay)
if err != nil {
panic(config.ErrDb.New().Append(err))
}
items := make([]*api.Checkin, 0)
for _, checkin := range checkts {
ch := new(api.Checkin)
ch.From(checkin)
items = append(items, ch)
}
return total, items
}
func (c *Checkin) Sync(sess *session.AdminSession, req *api.SyncCheckin) {
err := new(CS.Checkin).SyncCheckin(sess.GetCorpId(), req.StartDay, req.EndDay)
if err != nil {
panic(config.ErrInternal.New().Append(err))
}
}

79
service/checkin.go Normal file
View File

@ -0,0 +1,79 @@
package service
import (
"enterprise/common/dao"
"enterprise/common/model"
"git.u8t.cn/open/gosdk/qyweixin"
log "github.com/sirupsen/logrus"
"github.com/smbrave/goutil"
)
type Checkin struct {
}
func (c *Checkin) SyncCheckin(corpId int64, startDay, endDay string) error {
corp, err := dao.NewCorpDao().Get(corpId)
if err != nil {
log.Errorf("db error :%s", err.Error())
return err
}
cfg := corp.GetConfig()
qyw := qyweixin.NewAppCheckin(&qyweixin.AppConfig{
Corpid: cfg.CorpId,
Secret: cfg.EnterpriseSecret,
Agent: cfg.EnterpriseAgent,
})
users, err := qyw.GetCheckinEmployee(nil)
if err != nil {
log.Errorf("GetCheckinEmployee error :%s", err.Error())
return err
}
userDatas, err := qyw.GetCheckinData(startDay, endDay, users)
if err != nil {
log.Errorf("GetCheckinData[%s-%s]%s error :%s", startDay, endDay, goutil.EncodeJSON(users), err.Error())
return err
}
for _, user := range userDatas {
c.saveToDB(corpId, user)
}
return nil
}
func (c *Checkin) saveToDB(corpId int64, user *qyweixin.UserCheckIn) error {
checkin, err := dao.NewCheckinDao().GetByDay(user.UserId, user.Day)
if err != nil {
log.Errorf("db error :%s", err.Error())
return err
}
isNew := false
if checkin == nil {
checkin = new(model.Checkin)
checkin.Day = user.Day
checkin.Month = user.Month
checkin.Username = user.UserId
isNew = true
}
checkin.Exception = user.Exception
checkin.StartTime = user.StartTime
checkin.EndTime = user.EndTime
checkin.Month = user.Month
checkin.Rawdata = user.Rawdata
checkin.CorpId = corpId
if isNew {
_, err = dao.NewCheckinDao().Create(checkin)
} else {
err = dao.NewCheckinDao().Update(checkin)
}
if err != nil {
log.Errorf("create/update db error :%s", err.Error())
return err
}
return nil
}

View File

@ -32,15 +32,15 @@ func (s *SalaryCalculator1002) Calculate(salary *model.StaffSalary) {
if salary.Month == "202502" { if salary.Month == "202502" {
salary.ShouldDay = 21 salary.ShouldDay = 21
if salary.UserName == "luoyi" { if salary.Username == "luoyi" {
salary.AttendDay = float64(salary.ShouldDay - 5) salary.AttendDay = float64(salary.ShouldDay - 5)
} else if strings.ToLower(salary.UserName) == "wangyan" { } else if strings.ToLower(salary.Username) == "wangyan" {
salary.AttendDay = float64(salary.ShouldDay) - 5.6 salary.AttendDay = float64(salary.ShouldDay) - 5.6
} else if strings.ToLower(salary.UserName) == "zhouhong" { } else if strings.ToLower(salary.Username) == "zhouhong" {
salary.AttendDay = float64(salary.ShouldDay) - 5.6 salary.AttendDay = float64(salary.ShouldDay) - 5.6
} else if strings.ToLower(salary.UserName) == "chenmin" { } else if strings.ToLower(salary.Username) == "chenmin" {
salary.AttendDay = 19 salary.AttendDay = 19
} else if strings.ToLower(salary.UserName) == "xushiyu" { } else if strings.ToLower(salary.Username) == "xushiyu" {
salary.AttendDay = 7 salary.AttendDay = 7
} }
} }

View File

@ -39,7 +39,7 @@ func (s *StaffSalary) CalcSalary(salary *model.StaffSalary, month string) (*mode
salary.Month = month salary.Month = month
salary.CorpId = s.user.CorpId salary.CorpId = s.user.CorpId
salary.UserId = s.user.Id salary.UserId = s.user.Id
salary.UserName = s.user.Username salary.Username = s.user.Username
} }
entryTime, _ := time.ParseInLocation("2006-01-02", s.user.EntryDate, time.Local) entryTime, _ := time.ParseInLocation("2006-01-02", s.user.EntryDate, time.Local)

View File

@ -4,8 +4,8 @@ import (
"enterprise/common/dao" "enterprise/common/dao"
"enterprise/common/global" "enterprise/common/global"
"enterprise/common/model" "enterprise/common/model"
"enterprise/service"
"fmt" "fmt"
"git.u8t.cn/open/gosdk/qyweixin"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/smbrave/goutil" "github.com/smbrave/goutil"
"strings" "strings"
@ -24,78 +24,33 @@ func NewCheckin(corpId int64) *Checkin {
corpConfig: corp.GetConfig(), corpConfig: corp.GetConfig(),
} }
} }
func (c *Checkin) SyncCheckinMonth(month string) error {
func (c *Checkin) SyncCheckinMonth(month string) {
if month == "" { if month == "" {
month = time.Now().AddDate(0, -1, 0).Format("200601") month = time.Now().AddDate(0, -1, 0).Format("200601")
} }
cfg := c.corp.GetConfig()
startTime, _ := time.ParseInLocation("20060102", month+"01", time.Local) startTime, _ := time.ParseInLocation("20060102", month+"01", time.Local)
endDay := startTime.AddDate(0, 1, -1).Format("2006-01-02") endDay := startTime.AddDate(0, 1, -1).Format("2006-01-02")
startDay := startTime.Format("2006-01-02") startDay := startTime.Format("2006-01-02")
qyw := qyweixin.NewAppCheckin(&qyweixin.AppConfig{ new(service.Checkin).SyncCheckin(c.corp.Id, startDay, endDay)
Corpid: cfg.CorpId,
Secret: cfg.EnterpriseSecret,
Agent: cfg.EnterpriseAgent,
})
users, err := qyw.GetCheckinEmployee(nil)
if err != nil {
log.Errorf("GetCheckinEmployee error :%s", err.Error())
return err
}
userDatas, err := qyw.GetCheckinData(startDay, endDay, users)
if err != nil {
log.Errorf("GetCheckinData[%s-%s]%s error :%s", startDay, endDay, goutil.EncodeJSON(users), err.Error())
return err
}
for _, user := range userDatas {
c.saveToDB(user)
}
return nil
} }
func (c *Checkin) SyncCheckinDay(corpId int64, day string) { func (c *Checkin) SyncCheckinDay(day string) {
corp, err := dao.NewCorpDao().Get(corpId)
if err != nil {
log.Errorf("db error :%s", err.Error())
return
}
cfg := corp.GetConfig()
qyw := qyweixin.NewAppCheckin(&qyweixin.AppConfig{
Corpid: cfg.CorpId,
Secret: cfg.EnterpriseSecret,
Agent: cfg.EnterpriseAgent,
})
if day == "" { if day == "" {
day = time.Now().AddDate(0, 0, -1).Format("2006-01-02") day = time.Now().AddDate(0, 0, -1).Format("2006-01-02")
} }
users, err := qyw.GetCheckinEmployee(nil) new(service.Checkin).SyncCheckin(c.corp.Id, day, day)
if err != nil {
log.Errorf("GetCheckinEmployee error :%s", err.Error())
return
}
userDatas, err := qyw.GetCheckinData(day, day, users)
if err != nil {
log.Errorf("GetCheckinData[%s-%s]%s error :%s", day, day, goutil.EncodeJSON(users), err.Error())
return
}
for _, user := range userDatas {
c.saveToDB(user)
}
return
} }
func (c *Checkin) MonitorCheckinDay(corpId int64, day string) { func (c *Checkin) MonitorCheckinDay(day string) {
if day == "" { if day == "" {
day = time.Now().AddDate(0, 0, -1).Format("2006-01-02") day = time.Now().AddDate(0, 0, -1).Format("2006-01-02")
} }
checkins, err := dao.NewCheckinDao().QueryDay(corpId, day) checkins, err := dao.NewCheckinDao().QueryDay(c.corp.Id, day)
if err != nil { if err != nil {
log.Errorf("db error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
return return
@ -104,7 +59,7 @@ func (c *Checkin) MonitorCheckinDay(corpId int64, day string) {
if checkin.Exception == "" { if checkin.Exception == "" {
continue continue
} }
approvals, err := dao.NewApprovalVacationDao().GetByUsername(corpId, checkin.Username, "", checkin.Day) approvals, err := dao.NewApprovalVacationDao().GetByUsername(c.corp.Id, checkin.Username, "", checkin.Day)
if err != nil { if err != nil {
log.Errorf("db error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
continue continue
@ -121,38 +76,3 @@ func (c *Checkin) MonitorCheckinDay(corpId int64, day string) {
global.SendMessage([]string{"jiangyong", checkin.Username}, strings.Join(message, "\n")) global.SendMessage([]string{"jiangyong", checkin.Username}, strings.Join(message, "\n"))
} }
} }
func (c *Checkin) saveToDB(user *qyweixin.UserCheckIn) error {
checkin, err := dao.NewCheckinDao().GetByDay(user.UserId, user.Day)
if err != nil {
log.Errorf("db error :%s", err.Error())
return err
}
isNew := false
if checkin == nil {
checkin = new(model.Checkin)
checkin.Day = user.Day
checkin.Month = user.Month
checkin.Username = user.UserId
isNew = true
}
checkin.Exception = user.Exception
checkin.StartTime = user.StartTime
checkin.EndTime = user.EndTime
checkin.Month = user.Month
checkin.Rawdata = user.Rawdata
checkin.CorpId = c.corp.Id
if isNew {
_, err = dao.NewCheckinDao().Create(checkin)
} else {
err = dao.NewCheckinDao().Update(checkin)
}
if err != nil {
log.Errorf("create/update db error :%s", err.Error())
return err
}
return nil
}

View File

@ -22,11 +22,11 @@ func InitCorp1002(cron *gocron.Scheduler) {
//同步每日考勤数据 //同步每日考勤数据
cron.Every(1).Day().At("05:00").Do(func() { cron.Every(1).Day().At("05:00").Do(func() {
checkIn := NewCheckin(corpId) checkIn := NewCheckin(corpId)
go checkIn.SyncCheckinDay(corpId, "") go checkIn.SyncCheckinDay("")
}) })
cron.Every(1).Day().At("08:00").Do(func() { cron.Every(1).Day().At("08:00").Do(func() {
checkIn := NewCheckin(corpId) checkIn := NewCheckin(corpId)
go checkIn.MonitorCheckinDay(corpId, "") go checkIn.MonitorCheckinDay("")
}) })
//每月1号同步上月考勤、补卡审批、请假审批、报销审批 //每月1号同步上月考勤、补卡审批、请假审批、报销审批
@ -65,11 +65,11 @@ func InitCorp1000(cron *gocron.Scheduler) {
//同步每日考勤数据 //同步每日考勤数据
cron.Every(1).Day().At("05:00").Do(func() { cron.Every(1).Day().At("05:00").Do(func() {
checkIn := NewCheckin(corpId) checkIn := NewCheckin(corpId)
go checkIn.SyncCheckinDay(corpId, "") go checkIn.SyncCheckinDay("")
}) })
cron.Every(1).Day().At("08:00").Do(func() { cron.Every(1).Day().At("08:00").Do(func() {
checkIn := NewCheckin(corpId) checkIn := NewCheckin(corpId)
go checkIn.MonitorCheckinDay(corpId, "") go checkIn.MonitorCheckinDay("")
}) })
//每月1号同步上月考勤、补卡审批、请假审批、报销审批 //每月1号同步上月考勤、补卡审批、请假审批、报销审批