| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- /**
- * 人员模型 1970 只补用户清单里缺少的字段,不删不改已有列。
- * 凭据:环境变量 SJ_OAUTH_PASSWORD,不要把密码写进本文件。
- */
- const http = require('http')
- const qs = require('querystring')
- const HOST = '121.43.55.7'
- const PORT = 2101
- const USER = process.env.SJ_OAUTH_USER || 'user_liu'
- const PASS = process.env.SJ_OAUTH_PASSWORD
- const MODEL_ID = 1970
- if (!PASS) {
- console.error('缺少 SJ_OAUTH_PASSWORD')
- process.exit(1)
- }
- function post(urlPath, fields, token) {
- return new Promise((resolve, reject) => {
- const body = qs.stringify(fields || {})
- const headers = {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Content-Length': Buffer.byteLength(body),
- }
- if (token) {
- headers.Token = token
- headers.token = token
- }
- const req = http.request(
- { hostname: HOST, port: PORT, path: urlPath, method: 'POST', headers },
- (res) => {
- let data = ''
- res.on('data', (c) => (data += c))
- res.on('end', () => {
- try { resolve(JSON.parse(data)) } catch (e) { resolve({ raw: data, status: res.statusCode }) }
- })
- },
- )
- req.on('error', reject)
- req.write(body)
- req.end()
- })
- }
- function text(shortName, alias, seq) {
- return {
- alias,
- customType: '',
- describe: '格式为富文本',
- frontType: 'content',
- id: 2,
- must: false,
- name: 'c_' + shortName,
- searchType: '2',
- sequence: seq || 1,
- showParam: 'name,alias,desc,type,front_type,must,default_value',
- type: 'text',
- }
- }
- function normalizeFieldList(raw) {
- let fl = raw
- if (typeof fl === 'string') fl = JSON.parse(fl)
- const out = {}
- Object.keys(fl || {}).forEach((k) => {
- let v = fl[k]
- if (typeof v === 'string') v = JSON.parse(v)
- out[k] = v
- })
- return out
- }
- const ADD = [
- ['person_type', '人员类型'],
- ['urban_medicare_confirm', '转至城镇医保确认状态'],
- ['household_district', '户籍区县'],
- ['household_town', '户籍街镇'],
- ['household_village', '户籍村居委'],
- ['contact_name', '联系人'],
- ['contact_phone', '联系电话'],
- ['insurance_join_date', '参保日期'],
- ['person_mark', '人员标示'],
- ['change_reason', '变更原因'],
- ['benefit_apply_date', '待遇申领日期'],
- ['sentence_start', '刑期开始时间'],
- ['sentence_end', '刑期结束时间'],
- ['cancel_apply_date', '注销申办日期'],
- ['cancel_reason', '注销原因'],
- ['cancel_death_month', '注销(死亡)年月'],
- ['has_heir', '是否有继承人'],
- ['heir_id_type', '继承人证件类型'],
- ['heir_bank_name', '继承人银行名称'],
- ['heir_household_address', '继承人户籍地址'],
- ['heir_address', '继承人联系地址'],
- ['local_or_remote', '同城或异地'],
- ]
- async function main() {
- const login = await post('/proxy_oauth/user/login', {
- userName: USER,
- password: PASS,
- clientId: '1',
- })
- const token = login.message
- if (!token || String(token).indexOf('.') < 0) {
- console.error('login failed', login.code, String(login.message || login.msg || '').slice(0, 160))
- process.exit(1)
- }
- const modelRes = await post('/proxy_dms/model/getModelById', { modelId: String(MODEL_ID) }, token)
- if (modelRes.code != 200) throw new Error('getModel fail ' + JSON.stringify(modelRes).slice(0, 300))
- const model = modelRes.content
- const fieldList = normalizeFieldList(model.fieldList)
- const addfieldList = {}
- let seq = 80
- Object.keys(fieldList).forEach((k) => {
- const n = Number(fieldList[k] && fieldList[k].sequence) || 0
- if (n > seq) seq = n
- })
- ADD.forEach(([shortName, alias]) => {
- const full = 'c_' + shortName
- if (fieldList[full]) return
- seq += 1
- const p = text(shortName, alias, seq)
- fieldList[full] = p
- addfieldList[shortName] = {
- alias: p.alias,
- type: p.type,
- frontType: p.frontType,
- must: p.must,
- name: shortName,
- describe: p.describe,
- searchType: p.searchType,
- sortType: p.sortType,
- sequence: p.sequence,
- showParam: p.showParam,
- customType: '',
- id: p.id,
- }
- })
- const added = Object.keys(addfieldList)
- console.log('existing', Object.keys(fieldList).length - added.length, 'toAdd', added.join(',') || 'none')
- if (!added.length) return
- const res = await post('/proxy_dms/model/updateFieldList', {
- modelId: String(MODEL_ID),
- fieldList: JSON.stringify(fieldList),
- addfieldList: JSON.stringify(addfieldList),
- delfieldList: JSON.stringify({}),
- updatefieldList: JSON.stringify({}),
- }, token)
- const verify = await post('/proxy_dms/model/getModelById', { modelId: String(MODEL_ID) }, token)
- const after = normalizeFieldList(verify.content && verify.content.fieldList)
- const still = added.filter((n) => !after['c_' + n])
- console.log('update', res.code, String(res.message || res.content || '').slice(0, 200))
- console.log('after', Object.keys(after).length, 'stillMissing', still.join(',') || 'none')
- if (still.length) process.exit(2)
- }
- main().catch((e) => {
- console.error(e)
- process.exit(1)
- })
|