<?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.fs.company.mapper.CompanySalesPlanMapper">
    
    <resultMap type="CompanySalesPlan" id="CompanySalesPlanResult">
        <result property="id"    column="id"    />
        <result property="companyId"    column="company_id"    />
        <result property="planName"    column="plan_name"    />
        <result property="planCode"    column="plan_code"    />
        <result property="planUserId"    column="plan_user_id"    />
        <result property="planDeptId"    column="plan_dept_id"    />
        <result property="planTime"    column="plan_time"    />
        <result property="planDesc"    column="plan_desc"    />
        <result property="remark"    column="remark"    />
        <result property="productId"    column="product_id"    />
        <result property="stockId"    column="stock_id"    />
        <result property="saleNum"    column="sale_num"    />
        <result property="salePrice"    column="sale_price"    />
        <result property="saleTargetName"    column="sale_target_name"    />
        <result property="saleTargetMobile"    column="sale_target_mobile"    />
        <result property="saleTargetAddress"    column="sale_target_address"    />
        <result property="saleTargetRemark"    column="sale_target_remark"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="updateUserId"    column="update_user_id"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectCompanySalesPlanVo">
        select id, company_id, plan_name, plan_code, plan_user_id, plan_dept_id, plan_time, plan_desc, remark, product_id, stock_id, sale_num, sale_price, sale_target_name, sale_target_mobile, sale_target_address, sale_target_remark, status, create_time, update_time, create_user_id, update_user_id, is_del from company_sales_plan
    </sql>

    <select id="selectCompanySalesPlanList" parameterType="CompanySalesPlan" resultMap="CompanySalesPlanResult">
        <include refid="selectCompanySalesPlanVo"/>
        <where>  
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="planName != null  and planName != ''"> and plan_name like concat('%', #{planName}, '%')</if>
            <if test="planCode != null  and planCode != ''"> and plan_code = #{planCode}</if>
            <if test="planUserId != null "> and plan_user_id = #{planUserId}</if>
            <if test="planDeptId != null "> and plan_dept_id = #{planDeptId}</if>
            <if test="planTime != null "> and plan_time = #{planTime}</if>
            <if test="planDesc != null  and planDesc != ''"> and plan_desc = #{planDesc}</if>
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="stockId != null "> and stock_id = #{stockId}</if>
            <if test="saleNum != null "> and sale_num = #{saleNum}</if>
            <if test="salePrice != null "> and sale_price = #{salePrice}</if>
            <if test="saleTargetName != null  and saleTargetName != ''"> and sale_target_name like concat('%', #{saleTargetName}, '%')</if>
            <if test="saleTargetMobile != null  and saleTargetMobile != ''"> and sale_target_mobile = #{saleTargetMobile}</if>
            <if test="saleTargetAddress != null  and saleTargetAddress != ''"> and sale_target_address = #{saleTargetAddress}</if>
            <if test="saleTargetRemark != null  and saleTargetRemark != ''"> and sale_target_remark = #{saleTargetRemark}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
            <if test="updateUserId != null "> and update_user_id = #{updateUserId}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
        </where>
    </select>
    
    <select id="selectCompanySalesPlanById" parameterType="Long" resultMap="CompanySalesPlanResult">
        <include refid="selectCompanySalesPlanVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCompanySalesPlan" parameterType="CompanySalesPlan" useGeneratedKeys="true" keyProperty="id">
        insert into company_sales_plan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="planName != null">plan_name,</if>
            <if test="planCode != null">plan_code,</if>
            <if test="planUserId != null">plan_user_id,</if>
            <if test="planDeptId != null">plan_dept_id,</if>
            <if test="planTime != null">plan_time,</if>
            <if test="planDesc != null">plan_desc,</if>
            <if test="remark != null">remark,</if>
            <if test="productId != null">product_id,</if>
            <if test="stockId != null">stock_id,</if>
            <if test="saleNum != null">sale_num,</if>
            <if test="salePrice != null">sale_price,</if>
            <if test="saleTargetName != null">sale_target_name,</if>
            <if test="saleTargetMobile != null">sale_target_mobile,</if>
            <if test="saleTargetAddress != null">sale_target_address,</if>
            <if test="saleTargetRemark != null">sale_target_remark,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="updateUserId != null">update_user_id,</if>
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="planName != null">#{planName},</if>
            <if test="planCode != null">#{planCode},</if>
            <if test="planUserId != null">#{planUserId},</if>
            <if test="planDeptId != null">#{planDeptId},</if>
            <if test="planTime != null">#{planTime},</if>
            <if test="planDesc != null">#{planDesc},</if>
            <if test="remark != null">#{remark},</if>
            <if test="productId != null">#{productId},</if>
            <if test="stockId != null">#{stockId},</if>
            <if test="saleNum != null">#{saleNum},</if>
            <if test="salePrice != null">#{salePrice},</if>
            <if test="saleTargetName != null">#{saleTargetName},</if>
            <if test="saleTargetMobile != null">#{saleTargetMobile},</if>
            <if test="saleTargetAddress != null">#{saleTargetAddress},</if>
            <if test="saleTargetRemark != null">#{saleTargetRemark},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="updateUserId != null">#{updateUserId},</if>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateCompanySalesPlan" parameterType="CompanySalesPlan">
        update company_sales_plan
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="planName != null">plan_name = #{planName},</if>
            <if test="planCode != null">plan_code = #{planCode},</if>
            <if test="planUserId != null">plan_user_id = #{planUserId},</if>
            <if test="planDeptId != null">plan_dept_id = #{planDeptId},</if>
            <if test="planTime != null">plan_time = #{planTime},</if>
            <if test="planDesc != null">plan_desc = #{planDesc},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="stockId != null">stock_id = #{stockId},</if>
            <if test="saleNum != null">sale_num = #{saleNum},</if>
            <if test="salePrice != null">sale_price = #{salePrice},</if>
            <if test="saleTargetName != null">sale_target_name = #{saleTargetName},</if>
            <if test="saleTargetMobile != null">sale_target_mobile = #{saleTargetMobile},</if>
            <if test="saleTargetAddress != null">sale_target_address = #{saleTargetAddress},</if>
            <if test="saleTargetRemark != null">sale_target_remark = #{saleTargetRemark},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</if>
            <if test="updateUserId != null">update_user_id = #{updateUserId},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCompanySalesPlanById" parameterType="Long">
        delete from company_sales_plan where id = #{id}
    </delete>

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