Procházet zdrojové kódy

fix(national-motion-system-biz): 修复用户查询 SQL 语句中的错误

- 修复了查询用户所属部门名称时的 SQL语句错误
- 使用 GROUP_CONCAT 函数将多个部门名称合并为一个字符串
- 优化了 SQL 语句的格式和缩进
SheepHy před 2 dny
rodič
revize
8da8fe5142

+ 21 - 11
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/mapper/xml/AppInstructorMapper.xml

@@ -104,22 +104,31 @@
 
     </select>
     <select id="findPage" resultType="org.jeecg.modules.system.app.vo.staff.StaffResponseVO">
-        select a.id,a.username,a.realname,a.status,a.create_time,c.depart_name from sys_user a
-        left join  sys_user_depart b on a.id = b.user_id
-        left join sys_depart c on b.dep_id  = c.id and c.id in (select id from sys_depart where org_code LIKE CONCAT('',#{orgCode},'%'))
-        left join nm_instructor d on a.id =d.user_id and d.del_flag=0
-        where 1=1 and a.del_flag=0 and c.id in (select id from sys_depart where org_code LIKE CONCAT('',#{orgCode},'%'))
-        <if test="staffRequestVO!=null and staffRequestVO!=''">
-            <if test="staffRequestVO.deptId!=null and staffRequestVO.deptId!=''">
+        SELECT
+        a.id,
+        a.username,
+        a.realname,
+        a.status,
+        a.create_time,
+        GROUP_CONCAT(c.depart_name SEPARATOR ',') AS depart_name
+        FROM sys_user a
+        LEFT JOIN sys_user_depart b ON a.id = b.user_id
+        LEFT JOIN sys_depart c ON b.dep_id = c.id
+        AND c.id IN (SELECT id FROM sys_depart WHERE org_code LIKE CONCAT('', #{orgCode}, '%'))
+        LEFT JOIN nm_instructor d ON a.id = d.user_id AND d.del_flag = 0
+        WHERE a.del_flag = 0
+        AND c.id IN (SELECT id FROM sys_depart WHERE org_code LIKE CONCAT('', #{orgCode}, '%'))
+        <if test="staffRequestVO != null and staffRequestVO != ''">
+            <if test="staffRequestVO.deptId != null and staffRequestVO.deptId != ''">
                 AND c.id = #{staffRequestVO.deptId}
             </if>
-            <if test="staffRequestVO.phone!=null and staffRequestVO.phone!=''">
+            <if test="staffRequestVO.phone != null and staffRequestVO.phone != ''">
                 AND a.phone = #{staffRequestVO.phone}
             </if>
-            <if test="staffRequestVO.username!=null and staffRequestVO.username!=''">
+            <if test="staffRequestVO.username != null and staffRequestVO.username != ''">
                 AND a.username = #{staffRequestVO.username}
             </if>
-            <if test="staffRequestVO.status!=null and staffRequestVO.status!=''">
+            <if test="staffRequestVO.status != null and staffRequestVO.status != ''">
                 AND a.status = #{staffRequestVO.status}
             </if>
             <if test="staffRequestVO.endTime!=null  and staffRequestVO.endTime!=''">
@@ -129,7 +138,8 @@
                 <![CDATA[   AND DATE_FORMAT(a.create_time, '%Y-%m-%d')>=  DATE_FORMAT(#{staffRequestVO.startTime}, '%Y-%m-%d') ]]>
             </if>
         </if>
-        order by a.create_time desc
+        GROUP BY a.id
+        ORDER BY a.create_time DESC
     </select>
     <select id="findByStaffId"  resultMap="staffVOResult">
         select a.id as staffId,b.id as instructorId,a.username,a.realname,a.status,null as password,b.training_programs,b.teaching_philosophy,b.excel_msg,a.certificate_innocence,a.healthy,a.honor,b.background_img