From 53ae6ce03a438526ce8f5b5675e53245fafa3ec7 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 16 七月 2024 16:05:01 +0800
Subject: [PATCH] 2024-07-16

---
 src/templates/sharecomponent/actioncomponent/verifyexcelin/customscript/index.jsx |   92 +++++++++++++++++++++++++++++++++------------
 1 files changed, 67 insertions(+), 25 deletions(-)

diff --git a/src/templates/sharecomponent/actioncomponent/verifyexcelin/customscript/index.jsx b/src/templates/sharecomponent/actioncomponent/verifyexcelin/customscript/index.jsx
index f0d8651..bfc57cb 100644
--- a/src/templates/sharecomponent/actioncomponent/verifyexcelin/customscript/index.jsx
+++ b/src/templates/sharecomponent/actioncomponent/verifyexcelin/customscript/index.jsx
@@ -1,4 +1,4 @@
-import React, {Component} from 'react'
+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, Switch } from 'antd'
@@ -22,8 +22,7 @@
     editItem: null,
     usefulfields: null,
     loading: false,
-    skip: false,
-    verifySql: ''
+    skip: false
   }
 
   UNSAFE_componentWillMount () {
@@ -37,26 +36,12 @@
   }
 
   resetfield = (columns) => {
-    const { btn } = this.props
     columns = columns.filter(item => item.import !== 'false')
     let fields = columns.map(item => item.Column)
 
     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 = `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=''
-    `
     
     this.setState({
-      verifySql: _sql,
       usefulfields: fields.join(', ')
     })
   }
@@ -81,7 +66,7 @@
   }
 
   handleConfirm = () => {
-    const { type, btn, workFlow } = this.props
+    const { type, btn, workFlow, usefulfields } = this.props
     const { editItem, skip } = this.state
 
     // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
@@ -115,12 +100,6 @@
         let pass = checkSQL(values.sql, 'customscript')
 
         if (!pass) 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鍓嶆墽琛岃剼鏈�
@@ -165,8 +144,71 @@
             `
           }
         }
+        
+        let sheet = btn.sheet.replace(/(.*)\.(.*)\.|@db@/ig, '')
+        let fields = []
+        let _dec = []
+        let vals = []
 
-        let sql = this.state.verifySql + _initCustomScript + _prevCustomScript + _backCustomScript + tail
+        usefulfields.forEach(col => {
+          if (col.import === 'false') return
+
+          fields.push(col.Column)
+          _dec.push(col.Column + ' ' + col.type)
+
+          let val = ''
+          if (col.import === 'init') {
+            if (/^Nvarchar/ig.test(col.type)) {
+              val = ''
+            } else if (/^Decimal/ig.test(col.type) || /^int/ig.test(col.type)) {
+              val = 0
+            } else if (col.type === 'date') {
+              val = '1949-10-01'
+            } else if (col.type === 'datetime') {
+              val = '1949-10-01 00:00:00'
+            }
+          } else if (/^Nvarchar/ig.test(col.type)) {
+            val = 'mk'
+          } else if (/^Decimal/ig.test(col.type) || /^int/ig.test(col.type)) {
+            val = 1
+          } else if (col.type === 'date') {
+            val = '1949-10-01'
+          } else if (col.type === 'datetime') {
+            val = '1949-10-01 00:00:00'
+          }
+
+          vals.push(`'${val}'`)
+        })
+
+        vals.push(`'${new Date().getTime()}000010'`)
+        vals.push(`'bid'`)
+        vals =  `Select ${vals.join(',')}`
+
+        fields.push('jskey')
+        fields = fields.join(',')
+        
+        _dec = _dec.join(',')
+        _dec = _dec ? _dec + ',' : ''
+
+        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='', @UserName='', @FullName='', @RoleID='', @mk_departmentcode='', @mk_organization='', @mk_user_type='', @mk_nation='', @mk_province='', @mk_city='', @mk_district='', @mk_address=''
+        
+          ${_initCustomScript}
+
+          Insert into #${sheet} (${fields},BID)
+
+          /* excel鏁版嵁*/
+          ${vals}
+
+          ${_prevCustomScript}
+
+          ${_backCustomScript}
+
+          drop table #${sheet}
+          aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg
+        `
+
         sql = sql.replace(/@\$|\$@/ig, '').replace(/\$check@|@check\$/ig, '').replace(/@datam@/ig, `''`).replace(/@typename@/ig, `'debug'`)
         
         if (workFlow === 'true') {

--
Gitblit v1.8.0