From 4e1938344ca46c0cbe699756ecaffa630e698aec Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 06 五月 2020 13:59:54 +0800
Subject: [PATCH] 2020-05-06

---
 src/utils/utils.js |  194 +++++++++++++++++++++++++++++-------------------
 1 files changed, 118 insertions(+), 76 deletions(-)

diff --git a/src/utils/utils.js b/src/utils/utils.js
index 029cfc4..a08f503 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -789,25 +789,26 @@
     let _prevCustomScript = '' // 榛樿sql鍓嶆墽琛岃剼鏈�
     let _backCustomScript = '' // 榛樿sql鍚庢墽琛岃剼鏈�
 
-    if (verify.scripts) {
-      verify.scripts.forEach(item => {
-        if (item.status === 'false') return
+    verify.scripts && verify.scripts.forEach(item => {
+      if (item.status === 'false') return
 
-        if (item.position === 'init') {
-          _initCustomScript += `
-          ${item.sql}
-          `
-        } else if (item.position === 'front') {
-          _prevCustomScript += `
-          ${item.sql}
-          `
-        } else {
-          _backCustomScript += `
-          ${item.sql}
-          `
-        }
-      })
-    }
+      if (item.position === 'init') {
+        _initCustomScript += `
+        /* 鑷畾涔夎剼鏈� */
+        ${item.sql}
+        `
+      } else if (item.position === 'front') {
+        _prevCustomScript += `
+        /* 鑷畾涔夎剼鏈� */
+        ${item.sql}
+        `
+      } else {
+        _backCustomScript += `
+        /* 鑷畾涔夎剼鏈� */
+        ${item.sql}
+        `
+      }
+    })
 
     // 闇�瑕佸0鏄庣殑鍙橀噺闆�
     // let _vars = ['tbid', 'ErrorCode', 'retmsg', 'BillCode', 'BVoucher', 'FIBVoucherDate', 'FiYear', 'UserName', 'FullName', 'ID', 'BID', 'LoginUID', 'SessionUid', 'UserID', 'Appkey']
@@ -817,7 +818,8 @@
     let primaryKey = setting.primaryKey || 'id'
 
     // 绯荤粺鍙橀噺澹版槑涓庤缃垵濮嬪��
-    let _sql = `Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50), @UserName nvarchar(50),@FullName nvarchar(50),@ModularDetailCode nvarchar(50)
+    let _sql = `/* 绯荤粺鐢熸垚 */
+        Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50), @UserName nvarchar(50),@FullName nvarchar(50),@ModularDetailCode nvarchar(50)
       `
 
     // let _initvars = ['ID', 'BID', 'LoginUID', 'SessionUid', 'UserID', 'Appkey'] // 宸茶祴鍊煎瓧娈甸泦
@@ -834,8 +836,15 @@
         if (!_initvars.includes(_key)) {
           _initvars.push(_key)
 
-          if (form.type === 'number' && typeof(form.value) === 'number') {
-            _initfields.push(`@${_key}=${form.value}`)
+          if (form.type === 'number') {
+            let val = form.value
+            if (typeof(val) !== 'number') {
+              val = parseFloat(val)
+              if (isNaN(val)) {
+                val = 0
+              }
+            }
+            _initfields.push(`@${_key}=${val}`)
           } else {
             _initfields.push(`@${_key}='${form.value}'`)
           }
@@ -874,7 +883,13 @@
 
             let _val = data.hasOwnProperty(col.field) ? data[col.field] : ''
 
-            if (col.type === 'number' && typeof(_val) === 'number') {
+            if (col.type === 'number') {
+              if (typeof(_val) !== 'number') {
+                _val = parseFloat(_val)
+                if (isNaN(_val)) {
+                  _val = 0
+                }
+              }
               _initfields.push(`@${_key}=${_val}`)
             } else {
               _initfields.push(`@${_key}='${_val}'`)
@@ -906,8 +921,9 @@
     // 鍙橀噺澹版槑
     _declarefields = _declarefields.join(',')
     if (_declarefields) {
-      _sql += `,${_declarefields}
-        `
+      _sql = `/* 绯荤粺鐢熸垚 */
+        Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50), @UserName nvarchar(50),@FullName nvarchar(50),@ModularDetailCode nvarchar(50),${_declarefields}
+      `
     }
 
     // 鍙橀噺璧嬪��
@@ -940,8 +956,10 @@
     }
 
     // 鍒濆鍖栧嚟璇佸強鐢ㄦ埛淇℃伅瀛楁
-    _sql += `select @BVoucher='',@FIBVoucherDate='',@FiYear='',@ErrorCode='',@retmsg='',@UserName='${userName}', @FullName='${fullName}'
-      `
+    _sql += `
+        /* 鍑瘉鍙婄敤鎴蜂俊鎭垵濮嬪寲璧嬪�� */
+        select @BVoucher='',@FIBVoucherDate='',@FiYear='',@ErrorCode='',@retmsg='',@UserName='${userName}', @FullName='${fullName}'
+        `
 
     if (_initCustomScript) {
       _sql += _initCustomScript
@@ -949,7 +967,9 @@
 
     // 鍚敤璐︽湡楠岃瘉
     if (verify.accountdate === 'true') {
-      _sql += `exec s_FIBVoucherDateCheck @ErrorCode=@ErrorCode OUTPUT,@retmsg=@retmsg OUTPUT
+      _sql += `
+        /* 璐︽湡楠岃瘉 */
+        exec s_FIBVoucherDateCheck @ErrorCode=@ErrorCode OUTPUT,@retmsg=@retmsg OUTPUT
         if @ErrorCode!=''
           GOTO aaa
         `
@@ -962,7 +982,9 @@
         datasource = '(' + datasource + ') tb'
       }
 
-      _sql += `select @tbid='', @ErrorCode='',@retmsg=''
+      _sql += `
+        /* 澶辨晥楠岃瘉 */
+        select @tbid='', @ErrorCode='',@retmsg=''
         select @tbid=${primaryKey} from ${datasource} where ${primaryKey} ='${primaryId}'
         If @tbid=''
         Begin
@@ -975,12 +997,14 @@
     // 姣旇緝楠岃瘉
     if (verify.contrasts && verify.contrasts.length > 0) {
       verify.contrasts.forEach(item => {
-        _sql += `If ${item.frontfield} ${item.operator} ${item.backfield}
-          Begin
-            select @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}'
-              goto aaa
-          end
-          `
+        _sql += `
+        /* 姣旇緝楠岃瘉 */
+        If ${item.frontfield} ${item.operator} ${item.backfield}
+        Begin
+          select @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}'
+            goto aaa
+        end
+        `
       })
     }
 
@@ -1021,30 +1045,32 @@
           _fieldValue.push(`${primaryKey} !='${primaryId}'`)
         }
 
-        _sql += `select @tbid='', @ErrorCode='',@retmsg=''
-          select @tbid='X' from ${btn.sql} where ${_fieldValue.join(' and ')}${_verifyType}
-          If @tbid!=''
-          Begin
-            select @ErrorCode='${item.errorCode}',@retmsg='${_value.join(', ')} 宸插瓨鍦�'
-            goto aaa
-          end
-          `
+        _sql += `
+        /* 鍞竴鎬ч獙璇� */
+        select @tbid='', @ErrorCode='',@retmsg=''
+        select @tbid='X' from ${btn.sql} where ${_fieldValue.join(' and ')}${_verifyType}
+        If @tbid!=''
+        Begin
+          select @ErrorCode='${item.errorCode}',@retmsg='${_value.join(', ')} 宸插瓨鍦�'
+          goto aaa
+        end
+        `
       })
     }
     
     // 鑷畾涔夐獙璇�
-    if (verify.customverifys && verify.customverifys.length > 0) {
-      verify.customverifys.forEach(item => {        
-        _sql += `select @tbid='', @ErrorCode='',@retmsg=''
-          select top 1 @tbid='X' from (${item.sql}) a
-          If @tbid ${item.result === 'true' ? '!=' : '='}''
-          Begin
-            select @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}'
-            goto aaa
-          end
-          `
-      })
-    }
+    verify.customverifys && verify.customverifys.forEach(item => {        
+      _sql += `
+        /* 鑷畾涔夐獙璇� */
+        select @tbid='', @ErrorCode='',@retmsg=''
+        select top 1 @tbid='X' from (${item.sql}) a
+        If @tbid ${item.result === 'true' ? '!=' : '='}''
+        Begin
+          select @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}'
+          goto aaa
+        end
+        `
+    })
 
     // 鍗曞彿鐢熸垚锛屼娇鐢ㄤ笂绾d锛圔ID锛夋垨鍒楄〃鏁版嵁锛屽0鏄庡彉閲忥紙妫�楠岋級
     let _billcodesSql  = ''
@@ -1079,21 +1105,23 @@
           _vars.push(_key)
         }
 
-        _billcodesSql += `${_declare}
-          select @BillCode='', @${_key}='', @ModularDetailCode=''
-          ${_lpline}
-          exec s_get_BillCode
-            @ModularDetailCode=${_ModularDetailCode},
-            @Type=${item.Type},
-            @TypeCharOne='${item.TypeCharOne}',
-            @TypeCharTwo ='${item.TypeCharTwo}',
-            @BillCode =@BillCode output,
-            @ErrorCode =@ErrorCode output, 
-            @retmsg=@retmsg output
-          if @ErrorCode!=''
-            goto aaa
-          set @${_key}=@BillCode
-          `
+        _billcodesSql += `
+        /* 鍗曞彿鐢熸垚 */
+        ${_declare}
+        select @BillCode='', @${_key}='', @ModularDetailCode=''
+        ${_lpline}
+        exec s_get_BillCode
+          @ModularDetailCode=${_ModularDetailCode},
+          @Type=${item.Type},
+          @TypeCharOne='${item.TypeCharOne}',
+          @TypeCharTwo ='${item.TypeCharTwo}',
+          @BillCode =@BillCode output,
+          @ErrorCode =@ErrorCode output, 
+          @retmsg=@retmsg output
+        if @ErrorCode!=''
+          goto aaa
+        set @${_key}=@BillCode
+        `
       })
 
       if (_actionType !== 'insertOrUpdate') {
@@ -1109,7 +1137,9 @@
 
       hasvoucher = true
 
-      _sql += `exec s_BVoucher_Create
+      _sql += `
+        /* 鍒涘缓鍑瘉 */
+        exec s_BVoucher_Create
           @Bill ='${data[_voucher.linkField]}',
           @BVoucherType ='${_voucher.BVoucherType}',
           @VoucherTypeOne ='${_voucher.VoucherTypeOne}',
@@ -1210,11 +1240,17 @@
 
     // 娣诲姞銆佷慨鏀广�侀�昏緫鍒犻櫎銆佺墿鐞嗗垹闄�
     if (_actionType === 'insert') {
-      _sql += _insertsql
+      _sql += `
+        /* 榛樿sql */
+        ${_insertsql}`
     } else if (_actionType === 'update') {
-      _sql += _updatesql
+      _sql += `
+        /* 榛樿sql */
+        ${_updatesql}`
     } else if (_actionType === 'LogicDelete') { // 閫昏緫鍒犻櫎
-      _sql += `update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuserid=@userid@ where ${primaryKey}=@${primaryKeyName};`
+      _sql += `
+        /* 榛樿sql */
+        update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuserid=@userid@ where ${primaryKey}=@${primaryKeyName};`
     
     } else if (_actionType === 'delete') {      // 鐗╃悊鍒犻櫎
       let _msg = ''
@@ -1227,9 +1263,13 @@
           }
         })
       }
-      _sql += `insert into snote (remark,createuserid,CreateUser,CreateStaff) select left('鍒犻櫎琛�:${btn.sql} 鏁版嵁: ${_msg}${primaryKey}='+@${primaryKeyName},200),@userid@,@username,@fullname delete ${btn.sql} where ${primaryKey}=@${primaryKeyName};`
+      _sql += `
+        /* 榛樿sql */
+        insert into snote (remark,createuserid,CreateUser,CreateStaff) select left('鍒犻櫎琛�:${btn.sql} 鏁版嵁: ${_msg}${primaryKey}='+@${primaryKeyName},200),@userid@,@username,@fullname delete ${btn.sql} where ${primaryKey}=@${primaryKeyName};`
     } else if (_actionType === 'insertOrUpdate') {
-      _sql += `select @tbid=''
+      _sql += `
+        /* 榛樿sql */
+        select @tbid=''
         select @tbid='X' from ${btn.sql} where ${primaryKey}=@ID@
         if @tbid=''
           begin
@@ -1248,7 +1288,9 @@
     }
 
     _sql += `
-      aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
+        aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
+
+    _sql = _sql.replace(/\n\s{8}/ig, '\n')
     console.log(_sql)
     return _sql
   }

--
Gitblit v1.8.0