<?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="cn.superdesk.uniorder.dao.mapper.sys.SysBackAccountMapper">
	<resultMap id="BaseResultMap" type="cn.superdesk.uniorder.dao.entity.sys.SysBackAccount">
		<id column="id" property="id" jdbcType="BIGINT"/>
		<result column="dz_main_id" property="dzMainId" jdbcType="BIGINT"/>
		<result column="dz_order_id" property="dzOrderId" jdbcType="BIGINT"/>
		<result column="back_account_person_id" property="backAccountPersonId" jdbcType="INTEGER"/>
		<result column="back_account_person" property="backAccountPerson" jdbcType="VARCHAR"/>
		<result column="back_account_time" property="backAccountTime" jdbcType="TIMESTAMP"/>
		<result column="back_operation_time" property="backOperationTime" jdbcType="TIMESTAMP"/>
		<result column="back_account" property="backAccount" jdbcType="DECIMAL"/>
		<result column="back_account_remark" property="backAccountRemark" jdbcType="VARCHAR"/>
	</resultMap>
	<sql id="Base_Column_List">
    id, dz_main_id, dz_order_id, back_account_person_id, ,back_account_person,back_account_time, back_operation_time, 
    back_account, back_account_remark
  </sql>
	<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
		select
		<include refid="Base_Column_List"/>
		from sys_back_account
		where id = #{id,jdbcType=BIGINT}
	</select>
	<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from sys_back_account
    where id = #{id,jdbcType=BIGINT}
  </delete>
	<insert id="insert" parameterType="cn.superdesk.uniorder.dao.entity.sys.SysBackAccount">
		<selectKey resultType="java.lang.Long" keyProperty="id" order="AFTER">
			SELECT LAST_INSERT_ID()
		</selectKey>
		insert into sys_back_account (dz_main_id, dz_order_id, back_account_person_id,
		back_account_time, back_operation_time,
		back_account, back_account_remark)
		values (#{dzMainId,jdbcType=BIGINT}, #{dzOrderId,jdbcType=BIGINT}, #{backAccountPersonId,jdbcType=INTEGER},
		#{backAccountTime,jdbcType=TIMESTAMP}, #{backOperationTime,jdbcType=TIMESTAMP},
		#{backAccount,jdbcType=DECIMAL}, #{backAccountRemark,jdbcType=VARCHAR})
	</insert>
	<insert id="insertSelective" parameterType="cn.superdesk.uniorder.dao.entity.sys.SysBackAccount">
		<selectKey resultType="java.lang.Long" keyProperty="id" order="AFTER">
			SELECT LAST_INSERT_ID()
		</selectKey>
		insert into sys_back_account
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="dzMainId != null">
				dz_main_id,
			</if>
			<if test="dzOrderId != null">
				dz_order_id,
			</if>
			<if test="backAccountPersonId != null">
				back_account_person_id,
			</if>
			<if test="backAccountTime != null">
				back_account_time,
			</if>
			<if test="backOperationTime != null">
				back_operation_time,
			</if>
			<if test="backAccount != null">
				back_account,
			</if>
			<if test="backAccountRemark != null">
				back_account_remark,
			</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="dzMainId != null">
				#{dzMainId,jdbcType=BIGINT},
			</if>
			<if test="dzOrderId != null">
				#{dzOrderId,jdbcType=BIGINT},
			</if>
			<if test="backAccountPersonId != null">
				#{backAccountPersonId,jdbcType=INTEGER},
			</if>
			<if test="backAccountTime != null">
				#{backAccountTime,jdbcType=TIMESTAMP},
			</if>
			<if test="backOperationTime != null">
				#{backOperationTime,jdbcType=TIMESTAMP},
			</if>
			<if test="backAccount != null">
				#{backAccount,jdbcType=DECIMAL},
			</if>
			<if test="backAccountRemark != null">
				#{backAccountRemark,jdbcType=VARCHAR},
			</if>
		</trim>
	</insert>
	<update id="updateByPrimaryKeySelective" parameterType="cn.superdesk.uniorder.dao.entity.sys.SysBackAccount">
		update sys_back_account
		<set>
			<if test="dzMainId != null">
				dz_main_id = #{dzMainId,jdbcType=BIGINT},
			</if>
			<if test="dzOrderId != null">
				dz_order_id = #{dzOrderId,jdbcType=BIGINT},
			</if>
			<if test="backAccountPersonId != null">
				back_account_person_id = #{backAccountPersonId,jdbcType=INTEGER},
			</if>
			<if test="backAccountTime != null">
				back_account_time = #{backAccountTime,jdbcType=TIMESTAMP},
			</if>
			<if test="backOperationTime != null">
				back_operation_time = #{backOperationTime,jdbcType=TIMESTAMP},
			</if>
			<if test="backAccount != null">
				back_account = #{backAccount,jdbcType=DECIMAL},
			</if>
			<if test="backAccountRemark != null">
				back_account_remark = #{backAccountRemark,jdbcType=VARCHAR},
			</if>
		</set>
		where id = #{id,jdbcType=BIGINT}
	</update>
	<update id="updateByPrimaryKey" parameterType="cn.superdesk.uniorder.dao.entity.sys.SysBackAccount">
    update sys_back_account
    set dz_main_id = #{dzMainId,jdbcType=BIGINT},
      dz_order_id = #{dzOrderId,jdbcType=BIGINT},
      back_account_person_id = #{backAccountPersonId,jdbcType=INTEGER},
      back_account_time = #{backAccountTime,jdbcType=TIMESTAMP},
      back_operation_time = #{backOperationTime,jdbcType=TIMESTAMP},
      back_account = #{backAccount,jdbcType=DECIMAL},
      back_account_remark = #{backAccountRemark,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>


	<select id="findAll" resultMap="BaseResultMap">
		select
		bill.*,sysUser.fullname back_account_person
		from sys_back_account bill
		left join sys_user sysUser on bill.back_account_person_id=sysUser.id

		where 1=1

		<if test="mdzId != null ">
			and bill.dz_main_id = #{mdzId,jdbcType=BIGINT}
		</if>

		<if test="orderId != null ">
			and bill.dz_order_id = #{orderId,jdbcType=BIGINT}
		</if>

	</select>


</mapper>