更新
This commit is contained in:
1 parent
012f8edf8b
commit
36ff960fbd
33 files changed
+1644
-344
No files matched your search
@@ -13,6 +13,7 @@ import (
|
||||
"server/models"
|
||||
"server/pkg/identity"
|
||||
"server/pkg/jwtutil"
|
||||
"server/services/gueststore"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
@@ -22,9 +23,9 @@ type AppReminderController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// 只放行移动端与租户端令牌:/api/** 仅被 uniapp 调用,平台令牌不该能打移动端接口。
|
||||
// 放行移动端、租户端与游客令牌:游客调用时不进业务表,分流到 gueststore。
|
||||
func (c *AppReminderController) appClaims() (*jwtutil.Claims, error) {
|
||||
return identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndApp, identity.EndBackend)
|
||||
return identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndApp, identity.EndBackend, identity.EndGuest)
|
||||
}
|
||||
|
||||
func (c *AppReminderController) jsonErr(httpStatus, bizCode int, msg string) {
|
||||
@@ -75,6 +76,11 @@ func (c *AppReminderController) GetList() {
|
||||
pageSize = 20
|
||||
}
|
||||
|
||||
if identity.IsGuest(claims) {
|
||||
c.guestList(claims, page, pageSize, keyword, status)
|
||||
return
|
||||
}
|
||||
|
||||
qs := models.Orm.QueryTable(new(models.BackendSchedule)).
|
||||
Filter("user_id", claims.UserID).
|
||||
Filter("tid", claims.TenantId)
|
||||
@@ -171,6 +177,11 @@ func (c *AppReminderController) GetDetail() {
|
||||
return
|
||||
}
|
||||
|
||||
if identity.IsGuest(claims) {
|
||||
c.guestDetail(claims, id)
|
||||
return
|
||||
}
|
||||
|
||||
var schedule models.BackendSchedule
|
||||
err = models.Orm.QueryTable(new(models.BackendSchedule)).
|
||||
Filter("id", id).
|
||||
@@ -272,6 +283,11 @@ func (c *AppReminderController) Create() {
|
||||
title = "日程提醒"
|
||||
}
|
||||
|
||||
if identity.IsGuest(claims) {
|
||||
c.guestCreate(claims, p, content, schedTime)
|
||||
return
|
||||
}
|
||||
|
||||
schedule := models.BackendSchedule{
|
||||
Tid: claims.TenantId,
|
||||
Title: title,
|
||||
@@ -363,6 +379,11 @@ func (c *AppReminderController) Update() {
|
||||
return
|
||||
}
|
||||
|
||||
if identity.IsGuest(claims) {
|
||||
c.guestUpdate(claims, id, p)
|
||||
return
|
||||
}
|
||||
|
||||
var schedule models.BackendSchedule
|
||||
err = models.Orm.QueryTable(new(models.BackendSchedule)).
|
||||
Filter("id", id).
|
||||
@@ -482,6 +503,11 @@ func (c *AppReminderController) Delete() {
|
||||
return
|
||||
}
|
||||
|
||||
if identity.IsGuest(claims) {
|
||||
c.guestDelete(claims, id)
|
||||
return
|
||||
}
|
||||
|
||||
var schedule models.BackendSchedule
|
||||
err = models.Orm.QueryTable(new(models.BackendSchedule)).
|
||||
Filter("id", id).
|
||||
@@ -543,6 +569,11 @@ func (c *AppReminderController) ToggleComplete() {
|
||||
return
|
||||
}
|
||||
|
||||
if identity.IsGuest(claims) {
|
||||
c.guestToggle(claims, id)
|
||||
return
|
||||
}
|
||||
|
||||
var schedule models.BackendSchedule
|
||||
err = models.Orm.QueryTable(new(models.BackendSchedule)).
|
||||
Filter("id", id).
|
||||
@@ -587,3 +618,175 @@ func (c *AppReminderController) ToggleComplete() {
|
||||
"is_finished": newStatus == 2,
|
||||
})
|
||||
}
|
||||
|
||||
// ---------- 游客分支(免登录态):数据存 yz_guest_data,响应结构与登录态一致。
|
||||
// 游客日程不接提醒发送链路(无短信/邮件推送),仅作待办记录;转正合并时重建提醒。 ----------
|
||||
|
||||
func guestScheduleItemMap(it guestScheduleItem) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"id": it.ID,
|
||||
"content": it.Content,
|
||||
"schedule_time": it.ScheduleTime,
|
||||
"remind_channels": it.RemindChannels,
|
||||
"is_finished": it.IsFinished,
|
||||
"advance_minutes": it.AdvanceMinutes,
|
||||
"repeat_interval_minutes": it.RepeatIntervalMinutes,
|
||||
"max_send_count": it.MaxSendCount,
|
||||
"created_at": it.CreatedAt,
|
||||
"updated_at": it.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func guestScheduleFull(r gueststore.Row) guestScheduleItem {
|
||||
var it guestScheduleItem
|
||||
if json.Unmarshal(r.Payload, &it) != nil {
|
||||
it = guestScheduleItem{Content: "(数据异常)"}
|
||||
}
|
||||
it.ID = r.ID
|
||||
it.CreatedAt = r.CreateTime.Format("2006-01-02 15:04:05")
|
||||
it.UpdatedAt = it.CreatedAt
|
||||
if r.UpdateTime != nil {
|
||||
it.UpdatedAt = r.UpdateTime.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
if it.RemindChannels == nil {
|
||||
it.RemindChannels = []string{}
|
||||
}
|
||||
return it
|
||||
}
|
||||
|
||||
func (c *AppReminderController) guestList(claims *jwtutil.Claims, page, pageSize int, keyword, status string) {
|
||||
rows, err := gueststore.List(uint64(claims.UserID), guestModuleSchedule)
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "查询失败")
|
||||
return
|
||||
}
|
||||
items := make([]map[string]interface{}, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
it := guestScheduleFull(r)
|
||||
if keyword != "" && !strings.Contains(it.Content, keyword) {
|
||||
continue
|
||||
}
|
||||
if status == "pending" && it.IsFinished {
|
||||
continue
|
||||
}
|
||||
if status == "done" && !it.IsFinished {
|
||||
continue
|
||||
}
|
||||
items = append(items, guestScheduleItemMap(it))
|
||||
}
|
||||
total := len(items)
|
||||
start := (page - 1) * pageSize
|
||||
if start > total {
|
||||
start = total
|
||||
}
|
||||
end := start + pageSize
|
||||
if end > total {
|
||||
end = total
|
||||
}
|
||||
c.ok(map[string]interface{}{
|
||||
"list": items[start:end], "total": total, "page": page, "pageSize": pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *AppReminderController) guestDetail(claims *jwtutil.Claims, id uint64) {
|
||||
r, err := gueststore.Get(uint64(claims.UserID), guestModuleSchedule, id)
|
||||
if err != nil {
|
||||
c.jsonErr(404, 404, "日程未找到")
|
||||
return
|
||||
}
|
||||
c.ok(guestScheduleItemMap(guestScheduleFull(r)))
|
||||
}
|
||||
|
||||
func (c *AppReminderController) guestCreate(claims *jwtutil.Claims, p appSchedulePayload, content string, schedTime time.Time) {
|
||||
_ = schedTime
|
||||
now := time.Now().Format("2006-01-02 15:04:05")
|
||||
channels := p.RemindChannels
|
||||
if channels == nil {
|
||||
channels = []string{}
|
||||
}
|
||||
it := guestScheduleItem{
|
||||
Content: content,
|
||||
ScheduleTime: p.ScheduleTime,
|
||||
RemindChannels: channels,
|
||||
AdvanceMinutes: p.AdvanceMinutes,
|
||||
RepeatIntervalMinutes: p.RepeatIntervalMinutes,
|
||||
MaxSendCount: p.MaxSendCount,
|
||||
IsFinished: false,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
newID, err := gueststore.Insert(uint64(claims.UserID), guestModuleSchedule, it)
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "保存日程失败")
|
||||
return
|
||||
}
|
||||
c.ok(map[string]interface{}{"id": newID})
|
||||
}
|
||||
|
||||
func (c *AppReminderController) guestUpdate(claims *jwtutil.Claims, id uint64, p appSchedulePayload) {
|
||||
r, err := gueststore.Get(uint64(claims.UserID), guestModuleSchedule, id)
|
||||
if err != nil {
|
||||
c.jsonErr(404, 404, "日程未找到")
|
||||
return
|
||||
}
|
||||
it := guestScheduleFull(r)
|
||||
if it.IsFinished {
|
||||
c.jsonErr(400, 400, "该日程提醒已全部结束,无法编辑")
|
||||
return
|
||||
}
|
||||
if content := strings.TrimSpace(p.Content); content != "" {
|
||||
it.Content = content
|
||||
}
|
||||
if strings.TrimSpace(p.ScheduleTime) != "" {
|
||||
if _, perr := time.ParseInLocation("2006-01-02 15:04:05", p.ScheduleTime, time.Local); perr != nil {
|
||||
c.jsonErr(400, 400, "日程时间格式不合法")
|
||||
return
|
||||
}
|
||||
it.ScheduleTime = p.ScheduleTime
|
||||
}
|
||||
if p.RemindChannels != nil {
|
||||
it.RemindChannels = p.RemindChannels
|
||||
}
|
||||
it.AdvanceMinutes = p.AdvanceMinutes
|
||||
it.RepeatIntervalMinutes = p.RepeatIntervalMinutes
|
||||
it.MaxSendCount = p.MaxSendCount
|
||||
it.UpdatedAt = time.Now().Format("2006-01-02 15:04:05")
|
||||
if err = gueststore.Update(uint64(claims.UserID), guestModuleSchedule, id, it); err != nil {
|
||||
c.jsonErr(500, 500, "更新失败")
|
||||
return
|
||||
}
|
||||
c.ok(nil)
|
||||
}
|
||||
|
||||
func (c *AppReminderController) guestDelete(claims *jwtutil.Claims, id uint64) {
|
||||
r, err := gueststore.Get(uint64(claims.UserID), guestModuleSchedule, id)
|
||||
if err != nil {
|
||||
c.jsonErr(404, 404, "日程未找到")
|
||||
return
|
||||
}
|
||||
if guestScheduleFull(r).IsFinished {
|
||||
c.jsonErr(400, 400, "该日程提醒已全部结束,无法删除")
|
||||
return
|
||||
}
|
||||
if err = gueststore.Delete(uint64(claims.UserID), guestModuleSchedule, id); err != nil {
|
||||
c.jsonErr(500, 500, "删除失败")
|
||||
return
|
||||
}
|
||||
c.ok(nil)
|
||||
}
|
||||
|
||||
func (c *AppReminderController) guestToggle(claims *jwtutil.Claims, id uint64) {
|
||||
r, err := gueststore.Get(uint64(claims.UserID), guestModuleSchedule, id)
|
||||
if err != nil {
|
||||
c.jsonErr(404, 404, "日程未找到")
|
||||
return
|
||||
}
|
||||
it := guestScheduleFull(r)
|
||||
it.IsFinished = !it.IsFinished
|
||||
it.UpdatedAt = time.Now().Format("2006-01-02 15:04:05")
|
||||
if err = gueststore.Update(uint64(claims.UserID), guestModuleSchedule, id, it); err != nil {
|
||||
c.jsonErr(500, 500, "操作失败")
|
||||
return
|
||||
}
|
||||
c.ok(map[string]interface{}{"is_finished": it.IsFinished})
|
||||
}
|
||||
Reference in new issue
Block a user