<?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.accounting.unified.customer.AccountingUnifiedCustomerMapperEx">



	<resultMap id="OrderResultMap" type="cn.superdesk.uniorder.dao.entity.sys.SysOrder">
		<id column="id" property="id" jdbcType="BIGINT"/>
		<result column="my_order_id" property="myOrderId" jdbcType="VARCHAR"/>
		<result column="order_id" property="orderId" jdbcType="BIGINT"/>
		<result column="my_ordersn" property="myOrdersn" jdbcType="VARCHAR"/>
		<result column="ordersn" property="ordersn" jdbcType="VARCHAR"/>
		<result column="parent_order_id" property="parentOrderId" jdbcType="INTEGER"/>
		<result column="parent_ordersn" property="parentOrdersn" jdbcType="VARCHAR"/>
		<result column="detail_url" property="detailUrl" jdbcType="VARCHAR"/>
		<result column="dispatchprice" property="dispatchprice" jdbcType="DECIMAL"/>
		<result column="price" property="price" jdbcType="DECIMAL"/>
		<result column="organization_id" property="organizationId" jdbcType="BIGINT"/>
		<result column="enterprise_id" property="enterpriseId" jdbcType="BIGINT"/>
		<result column="invoice_type" property="invoicetype" jdbcType="TINYINT"/>
		<result column="dispatchname" property="dispatchname" jdbcType="VARCHAR"/>
		<result column="createtime" property="createtime" jdbcType="TIMESTAMP"/>
		<result column="sync_time" property="syncTime" jdbcType="TIMESTAMP"/>
		<result column="paytime" property="paytime" jdbcType="TIMESTAMP"/>
		<result column="realname_id" property="realnameId" jdbcType="INTEGER"/>
		<result column="examine_id" property="examineId" jdbcType="INTEGER"/>
		<result column="address_realname" property="addressRealname" jdbcType="VARCHAR"/>
		<result column="address_mobile" property="addressMobile" jdbcType="VARCHAR"/>
		<result column="address_address" property="addressAddress" jdbcType="VARCHAR"/>
		<result column="companyName" property="companyname" jdbcType="VARCHAR"/>
		<result column="taxpayersIDcode" property="taxpayersidcode" jdbcType="VARCHAR"/>
		<result column="sendtime" property="sendtime" jdbcType="TIMESTAMP"/>
		<result column="finishtime" property="finishtime" jdbcType="TIMESTAMP"/>
		<result column="status" property="status" jdbcType="TINYINT"/>
		<result column="merch_name" property="merchName" jdbcType="VARCHAR"/>
		<result column="order_type" property="orderType" jdbcType="VARCHAR"/>
		<result column="paytype" property="paytype" jdbcType="TINYINT"/>
		<result column="search_field1" property="searchField1" jdbcType="VARCHAR"/>
		<result column="search_field2" property="searchField2" jdbcType="VARCHAR"/>
		<result column="search_field3" property="searchField3" jdbcType="VARCHAR"/>
		<result column="other_field1" property="otherField1" jdbcType="VARCHAR"/>
		<result column="other_field2" property="otherField2" jdbcType="VARCHAR"/>
		<result column="other_field3" property="otherField3" jdbcType="VARCHAR"/>
		<result column="remark" property="remark" jdbcType="VARCHAR"/>
		<result column="invoiceAccount" property="invoiceaccount" jdbcType="VARCHAR"/>
		<result column="is_gen_bill" property="isGenBill" jdbcType="TINYINT"/>
		<result column="invoiceBank" property="invoicebank" jdbcType="VARCHAR"/>
	</resultMap>

	<select id="findAllFromOrder" resultMap="OrderResultMap">
		select
			id, my_order_id, order_id, my_ordersn, ordersn, parent_order_id, parent_ordersn,
		detail_url, dispatchprice, price, organization_id, enterprise_id, invoiceType, dispatchname,
		createtime, sync_time, paytime, realname_id, examine_id, address_realname, address_mobile,
		address_address, companyName, taxpayersIDcode, sendtime, finishtime, status, merch_name,
		order_type, paytype, search_field1, search_field2, search_field3, other_field1, other_field2,
		other_field3, remark, invoiceAccount, is_gen_bill, invoiceBank
		from sys_order where 1 = 1

		<if test="isGenBill != null ">
			and is_gen_bill = #{isGenBill,jdbcType=TINYINT}
		</if>
		<if test="enterpriseId != null ">
			and enterprise_id = #{enterpriseId,jdbcType=BIGINT}
		</if>
		<if test="realnameId != null ">
			and realname_id = #{realnameId,jdbcType=INTEGER}
		</if>
		<if test="ids !=null and ids != ''">
			and id in
			<foreach collection="ids" index="index" item="oid" open="(" close=")" separator=",">
				#{oid}
			</foreach>
		</if>
		<if test="dateType != null ">
			<choose>
				<when test="dateType == 1">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}
					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<when test="dateType == 2">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<otherwise>
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</otherwise>
			</choose>
		</if>

	</select>

	<select id="findRealNamesByOrder" resultType="java.lang.String">
		select DISTINCT(realname_id) from sys_order where is_gen_bill = 0

		<if test="enterpriseId != null ">
			and enterprise_id = #{enterpriseId,jdbcType=BIGINT}
		</if>
		<if test="dateType != null ">
			<choose>
				<when test="dateType == 1">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}
					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<when test="dateType == 2">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<otherwise>
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</otherwise>
			</choose>
		</if>

	</select>

	<resultMap id="ViewResultMap" type="cn.superdesk.uniorder.dto.vo.accounting.unified.customer.DzMainAutoPage">
		<id column="id" property="id" jdbcType="BIGINT"/>
		<result column="accounting_order_sn" jdbcType="VARCHAR" property="accountingOrderSn" />

		<result column="accounting_status" jdbcType="TINYINT" property="accountingStatus" />



		<result column="invoice_type" jdbcType="TINYINT" property="invoiceType" />
		<result column="invoice_status" jdbcType="TINYINT" property="invoiceStatus" />
		<result column="invoice_company_name" jdbcType="VARCHAR" property="invoiceCompanyName" />
		<result column="invoice_taxpayers_i_d_code" jdbcType="VARCHAR" property="invoiceTaxpayersIDCode" />


		<result column="enterprise_id" property="enterpriseId" jdbcType="BIGINT"/>
		<result column="purchase_user_id" jdbcType="INTEGER" property="purchaseUserId" />
		<result column="purchase_address" jdbcType="VARCHAR" property="purchaseAddress" />


		<result column="is_send_email" jdbcType="TINYINT" property="isSendEmail" />
		<result column="send_email_time" jdbcType="TIMESTAMP" property="sendEmailTime" />



		<result column="date_type" jdbcType="TINYINT" property="dateType" />
		<result column="start_time" jdbcType="TIMESTAMP" property="startTime" />
		<result column="end_time" jdbcType="TIMESTAMP" property="endTime" />




		<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
		<result column="create_user_id" jdbcType="BIGINT" property="createUserId" />
		<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
		<result column="update_user_id" jdbcType="BIGINT" property="updateUserId" />



	</resultMap>

	<select id="findAllView" resultMap="ViewResultMap">
		SELECT
		<include refid="cn.superdesk.uniorder.dao.mapper.accounting.unified.customer.AccountingUnifiedCustomerMapper.Base_Column_List" />
		FROM
			accounting_unified_customer
		<where>
		<if test="dateType != null ">
			and dz_datetype = #{dateType,jdbcType=TINYINT}
		</if>
		<if test="enterpriseName != null and enterpriseName != '' ">
			and enterprise_id in (
			select enterprise_id from sys_enterprise where enterprise_name like
			CONCAT('%',#{enterpriseName,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="starTime != null and starTime != ''">
			and DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}
		</if>
		<if test="endTime != null and endTime != ''">
			and DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
		</if>
		</where>
		order by create_time DESC
	</select>

	<resultMap id="ViewOrderResultMap" type="cn.superdesk.uniorder.dto.vo.accounting.unified.customer.ViewSysOrder">
		<id column="id" property="id" jdbcType="BIGINT"/>
		<result column="my_order_id" property="myOrderId" jdbcType="VARCHAR"/>
		<result column="order_id" property="orderId" jdbcType="BIGINT"/>
		<result column="my_ordersn" property="myOrdersn" jdbcType="VARCHAR"/>
		<result column="ordersn" property="ordersn" jdbcType="VARCHAR"/>
		<result column="parent_order_id" property="parentOrderId" jdbcType="INTEGER"/>
		<result column="parent_ordersn" property="parentOrdersn" jdbcType="VARCHAR"/>
		<result column="detail_url" property="detailUrl" jdbcType="VARCHAR"/>
		<result column="dispatchprice" property="dispatchprice" jdbcType="DECIMAL"/>
		<result column="price" property="price" jdbcType="DECIMAL"/>
		<result column="organization_id" property="organizationId" jdbcType="BIGINT"/>
		<result column="enterprise_id" property="enterpriseId" jdbcType="BIGINT"/>
		<result column="invoice_type" property="invoicetype" jdbcType="TINYINT"/>
		<result column="dispatchname" property="dispatchname" jdbcType="VARCHAR"/>
		<result column="createtime" property="createtime" jdbcType="TIMESTAMP"/>
		<result column="sync_time" property="syncTime" jdbcType="TIMESTAMP"/>
		<result column="paytime" property="paytime" jdbcType="TIMESTAMP"/>
		<result column="realname_id" property="realnameId" jdbcType="INTEGER"/>
		<result column="examine_id" property="examineId" jdbcType="INTEGER"/>
		<result column="address_realname" property="addressRealname" jdbcType="VARCHAR"/>
		<result column="address_mobile" property="addressMobile" jdbcType="VARCHAR"/>
		<result column="address_address" property="addressAddress" jdbcType="VARCHAR"/>
		<result column="companyName" property="companyname" jdbcType="VARCHAR"/>
		<result column="taxpayersIDcode" property="taxpayersidcode" jdbcType="VARCHAR"/>
		<result column="sendtime" property="sendtime" jdbcType="TIMESTAMP"/>
		<result column="finishtime" property="finishtime" jdbcType="TIMESTAMP"/>
		<result column="status" property="status" jdbcType="TINYINT"/>
		<result column="merch_name" property="merchName" jdbcType="VARCHAR"/>
		<result column="order_type" property="orderType" jdbcType="VARCHAR"/>
		<result column="paytype" property="paytype" jdbcType="TINYINT"/>
		<result column="search_field1" property="searchField1" jdbcType="VARCHAR"/>
		<result column="search_field2" property="searchField2" jdbcType="VARCHAR"/>
		<result column="search_field3" property="searchField3" jdbcType="VARCHAR"/>
		<result column="other_field1" property="otherField1" jdbcType="VARCHAR"/>
		<result column="other_field2" property="otherField2" jdbcType="VARCHAR"/>
		<result column="other_field3" property="otherField3" jdbcType="VARCHAR"/>
		<result column="remark" property="remark" jdbcType="VARCHAR"/>
		<result column="invoiceAccount" property="invoiceaccount" jdbcType="VARCHAR"/>
		<result column="is_gen_bill" property="isGenBill" jdbcType="TINYINT"/>
		<result column="invoiceBank" property="invoicebank" jdbcType="VARCHAR"/>
		<!-- <result column="enterprise_name" property="enterpriseName" jdbcType="VARCHAR" />
		<result column="mobile" property="mobile" jdbcType="VARCHAR" />
		<result column="realname" property="realname" jdbcType="VARCHAR" /> -->
	</resultMap>

	<select id="findViewFromOrder" resultMap="ViewOrderResultMap">
		SELECT
		id,
		my_order_id,
		order_id,
		my_ordersn,
		ordersn,
		parent_order_id,
		parent_ordersn,
		detail_url,
		dispatchprice,
		price,
		organization_id,
		enterprise_id,
		invoice_type,
		dispatchname,
		createtime,
		sync_time,
		paytime,
		realname_id,
		examine_id,
		address_realname,
		address_mobile,
		address_address,
		companyName,
		taxpayersIDcode,
		sendtime,
		finishtime,
		`status`,
		merch_name,
		order_type,
		paytype,
		search_field1,
		search_field2,
		search_field3,
		other_field1,
		other_field2,
		other_field3,
		remark,
		invoiceAccount,
		is_gen_bill,
		invoiceBank
		FROM
		sys_order where 1=1 and `status` != -1
		<!-- select b.enterprise_name,c.mobile,c.realname,a.* from sys_order a
		  left join sys_enterprise b on a.enterprise_id=b.enterprise_id
		  left join sys_oder_user c on c.user_id = a.realname_id
		  where 1=1 -->
		<if test="userId != null">
			and order_type in (
			select sourcetype_id from sys_user_order_sourcetype where user_id=#{userId,jdbcType=BIGINT}
			)
		</if>
		<if test="orderStatus != null ">
			and `status` = #{orderStatus,jdbcType=TINYINT}
		</if>

		<if test="isGenBill != null ">
			and is_gen_bill = #{isGenBill,jdbcType=TINYINT}
		</if>
		<if test="orderType != null ">
			and order_type = #{orderType,jdbcType=VARCHAR}
		</if>
		<if test="enterpriseName != null and enterpriseName != '' ">
			and enterprise_id in (
			select enterprise_id from sys_enterprise where enterprise_name like
			CONCAT('%',#{enterpriseName,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="companyName != null and companyName != '' ">
			and companyName like CONCAT('%',#{companyName,jdbcType=VARCHAR},'%')
		</if>
		<if test="merchName != null and merchName != '' ">
			and merch_name like CONCAT('%',#{merchName,jdbcType=VARCHAR},'%')
		</if>
		<if test="realname != null and realname != '' ">
			and realname_id in (
			select user_id from sys_oder_user where realname like CONCAT('%',#{realname,jdbcType=VARCHAR},'%')
			)

		</if>
		<if test="myOrdersn != null and myOrdersn != '' ">
			and my_ordersn like CONCAT('%',#{myOrdersn,jdbcType=VARCHAR},'%')
		</if>
		<if test="price != null and price != '' ">
			and price = #{price,jdbcType=VARCHAR}
		</if>
		<if test="addressRealname != null and addressRealname != '' ">
			and address_realname like CONCAT('%',#{addressRealname,jdbcType=VARCHAR},'%')
		</if>
		<if test="dateType != null ">
			<choose>
				<when test="dateType == 1">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}
					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<when test="dateType == 2">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<otherwise>
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</otherwise>
			</choose>
		</if>
		order by createtime DESC
	</select>

	<resultMap id="ViewOrderGoodsResultMap" type="cn.superdesk.uniorder.dto.vo.accounting.unified.customer.ViewSysOrderGoods">
		<id column="id" property="id" jdbcType="BIGINT"/>
		<result column="my_order_id" property="myOrderId" jdbcType="VARCHAR"/>
		<result column="order_id" property="orderId" jdbcType="BIGINT"/>
		<result column="my_ordersn" property="myOrdersn" jdbcType="VARCHAR"/>
		<result column="ordersn" property="ordersn" jdbcType="VARCHAR"/>
		<result column="parent_order_id" property="parentOrderId" jdbcType="INTEGER"/>
		<result column="parent_ordersn" property="parentOrdersn" jdbcType="VARCHAR"/>
		<result column="detail_url" property="detailUrl" jdbcType="VARCHAR"/>
		<result column="dispatchprice" property="dispatchprice" jdbcType="DECIMAL"/>
		<result column="price" property="price" jdbcType="DECIMAL"/>
		<result column="organization_id" property="organizationId" jdbcType="BIGINT"/>
		<result column="enterprise_id" property="enterpriseId" jdbcType="BIGINT"/>
		<result column="invoice_type" property="invoicetype" jdbcType="TINYINT"/>
		<result column="dispatchname" property="dispatchname" jdbcType="VARCHAR"/>
		<result column="createtime" property="createtime" jdbcType="TIMESTAMP"/>
		<result column="sync_time" property="syncTime" jdbcType="TIMESTAMP"/>
		<result column="paytime" property="paytime" jdbcType="TIMESTAMP"/>
		<result column="realname_id" property="realnameId" jdbcType="INTEGER"/>
		<result column="examine_id" property="examineId" jdbcType="INTEGER"/>
		<result column="address_realname" property="addressRealname" jdbcType="VARCHAR"/>
		<result column="address_mobile" property="addressMobile" jdbcType="VARCHAR"/>
		<result column="address_address" property="addressAddress" jdbcType="VARCHAR"/>
		<result column="companyName" property="companyname" jdbcType="VARCHAR"/>
		<result column="taxpayersIDcode" property="taxpayersidcode" jdbcType="VARCHAR"/>
		<result column="sendtime" property="sendtime" jdbcType="TIMESTAMP"/>
		<result column="finishtime" property="finishtime" jdbcType="TIMESTAMP"/>
		<result column="status" property="status" jdbcType="TINYINT"/>
		<result column="merch_name" property="merchName" jdbcType="VARCHAR"/>
		<result column="order_type" property="orderType" jdbcType="VARCHAR"/>
		<result column="paytype" property="paytype" jdbcType="TINYINT"/>
		<result column="search_field1" property="searchField1" jdbcType="VARCHAR"/>
		<result column="search_field2" property="searchField2" jdbcType="VARCHAR"/>
		<result column="search_field3" property="searchField3" jdbcType="VARCHAR"/>
		<result column="other_field1" property="otherField1" jdbcType="VARCHAR"/>
		<result column="other_field2" property="otherField2" jdbcType="VARCHAR"/>
		<result column="other_field3" property="otherField3" jdbcType="VARCHAR"/>
		<result column="remark" property="remark" jdbcType="VARCHAR"/>
		<result column="invoiceAccount" property="invoiceaccount" jdbcType="VARCHAR"/>
		<result column="is_gen_bill" property="isGenBill" jdbcType="TINYINT"/>
		<result column="invoiceBank" property="invoicebank" jdbcType="VARCHAR"/>
		<!--  <result column="enterprise_name" property="enterpriseName" jdbcType="VARCHAR" />
		 <result column="mobile" property="mobile" jdbcType="VARCHAR" />
		 <result column="realname" property="realname" jdbcType="VARCHAR" /> -->
		<collection property="goods" ofType="cn.superdesk.uniorder.dao.entity.sys.SysGood"
		            javaType="java.util.List" column="my_order_id" select="GetGoodsById">
		</collection>
	</resultMap>

	<select id="findViewFromOrderGoods" resultMap="ViewOrderGoodsResultMap">
		select id,
		my_order_id,
		order_id,
		my_ordersn,
		ordersn,
		parent_order_id,
		parent_ordersn,
		detail_url,
		dispatchprice,
		price,
		organization_id,
		enterprise_id,
		invoice_type,
		dispatchname,
		createtime,
		sync_time,
		paytime,
		realname_id,
		examine_id,
		address_realname,
		address_mobile,
		address_address,
		companyName,
		taxpayersIDcode,
		sendtime,
		finishtime,
		`status`,
		merch_name,
		order_type,
		paytype,
		search_field1,
		search_field2,
		search_field3,
		other_field1,
		other_field2,
		other_field3,
		remark,
		invoiceAccount,
		is_gen_bill,
		invoiceBank from sys_order

		where 1=1 and `status` != -1
		<if test="userId != null ">
			and order_type in (
			select sourcetype_id from sys_user_order_sourcetype where user_id=#{userId,jdbcType=BIGINT}
			)
		</if>
		<if test="isGenBill != null ">
			and is_gen_bill = #{isGenBill,jdbcType=TINYINT}
		</if>
		<if test="orderIds !=null and orderIds != ''">
			and id in
			<foreach collection="orderIds" index="index" item="orderId" open="(" close=")" separator=",">
				#{orderId}
			</foreach>
		</if>
		<if test="dateType != null ">
			<choose>
				<when test="dateType == 1">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>

				</when>
				<when test="dateType == 2">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}
					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<when test="dateType == 3">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<otherwise>
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</otherwise>
			</choose>
		</if>
		<if test="myOrdersn != null and myOrdersn != '' ">
			and my_ordersn like CONCAT('%',#{myOrdersn,jdbcType=VARCHAR},'%')
		</if>
		<if test="ordersn != null and ordersn != '' ">
			and ordersn like CONCAT('%',#{ordersn,jdbcType=VARCHAR},'%')
		</if>
		<if test="parentOrdersn != null and parentOrdersn != '' ">
			and parent_ordersn like CONCAT('%',#{parentOrdersn,jdbcType=VARCHAR},'%')
		</if>
		<if test="enterpriseName != null and enterpriseName != '' ">
			and enterprise_id in (
			select enterprise_id from sys_enterprise where enterprise_name like
			CONCAT('%',#{enterpriseName,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="dispatchname != null and dispatchname != '' ">
			and dispatchname like CONCAT('%',#{dispatchname,jdbcType=VARCHAR},'%')
		</if>
		<if test="realname != null and realname != '' ">
			and realname_id in (
			select user_id from sys_oder_user where realname like CONCAT('%',#{realname,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="mobile != null and mobile != '' ">
			and realname_id in (
			select user_id from sys_oder_user where mobile like CONCAT('%',#{mobile,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="addressRealname != null and addressRealname != '' ">
			and address_realname like CONCAT('%',#{addressRealname,jdbcType=VARCHAR},'%')
		</if>
		<if test="addressMobile != null and addressMobile != '' ">
			and address_mobile like CONCAT('%',#{addressMobile,jdbcType=VARCHAR},'%')
		</if>
		<if test="addressAddress != null and addressAddress != '' ">
			and address_address like CONCAT('%',#{addressAddress,jdbcType=VARCHAR},'%')
		</if>
		<if test="merchName != null and merchName != '' ">
			and merch_name like CONCAT('%',#{merchName,jdbcType=VARCHAR},'%')
		</if>
		<if test="orderType != null ">
			and order_type = #{orderType,jdbcType=VARCHAR}
		</if>
		<if test="paytype != null ">
			and paytype = #{paytype,jdbcType=TINYINT}
		</if>
		order by createtime DESC
	</select>

	<resultMap id="OrderViewGoodsTb" type="cn.superdesk.uniorder.dto.vo.accounting.unified.customer.ViewSysOrderJoinGoods">
		<result column="id" property="id" jdbcType="BIGINT"/>
		<result column="my_order_id" property="myOrderId" jdbcType="VARCHAR"/>
		<result column="order_id" property="orderId" jdbcType="BIGINT"/>
		<result column="my_ordersn" property="myOrdersn" jdbcType="VARCHAR"/>
		<result column="ordersn" property="ordersn" jdbcType="VARCHAR"/>
		<result column="parent_order_id" property="parentOrderId" jdbcType="INTEGER"/>
		<result column="parent_ordersn" property="parentOrdersn" jdbcType="VARCHAR"/>
		<result column="detail_url" property="detailUrl" jdbcType="VARCHAR"/>
		<result column="dispatchprice" property="dispatchprice" jdbcType="DECIMAL"/>
		<result column="organization_id" property="organizationId" jdbcType="BIGINT"/>
		<result column="enterprise_id" property="enterpriseId" jdbcType="BIGINT"/>
		<result column="invoice_type" property="invoicetype" jdbcType="TINYINT"/>
		<result column="dispatchname" property="dispatchname" jdbcType="VARCHAR"/>
		<result column="createtime" property="createtime" jdbcType="TIMESTAMP"/>
		<result column="sync_time" property="syncTime" jdbcType="TIMESTAMP"/>
		<result column="paytime" property="paytime" jdbcType="TIMESTAMP"/>
		<result column="realname_id" property="realnameId" jdbcType="INTEGER"/>
		<result column="examine_id" property="examineId" jdbcType="INTEGER"/>
		<result column="address_realname" property="addressRealname" jdbcType="VARCHAR"/>
		<result column="address_mobile" property="addressMobile" jdbcType="VARCHAR"/>
		<result column="address_address" property="addressAddress" jdbcType="VARCHAR"/>
		<result column="companyName" property="companyname" jdbcType="VARCHAR"/>
		<result column="taxpayersIDcode" property="taxpayersidcode" jdbcType="VARCHAR"/>
		<result column="sendtime" property="sendtime" jdbcType="TIMESTAMP"/>
		<result column="finishtime" property="finishtime" jdbcType="TIMESTAMP"/>
		<result column="status" property="status" jdbcType="TINYINT"/>
		<result column="merch_name" property="merchName" jdbcType="VARCHAR"/>
		<result column="order_type" property="orderType" jdbcType="VARCHAR"/>
		<result column="paytype" property="paytype" jdbcType="TINYINT"/>
		<result column="remark" property="remark" jdbcType="VARCHAR"/>
		<result column="invoiceAccount" property="invoiceaccount" jdbcType="VARCHAR"/>
		<result column="is_gen_bill" property="isGenBill" jdbcType="TINYINT"/>
		<result column="invoiceBank" property="invoicebank" jdbcType="VARCHAR"/>
		<result column="good_id" property="goodId" jdbcType="BIGINT"/>
		<result column="goodno" property="goodno" jdbcType="VARCHAR"/>
		<result column="total" property="total" jdbcType="INTEGER"/>
		<result column="unit_price" property="unitPrice" jdbcType="DECIMAL"/>
		<result column="price" property="price" jdbcType="DECIMAL"/>
		<result column="dispatch_price" property="dispatchPrice" jdbcType="DECIMAL"/>
		<result column="total_price" property="totalPrice" jdbcType="DECIMAL"/>
		<result column="optionname" property="optionname" jdbcType="VARCHAR"/>
		<result column="unit" property="unit" jdbcType="VARCHAR"/>
		<result column="other_field1" property="otherField1" jdbcType="VARCHAR"/>
		<result column="other_field2" property="otherField2" jdbcType="VARCHAR"/>
		<result column="tax_code" property="taxCode" jdbcType="VARCHAR"/>
		<result column="fiscal_code" property="fiscalCode" jdbcType="VARCHAR"/>
		<result column="order_price" property="orderPrice" jdbcType="DECIMAL"/>
		<result column="enterprise_no" property="enterpriseNo" jdbcType="VARCHAR"/>
		<result column="enterprise_name" property="enterpriseName" jdbcType="VARCHAR"/>
		<result column="realname" property="realname" jdbcType="VARCHAR"/>
		<result column="examine_name" property="examineName" jdbcType="VARCHAR"/>
		<result column="real_mobile" property="realMobile" jdbcType="VARCHAR"/>
		<result column="ex_mobile" property="exMobile" jdbcType="VARCHAR"/>
		<result column="real_billemail" property="realBillemail" jdbcType="VARCHAR"/>
		<result column="ex_billemail" property="exBillemail" jdbcType="VARCHAR"/>
	</resultMap>

	<select id="findOrderViewGoodsTb" resultMap="OrderViewGoodsTb">
		SELECT
		`sys_order`.`id` AS `id`,
		`sys_order`.`my_order_id` AS `my_order_id`,
		`sys_order`.`order_id` AS `order_id`,
		`sys_order`.`my_ordersn` AS `my_ordersn`,
		`sys_order`.`ordersn` AS `ordersn`,
		`sys_order`.`parent_order_id` AS `parent_order_id`,
		`sys_order`.`parent_ordersn` AS `parent_ordersn`,
		`sys_order`.`detail_url` AS `detail_url`,
		`sys_order`.`dispatchprice` AS `dispatchprice`,
		`sys_order`.`organization_id` AS `organization_id`,
		`sys_order`.`enterprise_id` AS `enterprise_id`,
		`sys_order`.`invoiceType` AS `invoiceType`,
		`sys_order`.`dispatchname` AS `dispatchname`,
		`sys_order`.`createtime` AS `createtime`,
		`sys_order`.`sync_time` AS `sync_time`,
		`sys_order`.`paytime` AS `paytime`,
		`sys_order`.`realname_id` AS `realname_id`,
		`sys_order`.`examine_id` AS `examine_id`,
		`sys_order`.`address_realname` AS `address_realname`,
		`sys_order`.`address_mobile` AS `address_mobile`,
		`sys_order`.`address_address` AS `address_address`,
		`sys_order`.`companyName` AS `companyName`,
		`sys_order`.`taxpayersIDcode` AS `taxpayersIDcode`,
		`sys_order`.`sendtime` AS `sendtime`,
		`sys_order`.`finishtime` AS `finishtime`,
		`sys_order`.`status` AS `status`,
		`sys_order`.`merch_name` AS `merch_name`,
		`sys_order`.`order_type` AS `order_type`,
		`sys_order`.`paytype` AS `paytype`,
		`sys_order`.`remark` AS `remark`,
		`sys_order`.`invoiceAccount` AS `invoiceAccount`,
		`sys_order`.`is_gen_bill` AS `is_gen_bill`,
		`sys_order`.`invoiceBank` AS `invoiceBank`,
		`sys_good`.`id` AS `good_id`,
		`sys_good`.`goodno` AS `goodno`,
		`sys_good`.`total` AS `total`,
		`sys_good`.`unit_price` AS `unit_price`,
		`sys_good`.`price` AS `price`,
		`sys_good`.`dispatch_price` AS `dispatch_price`,
		`sys_good`.`total_price` AS `total_price`,
		`sys_good`.`optionname` AS `optionname`,
		`sys_good`.`unit` AS `unit`,
		`sys_good`.`other_field1` AS `other_field1`,
		`sys_good`.`other_field2` AS `other_field2`,
		`sys_good`.`tax_code` AS `tax_code`,
		`sys_good`.`fiscal_code` AS `fiscal_code`,
		`sys_order`.`price` AS `order_price`,
		`sys_enterprise`.`enterprise_no` AS `enterprise_no`,
		`sys_enterprise`.`enterprise_name` AS `enterprise_name`,
		`order_user_real`.`realname` AS `realname`,
		`order_user_ex`.`realname` AS `examine_name`,
		`order_user_real`.`mobile` AS `real_mobile`,
		`order_user_ex`.`mobile` AS `ex_mobile`,
		`order_user_real`.`bill_email` AS `real_billemail`,
		`order_user_ex`.`bill_email` AS `ex_billemail`
		FROM
		(
		(
		(
		(
		`sys_good`
		LEFT JOIN `sys_order` ON (
		(
		`sys_good`.`sys_order_id` = `sys_order`.`my_order_id`
		)
		)
		)
		LEFT JOIN `sys_enterprise` ON (
		(
		`sys_order`.`enterprise_id` = `sys_enterprise`.`enterprise_id`
		)
		)
		)
		LEFT JOIN `sys_oder_user` `order_user_real` ON (
		(
		`sys_order`.`realname_id` = `order_user_real`.`user_id`
		)
		)
		)
		LEFT JOIN `sys_oder_user` `order_user_ex` ON (
		(
		`sys_order`.`examine_id` = `order_user_ex`.`user_id`
		)
		)
		)

		where 1=1
		<if test="isGenBill != null ">
			and sys_order.is_gen_bill = #{isGenBill,jdbcType=TINYINT}
		</if>
		<if test="orderIds !=null and orderIds != ''">
			and sys_order.id in
			<foreach collection="orderIds" index="index" item="orderId" open="(" close=")" separator=",">
				#{orderId}
			</foreach>
		</if>
		order by sys_order.my_order_id
	</select>

	<resultMap id="GoodsResultMap" type="cn.superdesk.uniorder.dao.entity.sys.SysGood">
		<id column="id" property="id" jdbcType="BIGINT"/>
		<result column="sys_order_id" property="sysOrderId" jdbcType="VARCHAR"/>
		<result column="goodno" property="goodno" jdbcType="VARCHAR"/>
		<result column="total" property="total" jdbcType="INTEGER"/>
		<result column="unit_price" property="unitPrice" jdbcType="DECIMAL"/>
		<result column="price" property="price" jdbcType="DECIMAL"/>
		<result column="dispatch_price" property="dispatchPrice" jdbcType="DECIMAL"/>
		<result column="total_price" property="totalPrice" jdbcType="DECIMAL"/>
		<result column="optionname" property="optionname" jdbcType="VARCHAR"/>
		<result column="unit" property="unit" jdbcType="VARCHAR"/>
		<result column="other_field1" property="otherField1" jdbcType="VARCHAR"/>
		<result column="other_field2" property="otherField2" jdbcType="VARCHAR"/>
		<result column="tax_code" property="taxCode" jdbcType="VARCHAR"/>
		<result column="fiscal_code" property="fiscalCode" jdbcType="VARCHAR"/>
	</resultMap>

	<select id="GetGoodsById" resultMap="GoodsResultMap">
		select
		<include refid="Goods_Column_List"/>
		from sys_good
		where sys_order_id = #{_parameter,jdbcType=VARCHAR}
	</select>

	<sql id="Goods_Column_List">
    id, sys_order_id, goodno, total, unit_price, price, dispatch_price, total_price, 
    optionname, unit, other_field1, other_field2, tax_code, fiscal_code
  </sql>

	<resultMap id="ReportOrderResultMap" type="cn.superdesk.uniorder.dto.vo.accounting.unified.customer.ReportOrderQA">
		<result column="amount" property="amount" jdbcType="DECIMAL"/>
		<result column="quantity" property="quantity" jdbcType="INTEGER"/>
	</resultMap>

	<select id="findReportFromOrder" resultMap="ReportOrderResultMap">
		select count(*) quantity,IFNULL(sum(price),0) amount from sys_order
		where 1=1 and `status` != -1
		<if test="userId != null">
			and order_type in (
			select sourcetype_id from sys_user_order_sourcetype where user_id=#{userId,jdbcType=BIGINT}
			)
		</if>
		<if test="orderStatus != null ">
			and `status` = #{orderStatus,jdbcType=TINYINT}
		</if>
		<if test="isGenBill != null ">
			and is_gen_bill = #{isGenBill,jdbcType=TINYINT}
		</if>
		<if test="orderType != null ">
			and order_type = #{orderType,jdbcType=VARCHAR}
		</if>
		<if test="enterpriseName != null and enterpriseName != '' ">
			and enterprise_id in (
			select enterprise_id from sys_enterprise where enterprise_name like
			CONCAT('%',#{enterpriseName,jdbcType=VARCHAR},'%')
			)

		</if>
		<if test="companyName != null and companyName != '' ">
			and companyName like CONCAT('%',#{companyName,jdbcType=VARCHAR},'%')
		</if>
		<if test="merchName != null and merchName != '' ">
			and merch_name like CONCAT('%',#{merchName,jdbcType=VARCHAR},'%')
		</if>
		<if test="realname != null and realname != '' ">
			and realname_id in (
			select user_id from sys_oder_user where realname like CONCAT('%',#{realname,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="myOrdersn != null and myOrdersn != '' ">
			and my_ordersn like CONCAT('%',#{myOrdersn,jdbcType=VARCHAR},'%')
		</if>
		<if test="price != null and price != '' ">
			and price = #{price,jdbcType=VARCHAR}
		</if>
		<if test="addressRealname != null and addressRealname != '' ">
			and address_realname like CONCAT('%',#{addressRealname,jdbcType=VARCHAR},'%')
		</if>
		<if test="dateType != null ">
			<choose>
				<when test="dateType == 1">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}
					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<when test="dateType == 2">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<otherwise>
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</otherwise>
			</choose>
		</if>
	</select>

	<resultMap id="NewViewDzOrderResultMap" type="cn.superdesk.uniorder.dto.vo.unified.ViewDzOrder">
		<result column="order_sn" property="orderSn" jdbcType="VARCHAR"/>
		<result column="order_sn_out_trade" property="orderSnOutTrade" jdbcType="VARCHAR"/>
		<result column="service_name" property="serviceName" jdbcType="VARCHAR"/>
		<result column="service_no" property="serviceNo" jdbcType="VARCHAR"/>
		<result column="project_id" property="projectId" jdbcType="BIGINT"/>
		<result column="project_name" property="projectName" jdbcType="VARCHAR"/>
		<result column="purchase_virt_id" property="purchaseVirtId" jdbcType="BIGINT"/>
		<result column="purchase_virt_name" property="purchaseVirtName" jdbcType="VARCHAR"/>
		<result column="purchase_user_id" property="purchaseUserId" jdbcType="BIGINT"/>
		<result column="purchase_user_name" property="purchaseUserName" jdbcType="VARCHAR"/>
		<result column="purchase_phone" property="purchasePhone" jdbcType="VARCHAR"/>
		<result column="sale_id" property="saleId" jdbcType="BIGINT"/>
		<result column="sale_name" property="saleName" jdbcType="VARCHAR"/>
		<result column="amount" property="amount" jdbcType="DECIMAL"/>
		<result column="cost_amount" property="costAmount" jdbcType="DECIMAL"/>
		<result column="transport_amount" property="transportAmount" jdbcType="DECIMAL"/>
		<result column="complet_state" property="completState" jdbcType="TINYINT"/>

		<!-- 客户对账:1-已对账;2-未对账 -->
		<result column="accounting_state_customer" property="accountingStateCustomer" jdbcType="TINYINT"/>
		<!-- 供应商对账:1-已对账;2-未对账 -->
		<result column="accounting_state_supplier" property="accountingStateSupplier" jdbcType="TINYINT"/>


		<result column="pay_type" property="payType" jdbcType="TINYINT"/>
		<result column="pay_state" property="payState" jdbcType="TINYINT"/>
		<result column="order_state" property="orderState" jdbcType="TINYINT"/>
		<result column="order_state_name" property="orderStateName" jdbcType="VARCHAR"/>
		<result column="settlement_type" property="settlementType" jdbcType="TINYINT"/>
		<result column="appraise_state" property="appraiseState" jdbcType="TINYINT"/>
		<result column="source_channel" property="sourceChannel" jdbcType="TINYINT"/>
		<result column="other_params" property="otherParams" jdbcType="VARCHAR"/>
		<result column="user_type" property="userType" jdbcType="VARCHAR"/>
		<result column="user_name" property="userName" jdbcType="VARCHAR"/>
		<result column="inv_state" property="invState" jdbcType="TINYINT"/>
		<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
		<result column="create_user_id" property="createUserId" jdbcType="BIGINT"/>
		<result column="rec_username" property="recUsername" jdbcType="VARCHAR"/>
		<result column="rec_userid" property="recUserid" jdbcType="BIGINT"/>
		<result column="rec_userphone" property="recUserphone" jdbcType="VARCHAR"/>
		<result column="rec_address" property="recAddress" jdbcType="VARCHAR"/>
		<result column="remarks" property="remarks" jdbcType="VARCHAR"/>
		<result column="inv_number" property="invNumber" jdbcType="VARCHAR"/>
		<result column="inv_sn" property="invSn" jdbcType="VARCHAR"/>
		<result column="dz_id" property="dzId" jdbcType="BIGINT"/>
		<result column="order_id" property="orderId" jdbcType="BIGINT"/>
		<result column="id" property="id" jdbcType="BIGINT"/>
		<result column="goods_name" property="goodsName" jdbcType="VARCHAR"/>
		<result column="quantity" property="quantity" jdbcType="INTEGER"/>
		<result column="price" property="price" jdbcType="DECIMAL"/>
		<result column="goods_params" property="goodsParams" jdbcType="VARCHAR"/>
	</resultMap>

	<select id="findAllDzOrderNew" resultMap="NewViewDzOrderResultMap">
		SELECT
			b.order_sn AS order_sn,
			b.order_sn_out_trade AS order_sn_out_trade,
			b.service_name AS serviceName,
			b.service_no AS service_no,
			b.project_id AS project_id,
			b.project_name AS project_name,
			b.purchase_virt_id AS purchase_virt_id,
			b.purchase_virt_name AS purchase_virt_name,
			b.purchase_user_id AS purchase_user_id,
			b.purchase_user_name AS purchase_user_name,
			b.purchase_phone AS purchase_phone,
			b.sale_id AS sale_id,
			b.sale_name AS sale_name,
			b.amount AS amount,
			b.cost_amount AS cost_amount,
			b.transport_amount AS transport_amount,
			b.complet_state AS complet_state,
			b.accounting_state_supplier AS accounting_state_supplier,
			b.accounting_state_customer AS accounting_state_customer,
			b.pay_type AS pay_type,
			b.pay_state AS pay_state,
			b.order_state AS order_state,
			b.order_state_name AS order_state_name,
			b.settlement_type AS settlement_type,
			b.appraise_state AS appraise_state,
			b.source_channel AS source_channel,
			b.other_params AS other_params,
			b.user_type AS user_type,
			b.user_name AS user_name,
			b.inv_state AS inv_state,
			b.create_time AS create_time,
			b.create_user_id AS create_user_id,
			b.rec_username AS rec_username,
			b.rec_userid AS rec_userid,
			b.rec_userphone AS rec_userphone,
			b.rec_address AS rec_address,
			b.remarks AS remarks,
			b.inv_number AS inv_number,
			b.inv_sn AS inv_sn,
			a.dz_id AS dz_id,
			a.order_id AS order_id,
			a.id AS id,
			c.goods_name AS goods_name,
			c.quantity AS quantity,
			c.price AS price,
			c.goods_params AS goods_params
		FROM
		(
		(
		accounting_unified_customer_order a
		LEFT JOIN unified_order b ON ((a.order_sn = b.order_sn))
		)
		LEFT JOIN unified_order_goods c ON ((b.order_sn = c.order_sn))
		) where 1=1
		<if test="dzId != null and dzId !=''">
			and a.dz_id = #{dzId}
		</if>
	</select>

	<resultMap id="ViewDzOrderResultMap" type="cn.superdesk.uniorder.dto.vo.accounting.unified.customer.ViewDzOrder">
		<result column="id" property="id" jdbcType="BIGINT"/>
		<result column="dz_id" property="dzId" jdbcType="BIGINT"/>
		<result column="order_id" property="orderId" jdbcType="BIGINT"/>
		<result column="order_sn" property="orderSn" jdbcType="VARCHAR"/>
		<result column="parent_order_id" property="parentOrderId" jdbcType="INTEGER"/>
		<result column="parent_ordersn" property="parentOrdersn" jdbcType="VARCHAR"/>
		<result column="createtime" property="createtime" jdbcType="TIMESTAMP"/>
		<result column="address_realname" property="addressRealname" jdbcType="VARCHAR"/>
		<result column="address_mobile" property="addressMobile" jdbcType="VARCHAR"/>
		<result column="address_address" property="addressAddress" jdbcType="VARCHAR"/>
		<result column="companyName" property="companyname" jdbcType="VARCHAR"/>
		<result column="taxpayersIDcode" property="taxpayersidcode" jdbcType="VARCHAR"/>
		<result column="sendtime" property="sendtime" jdbcType="TIMESTAMP"/>
		<result column="finishtime" property="finishtime" jdbcType="TIMESTAMP"/>
		<result column="status" property="status" jdbcType="TINYINT"/>
		<result column="merch_name" property="merchName" jdbcType="VARCHAR"/>
		<result column="order_type" property="orderType" jdbcType="VARCHAR"/>
		<result column="paytype" property="paytype" jdbcType="TINYINT"/>
		<result column="search_field1" property="searchField1" jdbcType="VARCHAR"/>
		<result column="search_field2" property="searchField2" jdbcType="VARCHAR"/>
		<result column="search_field3" property="searchField3" jdbcType="VARCHAR"/>
		<result column="remark" property="remark" jdbcType="VARCHAR"/>
		<result column="invoiceAccount" property="invoiceaccount" jdbcType="VARCHAR"/>
		<result column="invoiceBank" property="invoicebank" jdbcType="VARCHAR"/>
		<result column="examine_id" property="examineId" jdbcType="INTEGER"/>
		<result column="realname_id" property="realnameId" jdbcType="INTEGER"/>
		<result column="detail_url" property="detailUrl" jdbcType="VARCHAR"/>
		<result column="organization_id" property="organizationId" jdbcType="BIGINT"/>
		<result column="enterprise_id" property="enterpriseId" jdbcType="BIGINT"/>
		<result column="invoiceType" property="invoicetype" jdbcType="TINYINT"/>
		<result column="dispatchname" property="dispatchname" jdbcType="VARCHAR"/>
		<result column="sync_time" property="syncTime" jdbcType="TIMESTAMP"/>
		<result column="paytime" property="paytime" jdbcType="TIMESTAMP"/>
		<result column="dz_order_good_id" property="dzOrderGoodId" jdbcType="BIGINT"/>
		<result column="dz_order_id" property="dzOrderId" jdbcType="BIGINT"/>
		<result column="good_id" property="goodId" jdbcType="BIGINT"/>
		<result column="goodno" property="goodno" jdbcType="VARCHAR"/>
		<result column="price" property="price" jdbcType="DECIMAL"/>
		<result column="total" property="total" jdbcType="INTEGER"/>
		<result column="unit_price" property="unitPrice" jdbcType="DECIMAL"/>
		<result column="optionname" property="optionname" jdbcType="VARCHAR"/>
		<result column="unit" property="unit" jdbcType="VARCHAR"/>
		<result column="other_field1" property="otherField1" jdbcType="VARCHAR"/>
		<result column="other_field2" property="otherField2" jdbcType="VARCHAR"/>
		<result column="dispatch_price" property="dispatchPrice" jdbcType="DECIMAL"/>
		<result column="total_price" property="totalPrice" jdbcType="DECIMAL"/>
		<result column="tax_code" property="taxCode" jdbcType="VARCHAR"/>
		<result column="fiscal_code" property="fiscalCode" jdbcType="VARCHAR"/>
		<result column="realname" property="realname" jdbcType="VARCHAR"/>
		<result column="examine_name" property="examineName" jdbcType="VARCHAR"/>
		<result column="invoice_number" property="invoiceNumber" jdbcType="VARCHAR"/>
		<result column="invoice_no" property="invoiceNo" jdbcType="VARCHAR"/>
		<result column="order_price" property="orderPrice" jdbcType="DECIMAL"/>
		<result column="status_name" property="statusName" jdbcType="VARCHAR"/>
		<result column="paytype_name" property="paytypeName" jdbcType="VARCHAR"/>
		<result column="invoiceType_name" property="invoiceTypeName" jdbcType="VARCHAR"/>
	</resultMap>

	<select id="findAllDzOrderView" resultMap="ViewDzOrderResultMap">
		SELECT
		accounting_unified_customer_order.id AS id,
		accounting_unified_customer_order.dz_id AS dz_id,
		accounting_unified_customer_order.order_id AS order_id,
		accounting_unified_customer_order.order_sn AS order_sn,
		accounting_unified_customer_order.parent_order_id AS parent_order_id,
		accounting_unified_customer_order.parent_ordersn AS parent_ordersn,
		accounting_unified_customer_order.createtime AS createtime,
		accounting_unified_customer_order.address_realname AS address_realname,
		accounting_unified_customer_order.address_mobile AS address_mobile,
		accounting_unified_customer_order.address_address AS address_address,
		accounting_unified_customer_order.companyName AS companyName,
		accounting_unified_customer_order.taxpayersIDcode AS taxpayersIDcode,
		accounting_unified_customer_order.sendtime AS sendtime,
		accounting_unified_customer_order.finishtime AS finishtime,
		accounting_unified_customer_order.status AS status,
		CASE
		WHEN accounting_unified_customer_order.status = - 1 THEN
		'已关闭'
		WHEN accounting_unified_customer_order.status = 0 THEN
		'待付款'
		WHEN accounting_unified_customer_order.status = 1 THEN
		'待发货'
		WHEN accounting_unified_customer_order.status = 2 THEN
		'待收货'
		WHEN accounting_unified_customer_order.status = 3 THEN
		'已完成'
		ELSE
		'已关闭'
		END AS status_name,
		accounting_unified_customer_order.merch_name AS merch_name,
		accounting_unified_customer_order.order_type AS order_type,
		accounting_unified_customer_order.paytype AS paytype,
		CASE
		WHEN accounting_unified_customer_order.paytype = 0 THEN
		'未支付'
		WHEN accounting_unified_customer_order.paytype = 1 THEN
		'余额支付'
		WHEN accounting_unified_customer_order.paytype = 2 THEN
		'在线支付'
		WHEN accounting_unified_customer_order.paytype = 3 THEN
		'企业月结'
		WHEN accounting_unified_customer_order.paytype = 11 THEN
		'后台付款'
		WHEN accounting_unified_customer_order.paytype = 21 THEN
		'微信支付'
		WHEN accounting_unified_customer_order.paytype = 22 THEN
		'支付宝支付'
		WHEN accounting_unified_customer_order.paytype = 23 THEN
		'银联支付'
		ELSE
		'未支付'
		END AS paytype_name,
		accounting_unified_customer_order.search_field1 AS search_field1,
		accounting_unified_customer_order.search_field2 AS search_field2,
		accounting_unified_customer_order.search_field3 AS search_field3,
		accounting_unified_customer_order.remark AS remark,
		accounting_unified_customer_order.invoiceAccount AS invoiceAccount,
		accounting_unified_customer_order.invoiceBank AS invoiceBank,
		accounting_unified_customer_order.examine_id AS examine_id,
		accounting_unified_customer_order.realname_id AS realname_id,
		accounting_unified_customer_order.detail_url AS detail_url,
		accounting_unified_customer_order.organization_id AS organization_id,
		accounting_unified_customer_order.enterprise_id AS enterprise_id,
		accounting_unified_customer_order.invoiceType AS invoiceType,
		CASE
		WHEN accounting_unified_customer_order.invoiceType = 1 THEN
		'增值税普票'
		ELSE
		'增值税专票'
		END AS invoiceType_name,
		accounting_unified_customer_order.dispatchname AS dispatchname,
		accounting_unified_customer_order.sync_time AS sync_time,
		accounting_unified_customer_order.paytime AS paytime,
		accounting_unified_customer_order_goods.id AS dz_order_good_id,
		accounting_unified_customer_order_goods.dz_order_id AS dz_order_id,
		accounting_unified_customer_order_goods.good_id AS good_id,
		accounting_unified_customer_order_goods.goodno AS goodno,
		accounting_unified_customer_order_goods.price AS price,
		accounting_unified_customer_order_goods.total AS total,
		accounting_unified_customer_order_goods.unit_price AS unit_price,
		accounting_unified_customer_order_goods.optionname AS optionname,
		accounting_unified_customer_order_goods.unit AS unit,
		accounting_unified_customer_order_goods.other_field1 AS other_field1,
		accounting_unified_customer_order_goods.other_field2 AS other_field2,
		accounting_unified_customer_order_goods.dispatch_price AS dispatch_price,
		accounting_unified_customer_order_goods.total_price AS total_price,
		accounting_unified_customer_order_goods.tax_code AS tax_code,
		accounting_unified_customer_order_goods.fiscal_code AS fiscal_code,
		real_order_user.realname AS realname,
		examine_order_user.realname AS examine_name,
		(
		SELECT
		t2.invoice_number
		FROM
		invoice_order t1
		LEFT JOIN invoice_apply t2 ON t1.invoice_apply_id = t2.id
		WHERE
		t1.dz_good_id = accounting_unified_customer_order_goods.id
		AND t2.audit_status IN (1, 2) GROUP BY t1.dz_good_id
		) AS invoice_number,
		(
		SELECT
		t2.invoice_no
		FROM
		invoice_order t1
		LEFT JOIN invoice_apply t2 ON t1.invoice_apply_id = t2.id
		WHERE
		t1.dz_good_id = accounting_unified_customer_order_goods.id
		AND t2.audit_status IN (1, 2) GROUP BY t1.dz_good_id
		) AS invoice_no,
		accounting_unified_customer_order.price AS order_price
		FROM
		(
		accounting_unified_customer_order
		RIGHT JOIN accounting_unified_customer_order_goods ON (
		(
		accounting_unified_customer_order.id = accounting_unified_customer_order_goods.dz_order_id`
		)
		)
		)
		LEFT JOIN sys_oder_user AS real_order_user ON accounting_unified_customer_order.realname_id = real_order_user.user_id
		LEFT JOIN sys_oder_user AS examine_order_user ON accounting_unified_customer_order.examine_id = examine_order_user.user_id
		LEFT JOIN sys_invoice ON accounting_unified_customer_order.id = sys_invoice.dz_order_id
		WHERE 1 = 1
		<if test="dzId != null ">
			and accounting_unified_customer_order.dz_id = #{dzId,jdbcType=BIGINT}
		</if>
		<if test="dzIds !=null and dzIds != ''">
			and accounting_unified_customer_order.dz_id in
			<foreach collection="dzIds" index="index" item="mainid" open="(" close=")" separator=",">
				#{mainid}
			</foreach>
		</if>
		order by id
	</select>

	<resultMap id="ViewDzMainResultMap" type="cn.superdesk.uniorder.dto.vo.accounting.unified.customer.ViewDzMain">
		<result column="order_type" property="orderType" jdbcType="VARCHAR"/>
		<result column="dz_money" property="dzMoney" jdbcType="DECIMAL"/>
		<result column="order_quantity" property="dzQuantity" jdbcType="INTEGER"/>
		<result column="purchase_user_name" property="realname" jdbcType="VARCHAR"/>
		<result column="purchase_phone" property="mobile" jdbcType="VARCHAR"/>

		<result column="id" property="id" jdbcType="BIGINT"/>
		<result column="dz_datetype" property="dzDatetype" jdbcType="TINYINT"/>
		<result column="dz_sn" property="dzSn" jdbcType="VARCHAR"/>
		<result column="dz_status" property="dzStatus" jdbcType="TINYINT"/>
		<result column="dz_invstatus" property="dzInvstatus" jdbcType="TINYINT"/>
		<result column="enterprise_id" property="enterpriseId" jdbcType="BIGINT"/>
		<result column="realname_id" property="realnameId" jdbcType="INTEGER"/>
		<result column="companyName" property="companyname" jdbcType="VARCHAR"/>
		<result column="taxpayersIDcode" property="taxpayersidcode" jdbcType="VARCHAR"/>
		<result column="invoice_type" property="invoicetype" jdbcType="TINYINT"/>
		<result column="address" property="address" jdbcType="VARCHAR"/>
		<result column="is_email" property="isEmail" jdbcType="TINYINT"/>
		<result column="email_time" property="emailTime" jdbcType="TIMESTAMP"/>
		<result column="star_time" property="starTime" jdbcType="TIMESTAMP"/>
		<result column="end_time" property="endTime" jdbcType="TIMESTAMP"/>
		<result column="back_account_status" property="backAccountStatus" jdbcType="TINYINT"/>
		<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
		<result column="create_user_id" property="createUserId" jdbcType="BIGINT"/>
		<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
		<result column="update_user_id" property="updateUserId" jdbcType="BIGINT"/>
		<!--
		<result column="enterprise_name" property="enterpriseName" jdbcType="VARCHAR" />
		<result column="enterprise_no" property="enterpriseNo" jdbcType="VARCHAR" />
		<result column="mobile" property="mobile" jdbcType="VARCHAR" />
		<result column="bill_email" property="billEmail" jdbcType="VARCHAR" />
		<result column="realname" property="realname" jdbcType="VARCHAR" />
		-->
		<result column="pay_type" property="payType" jdbcType="TINYINT"/>
		<result column="pay_status" property="payStatus" jdbcType="TINYINT"/>
		<result column="wx_qrcode_imgurl" property="wxQrcodeImgurl" jdbcType="VARCHAR"/>
		<result column="bank_info_id" property="bankInfoId" jdbcType="BIGINT"/>
	</resultMap>

	<select id="getDzMainView" resultMap="ViewDzMainResultMap">
		SELECT
			order_quantity,
			dz_money,
			order_type,
			purchase_user_name,
			purchase_phone,
			id,
			dz_datetype,
			dz_sn,
			dz_status,
			dz_invstatus,
			enterprise_id,
			realname_id,
			companyName,
			taxpayersIDcode,
			invoice_type,
			address,
			is_email,
			email_time,
			star_time,
			end_time,
			back_account_status,
			create_time,
			create_user_id,
			update_time,
			update_user_id,
			pay_type,
			pay_status,
			wx_qrcode_imgurl,
			bank_info_id
		FROM
			accounting_unified_customer
		<where>
		<!--
		<if test="userId != null ">
			and id in (
				select dz_id from accounting_unified_customer_order where order_type in (
					select sourcetype_id from sys_user_order_sourcetype where user_id=#{userId,jdbcType=BIGINT}
				)
			)
		</if>
		-->
		<if test="serviceNo != null and serviceNo != ''">
			and order_type = #{serviceNo}
		</if>
		<if test="syear != null">
			and YEAR(create_time) =#{syear}
		</if>
		<if test="smonth != null">
			and MONTH(create_time) =#{smonth}
		</if>
		<if test="id != null ">
			and id = #{id,jdbcType=BIGINT}
		</if>
		<if test="outVirtIds != null and outVirtIds != ''">
			and enterprise_id in (
			SELECT enterprise_id from sys_enterprise where organization_id in
			<foreach collection="outVirtIds" index="index" item="pid" open="(" close=")" separator=",">
				#{pid}
			</foreach>
			)
		</if>
		<if test="outServices != null and outServices != ''">
			and order_type in
			<foreach collection="outServices" index="index" item="serviceno" open="(" close=")" separator=",">
				#{serviceno}
			</foreach>
		</if>
		<if test="virtId != null and virtId != '' ">
			and enterprise_id = #{virtId}
		</if>
		<if test="virtName != null and virtName != '' ">
			and enterprise_id in (
			SELECT enterprise_id from sys_enterprise where enterprise_name like CONCAT('%',#{virtName},'%')
			)
		</if>
		<if test="companyName != null and companyName != '' ">
			and companyName like CONCAT('%',#{companyName,jdbcType=VARCHAR},'%')
		</if>

		<if test="realname != null and realname != '' ">
			and purchase_user_name like CONCAT('%',#{realname,jdbcType=VARCHAR},'%')
		</if>
		<if test="userphone != null and userphone != '' ">
			and purchase_phone like CONCAT('%',#{userphone,jdbcType=VARCHAR},'%')
		</if>
		<if test="dzSn != null and dzSn != '' ">
			and dz_sn like CONCAT('%',#{dzSn,jdbcType=VARCHAR},'%')
		</if>


		<!-- 对账单状态，0-未确认，1-已确认，-1-已取消,2-已拒绝  3待提交 -->
		<choose>
			<when test="dzStatus != null ">
				and dz_status = #{dzStatus}
			</when>
			<otherwise>
				and dz_status not in (-1,2)
			</otherwise>
		</choose>

		<if test="dzStatusWx != null ">
			and dz_status not in (-1,2)
		</if>
		<if test="isEmail != null ">
			and is_email = #{isEmail,jdbcType=TINYINT}
		</if>
		<if test="dzInvstatus != null ">
			and dz_invstatus = #{dzInvstatus,jdbcType=TINYINT}
		</if>
		<if test="dateType != null ">
			<choose>
				<when test="dateType == 1">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(create_time,'%Y-%m-%d') &gt;= #{starTime,jdbcType=VARCHAR}
					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(create_time,'%Y-%m-%d') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<otherwise>
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(email_time,'%Y-%m-%d') &gt;= #{starTime,jdbcType=VARCHAR}
					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(email_time,'%Y-%m-%d') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</otherwise>
			</choose>
		</if>
		</where>
		order by create_time DESC
	</select>

	<!-- TODO 错错错 -->
	<select id="getOrderReportData" resultMap="ReportOrderResultMap">
		select
			count(id) quantity,IFNULL(sum(price),0) as amount
		from sys_order
		<where>
			1=1
			and `status` != -1

		<if test="userId != null ">
			and order_type in (
			select sourcetype_id from sys_user_order_sourcetype where user_id=#{userId,jdbcType=BIGINT}
			)
		</if>
		<if test="isGenBill != null ">
			and is_gen_bill = #{isGenBill,jdbcType=TINYINT}
		</if>
		<if test="orderIds !=null and orderIds != ''">
			and id in
			<foreach collection="orderIds" index="index" item="orderId" open="(" close=")" separator=",">
				#{orderId}
			</foreach>
		</if>
		<if test="dateType != null ">
			<choose>
				<when test="dateType == 1">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<when test="dateType == 2">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}
					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<when test="dateType == 3">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<otherwise>
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</otherwise>
			</choose>
		</if>
		<if test="myOrdersn != null and myOrdersn != '' ">
			and my_ordersn like CONCAT('%',#{myOrdersn,jdbcType=VARCHAR},'%')
		</if>
		<if test="ordersn != null and ordersn != '' ">
			and ordersn like CONCAT('%',#{ordersn,jdbcType=VARCHAR},'%')
		</if>
		<if test="parentOrdersn != null and parentOrdersn != '' ">
			and parent_ordersn like CONCAT('%',#{parentOrdersn,jdbcType=VARCHAR},'%')
		</if>
		<if test="enterpriseName != null and enterpriseName != '' ">
			and enterprise_id in (
			select enterprise_id from sys_enterprise where enterprise_name like
			CONCAT('%',#{enterpriseName,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="dispatchname != null and dispatchname != '' ">
			and dispatchname like CONCAT('%',#{dispatchname,jdbcType=VARCHAR},'%')
		</if>
		<if test="realname != null and realname != '' ">
			and realname_id in (
			select user_id from sys_oder_user where realname like CONCAT('%',#{realname,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="mobile != null and mobile != '' ">
			and realname_id in (
			select user_id from sys_oder_user where mobile like CONCAT('%',#{mobile,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="addressRealname != null and addressRealname != '' ">
			and address_realname like CONCAT('%',#{addressRealname,jdbcType=VARCHAR},'%')
		</if>
		<if test="addressMobile != null and addressMobile != '' ">
			and address_mobile like CONCAT('%',#{addressMobile,jdbcType=VARCHAR},'%')
		</if>
		<if test="addressAddress != null and addressAddress != '' ">
			and address_address like CONCAT('%',#{addressAddress,jdbcType=VARCHAR},'%')
		</if>
		<if test="merchName != null and merchName != '' ">
			and merch_name like CONCAT('%',#{merchName,jdbcType=VARCHAR},'%')
		</if>
		<if test="orderType != null ">
			and order_type = #{orderType,jdbcType=VARCHAR}
		</if>
		<if test="paytype != null ">
			and paytype = #{paytype,jdbcType=TINYINT}
		</if>
		</where>
	</select>

	<!-- TODO 写死了 戴德梁行-->
	<select id="getOrderReportDataDeath" resultMap="ReportOrderResultMap">
		select
			count(id) quantity,
			IFNULL(sum(price),0) as amount
		from
			sys_order
		where
			1=1
			and `status` != -1
			and enterprise_id in (SELECT id from temp_daide)
		<if test="userId != null ">
			and order_type in (select sourcetype_id from sys_user_order_sourcetype where user_id=#{userId,jdbcType=BIGINT})
		</if>
		<if test="isGenBill != null ">
			and is_gen_bill = #{isGenBill,jdbcType=TINYINT}
		</if>
		<if test="orderIds !=null and orderIds != ''">
			and id in
			<foreach collection="orderIds" index="index" item="orderId" open="(" close=")" separator=",">
				#{orderId}
			</foreach>
		</if>
		<if test="dateType != null ">
			<choose>
				<when test="dateType == 1">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>

				</when>
				<when test="dateType == 2">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}
					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<when test="dateType == 3">
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</when>
				<otherwise>
					<if test="starTime != null and starTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</otherwise>
			</choose>
		</if>
		<if test="myOrdersn != null and myOrdersn != '' ">
			and my_ordersn like CONCAT('%',#{myOrdersn,jdbcType=VARCHAR},'%')
		</if>
		<if test="ordersn != null and ordersn != '' ">
			and ordersn like CONCAT('%',#{ordersn,jdbcType=VARCHAR},'%')
		</if>
		<if test="parentOrdersn != null and parentOrdersn != '' ">
			and parent_ordersn like CONCAT('%',#{parentOrdersn,jdbcType=VARCHAR},'%')
		</if>

		<if test="enterpriseId != null and enterpriseId != '' ">
			and enterprise_id = #{enterpriseId}
		</if>
		<if test="enterpriseName != null and enterpriseName != '' ">
			and enterprise_id in (
			select enterprise_id from sys_enterprise where enterprise_name like
			CONCAT('%',#{enterpriseName,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="dispatchname != null and dispatchname != '' ">
			and dispatchname like CONCAT('%',#{dispatchname,jdbcType=VARCHAR},'%')
		</if>
		<if test="realname != null and realname != '' ">
			and realname_id in (
			select user_id from sys_oder_user where realname like CONCAT('%',#{realname,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="mobile != null and mobile != '' ">
			and realname_id in (
			select user_id from sys_oder_user where mobile like CONCAT('%',#{mobile,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="addressRealname != null and addressRealname != '' ">
			and address_realname like CONCAT('%',#{addressRealname,jdbcType=VARCHAR},'%')
		</if>
		<if test="addressMobile != null and addressMobile != '' ">
			and address_mobile like CONCAT('%',#{addressMobile,jdbcType=VARCHAR},'%')
		</if>
		<if test="addressAddress != null and addressAddress != '' ">
			and address_address like CONCAT('%',#{addressAddress,jdbcType=VARCHAR},'%')
		</if>
		<if test="merchName != null and merchName != '' ">
			and merch_name like CONCAT('%',#{merchName,jdbcType=VARCHAR},'%')
		</if>
		<if test="orderType != null ">
			and order_type = #{orderType,jdbcType=VARCHAR}
		</if>
		<if test="payType != null ">
			and pay_type = #{payType,jdbcType=TINYINT}
		</if>
	</select>

	<!-- TODO 错错错 -->
	<select id="getOrderReturnAmountDeath" resultMap="ReportOrderResultMap">
		select
			count(id) quantity,
			IFNULL(sum(amount),0) as amount
		from
			unified_order_return
		where
			1=1
			and complet_state=1
			and sn in ( select my_ordersn
						from sys_order
						where
							1=1
							and `status` != -1
							and enterprise_id in (SELECT id from temp_daide)
						<if test="userId != null ">
							and order_type in (
							select sourcetype_id from sys_user_order_sourcetype where user_id=#{userId,jdbcType=BIGINT}
							)
						</if>
						<if test="isGenBill != null ">
							and is_gen_bill = #{isGenBill,jdbcType=TINYINT}
						</if>
						<if test="orderIds !=null and orderIds != ''">
							and id in
							<foreach collection="orderIds" index="index" item="orderId" open="(" close=")" separator=",">
								#{orderId}
							</foreach>
						</if>
						<if test="dateType != null ">
							<choose>
								<when test="dateType == 1">
									<if test="starTime != null and starTime != ''">
										and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}
									</if>
									<if test="endTime != null and endTime != ''">
										and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
									</if>
								</when>
								<when test="dateType == 2">
									<if test="starTime != null and starTime != ''">
										and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}
									</if>
									<if test="endTime != null and endTime != ''">
										and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
									</if>
								</when>
								<when test="dateType == 3">
									<if test="starTime != null and starTime != ''">
										and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}
									</if>
									<if test="endTime != null and endTime != ''">
										and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
									</if>
								</when>
								<otherwise>
									<if test="starTime != null and starTime != ''">
										and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{starTime,jdbcType=VARCHAR}
									</if>
									<if test="endTime != null and endTime != ''">
										and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
									</if>
								</otherwise>
							</choose>
						</if>
						<if test="myOrdersn != null and myOrdersn != '' ">
							and my_ordersn like CONCAT('%',#{myOrdersn,jdbcType=VARCHAR},'%')
						</if>
						<if test="ordersn != null and ordersn != '' ">
							and ordersn like CONCAT('%',#{ordersn,jdbcType=VARCHAR},'%')
						</if>
						<if test="parentOrdersn != null and parentOrdersn != '' ">
							and parent_ordersn like CONCAT('%',#{parentOrdersn,jdbcType=VARCHAR},'%')
						</if>
						<if test="enterpriseId != null and enterpriseId != '' ">
							and enterprise_id = #{enterpriseId}
						</if>
						<if test="enterpriseName != null and enterpriseName != '' ">
							and enterprise_id in (
							select enterprise_id from sys_enterprise where enterprise_name like
							CONCAT('%',#{enterpriseName,jdbcType=VARCHAR},'%')
							)
						</if>
						<if test="dispatchname != null and dispatchname != '' ">
							and dispatchname like CONCAT('%',#{dispatchname,jdbcType=VARCHAR},'%')
						</if>
						<if test="realname != null and realname != '' ">
							and realname_id in (
							select user_id from sys_oder_user where realname like CONCAT('%',#{realname,jdbcType=VARCHAR},'%')
							)
						</if>
						<if test="mobile != null and mobile != '' ">
							and realname_id in (
							select user_id from sys_oder_user where mobile like CONCAT('%',#{mobile,jdbcType=VARCHAR},'%')
							)
						</if>
						<if test="addressRealname != null and addressRealname != '' ">
							and address_realname like CONCAT('%',#{addressRealname,jdbcType=VARCHAR},'%')
						</if>
						<if test="addressMobile != null and addressMobile != '' ">
							and address_mobile like CONCAT('%',#{addressMobile,jdbcType=VARCHAR},'%')
						</if>
						<if test="addressAddress != null and addressAddress != '' ">
							and address_address like CONCAT('%',#{addressAddress,jdbcType=VARCHAR},'%')
						</if>
						<if test="merchName != null and merchName != '' ">
							and merch_name like CONCAT('%',#{merchName,jdbcType=VARCHAR},'%')
						</if>
						<if test="orderType != null ">
							and order_type = #{orderType,jdbcType=VARCHAR}
						</if>
						<if test="payType != null ">
							and pay_type = #{payType,jdbcType=TINYINT}
						</if>
		)
	</select>

	<select id="findBySn"
	        resultMap="cn.superdesk.uniorder.dao.mapper.accounting.unified.customer.AccountingUnifiedCustomerMapper.BaseResultMap"
	        parameterType="java.lang.String">
		select
		<include refid="cn.superdesk.uniorder.dao.mapper.accounting.unified.customer.AccountingUnifiedCustomerMapper.Base_Column_List"/>
		from
			accounting_unified_customer
		where
			dz_sn = #{dzSn}
	</select>

</mapper>