From 988cc7be6f52ccc2fc8ba1382ca30646dfd6208a Mon Sep 17 00:00:00 2001 From: sugarBecomer Date: Wed, 25 Mar 2026 13:57:15 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E8=AF=B7=E5=81=87=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +- internal/application/cpdaily/leave/apply.go | 146 ++++++++++++++++++++ 2 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 internal/application/cpdaily/leave/apply.go diff --git a/.gitignore b/.gitignore index 8126dd3..0ef4f0a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ node_modules .claude *.exe -.serena \ No newline at end of file +.serena + +device_code_cfworker \ No newline at end of file diff --git a/internal/application/cpdaily/leave/apply.go b/internal/application/cpdaily/leave/apply.go new file mode 100644 index 0000000..8bd7586 --- /dev/null +++ b/internal/application/cpdaily/leave/apply.go @@ -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())) + } +}