From 5e82b0ad1b94b8d2d9603fb9384346e6be60d5ab Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 08 八月 2023 14:03:34 +0800
Subject: [PATCH] 2023-08-08

---
 src/templates/sharecomponent/actioncomponent/verifyexcelout/customscript/index.jsx |  263 ++++++++++++++++++++++++----------------------------
 1 files changed, 120 insertions(+), 143 deletions(-)

diff --git a/src/templates/sharecomponent/actioncomponent/verifyexcelout/customscript/index.jsx b/src/templates/sharecomponent/actioncomponent/verifyexcelout/customscript/index.jsx
index 32bba04..76aa845 100644
--- a/src/templates/sharecomponent/actioncomponent/verifyexcelout/customscript/index.jsx
+++ b/src/templates/sharecomponent/actioncomponent/verifyexcelout/customscript/index.jsx
@@ -1,8 +1,7 @@
 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 { QuestionCircleOutlined } from '@ant-design/icons'
+import { Form, Row, Col, Button, notification, Tooltip, Select, Switch } from 'antd'
 import moment from 'moment'
 
 import Api from '@/api'
@@ -12,39 +11,101 @@
 
 class CustomForm extends Component {
   static propTpyes = {
-    scripts: PropTypes.array,       // 鑷畾涔夎剼鏈垪琛�
-    usefulfields: PropTypes.any,    // 鍙敤瀛楁
-    systemScripts: PropTypes.array, // 绯荤粺鑴氭湰
-    scriptsChange: PropTypes.func   // 琛ㄥ崟
+    searches: PropTypes.any,        // 鎼滅储鏉′欢
+    linefields: PropTypes.any,
+    scriptsChange: PropTypes.func
   }
 
   state = {
     editItem: null,
+    systemScripts: [],
     usefulfields: null,
     loading: false,
-    verifySql: ''
+    skip: false
   }
 
   UNSAFE_componentWillMount () {
-    this.resetfield(this.props.usefulfields)
+    this.resetfield(this.props.searches)
   }
 
-  UNSAFE_componentWillReceiveProps (nextProps) {
-    if (nextProps.usefulfields && !is(fromJS(this.props.usefulfields), fromJS(nextProps.usefulfields))) {
-      this.resetfield(nextProps.usefulfields)
+  UNSAFE_componentWillReceiveProps(nextProps) {
+    if (!is(fromJS(this.props.searches), fromJS(nextProps.searches))) {
+      this.resetfield(nextProps.searches)
     }
   }
 
-  resetfield = (columns) => {
-    columns = columns.filter(item => item.Column !== '$Index')
-    let fields = columns.map(item => item.Column)
+  componentDidMount () {
+    this.getsysScript()
+  }
 
-    let _sql = `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)
-    `
+  getsysScript = () => {
+    if (sessionStorage.getItem('mk_sys_scripts')) {
+      this.setState({
+        systemScripts: JSON.parse(sessionStorage.getItem('mk_sys_scripts'))
+      })
+      return
+    }
     
+    let _scriptSql = `Select distinct func+Remark as funcname,longparam, s.Sort from聽 s_custom_script s inner join (select OpenID from sapp where ID=@Appkey@) p on s.openid = case when s.appkey='' then s.openid else p.OpenID end order by s.Sort`
+
+    _scriptSql = Utils.formatOptions(_scriptSql)
+
+    let _sParam = {
+      func: 'sPC_Get_SelectedList',
+      LText: _scriptSql,
+      obj_name: 'data',
+      arr_field: 'funcname,longparam'
+    }
+    
+    _sParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+    _sParam.secretkey = Utils.encrypt(_sParam.LText, _sParam.timestamp)
+    _sParam.open_key = Utils.encryptOpenKey(_sParam.secretkey, _sParam.timestamp) // 浜戠鏁版嵁楠岃瘉
+    
+    Api.getCloudConfig(_sParam).then(res => {
+      if (res.status) {
+        let _scripts = res.data.map(item => {
+          return {
+            name: item.funcname,
+            value: window.decodeURIComponent(window.atob(item.longparam))
+          }
+        })
+
+        sessionStorage.setItem('mk_sys_scripts', JSON.stringify(_scripts))
+
+        this.setState({
+          systemScripts: _scripts
+        })
+      } else {
+        notification.warning({
+          top: 92,
+          message: res.message,
+          duration: 5
+        })
+      }
+    })
+  }
+
+  resetfield = (searches) => {
+    let _usefulFields = []
+    searches.forEach(item => {
+      if (!item.field) return
+
+      if (item.type === 'group') {
+        _usefulFields.push(item.field)
+        _usefulFields.push(item.datefield)
+        _usefulFields.push(item.datefield + '1')
+      } else if (['dateweek', 'datemonth', 'daterange'].includes(item.type)) {
+        _usefulFields.push(item.field)
+        _usefulFields.push(item.field + '1')
+      } else if (item.type === 'date' && _usefulFields.includes(item.field)) {
+        _usefulFields.push(item.field + '1')
+      } else {
+        _usefulFields.push(item.field)
+      }
+    })
+
     this.setState({
-      verifySql: _sql,
-      usefulfields: fields.join(', ')
+      usefulfields: _usefulFields.join(', ')
     })
   }
 
@@ -54,12 +115,12 @@
     })
 
     this.props.form.setFieldsValue({
-      sql: record.sql,
-      position: record.position || 'back'
+      sql: record.sql
     })
   }
 
   handleConfirm = () => {
+    const { skip } = this.state
     // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
     this.props.form.validateFieldsAndScroll((err, values) => {
       if (!err) {
@@ -103,6 +164,13 @@
             duration: 5
           })
           return
+        } else if (/,,/ig.test(values.sql)) {
+          notification.warning({
+            top: 92,
+            message: '鑷畾涔塻ql璇彞涓紝涓嶅彲鍑虹幇杩炵画鐨勮嫳鏂囬�楀彿锛�,,锛�',
+            duration: 5
+          })
+          return
         }
 
         let error = Utils.verifySql(values.sql, 'customscript')
@@ -116,91 +184,26 @@
           return
         }
 
-        let tail = `
-          aaa:
-        `
-
-        let _initCustomScript = '' // 鍒濆鍖栬剼鏈�
-        let _prevCustomScript = '' // 榛樿sql鍓嶆墽琛岃剼鏈�
-        let _backCustomScript = '' // 榛樿sql鍚庢墽琛岃剼鏈�
-
-        this.props.scripts.forEach(item => {
-          if (item.status === 'false') return
-
-          if (item.position === 'init') {
-            _initCustomScript += `
-            /* 鍒濆鍖栬剼鏈� */
-            ${values.uuid === item.uuid ? values.sql : item.sql}
-            `
-          } else if (item.position === 'front') {
-            _prevCustomScript += `
-            /* 榛樿sql鍓嶈剼鏈� */
-            ${values.uuid === item.uuid ? values.sql : item.sql}
-            `
-          } else {
-            _backCustomScript += `
-            /* 榛樿sql鍚庤剼鏈� */
-            ${values.uuid === item.uuid ? values.sql : item.sql}
-            `
-          }
+        this.setState({
+          loading: true
         })
 
-        if (!values.uuid) {
-          if (values.position === 'init') {
-            _initCustomScript += `
-            /* 鍒濆鍖栬剼鏈� */
-            ${values.sql}
-            `
-          } else if (values.position === 'front') {
-            _prevCustomScript += `
-            /* 榛樿sql鍓嶈剼鏈� */
-            ${values.sql}
-            `
-          } else {
-            _backCustomScript += `
-            /* 榛樿sql鍚庤剼鏈� */
-            ${values.sql}
-            `
-          }
-        }
-
-        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(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id)@/ig, `'${param.timestamp}'`)
-
-        // 澶栬仈鏁版嵁搴撴浛鎹�
-        if (window.GLOB.externalDatabase !== null) {
-          param.LText = param.LText.replace(/@db@/ig, window.GLOB.externalDatabase)
-        }
-
-        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.props.scriptsChange(values, (status) => {
+          if (status) {
             this.setState({
+              skip: false,
               loading: false,
               editItem: null
-            }, () => {
-              this.props.scriptsChange(values)
             })
             this.props.form.setFieldsValue({
-              sql: ''
+              sql: ' '
             })
           } else {
-            this.setState({loading: false})
-
-            Modal.error({
-              title: res.message
+            this.setState({
+              loading: false
             })
           }
-        })
+        }, skip)
       }
     })
   }
@@ -211,26 +214,16 @@
     })
     
     this.props.form.setFieldsValue({
-      sql: ''
+      sql: ' '
     })
   }
 
   selectScript = (value, option) => {
-    const { usefulfields, sheet } = this.props
-
-    let _value = ''
-    if (value === 'default') {
-      let fields = usefulfields.filter(item => item.import !== 'false')
-      fields = fields.map(col => col.Column).join(',')
-
-      let _sheet = sheet.replace(/(.*)\.(.*)\.|@db@/ig, '')
-
-      _value = `Select ${fields} From ${_sheet}`
-    } else {
-      _value = value
-    }
-
+    let _value = value
     let _sql = this.props.form.getFieldValue('sql')
+    if (/^\s+$/.test(_sql)) {
+      _sql = ''
+    }
     if (_sql) {
       _sql = _sql + ` 
 
@@ -249,8 +242,8 @@
   }
 
   render() {
-    const { systemScripts, sheet } = this.props
-    const { usefulfields } = this.state
+    const { sheet, linefields } = this.props
+    const { usefulfields, systemScripts, skip } = this.state
     const { getFieldDecorator } = this.props.form
     const formItemLayout = {
       labelCol: {
@@ -267,51 +260,31 @@
       <Form {...formItemLayout} className="verify-form" id="verify-excelin-custom-scripts">
         <Row gutter={24}>
           <Col span={8}>
-            <Form.Item label={'琛ㄥ悕'} style={{whiteSpace: 'nowrap', margin: 0}}>
+            <Form.Item label="琛ㄥ悕" style={{whiteSpace: 'nowrap', margin: 0}}>
               {sheet}
             </Form.Item>
           </Col>
           <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>
           <Col span={24} className="sqlfield">
-            <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</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}
+            <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>
+              {usefulfields ? <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'鎼滅储鏉′欢锛岃鎸夌収@xxx@鏍煎紡浣跨敤銆�'}>,&nbsp;{usefulfields}</Tooltip> : null}
+              {linefields ? <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'琛ㄥ崟鍙婅鍙橀噺锛岀郴缁熶細瀹氫箟鍙橀噺骞惰祴鍊笺��'}>,&nbsp;{linefields}</Tooltip> : null}
             </Form.Item>
           </Col>
-          <Col span={8} style={{whiteSpace: 'nowrap'}}>
-            <Form.Item style={{marginBottom: 0}} label={
-              <Tooltip placement="bottomLeft" title={'鑷畾涔夎剼鏈笌榛樿sql浣嶇疆鍏崇郴銆�'}>
-                <QuestionCircleOutlined className="mk-form-tip" />
-                鎵ц浣嶇疆
-              </Tooltip>
-            }>
-              {getFieldDecorator('position', {
-                initialValue: 'front'
-              })(
-                <Radio.Group>
-                  <Radio value="init">鍒濆鍖�</Radio>
-                  <Radio value="front">sql鍓�</Radio>
-                  <Radio value="back">sql鍚�</Radio>
-                </Radio.Group>
-              )}
-            </Form.Item>
-          </Col>
-          <Col span={10}>
-            <Form.Item style={{marginBottom: 0}} label={'蹇嵎娣诲姞'}>
+          <Col span={8}>
+            <Form.Item style={{marginBottom: 0}} label="蹇嵎娣诲姞">
               <Select
                 showSearch
                 filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                 onSelect={this.selectScript}
                 getPopupContainer={() => document.getElementById('verify-excelin-custom-scripts')}
               >
-                <Select.Option key="default" value={'default'}>
-                  榛樿sql
-                </Select.Option>
                 <Select.Option key="debugger" value={`z_debug: select @ErrorCode='E',@retmsg='娴嬭瘯鏂偣' goto aaa`}>
                   娴嬭瘯鏂偣
                 </Select.Option>
@@ -323,7 +296,7 @@
               </Select>
             </Form.Item>
           </Col>
-          <Col span={6} className="add">
+          <Col span={5} className="add" style={{whiteSpace: 'nowrap'}}>
             <Button onClick={this.handleConfirm} loading={this.state.loading} className="mk-green" style={{marginBottom: 15, marginLeft: 40}}>
               淇濆瓨
             </Button>
@@ -331,8 +304,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