package user

import (
	"context"
	"net/http"
	"time"

	"git.i2edu.net/i2/i2-bill-api/internal/svc"
	"git.i2edu.net/i2/i2-bill-api/internal/types"

	"git.i2edu.net/i2/go-zero/core/logx"
)

type PunchClockGetLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPunchClockGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) PunchClockGetLogic {
	return PunchClockGetLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PunchClockGetLogic) PunchClockGet(r *http.Request) (*types.Response, error) {
	// todo: add your logic here and delete this line
	res, err := l.svcCtx.DB.SQL("select * from i2bill_acquirer_attendance_record where del_flag = 0 and user_id = ? and  DATE_FORMAT(create_time,'%Y-%m-%d') = ? order by id desc limit 0,1", l.svcCtx.GetUserIdByJwt(l.ctx), time.Now().Format("2006-01-02")).Query().List()
	if err != nil {
		return &types.Response{500, err.Error(), nil}, nil
	}
	return &types.Response{200, "", res}, nil
}
