From 072227ec43346c50c93cda3bf21c346f463eb551 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 19 十月 2023 22:28:56 +0800
Subject: [PATCH] 2023-10-19

---
 src/utils/utils.js |  271 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 221 insertions(+), 50 deletions(-)

diff --git a/src/utils/utils.js b/src/utils/utils.js
index 86577d3..7da4357 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -1,3 +1,4 @@
+import React from 'react'
 import moment from 'moment'
 import md5 from 'md5'
 
@@ -138,7 +139,7 @@
     ]
     
     if (type === 'customscript') {
-      chars = chars.filter(char => !['insert', 'delete', 'update', 'set', 'if', 'exec'].includes(char.key))
+      chars = chars.filter(char => !['create', 'insert', 'delete', 'update', 'set', 'drop', 'if', 'exec'].includes(char.key))
     }
 
     let error = ''
@@ -407,6 +408,10 @@
       }
 
       if (item.type === 'text' || item.type === 'select') {
+        if (/@username@|@fullName@/ig.test(item.initval)) {
+          item.initval = item.initval.replace(/@username@/ig, sessionStorage.getItem('User_Name') || '').replace(/@fullName@/ig, sessionStorage.getItem('Full_Name') || '')
+          item.oriInitval = item.initval
+        }
         if (/,/.test(item.field)) {
           item.field.split(',').forEach(field => {
             keys.push(field.toLowerCase())
@@ -1166,6 +1171,7 @@
     sql = sql.replace(/\n\s{6}/ig, '\n')
 
     if (window.GLOB.debugger === true) {
+      console.info('%c' + item.logLabel, 'color: blue')
       console.info(sql)
     }
   } else {
@@ -1372,6 +1378,7 @@
     sql = sql.replace(/\n\s{6}/ig, '\n')
 
     if (window.GLOB.debugger === true) {
+      console.info('%c' + btn.logLabel, 'color: blue')
       console.info(sql)
     }
   } else {
@@ -1557,8 +1564,6 @@
     }
 
     columns.forEach(col => {
-      if (col.field === 'works_flow_param') return
-
       if (col.type === 'colspan' || col.type === 'old_colspan') {
         col.subcols.forEach(cell => {
           setField(cell)
@@ -1578,7 +1583,7 @@
       Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50),@ModularDetailCode nvarchar(50), @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),@mk_deleted int,@bid nvarchar(50)${_declarefields}
     `
 
-  let userName = sessionStorage.getItem('User_Name') || ''
+  let userName = sessionStorage.getItem('User_Name') || '' 
   let fullName = sessionStorage.getItem('Full_Name') || ''
   let RoleID = sessionStorage.getItem('role_id') || ''
   let departmentcode = sessionStorage.getItem('departmentcode') || ''
@@ -2113,43 +2118,209 @@
     let status = 0
     let statusName = ''
     let detailId = ''
+    let error = ''
 
-    if (verify.flowSql === 'true') {
-      if (verify.flowType === 'start') {
-        target = flow.cells.filter(cell => cell.mknode === 'start')[0]
-
-        if (target) {
-          detailId = target.id
-          status = target.mkdata.status
-          statusName = target.mkdata.statusName
-        }
-      } else if (_data.works_flow_param) {
-        node = JSON.parse(window.decodeURIComponent(window.atob(_data.works_flow_param)))
-
-        if (node) {
-          line = flow.cells.filter(cell => cell.shape === 'edge' && cell.source.cell === node.id)[0]
-        }
-        
-        if (line) {
-          target = flow.cells.filter(cell => cell.id === line.target.cell)[0]
-        }
-      }
+    if (verify.flowType === 'start') {
+      target = flow.cells.filter(cell => cell.mknode === 'start')[0]
 
       if (target) {
+        detailId = target.id
+        status = target.mkdata.status
+        statusName = target.mkdata.statusName
+      } else {
+        error = '宸ヤ綔娴佹棤寮�濮嬭妭鐐�'
+      }
+    } else if (_data.works_flow_param) {
+      try {
+        node = JSON.parse(window.decodeURIComponent(window.atob(_data.works_flow_param)))
+      } catch (e) {
+        node = null
+      }
+
+      if (node) {
+        let lines = flow.cells.filter(cell => cell.shape === 'edge' && cell.source.cell === node.id)
+        if (verify.flowType === 'reject') {
+          line = lines.filter(cell => cell.mkdata.flowType === 'reject' || cell.mknode === 'startEdge')[0]
+        } else {
+          let endEdge = null
+          lines = lines.filter(cell => {
+            if (cell.mknode === 'endEdge') {
+              endEdge = cell
+              return false
+            }
+
+            return cell.mkdata.flowType !== 'reject' && cell.mknode !== 'startEdge'
+          })
+
+          if (lines.length === 0) {
+            if (!endEdge) {
+              error = '鏃犲彲鎵ц鐨勬祦绋嬪垎鏀�'
+            } else {
+              line = endEdge
+            }
+          } else {
+            let branchKey = verify.flowBranch ? verify.flowBranch.toLowerCase() : ''
+  
+            if (!branchKey) {
+              lines.forEach(line => {
+                if (line.mkdata.execCondition === 'open') {
+                  error = '鎸夐挳鏈缃祦绋嬫帶鍒跺瓧娈点��'
+                }
+              })
+              if (!error) {
+                line = lines[0]
+              }
+            } else if (!_data.hasOwnProperty(branchKey)) {
+              error = '琛屼俊鎭腑鏃犳祦绋嬫帶鍒跺瓧娈点��'
+            } else {
+              if (endEdge) {
+                line = endEdge
+              }
+
+              let equalLine = null
+              let gtOrLtLine = []
+              let unEqualLine = null
+              let branchVal = _data[branchKey]
+
+              if (branchVal && typeof(branchVal) === 'string' && !isNaN(branchVal)) {
+                branchVal = +branchVal
+              }
+
+              lines.forEach(item => {
+                if (item.mkdata.execCondition !== 'open') {
+                  line = item
+                } else {
+                  if (item.mkdata.match === '=') {
+                    if (item.mkdata.matchVal === branchVal + '') {
+                      equalLine = item
+                    }
+                  } else if (item.mkdata.match === '!=') {
+                    if (item.mkdata.matchVal !== branchVal + '') {
+                      unEqualLine = item
+                    }
+                  } else {
+                    if (item.mkdata.match === '<') {
+                      if (item.mkdata.matchVal < branchVal) {
+                        gtOrLtLine.push({...item, dist: Math.abs(item.mkdata.matchVal - branchVal)})
+                      }
+                    } else if (item.mkdata.match === '>') {
+                      if (item.mkdata.matchVal > branchVal) {
+                        gtOrLtLine.push({...item, dist: Math.abs(item.mkdata.matchVal - branchVal)})
+                      }
+                    } else if (item.mkdata.match === '<=') {
+                      if (item.mkdata.matchVal <= branchVal) {
+                        gtOrLtLine.push({...item, dist: Math.abs(item.mkdata.matchVal - branchVal)})
+                      }
+                    } else if (item.mkdata.match === '>=') {
+                      if (item.mkdata.matchVal >= branchVal) {
+                        gtOrLtLine.push({...item, dist: Math.abs(item.mkdata.matchVal - branchVal)})
+                      }
+                    }
+                  }
+                }
+              })
+
+              if (equalLine) {
+                line = equalLine
+              } else if (gtOrLtLine.length > 0) {
+                gtOrLtLine.sort((a, b) => a.dist - b.dist)
+                line = gtOrLtLine[0]
+              } else if (unEqualLine) {
+                line = unEqualLine
+              }
+            }
+          }
+        }
+      } else {
+        error = '琛屼俊鎭腑宸ヤ綔娴佸弬鏁版棤娉曡В鏋�'
+      }
+      
+      if (line) {
+        detailId = line.id
+        status = line.mkdata.status
+        statusName = line.mkdata.statusName
+        target = flow.cells.filter(cell => cell.id === line.target.cell)[0]
+      } else if (!error) {
+        error = '宸ヤ綔娴佷腑鏃犲搴旀祦绋�'
+      }
+    } else {
+      error = '琛屼俊鎭腑鏃犲伐浣滄祦鍙傛暟'
+    }
+
+    if (verify.flowSql === 'true' && target) {
+      if (verify.flowType === 'start') {
         _sql += `
       /* 宸ヤ綔娴侀粯璁ql */
-      insert into s_my_works_flow (works_flow_id,works_flow_code,works_flow_name,works_flow_param,work_group,works_flow_detail_id,work_grade,bid,createuserid,CreateUser,CreateStaff)
-      select @ID@,@works_flow_code@,@works_flow_name@,@works_flow_param@,@work_group@,@works_flow_detail_id@,@work_grade@,@bid@,@UserID@,@UserName,@FullName
-      insert into s_my_works_flow_log (works_flow_id,works_flow_code,works_flow_name,works_flow_param,status,statusname,works_flow_detail_id,work_group,work_grade)
-      select @ID@,@works_flow_code@,@works_flow_name@,@works_flow_param@,@status@,@statusname@,@works_flow_detail_id@,@work_group@,@work_grade@
+      insert into s_my_works_flow (works_flow_id,works_flow_code,works_flow_name,works_flow_param,status,statusname,work_group,works_flow_detail_id,work_grade,bid,createuserid,CreateUser,CreateStaff,upid)
+      select @ID@,@works_flow_code@,@works_flow_name@,@works_flow_param@,@status@,@statusname@,@work_group@,@works_flow_detail_id@,@work_grade@,@bid@,@UserID@,@UserName,@FullName,@time_id@
+      insert into s_my_works_flow_log (works_flow_id,works_flow_code,works_flow_name,works_flow_param,status,statusname,works_flow_detail_id,work_group,work_grade,upid)
+      select @ID@,@works_flow_code@,@works_flow_name@ ,@works_flow_param@,@status@,@statusname@,@works_flow_detail_id@,@work_group@,@work_grade@,@time_id@
+      insert into s_my_works_flow_notice (works_flow_id,works_flow_code,works_flow_detail_id,userid,notice_type,createuserid,CreateUser,CreateStaff,upid)
+      select @ID@,@works_flow_code@,@works_flow_detail_id@,@userid@,@start_type@,@userid@,@UserName,@FullName,@time_id@
+      `
+      } else {
+        _sql += `
+      /* 宸ヤ綔娴侀粯璁ql */
+      update s_my_works_flow set status=@status@,statusname=@statusname@,works_flow_param=@works_flow_param@,works_flow_detail_id=@works_flow_detail_id@,modifydate=getdate(),modifyuserid=@userid@,modifyuser=@username,modifystaff=@fullname
+      where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and deleted=0
+      insert into s_my_works_flow_log (works_flow_id,works_flow_code,works_flow_name,works_flow_param,status,statusname,works_flow_detail_id,work_group,work_grade,upid)
+      select @ID@,@works_flow_code@,@works_flow_name@ ,@works_flow_param@,@status@,@statusname@,@works_flow_detail_id@,@work_group@,@work_grade@,@time_id@
+      if @check_userids@ != ''
+      begin
+            delete s_my_works_flow_role where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and deleted=0
+            insert into s_my_works_flow_role (works_flow_id,works_flow_code,userid,works_flow_detail_id,createuserid,CreateUser,CreateStaff,upid)
+            select @ID@,@works_flow_code@,ID,@works_flow_detail_id@,@userid@,@UserName,@FullName,@time_id@ from dbo.SplitComma(@check_userids@)
+            insert into s_my_works_flow_notice (works_flow_id,works_flow_code,works_flow_detail_id,userid,notice_type,createuserid,CreateUser,CreateStaff,upid)
+            select @ID@,@works_flow_code@,@works_flow_detail_id@,ID,@check_type@,@userid@,@UserName,@FullName,@time_id@ from dbo.SplitComma(@check_userids@)
+      end
+      if @notice_userids@ != ''
+      begin
+            delete n
+            from (select * from s_my_works_flow_notice where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and deleted=0) n
+            inner join (select ID from dbo.SplitComma(@notice_userids@)) s
+            on n.userid = s.id
+            insert into s_my_works_flow_notice (works_flow_id,works_flow_code,works_flow_detail_id,userid,notice_type,createuserid,CreateUser,CreateStaff,upid)
+            select @ID@,@works_flow_code@,@works_flow_detail_id@,ID,@notice_type@,@userid@,@UserName,@FullName,@time_id@ from dbo.SplitComma(@notice_userids@)
+      end
       `
       }
+    } else if (verify.flowSql === 'true') {
+      status = 0
+      statusName = '寮傚父'
+
+      _sql += `
+      /* 宸ヤ綔娴佸紓甯竤ql */
+      select @ErrorCode='E',@retmsg='${error || '宸ヤ綔娴佹墽琛屽紓甯�'}' goto aaa
+      `
     }
+
+    if (verify.flowType !== 'start') {
+      if (line) {
+        let checkIds = []
+        let noticeIds = []
+        line.mkdata.members && line.mkdata.members.forEach(item => {
+          checkIds.push(item.worker_id)
+        })
+        line.mkdata.copys && line.mkdata.copys.forEach(item => {
+          noticeIds.push(item.worker_id)
+        })
+        _sql = _sql.replace(/@check_userids@/ig, `'${checkIds.join(',')}'`)
+        _sql = _sql.replace(/@notice_userids@/ig, `'${noticeIds.join(',')}'`)
+      } else {
+        _sql = _sql.replace(/@check_userids@/ig, `''`)
+        _sql = _sql.replace(/@notice_userids@/ig, `''`)
+      }
+    }
+
+    _sql = _sql.replace(/@start_type@/ig, `'寮�濮�'`)
+    _sql = _sql.replace(/@check_type@/ig, verify.flowType === 'reject' ? `'椹冲洖'` : `'瀹℃牳'`)
+    _sql = _sql.replace(/@notice_type@/ig, `'鎶勯��'`)
 
     _sql = _sql.replace(/@works_flow_code@/ig, `'${flow.flow_code}'`)
     _sql = _sql.replace(/@works_flow_name@/ig, `'${flow.flow_name}'`)
     if (target) {
-      let msg = {...target.mkdata, id: target.id}
+      let label = target.attrs && target.attrs.text && target.attrs.text.text ? target.attrs.text.text : ''
+      let msg = {...target.mkdata, label: label, id: target.id}
       _sql = _sql.replace(/@works_flow_param@/ig, `'${window.btoa(window.encodeURIComponent(JSON.stringify(msg)))}'`)
     } else {
       _sql = _sql.replace(/@works_flow_param@/ig, `''`)
@@ -2206,7 +2377,7 @@
   }
 
   if (window.GLOB.debugger === true) {
-    // _sql = _sql.replace(/\n\s{8}/ig, '\n')
+    console.info('%c' + btn.logLabel, 'color: blue')
     console.info(_sql)
   }
 
@@ -2224,10 +2395,7 @@
  * @description 鑾峰彇鏍囪淇℃伅
  */
 export function getMark (marks, record, style = {}) {
-  let icon = null
-  let innerStyle = null
-  let position = null
-  let signType = ''
+  let res = {}
   style = JSON.parse(JSON.stringify(style))
 
   marks.some(mark => {
@@ -2264,42 +2432,45 @@
 
     if (type === 'font') {
       style.color = mark.color
-      innerStyle = {color: mark.color}
-      signType = ' sign-font'
+      res.innerStyle = {color: mark.color}
+      res.signType = ' sign-font'
     } else if (type === 'background') {
       style.backgroundColor = mark.color
       if (mark.fontColor) {
         style.color = mark.fontColor
-        innerStyle = {color: mark.fontColor}
+        res.innerStyle = {color: mark.fontColor}
       }
     } else if (type === 'underline') {
       style.textDecoration = 'underline'
       style.color = mark.color
-      innerStyle = {color: mark.color, textDecoration: 'underline'}
+      res.innerStyle = {color: mark.color, textDecoration: 'underline'}
     } else if (type === 'line-through') {
       style.textDecoration = 'line-through'
       style.color = mark.color
-      innerStyle = {color: mark.color, textDecoration: 'line-through'}
+      res.innerStyle = {color: mark.color, textDecoration: 'line-through'}
     } else if (type.indexOf('icon') > -1) {
-      icon = mark.signType[mark.signType.length - 1]
-      innerStyle = {color: mark.color}
+      res.icon = mark.signType[mark.signType.length - 1]
+      res.innerStyle = {color: mark.color}
       if (type === 'iconfront' || mark.signType[1] === 'front') {
-        position = 'front'
+        res.position = 'front'
       } else {
-        position = 'back'
+        res.position = 'back'
       }
+    } else if (type === 'indent') {
+      style.color = mark.color
+      res.space = Array(mark.signType[1] + 1).join('&nbsp;')
+    } else if (type === 'pointfront') {
+      res.position = 'front'
+      res.point = <span style={{display: 'inline-block', marginRight: '3px', width: '8px', height: '8px', borderRadius: '14px', background: mark.color, verticalAlign: 'middle'}}></span>
+    } else if (type === 'pointback') {
+      res.position = 'back'
+      res.point = <span style={{display: 'inline-block', marginLeft: '3px', width: '8px', height: '8px', borderRadius: '14px', background: mark.color, verticalAlign: 'middle'}}></span>
     }
 
     return true
   })
 
-  return {
-    style,
-    icon,
-    innerStyle,
-    position,
-    signType
-  }
+  return res
 }
 
 /**

--
Gitblit v1.8.0