<?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.djhk.uav.equ.mapper.EquTranMapper">

	<resultMap id="EquTranEntityResult" type="com.djhk.uav.equ.domain.EquTranEntity">
		<id property="tranSeq" column="tran_seq" jdbcType="INTEGER"/>
		<result property="equId" column="equ_id" jdbcType="INTEGER"/>
		<result property="sendOrgan" column="send_organ" jdbcType="BIGINT"/>
		<result property="recvOrgan" column="recv_organ" jdbcType="BIGINT"/>
		<result property="tranSts" column="tran_sts" jdbcType="CHAR"/>
		<result property="sendBy" column="send_by" jdbcType="VARCHAR"/>
		<result property="sendTime" column="send_time" jdbcType="TIMESTAMP"/>
		<result property="recvBy" column="recv_by" jdbcType="VARCHAR"/>
		<result property="recvTime" column="recv_time" jdbcType="TIMESTAMP"/>
		<result property="cacelBy" column="cacel_by" jdbcType="VARCHAR"/>
		<result property="cancelTime" column="cancel_time" jdbcType="TIMESTAMP"/>
	</resultMap>

	<sql id="selectEquTranVo">
     select tran_seq,equ_id,send_organ,
        recv_organ,tran_sts,send_by,
        send_time,recv_by,recv_time,
        cacel_by,cancel_time from equ_tran tran
    </sql>

	<select id="selectEquTranList" parameterType="com.djhk.uav.equ.domain.EquTranEntity" resultMap="EquTranEntityResult">
		<include refid="selectEquTranVo"/>
		<where>
			<if test="equId != null and equId != ''">
				AND equ_id = #{equId}
			</if>
			<if test="tranSts != null and tranSts != ''">
				AND tran_sts = #{tranSts}
			</if>
		</where>
		order by send_time asc
	</select>

	<select id="selectEquTranById" parameterType="String" resultMap="EquTranEntityResult">
		<include refid="selectEquTranVo"/>
		where tran_seq = #{tranSeq}
	</select>


	<delete id="deleteEquTranById" parameterType="String">
 		delete from equ_tran where tran_seq = #{tranSeq}
 	</delete>


	<insert id="insertEquTran" parameterType="com.djhk.uav.equ.domain.EquTranEntity">
		insert into equ_tran(
		<if test="equId != null and equId != ''">equ_id,</if>
		<if test="sendOrgan != null and sendOrgan != ''">send_organ,</if>
		<if test="recvOrgan != null and recvOrgan != ''">recv_organ,</if>
		<if test="sendBy != null and sendBy != ''">send_by,</if>
		<if test="recvBy != null and recvBy != ''">recv_by,</if>
		<if test="recvTime != null and recvTime != ''">recv_time,</if>
		<if test="cacelBy != null and cacelBy != ''">cacel_by,</if>
		<if test="cancelTime != null and cancelTime != ''">cancel_time,</if>
		tran_sts,
		send_time
		)values(
		<if test="equId != null and equId != ''">#{equId},</if>
		<if test="sendOrgan != null and sendOrgan != ''">#{sendOrgan},</if>
		<if test="recvOrgan != null and recvOrgan != ''">#{recvOrgan},</if>
		<if test="sendBy != null and sendBy != ''">#{sendBy},</if>
		<if test="recvBy != null and recvBy != ''">#{recvBy},</if>
		<if test="recvTime != null and recvTime != ''">#{recvTime},</if>
		<if test="cacelBy != null and cacelBy != ''">#{cacelBy},</if>
		<if test="cancelTime != null and cancelTime != ''">#{cancelTime},</if>
		0,
		DATE_FORMAT(SYSDATE(), '%Y-%m-%d %H:%i:%s')
		)
	</insert>
	<update id="updateEquTran" parameterType="com.djhk.uav.equ.domain.EquTranEntity">
		update equ_tran
		<set>
			<if test="sendOrgan != null and sendOrgan != ''">send_organ = #{sendOrgan},</if>
			<if test="recvOrgan != null and recvOrgan != ''">recv_organ = #{recvOrgan},</if>
			<if test="tranSts != null and tranSts != ''">tran_sts = #{tranSts},</if>
			<if test="sendBy != null and sendBy != ''">send_by = #{sendBy},</if>
			<if test="recvBy != null and recvBy != ''">recv_by = #{recvBy},recv_time = DATE_FORMAT(SYSDATE(), '%Y-%m-%d %H:%i:%s'),</if>
			<if test="cacelBy != null and cacelBy != ''">cacel_by = #{cacelBy},cancel_time = DATE_FORMAT(SYSDATE(), '%Y-%m-%d %H:%i:%s'),</if>
			equ_id = #{equId}
		</set>
		where tran_seq = #{tranSeq}
	</update>

	<select id="getTranSts" resultMap="EquTranEntityResult">
		<include refid="selectEquTranVo"/>
		 where equ_id=#{equId} order by send_time desc limit 1
	</select>

</mapper>
