<?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.AccountingUnifiedCustomerMapperExSys">




	<!-- TODO 弃弃弃 sys_order 已弃-->
	<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="startTime != null and startTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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>

	<!-- TODO 弃弃弃 sys_order 已弃-->
	<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_order_sn" 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>

	<!-- TODO 弃弃弃 sys_order 已弃-->
	<select id="findViewFromOrder" resultMap="ViewOrderResultMap">
		SELECT
		id,
		my_order_id,
		order_id,
		my_ordersn,
		ordersn,
		parent_order_id,
		parent_order_sn,
		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="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="startTime != null and startTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="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>

	<!-- TODO 弃弃弃 sys_order 已弃-->
	<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="startTime != null and startTime != ''">
							and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
							and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
							and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
							and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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_order_sn 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 弃弃弃 sys_order 已弃 写死 戴德梁行-->
	<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="startTime != null and startTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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_order_sn 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 弃弃弃 sys_order 已弃-->
	<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="startTime != null and startTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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>

	<!-- TODO 弃弃弃 sys_order -->
	<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="startTime != null and startTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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_order_sn 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 弃弃弃 sys_order -->
	<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_order_sn" 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>

	<!-- TODO 弃弃弃 sys_order -->
	<select id="findViewFromOrderGoods" resultMap="ViewOrderGoodsResultMap">
		select id,
		my_order_id,
		order_id,
		my_ordersn,
		ordersn,
		parent_order_id,
		parent_order_sn,
		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="startTime != null and startTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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_order_sn 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>



	<!-- TODO 弃弃弃 消失吧 sys_good -->
	<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>

	<!-- TODO 弃弃弃 消失吧 sys_good -->
	<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>

	<!-- TODO 弃弃弃 消失吧 sys_good -->
	<select id="GetGoodsById" resultMap="GoodsResultMap">
		select
		<include refid="Goods_Column_List"/>
		from sys_good
		where sys_order_id = #{_parameter,jdbcType=VARCHAR}
	</select>



	<!-- TODO 弃弃弃 消失吧 -->
	<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_order_sn" 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>

	<!-- TODO 弃弃弃 消失吧 -->
	<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_order_sn` AS `parent_order_sn`,
		`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>

	<!-- TODO 弃弃弃 消失吧 -->
	<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_order_sn" 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>

	<!-- TODO 弃弃弃 消失吧 -->
	<select id="findAllFromOrder" resultMap="OrderResultMap">
		select
		id, my_order_id, order_id, my_ordersn, ordersn, parent_order_id, parent_order_sn,
		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="startTime != null and startTime != ''">
						and DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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="startTime != null and startTime != ''">
						and DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,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>
</mapper>