From d1cd5af5adb53e91efdd278328e1b6f8ad834fb5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 06 二月 2025 21:11:56 +0800
Subject: [PATCH] Merge branch 'positec' into dms

---
 src/menu/components/table/edit-table/columns/tableIn/customscript/index.jsx |  215 ++++++++++++-----------------------------------------
 1 files changed, 51 insertions(+), 164 deletions(-)

diff --git a/src/menu/components/table/edit-table/columns/tableIn/customscript/index.jsx b/src/menu/components/table/edit-table/columns/tableIn/customscript/index.jsx
index 180e506..eeb2476 100644
--- a/src/menu/components/table/edit-table/columns/tableIn/customscript/index.jsx
+++ b/src/menu/components/table/edit-table/columns/tableIn/customscript/index.jsx
@@ -1,12 +1,11 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { Form, Row, Col, Button, notification, Modal, Tooltip, Radio, Select, Switch } from 'antd'
+import { Form, Row, Col, Button, notification, Tooltip, Radio, Select, Switch } from 'antd'
 import { QuestionCircleOutlined } from '@ant-design/icons'
 
-import Utils from '@/utils/utils.js'
-import Api from '@/api'
+import { checkSQL } from '@/utils/utils-custom.js'
 import CodeMirror from '@/templates/zshare/codemirror'
-import './index.scss'
+// import './index.scss'
 
 class CustomForm extends Component {
   static propTpyes = {
@@ -36,7 +35,7 @@
     fields.push('jskey')
 
     let sheet = btn.sheet.replace(/(.*)\.(.*)\.|@db@/ig, '')
-    let _sql = `create table #${sheet} (${usefulfields.map(item => item.field + ' ' + item.type).join(',')},jskey nvarchar(50),data_type nvarchar(50),BID nvarchar(50))
+    let _sql = `create table #${sheet} (${usefulfields.map(item => item.field + ' ' + item.datatype).join(',')},jskey nvarchar(50),data_type nvarchar(50),BID nvarchar(256))
       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=''
     `
@@ -67,20 +66,12 @@
   }
 
   handleConfirm = () => {
-    const { type, btn } = this.props
+    const { type } = this.props
     const { editItem, skip } = this.state
     // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
     this.props.form.validateFieldsAndScroll((err, values) => {
-      if (type === 'fullscreen' && err) {
-        notification.warning({
-          top: 92,
-          message: '璇疯緭鍏ql!',
-          duration: 5
-        })
-        return
-      }
       if (!err) {
-        if (/^[\s\n]+$/.test(values.sql)) {
+        if (!values.sql || /^[\s\n]+$/.test(values.sql)) {
           notification.warning({
             top: 92,
             message: '璇疯緭鍏ql!',
@@ -95,158 +86,43 @@
           values.status = editItem.status || 'true'
         }
 
-        let _quot = values.sql.match(/'{1}/g)
-        let _lparen = values.sql.match(/\({1}/g)
-        let _rparen = values.sql.match(/\){1}/g)
+        let pass = checkSQL(values.sql, 'customscript')
 
-        _quot = _quot ? _quot.length : 0
-        _lparen = _lparen ? _lparen.length : 0
-        _rparen = _rparen ? _rparen.length : 0
+        if (!pass && !skip) return
 
-        if (_quot % 2 !== 0) {
+        if (/@ID@/ig.test(values.sql) && !skip) {
           notification.warning({
             top: 92,
-            message: 'sql涓璡'蹇呴』鎴愬鍑虹幇',
-            duration: 5
-          })
-          return
-        } else if (_lparen !== _rparen) {
-          notification.warning({
-            top: 92,
-            message: 'sql涓�()蹇呴』鎴愬鍑虹幇',
-            duration: 5
-          })
-          return
-        } else if (/--/ig.test(values.sql)) {
-          notification.warning({
-            top: 92,
-            message: '鑷畾涔塻ql璇彞涓紝涓嶅彲鍑虹幇瀛楃 -- 锛屾敞閲婅鐢� /*鍐呭*/',
-            duration: 5
-          })
-          return
-        } else if (/,,/ig.test(values.sql)) {
-          notification.warning({
-            top: 92,
-            message: '鑷畾涔塻ql璇彞涓紝涓嶅彲鍑虹幇杩炵画鐨勮嫳鏂囬�楀彿锛�,,锛�',
-            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')
-
-        if (error) {
-          notification.warning({
-            top: 92,
-            message: 'sql涓笉鍙娇鐢�' + error,
+            message: '鑴氭湰涓笉鍙娇鐢ˊID@锛�',
             duration: 5
           })
           return
         }
-
-        let sheet = btn.sheet.replace(/(.*)\.(.*)\.|@db@/ig, '')
-        let tail = `
-          drop table #${sheet}
-          aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg
-        `
-
-        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}
-            `
-          }
-        })
-
-        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 sql = this.state.verifySql + _initCustomScript + _prevCustomScript + _backCustomScript + tail
-        
-        sql = sql.replace(/@\$|\$@/ig, '').replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id)@/ig, `'1949-10-01 15:00:00'`)
 
         if (skip) {
           this.setState({
-            editItem: null,
-            skip: false
-          }, () => {
-            this.props.scriptsChange(values)
+            skip: false,
+            editItem: null
           })
           this.props.form.setFieldsValue({
-            sql: ' '
+            sql: ''
           })
+          this.props.scriptsChange(values)
         } 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
-              })
-            }
+          this.props.scriptsChange(values, () => {
+            this.setState({
+              loading: false,
+              editItem: null
+            })
+            this.props.form.setFieldsValue({
+              sql: ''
+            })
+          }, () => {
+            this.setState({
+              loading: false
+            })
           })
         }
       }
@@ -264,14 +140,18 @@
   }
 
   selectScript = (value, option) => {
-    const { usefulfields, btn } = this.props
+    const { usefulfields, btn, setting } = this.props
 
     let _value = ''
     if (value === 'default') {
       let fields = usefulfields.map(col => col.field).join(',')
+      let upFields = usefulfields.map(col => `${col.field}=t.${col.field}`).join(',')
       
       if (fields) {
         fields = fields + ','
+      }
+      if (upFields) {
+        upFields = upFields + ','
       }
 
       let database = btn.sheet.match(/(.*)\.(.*)\.|@db@/ig) || ''
@@ -279,7 +159,20 @@
 
       database = database ? (database[0] || '') : ''
 
-      _value = `Insert into ${database}${sheet} (${fields}createuserid,createuser,createstaff,bid)\nSelect ${fields}@userid@,@username,@fullname,@BID@ From #${sheet}`
+      _value = `update a set ${upFields}modifydate=getdate(),modifyuserid=@UserID@,modifyuser=@username,modifystaff=@fullname,deleted=0
+      from (select * from #${sheet} where data_type='upt') t
+      inner join ${database}${sheet} a on t.jskey=a.${setting.primaryKey || 'id'}
+
+      update a set deleted=1,modifydate=getdate(),modifyuserid=@UserID@,modifyuser=@username,modifystaff=@fullname 
+      from (select * from #${sheet} where data_type='del') t
+      inner join ${database}${sheet} a on t.jskey=a.${setting.primaryKey || 'id'}
+
+      delete t from #${sheet} t inner join ${database}${sheet} a on t.jskey=a.${setting.primaryKey || 'id'}
+
+      Insert into ${database}${sheet} (${fields}createuserid,createuser,createstaff,bid)
+      Select ${fields}@UserID@,@username,@fullname,@BID@ From #${sheet}
+      `
+      _value = _value.replace(/\s{6}[fiuds]/ig, (word) => word.replace(/\s{6}/ig, ''))
     } else {
       _value = value
     }
@@ -330,12 +223,12 @@
           </Col> : null}
           {!type ? <Col span={10}>
             <Form.Item label="鎶ラ敊瀛楁" style={{margin: 0, whiteSpace: 'nowrap'}}>
-              ErrorCode锛堝鍔犲悗缂�NT琛ㄧず鏁版嵁涓嶅洖婊氾紝濡侲NT銆丯NT銆丗NT銆丯MNT锛�, retmsg
+              errorcode, retmsg
             </Form.Item>
           </Col> : null}
           {!type ? <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={'鍏叡鍊硷紝璇锋寜鐓xxx@鏍煎紡浣跨敤銆�'}><span style={{color: '#1890ff'}}>BID, LoginUID, SessionUid, UserID, Appkey, lang, typename, datam, 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},data_type锛堟敞锛歫skey涓轰富閿�硷紝鏂板鏃跺墠绔敓鎴愶紱data_type涓烘搷浣滅被鍨嬶紝鏂板 - add銆佷慨鏀� - upt銆佸垹闄� - del锛�
             </Form.Item>
@@ -380,7 +273,7 @@
               </Select>
             </Form.Item>
           </Col> : null}
-          <Col span={5} style={{paddingTop: '3px', whiteSpace: 'nowrap'}}>
+          <Col span={5} className="add" style={{paddingTop: '3px', whiteSpace: 'nowrap'}}>
             <Button onClick={this.handleConfirm} loading={this.state.loading} className="mk-green" style={{marginBottom: 15, marginLeft: 15}}>
               {type === 'fullscreen' && !editItem ? '娣诲姞' : '淇濆瓨'}
             </Button>
@@ -388,20 +281,14 @@
               鍙栨秷
             </Button>
           </Col>
-          <Col span={3} style={{paddingTop: '12px', fontSize: '12px', whiteSpace: 'nowrap'}}>
+          <Col span={3} className="forced" style={{paddingTop: '12px', 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" required>
               {getFieldDecorator('sql', {
-                initialValue: '',
-                rules: [
-                  {
-                    required: true,
-                    message: '璇疯緭鍏ql!'
-                  }
-                ]
+                initialValue: ''
               })(<CodeMirror />)}
             </Form.Item>
           </Col>

--
Gitblit v1.8.0