<?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="net.northking.cctp.project.db.dao.CpProjectSoftwareDao">

    <delete id="deleteByProjectId" parameterType="java.lang.String">
        delete from
        <include refid="Table_Name"/>
        where project_id =#{projectId}
    </delete>

    <select id="listProjectIdSoftware" resultType="java.lang.String"
            parameterType="net.northking.cctp.project.db.entity.CpProjectSoftware">
        select
        project_id
        from
        <include refid="Table_Name"/>
        software
        inner join
        ${defaultSchema}.cp_project pro
        on software.project_id = pro.id where pro.is_deleted = false
        <if test="tenantId != null">
            AND software.tenant_id=#{tenantId,jdbcType=VARCHAR}
        </if>
        <if test="softwareId != null">
            AND software.software_id=#{softwareId,jdbcType=VARCHAR}
        </if>
    </select>

    <insert id="saveProjectSoftware">
        insert into
        <include refid="Table_Name"/>
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="tenantId!= null">
                tenant_id,
            </if>
            <if test="projectId!= null">
                project_id,
            </if>
            <if test="softwareId!= null">
                software_id,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="tenantId!= null">
                #{tenantId},
            </if>
            <if test="projectId!= null">
                #{projectId},
            </if>
            <if test="softwareId!= null">
                #{softwareId},
            </if>
        </trim>
    </insert>
</mapper>