<?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.ruoyi.system.mapper.CompanyAppMapper">

    <resultMap type="CompanyApp" id="CompanyAppResult">
        <result property="id"    column="id"    />
        <result property="companyId"    column="company_id"    />
        <result property="appName"    column="app_name"    />
        <result property="wxAppId"    column="wx_app_id"    />
        <result property="imgUrl"    column="img_url"    />
        <result property="videoUrl"    column="video_url"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCompanyAppVo">
        select id, company_id, app_name, wx_app_id, img_url, video_url, status, create_time, create_by, update_by, update_time, remark from company_app
    </sql>

    <select id="selectCompanyAppList" parameterType="CompanyApp" resultMap="CompanyAppResult">
        <include refid="selectCompanyAppVo"/>
        <where>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="appName != null  and appName != ''"> and app_name like concat('%', #{appName}, '%')</if>
            <if test="wxAppId != null  and wxAppId != ''"> and wx_app_id = #{wxAppId}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>

    <select id="selectCompanyAppById" parameterType="Long" resultMap="CompanyAppResult">
        <include refid="selectCompanyAppVo"/>
        where id = #{id}
    </select>

    <insert id="insertCompanyApp" parameterType="CompanyApp" useGeneratedKeys="true" keyProperty="id">
        insert into company_app
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="appName != null">app_name,</if>
            <if test="wxAppId != null">wx_app_id,</if>
            <if test="imgUrl != null">img_url,</if>
            <if test="videoUrl != null">video_url,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="appName != null">#{appName},</if>
            <if test="wxAppId != null">#{wxAppId},</if>
            <if test="imgUrl != null">#{imgUrl},</if>
            <if test="videoUrl != null">#{videoUrl},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateCompanyApp" parameterType="CompanyApp">
        update company_app
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="appName != null">app_name = #{appName},</if>
            <if test="wxAppId != null">wx_app_id = #{wxAppId},</if>
            <if test="imgUrl != null">img_url = #{imgUrl},</if>
            <if test="videoUrl != null">video_url = #{videoUrl},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCompanyAppById" parameterType="Long">
        delete from company_app where id = #{id}
    </delete>

    <delete id="deleteCompanyAppByIds" parameterType="String">
        delete from company_app where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>