Edit D:\xinhaisoft\crisis_new\api\controllers\hitsz.js
/** * ????????????????? * ?????????????????????????????????????? */ const util = require('../utils') const db = require('../data') const dayjs = require('dayjs') let [sql, rs] = ['', null] const EasySoap = require('easysoap') const client = EasySoap({ host: '219.223.236.43', path: '/bgSync/webservice/GetData', wsdl: '/bgSync/webservice/GetData?wsdl' }) /** * ?????? * get: /hitsz/total */ exports.Total = async ctx => { const params = { key: 'BFD6723E68202AFCE0530B18F80A3806', pageno: 1, interval: 1 } await client.call({ method: 'query', params }).then(res => { const json = res.data const data = JSON.parse(json.return) ctx.body = { code: 0, data: data.total } }).catch(err => ctx.body = { code: 1, message: JSON.stringify(err) }) } /** * ??? * get: /hitsz/import */ exports.Import = async ctx => { const pageno = ctx.query.page || 1 const interval = ctx.query.pagesize || 10 const params = { key: 'BFD6723E68202AFCE0530B18F80A3806', pageno, interval } await client.call({ method: 'query', params }) .then(async res => { const today = dayjs().format('YYYY-MM-DD') const list = JSON.parse(res.data.return).data const data = [0, 0] rs = await db.select('select top 1 id from member order by id desc') let maxid = rs.id let sql = '' for (let i = 0; i < list.length; i++) { const row = list[i] const type = await GetType(row.YMC, row.ZYXKMC) const grade = await GetGrade(row.njmc) const number = row.XH const birthday = row.CSRQ ? row.CSRQ.substring(0, 10) : today const sex = row.XBM === '1' ? 1 : 0 rs = await db.select(`select top 1 id from member where number='${number}'`) if (rs) { sql += 'update member set' + ` realname='${row.XM}'` + ',sex=' + sex + `,birthday='${birthday}'` + ',type=' + type + ',grade=' + grade + ' where id=' + rs.id + ';' data[0]++ } else { sql += 'insert into member(id,number,password,realname,type,grade,[state],[group],sex,birthday,isstudent) values(' + (++maxid) + `,'${number}'` + `,'${util.MD5(number.slice(-6))}'` + `,'${row.XM}'` + ',' + type + ',' + grade + ',5' + ',1' + ',' + sex + `,'${birthday}'` + ',1' + ');' data[1]++ } } // console.log(sql) db.execute(sql) ctx.body = { code: 0, data } }).catch(err => { console.log(err) ctx.body = { code: 1, message: '????????????????????' } }) } /** * ???????? * get: /hitsz/number */ exports.GetNumber = async ctx => { const pageno = ctx.query.page || 1 const interval = ctx.query.pagesize || 10 const params = { key: 'BFD6723E68202AFCE0530B18F80A3806', pageno, interval } await client.call({ method: 'query', params }) .then(async res => { const data = JSON.parse(res.data.return).data.map(item => item.XH) ctx.body = { code: 0, data } }).catch(err => { console.log(err) ctx.body = { code: 1, message: '?????????????????' } }) } /** * ??????????????D????????? */ const GetType = async (yx, zy) => { let type = 1 if (yx && zy) { const parent = await db.select(`select top 1 id,path from member_type where name='${yx}' and parid=1`) if (parent) { const child = await db.select(`select top 1 id from member_type where name='${zy}' and parid=${parent.id}`) if (child) { type = child.id } else { type = await db.newid('member_type') sql = 'insert into member_type(id,parid,path,topid,name,sort) values(' + type + ',' + parent.id + `,'${parent.path + ',' + type}'` + ',1' + `,'${zy}'` + ',' + type + ')' db.execute(sql) } } else { const maxid = await db.scalar('select top 1 id from member_type order by id desc') const yxid = maxid + 1 const zyid = maxid + 2 sql = 'insert into member_type(id,parid,path,topid,name,sort) values(' + yxid + ',1' + `,'${'0,2,1,' + yxid}'` + ',1' + `,'${yx}'` + ',' + yxid + ');' + 'insert into member_type(id,parid,path,topid,name,sort) values(' + zyid + ',' + yxid + `,'${'0,2,1,' + yxid + ',' + zyid}'` + ',1' + `,'${zy}'` + ',' + zyid + ')' db.execute(sql) type = zyid } } return type } /** * ??????ID????????? */ const GetGrade = async nj => { let grade = 0 if (nj) { rs = await db.select(`select top 1 id from member_grade where name='${nj}'`) if (rs) { grade = rs.id } else { grade = await db.newid('member_grade') sql = 'insert into member_grade(id,name,sort,membertype) values(' + grade + `,'${nj}'` + ',' + grade + ',1' + ')' db.execute(sql) } } return grade }
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de