<?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.th.demo.mapping.maint.OrdTractMapper" >
    <resultMap id="BaseResultMap" type="com.th.demo.model.maint.OrdTract" >
        <result column="contract_no" property="contractNo" jdbcType="VARCHAR" />
        <result column="ord_no" property="ordNo" jdbcType="VARCHAR" />
        <result column="pay_way" property="payWay" jdbcType="VARCHAR" />
        <result column="remark" property="remark" jdbcType="VARCHAR" />

    </resultMap>

    <insert id="insert" parameterType="com.th.demo.model.maint.OrdTract" >
        insert into t_maint_ordtract (contract_no,ord_no,pay_way,remark,cancel_flag)
        values (#{contractNo,jdbcType=VARCHAR}, #{ordNo,jdbcType=VARCHAR}, #{payWay,jdbcType=VARCHAR},
                #{remark,jdbcType=VARCHAR}, #{cancelFlag,jdbcType=VARCHAR})
    </insert>

    <update id="delete"  parameterType="java.lang.String">
        update t_maint_ordtract
        set cancel_flag = '1'
        where ord_no = #{param1,jdbcType=VARCHAR}
    </update>

    <update id="update" parameterType="com.th.demo.model.maint.OrdTract" >
        update t_maint_ordtract
        set contract_no = #{contractNo,jdbcType=VARCHAR},
            pay_way = #{payWay,jdbcType=VARCHAR},
            cancel_flag = #{cancelFlag,jdbcType=VARCHAR},
            remark = #{remark,jdbcType=VARCHAR}
        where ord_no = #{ordNo,jdbcType=VARCHAR}
    </update>

    <select id="select" resultMap="BaseResultMap" parameterType="java.lang.String" >
        select *
        from t_maint_ordtract
        where 1= 1
        <if test="param1 != null and param1 != ''" >
            AND (ord_no like concat('%',#{param1,jdbcType=VARCHAR},'%')
            or contract_no like concat('%',#{param1,jdbcType=VARCHAR},'%'))
        </if>
        and ifnull(cancel_flag,'0') = '0'
    </select>

    <select id="selectByOrdNo" resultMap="BaseResultMap" >
        select t.*
        from t_maint_ordtract t
        where t.ord_no  = #{param1,jdbcType=VARCHAR}
          and ifnull(t.cancel_flag,'0') = '0'
    </select>

</mapper>