✨ 请假功能
This commit is contained in:
+3
-1
@@ -4,4 +4,6 @@
|
||||
node_modules
|
||||
.claude
|
||||
*.exe
|
||||
.serena
|
||||
.serena
|
||||
|
||||
device_code_cfworker
|
||||
@@ -0,0 +1,146 @@
|
||||
package leave
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/application/cpdaily"
|
||||
"likedream-goframe/internal/application/cpdaily/leave/model"
|
||||
"likedream-goframe/internal/application/cpdaily/taskhelper"
|
||||
"likedream-goframe/internal/common/errors"
|
||||
"likedream-goframe/internal/utils"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
// CheckOnceLeave 检查是否允许请假
|
||||
func (c *CpdailyReportApp) CheckOnceLeave() error {
|
||||
post, err := c.client.R().SetBody(map[string]any{}).
|
||||
Post(fmt.Sprintf("%s/wec-counselor-leave-apps/leave/stu/checkOnceLeave", c.host))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result := utils.ReadGjsonResult(post.Body)
|
||||
if result.Get("code").String() != "0" {
|
||||
return errors.NewBusinessError(400, result.Get("message").String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// QueryLeaveTypes 获取请假类型列表
|
||||
func (c *CpdailyReportApp) QueryLeaveTypes() gjson.Result {
|
||||
post, err := c.client.R().SetBody(map[string]any{}).
|
||||
Post(fmt.Sprintf("%s/wec-counselor-leave-apps/leave/queryLeaveTypes", c.host))
|
||||
utils.OkOrPanic(err)
|
||||
result := utils.ReadGjsonResult(post.Body)
|
||||
if result.Get("code").String() != "0" {
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, result.Get("message").String()))
|
||||
}
|
||||
return result.Get("datas.leaveType")
|
||||
}
|
||||
|
||||
// QueryLeaveTypeCfg 查询请假类型配置
|
||||
func (c *CpdailyReportApp) QueryLeaveTypeCfg(code int) gjson.Result {
|
||||
post, err := c.client.R().SetBody(map[string]any{"code": code}).
|
||||
Post(fmt.Sprintf("%s/wec-counselor-leave-apps/leave/stu/queryLeaveTypeCfg", c.host))
|
||||
utils.OkOrPanic(err)
|
||||
result := utils.ReadGjsonResult(post.Body)
|
||||
if result.Get("code").String() != "0" {
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, result.Get("message").String()))
|
||||
}
|
||||
return result.Get("datas")
|
||||
}
|
||||
|
||||
// ObtainApproveFlow 获取审批人列表
|
||||
func (c *CpdailyReportApp) ObtainApproveFlow(leaveType int, startTime, endTime string) gjson.Result {
|
||||
post, err := c.client.R().SetBody(map[string]any{
|
||||
"leaveType": leaveType,
|
||||
"startTime": startTime,
|
||||
"endTime": endTime,
|
||||
}).Post(fmt.Sprintf("%s/wec-counselor-leave-apps/leave/stu/obtainApproveFlow", c.host))
|
||||
utils.OkOrPanic(err)
|
||||
result := utils.ReadGjsonResult(post.Body)
|
||||
if result.Get("code").String() != "0" {
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, result.Get("message").String()))
|
||||
}
|
||||
return result.Get("datas")
|
||||
}
|
||||
|
||||
// SubmitLeaveApply 提交请假申请
|
||||
func (c *CpdailyReportApp) SubmitLeaveApply(ctx context.Context, req *v1.CpLeaveApplyReq, username, deviceId string) {
|
||||
cpdailyInfo := cpdaily.GetInfo(ctx)
|
||||
|
||||
// 构造请假申请体
|
||||
applyBody := map[string]any{
|
||||
"leaveType": req.LeaveType,
|
||||
"startTime": req.StartTime,
|
||||
"endTime": req.EndTime,
|
||||
"urgencyMobile": req.UrgencyMobile,
|
||||
"leaveReason": req.LeaveReason,
|
||||
"isAttendance": nil,
|
||||
"outStatus": req.OutStatus,
|
||||
"address": req.Address,
|
||||
"detailAddress": req.DetailAddress,
|
||||
"destination": req.Address + "/" + req.DetailAddress,
|
||||
"holidayAutoDefineVos": []any{},
|
||||
"appVersion": cpdailyInfo.AppVersion,
|
||||
"deviceId": deviceId,
|
||||
"ccInfo": map[string]any{"teachers": []any{}, "students": []any{}},
|
||||
"cheatType": nil,
|
||||
"source": 1,
|
||||
"location": map[string]any{
|
||||
"deviceId": deviceId,
|
||||
"systemName": "Android",
|
||||
"systemVersion": cpdailyInfo.SystemVersion,
|
||||
"model": "Redmi Note 8 Pro",
|
||||
"address": req.LocationAddr,
|
||||
"latitude": req.Latitude,
|
||||
"longitude": req.Longitude,
|
||||
},
|
||||
"locationType": 0,
|
||||
"disclaimers": "本人承诺填写的信息真实有效,并对本次提交请假申请的信息真实性负责。",
|
||||
"uaIsCpadaily": "true",
|
||||
"leaveApplyExplain": nil,
|
||||
}
|
||||
|
||||
// 审批人信息
|
||||
if req.ApproverWid != "" {
|
||||
applyBody["approverWid"] = req.ApproverWid
|
||||
applyBody["approverId"] = req.ApproverId
|
||||
applyBody["approverName"] = req.ApproverName
|
||||
}
|
||||
|
||||
// 图片附件
|
||||
if req.ImageUrl != "" {
|
||||
applyBody["applyAttach"] = []model.Attach{{Type: 1, Url: req.ImageUrl}}
|
||||
} else {
|
||||
applyBody["applyAttach"] = []any{}
|
||||
}
|
||||
|
||||
// 构造加密扩展头
|
||||
extensionForm := map[string]*gvar.Var{
|
||||
"lon": gvar.New(req.Longitude),
|
||||
"lat": gvar.New(req.Latitude),
|
||||
"model": gvar.New("Redmi Note 8 Pro"),
|
||||
"appVersion": gvar.New(cpdailyInfo.AppVersion),
|
||||
"systemVersion": gvar.New(cpdailyInfo.SystemVersion),
|
||||
"userId": gvar.New(username),
|
||||
"systemName": gvar.New("android"),
|
||||
"deviceId": gvar.New(deviceId),
|
||||
}
|
||||
extensionString := taskhelper.GetCpdailyExtension(ctx, extensionForm)
|
||||
|
||||
// 提交请假
|
||||
response, e := c.client.R().
|
||||
SetBody(applyBody).
|
||||
WithContext(ctx).
|
||||
SetHeader("Cpdaily-Extension", extensionString).
|
||||
Post(fmt.Sprintf("%s/wec-counselor-leave-apps/leave/apply", c.host))
|
||||
|
||||
utils.OkOrPanic(e)
|
||||
responseJSON := utils.ReadGjsonResult(response.Body)
|
||||
if responseJSON.Get("code").String() != "0" {
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, responseJSON.Get("message").String()))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user