<?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.persagy.adm.server.algorithm.dao.AdmProjectUserMapper">

    <resultMap id="BaseResultMap" type="com.persagy.adm.server.algorithm.entity.AdmProjectUser">
            <id property="id" column="id" jdbcType="VARCHAR"/>
            <result property="projectId" column="project_id" jdbcType="VARCHAR"/>
            <result property="userId" column="user_id" jdbcType="VARCHAR"/>
            <result property="creator" column="creator" jdbcType="VARCHAR"/>
            <result property="creationTime" column="creation_time" jdbcType="CHAR"/>
            <result property="modifier" column="modifier" jdbcType="VARCHAR"/>
            <result property="modifiedTime" column="modified_time" jdbcType="CHAR"/>
            <result property="valid" column="valid" jdbcType="TINYINT"/>
            <result property="ts" column="ts" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,project_id,user_id,
        creator,creation_time,modifier,
        modified_time,valid,ts
    </sql>
    <select id="getProjectsByUserId" resultType="com.persagy.dmp.auth.domain.Project">
        SELECT project_user.project_id AS projectId,project.`name` AS projectName,project.group_code AS groupCode,
               project.group_name AS groupName FROM project_user INNER JOIN project
                   ON(project_user.project_id=project.id AND project.valid=TRUE AND project_user.valid=TRUE)
        WHERE project_user.user_id=#{userId};
    </select>
</mapper>
