| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- /**
- * 确保生产 DMS 有 shba_user 栏目(系统账号:职务 + 部门)。
- * 凭据默认与 src/api/dmsAuth.ts 相同,不要打印密码。栏目已存在则只打印状态。
- */
- import { DMS_CLIENT_ID, DMS_GATEWAY, DMS_PASSWORD, DMS_USER } from './dms-cred.mjs'
- const gateway = DMS_GATEWAY
- const user = DMS_USER
- const password = DMS_PASSWORD
- const clientId = DMS_CLIENT_ID
- async function call(urlPath, fields = {}, method = 'POST', token = '') {
- const body = new URLSearchParams()
- for (const [k, v] of Object.entries(fields)) body.set(k, String(v))
- const headers = { 'Content-Type': 'application/x-www-form-urlencoded' }
- if (token) headers.Token = token
- const res = await fetch(urlPath.startsWith('http') ? urlPath : `${gateway}${urlPath}`, { method, headers, body })
- return res.json()
- }
- function walk(nodes, map = {}) {
- for (const n of nodes || []) {
- if (n.tag) map[n.tag] = n
- walk(n.columnList, map)
- }
- return map
- }
- const login = await call(`${gateway}/proxy_oauth/user/login`, { userName: user, password, clientId })
- if (login.code !== 200 || !login.message) {
- console.error('登录失败', login.message || login)
- process.exit(1)
- }
- const token = login.message
- const cols = walk((await call('/proxy_dms/column/getColumnList', {}, 'POST', token)).content)
- const col = cols.shba_user
- if (!col?.id) {
- console.error('shba_user 栏目不存在。请从 shba_org_model 克隆字段后 addColumn,不要自造 addModel 字段结构。')
- process.exit(1)
- }
- const listed = await call('/proxy_dms/content/selectContentList', {
- columnId: col.id,
- search: '[]',
- orderBy: '[{"field":"update_time","orderByType":2}]',
- page: 0,
- pageSize: 50,
- }, 'POST', token)
- const rows = listed.content?.data || []
- console.log('shba_user', col.id, col.modelName, 'accounts', rows.length, rows.map((r) => `${r.content}:${r.c_account}/${r.c_role}/${r.c_branch_name}`).join(' | '))
|