From bdfec77e57c90ad4750e08ee822818ce991b019f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 26 十一月 2023 14:11:58 +0800
Subject: [PATCH] 2023-11-26

---
 src/menu/datasource/verifycard/index.jsx |  182 +++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 173 insertions(+), 9 deletions(-)

diff --git a/src/menu/datasource/verifycard/index.jsx b/src/menu/datasource/verifycard/index.jsx
index 97016ce..a8e84f7 100644
--- a/src/menu/datasource/verifycard/index.jsx
+++ b/src/menu/datasource/verifycard/index.jsx
@@ -2,7 +2,7 @@
 import PropTypes from 'prop-types'
 import { fromJS } from 'immutable'
 import { Form, Tabs, Popconfirm, notification, Modal, Typography, Spin, message, Button, Input } from 'antd'
-import { StopOutlined, CheckCircleOutlined, EditOutlined, SwapOutlined, DeleteOutlined, CopyOutlined, BorderOutlined, SnippetsOutlined } from '@ant-design/icons'
+import { StopOutlined, CheckCircleOutlined, TableOutlined, EditOutlined, SwapOutlined, DeleteOutlined, CopyOutlined, BorderOutlined, SnippetsOutlined } from '@ant-design/icons'
 import moment from 'moment'
 import md5 from 'md5'
 
@@ -40,6 +40,7 @@
     subColumns: [],
     activeKey: 'setting',
     loading: false,
+    colLoading: false,
     searchKey: '',
     initsql: '',          // sql楠岃瘉鏃跺彉閲忓0鏄庡強璧嬪��
     usefulfields: '',
@@ -58,6 +59,7 @@
         dataIndex: 'label',
         inputType: 'input',
         editable: true,
+        searchable: true,
         width: '28%'
       },
       {
@@ -67,6 +69,7 @@
         editable: true,
         unique: true,
         strict: true,
+        searchable: true,
         copy: true,
         rules: [{
           pattern: /^[\u4E00-\u9FA50-9a-zA-Z_]*$/ig,
@@ -214,6 +217,27 @@
 
     columns.reverse()
     subColumns.reverse()
+
+    columns.forEach(col => {
+      if (!col.datatype) return
+      if (/^nvarchar/.test(col.datatype)) {
+        col.datatype = col.datatype.replace(/^nvarchar/, 'Nvarchar')
+      } else if (/^decimal/.test(col.datatype)) {
+        col.datatype = col.datatype.replace(/^decimal/, 'Decimal')
+      } else if (/^int/.test(col.datatype)) {
+        col.datatype = col.datatype.replace(/^int/, 'Int')
+      }
+    })
+    subColumns.forEach(col => {
+      if (!col.datatype) return
+      if (/^nvarchar/.test(col.datatype)) {
+        col.datatype = col.datatype.replace(/^nvarchar/, 'Nvarchar')
+      } else if (/^decimal/.test(col.datatype)) {
+        col.datatype = col.datatype.replace(/^decimal/, 'Decimal')
+      } else if (/^int/.test(col.datatype)) {
+        col.datatype = col.datatype.replace(/^int/, 'Int')
+      }
+    })
 
     this.setState({
       scripts,
@@ -368,6 +392,7 @@
     if (values.uuid) {
       scripts = scripts.map(item => {
         if (item.uuid === values.uuid) {
+          values.$index = item.$index || ''
           return values
         } else {
           return item
@@ -504,7 +529,6 @@
     let arr_field = columns.map(col => col.field).join(',')
 
     let _search = joinMainSearchkey(searches)
-    _search = _search ? 'where ' + _search : ''
 
     if (setting.dataresource) {
       let _dataresource = setting.dataresource
@@ -607,7 +631,7 @@
 
   sqlverify = (resolve, reject, type, testScripts) => {
     const { config } = this.props
-    const { columns, setting, scripts, searches, debugId } = this.state
+    const { columns, setting, scripts, searches, debugId, subColumns } = this.state
 
     let _scripts = scripts.filter(item => item.status !== 'false')
 
@@ -630,9 +654,32 @@
     }
 
     if ((setting.interType === 'system' && setting.execute !== 'false') || _scripts.length > 0) {
-      let r = SettingUtils.getDebugSql(setting, _scripts, columns, searches, config.type)
+      let _columns = columns
+      if (config.subtype === 'dualdatacard') {
+        _columns = [...columns, ...subColumns]
+      }
+      let r = SettingUtils.getDebugSql(setting, _scripts, _columns, searches, config.type)
 
       let _debugId = md5(r.sql)
+      
+      if (r.custompage && setting.laypage === 'true' && _columns.findIndex(col => col.field === 'mk_total') === -1) {
+        if (config.subtype !== 'basetable') {
+          Modal.warning({
+            title: `鏁版嵁婧愭垨鑷畾涔夎剼鏈腑浣跨敤鑷畾涔夊垎椤垫帓搴忔椂锛岃鍦ㄥ瓧娈甸泦涓坊鍔� mk_total銆俙,
+            okText: '鐭ラ亾浜�',
+            onOk: () => {
+              reject()
+            }
+          })
+          return
+        } else {
+          notification.warning({
+            top: 92,
+            message: '鏁版嵁婧愭垨鑷畾涔夎剼鏈腑浣跨敤鑷畾涔夊垎椤垫帓搴忔椂锛岃鍦ㄦ樉绀哄垪涓坊鍔� mk_total銆�',
+            duration: 5
+          })
+        }
+      }
 
       if (debugId === _debugId) {
         resolve()
@@ -653,6 +700,57 @@
             resolve()
           })
         } else {
+          if (/鍒楀悕\s*'[a-zA-Z0-9_-]+'\s*鏃犳晥/.test(result.message)) {
+            let tail = ''
+            let type = ''
+            if (setting.execute !== 'false' && setting.queryType !== 'statistics') {
+              searches.forEach(item => {
+                if (item.forbid) return
+                item.key.split(',').forEach(field => {
+                  if (new RegExp(`'${field}'`).test(result.message)) {
+                    tail = field
+                    type = '鎼滅储鏉′欢'
+                  }
+                })
+              })
+            }
+
+            if (!tail && setting.order) {
+              let keys = setting.order.replace(/\s+(asc|desc)/ig, '').replace(/\s+/g, '')
+              keys.split(',').forEach(field => {
+                if (new RegExp(`'${field}'`).test(result.message)) {
+                  tail = field
+                  type = '鎺掑簭'
+                }
+              })
+            }
+
+            if (!tail) {
+              columns.forEach(item => {
+                if (new RegExp(`'${item.field}'`).test(result.message)) {
+                  tail = item.field
+                  if (config.subtype === 'basetable') {
+                    type = '鏄剧ず鍒�'
+                  } else {
+                    type = '瀛楁闆�'
+                  }
+                }
+              })
+              if (!tail && config.subtype === 'dualdatacard') {
+                subColumns.forEach(item => {
+                  if (new RegExp(`'${item.field}'`).test(result.message)) {
+                    tail = item.field
+                    type = '瀛愯〃瀛楁闆�'
+                  }
+                })
+              }
+            }
+
+            if (tail) {
+              result.message = result.message.replace(/ROLLBACK TRANSACTION 璇锋眰娌℃湁瀵瑰簲鐨� BEGIN TRANSACTION銆�/, '')
+              result.message = <>{result.message}<span style={{color: 'red'}}>娉細{type}涓瓨鍦ㄥ瓧娈祘tail}</span></>
+            }
+          }
           if (type === 'submit') {
             Modal.confirm({
               title: result.message,
@@ -840,11 +938,25 @@
     const { columns } = this.state
     let m = []
     let n = []
+    let s = []
 
     columns.forEach(col => {
-      m.push(`${col.field} ${col.datatype}`)
-      n.push(col.field)
+      m.unshift(`${col.field} ${col.datatype}`)
+      n.unshift(col.field)
+      if (/decimal|int/ig.test(col.datatype)) {
+        s.unshift(`${Math.round(Math.random() * 10)} as ${col.field}`)
+      } else if (/datetime/.test(col.datatype)) {
+        s.unshift(`'${moment().format('YYYY-MM-DD HH:mm:ss')}' as ${col.field}`)
+      } else if (/date/.test(col.datatype)) {
+        s.unshift(`'${moment().format('YYYY-MM-DD')}' as ${col.field}`)
+      } else {
+        s.unshift(`'${col.label}' as ${col.field}`)
+      }
     })
+
+    if (window.debugger) {
+      console.info('select ' + s.join(', '))
+    }
 
     let oInput = document.createElement('input')
     oInput.value = `/*${m.join(',')}*/
@@ -921,6 +1033,49 @@
     })
   }
 
+  updateColumns = (tableName) => {
+    const { config } = this.props
+    const { colLoading, columns } = this.state
+
+    if (colLoading || columns.length > 0) return
+
+    if (config.subtype === 'basetable') return
+
+    let param = {func: 'sPC_Get_FieldName', TBName: tableName}
+    if (window.GLOB.cloudServiceApi) { // 涓斿瓨鍦ㄤ簯绔湴鍧�
+      param.rduri = window.GLOB.cloudServiceApi
+      param.userid = sessionStorage.getItem('CloudUserID') || ''
+      param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
+    }
+
+    this.setState({colLoading: true})
+
+    Api.getSystemCacheConfig(param).then(result => {
+      this.setState({colLoading: false})
+      if (!result.status) return
+
+      let fields = []
+      result.FDName.forEach(item => {
+        if (item.f_type !== 0) return
+
+        if (/nvarchar|int|decimal/ig.test(item.FieldType) || item.FieldType === 'date' || item.FieldType === 'datetime') {
+          fields.unshift({
+            uuid: Utils.getuuid(),
+            label: item.FieldDec,
+            field: item.FieldName,
+            datatype: item.FieldType.toLowerCase()
+          })
+        }
+      })
+
+      if (fields.length === 0) return
+
+      this.setState({columns: fields})
+    }, () => {
+      this.setState({colLoading: false})
+    })
+  }
+
   /**
    * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
    */
@@ -951,6 +1106,7 @@
               setting={setting}
               scripts={scripts}
               updateStatus={this.updateStatus}
+              updateColumns={this.updateColumns}
               addProcess={this.addProcess}
               wrappedComponentRef={(inst) => this.settingForm = inst}
             /> : null}
@@ -968,7 +1124,15 @@
               updatefield={this.updatefields}
             />
             <EditTable actions={['edit', 'move', 'copy', 'del', 'clear']} searchKey={searchKey} type="datasourcefield" wrappedComponentRef={(inst) => this.datasource = inst} data={columns} columns={colColumns} onChange={(columns) => this.setState({columns})}/>
-          </TabPane> : null}
+          </TabPane> : <TabPane tab={
+            <span>
+              瀛楁闆�<TableOutlined style={{marginLeft: '5px', fontSize: '12px'}} />
+              {columns.length ? <span className="count-tip">{columns.length}</span> : null}
+            </span>
+          } key="columns">
+            <div className="base-table-columns"></div>
+            <EditTable actions={[]} searchKey={searchKey} type="datasourcefield" data={columns} columns={colColumns}/>
+          </TabPane>}
           {config.subtype === 'dualdatacard' ? <TabPane tab={
             <span>
               瀛愯〃瀛楁闆�
@@ -987,8 +1151,8 @@
             <span>
               鑷畾涔夎剼鏈�
               {scripts.length ? <span className="count-tip">{scripts.length}</span> : null}
-              {config.type !== 'interface' && activeKey === 'setting' ? <CopyOutlined title="澶嶅埗鏁版嵁婧�" className="mk-copy-datasource" onClick={(e) => {e.stopPropagation();this.copyDatasource()}}/> : null}
-              {config.type !== 'interface' && activeKey === 'setting' ? <SnippetsOutlined title="瀵煎叆鏁版嵁婧�" className="mk-paste-datasource" onClick={(e) => {e.stopPropagation();this.setState({pvisible: true})}}/> : null}
+              {activeKey === 'setting' ? <CopyOutlined title="澶嶅埗鏁版嵁婧�" className="mk-copy-datasource" onClick={(e) => {e.stopPropagation();this.copyDatasource()}}/> : null}
+              {activeKey === 'setting' ? <SnippetsOutlined title="瀵煎叆鏁版嵁婧�" className="mk-paste-datasource" onClick={(e) => {e.stopPropagation();this.setState({pvisible: true})}}/> : null}
               {activeKey === 'columns' ? <CopyOutlined title="浠ラ�楀彿鎷兼帴褰㈠紡澶嶅埗瀛楁" className="mk-copy-fields" onClick={(e) => {e.stopPropagation();this.copyColumns()}}/> : null}
               {activeKey === 'subcolumns' ? <CopyOutlined title="浠ラ�楀彿鎷兼帴褰㈠紡澶嶅埗瀛楁" className="mk-copy-fields" onClick={(e) => {e.stopPropagation();this.copySubColumns()}}/> : null}
               {activeKey === 'subcolumns' || activeKey === 'columns' ? <span onClick={(e) => {e.stopPropagation()}}><Search className="mk-search-fields" defaultValue={searchKey} allowClear onSearch={(val, e) => {e.stopPropagation();this.setState({searchKey: val})}} /></span> : null}

--
Gitblit v1.8.0