<?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.zehong.system.mapper.TTransactionProjectMapper">
    
    <resultMap type="TTransactionProject" id="TTransactionProjectResult">
        <result property="transactionProjectId"    column="transaction_project_id"    />
        <result property="transactionProjectName"    column="transaction_project_name"    />
        <result property="dutyDetailDescribe"    column="duty_detail_describe"    />
        <result property="workResultStyle"    column="work_result_style"    />
        <result property="workResultDetail"    column="work_result_detail"    />
        <result property="workResultMethod"    column="work_result_method"    />
        <result property="dutyMethod"    column="duty_method"    />
        <result property="priceType"    column="price_type"    />
        <result property="price"    column="price"    />
        <result property="deptId"    column="deptId"    />
        <result property="unit"    column="unit"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remark"    column="remark"    />
        <result property="deptName" column="dept_name"/>
    </resultMap>

    <sql id="selectTTransactionProjectVo">
        select transaction_project_id, transaction_project_name, duty_detail_describe, work_result_style, work_result_detail, work_result_method, duty_method, price_type, price, dept_id AS deptId,unit, create_time, update_time, is_del, remark,(SELECT dept.dept_name FROM sys_dept dept WHERE dept.dept_id = deptId)AS dept_name from t_transaction_project
    </sql>

    <select id="selectTTransactionProjectList" parameterType="TTransactionProject" resultMap="TTransactionProjectResult">
        <include refid="selectTTransactionProjectVo"/>
        <where>  
            <if test="transactionProjectName != null  and transactionProjectName != ''"> and transaction_project_name like concat('%', #{transactionProjectName}, '%')</if>
            <if test="dutyDetailDescribe != null  and dutyDetailDescribe != ''"> and duty_detail_describe = #{dutyDetailDescribe}</if>
            <if test="workResultStyle != null  and workResultStyle != ''"> and work_result_style = #{workResultStyle}</if>
            <if test="workResultDetail != null  and workResultDetail != ''"> and work_result_detail = #{workResultDetail}</if>
            <if test="workResultMethod != null  and workResultMethod != ''"> and work_result_method = #{workResultMethod}</if>
            <if test="dutyMethod != null  and dutyMethod != ''"> and duty_method = #{dutyMethod}</if>
            <if test="priceType != null  and priceType != ''"> and price_type = #{priceType}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="isDel != null  and isDel != ''"> and is_del = #{isDel}</if>
        </where>
        ORDER BY create_time DESC
    </select>
    
    <select id="selectTTransactionProjectById" parameterType="Long" resultMap="TTransactionProjectResult">
        <include refid="selectTTransactionProjectVo"/>
        where transaction_project_id = #{transactionProjectId}
    </select>

    <select id="selectTransactionProjectByName" parameterType="String" resultMap="TTransactionProjectResult">
        <include refid="selectTTransactionProjectVo"/>
        where transaction_project_name = #{transactionProjectName}
    </select>
        
    <insert id="insertTTransactionProject" parameterType="TTransactionProject" useGeneratedKeys="true" keyProperty="transactionProjectId">
        insert into t_transaction_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="transactionProjectName != null">transaction_project_name,</if>
            <if test="dutyDetailDescribe != null">duty_detail_describe,</if>
            <if test="workResultStyle != null">work_result_style,</if>
            <if test="workResultDetail != null">work_result_detail,</if>
            <if test="workResultMethod != null">work_result_method,</if>
            <if test="dutyMethod != null">duty_method,</if>
            <if test="priceType != null">price_type,</if>
            <if test="price != null">price,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="unit != null">unit,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="transactionProjectName != null">#{transactionProjectName},</if>
            <if test="dutyDetailDescribe != null">#{dutyDetailDescribe},</if>
            <if test="workResultStyle != null">#{workResultStyle},</if>
            <if test="workResultDetail != null">#{workResultDetail},</if>
            <if test="workResultMethod != null">#{workResultMethod},</if>
            <if test="dutyMethod != null">#{dutyMethod},</if>
            <if test="priceType != null">#{priceType},</if>
            <if test="price != null">#{price},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="unit != null">#{unit},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTTransactionProject" parameterType="TTransactionProject">
        update t_transaction_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="transactionProjectName != null">transaction_project_name = #{transactionProjectName},</if>
            <if test="dutyDetailDescribe != null">duty_detail_describe = #{dutyDetailDescribe},</if>
            <if test="workResultStyle != null">work_result_style = #{workResultStyle},</if>
            <if test="workResultDetail != null">work_result_detail = #{workResultDetail},</if>
            <if test="workResultMethod != null">work_result_method = #{workResultMethod},</if>
            <if test="dutyMethod != null">duty_method = #{dutyMethod},</if>
            <if test="priceType != null">price_type = #{priceType},</if>
            <if test="price != null">price = #{price},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where transaction_project_id = #{transactionProjectId}
    </update>

    <delete id="deleteTTransactionProjectById" parameterType="Long">
        delete from t_transaction_project where transaction_project_id = #{transactionProjectId}
    </delete>

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