<?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.dataease.base.mapper.ext.ExtProjectMapper">

    <select id="getProjectWithWorkspace" resultType="io.dataease.dto.ProjectDTO">
        select p.id, p.workspace_id, p.name, p.description, p.update_time,
        p.create_time, w.id as workspaceId, w.name as workspaceName, p.tapd_id, p.jira_key, p.zentao_id,p.repeatable
        from project p
        join workspace w on p.workspace_id = w.id
        <where>
            <if test="proRequest.name != null and proRequest.name != ''">
                and p.name like #{proRequest.name, jdbcType=VARCHAR}
            </if>
            <if test="proRequest.workspaceId != null">
                and w.id = #{proRequest.workspaceId}
            </if>
        </where>
        <if test="proRequest.orders != null and proRequest.orders.size() > 0">
            order by
            <foreach collection="proRequest.orders" separator="," item="order">
                p.${order.name} ${order.type}
            </foreach>
        </if>
    </select>
    <select id="getProjectIdByWorkspaceId" resultType="java.lang.String">
        select id
          from project
          where workspace_id = #{workspaceId}
    </select>

    <update id="removeIssuePlatform">
        update project
        <set>
            <if test="platform == 'Jira'">
                jira_key = null
            </if>
            <if test="platform == 'Tapd'">
                tapd_id = null
            </if>
            <if test="platform == 'Zentao'">
                zentao_id = null
            </if>
        </set>
        where project.id in (select id from (select id
        from project
        where workspace_id in
        (select workspace.id
        from workspace
        where organization_id = #{orgId})) as a)
    </update>

</mapper>
