更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
)
|
||||
|
||||
// Attachment 日报附件,与 PC / 小程序上传接口返回的文件信息对齐。
|
||||
type Attachment struct {
|
||||
ID uint64 `json:"id"`
|
||||
URL string `json:"url"`
|
||||
@@ -20,7 +19,6 @@ type Attachment struct {
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
// ReportItem 日报列表/详情中的主体。
|
||||
type ReportItem struct {
|
||||
ID uint64 `json:"id"`
|
||||
UserID uint64 `json:"user_id"`
|
||||
@@ -39,7 +37,6 @@ type ReportItem struct {
|
||||
CommentCount int `json:"comment_count"`
|
||||
}
|
||||
|
||||
// Comment 日报评论(两级回复)。
|
||||
type Comment struct {
|
||||
ID uint64 `json:"id"`
|
||||
UserID uint64 `json:"user_id"`
|
||||
@@ -52,7 +49,6 @@ type Comment struct {
|
||||
CanDelete bool `json:"can_delete"`
|
||||
}
|
||||
|
||||
// Detail 日报详情:主体 + 评论 + 修改痕迹 + 当前用户可执行的操作。
|
||||
type Detail struct {
|
||||
Report ReportItem `json:"report"`
|
||||
Comments []Comment `json:"comments"`
|
||||
@@ -64,10 +60,9 @@ type Detail struct {
|
||||
CanWithdraw bool `json:"can_withdraw"`
|
||||
}
|
||||
|
||||
// HistoryItem 日报修改痕迹:撤销提交 / 撤销后重新提交时的内容快照。
|
||||
type HistoryItem struct {
|
||||
ID uint64 `json:"id"`
|
||||
Action int8 `json:"action"` // 1撤销提交 2重新提交
|
||||
Action int8 `json:"action"`
|
||||
UserName string `json:"user_name"`
|
||||
TodayDone string `json:"today_done"`
|
||||
TomorrowPlan string `json:"tomorrow_plan"`
|
||||
@@ -77,7 +72,6 @@ type HistoryItem struct {
|
||||
CreateTime string `json:"create_time"`
|
||||
}
|
||||
|
||||
// SaveInput 保存日报入参;Submit=true 表示提交,否则保存草稿。
|
||||
type SaveInput struct {
|
||||
Date string `json:"date"`
|
||||
TodayDone string `json:"today_done"`
|
||||
@@ -87,7 +81,6 @@ type SaveInput struct {
|
||||
Submit bool `json:"submit"`
|
||||
}
|
||||
|
||||
// MineQuery 我的日报列表查询。
|
||||
type MineQuery struct {
|
||||
StartDate string
|
||||
EndDate string
|
||||
@@ -95,25 +88,21 @@ type MineQuery struct {
|
||||
PageSize int
|
||||
}
|
||||
|
||||
// MineSummary 我的日报页头统计。
|
||||
type MineSummary struct {
|
||||
MonthTotal int `json:"month_total"`
|
||||
MonthSubmitted int `json:"month_submitted"`
|
||||
TodayStatus int8 `json:"today_status"` // -1=今天未填写
|
||||
TodayStatus int8 `json:"today_status"`
|
||||
TodayReportID uint64 `json:"today_report_id"`
|
||||
WindowStart string `json:"window_start"`
|
||||
WindowEnd string `json:"window_end"`
|
||||
}
|
||||
|
||||
// MineResult 我的日报列表结果。
|
||||
type MineResult struct {
|
||||
List []ReportItem `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
Summary MineSummary `json:"summary"`
|
||||
}
|
||||
|
||||
// Save 新建或更新一条日报(同一人同一天唯一)。
|
||||
// 已提交的日报处于锁定状态,必须先撤销提交退回草稿才能修改。
|
||||
func Save(u *UserContext, in SaveInput) (*ReportItem, error) {
|
||||
date, err := ParseDate(in.Date)
|
||||
if err != nil {
|
||||
@@ -183,11 +172,9 @@ func Save(u *UserContext, in SaveInput) (*ReportItem, error) {
|
||||
return nil, findErr
|
||||
}
|
||||
|
||||
// 已提交的日报锁定:必须先撤销提交退回草稿,才能修改内容。
|
||||
if existing.Status == 1 {
|
||||
return nil, errBad("日报已提交并锁定,如需修改请先撤销提交")
|
||||
}
|
||||
// 撤销过提交的日报再次提交时,留下重新提交痕迹。
|
||||
resubmit := false
|
||||
if in.Submit {
|
||||
if existing.SubmitTime != nil {
|
||||
@@ -241,7 +228,6 @@ func Save(u *UserContext, in SaveInput) (*ReportItem, error) {
|
||||
return buildItem(&existing, count), nil
|
||||
}
|
||||
|
||||
// ListMine 我的日报分页列表 + 页头统计。
|
||||
func ListMine(u *UserContext, q MineQuery) (*MineResult, error) {
|
||||
if q.Page < 1 {
|
||||
q.Page = 1
|
||||
@@ -296,14 +282,12 @@ func ListMine(u *UserContext, q MineQuery) (*MineResult, error) {
|
||||
return &MineResult{List: list, Total: total, Summary: *summary}, nil
|
||||
}
|
||||
|
||||
// CalendarDay 我的日报日历热力图单日状态。
|
||||
type CalendarDay struct {
|
||||
Date string `json:"date"`
|
||||
Status int8 `json:"status"` // 0草稿 1已提交
|
||||
Status int8 `json:"status"`
|
||||
ID uint64 `json:"id"`
|
||||
}
|
||||
|
||||
// CalendarResult 近期热力图数据(默认近三个月)。
|
||||
type CalendarResult struct {
|
||||
StartDate string `json:"start_date"`
|
||||
EndDate string `json:"end_date"`
|
||||
@@ -312,8 +296,6 @@ type CalendarResult struct {
|
||||
Days []CalendarDay `json:"days"`
|
||||
}
|
||||
|
||||
// Calendar 返回最近 months 个月(含本月)本人日报的逐日状态,供热力图按月/周渲染。
|
||||
// months 越界时回落到 3 个月。
|
||||
func Calendar(u *UserContext, months int) (*CalendarResult, error) {
|
||||
if months < 1 || months > 12 {
|
||||
months = 3
|
||||
@@ -343,8 +325,6 @@ func Calendar(u *UserContext, months int) (*CalendarResult, error) {
|
||||
}
|
||||
for i := range rows {
|
||||
res.Days = append(res.Days, CalendarDay{
|
||||
// DATE 列在 parseTime=true 下会带上时间与时区,必须归一化为 YYYY-MM-DD,
|
||||
// 否则前端按日期匹配热力图格子时永远匹配不到。
|
||||
Date: dateOnly(rows[i].ReportDate),
|
||||
Status: rows[i].Status,
|
||||
ID: rows[i].ID,
|
||||
@@ -357,7 +337,6 @@ func Calendar(u *UserContext, months int) (*CalendarResult, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// mineSummary 本月提交统计与今天的状态。
|
||||
func mineSummary(u *UserContext) (*MineSummary, error) {
|
||||
now := time.Now()
|
||||
monthStart := now.Format("2006-01") + "-01"
|
||||
@@ -386,7 +365,6 @@ func mineSummary(u *UserContext) (*MineSummary, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// GetDetail 读取日报详情;无权限时返回 403。
|
||||
func GetDetail(u *UserContext, id uint64) (*Detail, error) {
|
||||
report, err := loadReport(u.Tid, id)
|
||||
if err != nil {
|
||||
@@ -407,15 +385,12 @@ func GetDetail(u *UserContext, id uint64) (*Detail, error) {
|
||||
author := report.UserID == u.UID
|
||||
canEdit := author && report.Status == 0 && InWindow(report.ReportDate)
|
||||
canWithdraw := author && report.Status == 1 && InWindow(report.ReportDate)
|
||||
// 删除仅限草稿:已提交日报需先撤销提交才能删除。
|
||||
canDelete := report.Status == 0 && (u.IsAdmin || (author && InWindow(report.ReportDate)))
|
||||
|
||||
// 修改痕迹只对作者本人与租户管理员可见。
|
||||
histories := make([]HistoryItem, 0)
|
||||
if author || u.IsAdmin {
|
||||
histories, err = loadHistories(u.Tid, report.ID)
|
||||
if err != nil {
|
||||
// 痕迹表缺失或查询异常时降级为空,避免详情整体 500(部署时需执行 create_oa_dailyreport_history.sql)。
|
||||
histories = make([]HistoryItem, 0)
|
||||
}
|
||||
}
|
||||
@@ -431,8 +406,6 @@ func GetDetail(u *UserContext, id uint64) (*Detail, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Withdraw 撤销提交:把已提交日报退回草稿,并把本次提交的内容快照写入修改痕迹。
|
||||
// 仅作者本人、且日报在补写窗口内时可操作;撤销后需修改并重新提交。
|
||||
func Withdraw(u *UserContext, id uint64) (*ReportItem, error) {
|
||||
report, err := loadReport(u.Tid, id)
|
||||
if err != nil {
|
||||
@@ -484,16 +457,11 @@ func Withdraw(u *UserContext, id uint64) (*ReportItem, error) {
|
||||
return buildItem(report, count), nil
|
||||
}
|
||||
|
||||
// Delete 软删除日报及其评论:作者限补写窗口内,管理员不受限。
|
||||
//
|
||||
// 日报的 is_deleted 写入记录 ID(而非 1),既标记删除,又让唯一键
|
||||
// (tid, user_id, report_date, is_deleted) 在「删除后同一天重新填写」时不冲突。
|
||||
func Delete(u *UserContext, id uint64) error {
|
||||
report, err := loadReport(u.Tid, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 已提交日报锁定:不允许直接删除,需先撤销提交退回草稿。
|
||||
if report.Status == 1 {
|
||||
return errBad("日报已提交并锁定,请先撤销提交后再删除")
|
||||
}
|
||||
@@ -525,7 +493,6 @@ func Delete(u *UserContext, id uint64) error {
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
// AddComment 对已提交日报发表评论或回复;replyToID=0 表示直接评论。
|
||||
func AddComment(u *UserContext, reportID uint64, content string, replyToID uint64) (*Comment, error) {
|
||||
content = strings.TrimSpace(content)
|
||||
if content == "" {
|
||||
@@ -573,7 +540,6 @@ func AddComment(u *UserContext, reportID uint64, content string, replyToID uint6
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
// DeleteComment 软删除评论:评论作者本人或管理员。
|
||||
func DeleteComment(u *UserContext, commentID uint64) error {
|
||||
var row models.OaDailyReportComment
|
||||
if err := models.Orm.QueryTable(new(models.OaDailyReportComment)).
|
||||
@@ -589,8 +555,6 @@ func DeleteComment(u *UserContext, commentID uint64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// ========================== 内部工具 ==========================
|
||||
|
||||
func loadReport(tid, id uint64) (*models.OaDailyReport, error) {
|
||||
var report models.OaDailyReport
|
||||
if err := models.Orm.QueryTable(new(models.OaDailyReport)).
|
||||
@@ -600,12 +564,10 @@ func loadReport(tid, id uint64) (*models.OaDailyReport, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
// 统一成 YYYY-MM-DD,保证 InWindow 与前端日期比较正确。
|
||||
report.ReportDate = dateOnly(report.ReportDate)
|
||||
return &report, nil
|
||||
}
|
||||
|
||||
// canViewReport 本人 / 管理员 / 作者所在部门的主管;草稿仅本人与管理员可见。
|
||||
func canViewReport(u *UserContext, r *models.OaDailyReport) bool {
|
||||
if r.UserID == u.UID || u.IsAdmin {
|
||||
return true
|
||||
@@ -648,7 +610,6 @@ func buildComment(u *UserContext, r *models.OaDailyReportComment) Comment {
|
||||
}
|
||||
}
|
||||
|
||||
// hasWithdrawHistory 判断一条日报是否被撤销过提交,用于识别“重新提交”。
|
||||
func hasWithdrawHistory(tid, reportID uint64) bool {
|
||||
n, err := models.Orm.QueryTable(new(models.OaDailyReportHistory)).
|
||||
Filter("tid", tid).Filter("report_id", reportID).Filter("action", 1).
|
||||
@@ -656,7 +617,6 @@ func hasWithdrawHistory(tid, reportID uint64) bool {
|
||||
return err == nil && n > 0
|
||||
}
|
||||
|
||||
// loadHistories 读取一条日报的全部修改痕迹,按写入顺序返回。
|
||||
func loadHistories(tid, reportID uint64) ([]HistoryItem, error) {
|
||||
var rows []models.OaDailyReportHistory
|
||||
if _, err := models.Orm.QueryTable(new(models.OaDailyReportHistory)).
|
||||
@@ -720,7 +680,6 @@ func formatTime(t *time.Time) string {
|
||||
return t.Format("2006-01-02 15:04")
|
||||
}
|
||||
|
||||
// normalizeAttachments 校验并规范化附件 JSON,最多 20 个。
|
||||
func normalizeAttachments(raw string) (string, []Attachment, error) {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" || raw == "null" {
|
||||
@@ -752,7 +711,6 @@ func optionalDate(v string) (string, error) {
|
||||
return ParseDate(v)
|
||||
}
|
||||
|
||||
// countWhere 依次应用列值条件后计数。
|
||||
func countWhere(qs orm.QuerySeter, kv ...string) int64 {
|
||||
for i := 0; i+1 < len(kv); i += 2 {
|
||||
qs = qs.Filter(kv[i], kv[i+1])
|
||||
@@ -766,7 +724,6 @@ func commentCount(tid, reportID uint64) int {
|
||||
return counts[reportID]
|
||||
}
|
||||
|
||||
// commentCounts 批量统计评论数,避免列表逐条查询。
|
||||
func commentCounts(tid uint64, ids []uint64) map[uint64]int {
|
||||
out := make(map[uint64]int, len(ids))
|
||||
if len(ids) == 0 {
|
||||
|
||||
Reference in new issue
Block a user