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 |  145 +++++++++++++++--------------------------------
 1 files changed, 47 insertions(+), 98 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 0537dcf..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,9 +1,8 @@
 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 Api from '@/api'
 import { checkSQL } from '@/utils/utils-custom.js'
 import CodeMirror from '@/templates/zshare/codemirror'
 // import './index.scss'
@@ -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!',
@@ -99,92 +90,39 @@
 
         if (!pass && !skip) 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}
-            `
-          }
+        if (/@ID@/ig.test(values.sql) && !skip) {
+          notification.warning({
+            top: 92,
+            message: '鑴氭湰涓笉鍙娇鐢ˊID@锛�',
+            duration: 5
+          })
+          return
         }
-
-        let sql = this.state.verifySql + _initCustomScript + _prevCustomScript + _backCustomScript + tail
-        
-        sql = sql.replace(/@\$|\$@/ig, '')
-        sql = sql.replace(/@datam@/ig, `''`)
-        sql = sql.replace(/@typename@/ig, `'debug'`)
 
         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
+            })
           })
         }
       }
@@ -202,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) || ''
@@ -217,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
     }
@@ -331,15 +286,9 @@
             <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