| | |
| | | import moment from 'moment' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Button, Modal, notification, message } from 'antd' |
| | | import md5 from 'md5' |
| | | |
| | | import ExcelIn from './excelin' |
| | | import Utils, { getExcelInSql } from '@/utils/utils.js' |
| | |
| | | this.refs.excelIn.exceltrigger() |
| | | }) |
| | | |
| | | if (window.GLOB.systemType === 'production') { |
| | | MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: '导入Excel'}) |
| | | } |
| | | // if (window.GLOB.systemType === 'production') { |
| | | // MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: '导入Excel'}) |
| | | // } |
| | | } |
| | | } |
| | | |
| | |
| | | }) |
| | | } |
| | | |
| | | if (btn.intertype === 'system' && window.backend && window.GLOB.CacheData.has('sql_' + btn.uuid)) { |
| | | let ex = window.GLOB.CacheData.get('sql_' + btn.uuid) |
| | | let param = this.getExps(ex, data) |
| | | |
| | | if (param.errors) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: param.errors, |
| | | duration: 5 |
| | | }) |
| | | this.setState({ loading: false }) |
| | | return |
| | | } |
| | | |
| | | let unCheckParam = null |
| | | |
| | | if (ex.reps.includes('mk_check_begin')) { |
| | | unCheckParam = fromJS(param).toJS() |
| | | |
| | | param.data[0].exps.push({ |
| | | key: 'mk_check_begin', |
| | | value: '' |
| | | }, { |
| | | key: 'mk_check_end', |
| | | value: '' |
| | | }) |
| | | unCheckParam.data[0].exps.push({ |
| | | key: 'mk_check_begin', |
| | | value: 'Y' |
| | | }, { |
| | | key: 'mk_check_end', |
| | | value: 'Y' |
| | | }) |
| | | } |
| | | |
| | | if (unCheckParam) { |
| | | Api.genericInterface(param).then(res => { |
| | | if (res.status) { |
| | | this.execSuccess(res) |
| | | } else if (res.ErrCode === 'C') { |
| | | const that = this |
| | | confirm({ |
| | | title: window.GLOB.dict['exec_sure'] || '请确认', |
| | | content: res.message, |
| | | okText: window.GLOB.dict['ok'] || '确定', |
| | | cancelText: window.GLOB.dict['cancel'] || '取消', |
| | | onOk() { |
| | | return new Promise(resolve => { |
| | | Api.genericInterface(unCheckParam).then(result => { |
| | | if (result.status) { |
| | | that.execSuccess(result) |
| | | } else { |
| | | that.execError(result) |
| | | } |
| | | resolve() |
| | | }) |
| | | }) |
| | | }, |
| | | onCancel() { |
| | | that.execError(res) |
| | | } |
| | | }) |
| | | } else { |
| | | this.execError(res) |
| | | } |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | | this.execError({}) |
| | | }) |
| | | } else { |
| | | Api.genericInterface(param).then((res) => { |
| | | if (res.status) { |
| | | this.execSuccess(res) |
| | | } else { |
| | | this.execError(res) |
| | | } |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | | this.execError({}) |
| | | }) |
| | | } |
| | | } else { |
| | | let result = getExcelInSql(btn, data, (BID || ''), this.state.primaryId) |
| | | |
| | | if (result.errors) { |
| | |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | |
| | | getExps = (ex, data) => { |
| | | const { BID, btn } = this.props |
| | | const { primaryId } = this.state |
| | | |
| | | let exps = [] |
| | | let values = { |
| | | time_id: Utils.getguid(), |
| | | roleid: sessionStorage.getItem('role_id') || '', |
| | | mk_departmentcode: sessionStorage.getItem('departmentcode') || '', |
| | | mk_organization: sessionStorage.getItem('organization') || '', |
| | | mk_user_type: sessionStorage.getItem('mk_user_type') || '', |
| | | mk_nation: sessionStorage.getItem('nation') || '', |
| | | mk_province: sessionStorage.getItem('province') || '', |
| | | mk_city: sessionStorage.getItem('city') || '', |
| | | mk_district: sessionStorage.getItem('district') || '', |
| | | mk_address: sessionStorage.getItem('address') || '', |
| | | id: primaryId || '', |
| | | bid: BID || '', |
| | | typename: 'admin', |
| | | datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | // mk_check_begin: '', |
| | | // mk_check_end: '' |
| | | } |
| | | |
| | | if (window.GLOB.externalDatabase !== null) { |
| | | values.db = window.GLOB.externalDatabase |
| | | } |
| | | |
| | | let keys = ['delete', 'drop', 'insert', 'truncate', 'update'] |
| | | let errors = [] |
| | | let _topline = btn.verify.range || 0 |
| | | let cols = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] |
| | | for (let i = 0; i < 26; i++) { |
| | | cols.push('A' + cols[i]) |
| | | } |
| | | |
| | | let lines = data.map((item, lindex) => { |
| | | let vals = [] |
| | | btn.verify.columns.forEach((col, cindex) => { |
| | | if (col.import === 'false') return |
| | | |
| | | let val = item[col.Column] !== undefined ? item[col.Column] : '' |
| | | let _colindex = cols[cindex] || (cindex + 1) |
| | | let _position = (_topline + lindex + 1) + '行 ' + _colindex + '列 ' |
| | | |
| | | if (col.import === 'init') { |
| | | if (/^Nvarchar/ig.test(col.type)) { |
| | | val = '' |
| | | } else if (/^Decimal/ig.test(col.type) || /^int/ig.test(col.type)) { |
| | | val = 0 |
| | | } else if (col.type === 'date') { |
| | | val = '1949-10-01' |
| | | } else if (col.type === 'datetime') { |
| | | val = '1949-10-01 00:00:00' |
| | | } |
| | | } else if (/^Nvarchar/ig.test(col.type)) { |
| | | val = val + '' |
| | | |
| | | if (/'/.test(val)) { |
| | | val = val.replace(/'/ig, '"') |
| | | } |
| | | |
| | | val = val.replace(/(^\s+$)|\t+|\v+/ig, '') |
| | | |
| | | if (!val && col.required === 'true') { // 必填校验 |
| | | errors.push(_position + '内容不可为空') |
| | | } else if (col.limit && val.length > col.limit) { // 长度校验 |
| | | errors.push(_position + '内容超长') |
| | | } else { // 关键字校验 |
| | | keys.forEach(key => { |
| | | let _patten = new RegExp('(^' + key + '\\s+)|(\\s+' + key + '\\s+)', 'ig') |
| | | if (_patten.test(val)) { |
| | | errors.push(_position + '含有关键字' + key) |
| | | } |
| | | }) |
| | | } |
| | | } else if (/^Decimal/ig.test(col.type) || /^int/ig.test(col.type)) { |
| | | if (col.required === 'false') { |
| | | if (!val || isNaN(val)) { |
| | | val = 0 |
| | | } |
| | | } else if (!val && val !== 0) { |
| | | errors.push(_position + '内容不可为空') |
| | | } else if (isNaN(val)) { // 检验是否为数值 |
| | | errors.push(_position + '内容应为数值') |
| | | } else if ((col.min || col.min === 0) && val < col.min) { // 最小值检验 |
| | | errors.push(_position + '小于最小值') |
| | | } else if ((col.max || col.max === 0) && val > col.max) { // 最大值检验 |
| | | errors.push(_position + '大于最大值') |
| | | } |
| | | } else if (col.type === 'date' || col.type === 'datetime') { |
| | | if (typeof(val) === 'number') { |
| | | if (val > 2958465 || val <= 0) { // 时间过大或小于等于0 |
| | | errors.push(_position + '时间为负值或太大') |
| | | } else { // 时间格式化 |
| | | if (val < 60) { // 1900-2-29,excel中存在,实际不存在 |
| | | val++ |
| | | } |
| | | if (col.type === 'datetime') { |
| | | val = val - 2 |
| | | let day = Math.floor(val) |
| | | let seconds = Math.round((val - day) * 24 * 60 * 60) |
| | | val = moment('19000101', 'YYYYMMDD').add(day, 'days').add(seconds, 'seconds').format('YYYY-MM-DD HH:mm:ss') |
| | | } else { |
| | | val = moment('19000101', 'YYYYMMDD').add(Math.floor(val - 2), 'days').format('YYYY-MM-DD') |
| | | } |
| | | } |
| | | } else if (typeof(val) === 'string') { |
| | | val = val.replace(/(^\s+$)|\t+|\v+/ig, '') |
| | | if (!val) { |
| | | if (col.required === 'true') { // 时间必填校验 |
| | | errors.push(_position + '内容不可为空') |
| | | } else if (col.type === 'date') { |
| | | val = '1949-10-01' |
| | | } else if (col.type === 'datetime') { |
| | | val = '1949-10-01 00:00:00' |
| | | } |
| | | } else if (!/^[1-9][0-9]{3}/.test(val)) { // 时间正则校验 |
| | | errors.push(_position + '时间格式错误') |
| | | } |
| | | } else { // 时间格式错误 |
| | | errors.push(_position + '时间格式错误') |
| | | } |
| | | } |
| | | |
| | | vals.push(val) |
| | | }) |
| | | |
| | | let _lineIndex = '0000' + (lindex + 1) + '0' |
| | | _lineIndex = _lineIndex.substring(_lineIndex.length - 6) |
| | | |
| | | vals.push(Utils.getguid() + _lineIndex) |
| | | vals.push(BID) |
| | | |
| | | return vals |
| | | }) |
| | | |
| | | if (errors.length) return {errors: errors.join('; ')} |
| | | |
| | | ex.reps.forEach(n => { |
| | | let key = n.toLowerCase() |
| | | if (values.hasOwnProperty(key)) { |
| | | exps.push({ |
| | | key: n, |
| | | value: values[key] |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | exps.push({ |
| | | key: 'mk_excel_data', |
| | | value: lines |
| | | }) |
| | | |
| | | if (btn.$process && btn.verify.workFlow === 'true') { |
| | | let flow = window.GLOB.UserCacheMap.get(btn.$flowId) |
| | | let target = flow ? flow.cells.filter(cell => cell.mknode === 'start')[0] : '' |
| | | |
| | | let error = '' |
| | | let msg = '' |
| | | let status = 0 |
| | | let statusName = '' |
| | | let detailId = '' |
| | | |
| | | if (target) { |
| | | detailId = target.id |
| | | status = target.mkdata.status |
| | | statusName = target.mkdata.statusName |
| | | |
| | | let label = target.attrs && target.attrs.text && target.attrs.text.text ? target.attrs.text.text : '' |
| | | msg = {...target.mkdata, label: label, id: target.id, checkIds: [], checkUsers: []} |
| | | msg = window.btoa(window.encodeURIComponent(JSON.stringify(msg))) |
| | | } else { |
| | | status = 0 |
| | | statusName = '异常' |
| | | error = '工作流无开始节点' |
| | | } |
| | | |
| | | exps.push( |
| | | { key: 'works_flow_error', value: error }, |
| | | { key: 'works_flow_code', value: flow ? flow.flow_code : '' }, |
| | | { key: 'works_flow_name', value: flow ? flow.flow_name : '' }, |
| | | { key: 'works_flow_param', value: msg }, |
| | | { key: 'works_flow_detail_id', value: detailId }, |
| | | { key: 'status', value: status }, |
| | | { key: 'statusname', value: statusName }, |
| | | { key: 'work_group', value: sessionStorage.getItem('work_group') || '' }, |
| | | { key: 'work_grade', value: sessionStorage.getItem('work_grade') || 0 }, |
| | | // { key: 'start_type', value: '开始' }, |
| | | ) |
| | | } |
| | | |
| | | let md5_id = '' |
| | | if (window.GLOB.probation) { |
| | | md5_id = md5(ex.id + JSON.stringify(exps) + Math.floor(new Date().getTime() / 600000)) |
| | | md5_id = moment().format('YYYYMMDDHHmmss') + md5_id.slice(-18) |
| | | } |
| | | |
| | | return { |
| | | $backend: true, |
| | | data: [{ |
| | | id: ex.id, |
| | | exps: exps, |
| | | menuname: btn.logLabel || '', |
| | | md5_id: md5_id |
| | | }] |
| | | } |
| | | } |
| | | |
| | | render() { |
| | | const { btn } = this.props |