From c8c8bdf0c362ca76253d8e0cbb0dbaa13efad4a3 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 12 二月 2025 23:09:48 +0800
Subject: [PATCH] 2025-02-12

---
 src/templates/sharecomponent/actioncomponent/verifyexcelin/index.jsx |  235 ++++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 176 insertions(+), 59 deletions(-)

diff --git a/src/templates/sharecomponent/actioncomponent/verifyexcelin/index.jsx b/src/templates/sharecomponent/actioncomponent/verifyexcelin/index.jsx
index 5c664eb..677ab76 100644
--- a/src/templates/sharecomponent/actioncomponent/verifyexcelin/index.jsx
+++ b/src/templates/sharecomponent/actioncomponent/verifyexcelin/index.jsx
@@ -78,6 +78,8 @@
           { value: 'Decimal(18,2)', text: 'Decimal(18,2)' },
           { value: 'Decimal(18,4)', text: 'Decimal(18,4)' },
           { value: 'Decimal(18,6)', text: 'Decimal(18,6)' },
+          { value: 'Decimal(18,8)', text: 'Decimal(18,8)' },
+          { value: 'Decimal(18,10)', text: 'Decimal(18,10)' },
           { value: 'date', text: 'date' },
           { value: 'datetime', text: 'datetime' }
         ]
@@ -119,7 +121,7 @@
         unlimit: true,
         editable: true,
         keyVals: ['Int', 'Decimal(18,0)', 'Decimal(18,2)', 'Decimal(18,4)', 'Decimal(18,6)'],
-        render: (text, record) => /^Decimal/ig.test(record.type) || /^int/ig.test(record.type) ? text : ''
+        render: (text, record) => record.required === 'true' && (/^Decimal/ig.test(record.type) || /^int/ig.test(record.type)) ? text : ''
         
       },
       {
@@ -131,7 +133,7 @@
         unlimit: true,
         editable: true,
         keyVals: ['Int', 'Decimal(18,0)', 'Decimal(18,2)', 'Decimal(18,4)', 'Decimal(18,6)'],
-        render: (text, record) => /^Decimal/ig.test(record.type) || /^int/ig.test(record.type) ? text : ''
+        render: (text, record) => record.required === 'true' && (/^Decimal/ig.test(record.type) || /^int/ig.test(record.type)) ? text : ''
       }
     ],
     uniqueColumns: [
@@ -205,6 +207,89 @@
             </div>
           )
       },
+      {
+        dataIndex: 'sqlRender',
+        render: (record) => {
+          let columns = this.state.verify.columns
+
+          let textFields = []
+          let numberFields = []
+          let dateFields = []
+          columns.forEach((col) => {
+            if (/Nvarchar/ig.test(col.type)) {
+              textFields.push(col.Column)
+            } else if (/Decimal|int/ig.test(col.type)) {
+              numberFields.push(col.Column)
+            } else if (/date/ig.test(col.type)) {
+              dateFields.push(col.Column)
+            }
+          })
+
+          let _fields = record.field.split(',')
+          let _fields_ = _fields.map(_field => `a.${_field}=b.${_field}`)
+          _fields_ = _fields_.join(' and ')
+
+          let _where = []
+          _fields.forEach(f => {
+            if (textFields.includes(f)) {
+              _where.push(`${f}!=''`)
+            } else if (numberFields.includes(f)) {
+              _where.push(`${f}!=0`)
+            } else if (dateFields.includes(f)) {
+              _where.push(`${f}>'1949-10-01'`)
+            }
+          })
+          _where = _where.length ? `where ${_where.join(' and ')} ` : ''
+
+          if (record.verifyType === 'logic' || record.verifyType === 'logic_temp') {
+            _fields_ += ' and b.deleted=0'
+          }
+
+          let _afields = []
+          _fields = _fields.map(f => {
+            if (numberFields.includes(f)) {
+              _afields.push(`cast(a.${f} as nvarchar(50))`)
+              return `cast(${f} as nvarchar(50))`
+            } else if (dateFields.includes(f)) {
+              _afields.push(`CONVERT(nvarchar(50), a.${f}, 21)`)
+              return `CONVERT(nvarchar(50), ${f}, 21)`
+            }
+            _afields.push(`a.${f}`)
+
+            return f
+          })
+
+          let _sheet = this.props.card.sheet
+
+          let database = _sheet.match(/(.*)\.(.*)\.|@db@/ig) || ''
+          let sheet = _sheet.replace(/(.*)\.(.*)\.|@db@/ig, '')
+          
+          database = database ? (database[0] || '') : ''
+
+          let sql = `
+          /* 閲嶅鎬ч獙璇� */
+          Set @tbid=''
+          Select top 1 @tbid=${_fields.join('+\' \'+')} from (select 1 as n,${record.field} from #${sheet} ${_where}) a group by ${record.field} having sum(n)>1
+          
+          If @tbid!=''
+          Begin
+            select @ErrorCode='${record.errorCode}',@retmsg=@tbid+' 閲嶅'
+            goto aaa
+          end
+          
+          ${record.verifyType.indexOf('temp') === -1 ? `Set @tbid=''
+          Select top 1 @tbid=${_afields.join('+\' \'+')} from ${_where ? `(select * from #${sheet} ${_where})` : `#${sheet}`} a Inner join ${database}${sheet} b on ${_fields_}
+          
+          If @tbid!=''
+          Begin
+            select @ErrorCode='${record.errorCode}',@retmsg=@tbid+' 涓庡凡鏈夋暟鎹噸澶�'
+            goto aaa
+          end` : ''}
+          `
+          
+          return sql.split(/\n\s{10}/ig).map(n => n.replace(/^\s{2}/ig, '&nbsp;&nbsp;'))
+        }
+      }
     ],
     scriptsColumns: [
       {
@@ -316,6 +401,16 @@
     _verify.columns = _columns
     _verify.scripts = _verify.scripts || []
     _verify.uniques = _verify.uniques || []
+
+    if (window.GLOB.process && card.intertype === 'system') {
+      _verify.workFlow = _verify.workFlow || 'false'
+      _verify.flowType = 'start'
+      _verify.flowSql = _verify.flowSql || 'true'
+    } else {
+      delete _verify.workFlow
+      delete _verify.flowType
+      delete _verify.flowSql
+    }
 
     this.setState({
       searchKey: '',
@@ -503,35 +598,37 @@
 
   clearField = () => {
     const { verify } = this.state
-    const _this = this
+    const that = this
 
     confirm({
       content: `纭畾娓呯┖Excel鍒楀悧锛焋,
       onOk() {
-        _this.setState({
+        that.setState({
           verify: {
             ...verify,
             columns: []
           }
         }, () => {
-          _this.resetUniqueColumns()
+          that.resetUniqueColumns()
         })
       },
       onCancel() {}
     })
   }
 
-  columnChange = (values) => {
+  columnChange = (values, callback) => {
     let verify = JSON.parse(JSON.stringify(this.state.verify))
 
-    let fields = verify.columns.map(item => item.Column)
-    if (fields.includes(values.Column)) {
+    let fields = verify.columns.map(item => item.Column.toLowerCase())
+    if (fields.includes(values.Column.toLowerCase())) {
       notification.warning({
         top: 92,
         message: values.Column + '瀛楁宸插瓨鍦紒',
         duration: 5
       })
       return
+    } else {
+      callback()
     }
 
     values.uuid = Utils.getuuid()
@@ -714,37 +811,44 @@
         if (!err) {
           let _verify = {...verify, ...values}
 
-          if (_verify.excelHandle !== 'true') {
+          if (_verify.excelHandle !== 'true') { 
             delete _verify.excel_func
+          }
+          if (_verify.default === 'false' && _verify.scripts.length === 0) {
+            notification.warning({
+              top: 92,
+              message: '涓嶆墽琛岄粯璁ql鏃讹紝蹇呴』璁剧疆鑷畾涔夎剼鏈紒',
+              duration: 5
+            })
+            return
           }
 
           let cols = _verify.columns.map(col => col.Column.toLowerCase())
           cols = Array.from(new Set(cols))
+          let error = ''
 
           if (_verify.columns.length === 0) {
-            notification.warning({
-              top: 92,
-              message: '璇疯缃瓻xcel鍒楀瓧娈�!',
-              duration: 5
-            })
-            return
+            error = '璇疯缃瓻xcel鍒楀瓧娈�!'
           } else if (_verify.columns.length > cols.length) {
-            notification.warning({
-              top: 92,
-              message: 'Excel鍒楀瓧娈靛悕锛屼笉鍙噸澶�!',
-              duration: 5
-            })
-            return
+            error = 'Excel鍒楀瓧娈靛悕锛屼笉鍙噸澶�!'
+          } else if (cols.includes('bid')) {
+            error = 'bid瀛楁涓轰繚鐣欏瓧锛屼笉鍙娇鐢�!'
+          } else if (cols.includes('jskey')) {
+            error = 'jskey瀛楁涓轰繚鐣欏瓧锛屼笉鍙娇鐢�!'
           } else if (_verify.range === 1) {
             let tEmptys = _verify.columns.filter(op => !op.Text)
             if (tEmptys.length > 0) {
-              notification.warning({
-                top: 92,
-                message: '蹇界暐棣栬鏃讹紝浼氫娇鐢═ext鍊兼牎楠孍xcel棣栬鍐呭锛孴ext鍊间笌Excel琛ㄩ琛屽唴瀹圭浉鍚岋紝涓斿潎涓嶅彲涓虹┖锛�',
-                duration: 5
-              })
-              return
+              error = '蹇界暐棣栬鏃讹紝浼氫娇鐢═ext鍊兼牎楠孍xcel棣栬鍐呭锛孴ext鍊间笌Excel琛ㄩ琛屽唴瀹圭浉鍚岋紝涓斿潎涓嶅彲涓虹┖锛�'
             }
+          }
+
+          if (error) {
+            notification.warning({
+              top: 92,
+              message: error,
+              duration: 5
+            })
+            return
           }
 
           _verify.columns.sort((a, b) => {
@@ -783,21 +887,11 @@
     })
   }
 
-  onOptionChange = (e) => {
+  onOptionChange = (value, key) => {
     const { verify } = this.state
-    let value = e.target.value
 
     this.setState({
-      verify: {...verify, default: value}
-    })
-  }
-
-  onHandleChange = (e) => {
-    const { verify } = this.state
-    let value = e.target.value
-
-    this.setState({
-      verify: {...verify, excelHandle: value}
+      verify: {...verify, [key]: value}
     })
   }
 
@@ -879,8 +973,8 @@
             <Form {...formItemLayout}>
               <Row gutter={24}>
                 {card.intertype === 'system' ? <Col span={8}>
-                  <Form.Item label={'榛樿sql'}>
-                    <Radio.Group value={verify.default} onChange={this.onOptionChange}>
+                  <Form.Item label="榛樿sql">
+                    <Radio.Group value={verify.default} onChange={(e) => this.onOptionChange(e.target.value, 'default')}>
                       <Radio value="true">鎵ц</Radio>
                       <Radio value="false">涓嶆墽琛�</Radio>
                     </Radio.Group>
@@ -888,7 +982,7 @@
                 </Col> : null}
                 <Col span={8}>
                   <Form.Item label={
-                    <Tooltip placement="topRight" title="鑷畾涔夐獙璇丒xcel鏍煎紡锛屽彲鐢ㄥ弬鏁颁负 XLSX銆乨ata銆乧olumns銆乧allback銆�">
+                    <Tooltip placement="topRight" title="鑷畾涔夐獙璇丒xcel鏍煎紡锛屽彲鐢ㄥ弬鏁颁负 XLSX銆亀orkbook銆乥tn銆乧allback銆�">
                       <QuestionCircleOutlined className="mk-form-tip" />
                       瀵煎叆鏍煎紡
                     </Tooltip>
@@ -896,25 +990,12 @@
                     {getFieldDecorator('excelHandle', {
                       initialValue: verify.excelHandle
                     })(
-                    <Radio.Group onChange={this.onHandleChange}>
+                    <Radio.Group onChange={(e) => this.onOptionChange(e.target.value, 'excelHandle')}>
                       <Radio value="false">榛樿</Radio>
                       <Radio value="true">鑷畾涔�</Radio>
                     </Radio.Group>)}
                   </Form.Item>
                 </Col>
-                {verify.excelHandle === 'true' ? <Col span={24} style={{paddingLeft: '30px'}}>
-                  <Form.Item wrapperCol={ {xs: { span: 24 }, sm: { span: 24 }} } label="">
-                    {getFieldDecorator('excel_func', {
-                      initialValue: verify.excel_func || '',
-                      rules: [
-                        {
-                          required: true,
-                          message: '璇峰~鍐欒嚜瀹氫箟閫昏緫!'
-                        }
-                      ]
-                    })(<CodeMirror mode="text/javascript" theme="cobalt" />)}
-                  </Form.Item>
-                </Col> : null}
                 {verify.excelHandle !== 'true' ? <Col span={8}>
                   <Form.Item label={
                     <Tooltip placement="bottomLeft" title="瀵煎叆鏃跺伐浣滆〃鍚嶄笌excel涓繀椤讳竴鑷达紝娉細宸ヤ綔琛ㄥ悕涓篠heet1涓攅xcel涓粎鏈変竴涓伐浣滆〃鏃朵笉杩涜琛ㄥ悕楠岃瘉銆�">
@@ -933,7 +1014,7 @@
                     })(<Input placeholder="" autoComplete="off" />)}
                   </Form.Item>
                 </Col> : null}
-                {verify.excelHandle !== 'true' ? <Col span={8}>
+                <Col span={8}>
                   <Form.Item label={
                     <Tooltip placement="bottomLeft" title="蹇界暐棣栬鏃讹紝浼氭牎楠宔xcel涓〃澶村悕绉颁笌excel鍒楄缃槸鍚︿竴鑷淬��">
                       <QuestionCircleOutlined className="mk-form-tip" />
@@ -943,6 +1024,40 @@
                     {getFieldDecorator('range', {
                       initialValue: verify.range || 0
                     })(<InputNumber min={0} max={100} precision={0} />)}
+                  </Form.Item>
+                </Col>
+                {verify.excelHandle === 'true' ? <Col span={24} style={{paddingLeft: '30px'}}>
+                  <Form.Item wrapperCol={ {xs: { span: 24 }, sm: { span: 24 }} } label="">
+                    {getFieldDecorator('excel_func', {
+                      initialValue: verify.excel_func || '',
+                      rules: [
+                        {
+                          required: true,
+                          message: '璇峰~鍐欒嚜瀹氫箟閫昏緫!'
+                        }
+                      ]
+                    })(<CodeMirror mode="text/javascript" theme="cobalt" />)}
+                  </Form.Item>
+                </Col> : null}
+                {window.GLOB.process && card.intertype === 'system' ? <Col span={8}>
+                  <Form.Item label={
+                    <Tooltip placement="bottomLeft" title="瀵煎叆Excel宸ヤ綔娴佷粎鏀寔鍙戣捣娴佺▼銆�">
+                      <QuestionCircleOutlined className="mk-form-tip" />
+                      宸ヤ綔娴�
+                    </Tooltip>
+                  }>
+                    <Radio.Group value={verify.workFlow} onChange={(e) => {this.onOptionChange(e.target.value, 'workFlow')}}>
+                      <Radio value="true">寮�鍚�</Radio>
+                      <Radio value="false">涓嶅紑鍚�</Radio>
+                    </Radio.Group>
+                  </Form.Item>
+                </Col> : null}
+                {verify.workFlow === 'true' ? <Col span={8}>
+                  <Form.Item label="榛樿sql锛堝伐浣滄祦锛�">
+                    <Radio.Group value={verify.flowSql} onChange={(e) => {this.onOptionChange(e.target.value, 'flowSql')}}>
+                      <Radio value="true">鎵ц</Radio>
+                      <Radio value="false">涓嶆墽琛�</Radio>
+                    </Radio.Group>
                   </Form.Item>
                 </Col> : null}
               </Row>
@@ -961,7 +1076,7 @@
             <Button className="excel-col-add mk-red" title="娓呯┖Excel鍒�" onClick={this.clearField}>
               娓呯┖Excel鍒�
             </Button>
-            <Col style={{fontSize: '12px', color: '#757575', paddingLeft: '10px'}} span={24}>娉細鏁板�肩被鍨嬶紙int 鎴� decimal锛夛紝鍐呭涓哄繀濉紱鏈�澶у�煎拰鏈�灏忓�煎湪绫诲瀷涓烘暟鍊兼椂鏈夋晥銆傚鍏�-鍒濆鍖栵細鐢ㄤ簬excel涓笉瀛樺湪锛屽鍏ユ椂闇�瑕佸垵濮嬪寲鐨勫瓧娈�</Col>
+            <Col style={{fontSize: '12px', color: '#757575', paddingLeft: '10px'}} span={24}>娉細鏁板�肩被鍨嬶紙int 鎴� decimal锛夛紝鍐呭涓哄繀濉紱鏈�澶у�煎拰鏈�灏忓�煎湪绫诲瀷涓烘暟鍊兼椂锛堝繀濉級鏈夋晥銆傚鍏�-鍒濆鍖栵細鐢ㄤ簬excel涓笉瀛樺湪锛屽鍏ユ椂闇�瑕佸垵濮嬪寲鐨勫瓧娈�</Col>
             <EditTable actions={['edit', 'move', 'copy', 'del', 'extra:required:鏄惁蹇呭~']} searchKey={searchKey} type="excelcolumn" data={verify.columns} columns={excelColumns} onChange={this.changeColumns}/>
           </TabPane>
           {card.intertype === 'system' ? <TabPane tab={
@@ -971,7 +1086,7 @@
             </span>
           } key="unique">
             <UniqueForm fields={verify.columns} uniqueChange={this.uniqueChange}/>
-            <EditTable actions={['edit', 'move', 'del', 'status']} data={verify.uniques} columns={uniqueColumns} onChange={this.changeUniques}/>
+            <EditTable actions={['edit', 'move', 'del', 'status', 'sql']} data={verify.uniques} columns={uniqueColumns} onChange={this.changeUniques}/>
           </TabPane> : null}
           {card.intertype === 'system' ? <TabPane tab={
             <span>
@@ -991,6 +1106,7 @@
                 btn={this.props.card}
                 usefulfields={verify.columns}
                 scripts={verify.scripts}
+                workFlow={verify.workFlow}
                 systemScripts={this.state.systemScripts}
                 scriptsChange={this.scriptsChange}
                 wrappedComponentRef={(inst) => this.scriptsFullForm = inst}
@@ -1000,6 +1116,7 @@
               btn={this.props.card}
               usefulfields={verify.columns}
               scripts={verify.scripts}
+              workFlow={verify.workFlow}
               systemScripts={this.state.systemScripts}
               scriptsChange={this.scriptsChange}
               wrappedComponentRef={(inst) => this.scriptsForm = inst}

--
Gitblit v1.8.0