211 lines
6.9 KiB
Go
211 lines
6.9 KiB
Go
package leave
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
v1 "likedream-goframe/internal/api/v1"
|
|
"likedream-goframe/internal/application/cpdaily"
|
|
"likedream-goframe/internal/application/cpdaily/cryptoutil"
|
|
"likedream-goframe/internal/application/cpdaily/imageuploader"
|
|
"likedream-goframe/internal/application/cpdaily/leave/model"
|
|
"likedream-goframe/internal/application/cpdaily/task/leavetype"
|
|
"likedream-goframe/internal/application/cpdaily/taskhelper"
|
|
"likedream-goframe/internal/application/cpdaily/types"
|
|
"likedream-goframe/internal/common/errors"
|
|
"likedream-goframe/internal/utils"
|
|
|
|
"github.com/gogf/gf/v2/container/gvar"
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
"github.com/google/uuid"
|
|
"github.com/samber/oops"
|
|
"github.com/tidwall/gjson"
|
|
"resty.dev/v3"
|
|
)
|
|
|
|
/**
|
|
* @Description: 销假相关功能
|
|
*/
|
|
type CpdailyReportApp struct {
|
|
client *resty.Client
|
|
host string
|
|
}
|
|
|
|
func NewCpdailyReportApp(client *resty.Client, host string) *CpdailyReportApp {
|
|
|
|
return &CpdailyReportApp{
|
|
client: client,
|
|
host: host,
|
|
}
|
|
}
|
|
|
|
// 获取请假记录
|
|
func (c *CpdailyReportApp) GetLeaveList() []leavetype.LeaveListOne {
|
|
// https://fzfu.campusphere.net/wec-counselor-leave-apps/leave/stu/listOther
|
|
post, err := c.client.R().SetBody(map[string]int{
|
|
"pageNumber": 1,
|
|
"pageSize": 20,
|
|
"needApproval": 1,
|
|
}).Post(fmt.Sprintf("%s/wec-counselor-leave-apps/leave/stu/listOther", c.host))
|
|
|
|
utils.OkOrPanic(err, func(err error) error {
|
|
return oops.
|
|
With("host", c.host).
|
|
In("CpdailyReport.GetLeaveList").
|
|
Wrap(err)
|
|
})
|
|
responseJSON := utils.ReadGjsonResult(post.Body)
|
|
rows := responseJSON.Get("datas.rows")
|
|
|
|
if !rows.Exists() {
|
|
utils.OkOrPanic(errors.NewBusinessError(503, "没有获取到待销假信息"), func(err error) error {
|
|
return oops.
|
|
With("host", c.host).
|
|
In("CpdailyReport.GetLeaveList").
|
|
Wrap(err)
|
|
})
|
|
}
|
|
|
|
var listList []leavetype.LeaveListOne
|
|
for _, row := range rows.Array() {
|
|
// 已完成
|
|
if row.Get("status").String() == "4" {
|
|
continue
|
|
}
|
|
id := row.Get("id").String()
|
|
detail := c.LeaveDetail(id)
|
|
leaveOne := leavetype.LeaveListOne{
|
|
Id: row.Get("id").String(),
|
|
LeaveType: row.Get("leaveType").String(),
|
|
CreateTime: row.Get("createTime").String(),
|
|
Reason: row.Get("leaveReason").String(),
|
|
AceEndTime: row.Get("actEndTime").String(),
|
|
Status: row.Get("status").String(),
|
|
ChooseAttendance: detail.Get("leaveType.chooseAttendance").Int(),
|
|
//Longitude: detail.Get("detail.applyLocation.longitude").String(),
|
|
//Latitude: detail.Get("detail.applyLocation.latitude").String(),
|
|
//Address: detail.Get("detail.applyLocation.address").String(),
|
|
|
|
Longitude: detail.Get("leaveExtends.0.longitude").String(),
|
|
Latitude: detail.Get("leaveExtends.0.latitude").String(),
|
|
Address: detail.Get("leaveExtends.0.address").String(),
|
|
}
|
|
|
|
listList = append(listList, leaveOne)
|
|
}
|
|
return listList
|
|
}
|
|
|
|
func (c *CpdailyReportApp) LeaveDetail(leaveId string) gjson.Result {
|
|
// https://fzfu.campusphere.net/wec-counselor-leave-apps/leave/stu/detailOther
|
|
post, err := c.client.R().SetBody(map[string]any{
|
|
"id": leaveId,
|
|
"needApproval": 1,
|
|
"uaIsCpadaily": "true",
|
|
}).Post(fmt.Sprintf("%s/wec-counselor-leave-apps/leave/stu/detailOther", c.host))
|
|
utils.OkOrPanic(err, func(err error) error {
|
|
return oops.
|
|
With("host", c.host).
|
|
In("CpdailyReport.LeaveDetail").
|
|
Wrap(err)
|
|
})
|
|
datas := utils.ReadGjsonResult(post.Body).Get("datas")
|
|
if !datas.Exists() {
|
|
utils.OkOrPanic(errors.NewBusinessError(503, "没有获取到待销假详情信息"), func(err error) error {
|
|
return oops.
|
|
With("host", c.host).
|
|
In("CpdailyReport.LeaveDetail").
|
|
Wrap(err)
|
|
})
|
|
}
|
|
return datas
|
|
}
|
|
|
|
func (c *CpdailyReportApp) UploadImage(ctx context.Context, file *ghttp.UploadFile) string {
|
|
return imageuploader.UploadImageFromFile(ctx, c.host, file, types.TaskTypeLeave, c.client)
|
|
}
|
|
|
|
func (c *CpdailyReportApp) FillReportForm(detail gjson.Result, req *v1.CpLeaveReportReq) map[string]*gvar.Var {
|
|
resultForm := make(map[string]*gvar.Var)
|
|
resultForm["id"] = gvar.New(detail.Get("detail.id").String())
|
|
resultForm["needApproval"] = gvar.New(1)
|
|
resultForm["leaveType"] = gvar.New(detail.Get("leaveType.code").String())
|
|
if req.Address == "" {
|
|
resultForm["reportLocation"] = gvar.New(detail.Get("leaveExtends.0.address").String())
|
|
} else {
|
|
resultForm["reportLocation"] = gvar.New(req.Address)
|
|
}
|
|
resultForm["approverWid"] = gvar.New("")
|
|
resultForm["reportApplyExplain"] = gvar.New(nil)
|
|
resultForm["uaIsCpadaily"] = gvar.New(true)
|
|
if req.ImageUrl != "" {
|
|
var attach []model.Attach
|
|
attach = append(attach, model.Attach{
|
|
Type: 1,
|
|
Url: req.ImageUrl,
|
|
})
|
|
resultForm["reportAttach"] = gvar.New(attach)
|
|
} else {
|
|
resultForm["reportAttach"] = gvar.New([]string{})
|
|
}
|
|
return resultForm
|
|
}
|
|
|
|
func (c *CpdailyReportApp) GetLocation(detail gjson.Result) (lon, lat string) {
|
|
applyLocation := detail.Get("detail.applyLocation")
|
|
lon = applyLocation.Get("longitude").String()
|
|
lat = applyLocation.Get("latitude").String()
|
|
return
|
|
}
|
|
func (c *CpdailyReportApp) SubmitReport(ctx context.Context, form map[string]*gvar.Var, lon, lat, username, deviceId string) {
|
|
cpdailyInfo := cpdaily.GetInfo(ctx)
|
|
|
|
extensionForm := map[string]*gvar.Var{
|
|
"lon": gvar.New(lon),
|
|
"lat": gvar.New(lat),
|
|
"model": gvar.New(uuid.New().String()),
|
|
"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)
|
|
bodyString := taskhelper.GetBodyString(ctx, form)
|
|
// 构造提交数据
|
|
submitData := map[string]*gvar.Var{
|
|
"lon": gvar.New(lon),
|
|
"version": gvar.New(cryptoutil.EncryptVersion),
|
|
"calVersion": gvar.New(cpdailyInfo.CalVersion),
|
|
"deviceId": extensionForm["deviceId"],
|
|
"userId": gvar.New(username),
|
|
"systemName": gvar.New("android"),
|
|
"bodyString": gvar.New(bodyString),
|
|
"lat": gvar.New(lat),
|
|
"systemVersion": gvar.New(cpdailyInfo.SystemVersion),
|
|
"appVersion": gvar.New(cpdailyInfo.AppVersion),
|
|
"model": extensionForm["model"],
|
|
}
|
|
// https://fzfu.campusphere.net/wec-counselor-leave-apps/leave/report
|
|
response, e := c.client.R().
|
|
SetBody(submitData).
|
|
WithContext(ctx).
|
|
SetHeader("Cpdaily-Extension", extensionString).
|
|
Post(fmt.Sprintf("%s/wec-counselor-leave-apps/leave/report", c.host))
|
|
|
|
utils.OkOrPanic(e, func(err error) error {
|
|
return oops.
|
|
With("host", c.host).
|
|
With("username", username).
|
|
With("deviceId", deviceId).
|
|
In("CpdailySleepCheckTask.Submit").
|
|
Wrap(err)
|
|
})
|
|
|
|
responseJSON := utils.ReadGjsonResult(response.Body)
|
|
|
|
if responseJSON.Get("code").String() != "0" {
|
|
utils.OkOrPanic(errors.NewBusinessError(503, responseJSON.Get("message").String()), oops.WithContext(ctx).Wrap)
|
|
}
|
|
}
|