<?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.bonus.zlpt.company.mapper.BusinessOpenMapper">


    <insert id="insertBusinessOpenInfo">
        insert into business_open
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null ">
                user_id,
            </if>
            <if test="coId != null and ">
                co_id,
            </if>
            <if test="businessId != null ">
                business_id,
            </if>
            <if test="time != null and time != ''">
                `time`,
            </if>
            <if test="fileName != null and fileName != ''">
                file_name,
            </if>
            <if test="fileUrl != null and fileUrl != ''">
                file_url,
            </if>
            <if test="auditor != null and auditor != ''">
                auditor,
            </if>
            <if test="auditTime != null and auditTime != ''">
                audit_time,
            </if>
            <if test="status != null and status != ''">
                status,
            </if>
            <if test="auditRemark != null and auditRemark != ''">
                audit_remark,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">
                #{userId},
            </if>
            <if test="coId != null">
                #{coId},
            </if>
            <if test="businessId != null and businessId != ''">
                #{businessId},
            </if>
            <if test="time != null and time != ''">
                #{time},
            </if>
            <if test="fileName != null and fileName != ''">
                #{fileName},
            </if>
            <if test="fileUrl != null and fileUrl != ''">
                #{fileUrl},
            </if>
            <if test="auditor != null and auditor != ''">
                #{auditor},
            </if>
            <if test="auditTime != null and auditTime != ''">
                #{auditTime},
            </if>
            <if test="status != null and status != ''">
                #{status},
            </if>
            <if test="auditRemark != null and auditRemark != ''">
                #{auditRemark},
            </if>
        </trim>


    </insert>


    <select id="selectList" resultType="com.bonus.zlpt.company.domain.vo.BusinessOpenVo">
        select b.*,c.company_name,c.credit_code,m.type businessType,u.nick_name nickName,u.user_name userName
        from
            business_open b,business_menu m,bm_company_info c,sys_user u
        <where>
            b.co_id = c.company_id
            and
            b.business_id = m.id
            and
            b.user_id = u.user_id
            <if test="companyName != null and companyName != ''">and c.company_name LIKE CONCAT('%',#{companyName},'%') </if>
            <if test="creditCode != null and creditCode != ''">and c.credit_code LIKE CONCAT('%',#{creditCode},'%')</if>
            <if test="userName != null and userName != ''">and u.nick_name LIKE CONCAT('%',#{userName},'%')</if>
            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
                and date_format( b.time, '%Y-%m-%d' )
                BETWEEN date_format( #{beginTime}, '%Y-%m-%d' )
                and date_format( #{endTime}, '%Y-%m-%d' )
            </if>
        </where>
    </select>


    <update id="updateBusiness">

        update business_open
        <set>
            <if test="userId != null">  user_id = #{userId},</if>
            <if test="coId != null ">  co_id = #{coId},</if>
            <if test="businessId != null ">  business_id=#{businessId} , </if>
            <if test="time != null and time != ''">  `time` = #{time}, </if>
            <if test="fileName != null and fileName != ''">  file_name = #{fileName},</if>
            <if test="fileUrl != null and fileUrl != ''">  file_url = #{fileUrl},</if>
            <if test="auditor != null and auditor != ''">  auditor = #{auditor},</if>
            <if test="auditTime != null and auditTime != ''">  audit_time = #{auditTime},</if>
            <if test="status != null and status != ''">  status = #{status},</if>
            <if test="auditRemark != null and auditRemark != ''">  audit_remark = #{auditRemark},</if>
        </set>
        where id = #{id}

    </update>


</mapper>