n8nに構築済みのHC-SUB/HC-WP/HC-WAワークフロー設計・実装計画・エクスポートJSONを Pleasanter/健康診断管理/docs/n8n/に集約管理。508971/513156のColumns/Styles/Summaries 反映用ワンショットスクリプトも合わせて追加。worktree-healthcheck-survey-botブランチを mainへfast-forward mergeし、.claude/worktrees/はgit管理対象外に追加。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
129 lines
5.5 KiB
JavaScript
129 lines
5.5 KiB
JavaScript
// 健康診断管理 SiteId 508971(社員別健康診断管理): 513156(実施年度-集計)側で
|
|
// NumA~H→Num031~038へ置き換えた後の設定(LabelText/Unit/TextAlign/NoWrap等)をそのまま複製し、
|
|
// 508971のColumnsへ新規追加するワンショットスクリプト。EditorColumnHash._Tab-2(カウンタータブ)には
|
|
// 画面上で既にNum031~038が配置済み(Columns定義のみ未設定)のため、EditorColumnHashは変更しない。
|
|
// 508971の既存Num項目(NumA=年齢, Num001~003, Num061~091)には一切触れない。
|
|
// updatesite(Mode:full)を使う。--execute指定時のみ実際に送信、指定なければプレビューのみ出力。
|
|
"use strict";
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { findSiteDir, newModifyDir } = require("../../site-paths.js");
|
|
|
|
const PROJECT_NAME = "健康診断管理";
|
|
const ENV = "production";
|
|
const SRC_SITE_ID = 513156;
|
|
const DST_SITE_ID = 508971;
|
|
const DST_SITE_NAME = "社員別健康診断管理";
|
|
const REQUEST_LABEL = "apply-num031-038-columns";
|
|
|
|
const NUM_COLUMN_NAMES = ["Num031", "Num032", "Num033", "Num034", "Num035", "Num036", "Num037", "Num038"];
|
|
|
|
const REPO_ROOT = path.join(__dirname, "..", "..", "..", "..");
|
|
const PROJECT_ROOT = path.join(REPO_ROOT, PROJECT_NAME);
|
|
const CONFIGS_DIR = path.join(PROJECT_ROOT, "configs", ENV);
|
|
|
|
function loadServerConfig() {
|
|
const configPath = path.join(REPO_ROOT, `config_${ENV}.json`);
|
|
const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
if (!config.BaseUrl || !config.ApiKey) {
|
|
console.error(`[エラー] ${configPath} に BaseUrl / ApiKey を設定してください。`);
|
|
process.exit(1);
|
|
}
|
|
return config;
|
|
}
|
|
|
|
function loadLatest(siteId) {
|
|
const siteDir = findSiteDir(CONFIGS_DIR, siteId);
|
|
if (!siteDir) {
|
|
console.error(`[エラー] configs/${ENV}/site-${siteId}_* が見つかりません。先にget-site-config.jsを実行してください。`);
|
|
process.exit(1);
|
|
}
|
|
const p = path.join(siteDir, "sitesettings", `site-${siteId}_latest.json`);
|
|
const raw = JSON.parse(fs.readFileSync(p, "utf-8"));
|
|
return { current: raw.Response.Data, siteDir, rawText: fs.readFileSync(p, "utf-8") };
|
|
}
|
|
|
|
function buildDesiredSiteSettings(srcCurrent, dstCurrent) {
|
|
const settings = JSON.parse(JSON.stringify(dstCurrent.SiteSettings));
|
|
|
|
const tab2 = settings.EditorColumnHash["_Tab-2"] || [];
|
|
const addedColumns = [];
|
|
for (const name of NUM_COLUMN_NAMES) {
|
|
if (settings.Columns.some((c) => c.ColumnName === name)) {
|
|
console.error(`[エラー] 移行先(508971)Columns内に${name}が既に存在します(重複防止のため中断)。`);
|
|
process.exit(1);
|
|
}
|
|
if (!tab2.includes(name)) {
|
|
console.error(`[エラー] EditorColumnHash._Tab-2内に${name}が見つかりません。画面上の配置状況を確認してください。`);
|
|
process.exit(1);
|
|
}
|
|
const src = srcCurrent.SiteSettings.Columns.find((c) => c.ColumnName === name);
|
|
if (!src) {
|
|
console.error(`[エラー] 移行元(513156)Columns内に${name}が見つかりません。`);
|
|
process.exit(1);
|
|
}
|
|
const col = JSON.parse(JSON.stringify(src));
|
|
settings.Columns.push(col);
|
|
addedColumns.push(col);
|
|
}
|
|
|
|
// Links省略厳禁(全置換のため既存値をそのまま含める)
|
|
settings.Links = dstCurrent.SiteSettings.Links || [];
|
|
|
|
return { settings, addedColumns };
|
|
}
|
|
|
|
function buildUpdateBody(apiKey, current, desiredSettings) {
|
|
return {
|
|
ApiVersion: "1.1",
|
|
ApiKey: apiKey,
|
|
SiteId: DST_SITE_ID,
|
|
Title: current.Title,
|
|
ReferenceType: current.ReferenceType,
|
|
ParentId: current.ParentId,
|
|
InheritPermission: current.InheritPermission,
|
|
SiteSettings: desiredSettings,
|
|
};
|
|
}
|
|
|
|
const execute = process.argv.includes("--execute");
|
|
const server = loadServerConfig();
|
|
|
|
(async () => {
|
|
const { current: srcCurrent } = loadLatest(SRC_SITE_ID);
|
|
const { current: dstCurrent, siteDir: dstSiteDir, rawText: dstRawText } = loadLatest(DST_SITE_ID);
|
|
|
|
const { settings: desiredSettings, addedColumns } = buildDesiredSiteSettings(srcCurrent, dstCurrent);
|
|
const body = buildUpdateBody(server.ApiKey, dstCurrent, desiredSettings);
|
|
|
|
const modifyDir = newModifyDir(dstSiteDir, REQUEST_LABEL);
|
|
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
|
|
fs.writeFileSync(path.join(modifyDir, `before_site-${DST_SITE_ID}_latest.json`), dstRawText, "utf-8");
|
|
const updatedPath = path.join(modifyDir, `site-${DST_SITE_ID}_updated_${timestamp}.json`);
|
|
fs.writeFileSync(updatedPath, JSON.stringify(body, null, 2), "utf-8");
|
|
|
|
console.log(`\n==== SiteId ${DST_SITE_ID} (${DST_SITE_NAME}) ====`);
|
|
console.log("追加するColumns(513156から複製):");
|
|
for (const c of addedColumns) console.log(` - ${JSON.stringify(c)}`);
|
|
console.log(`\nColumns件数: 変更前${dstCurrent.SiteSettings.Columns.length} → 変更後${desiredSettings.Columns.length}`);
|
|
console.log(`プレビュー保存先: ${updatedPath}`);
|
|
|
|
if (!execute) {
|
|
console.log("\n(--execute 未指定のためプレビューのみ。送信していません)");
|
|
return;
|
|
}
|
|
|
|
const url = `${server.BaseUrl}api/items/${DST_SITE_ID}/updatesite`;
|
|
console.log(`送信先: ${url}`);
|
|
const res = await fetch(url, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(body),
|
|
});
|
|
const json = await res.json();
|
|
console.log(`[結果] HTTP ${res.status}:`, JSON.stringify(json));
|
|
const resultPath = path.join(modifyDir, `site-${DST_SITE_ID}_result_${timestamp}.json`);
|
|
fs.writeFileSync(resultPath, JSON.stringify(json, null, 2), "utf-8");
|
|
})();
|