From c5a07dba94694d13f0a78e051dfa26c3522933ee Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 15 十一月 2024 18:10:02 +0800 Subject: [PATCH] 2024-11-15 --- src/templates/zshare/verifycard/index.jsx | 941 +++++++++++++++++++++++++++++++++------------------------- 1 files changed, 532 insertions(+), 409 deletions(-) diff --git a/src/templates/zshare/verifycard/index.jsx b/src/templates/zshare/verifycard/index.jsx index 00076a1..d674655 100644 --- a/src/templates/zshare/verifycard/index.jsx +++ b/src/templates/zshare/verifycard/index.jsx @@ -2,7 +2,7 @@ import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' import { Form, Tabs, Row, Col, Button, Popconfirm, notification, Modal, message, InputNumber, Typography } from 'antd' -import { CheckCircleOutlined, StopOutlined, EditOutlined, SwapOutlined, DeleteOutlined, ExclamationOutlined } from '@ant-design/icons' +import { CheckCircleOutlined, StopOutlined, EditOutlined, SwapOutlined, DeleteOutlined, ExclamationOutlined, ConsoleSqlOutlined } from '@ant-design/icons' import Toast from 'antd-mobile/es/components/toast' import Dialog from 'antd-mobile/es/components/dialog' import moment from 'moment' @@ -18,7 +18,7 @@ import BillcodeForm from './billcodeform' import VoucherForm from './voucherform' import asyncComponent from '@/utils/asyncComponent' -import { updateForm } from '@/utils/utils-update.js' +// import { updateForm } from '@/utils/utils-update.js' import MKEmitter from '@/utils/events.js' import './index.scss' @@ -30,7 +30,6 @@ class VerifyCard extends Component { static propTpyes = { - btnTab: PropTypes.any, // 琛ㄥ崟鏍囩椤碉紙鎸夐挳锛夊弬鏁� config: PropTypes.any, // 琛ㄥ崟鏍囩椤靛弬鏁� card: PropTypes.object, // 鎸夐挳淇℃伅 columns: PropTypes.array @@ -45,7 +44,8 @@ emailCodes: [], // 閭妯℃澘 verify: {}, fields: [], - usefulfields: '', + formfields: '', + colfields: '', defaultsql: '', // 榛樿Sql orderModular: [], orderModularDetail: [], @@ -86,7 +86,7 @@ title: '楠岃瘉绫诲瀷', dataIndex: 'verifyType', width: '14%', - render: (text, record) => record.verifyType === 'logic' ? '閫昏緫楠岃瘉' : '鐗╃悊楠岃瘉', + render: (text) => text === 'logic' ? '閫昏緫楠岃瘉' : '鐗╃悊楠岃瘉', inputType: 'select', editable: true, options: [ @@ -114,6 +114,34 @@ <CheckCircleOutlined style={{marginLeft: '5px'}}/> </div> ) + }, + { + dataIndex: 'sqlRender', + render: (record) => { + let _fieldValue = [] + let _value = [] + let _labels = record.fieldlabel.split(',') + + record.field.split(',').forEach((_field, index) => { + let _key = _field.toLowerCase() + _fieldValue.push(`${_key}=${_key === 'bid' ? '@BID@' : `''`}`) + _value.push(`${_labels[index] || ''}锛歺xx`) + }) + + let _verifyType = '' + if (record.verifyType === 'logic') { + _verifyType = ' and deleted=0' + } + + let sql = `select @tbid='', @ErrorCode='',@retmsg='' + select @tbid='X' from ${this.props.card.sql} where ${_fieldValue.join(' and ')}${_verifyType} + If @tbid!='' + Begin + select @ErrorCode='${record.errorCode}',@retmsg='${_value.join(', ')} 宸插瓨鍦�' + goto aaa + end` + return sql.split(/\n\s{10}/ig).map(n => n.replace(/^\s{2}/ig, ' ')) + } } ], onceUniqueColumns: [ @@ -151,6 +179,27 @@ </div> ) }, + { + dataIndex: 'sqlRender', + render: (record) => { + let primaryKey = 'id' + + if (this.props.config && this.props.config.setting && this.props.config.setting.primaryKey) { + primaryKey = this.props.config.setting.primaryKey + } + + let sql = `Set @tbid='' + Select top 1 @tbid='X' from (select distinct ${record.field},1 as n from (鏁版嵁婧�) tb inner join (select ID from dbo.SplitComma(@ID@)) sp on tb.${primaryKey}=sp.ID ) a having sum(n)>1 + + If @tbid!='' + Begin + Set @ErrorCode='E' Set @retmsg='${record.fieldlabel} 鍊间笉鍞竴' + goto aaa + end` + + return sql.split(/\n\s{10}/ig).map(n => n.replace(/^\s{2}/ig, ' ')) + } + } ], contrastColumns: [ { @@ -163,7 +212,7 @@ { title: '杩愮畻绗�', dataIndex: 'operator', - width: '14%', + width: '13%', editable: true, inputType: 'select', options: [ @@ -187,14 +236,14 @@ { title: '鎻愮ず淇℃伅', dataIndex: 'errmsg', - width: '14%', + width: '13%', inputType: 'input', editable: true }, { title: '鎶ラ敊缂栫爜', dataIndex: 'errorCode', - width: '14%', + width: '13%', editable: true, inputType: 'select', options: [ @@ -224,6 +273,18 @@ <CheckCircleOutlined style={{marginLeft: '5px'}}/> </div> ) + }, + { + dataIndex: 'sqlRender', + render: (record) => { + let sql = `If ${record.frontfield} ${record.operator} ${record.backfield} + Begin + select @ErrorCode='${record.errorCode}',@retmsg='${record.errmsg}' + goto aaa + end` + + return sql.split(/\n\s{10}/ig).map(n => n.replace(/^\s{2}/ig, ' ')) + } } ], customColumns: [ @@ -530,13 +591,14 @@ }> <span className="operation-btn" style={{color: '#ff4d4f'}}><DeleteOutlined /></span> </Popconfirm> + <span className="operation-btn" title="SQL" onClick={() => this.orderSql(record)} style={{color: '#1890ff'}}><ConsoleSqlOutlined /></span> </div>) } ] } UNSAFE_componentWillMount() { - const { columns, config, card, btnTab } = this.props + const { columns, config, card } = this.props const { appType } = this.state let _verify = fromJS(card.verify || {}).toJS() @@ -579,20 +641,19 @@ _verify.uniques = _verify.uniques || [] _verify.contrasts = _verify.contrasts || [] _verify.accountdate = _verify.accountdate || 'false' - _verify.accountfield = _verify.accountfield || '' - _verify.voucherdate = _verify.voucherdate || '' _verify.customverifys = _verify.customverifys || [] _verify.billcodes = _verify.billcodes || [] _verify.voucher = _verify.voucher || {enabled: false} _verify.scripts = _verify.scripts || [] _verify.cbScripts = _verify.cbScripts || [] - if (window.GLOB.process) { + if (window.GLOB.process && card.intertype !== 'inner') { _verify.workFlow = _verify.workFlow || 'false' _verify.flowType = _verify.flowType || (card.sqlType === 'insert' ? 'start' : 'approval') _verify.flowSql = _verify.flowSql || 'true' } else { delete _verify.workFlow + delete _verify.flowRemark delete _verify.flowType delete _verify.flowSql } @@ -602,20 +663,20 @@ _verify.printTempId = '' } - if (window.GLOB.funcs && window.GLOB.funcs.length > 0) { - window.GLOB.funcs.forEach(m => { - let reg = new RegExp(`\\/\\*\\$ex@${m.func_code}-begin\\*\\/[\\s\\S]+\\/\\*@ex\\$-end\\*\\/`, 'ig') - _verify.customverifys.forEach(item => { - item.sql = item.sql.replace(reg, `$ex@${m.func_code}@ex$`) - }) - _verify.scripts.forEach(item => { - item.sql = item.sql.replace(reg, `$ex@${m.func_code}@ex$`) - }) - _verify.cbScripts.forEach(item => { - item.sql = item.sql.replace(reg, `$ex@${m.func_code}@ex$`) - }) - }) - } + // if (window.GLOB.funcs && window.GLOB.funcs.length > 0) { + // window.GLOB.funcs.forEach(m => { + // let reg = new RegExp(`\\/\\*\\$ex@${m.func_code}-begin\\*\\/[\\s\\S]+\\/\\*@ex\\$-end\\*\\/`, 'ig') + // _verify.customverifys.forEach(item => { + // item.sql = item.sql.replace(reg, `$ex@${m.func_code}@ex$`) + // }) + // _verify.scripts.forEach(item => { + // item.sql = item.sql.replace(reg, `$ex@${m.func_code}@ex$`) + // }) + // _verify.cbScripts.forEach(item => { + // item.sql = item.sql.replace(reg, `$ex@${m.func_code}@ex$`) + // }) + // }) + // } _verify.customverifys.forEach((item, i) => { item.$index = i + 1 @@ -634,399 +695,375 @@ activeKey = 'cbScripts' } + let oriVerify = fromJS(_verify).toJS() + + if (_verify.wxAppId) { + if (!window.GLOB.WXApps || window.GLOB.WXApps.filter(app => app.appType === 'public').length === 0) { + delete _verify.wxAppId + } + } + this.setState({ activeKey: activeKey, verifyInter: verifyInter, verify: _verify, - oriVerify: fromJS(_verify).toJS() + oriVerify: oriVerify }) - if (card.intertype === 'inner') { - return + if (card.intertype === 'inner') return + + let _fields = [] + if (card.OpenType === 'form') { + _fields.push({ + field: card.field, + label: card.label, + type: 'text' + }) + } else if (card.modal && (card.OpenType === 'pop' || !card.OpenType)) { + _fields = card.modal.fields || [] } - new Promise(resolve => { - let _fields = [] - if (card.OpenType === 'form') { - _fields.push({ - field: card.field, - label: card.label, - type: 'text' - }) - resolve(_fields) - } else if (card.modal && (card.OpenType === 'pop' || !card.OpenType)) { - _fields = card.modal.fields || [] - resolve(_fields) - } else if (card.OpenType === 'pop') { - Api.getCloudConfig({ - func: 'sPC_Get_LongParam', - MenuID: card.uuid - }).then(res => { - if (res.status) { - let _LongParam = '' - if (res.LongParam) { - try { - _LongParam = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam))) - } catch (e) { - console.warn('Parse Failure') - _LongParam = '' - } - } - - if (!_LongParam) { - message.warning('鏈幏鍙栧埌琛ㄥ崟淇℃伅锛岄儴鍒嗛獙璇佸皢鏃犳硶璁剧疆锛�') - } else { - _LongParam = updateForm(_LongParam) - _fields = _LongParam.fields || [] - } - } else { - notification.warning({ - top: 92, - message: res.message, - duration: 5 - }) - } - resolve(_fields) - }) - } else { - resolve(_fields) - } - }).then(_fields => { - let _usefulfields = ['UserName', 'FullName', 'RoleID', 'mk_departmentcode', 'mk_organization', 'mk_user_type', 'mk_nation', 'mk_province', 'mk_city', 'mk_district', 'mk_address', 'BillCode', 'BVoucher', 'FIBVoucherDate', 'FiYear', 'ModularDetailCode', 'tbid', 'mk_deleted'] - let _declare = ['@UserName nvarchar(50)', '@FullName nvarchar(50)', '@RoleID nvarchar(512)', '@mk_departmentcode nvarchar(512)', '@mk_organization nvarchar(512)', '@mk_user_type nvarchar(20)', '@mk_nation nvarchar(50)', '@mk_province nvarchar(50)', '@mk_city nvarchar(50)', '@mk_district nvarchar(50)', '@mk_address nvarchar(100)', '@ErrorCode nvarchar(50)', '@retmsg nvarchar(4000)', '@BillCode nvarchar(50)', '@BVoucher nvarchar(50)', '@FIBVoucherDate nvarchar(50)', '@FiYear nvarchar(50)', '@ModularDetailCode nvarchar(50)', '@bid nvarchar(50)', '@tbid nvarchar(50)', '@mk_deleted int'] - let _select = ['@UserName=\'\'', '@FullName=\'\'', '@RoleID=\'\'', '@mk_departmentcode=\'\'', '@mk_organization=\'\'', '@mk_user_type=\'\'', '@mk_nation=\'\'', '@mk_province=\'\'', '@mk_city=\'\'', '@mk_district=\'\'', '@mk_address=\'\'', '@ErrorCode=\'\'', '@retmsg=\'\'', '@BillCode=\'\'', '@BVoucher=\'\'', '@FIBVoucherDate=\'\'', '@FiYear=\'\'', '@ModularDetailCode=\'\'', '@bid=\'\'', '@mk_deleted=1'] - let fieldArr = _usefulfields.map(_f => _f.toLowerCase()) - let hasBid = false + let sysfields = ['UserName', 'FullName', 'RoleID', 'mk_departmentcode', 'mk_organization', 'mk_user_type', 'mk_nation', 'mk_province', 'mk_city', 'mk_district', 'mk_address', 'BillCode', 'BVoucher', 'FIBVoucherDate', 'FiYear', 'ModularDetailCode', 'tbid', 'mk_deleted', 'bid', 'mk_submit_type'] + let _declare = ['@UserName nvarchar(50)', '@FullName nvarchar(50)', '@RoleID nvarchar(512)', '@mk_departmentcode nvarchar(512)', '@mk_organization nvarchar(512)', '@mk_user_type nvarchar(20)', '@mk_nation nvarchar(50)', '@mk_province nvarchar(50)', '@mk_city nvarchar(50)', '@mk_district nvarchar(50)', '@mk_address nvarchar(100)', '@ErrorCode nvarchar(50)', '@retmsg nvarchar(4000)', '@BillCode nvarchar(50)', '@BVoucher nvarchar(50)', '@FIBVoucherDate nvarchar(50)', '@FiYear nvarchar(50)', '@ModularDetailCode nvarchar(50)', '@bid nvarchar(50)', '@tbid nvarchar(50)', '@mk_deleted int', '@mk_submit_type nvarchar(50)'] + let _select = ['@UserName=\'\'', '@FullName=\'\'', '@RoleID=\'\'', '@mk_departmentcode=\'\'', '@mk_organization=\'\'', '@mk_user_type=\'\'', '@mk_nation=\'\'', '@mk_province=\'\'', '@mk_city=\'\'', '@mk_district=\'\'', '@mk_address=\'\'', '@ErrorCode=\'\'', '@retmsg=\'\'', '@BillCode=\'\'', '@BVoucher=\'\'', '@FIBVoucherDate=\'\'', '@FiYear=\'\'', '@ModularDetailCode=\'\'', '@bid=\'\'', '@mk_deleted=1', '@mk_submit_type=\'\''] + + let fieldArr = sysfields.map(_f => _f.toLowerCase()) + let hasBid = false - _usefulfields = [] - - fieldArr.push('bid') - - let verIndex = _fields.findIndex(item => item.type === 'vercode') - if (verIndex > -1) { - _fields = fromJS(_fields).toJS() - _fields.splice(verIndex, 0, { - type: 'text', - fieldlength: 50, - writein: 'false', - field: 'mk_timestamp' - }, { - type: 'text', - fieldlength: 50, - writein: 'false', - field: 'mk_send_type' - }, { - type: 'text', - fieldlength: 50, - writein: 'false', - field: 'mk_n_id' - }) - } - - _fields = _fields.filter(_f => _f.field) - _fields.forEach(_f => { - if (_f.field.toLowerCase() === 'bid') { - hasBid = true - } - - if (fieldArr.includes(_f.field.toLowerCase())) return - - fieldArr.push(_f.field.toLowerCase()) - - _usefulfields.push(_f.field) - - let _fieldlen = _f.fieldlength || 50 - - if (_f.type === 'number') { - _fieldlen = _f.decimal ? _f.decimal : 0 - } - - if (_fieldlen > 4000) { - _fieldlen = 'max' - } - - let _type = `nvarchar(${_fieldlen})` - - if (_f.type.match(/date/ig)) { - _type = 'datetime' - _select.push(`@${_f.field}='1949-10-01'`) - } else if (_f.type === 'number') { - _type = `decimal(18,${_fieldlen})` - _select.push(`@${_f.field}=0`) - } else if (_f.type === 'rate') { - _type = `decimal(18,2)` - _select.push(`@${_f.field}=0`) - } else { - _select.push(`@${_f.field}=''`) - } - - _declare.push(`@${_f.field} ${_type}`) + let verIndex = _fields.findIndex(item => item.type === 'vercode') + if (verIndex > -1) { + _fields = fromJS(_fields).toJS() + _fields.splice(verIndex, 0, { + type: 'text', + fieldlength: 50, + writein: 'false', + field: 'mk_timestamp' + }, { + type: 'text', + fieldlength: 50, + writein: 'false', + field: 'mk_send_type' + }, { + type: 'text', + fieldlength: 50, + writein: 'false', + field: 'mk_n_id' }) + } - let uniqueFields = fromJS(_fields).toJS() - - if (!hasBid) { // 鍞竴鎬ч獙璇佹坊鍔燘ID - uniqueFields.unshift({ uuid: 'BID', field: 'BID', label: 'BID', type: 'text' }) - _fields.unshift({ uuid: 'BID', field: 'BID', label: 'BID', type: 'text' }) + let formfields = [] + _fields = _fields.filter(_f => _f.field) + _fields.forEach(_f => { + let key = _f.field.toLowerCase() + if (key === 'bid') { + hasBid = true } - let hasColumn = false - if (columns && columns.length > 0) { - if (btnTab) { // 琛ㄥ崟鏍囩 - hasColumn = btnTab.Ot !== 'notRequired' - } else if (card.Ot !== 'notRequired') { - hasColumn = true + if (fieldArr.includes(key)) return + + fieldArr.push(key) + + formfields.push(_f.field) + + let _fieldlen = _f.fieldlength || 50 + + if (_f.type === 'number') { + _fieldlen = _f.decimal ? _f.decimal : 0 + } + + if (_fieldlen > 4000) { + _fieldlen = 'max' + } + + let _type = `nvarchar(${_fieldlen})` + + if (_f.type.match(/date/ig)) { + _type = 'datetime' + _select.push(`@${_f.field}='1949-10-01'`) + } else if (_f.type === 'number') { + _type = `decimal(18,${_fieldlen})` + _select.push(`@${_f.field}=1`) + } else if (_f.declare === 'decimal') { + _type = `decimal(18,${_f.decimal || 0})` + _select.push(`@${_f.field}=1`) + } else if (_f.type === 'rate') { + _type = `decimal(18,2)` + _select.push(`@${_f.field}=1`) + } else { + _select.push(`@${_f.field}=''`) + } + + if (['appkey'].includes(key)) return + + _declare.push(`@${_f.field} ${_type}`) + }) + + let uniqueFields = fromJS(_fields).toJS() + + if (!hasBid) { // 鍞竴鎬ч獙璇佹坊鍔燘ID + uniqueFields.unshift({ uuid: 'BID', field: 'BID', label: 'BID', type: 'text' }) + _fields.unshift({ uuid: 'BID', field: 'BID', label: 'BID', type: 'text' }) + } + + let unionFields = fromJS(_fields).toJS() + let formArr = _fields.map(_f => _f.field.toLowerCase()) + + let colfields = [] + if (card.Ot !== 'notRequired' && columns) { + columns.forEach(_f => { + if (!_f.field) return + + let key = _f.field.toLowerCase() + + if (!formArr.includes(key)) { + formArr.push(key) + unionFields.push(_f) } - } - let unionFields = fromJS(_fields).toJS() - let formArr = _fields.map(_f => _f.field.toLowerCase()) + if (fieldArr.includes(key)) return - if (hasColumn) { - columns.forEach(_f => { - if (_f.field && !formArr.includes(_f.field.toLowerCase())) { - formArr.push(_f.field.toLowerCase()) - unionFields.push(_f) - } - if (!_f.field || fieldArr.includes(_f.field.toLowerCase())) return + fieldArr.push(key) + colfields.push(_f.field) - fieldArr.push(_f.field.toLowerCase()) - _usefulfields.push(_f.field) - - if (_f.datatype) { // 鑷畾涔夊瓧娈� - if (/decimal/ig.test(_f.datatype)) { - _select.push(`@${_f.field}=0`) - } else { - _select.push(`@${_f.field}=''`) - } - - _declare.push(`@${_f.field} ${_f.datatype}`) - return + if (_f.datatype) { // 鑷畾涔夊瓧娈� + if (/decimal|int/ig.test(_f.datatype)) { + _select.push(`@${_f.field}=1`) + } else if (/date/ig.test(_f.datatype)) { + _select.push(`@${_f.field}='1949-10-01'`) + } else { + _select.push(`@${_f.field}=''`) } + if (['appkey'].includes(key)) return + + _declare.push(`@${_f.field} ${_f.datatype}`) + } else { let _fieldlen = _f.fieldlength || 50 - + if (_fieldlen > 4000) { _fieldlen = 'max' } - + let _type = `nvarchar(${_fieldlen})` - + if (_f.type === 'number') { _type = `decimal(18,${_f.decimal ? _f.decimal : 0})` } else if (_f.type === 'picture' || _f.type === 'textarea') { _type = `nvarchar(${_fieldlen})` } - + if (_f.type === 'number') { - _select.push(`@${_f.field}=0`) + _select.push(`@${_f.field}=1`) } else { _select.push(`@${_f.field}=''`) } + + if (['appkey'].includes(key)) return _declare.push(`@${_f.field} ${_type}`) - }) - } - - let _sql = `Declare ${_declare.join(', ')} - Select ${_select.join(', ')} - ` - - // 榛樿sql - let _defaultsql = '' - let _insertsql = '' - let _updatesql = '' - let _primaryKey = config.setting.primaryKey || 'id' - - if (this.props.side === 'sub') { - _primaryKey = config.setting.subKey || 'id' - } - - if (card.sqlType === 'insert' || card.sqlType === 'insertOrUpdate') { - let keys = [] - let values = [] - - _fields.forEach(item => { - if (!item.field || item.writein === 'false') return - - keys.push(item.field.toLowerCase()) - - if (item.field.toLowerCase() === 'bid' && item.uuid === 'BID') { - values.push('@BID@') - } else { - values.push('@' + item.field) - } - }) - - if (!keys.includes(_primaryKey.toLowerCase())) { - keys.push(_primaryKey.toLowerCase()) - values.push('@ID@') } - if (!keys.includes('createuserid')) { - keys.push('createuserid') - values.push('@userid@') - } - if (!keys.includes('createuser')) { - keys.push('createuser') - values.push('@username') - } - if (!keys.includes('createstaff')) { - keys.push('createstaff') - values.push('@fullname') - } - if (!keys.includes('bid')) { - keys.push('bid') - values.push('@BID@') - } - if (!keys.includes('typename')) { - keys.push('typename') - values.push('@typename@') - } - - keys = keys.join(', ') - values = values.join(', ') - _insertsql = `insert into ${card.sql} (${keys}) select ${values};` - } - - if (card.sqlType === 'update' || card.sqlType === 'audit' || card.sqlType === 'insertOrUpdate') { - let _form = [] - let _arr = [] - - _fields.forEach(item => { - if (!item.field || item.writein === 'false' || item.uuid === 'BID') return - - _arr.push(item.field.toLowerCase()) - if (item.field.toLowerCase() === 'bid') { - _form.push(item.field + '=@BID@') - } else { - _form.push(item.field + '=@' + item.field) - } - }) - - if (this.props.card.sqlType === 'audit') { - if (!_arr.includes('submitdate')) { - _form.push('submitdate=getdate()') - } - if (!_arr.includes('submituser')) { - _form.push('submituser=@username') - } - if (!_arr.includes('submitstaff')) { - _form.push('submitstaff=@fullname') - } - if (!_arr.includes('submituserid')) { - _form.push('submituserid=@userid@') - } - if (!_arr.includes('typename')) { - _form.push(`typename=@typename@`) - } - } else { - if (!_arr.includes('modifydate')) { - _form.push('modifydate=getdate()') - } - if (!_arr.includes('modifyuser')) { - _form.push('modifyuser=@username') - } - if (!_arr.includes('modifystaff')) { - _form.push('modifystaff=@fullname') - } - if (!_arr.includes('modifyuserid')) { - _form.push('modifyuserid=@userid@') - } - if (!_arr.includes('typename')) { - _form.push(`typename=@typename@`) - } - } - - if (_verify.voucher && _verify.voucher.enabled) { - if (!_arr.includes('bvoucher')) { - _form.push('BVoucher=@BVoucher') - } - if (!_arr.includes('fibvoucherdate')) { - _form.push('FIBVoucherDate=@FIBVoucherDate') - } - if (!_arr.includes('fiyear')) { - _form.push('FiYear=@FiYear') - } - } - - _form = _form.join(', ') - _updatesql = `update ${card.sql} set ${_form} where ${_primaryKey}${card.Ot !== 'requiredOnce' ? '=@ID@' : ' in (select ID from dbo.SplitComma(@ID@))'};` - } - - if (card.sqlType === 'insert') { - _defaultsql = _insertsql - } else if (card.sqlType === 'update' || card.sqlType === 'audit') { - _defaultsql = _updatesql - } else if (card.sqlType === 'insertOrUpdate') { - _defaultsql += `select @tbid='' - select @tbid='X' from ${card.sql} where ${_primaryKey}=@ID@ - if @tbid='' - begin - ${_insertsql} - end - else - begin - ${_updatesql} - end - ` - } else if (card.sqlType === 'LogicDelete' || card.sqlType === 'custom') { - let _voucher = '' - if (_verify.voucher && _verify.voucher.enabled) { - _voucher = ',BVoucher=@BVoucher,FIBVoucherDate=@FIBVoucherDate,FiYear=@FiYear' - } - _defaultsql = `update ${card.sql} set deleted=@mk_deleted,modifydate=getdate(),modifyuser=@username,modifystaff=@fullname,modifyuserid=@userid@${_voucher} where ${_primaryKey}${card.Ot !== 'requiredOnce' ? '=@ID@' : ' in (select ID from dbo.SplitComma(@ID@))'};` - } else if (card.sqlType === 'delete') { - let _msg = '' - if (columns && columns.length > 0 && card.Ot !== 'notRequired') { - let _index = 0 - columns.forEach(col => { - if (!col.field || col.Hide === 'true' || _index >= 4) return - - _msg += col.label + '=\'\',' - _index++ - }) - } - _defaultsql += `insert into snote (remark,createuserid,CreateUser,CreateStaff,typename) select left('鍒犻櫎琛�:${card.sql} 鏁版嵁: ${_msg}${_primaryKey}='+@ID@,200),@userid@,@username,@fullname,@typename@ delete ${card.sql} where ${_primaryKey}${card.Ot !== 'requiredOnce' ? '=@ID@' : ' in (select ID from dbo.SplitComma(@ID@))'};` - } - - let _columns = [] - if (columns) { - _columns = fromJS(columns).toJS() - let hasbid = false - _columns = _columns.filter(col => { - if (col.field && col.field.toLowerCase() === 'bid') { - hasbid = true - } - - return !!col.field - }) - - if (!hasbid) { - _columns.unshift({ uuid: 'BID', field: 'BID', label: 'BID', type: 'text' }) - } - } - - this.setState({ - fields: _fields, - columnsFields: _columns, - initsql: _sql, - defaultsql: _defaultsql, - usefulfields: _usefulfields.join(', '), - uniqueColumns: this.state.uniqueColumns.map(col => { - if (col.dataIndex === 'field') { - col.options = uniqueFields - } - return col - }), - onceUniqueColumns: this.state.onceUniqueColumns.map(col => { - if (col.dataIndex === 'field') { - col.options = _columns - } - return col - }), - unionFields, - uniqueFields }) + } + + let _sql = `Declare ${_declare.join(', ')} + Select ${_select.join(', ')} + ` + + // 榛樿sql + let _defaultsql = '' + let _insertsql = '' + let _updatesql = '' + let _primaryKey = config.setting.primaryKey || 'id' + + if (this.props.side === 'sub') { + _primaryKey = config.setting.subKey || 'id' + } + + if (card.sqlType === 'insert' || card.sqlType === 'insertOrUpdate') { + let keys = [] + let values = [] + + _fields.forEach(item => { + if (!item.field || item.writein === 'false') return + + keys.push(item.field.toLowerCase()) + + if (item.field.toLowerCase() === 'bid' && item.uuid === 'BID') { + values.push('@BID@') + } else { + values.push('@' + item.field) + } + }) + + if (!keys.includes(_primaryKey.toLowerCase())) { + keys.push(_primaryKey.toLowerCase()) + values.push('@ID@') + } + if (!keys.includes('createuserid')) { + keys.push('createuserid') + values.push('@userid@') + } + if (!keys.includes('createuser')) { + keys.push('createuser') + values.push('@username') + } + if (!keys.includes('createstaff')) { + keys.push('createstaff') + values.push('@fullname') + } + if (!keys.includes('bid')) { + keys.push('bid') + values.push('@BID@') + } + if (!keys.includes('typename')) { + keys.push('typename') + values.push('@typename@') + } + + keys = keys.join(', ') + values = values.join(', ') + _insertsql = `insert into ${card.sql} (${keys}) select ${values};` + } + + if (card.sqlType === 'update' || card.sqlType === 'audit' || card.sqlType === 'insertOrUpdate') { + let _form = [] + let _arr = [] + + _fields.forEach(item => { + if (!item.field || item.writein === 'false' || item.uuid === 'BID') return + + _arr.push(item.field.toLowerCase()) + if (item.field.toLowerCase() === 'bid') { + _form.push(item.field + '=@BID@') + } else { + _form.push(item.field + '=@' + item.field) + } + }) + + if (this.props.card.sqlType === 'audit') { + if (!_arr.includes('submitdate')) { + _form.push('submitdate=getdate()') + } + if (!_arr.includes('submituser')) { + _form.push('submituser=@username') + } + if (!_arr.includes('submitstaff')) { + _form.push('submitstaff=@fullname') + } + if (!_arr.includes('submituserid')) { + _form.push('submituserid=@userid@') + } + if (!_arr.includes('typename')) { + _form.push(`typename=@typename@`) + } + } else { + if (!_arr.includes('modifydate')) { + _form.push('modifydate=getdate()') + } + if (!_arr.includes('modifyuser')) { + _form.push('modifyuser=@username') + } + if (!_arr.includes('modifystaff')) { + _form.push('modifystaff=@fullname') + } + if (!_arr.includes('modifyuserid')) { + _form.push('modifyuserid=@userid@') + } + if (!_arr.includes('typename')) { + _form.push(`typename=@typename@`) + } + } + + if (_verify.voucher && _verify.voucher.enabled) { + if (!_arr.includes('bvoucher')) { + _form.push('BVoucher=@BVoucher') + } + if (!_arr.includes('fibvoucherdate')) { + _form.push('FIBVoucherDate=@FIBVoucherDate') + } + if (!_arr.includes('fiyear')) { + _form.push('FiYear=@FiYear') + } + } + + _form = _form.join(', ') + _updatesql = `update ${card.sql} set ${_form} where ${_primaryKey}${card.Ot !== 'requiredOnce' ? '=@ID@' : ' in (select ID from dbo.SplitComma(@ID@))'};` + } + + if (card.sqlType === 'insert') { + _defaultsql = _insertsql + } else if (card.sqlType === 'update' || card.sqlType === 'audit') { + _defaultsql = _updatesql + } else if (card.sqlType === 'insertOrUpdate') { + _defaultsql += `select @tbid='' + select @tbid='X' from ${card.sql} where ${_primaryKey}=@ID@ + if @tbid='' + begin + ${_insertsql} + end + else + begin + ${_updatesql} + end + ` + } else if (card.sqlType === 'LogicDelete' || card.sqlType === 'custom') { + let _voucher = '' + if (_verify.voucher && _verify.voucher.enabled) { + _voucher = ',BVoucher=@BVoucher,FIBVoucherDate=@FIBVoucherDate,FiYear=@FiYear' + } + _defaultsql = `update ${card.sql} set deleted=@mk_deleted,modifydate=getdate(),modifyuser=@username,modifystaff=@fullname,modifyuserid=@userid@${_voucher} where ${_primaryKey}${card.Ot !== 'requiredOnce' ? '=@ID@' : ' in (select ID from dbo.SplitComma(@ID@))'};` + } else if (card.sqlType === 'delete') { + let _msg = '' + if (columns && columns.length > 0 && card.Ot !== 'notRequired') { + let _index = 0 + columns.forEach(col => { + if (!col.field || col.Hide === 'true' || _index >= 4) return + + _msg += col.label + '=\'\',' + _index++ + }) + } + _defaultsql += `insert into snote (remark,createuserid,CreateUser,CreateStaff,typename) select left('鍒犻櫎琛�:${card.sql} 鏁版嵁: ${_msg}${_primaryKey}='+@ID@,200),@userid@,@username,@fullname,@typename@ delete ${card.sql} where ${_primaryKey}${card.Ot !== 'requiredOnce' ? '=@ID@' : ' in (select ID from dbo.SplitComma(@ID@))'};` + } + + let _columns = [] + if (columns) { + _columns = fromJS(columns).toJS() + let hasbid = false + _columns = _columns.filter(col => { + if (col.field && col.field.toLowerCase() === 'bid') { + hasbid = true + } + + return !!col.field + }) + + if (!hasbid) { + _columns.unshift({ uuid: 'BID', field: 'BID', label: 'BID', type: 'text' }) + } + } + + this.setState({ + fields: _fields, + columnsFields: _columns, + initsql: _sql, + defaultsql: _defaultsql, + formfields: formfields.join(', '), + colfields: colfields.join(', '), + uniqueColumns: this.state.uniqueColumns.map(col => { + if (col.dataIndex === 'field') { + col.options = uniqueFields + } + return col + }), + onceUniqueColumns: this.state.onceUniqueColumns.map(col => { + if (col.dataIndex === 'field') { + col.options = _columns + } + return col + }), + unionFields, + uniqueFields }) } @@ -1082,12 +1119,13 @@ LText: mutilForms.join(' union all '), obj_name: '', arr_field: '', - table_type: 'Y' + table_type: 'Y', + exec_type: 'x' } - mutilparam.LText = Utils.formatOptions(mutilparam.LText) + mutilparam.LText = Utils.formatOptions(mutilparam.LText, 'x') mutilparam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') - mutilparam.secretkey = Utils.encrypt(mutilparam.LText, mutilparam.timestamp) + mutilparam.secretkey = Utils.encrypt('', mutilparam.timestamp) mutilparam.open_key = Utils.encryptOpenKey(mutilparam.secretkey, mutilparam.timestamp) if (window.GLOB.cloudServiceApi) { // 浜戠璇锋眰 @@ -1131,6 +1169,47 @@ duration: 5 }) } + }) + } + + orderSql = (record) => { + let _lpline = '' + if (record.TypeCharOne === 'Lp') { + if (record.linkField.toLowerCase() === 'bid') { + _lpline = `set @ModularDetailCode= 'Lp'+ right('${record.mark || this.props.card.uuid}'+@BID@,48)` + } else { + _lpline = `set @ModularDetailCode= 'Lp'+ right('${record.mark || this.props.card.uuid}'+@${record.linkField.toLowerCase()},48)` + } + } else if (record.TypeCharOne === 'BN') { + if (record.linkField.toLowerCase() === 'bid') { + _lpline = `set @ModularDetailCode= 'BN'+ right(@BID@,48)` + } else { + _lpline = `set @ModularDetailCode= 'BN'+ right(@${record.linkField.toLowerCase()},48)` + } + } else { + _lpline = `set @ModularDetailCode= right('${record.ModularDetailCode}',50)` + } + + let sql = `select @BillCode='', @${record.field}='', @ModularDetailCode='' + ${_lpline} + exec s_get_BillCode + @ModularDetailCode=@ModularDetailCode, + @Type=${record.Type}, + @TypeCharOne='${record.TypeCharOne}', + @TypeCharTwo ='${record.TypeCharTwo}', + @BillCode =@BillCode output, + @ErrorCode =@ErrorCode output, + @retmsg=@retmsg output + if @ErrorCode!='' + goto aaa + set @${record.field}=@BillCode` + + Modal.info({ + title: '', + width: 500, + className: 'sql-example', + icon: null, + content: sql.split(/\n\s{4}/ig).map((n, index) => <div key={index} dangerouslySetInnerHTML={{ __html: n.replace(/\s/ig, ' ') }} style={{whiteSpace: 'nowrap'}}></div>) }) } @@ -1183,6 +1262,8 @@ } scriptsChange = (values) => { + const { columns, card } = this.props + let verify = fromJS(this.state.verify).toJS() if (values.uuid) { @@ -1196,6 +1277,35 @@ } else { values.uuid = Utils.getuuid() verify.scripts.push(values) + } + + if (/@bvoucher(\s|\))/ig.test(values.sql) && !/s_BVoucher_Create/ig.test(values.sql)) { + if (verify.voucher && verify.voucher.enabled) { + + } else if (card.Ot !== 'notRequired' && columns) { + let hasvoucher = false + columns.forEach(_f => { + if (!_f.field) return + + if (_f.field.toLowerCase() === 'bvoucher') { + hasvoucher = true + } + }) + + if (!hasvoucher) { + notification.warning({ + top: 92, + message: '鏈惎鐢ㄥ垱寤哄嚟璇侊紝涓斿瓧娈甸泦涓笉瀛樺湪鍑瘉瀛楁锛坆voucher锛夈��', + duration: 5 + }) + } + } else { + notification.warning({ + top: 92, + message: '鏈惎鐢ㄥ垱寤哄嚟璇侊紝涓斿瓧娈甸泦涓笉瀛樺湪鍑瘉瀛楁锛坆voucher锛夈��', + duration: 5 + }) + } } MKEmitter.emit('editLineId', values.uuid) @@ -1469,7 +1579,7 @@ // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭� return new Promise((resolve, reject) => { - if ((card.sqlType === 'custom' || verify.default === 'false') && verify.scripts.length === 0) { + if ((card.sqlType === 'custom' || verify.default === 'false') && !(verify.workFlow === 'true' && verify.flowSql === 'true') && verify.scripts.length === 0) { notification.warning({ top: 92, message: '涓嶆墽琛岄粯璁ql鏃讹紝蹇呴』璁剧疆鑷畾涔夎剼鏈紒', @@ -1491,20 +1601,20 @@ msg = '鑷畾涔夎剼鏈�' } - if (window.GLOB.funcs && window.GLOB.funcs.length > 0) { - window.GLOB.funcs.forEach(m => { - let reg = new RegExp('\\$ex@' + m.func_code + '@ex\\$', 'ig') - verify.customverifys.forEach(item => { - item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`) - }) - verify.scripts.forEach(item => { - item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`) - }) - verify.cbScripts.forEach(item => { - item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`) - }) - }) - } + // if (window.GLOB.funcs && window.GLOB.funcs.length > 0) { + // window.GLOB.funcs.forEach(m => { + // let reg = new RegExp('\\$ex@' + m.func_code + '@ex\\$', 'ig') + // verify.customverifys.forEach(item => { + // item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`) + // }) + // verify.scripts.forEach(item => { + // item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`) + // }) + // verify.cbScripts.forEach(item => { + // item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`) + // }) + // }) + // } delete verify.limitInvalid delete verify.limitText @@ -1572,7 +1682,7 @@ render() { const { card, columns } = this.props - const { activeKey, verifyInter, verify, fields, uniqueFields, uniqueColumns, unionFields, onceUniqueColumns, columnsFields, contrastColumns, customColumns, orderColumns, scriptsColumns, cbScriptsColumns, orderModular, orderModularDetail, voucher, voucherDetail, notes, emailCodes, appType } = this.state + const { activeKey, verifyInter, verify, fields, uniqueFields, uniqueColumns, unionFields, onceUniqueColumns, columnsFields, contrastColumns, customColumns, orderColumns, scriptsColumns, cbScriptsColumns, orderModular, orderModularDetail, voucher, voucherDetail, notes, emailCodes, appType, formfields, colfields } = this.state const formItemLayout = { labelCol: { xs: { span: 24 }, @@ -1594,7 +1704,7 @@ {verify.default === 'false' ? <span className="count-tip"><ExclamationOutlined style={{color: 'orange'}}/></span> : null} </span> } key="base"> - <BaseForm card={card} appType={appType} columns={columns} unionFields={unionFields} verify={verify} notes={notes} emailCodes={emailCodes} onChange={(verify) => this.setState({verify})} wrappedComponentRef={(inst) => this.baseForm = inst}/> + <BaseForm card={card} appType={appType} fields={fields} columns={columns} unionFields={unionFields} verify={verify} notes={notes} emailCodes={emailCodes} onChange={(verify) => this.setState({verify})} wrappedComponentRef={(inst) => this.baseForm = inst}/> </TabPane> : null} {verifyInter === 'system' ? <TabPane tab={ <span> @@ -1603,7 +1713,7 @@ </span> } key="contrasts"> <ContrastForm contrastChange={this.contrastChange}/> - <EditTable actions={['edit', 'move', 'copy', 'del', 'status']} type="contrastverify" data={verify.contrasts} columns={contrastColumns} onChange={(contrasts) => this.setState({verify: {...verify, contrasts}})}/> + <EditTable actions={['edit', 'move', 'copy', 'del', 'status', 'sql']} type="contrastverify" data={verify.contrasts} columns={contrastColumns} onChange={(contrasts) => this.setState({verify: {...verify, contrasts}})}/> </TabPane> : null} {verifyInter === 'system' ? <TabPane tab={ <span> @@ -1614,7 +1724,8 @@ <CustomForm btn={this.props.card} initsql={this.state.initsql} - usefulfields={this.state.usefulfields} + formfields={formfields} + colfields={colfields} customChange={this.customChange} wrappedComponentRef={(inst) => this.customForm = inst} /> @@ -1649,7 +1760,7 @@ fields={card.Ot !== 'requiredOnce' ? uniqueFields : columnsFields} uniqueChange={this.uniqueChange} /> - <EditTable actions={['edit', 'move', 'del', 'status']} data={verify.uniques} columns={card.Ot !== 'requiredOnce' ? uniqueColumns : onceUniqueColumns} onChange={this.changeUniques}/> + <EditTable actions={['edit', 'move', 'del', 'status', 'sql']} data={verify.uniques} columns={card.Ot !== 'requiredOnce' ? uniqueColumns : onceUniqueColumns} onChange={this.changeUniques}/> </TabPane> : null} {verifyInter === 'system' ? <TabPane tab={ <span> @@ -1683,9 +1794,15 @@ type="fullscreen" btn={this.props.card} initsql={this.state.initsql} + workFlow={verify.workFlow} + flowRemark={verify.flowRemark} + flowType={verify.flowType} + flowSql={verify.flowSql} customScripts={verify.scripts} + useDefaultSql={verify.default !== 'false'} defaultsql={this.state.defaultsql} - usefulfields={this.state.usefulfields} + formfields={formfields} + colfields={colfields} systemScripts={this.state.systemScripts} scriptsChange={this.scriptsChange} wrappedComponentRef={(inst) => this.scriptsFullForm = inst} @@ -1695,10 +1812,14 @@ btn={this.props.card} initsql={this.state.initsql} workFlow={verify.workFlow} + flowRemark={verify.flowRemark} flowType={verify.flowType} + flowSql={verify.flowSql} customScripts={verify.scripts} + useDefaultSql={verify.default !== 'false'} defaultsql={this.state.defaultsql} - usefulfields={this.state.usefulfields} + formfields={formfields} + colfields={colfields} systemScripts={this.state.systemScripts} scriptsChange={this.scriptsChange} wrappedComponentRef={(inst) => this.scriptsForm = inst} @@ -1723,7 +1844,8 @@ btn={this.props.card} initsql={this.state.initsql} customScripts={verify.cbScripts} - usefulfields={this.state.usefulfields} + formfields={formfields} + colfields={colfields} systemScripts={this.state.systemScripts} scriptsChange={this.cbScriptsChange} wrappedComponentRef={(inst) => this.cbscriptsFullForm = inst} @@ -1733,7 +1855,8 @@ btn={this.props.card} initsql={this.state.initsql} customScripts={verify.cbScripts} - usefulfields={this.state.usefulfields} + formfields={formfields} + colfields={colfields} systemScripts={this.state.systemScripts} scriptsChange={this.cbScriptsChange} wrappedComponentRef={(inst) => this.cbscriptsForm = inst} -- Gitblit v1.8.0