ken_nogi/Pleasanter/.claude/js/site-scripts/新・着工要因システム/apply-jisseki-label-fix-496626.js
Kenichiro NOGI ce58cb4be4 初回コミット: dev配下(NodeSrv/Pleasanter等)をGitea管理下に統合
GitHub(nextgroup2706/ken_nogi)は今後使わず自社Gitea運用に切替え。
NodeSrvは旧リポジトリの履歴を破棄しファイルのみ統合(Dokploy用サービスアカウントは
別途mygit-admin/NodeSrv.gitに履歴あり)。notepmエクスポート(12GB)とPleasanter
インストーラzip(208MB)はサイズが大きいため.gitignoreで除外。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-04 15:37:06 +09:00

150 lines
6.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* apply-jisseki-label-fix-496626.js
* ------------------------------------------------------------
* site-496626のColumns定義のうち、Date111〜Date148実績日、37項目
* LabelTextが「実行」のままになっているものだけを「実績」に書き換える専用スクリプト。
*
* 現在のサイト全体getsiteを取得し、対象37項目のLabelTextだけを書き換えて
* updatesite全体更新で送信する。Columns内の対象37項目以外のフィールド
* ColumnName/GridLabelText/Type/各種設定等、GridColumns、他のSiteSettings・
* Permissions・Title等は一切変更しない。
*
* 使い方:
* node apply-jisseki-label-fix-496626.js … 差分表示のみ(送信なし)
* node apply-jisseki-label-fix-496626.js --execute … 上記に加えて実際に送信する
* ------------------------------------------------------------
*/
const fs = require("fs");
const path = require("path");
const { findSiteDir, newModifyDir, latestModifyDir } = require("../../site-paths");
const { REPO_ROOT, loadServerConfig } = require("../../resolve-project");
const PROJECT_NAME = "新・着工要因システム";
const ENV = "production";
const SITE_ID = 496626;
const baseDir = path.join(REPO_ROOT, PROJECT_NAME);
const configsDir = path.join(baseDir, "configs", ENV);
const execute = process.argv.includes("--execute");
// 対象: Date111〜Date148
const TARGET_COLUMNS = new Set(
Array.from({ length: 38 }, (_, i) => i + 111).map((n) => `Date${n}`)
);
const OLD_LABEL = "実行";
const NEW_LABEL = "実績";
function loadJson(p) {
return JSON.parse(fs.readFileSync(p, "utf-8"));
}
function maskApiKey(key) {
if (!key) return key;
return key.length > 8 ? key.slice(0, 4) + "****" + key.slice(-4) : "****";
}
function timestamp() {
return new Date().toISOString().replace(/[:.]/g, "-");
}
const config = loadServerConfig(ENV);
const siteDir = findSiteDir(configsDir, SITE_ID);
(async () => {
console.log("[INFO] 現在のサイト情報を取得しています...");
const getUrl = `${config.BaseUrl.replace(/\/+$/, "")}/api/items/${SITE_ID}/getsite`;
const getRes = await fetch(getUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ ApiVersion: config.ApiVersion || "1.1", ApiKey: config.ApiKey }),
});
const getJson = await getRes.json();
if (getJson.StatusCode !== 200) {
console.error("[エラー] getsiteに失敗しました:", JSON.stringify(getJson).slice(0, 500));
process.exit(1);
}
const data = getJson.Response.Data;
console.log(`[OK] 取得しました現在のVer: ${data.Ver}, UpdatedTime: ${data.UpdatedTime}`);
const siteSettings = JSON.parse(JSON.stringify(data.SiteSettings));
console.log("========================================");
console.log(` Columns LabelText「実行」→「実績」書き換えupdatesite全体更新${execute ? "(実行)" : "(プレビューのみ)"}`);
console.log("========================================");
const changed = [];
const alreadyOk = [];
const missing = [];
TARGET_COLUMNS.forEach((columnName) => {
const column = siteSettings.Columns.find((c) => c.ColumnName === columnName);
if (!column) {
missing.push(columnName);
return;
}
if (column.LabelText === OLD_LABEL) {
column.LabelText = NEW_LABEL;
changed.push(`${columnName} (${column.GridLabelText || ""})`);
} else if (column.LabelText === NEW_LABEL) {
alreadyOk.push(columnName);
} else {
console.log(` [注意] ${columnName} のLabelTextは想定外の値です: "${column.LabelText}"(変更しません)`);
}
});
console.log(`変更対象: ${changed.length}`);
changed.forEach((c) => console.log(` ${c}: 実行 -> 実績`));
if (alreadyOk.length > 0) {
console.log(`既に「実績」: ${alreadyOk.length}`);
}
if (missing.length > 0) {
console.log(`[警告] Columnsに見つからなかった項目: ${missing.join(", ")}`);
}
console.log("他のSiteSettingsColumns内の対象外フィールド・GridColumns・Scripts/Styles/ServerScripts等・Permissions・Title等は一切変更しません。");
if (changed.length === 0) {
console.log("\n変更対象がないため、送信を行いません。");
process.exit(0);
}
const body = {
ApiVersion: config.ApiVersion || "1.1",
ApiKey: config.ApiKey,
SiteId: SITE_ID,
Title: data.Title,
ReferenceType: data.ReferenceType,
ParentId: data.ParentId,
InheritPermission: data.InheritPermission,
Permissions: data.Permissions,
SiteSettings: siteSettings,
};
const modifyDir = latestModifyDir(siteDir) || newModifyDir(siteDir, "jisseki-labeltext-fix");
const ts = timestamp();
const maskedBody = { ...body, ApiKey: maskApiKey(body.ApiKey) };
const previewPath = path.join(modifyDir, `site-${SITE_ID}_labeltext_update_preview_${ts}.json`);
fs.writeFileSync(previewPath, JSON.stringify(maskedBody, null, 2), "utf-8");
console.log(`\n[OK] 送信予定内容を保存しました: ${previewPath}`);
if (!execute) {
console.log("\n[注意] --execute が指定されていないため、送信は行っていません。");
console.log("内容を確認の上、問題なければ次を実行してください: node apply-jisseki-label-fix-496626.js --execute");
process.exit(0);
}
console.log("\n実際に送信しますupdatesite...");
const url = `${config.BaseUrl.replace(/\/+$/, "")}/api/items/${SITE_ID}/updatesite`;
const res = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
const text = await res.text();
const resultOutPath = path.join(modifyDir, `site-${SITE_ID}_labeltext_update_result_${ts}.json`);
fs.writeFileSync(resultOutPath, text, "utf-8");
console.log(`HTTP ${res.status} ${res.statusText}`);
console.log(`[OK] 応答を保存しました: ${resultOutPath}`);
console.log(text);
})();