1) 管理员颜色 - users 表新增 color;设置 → 管理员 每行一个颜色选择器,保存即生效 - 新建管理员自动从 8 色调色板分配,尽量不重复;支持 #RRGGBB 校验,非法值拒绝 2) 客户归属打手 - customers 表新增 assignee_id(可空,指向 users) - 新建/编辑客户时可选择「归属打手」,客户详情页也能直接改派 - 语义:一个客户一个打手,该客户之后的所有单子都归这个打手 - 停用的账户不出现在打手候选里;未指派显示灰色「未指派」 3) 日历 - 每个日期格左侧新增 5px 竖条,按当天涉及的打手颜色等分显示(几种颜色几段) - 竖条按“当天全部任务”去重计算,不受格内色签 3 条上限影响 - 未指派的任务用中性灰段落 4) 待办与大屏 - 「当日待完成」每条任务左侧 3px 打手色条 + 圆点色标 + 打手名字,未指派灰字 - 大屏:今日待打列表、热力格竖条、悬停浮层(新增 who / who_color 字段)统一使用同一套颜色 - 加急样式改为红底,避免与打手色左边框冲突 数据库兼容性: - 只做加法:users.color、customers.assignee_id 两列;老库打开时自动 ALTER,可重复迁移 - 原有表结构、字段、页面接口不变;未指派的存量数据照常工作 测试: - 新增单测:颜色自动分配/规范化/非法值拒绝、客户指派与取消、订阅联表带出打手、停用账户不进候选 - 旧库迁移测试扩展:老 users / customers 表自动补列并可写 - 功能验证 16 项(颜色保存、指派、详情展示、日历多色竖条分段、大屏列表与浮层接口)全部通过 - 原有 119 项验收回归全绿;go vet / go test ./... 通过;版本号 1.3.0
282 lines
7.0 KiB
Go
282 lines
7.0 KiB
Go
package web
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"daili/internal/domain"
|
|
"daili/internal/store"
|
|
)
|
|
|
|
type screenDay struct {
|
|
Date string
|
|
Day int
|
|
InMonth bool
|
|
IsToday bool
|
|
IsPast bool
|
|
Count int
|
|
Urgent int
|
|
Heat int
|
|
// Strip 打手色竖条(去重)
|
|
Strip []string
|
|
}
|
|
|
|
type screenTask struct {
|
|
TaskRow
|
|
}
|
|
|
|
type screenData struct {
|
|
Stats *store.Stats
|
|
MonthTitle string
|
|
Year, Month int
|
|
Weeks [][]screenDay
|
|
Weekdays []string
|
|
Top []SubView
|
|
DueToday []SubView
|
|
TodayList []screenTask
|
|
Recent []store.Adjustment
|
|
TodayTasks int
|
|
TodayDone int
|
|
TodayUrgent int
|
|
Refresh int
|
|
Version string
|
|
|
|
HeatMode string // task = 每日待完成;due = 到期
|
|
HeatTotal int
|
|
Tabs []PkgTab
|
|
PkgID int64
|
|
HasTabs bool
|
|
Theme string
|
|
}
|
|
|
|
// screenCalSubs 读取大屏日历区间内的订阅,并带上暂停/打卡/加急。
|
|
func (s *Server) screenCalSubs(from, to string, pkgID int64) ([]calSub, map[int64]map[string]store.Checkin, map[int64]map[string]bool, error) {
|
|
subs, pauses, checkins, urgent, err := s.loadCalendarSubs(from, to, pkgID)
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
today := domain.Today()
|
|
warn := s.warnDays()
|
|
list := make([]calSub, 0, len(subs))
|
|
for _, sub := range subs {
|
|
cs := calSub{sub: sub, pauses: pauses[sub.ID], eval: sub.Eval(today, warn)}
|
|
if sub.EndDate != "" {
|
|
cs.hasEnd = true
|
|
cs.end = domain.ParseDateOr(sub.EndDate, today)
|
|
}
|
|
list = append(list, cs)
|
|
}
|
|
return list, checkins, urgent, nil
|
|
}
|
|
|
|
func (s *Server) handleScreen(w http.ResponseWriter, r *http.Request) {
|
|
today := domain.Today()
|
|
warn := s.warnDays()
|
|
pkgID := int64(s.queryInt(r, "pkg", 0))
|
|
heatMode := r.URL.Query().Get("heat")
|
|
if heatMode != "due" {
|
|
heatMode = "task"
|
|
}
|
|
|
|
stats, err := s.db.ScreenStats(today, warn)
|
|
if err != nil {
|
|
http.Error(w, "读取大屏数据失败", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
data := &screenData{
|
|
Stats: stats,
|
|
MonthTitle: fmt.Sprintf("%d 年 %d 月", today.Year(), int(today.Month())),
|
|
Year: today.Year(),
|
|
Month: int(today.Month()),
|
|
Weekdays: []string{"一", "二", "三", "四", "五", "六", "日"},
|
|
Top: subViews(stats.Top, today, warn),
|
|
Refresh: s.screenRefresh(),
|
|
Version: s.cfg.Version,
|
|
HeatMode: heatMode,
|
|
PkgID: pkgID,
|
|
}
|
|
|
|
// 今日到期(可按套餐过滤)
|
|
dueToday := []store.Subscription{}
|
|
for _, sub := range stats.DueTodaySubs {
|
|
if pkgID > 0 && sub.PackageID != pkgID {
|
|
continue
|
|
}
|
|
dueToday = append(dueToday, sub)
|
|
}
|
|
data.DueToday = subViews(dueToday, today, warn)
|
|
|
|
// 本月热力:默认统计“每日待完成的单子”,可切换到“到期”
|
|
monthStart := domain.MonthStart(today.Year(), today.Month())
|
|
monthEnd := domain.MonthEnd(today.Year(), today.Month())
|
|
gridStart := domain.AddDays(monthStart, -domain.WeekdayIndex(monthStart))
|
|
weeks := (domain.WeekdayIndex(monthStart) + monthEnd.Day() + 6) / 7
|
|
gridEnd := domain.AddDays(gridStart, weeks*7-1)
|
|
|
|
list, checkins, urgent, err := s.screenCalSubs(domain.Date(gridStart), domain.Date(gridEnd), pkgID)
|
|
if err != nil {
|
|
http.Error(w, "读取大屏日历失败", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
for wi := 0; wi < weeks; wi++ {
|
|
week := make([]screenDay, 0, 7)
|
|
for di := 0; di < 7; di++ {
|
|
d := domain.AddDays(gridStart, wi*7+di)
|
|
ds := domain.Date(d)
|
|
count, urgentN := 0, 0
|
|
strip := []string{}
|
|
seenColor := map[string]bool{}
|
|
for _, cs := range list {
|
|
if heatMode == "due" {
|
|
if cs.sub.EndDate == ds {
|
|
count++
|
|
}
|
|
continue
|
|
}
|
|
if !cs.covers(ds) {
|
|
continue
|
|
}
|
|
ci, has := checkins[cs.sub.ID][ds]
|
|
if has && (ci.Status == "done" || ci.Status == "skipped") {
|
|
continue // “待完成”只统计还没处理的
|
|
}
|
|
count++
|
|
if urgent[cs.sub.ID][ds] {
|
|
urgentN++
|
|
}
|
|
color := cs.sub.AssigneeColor
|
|
if color == "" {
|
|
color = "#8A8F98"
|
|
}
|
|
if !seenColor[color] {
|
|
seenColor[color] = true
|
|
strip = append(strip, color)
|
|
}
|
|
}
|
|
if d.Month() == today.Month() {
|
|
data.HeatTotal += count
|
|
}
|
|
week = append(week, screenDay{
|
|
Date: ds,
|
|
Day: d.Day(),
|
|
InMonth: d.Month() == today.Month(),
|
|
IsToday: ds == domain.Date(today),
|
|
IsPast: d.Before(today),
|
|
Count: count,
|
|
Urgent: urgentN,
|
|
Heat: heatLevel(count),
|
|
Strip: strip,
|
|
})
|
|
}
|
|
data.Weeks = append(data.Weeks, week)
|
|
}
|
|
|
|
// 今日待打(加急置顶)
|
|
rows, err := s.pendingTasks(domain.Date(today), nil, pkgID)
|
|
if err == nil {
|
|
for _, row := range rows {
|
|
if row.Done || row.Skipped {
|
|
continue
|
|
}
|
|
data.TodayList = append(data.TodayList, screenTask{TaskRow: row})
|
|
if row.Urgent {
|
|
data.TodayUrgent++
|
|
}
|
|
}
|
|
}
|
|
data.TodayTasks = len(data.TodayList)
|
|
for _, row := range rows {
|
|
if row.Done {
|
|
data.TodayDone++
|
|
}
|
|
}
|
|
|
|
// 最近追加(底部细条)
|
|
if adj, err := s.db.RecentAdjustments(6); err == nil {
|
|
data.Recent = adj
|
|
}
|
|
|
|
// 套餐标签
|
|
pkgs, _ := s.db.ListPackages(true)
|
|
for _, p := range pkgs {
|
|
if p.CalendarSeparate && !p.Archived {
|
|
if !data.HasTabs {
|
|
data.HasTabs = true
|
|
data.Tabs = append(data.Tabs, PkgTab{ID: 0, Name: "全部", Color: "#8A8F98"})
|
|
}
|
|
data.Tabs = append(data.Tabs, PkgTab{ID: p.ID, Name: p.Name, Color: p.Color})
|
|
}
|
|
}
|
|
|
|
data.Theme = themeFromRequest(r)
|
|
p := s.newPage(r, "大屏", "screen")
|
|
p.Theme = data.Theme
|
|
p.D = data
|
|
s.render(w, r, "screen", p)
|
|
}
|
|
|
|
// handleScreenDay 返回某天的待办明细,供大屏悬停浮层使用。
|
|
func (s *Server) handleScreenDay(w http.ResponseWriter, r *http.Request) {
|
|
date := r.URL.Query().Get("date")
|
|
if _, err := domain.ParseDate(date); err != nil {
|
|
http.Error(w, "日期不正确", http.StatusBadRequest)
|
|
return
|
|
}
|
|
pkgID := int64(s.queryInt(r, "pkg", 0))
|
|
rows, err := s.pendingTasks(date, nil, pkgID)
|
|
if err != nil {
|
|
http.Error(w, "读取失败", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
type item struct {
|
|
Tail string `json:"tail"`
|
|
Name string `json:"name"`
|
|
Pkg string `json:"pkg"`
|
|
Color string `json:"color"`
|
|
Remain string `json:"remain"`
|
|
Urgent bool `json:"urgent"`
|
|
Done bool `json:"done"`
|
|
Who string `json:"who"`
|
|
WhoCol string `json:"who_color"`
|
|
}
|
|
out := struct {
|
|
Date string `json:"date"`
|
|
Total int `json:"total"`
|
|
Done int `json:"done"`
|
|
Urgent int `json:"urgent"`
|
|
More int `json:"more"`
|
|
Items []item `json:"items"`
|
|
}{Date: date}
|
|
|
|
const limit = 60
|
|
for _, row := range rows {
|
|
out.Total++
|
|
if row.Done || row.Skipped {
|
|
out.Done++
|
|
}
|
|
if row.Urgent {
|
|
out.Urgent++
|
|
}
|
|
if len(out.Items) >= limit {
|
|
out.More++
|
|
continue
|
|
}
|
|
out.Items = append(out.Items, item{
|
|
Tail: row.CustomerTail,
|
|
Name: row.CustomerName,
|
|
Pkg: row.PackageName,
|
|
Color: row.PackageColor,
|
|
Remain: row.RemainText,
|
|
Urgent: row.Urgent,
|
|
Done: row.Done || row.Skipped,
|
|
Who: row.AssigneeLabel(),
|
|
WhoCol: row.AssigneeHex(),
|
|
})
|
|
}
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.Header().Set("Cache-Control", "no-store")
|
|
_ = json.NewEncoder(w).Encode(out)
|
|
}
|