fix: 优化SQL

This commit is contained in:
萌狼蓝天 2024-11-18 18:22:59 +08:00
parent ebc2e3a22b
commit 3e01554ae5
2 changed files with 27 additions and 8 deletions

View File

@ -116,6 +116,9 @@ public class UserServiceImpl implements UserService {
Map<String, Object> queryConditions = new HashMap<>(); Map<String, Object> queryConditions = new HashMap<>();
queryConditions.put("excludeUid", uid); queryConditions.put("excludeUid", uid);
queryConditions.put("currentLevel", currentLevel); // 添加当前用户的等级作为查询条件 queryConditions.put("currentLevel", currentLevel); // 添加当前用户的等级作为查询条件
System.out.println("==============================" +
queryConditions.toString() +
"============================");
List<UserInfo> userInfos; List<UserInfo> userInfos;
log.info("要查询的用户类型是:{}", userListParam.getUserType()); log.info("要查询的用户类型是:{}", userListParam.getUserType());
if (Objects.equals(userListParam.getUserType(), "activate")) { if (Objects.equals(userListParam.getUserType(), "activate")) {

View File

@ -41,11 +41,28 @@
</select> </select>
<!-- getUserListAll 方法 --> <!-- getUserListAll 方法 -->
<!-- <select id="getUserListAll" resultType="com.guaiguailang.harmony.domain.entity.UserInfo">-->
<!-- SELECT * FROM user_info-->
<!-- <where>-->
<!-- <if test="merchantCode != 'ALL'">-->
<!-- WHERE merchant_code = #{merchantCode}-->
<!-- </if>-->
<!-- <if test="queryConditions.excludeUid != null">-->
<!-- AND id != #{queryConditions.excludeUid}-->
<!-- </if>-->
<!-- <if test="queryConditions.currentLevel != null">-->
<!-- AND role_id IN (-->
<!-- SELECT role_id FROM system_role WHERE level >= #{queryConditions.currentLevel}-->
<!-- )-->
<!-- </if>-->
<!-- </where>-->
<!-- LIMIT #{limit},#{end}-->
<!-- </select>-->
<select id="getUserListAll" resultType="com.guaiguailang.harmony.domain.entity.UserInfo"> <select id="getUserListAll" resultType="com.guaiguailang.harmony.domain.entity.UserInfo">
SELECT * FROM user_info SELECT * FROM user_info
<where> <where>
<if test="merchantCode != 'ALL'"> <if test="merchantCode != 'ALL'">
WHERE merchant_code = #{merchantCode} merchant_code = #{merchantCode}
</if> </if>
<if test="queryConditions.excludeUid != null"> <if test="queryConditions.excludeUid != null">
AND id != #{queryConditions.excludeUid} AND id != #{queryConditions.excludeUid}
@ -56,9 +73,8 @@
) )
</if> </if>
</where> </where>
LIMIT #{limit},#{end} LIMIT #{limit}, #{end}
</select> </select>
<select id="getUserListNum" resultType="com.guaiguailang.harmony.domain.vo.UserListNum"> <select id="getUserListNum" resultType="com.guaiguailang.harmony.domain.vo.UserListNum">
SELECT SELECT
SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) AS userActivatedNum, SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) AS userActivatedNum,