<?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="com.huatek.busi.mapper.AlgorithmBasicDataMapper">

    <sql id="Base_Column_List">
        A.id,
        A.algorithm AS algorithm,
        A.parent_id AS "parent.id",
		A.parent_ids AS parentIds,
        B.algorithm AS parentName,
        A.create_user AS createUser,
        A.create_time AS createTime,
        A.update_user AS updateUser,
        A.update_time AS updateTime,
        A.deleted
    </sql>

    <sql id="AlgorithmBasicDataJoins">
        LEFT JOIN x_algorithm_basic_data B ON A.parent_id = B.id
    </sql>

    <select id = "findPage" parameterType = "com.huatek.busi.where.AlgorithmBasicDataSelectVo" resultType="com.huatek.busi.dto.AlgorithmBasicDataDto">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        x_algorithm_basic_data A
        <include refid="AlgorithmBasicDataJoins"/>
        WHERE
        A.deleted = 0
        <if test="algorithm != null and algorithm != '' ">
            and A.algorithm like CONCAT('%',#{algorithm},'%')
        </if>

        <if test="parentName != null and parentName != '' ">
            and B.algorithm like CONCAT('%',#{algorithm},'%')
        </if>
    </select>

    <select id="findByParentIdsLike" resultType="com.huatek.busi.entity.AlgorithmBasicData">
		SELECT
			a.id,
			a.parent_id AS "parent.id",
			a.parent_ids
		FROM x_algorithm_basic_data a
		WHERE a.deleted = 0 AND a.parent_id LIKE #{parentId}
	</select>

    <update id="updateParentIds">
		UPDATE x_algorithm_basic_data SET
			parent_id = #{parent.id},
			parent_ids = #{parentIds}
		WHERE id = #{id}
	</update>

    <update id="delete">
		UPDATE x_algorithm_basic_data SET
			deleted = 1
		WHERE id = #{id}
	</update>
</mapper>