68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
|
package worker
|
||
|
|
||
|
import (
|
||
|
"enterprise/common/config"
|
||
|
"enterprise/common/dao"
|
||
|
"enterprise/common/model"
|
||
|
"enterprise/common/weixin"
|
||
|
log "github.com/sirupsen/logrus"
|
||
|
"github.com/smbrave/goutil"
|
||
|
"github.com/spf13/cast"
|
||
|
"strings"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type Approval struct {
|
||
|
}
|
||
|
|
||
|
func (s *Approval) SyncCheckinMonth(month string) {
|
||
|
templateId := "C4UCJS891Afmu1rE1Ws6cvph7YHqebWtt7KRFqh8c"
|
||
|
cfg := config.GetConfig().QyWeixin
|
||
|
approve := weixin.NewQyWeixinApprove(cfg.Corpid, cfg.ApproveSecret, cfg.ApproveAgent)
|
||
|
startTime, _ := time.ParseInLocation("200601", month, time.Local)
|
||
|
endTime := startTime.AddDate(0, 1, 0)
|
||
|
spNos, err := approve.GetList(startTime.Unix(), endTime.Unix()-1, templateId)
|
||
|
if err != nil {
|
||
|
log.Errorf("approve getlist error :%s", err.Error())
|
||
|
return
|
||
|
}
|
||
|
//result := make(map[string]float64)
|
||
|
for _, spNo := range spNos {
|
||
|
detail, err := approve.GetDetail(spNo)
|
||
|
if err != nil {
|
||
|
log.Errorf("approve GetDetail error :%s", err.Error())
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
value := strings.SplitN(detail.GetValue("补卡"), ",", 3)
|
||
|
|
||
|
ac, err := dao.NewApprovalCheckinDao().GetBySpNo(spNo)
|
||
|
if err != nil {
|
||
|
log.Errorf("db error :%s", err.Error())
|
||
|
continue
|
||
|
}
|
||
|
isNew := false
|
||
|
if ac == nil {
|
||
|
ac = new(model.ApprovalCheckin)
|
||
|
ac.SpNo = detail.SpNo
|
||
|
isNew = true
|
||
|
}
|
||
|
|
||
|
ac.Username = detail.GetUserid()
|
||
|
ac.ApplyTime = goutil.TimeToDateTime(detail.ApplyTime)
|
||
|
ac.CheckinRemark = detail.GetValue("补卡事由")
|
||
|
ac.CheckinDate = goutil.TimeToDate(cast.ToInt64(value[0]))
|
||
|
ac.CheckinTime = goutil.TimeToDateTime(cast.ToInt64(value[1]))
|
||
|
ac.CheckinType = value[2]
|
||
|
if isNew {
|
||
|
_, err = dao.NewApprovalCheckinDao().Create(ac)
|
||
|
} else {
|
||
|
err = dao.NewApprovalCheckinDao().Update(ac)
|
||
|
}
|
||
|
if err != nil {
|
||
|
log.Errorf("db error :%s", err.Error())
|
||
|
}
|
||
|
}
|
||
|
return
|
||
|
}
|