<?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="io.renren.modules.minio.mapper.MinioAlgorithmMapper">

    <select id="getMinioAlgorithmList" resultMap="minioAlgorithmMapping">
        select model_id,
               model_name,
               classification.name          as classification,
               sys_user.username            as creator,
               if(form = 1, '传统算法', '智能算法') as form,
               remark,
               construct_message
        from algorithm_model,
             classification,
             sys_user
        where algorithm_model.category_id = classification.id
          and algorithm_model.uid = sys_user.user_id
          and is_approvaled = 1
          and is_preassembled is NULL
    </select>
    <select id="selectByName" parameterType="java.lang.String" resultMap="minioAlgorithmMapping">
        select model_id,
               model_name,
               classification.name          as classification,
               sys_user.username            as creator,
               if(form = 1, '传统算法', '智能算法') as form,
               remark,
               construct_message
        from algorithm_model,
             classification,
             sys_user
        where algorithm_model.category_id = classification.id
          and algorithm_model.uid = sys_user.user_id
          and is_approvaled = 1
          and is_preassembled is NULL
          and model_name like concat('%','${algName}','%')
    </select>

    <select id="getAlgorithmNum" resultType="Integer">
        select count(*)
        from algorithm_model,
             classification,
             sys_user
        where algorithm_model.category_id = classification.id
          and algorithm_model.uid = sys_user.user_id
    </select>

    <resultMap type="io.renren.modules.minio.pojo.MinioAlgorithm" id="minioAlgorithmMapping">
        <id property="algorithmId" column="model_id"/>
        <result property="algorithmName" column="model_name"/>
        <result property="category" column="classification"/>
        <result property="creator" column="creator"/>
        <result property="form" column="form"/>
        <result property="remark" column="remark"/>
        <result property="constructMessage" column="construct_message" />
    </resultMap>

    <select id="findModelByName" resultType="Integer">
        select algorithm_model.model_id
        from algorithm_model
        where algorithm_model.model_name = #{algorithmName}
    </select>

    <select id="findAppFileByName" resultType="String">
        select algorithm_model.app_file
        from algorithm_model
        where algorithm_model.model_name = #{algorithmName}
    </select>

    <select id="findImageFileByName" resultType="String">
        select algorithm_model.image_file
        from algorithm_model
        where algorithm_model.model_name = #{algorithmName}
    </select>

    <select id="findBelongAlgId" resultType="Long">
        select algorithm_model.algorithm_id
        from algorithm_model
        where algorithm_model.model_name = #{algorithmName}
    </select>

</mapper>