From d49124329b0119ba0ce7c69afbe2b864209e2495 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 25 十月 2023 11:58:11 +0800
Subject: [PATCH] 2023-10-25

---
 src/templates/sharecomponent/actioncomponent/verifyexcelin/customscript/index.jsx |  132 ++++++++++++++++++++++++++------------------
 1 files changed, 78 insertions(+), 54 deletions(-)

diff --git a/src/templates/sharecomponent/actioncomponent/verifyexcelin/customscript/index.jsx b/src/templates/sharecomponent/actioncomponent/verifyexcelin/customscript/index.jsx
index 2895d40..73b091b 100644
--- a/src/templates/sharecomponent/actioncomponent/verifyexcelin/customscript/index.jsx
+++ b/src/templates/sharecomponent/actioncomponent/verifyexcelin/customscript/index.jsx
@@ -1,9 +1,8 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Form, Row, Col, Button, notification, Modal, Tooltip, Radio, Select } from 'antd'
+import { Form, Row, Col, Button, notification, Modal, Tooltip, Radio, Select, Switch } from 'antd'
 import { QuestionCircleOutlined } from '@ant-design/icons'
-import moment from 'moment'
 
 import Utils from '@/utils/utils.js'
 import Api from '@/api'
@@ -23,6 +22,7 @@
     editItem: null,
     usefulfields: null,
     loading: false,
+    skip: false,
     verifySql: ''
   }
 
@@ -44,12 +44,13 @@
     fields.push('jskey')
 
     let _dec = columns.map(item => item.Column + ' ' + item.type).join(',')
+    let sheet = btn.sheet.replace(/(.*)\.(.*)\.|@db@/ig, '')
 
     if (_dec) {
       _dec += ','
     }
 
-    let _sql = `Declare @${btn.sheet.replace(/@db@/ig, '')} table (${_dec}jskey nvarchar(50) )
+    let _sql = `create table #${sheet} (${_dec}jskey nvarchar(50),BID nvarchar(50) )
       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),@tbid Nvarchar(512)
       Select @ErrorCode='', @retmsg=''
     `
@@ -80,8 +81,8 @@
   }
 
   handleConfirm = () => {
-    const { type } = this.props
-    const { editItem } = this.state
+    const { type, btn } = this.props
+    const { editItem, skip } = this.state
 
     // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
     this.props.form.validateFieldsAndScroll((err, values) => {
@@ -105,6 +106,7 @@
         }
         
         values.uuid = editItem ? editItem.uuid : ''
+        values.position = values.position || (editItem ? editItem.position : 'front')
 
         if (type === 'fullscreen' && editItem) {
           values.status = editItem.status || 'true'
@@ -146,6 +148,25 @@
             duration: 5
           })
           return
+        } else if (/\son\s+[a-z0-9_]+\.[a-z0-9_]+\s*=\s*[a-z0-9_]+\.[a-z0-9_]+/ig.test(values.sql)) {
+          let list = values.sql.match(/\son\s+[a-z0-9_]+\.[a-z0-9_]+\s*=\s*[a-z0-9_]+\.[a-z0-9_]+/ig)
+          let errors = []
+          list.forEach(str => {
+            str = str.replace(/^\s/, '')
+            let strs = str.match(/(\s|=)[a-z0-9_]+\./ig)
+            if (strs.length === 2 && (strs[0].replace(/\s|\./g, '') === strs[1].replace(/\s|\./g, ''))) {
+              errors.push(str)
+            }
+          })
+
+          if (errors.length > 0) {
+            notification.warning({
+              top: 92,
+              message: '涓嶅彲浣跨敤鍚屼竴涓〃瀛楁杩涜鍏宠仈锛�' + errors.join('銆�'),
+              duration: 5
+            })
+            return
+          }
         }
 
         let error = Utils.verifySql(values.sql, 'customscript')
@@ -159,8 +180,10 @@
           return
         }
 
+        let sheet = btn.sheet.replace(/(.*)\.(.*)\.|@db@/ig, '')
         let tail = `
-          aaa:
+          drop table #${sheet}
+          aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg
         `
 
         let _initCustomScript = '' // 鍒濆鍖栬剼鏈�
@@ -207,44 +230,41 @@
           }
         }
 
-        let param = {
-          func: 's_debug_sql',
-          exec_type: 'y',
-          LText: this.state.verifySql + _initCustomScript + _prevCustomScript + _backCustomScript + tail
-        }
-
-        param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
-        param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/\$check@|@check\$/ig, '').replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|typename)@/ig, `'${param.timestamp}'`)
-        param.LText = param.LText.replace(/\n/g, ' ')
+        let sql = this.state.verifySql + _initCustomScript + _prevCustomScript + _backCustomScript + tail
+        sql = sql.replace(/@\$|\$@/ig, '').replace(/\$check@|@check\$/ig, '').replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|datam|typename)@/ig, `'1949-10-01 15:00:00'`)
         
-        // 澶栬仈鏁版嵁搴撴浛鎹�
-        if (window.GLOB.externalDatabase !== null) {
-          param.LText = param.LText.replace(/@db@/ig, window.GLOB.externalDatabase)
+        if (skip) {
+          this.setState({
+            skip: false,
+            editItem: null
+          }, () => {
+            this.props.scriptsChange(values)
+          })
+          this.props.form.setFieldsValue({
+            sql: ' '
+          })
+        } else {
+          this.setState({loading: true})
+          Api.sDebug(sql).then(res => {
+            if (res.status || res.ErrCode === '-2') {
+              this.setState({
+                loading: false,
+                editItem: null
+              }, () => {
+                this.props.scriptsChange(values)
+              })
+              this.props.form.setFieldsValue({
+                sql: ' '
+              })
+            } else {
+              this.setState({loading: false})
+  
+              Modal.error({
+                title: res.message
+              })
+            }
+          })
         }
-
-        param.LText = Utils.formatOptions(param.LText)
-        param.secretkey = Utils.encrypt('', param.timestamp)
-        
-        this.setState({loading: true})
-        Api.genericInterface(param).then(res => {
-          if (res.status) {
-            this.setState({
-              loading: false,
-              editItem: null
-            }, () => {
-              this.props.scriptsChange(values)
-            })
-            this.props.form.setFieldsValue({
-              sql: ' '
-            })
-          } else {
-            this.setState({loading: false})
-
-            Modal.error({
-              title: res.message
-            })
-          }
-        })
       }
     })
   }
@@ -276,7 +296,7 @@
 
       database = database ? (database[0] || '') : ''
 
-      _value = `Insert into ${database}${sheet} (${fields}createuserid,createuser,createstaff,bid)\nSelect ${fields}@userid@,@username,@fullname,@BID@ From @${sheet}`
+      _value = `Insert into ${database}${sheet} (${fields}createuserid,createuser,createstaff,bid)\nSelect ${fields}@userid@,@username,@fullname,@BID@ From #${sheet}`
     } else {
       _value = value
     }
@@ -304,7 +324,7 @@
 
   render() {
     const { systemScripts, btn, type } = this.props
-    const { usefulfields, editItem } = this.state
+    const { usefulfields, editItem, skip } = this.state
     const { getFieldDecorator } = this.props.form
     const formItemLayout = {
       labelCol: {
@@ -321,17 +341,17 @@
       <Form {...formItemLayout} className="verify-form" id="verify-excelin-custom-scripts">
         <Row gutter={24}>
           {!type && btn.sheet ? <Col span={8}>
-            <Form.Item label={'琛ㄥ悕'} style={{whiteSpace: 'nowrap', margin: 0}}>
-              {btn.sheet}
+            <Form.Item label="琛ㄥ悕" style={{whiteSpace: 'nowrap', margin: 0}}>
+              {btn.sheet}锛堣〃鍙橀噺璇蜂娇鐢�#{btn.sheet.replace(/(.*)\.(.*)\.|@db@/ig, '')}锛�
             </Form.Item>
           </Col> : null}
           {!type ? <Col span={10}>
-            <Form.Item label={'鎶ラ敊瀛楁'} style={{margin: 0, whiteSpace: 'nowrap'}}>
-              ErrorCode锛堝鍔犲悗缂�NT琛ㄧず鏁版嵁涓嶅洖婊氾紝濡侲NT銆丯NT銆丗NT銆丯MNT锛�, retmsg
+            <Form.Item label="鎶ラ敊瀛楁" style={{margin: 0, whiteSpace: 'nowrap'}}>
+              ErrorCode锛堝鍔犲悗缂�NT琛ㄧず鏁版嵁涓嶅洖婊氾紝濡侲NT銆丯NT銆丗NT銆丯MNT銆丆NT銆�-2NT锛�, retmsg
             </Form.Item>
           </Col> : null}
           {!type ? <Col span={24} className="sqlfield">
-            <Form.Item label={'鍙敤瀛楁'}>
+            <Form.Item label="鍙敤瀛楁">
               <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'鍏叡鍊硷紝璇锋寜鐓xxx@鏍煎紡浣跨敤銆�'}><span style={{color: '#1890ff'}}>BID, ID, LoginUID, SessionUid, UserID, Appkey, time_id, typename</span></Tooltip>,&nbsp;
               <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'绯荤粺鍙橀噺锛岀郴缁熶細瀹氫箟鍙橀噺骞惰祴鍊笺��'}><span style={{color: '#fa8c16'}}>UserName, FullName, RoleID, mk_departmentcode, mk_organization, mk_user_type, mk_nation, mk_province, mk_city, mk_district, mk_address</span></Tooltip>,&nbsp;
               {usefulfields}
@@ -339,7 +359,7 @@
           </Col> : null}
           {!type ? <Col span={8} style={{whiteSpace: 'nowrap'}}>
             <Form.Item style={{marginBottom: 0}} label={
-              <Tooltip placement="bottomLeft" title={'鑷畾涔夎剼鏈笌榛樿sql浣嶇疆鍏崇郴銆�'}>
+              <Tooltip placement="bottomLeft" title="鑷畾涔夎剼鏈笌榛樿sql浣嶇疆鍏崇郴銆�">
                 <QuestionCircleOutlined className="mk-form-tip" />
                 鎵ц浣嶇疆
               </Tooltip>
@@ -355,8 +375,8 @@
               )}
             </Form.Item>
           </Col> : null}
-          {!type ? <Col span={10}>
-            <Form.Item style={{marginBottom: 0}} label={'蹇嵎娣诲姞'}>
+          {!type ? <Col span={8}>
+            <Form.Item style={{marginBottom: 0}} label="蹇嵎娣诲姞">
               <Select
                 showSearch
                 filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
@@ -377,7 +397,7 @@
               </Select>
             </Form.Item>
           </Col> : null}
-          <Col span={6} className="add">
+          <Col span={5} className="add" style={{paddingTop: '2px', whiteSpace: 'nowrap'}}>
             <Button onClick={this.handleConfirm} loading={this.state.loading} className="mk-green" style={{marginBottom: 15, marginLeft: 40}}>
             {type === 'fullscreen' && !editItem ? '娣诲姞' : '淇濆瓨'}
             </Button>
@@ -385,8 +405,12 @@
               鍙栨秷
             </Button>
           </Col>
+          <Col span={3} style={{paddingTop: '15px', fontSize: '12px', whiteSpace: 'nowrap'}}>
+            寮哄埗淇濆瓨锛�
+            <Switch checked={skip} size="small" onChange={() => this.setState({skip: !skip})}/>
+          </Col>
           <Col span={24} className="sql">
-            <Form.Item label={'sql'}>
+            <Form.Item label="sql">
               {getFieldDecorator('sql', {
                 initialValue: '',
                 rules: [

--
Gitblit v1.8.0