From ae170a9d58b4f91a225eada1dc83ed4a116b8d50 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期日, 25 八月 2024 00:57:37 +0800 Subject: [PATCH] 2024-08-25 --- src/templates/sharecomponent/actioncomponent/verifyexcelin/index.jsx | 243 +++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 199 insertions(+), 44 deletions(-) diff --git a/src/templates/sharecomponent/actioncomponent/verifyexcelin/index.jsx b/src/templates/sharecomponent/actioncomponent/verifyexcelin/index.jsx index 5dd577b..f22a3ef 100644 --- a/src/templates/sharecomponent/actioncomponent/verifyexcelin/index.jsx +++ b/src/templates/sharecomponent/actioncomponent/verifyexcelin/index.jsx @@ -19,7 +19,9 @@ const { confirm } = Modal const { Search } = Input const { Paragraph } = Typography + const EditTable = asyncComponent(() => import('@/templates/zshare/editTable')) +const CodeMirror = asyncComponent(() => import('@/templates/zshare/codemirror')) const FullScripts = asyncComponent(() => import('@/templates/zshare/verifycard/fullScripts')) class VerifyCard extends Component { @@ -203,6 +205,89 @@ </div> ) }, + { + dataIndex: 'sqlRender', + render: (record) => { + let columns = this.state.verify.columns + + let textFields = [] + let numberFields = [] + let dateFields = [] + columns.forEach((col) => { + if (/Nvarchar/ig.test(col.type)) { + textFields.push(col.Column) + } else if (/Decimal|int/ig.test(col.type)) { + numberFields.push(col.Column) + } else if (/date/ig.test(col.type)) { + dateFields.push(col.Column) + } + }) + + let _fields = record.field.split(',') + let _fields_ = _fields.map(_field => `a.${_field}=b.${_field}`) + _fields_ = _fields_.join(' and ') + + let _where = [] + _fields.forEach(f => { + if (textFields.includes(f)) { + _where.push(`${f}!=''`) + } else if (numberFields.includes(f)) { + _where.push(`${f}!=0`) + } else if (dateFields.includes(f)) { + _where.push(`${f}>'1949-10-01'`) + } + }) + _where = _where.length ? `where ${_where.join(' and ')} ` : '' + + if (record.verifyType === 'logic' || record.verifyType === 'logic_temp') { + _fields_ += ' and b.deleted=0' + } + + let _afields = [] + _fields = _fields.map(f => { + if (numberFields.includes(f)) { + _afields.push(`cast(a.${f} as nvarchar(50))`) + return `cast(${f} as nvarchar(50))` + } else if (dateFields.includes(f)) { + _afields.push(`CONVERT(nvarchar(50), a.${f}, 21)`) + return `CONVERT(nvarchar(50), ${f}, 21)` + } + _afields.push(`a.${f}`) + + return f + }) + + let _sheet = this.props.card.sheet + + let database = _sheet.match(/(.*)\.(.*)\.|@db@/ig) || '' + let sheet = _sheet.replace(/(.*)\.(.*)\.|@db@/ig, '') + + database = database ? (database[0] || '') : '' + + let sql = ` + /* 閲嶅鎬ч獙璇� */ + Set @tbid='' + Select top 1 @tbid=${_fields.join('+\' \'+')} from (select 1 as n,${record.field} from #${sheet} ${_where}) a group by ${record.field} having sum(n)>1 + + If @tbid!='' + Begin + select @ErrorCode='${record.errorCode}',@retmsg=@tbid+' 閲嶅' + goto aaa + end + + ${record.verifyType.indexOf('temp') === -1 ? `Set @tbid='' + Select top 1 @tbid=${_afields.join('+\' \'+')} from ${_where ? `(select * from #${sheet} ${_where})` : `#${sheet}`} a Inner join ${database}${sheet} b on ${_fields_} + + If @tbid!='' + Begin + select @ErrorCode='${record.errorCode}',@retmsg=@tbid+' 涓庡凡鏈夋暟鎹噸澶�' + goto aaa + end` : ''} + ` + + return sql.split(/\n\s{10}/ig).map(n => n.replace(/^\s{2}/ig, ' ')) + } + } ], scriptsColumns: [ { @@ -307,17 +392,27 @@ _verify.range = 1 } + _verify.excelHandle = _verify.excelHandle || 'false' + _verify.default = _verify.default || 'true' + _verify.sheet = _verify.sheet || 'Sheet1' + _verify.range = _verify.range || 0 + _verify.columns = _columns + _verify.scripts = _verify.scripts || [] + _verify.uniques = _verify.uniques || [] + + if (window.GLOB.process && card.intertype === 'system') { + _verify.workFlow = _verify.workFlow || 'false' + _verify.flowType = 'start' + _verify.flowSql = _verify.flowSql || 'true' + } else { + delete _verify.workFlow + delete _verify.flowType + delete _verify.flowSql + } + this.setState({ searchKey: '', - verify: { - ..._verify, - default: _verify.default || 'true', - sheet: _verify.sheet || 'Sheet1', - range: _verify.range || 0, - columns: _columns, - scripts: _verify.scripts || [], - uniques: _verify.uniques || [] - } + verify: _verify }, () => { this.resetUniqueColumns() }) @@ -501,25 +596,25 @@ clearField = () => { const { verify } = this.state - const _this = this + const that = this confirm({ content: `纭畾娓呯┖Excel鍒楀悧锛焋, onOk() { - _this.setState({ + that.setState({ verify: { ...verify, columns: [] } }, () => { - _this.resetUniqueColumns() + that.resetUniqueColumns() }) }, onCancel() {} }) } - columnChange = (values) => { + columnChange = (values, callback) => { let verify = JSON.parse(JSON.stringify(this.state.verify)) let fields = verify.columns.map(item => item.Column) @@ -530,6 +625,8 @@ duration: 5 }) return + } else { + callback() } values.uuid = Utils.getuuid() @@ -712,33 +809,44 @@ if (!err) { let _verify = {...verify, ...values} + if (_verify.excelHandle !== 'true') { + delete _verify.excel_func + } + if (_verify.default === 'false' && _verify.scripts.length === 0) { + notification.warning({ + top: 92, + message: '涓嶆墽琛岄粯璁ql鏃讹紝蹇呴』璁剧疆鑷畾涔夎剼鏈紒', + duration: 5 + }) + return + } + let cols = _verify.columns.map(col => col.Column.toLowerCase()) cols = Array.from(new Set(cols)) + let error = '' if (_verify.columns.length === 0) { - notification.warning({ - top: 92, - message: '璇疯缃瓻xcel鍒楀瓧娈�!', - duration: 5 - }) - return + error = '璇疯缃瓻xcel鍒楀瓧娈�!' } else if (_verify.columns.length > cols.length) { - notification.warning({ - top: 92, - message: 'Excel鍒楀瓧娈靛悕锛屼笉鍙噸澶�!', - duration: 5 - }) - return + error = 'Excel鍒楀瓧娈靛悕锛屼笉鍙噸澶�!' + } else if (cols.includes('bid')) { + error = 'bid瀛楁涓轰繚鐣欏瓧锛屼笉鍙娇鐢�!' + } else if (cols.includes('jskey')) { + error = 'jskey瀛楁涓轰繚鐣欏瓧锛屼笉鍙娇鐢�!' } else if (_verify.range === 1) { let tEmptys = _verify.columns.filter(op => !op.Text) if (tEmptys.length > 0) { - notification.warning({ - top: 92, - message: '蹇界暐棣栬鏃讹紝浼氫娇鐢═ext鍊兼牎楠孍xcel棣栬鍐呭锛孴ext鍊间笌Excel琛ㄩ琛屽唴瀹圭浉鍚岋紝涓斿潎涓嶅彲涓虹┖锛�', - duration: 5 - }) - return + error = '蹇界暐棣栬鏃讹紝浼氫娇鐢═ext鍊兼牎楠孍xcel棣栬鍐呭锛孴ext鍊间笌Excel琛ㄩ琛屽唴瀹圭浉鍚岋紝涓斿潎涓嶅彲涓虹┖锛�' } + } + + if (error) { + notification.warning({ + top: 92, + message: error, + duration: 5 + }) + return } _verify.columns.sort((a, b) => { @@ -771,22 +879,17 @@ resolve(_verify) } } else { - notification.warning({ - top: 92, - message: '璇疯缃瓻xcel琛ㄥ悕!', - duration: 5 - }) + this.setState({activeKey: 'basemsg'}) } }) }) } - onOptionChange = (e, key) => { + onOptionChange = (value, key) => { const { verify } = this.state - let value = e.target.value this.setState({ - verify: {...verify, default: value} + verify: {...verify, [key]: value} }) } @@ -867,7 +970,31 @@ <TabPane tab="鍩虹楠岃瘉" key="basemsg"> <Form {...formItemLayout}> <Row gutter={24}> + {card.intertype === 'system' ? <Col span={8}> + <Form.Item label="榛樿sql"> + <Radio.Group value={verify.default} onChange={(e) => this.onOptionChange(e.target.value, 'default')}> + <Radio value="true">鎵ц</Radio> + <Radio value="false">涓嶆墽琛�</Radio> + </Radio.Group> + </Form.Item> + </Col> : null} <Col span={8}> + <Form.Item label={ + <Tooltip placement="topRight" title="鑷畾涔夐獙璇丒xcel鏍煎紡锛屽彲鐢ㄥ弬鏁颁负 XLSX銆亀orkbook銆乥tn銆乧allback銆�"> + <QuestionCircleOutlined className="mk-form-tip" /> + 瀵煎叆鏍煎紡 + </Tooltip> + }> + {getFieldDecorator('excelHandle', { + initialValue: verify.excelHandle + })( + <Radio.Group onChange={(e) => this.onOptionChange(e.target.value, 'excelHandle')}> + <Radio value="false">榛樿</Radio> + <Radio value="true">鑷畾涔�</Radio> + </Radio.Group>)} + </Form.Item> + </Col> + {verify.excelHandle !== 'true' ? <Col span={8}> <Form.Item label={ <Tooltip placement="bottomLeft" title="瀵煎叆鏃跺伐浣滆〃鍚嶄笌excel涓繀椤讳竴鑷达紝娉細宸ヤ綔琛ㄥ悕涓篠heet1涓攅xcel涓粎鏈変竴涓伐浣滆〃鏃朵笉杩涜琛ㄥ悕楠岃瘉銆�"> <QuestionCircleOutlined className="mk-form-tip" /> @@ -884,7 +1011,7 @@ ] })(<Input placeholder="" autoComplete="off" />)} </Form.Item> - </Col> + </Col> : null} <Col span={8}> <Form.Item label={ <Tooltip placement="bottomLeft" title="蹇界暐棣栬鏃讹紝浼氭牎楠宔xcel涓〃澶村悕绉颁笌excel鍒楄缃槸鍚︿竴鑷淬��"> @@ -897,9 +1024,35 @@ })(<InputNumber min={0} max={100} precision={0} />)} </Form.Item> </Col> - {card.intertype === 'system' ? <Col span={8}> - <Form.Item label={'榛樿sql'}> - <Radio.Group value={verify.default} onChange={this.onOptionChange}> + {verify.excelHandle === 'true' ? <Col span={24} style={{paddingLeft: '30px'}}> + <Form.Item wrapperCol={ {xs: { span: 24 }, sm: { span: 24 }} } label=""> + {getFieldDecorator('excel_func', { + initialValue: verify.excel_func || '', + rules: [ + { + required: true, + message: '璇峰~鍐欒嚜瀹氫箟閫昏緫!' + } + ] + })(<CodeMirror mode="text/javascript" theme="cobalt" />)} + </Form.Item> + </Col> : null} + {window.GLOB.process && card.intertype === 'system' ? <Col span={8}> + <Form.Item label={ + <Tooltip placement="bottomLeft" title="瀵煎叆Excel宸ヤ綔娴佷粎鏀寔鍙戣捣娴佺▼銆�"> + <QuestionCircleOutlined className="mk-form-tip" /> + 宸ヤ綔娴� + </Tooltip> + }> + <Radio.Group value={verify.workFlow} onChange={(e) => {this.onOptionChange(e.target.value, 'workFlow')}}> + <Radio value="true">寮�鍚�</Radio> + <Radio value="false">涓嶅紑鍚�</Radio> + </Radio.Group> + </Form.Item> + </Col> : null} + {verify.workFlow === 'true' ? <Col span={8}> + <Form.Item label="榛樿sql锛堝伐浣滄祦锛�"> + <Radio.Group value={verify.flowSql} onChange={(e) => {this.onOptionChange(e.target.value, 'flowSql')}}> <Radio value="true">鎵ц</Radio> <Radio value="false">涓嶆墽琛�</Radio> </Radio.Group> @@ -931,7 +1084,7 @@ </span> } key="unique"> <UniqueForm fields={verify.columns} uniqueChange={this.uniqueChange}/> - <EditTable actions={['edit', 'move', 'del', 'status']} data={verify.uniques} columns={uniqueColumns} onChange={this.changeUniques}/> + <EditTable actions={['edit', 'move', 'del', 'status', 'sql']} data={verify.uniques} columns={uniqueColumns} onChange={this.changeUniques}/> </TabPane> : null} {card.intertype === 'system' ? <TabPane tab={ <span> @@ -951,6 +1104,7 @@ btn={this.props.card} usefulfields={verify.columns} scripts={verify.scripts} + workFlow={verify.workFlow} systemScripts={this.state.systemScripts} scriptsChange={this.scriptsChange} wrappedComponentRef={(inst) => this.scriptsFullForm = inst} @@ -960,6 +1114,7 @@ btn={this.props.card} usefulfields={verify.columns} scripts={verify.scripts} + workFlow={verify.workFlow} systemScripts={this.state.systemScripts} scriptsChange={this.scriptsChange} wrappedComponentRef={(inst) => this.scriptsForm = inst} -- Gitblit v1.8.0