<?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.ytpm.dao.AppMapper">

    <insert id="insertOne">
        insert into yt_app
        (
         app_id,
         app_key,
         app_name,
         user_id,
         app_type,
         apk_url,
         qr_code,
         version_code,
         update_tips,
         store_on_sale,
         store_type,
         package_name,
         domain,
         category,
         sub_category,
         coppa,
         screen_orientation,
         ccpa,
         store_url,
         ditch_id,
         ditch_name,
         superior_id,
         enabled
        )
        values
        (
         #{appId},
         #{appKey},
         #{appName},
         #{userId},
         #{appType},
         #{apkUrl},
         #{qrCode},
         #{versionCode},
         #{updateTips},
         #{storeOnSale},
         #{storeType},
         #{packageName},
         #{domain},
         #{category},
         #{subCategory},
         #{coppa},
         #{screenOrientation},
         #{ccpa},
         #{storeUrl},
         #{ditchId},
         #{ditchName},
         #{superiorId},
         #{enabled}
        )
    </insert>
    <update id="updateOne">
        update yt_app
        <set>
            <if test="appKey != null">
                app_key = #{appKey},
            </if>
            <if test="appName != null">
                app_name = #{appName},
            </if>
            <if test="appType != null">
                app_type = #{appType},
            </if>
            <if test="versionCode != null">
                version_code = #{versionCode},
            </if>
            <if test="updateTips != null">
                update_tips = #{updateTips},
            </if>
            <if test="enabled != null">
                enabled = #{enabled},
            </if>
            <if test="storeOnSale != null">
                store_on_sale = #{storeOnSale},
            </if>
            <if test="storeType != null">
                store_type = #{storeType},
            </if>
            <if test="storeUrl != null">
                store_url = #{storeUrl},
            </if>
            <if test="packageName != null">
                package_name = #{packageName},
            </if>
            <if test="domain != null">
                domain = #{domain},
            </if>
            <if test="category != null">
                category = #{category},
            </if>
            <if test="subCategory != null">
                sub_category = #{subCategory},
            </if>
            <if test="coppa != null">
                coppa = #{coppa},
            </if>
            <if test="screenOrientation != null">
                screen_orientation = #{screenOrientation},
            </if>
            <if test="ccpa != null">
                ccpa = #{ccpa},
            </if>
            <if test=" apkUrl != null">
                apk_url = #{apkUrl},
            </if>
            <if test="qrCode != null">
                qr_code = #{qrCode},
            </if>
            <if test="ditchId != null">
                ditch_id = #{ditchId},
            </if>
            <if test="ditchName != null">
                ditch_name = #{ditchName},
            </if>
            <if test="superiorId != null">
                superior_id = #{superiorId}
            </if>
        </set>
        where app_id = #{appId}
    </update>
    <update id="deleteApp">
        update yt_app set enabled = 0 where app_id = #{appId}
    </update>
    <select id="selectPrimary" resultType="com.ytpm.agent.model.YtApp">
        select
            app_id,ditch_id, ditch_name,  app_key, app_name,user_id, app_type, apk_url, qr_code, version_code, update_tips, enabled,superior_id
        from yt_app
        where app_id = #{appId}
    </select>
    <select id="queryAll" resultType="com.ytpm.agent.model.YtApp">
        select
            app_id, ditch_id, ditch_name, app_key, app_name, user_id, app_type, apk_url, qr_code, version_code, update_tips, enabled, store_on_sale, store_type, store_url, package_name, domain, category, sub_category, coppa, screen_orientation, ccpa, superior_id
        from yt_app
        where user_id = #{userId}
    </select>

    <select id="selectByDitchId" resultType="com.ytpm.agent.model.YtApp">
        select
            app_id, ditch_id, ditch_name, app_key, app_name,user_id, app_type, apk_url, qr_code, version_code, update_tips, enabled,ditch_name,ditch_id
        from yt_app
        where ditch_id = #{ditchId}
    </select>
    <select id="getAppList" resultType="com.ytpm.middle.view.AppListVO">
        select
        pua.app_id,
        pua.app_name,
        pua.user_id,
        pua.app_type,
        pua.detail_url,
        pua.package_name,
        pua.domain,
        pua.issued_time,
        pua.wx_app_id,
        pua.wx_secret,
        me.enterprise_name,
        me.legal,
        me.concat_phone,
        me.credit_code
        from yt_platform_user_app pua
        left join yt_middle_enterprise me on pua.user_id = me.user_id
        <where>
            pua.available = 1
            <if test="appType != null">
                and pua.app_type = #{appType}
            </if>
            <if test="appName != null and appName!=''">
                and pua.app_name like concat('%', #{appName} ,'%')
            </if>
        </where>
        order by
        pua.issued_time
    </select>
    <select id="getByDitchIdAndSuperiorId" resultType="com.ytpm.agent.model.YtApp">
        select
            app_id, app_key, app_name, user_id, app_type, apk_url, qr_code, version_code, update_tips, enabled, store_on_sale, store_type, store_url, package_name, domain, category, sub_category, coppa, screen_orientation, ccpa, feign_path, ditch_id, ditch_name, superior_id
        from yt_app
        where superior_id = #{superiorId} and ditch_id = #{ditchId}
    </select>
    <select id="getBySuperiorId" resultType="com.ytpm.agent.model.YtApp">
        select
            app_id, app_key, app_name, user_id, app_type, apk_url, qr_code, version_code, update_tips, enabled, store_on_sale, store_type, store_url, package_name, domain, category, sub_category, coppa, screen_orientation, ccpa, feign_path, ditch_id, ditch_name, superior_id
        from yt_app
        where superior_id = #{superiorId}
    </select>
</mapper>