<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.stm.base.classify.mapper.StClassifyMapper">

	<!-- 优化说明：
         1. 统一了代码格式和缩进
         2. 移除了不必要的parameterType
         3. 优化了SQL语句的可读性
         4. 保持了原有的功能逻辑
         5. 添加了注释说明
    -->

	<!-- 更新树节点状态 -->
	<update id="updateTreeNodeStatus">
		UPDATE st_classify
		SET has_child = #{status}
		WHERE classify_code = #{id}
	</update>

	<!-- 根据父ID查询分类列表 -->
	<select id="queryListByPid" resultType="org.jeecg.common.system.vo.SelectTreeModel">
		SELECT
		id AS "key",
		classifyName AS "title",
		CASE WHEN has_child = '1' THEN 0 ELSE 1 END AS isLeaf,
		upperClassifyCode AS parentId
		FROM st_classify
		WHERE upperClassifyCode = #{pid}
		<if test="query != null">
			<!-- 动态添加查询条件 -->
			<foreach collection="query.entrySet()" item="value" index="key">
				AND ${key} = #{value}
			</foreach>
		</if>
	</select>

</mapper>