| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- /*
- 修改脚本,请现在指定spid测试
- 例如: node db_script/sub_project local 3fcee213-92c9-41de-8f5a-b896c986311a
- 没有意外再全部执行
- 所有修改均应考虑脚本二次执行时的兼容,应检查是否已执行过,避免在生产环境运行时出现问题后需要二次执行,参见自定义分类脚本
- */
- const BaseUtil = require('./baseUtils');
- const scheduleConst = require('../app/const/schedule');
- const querySql = BaseUtil.querySql;
- const uuid = require('node-uuid');
- const getInsertSql = function (tableName, data) {
- const column = [], query = [], value = [];
- for (const prop in data) {
- column.push(prop);
- query.push('?');
- value.push(data[prop]);
- }
- return [`INSERT INTO ${tableName} (${column.join(',')}) VALUES (${query.join(',')})`, value];
- };
- console.log('Copy tender_permission properties: schedule');
- const doComplete = async function() {
- try {
- const audits = await querySql('Select * From zh_schedule_audit');
- for (const a of audits) {
- const existTender = await querySql('SELECT * FROM zh_tender where id = ?;', [a.tid]);
- if (existTender.length === 0) {
- continue;
- } else {
- const existTenderPermission = await querySql('SELECT * FROM zh_tender_permission WHERE tid = ? and uid = ?', [existTender[0].id, a.audit_id]);
- let schedule_permission = '';
- if (a.permission === scheduleConst.permission.show) {
- schedule_permission = '1';
- } else if (a.permission === scheduleConst.permission.edit) {
- schedule_permission = '1,2';
- }
- const fund_pay_permission = [];
- if (a.permission_pay_show) {
- fund_pay_permission.push(1);
- }
- if (a.permission_pay_file) {
- fund_pay_permission.push(3);
- }
- if (schedule_permission !== '') {
- console.log('Copy tender_permission_schedule: ' + a.audit_id + ' ' + a.tid + ' ');
- if (existTenderPermission.length === 0) {
- const tender_permission = { id: uuid.v4(), pid: existTender[0].project_id, spid: existTender[0].spid, tid: existTender[0].id, uid: a.audit_id, schedule: schedule_permission };
- const [spSql, spSqlParam] = getInsertSql('zh_tender_permission', tender_permission);
- await querySql(spSql, spSqlParam);
- } else {
- await querySql('Update zh_tender_permission SET schedule = ? WHERE id = ?; ', [schedule_permission, existTenderPermission[0].id]);
- }
- }
- }
- }
- console.log('END Update;');
- } catch (err) {
- console.log(err);
- }
- BaseUtil.closePool();
- };
- doComplete();
|