serv\web- 多租户修改
This commit is contained in:
@@ -65,13 +65,57 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 查询成就列表 -->
|
||||
<!-- 权限过滤条件(基于dept_path的高效继承) -->
|
||||
<sql id="Permission_Filter">
|
||||
INNER JOIN tb_resource_permission rp ON a.achievement_id = rp.resource_id
|
||||
AND rp.resource_type = 6
|
||||
AND rp.deleted = 0
|
||||
AND rp.can_read = 1
|
||||
AND (
|
||||
(rp.dept_id IS NULL AND rp.role_id IS NULL)
|
||||
<if test="userDeptRoles != null and userDeptRoles.size() > 0">
|
||||
OR EXISTS (
|
||||
SELECT 1
|
||||
FROM (
|
||||
<foreach collection="userDeptRoles" item="udr" separator=" UNION ALL ">
|
||||
SELECT #{udr.deptID} AS dept_id, #{udr.deptPath} AS dept_path, #{udr.roleID} AS role_id
|
||||
</foreach>
|
||||
) user_roles
|
||||
LEFT JOIN tb_sys_dept perm_dept ON perm_dept.dept_id = rp.dept_id AND perm_dept.deleted = 0
|
||||
WHERE
|
||||
(rp.role_id IS NULL AND rp.dept_id IS NOT NULL
|
||||
AND user_roles.dept_path LIKE CONCAT(perm_dept.dept_path, '%'))
|
||||
OR (rp.dept_id IS NULL AND rp.role_id = user_roles.role_id)
|
||||
OR (rp.dept_id = user_roles.dept_id AND rp.role_id = user_roles.role_id)
|
||||
)
|
||||
</if>
|
||||
)
|
||||
</sql>
|
||||
|
||||
<!-- 查询成就列表 - 添加权限过滤 -->
|
||||
<select id="selectAchievements" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_achievement
|
||||
<include refid="Base_Where_Clause" />
|
||||
ORDER BY order_num ASC, create_time DESC
|
||||
SELECT DISTINCT a.*
|
||||
FROM tb_achievement a
|
||||
<include refid="Permission_Filter" />
|
||||
WHERE 1=1
|
||||
<if test="filter != null">
|
||||
<if test="filter.achievementID != null and filter.achievementID != ''">
|
||||
AND a.achievement_id = #{filter.achievementID}
|
||||
</if>
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND a.name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.type != null">
|
||||
AND a.type = #{filter.type}
|
||||
</if>
|
||||
<if test="filter.level != null">
|
||||
AND a.level = #{filter.level}
|
||||
</if>
|
||||
<if test="filter.deleted != null">
|
||||
AND a.deleted = #{filter.deleted}
|
||||
</if>
|
||||
</if>
|
||||
ORDER BY a.order_num ASC, a.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据成就ID查询成就信息 -->
|
||||
@@ -227,20 +271,133 @@
|
||||
</delete>
|
||||
|
||||
<!-- 分页查询成就 -->
|
||||
<!-- selectAchievementsPage - 添加权限过滤 -->
|
||||
<select id="selectAchievementsPage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_achievement
|
||||
<include refid="Base_Where_Clause" />
|
||||
ORDER BY order_num ASC, create_time DESC
|
||||
SELECT DISTINCT a.*
|
||||
FROM tb_achievement a
|
||||
<include refid="Permission_Filter" />
|
||||
WHERE 1=1
|
||||
<if test="filter != null">
|
||||
<if test="filter.achievementID != null and filter.achievementID != ''">
|
||||
AND a.achievement_id = #{filter.achievementID}
|
||||
</if>
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND a.name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.type != null">
|
||||
AND a.type = #{filter.type}
|
||||
</if>
|
||||
<if test="filter.level != null">
|
||||
AND a.level = #{filter.level}
|
||||
</if>
|
||||
<if test="filter.deleted != null">
|
||||
AND a.deleted = #{filter.deleted}
|
||||
</if>
|
||||
</if>
|
||||
ORDER BY a.order_num ASC, a.create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<!-- 统计成就总数 -->
|
||||
<!-- 统计成就总数 - 添加权限过滤 -->
|
||||
<select id="countAchievements" resultType="long">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_achievement
|
||||
<include refid="Base_Where_Clause" />
|
||||
SELECT COUNT(DISTINCT a.id)
|
||||
FROM tb_achievement a
|
||||
<include refid="Permission_Filter" />
|
||||
WHERE 1=1
|
||||
<if test="filter != null">
|
||||
<if test="filter.achievementID != null and filter.achievementID != ''">
|
||||
AND a.achievement_id = #{filter.achievementID}
|
||||
</if>
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND a.name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.type != null">
|
||||
AND a.type = #{filter.type}
|
||||
</if>
|
||||
<if test="filter.level != null">
|
||||
AND a.level = #{filter.level}
|
||||
</if>
|
||||
<if test="filter.deleted != null">
|
||||
AND a.deleted = #{filter.deleted}
|
||||
</if>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- AchievementVO 结果映射(包含用户成就和进度信息) -->
|
||||
<resultMap id="AchievementVOResultMap" type="org.xyzh.common.vo.AchievementVO">
|
||||
<!-- 成就基本信息 -->
|
||||
<id column="id" property="ID" />
|
||||
<result column="achievement_id" property="achievementID" />
|
||||
<result column="name" property="name" />
|
||||
<result column="description" property="description" />
|
||||
<result column="icon" property="icon" />
|
||||
<result column="type" property="type" />
|
||||
<result column="level" property="level" />
|
||||
<result column="condition_type" property="conditionType" />
|
||||
<result column="condition_value" property="conditionValue" />
|
||||
<result column="points" property="points" />
|
||||
<result column="order_num" property="orderNum" />
|
||||
<result column="creator" property="creator" />
|
||||
<result column="updater" property="updater" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="update_time" property="updateTime" />
|
||||
<result column="deleted" property="deleted" />
|
||||
|
||||
<!-- 用户信息 -->
|
||||
<result column="user_id" property="userID" />
|
||||
|
||||
<!-- 用户成就信息 -->
|
||||
<result column="user_achievement_id" property="userAchievementID" />
|
||||
<result column="obtain_time" property="obtainTime" />
|
||||
<result column="obtained" property="obtained" />
|
||||
|
||||
<!-- 进度信息 -->
|
||||
<result column="progress_id" property="progressID" />
|
||||
<result column="current_value" property="currentValue" />
|
||||
<result column="target_value" property="targetValue" />
|
||||
<result column="progress_percentage" property="progressPercentage" />
|
||||
<result column="completed" property="completed" />
|
||||
<result column="last_update_time" property="lastUpdateTime" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 联表查询用户成就列表(包含进度信息)- 带权限过滤 -->
|
||||
<select id="selectUserAchievementsWithProgress" resultMap="AchievementVOResultMap">
|
||||
SELECT
|
||||
a.id,
|
||||
a.achievement_id,
|
||||
a.name,
|
||||
a.description,
|
||||
a.icon,
|
||||
a.type,
|
||||
a.level,
|
||||
a.condition_type,
|
||||
a.condition_value,
|
||||
a.points,
|
||||
a.order_num,
|
||||
a.creator,
|
||||
a.updater,
|
||||
a.create_time,
|
||||
a.update_time,
|
||||
a.deleted,
|
||||
#{userId} as user_id,
|
||||
ua.id as user_achievement_id,
|
||||
ua.obtain_time,
|
||||
CASE WHEN ua.id IS NOT NULL THEN 1 ELSE 0 END as obtained,
|
||||
p.id as progress_id,
|
||||
COALESCE(p.current_value, 0) as current_value,
|
||||
COALESCE(p.target_value, a.condition_value) as target_value,
|
||||
COALESCE(p.progress_percentage, 0) as progress_percentage,
|
||||
COALESCE(p.completed, 0) as completed,
|
||||
p.last_update_time
|
||||
FROM tb_achievement a
|
||||
<include refid="Permission_Filter"/>
|
||||
LEFT JOIN tb_user_achievement ua ON a.achievement_id = ua.achievement_id AND ua.user_id = #{userId}
|
||||
LEFT JOIN tb_user_achievement_progress p ON a.achievement_id = p.achievement_id AND p.user_id = #{userId}
|
||||
WHERE a.deleted = 0
|
||||
<if test="type != null">
|
||||
AND a.type = #{type}
|
||||
</if>
|
||||
ORDER BY a.order_num ASC, a.create_time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user