ken_nogi/NodeSrv/apps/org-master-sync/scripts/set-status-classx.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

65 lines
2.8 KiB
JavaScript
Raw 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.

"use strict";
/*
* 新規追加されたClassX状態、ChoicesText: "0,在籍中,..." / "1,退職済み,..." / "9,その他,...")へ、
* 以下のルールで値を一括設定する:
* ClassY=有 かつ ClassZ=有 → "0"(在籍中)
* ClassY=無 かつ ClassZ=有LINEWORKS在籍・プリザンター未作成 → "0"在籍中、2026-08-09追加
* ClassY=有 かつ ClassZ=無 かつ Class018="7"(退職済み組織) → "1"(退職済み)
* それ以外 → "9"(その他)
* 既定はドライラン(分類件数の表示のみ)。実際に送信するには --execute を付ける。
*
* 実行: node scripts/set-status-classx.js [--execute]
*/
const { getSiteItems, updateSiteItem } = require("../src/lib/pleasanterClient");
const BASE_URL = process.env.PLEASANTER_BASE_URL;
const API_KEY = process.env.PLEASANTER_API_KEY;
const SITE_ID = process.env.PLEASANTER_MASTER_SITE_ID;
const RETIRED_DEPT_ID = "7"; // DeptCode=999999退職済み組織に対応するDeptId
if (!BASE_URL || !API_KEY || !SITE_ID) {
console.error("PLEASANTER_BASE_URL / PLEASANTER_API_KEY / PLEASANTER_MASTER_SITE_ID が未設定");
process.exit(1);
}
function classifyStatus(item) {
if (item.ClassY === "有" && item.ClassZ === "有") return "0";
if (item.ClassY === "無" && item.ClassZ === "有") return "0"; // LINEWORKS在籍・プリザンター未作成も在籍中扱い2026-08-09
if (item.ClassY === "有" && item.ClassZ === "無" && item.Class018 === RETIRED_DEPT_ID) return "1";
return "9";
}
async function main() {
const execute = process.argv.includes("--execute");
const config = { baseUrl: BASE_URL, apiKey: API_KEY, siteId: SITE_ID };
const items = await getSiteItems(config);
const targets = items
.map((i) => ({ item: i, newStatus: classifyStatus(i) }))
.filter(({ item, newStatus }) => item.ClassX !== newStatus);
const counts = { "0": 0, "1": 0, "9": 0 };
for (const { newStatus } of targets) counts[newStatus]++;
console.log(`更新対象件数: ${targets.length} / 総件数: ${items.length}`);
console.log(` 在籍中(0): ${counts["0"]}`);
console.log(` 退職済み(1): ${counts["1"]}`);
console.log(` その他(9): ${counts["9"]}`);
if (!execute) {
console.log("\n[ドライラン] --execute を付けずに実行したため送信していません。");
return;
}
let updated = 0;
for (const { item, newStatus } of targets) {
await updateSiteItem({ baseUrl: BASE_URL, apiKey: API_KEY, itemId: item.ResultId, fields: { ClassX: newStatus } });
updated++;
}
console.log(`\n[OK] ${updated}件のClassXを更新しました。`);
}
main().catch((e) => {
console.error(e);
process.exit(1);
});