Procházet zdrojové kódy

2023-12-5 修改sql之前的内置函数,用find_in_set函数代替。

chaiyunlong před 2 roky
rodič
revize
aa298d0bcd

+ 4 - 36
zd-modules/zd-chemical/src/main/resources/mapper/chemical/ActHxpapplyMapper.xml

@@ -29,29 +29,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             SELECT xx.id,xx.applyNum,xx.subscriber,xx.subName,xx.chemicalNames,xx.createTime,xx.overTime,xx.approvalContent,xx.approvalStatus,
             CASE WHEN xx.approvalStatus = 0 THEN
             (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur
-                WHERE ur.`user_id`
-                IN (
-                SELECT
-                SUBSTRING_INDEX(SUBSTRING_INDEX(xx.currentApprover,',', b.help_topic_id + 1), ',', -1) result
-                FROM
-                mysql.help_topic b
-                WHERE
-                b.help_topic_id < (LENGTH(xx.currentApprover) - LENGTH(REPLACE(xx.currentApprover, ',', '')) + 1)
-                )
+                WHERE FIND_IN_SET(ur.`user_id` ,xx.currentApprover )
             )
             ELSE ''
             END currentApprover,
             CASE WHEN xx.approvalStatus = 3 THEN ''
             ELSE (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur
-                WHERE ur.`user_id`
-                IN (
-                SELECT
-                SUBSTRING_INDEX(SUBSTRING_INDEX(xx.historyApprover,',', b.help_topic_id + 1), ',', -1) result
-                FROM
-                mysql.help_topic b
-                WHERE
-                b.help_topic_id < (LENGTH(xx.historyApprover) - LENGTH(REPLACE(xx.historyApprover, ',', '')) + 1)
-                )
+                WHERE FIND_IN_SET(ur.`user_id` ,xx.historyApprover)
             )
             END historyApprover,
             xx.currentApprover currentApproverIds,xx.userId
@@ -127,29 +111,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             SELECT xx.id,xx.applyNum,xx.subscriber,xx.subName,xx.chemicalNames,xx.createTime,xx.overTime,xx.approvalContent,xx.approvalStatus,
             CASE WHEN xx.approvalStatus = 0 THEN
             (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur
-                WHERE ur.`user_id`
-                IN (
-                SELECT
-                SUBSTRING_INDEX(SUBSTRING_INDEX(xx.currentApprover,',', b.help_topic_id + 1), ',', -1) result
-                FROM
-                mysql.help_topic b
-                WHERE
-                b.help_topic_id < (LENGTH(xx.currentApprover) - LENGTH(REPLACE(xx.currentApprover, ',', '')) + 1)
-                )
+                WHERE FIND_IN_SET(ur.`user_id` ,xx.currentApprover)
             )
             ELSE ''
             END currentApprover,
             CASE WHEN xx.approvalStatus = 3 THEN ''
             ELSE (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur
-                WHERE ur.`user_id`
-                IN (
-                SELECT
-                SUBSTRING_INDEX(SUBSTRING_INDEX(xx.historyApprover,',', b.help_topic_id + 1), ',', -1) result
-                FROM
-                mysql.help_topic b
-                WHERE
-                b.help_topic_id < (LENGTH(xx.historyApprover) - LENGTH(REPLACE(xx.historyApprover, ',', '')) + 1)
-                )
+                WHERE FIND_IN_SET(ur.`user_id` ,xx.historyApprover)
             )
             END historyApprover,
             xx.currentApprover currentApproverIds,xx.userId

+ 5 - 42
zd-modules/zd-modules-laboratory/src/main/resources/mapper/laboratory/LabSubjectMapper.xml

@@ -177,14 +177,7 @@
                hardware_type,
                (SELECT GROUP_CONCAT(ur.nick_name)
                 FROM sys_user ur
-                WHERE ur.`user_id`
-                          IN (
-                          SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(s.safe_user_id, ',', b.help_topic_id + 1), ',',
-                                                 -1) result
-                          FROM mysql.help_topic b
-                          WHERE b.help_topic_id <
-                                (LENGTH(s.safe_user_id) - LENGTH(REPLACE(s.safe_user_id, ',', '')) + 1)
-                      )
+                WHERE FIND_IN_SET(ur.`user_id` ,s.safe_user_id)
                )                                                                safeUserNames,
                (select f.`name`
                 from lab_build_floor f
@@ -205,14 +198,7 @@
                 where bfl.sub_id = s.id)                                        roomName,
                (SELECT GROUP_CONCAT(phonenumber)
                 FROM sys_user ur
-                WHERE ur.`user_id`
-                          IN (
-                          SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(s.safe_user_id, ',', b.help_topic_id + 1), ',',
-                                                 -1) result
-                          FROM mysql.help_topic b
-                          WHERE b.help_topic_id <
-                                (LENGTH(s.safe_user_id) - LENGTH(REPLACE(s.safe_user_id, ',', '')) + 1)
-                      )
+                WHERE FIND_IN_SET(ur.`user_id` ,s.safe_user_id)
                )                                                                safeUserPhone
         from lab_subject s
     </sql>
@@ -1169,15 +1155,7 @@
         check_out, check_in, safe_user_id, safe_signs, hazard_category, risk_measure,
         outfire, qr_code,safe_user_id, skipped, check_count,sign_time,
         (SELECT GROUP_CONCAT(ur.nick_name) FROM sys_user ur
-        WHERE ur.`user_id`
-        IN (
-        SELECT
-        SUBSTRING_INDEX(SUBSTRING_INDEX(s.safe_user_id,',', b.help_topic_id + 1), ',', -1) result
-        FROM
-        mysql.help_topic b
-        WHERE
-        b.help_topic_id &lt; (LENGTH(s.safe_user_id) - LENGTH(REPLACE(s.safe_user_id, ',', '')) + 1)
-        )
+        WHERE FIND_IN_SET(ur.`user_id` ,s.safe_user_id )
         ) AS safeUserNames,
         (select f.`name`
         from lab_build_floor f
@@ -1197,15 +1175,7 @@
         from lab_build_floor_layout bfl
         where bfl.sub_id = s.id ) roomName,
         (SELECT GROUP_CONCAT(phonenumber) FROM sys_user ur
-        WHERE ur.`user_id`
-        IN (
-        SELECT
-        SUBSTRING_INDEX(SUBSTRING_INDEX(s.safe_user_id,',', b.help_topic_id + 1), ',', -1) result
-        FROM
-        mysql.help_topic b
-        WHERE
-        b.help_topic_id &lt; (LENGTH(s.safe_user_id) - LENGTH(REPLACE(s.safe_user_id, ',', '')) + 1)
-        )
+        WHERE FIND_IN_SET(ur.`user_id` ,s.safe_user_id )
         ) safeUserPhone
         from lab_subject s
         <where>
@@ -1281,14 +1251,7 @@
             ls.safe_user_id safeUserId,
             (SELECT GROUP_CONCAT(ur.phonenumber)
                 FROM sys_user ur
-                WHERE ur.`user_id`
-                IN (
-                SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(ls.safe_user_id, ',', b.help_topic_id + 1), ',',
-                -1) result
-                FROM mysql.help_topic b
-                WHERE b.help_topic_id &lt;
-                (LENGTH(ls.safe_user_id) - LENGTH(REPLACE(ls.safe_user_id, ',', '')) + 1)
-                )
+                WHERE FIND_IN_SET(ur.`user_id`,ls.safe_user_id)
             ) safeUserPhone
         FROM
         `lab_subject` ls

+ 2 - 8
zd-modules/zd-modules-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -1157,14 +1157,8 @@
         </if>
 
         <if test="subSafe != null and subSafe != ''">
-            SELECT s.id subId,s.`name` subName,s.`room` subRomm,d.`dept_id` deptId,d.`dept_name` deptName,u.`user_id` userId,u.`nick_name` nickName,2 attriType FROM lab_subject s INNER JOIN sys_user u ON u.`user_id`
-            IN (
-            SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(s.safe_user_id, ',', b.help_topic_id + 1), ',',
-            -1) result
-            FROM mysql.help_topic b
-            WHERE b.help_topic_id &lt;
-            (LENGTH(s.safe_user_id) - LENGTH(REPLACE(s.safe_user_id, ',', '')) + 1)
-            )
+            SELECT s.id subId,s.`name` subName,s.`room` subRomm,d.`dept_id` deptId,d.`dept_name` deptName,u.`user_id` userId,u.`nick_name` nickName,2 attriType FROM lab_subject s INNER JOIN sys_user u
+            ON FIND_IN_SET(u.`user_id`,s.safe_user_id)
             INNER JOIN sys_dept d ON s.`dept_id` = d.`dept_id`
             WHERE u.del_flag=0 AND s.is_del=0
             <if test="(subWhite != null and subWhite != '')">