feat(project): 회의록 주차를 열면 매출 자료를 쇼핑몰에서 한 번 더 받아 숫자 갱신

- 실적 모듈 매출 업데이트(POST /performance/api/sync, background)를 지난주 월요일 ~ 이번 주 오늘 기간으로 실행,
  진행 상황(쇼핑몰 n/m·받은 자료)을 상태 줄에 표시
- 끝나면 화면을 서버에서 다시 받아 숫자 칸만 교체(머리 카드·자동 결과·달성률·이번주 실적), 입력 중인 칸은 그대로
- 같은 주는 10분에 한 번만 자동(새로고침마다 쇼핑몰 API 를 부르지 않게), [매출 갱신] 버튼은 언제나,
  다른 업데이트가 돌면 그 작업을 기다림, 실적 권한 없음·실패 쇼핑몰 안내
- project.css/js 캐시 버전 20261001f, 문서 갱신

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 12:04:14 +09:00
parent 45a671940b
commit be298777af
11 changed files with 131 additions and 16 deletions
+13
View File
@@ -2185,6 +2185,19 @@ html.pj-goal-selecting, html.pj-goal-selecting * { user-select: none !important;
.pj-meet-week.is-on { border-color: var(--pj-accent); box-shadow: inset 0 0 0 1px var(--pj-accent); background: var(--pj-accent-tint); }
.pj-meet-dot { position: absolute; top: 9px; right: 9px; width: 7px; height: 7px; border-radius: 50%; background: #34a853; }
/* 매출 자료 갱신 상태 줄 */
.pj-meet-sync {
display: flex; align-items: center; gap: 8px; margin: -4px 0 10px; padding: 6px 10px; border-radius: 8px;
background: #f6f7f9; color: var(--pj-ink-soft); font-size: 12.5px;
}
.pj-meet-sync .material-symbols-outlined { font-size: 17px; }
.pj-meet-sync .pj-btn { margin-left: auto; }
.pj-meet-sync.is-running { background: #eef4ff; color: #1d4ed8; }
.pj-meet-sync.is-running .material-symbols-outlined { animation: pj-meet-spin 1s linear infinite; }
.pj-meet-sync.is-done { background: #eefaf2; color: #1f7a44; }
.pj-meet-sync.is-warn { background: #fff4ec; color: #b45309; }
@keyframes pj-meet-spin { to { transform: rotate(360deg); } }
@media print { .pj-meet-sync { display: none !important; } }
.pj-meet-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
.pj-meet-kpis.is-week { grid-template-columns: repeat(5, minmax(0, 1fr)); margin-bottom: 12px; }
.pj-meet-kpi {
+89
View File
@@ -8635,6 +8635,94 @@
}
}
// ── 회의록 매출 자료 갱신 — 주차를 열면 실적 모듈 [매출 업데이트](지난주 월요일 ~ 이번 주 오늘, 백그라운드)를 한 번 더
// 돌리고, 끝나면 이 화면을 서버에서 다시 그려 숫자 칸만 바꿔 끼운다(입력 중인 칸·저장 안 된 글은 건드리지 않는다).
// 같은 주는 10분에 한 번만 자동(새로고침마다 쇼핑몰 API 를 부르지 않게), [매출 갱신] 버튼은 언제나.
// 실적 권한이 없거나 이미 다른 업데이트가 돌면 그 상태를 보여 준다(다른 사람 업데이트면 그게 끝나길 기다려 다시 그림).
function initMeetingSync(pane) {
const box = el("pj-meet-sync");
if (!box) return;
const text = box.querySelector(".pj-meet-sync-text");
const btn = el("pj-meet-sync-btn");
const KEY = "pj_meet_sync:" + pane.dataset.week;
const THROTTLE_MS = 10 * 60 * 1000;
let running = false;
function say(msg, cls) {
text.textContent = msg;
box.classList.remove("is-running", "is-done", "is-warn");
if (cls) box.classList.add(cls);
}
function hhmm(d) { return String(d.getHours()).padStart(2, "0") + ":" + String(d.getMinutes()).padStart(2, "0"); }
// 서버가 새로 그린 화면에서 숫자 칸만 옮겨 온다(입력칸이 있는 카드·칸은 안내 문구만)
async function repaint() {
const res = await fetch(location.href, { credentials: "same-origin" });
if (!res.ok) throw new Error("화면을 다시 읽지 못했습니다(" + res.status + ")");
const doc = new DOMParser().parseFromString(await res.text(), "text/html");
const swap = function (sel) {
const now = document.querySelectorAll(sel), fresh = doc.querySelectorAll(sel);
if (now.length !== fresh.length) return false;
now.forEach(function (n, i) {
if (n.querySelector("input, textarea, select")) {
const a = n.querySelector(".pj-meet-sub-slot"), b = fresh[i].querySelector(".pj-meet-sub-slot");
if (a && b) a.innerHTML = b.innerHTML;
return;
}
n.innerHTML = fresh[i].innerHTML;
});
return true;
};
swap(".pj-meet-kpi");
document.querySelectorAll("#pj-meet-table tr[data-item]").forEach(function (tr) {
const ftr = doc.querySelector('#pj-meet-table tr[data-item="' + tr.dataset.item + '"]');
if (!ftr) return;
[".pj-meet-c-result", "[data-rate]", ".pj-meet-week-slot"].forEach(function (sel) {
const a = tr.querySelector(sel), b = ftr.querySelector(sel);
if (!a || !b) return;
if (a.querySelector("input:focus")) return; // 결과를 입력하는 중
if (a.querySelector("input") && b.querySelector("input")) return; // 직접 입력 칸은 그대로
a.innerHTML = b.innerHTML;
});
});
}
async function run(force) {
if (running) return;
if (!force) {
try {
const last = Number(sessionStorage.getItem(KEY) || 0);
if (Date.now() - last < THROTTLE_MS) { say("매출 자료 갱신됨 " + hhmm(new Date(last)) + " (10분 안에는 다시 받지 않음)", "is-done"); return; }
} catch (_) {}
}
running = true;
btn.disabled = true;
say("쇼핑몰에서 매출 자료를 다시 받는 중…", "is-running");
try {
let r = await api("POST", "/performance/api/sync", { from: box.dataset.from, to: box.dataset.to, background: true });
const joined = r.joined;
let job = r.job;
while (!job.finished) {
const o = job.overall || {};
say((joined ? "다른 매출 업데이트 진행 중 — " : "매출 자료 다시 받는 중 — ") + (o.finished || 0) + "/" + (o.shops || 0) +
" 쇼핑몰" + (o.items ? " · 받은 자료 " + Number(o.items).toLocaleString("ko-KR") + "건" : ""), "is-running");
await new Promise(function (ok) { setTimeout(ok, 1000); });
job = (await api("GET", "/performance/api/sync/jobs/" + encodeURIComponent(job.id))).job;
}
await repaint();
try { sessionStorage.setItem(KEY, String(Date.now())); } catch (_) {}
const bad = (job.shops || []).filter(function (s) { return s.state === "error"; })
.map(function (s) { return s.name + (s.label ? "(" + s.label + ")" : ""); });
say("매출 자료 갱신 " + hhmm(new Date()) + " · " + Number((job.overall || {}).upserted || 0).toLocaleString("ko-KR") + "건 반영" +
(bad.length ? " · 실패: " + bad.join(", ") : ""), bad.length ? "is-warn" : "is-done");
} catch (e) {
say(e.status === 403 ? "실적 권한이 없어 저장된 실적으로 보여 줍니다" : "매출 갱신 실패: " + e.message, "is-warn");
} finally {
running = false;
btn.disabled = false;
}
}
btn.addEventListener("click", function () { run(true); });
run(false);
}
// ── 주간 회의록(/project/goals/{연도}/meetings/{월}?week=) — 관리자만 입력, 칸마다 바로 저장.
// · 글(이번주 할 일·메모): 0.8초 멈춤·칸 떠남·페이지 떠남에 저장. 금액·참석자: 칸 떠남·Enter 에 저장.
// · 지난주 결과·평가는 지난 회의록의 같은 줄(tr data-prev)에 저장하고 달성률을 바로 다시 그린다.
@@ -8665,6 +8753,7 @@
location.reload();
} catch (e) { create.disabled = false; showToast("만들기 실패: " + e.message, "error"); }
});
initMeetingSync(pane); // 보기만 하는 사람도(실적 권한이 있으면) 매출 자료 갱신
if (!isAdmin) return;
const table = el("pj-meet-table");