<?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.lz.modules.flow.dao.ResultCalculateMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.flow.entity.ResultCalculate">
        <id column="id" property="id"/>
        <result column="is_delete" property="isDelete"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="name" property="name"/>
        <result column="calculate" property="calculate"/>
        <result column="remark" property="remark"/>
        <result column="business_id" property="businessId"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, name AS name, calculate AS calculate, remark AS remark, business_id AS businessId
    </sql>




    <select id="selectResultCalculateById" resultType="ResultCalculate" >
        select * from lz_result_calculate  where id=#{id} and is_delete = 0 limit 1 
    </select>


    <insert id="insertResultCalculate" parameterType="ResultCalculate" useGeneratedKeys="true" keyProperty="id" >
        insert into lz_result_calculate(
            <if test="name != null">name, </if>
            <if test="calculate != null">calculate, </if>
            <if test="remark != null">remark, </if>
            <if test="businessId != null">business_id, </if>
            is_delete,
            gmt_create,
            gmt_modified
        )values(
            <if test="name != null">#{ name}, </if>
            <if test="calculate != null">#{ calculate}, </if>
            <if test="remark != null">#{ remark}, </if>
            <if test="businessId != null">#{ businessId}, </if>
            0,
            now(),
            now()
        )
    </insert>


    <update id="updateResultCalculateById" parameterType="ResultCalculate" >
        update
            lz_result_calculate
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="name != null">name = #{name},</if>
            <if test="calculate != null">calculate = #{calculate},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="businessId != null">business_id = #{businessId}</if>                
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverResultCalculateById" parameterType="ResultCalculate" >
        update
            lz_result_calculate    
        set     
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            name = #{name},
            calculate = #{calculate},
            remark = #{remark},
            business_id = #{businessId}                
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="deleteResultCalculateById" parameterType="java.lang.Long">
        update lz_result_calculate set is_delete = 1 where id=#{id} limit 1  
    </update>

    <select id="selectResultCalculateByBusinessId" resultType="com.lz.modules.flow.model.ResultCalculateDto" >
        select id, name, remark from lz_result_calculate  where business_id=#{id} and is_delete = 0
    </select>

</mapper>

