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


	<resultMap id="SysOrderDetailResultMap" type="cn.superdesk.uniorder.dto.vo.accounting.unified.customer.ExpSysOrder">
		<id column="id" property="id" jdbcType="BIGINT"/>
		<result column="detail_url" property="detailUrl" jdbcType="VARCHAR"/>
		<result column="service_name" property="serviceName" jdbcType="VARCHAR"/>
		<result column="order_type_name" property="orderTypeName" jdbcType="VARCHAR"/>
		<result column="parent_ordersn" property="parentOrdersn" jdbcType="VARCHAR"/>
		<result column="ordersn" property="ordersn" jdbcType="VARCHAR"/>
		<result column="organization_name" property="organizationName" jdbcType="VARCHAR"/>
		<result column="enterprise_name" property="enterpriseName" jdbcType="VARCHAR"/>
		<result column="price" property="price" jdbcType="DECIMAL"/>
		<result column="paytype_name" property="paytypeName" jdbcType="VARCHAR"/>
		<result column="status_name" property="statusName" jdbcType="VARCHAR"/>
		<result column="realname" property="realname" jdbcType="VARCHAR"/>
		<result column="mobile" property="mobile" jdbcType="VARCHAR"/>
		<result column="address_address" property="addressAddress" jdbcType="VARCHAR"/>
		<result column="createtime" property="createtime" jdbcType="TIMESTAMP"/>
		<result column="merch_name" property="merchName" jdbcType="VARCHAR"/>
		<result column="remark" property="remark" jdbcType="VARCHAR"/>
		<result column="other_field1" property="otherField1" jdbcType="VARCHAR"/>
		<result column="taxCode" property="taxcode" jdbcType="VARCHAR"/>
		<result column="optionname" property="optionname" jdbcType="VARCHAR"/>
		<result column="total" property="total" jdbcType="INTEGER"/>
		<result column="unit_price" property="unitPrice" jdbcType="DECIMAL"/>
		<result column="total_price" property="totalPrice" jdbcType="DECIMAL"/>
		<result column="unit" property="unit" jdbcType="VARCHAR"/>
		<result column="address_realname" property="addressRealname" jdbcType="VARCHAR"/>
		<result column="address_mobile" property="addressMobile" jdbcType="VARCHAR"/>
		<result column="invoicetype_name" property="invoicetypeName" jdbcType="VARCHAR"/>
		<result column="sendtime" property="sendtime" jdbcType="TIMESTAMP"/>
		<result column="dispatch_price" property="dispatchPrice" jdbcType="DECIMAL"/>
		<result column="finishtime" property="finishtime" jdbcType="TIMESTAMP"/>

		<result column="express_no" property="expressNo" jdbcType="VARCHAR"/>
		<result column="company_name" property="companyName" jdbcType="VARCHAR"/>
		<result column="invoice_number" property="invoiceNumber" jdbcType="VARCHAR"/>
		<result column="invoice_time" property="invoiceTime" jdbcType="TIMESTAMP"/>
		<result column="invoice_status_name" property="invoiceStatusName" jdbcType="VARCHAR"/>

	</resultMap>
	<resultMap id="ExpSysOrderResultMap" type="cn.superdesk.uniorder.dto.vo.accounting.unified.customer.ExpSysOrder">
		<id column="id" property="id" jdbcType="BIGINT"/>
		<result column="parent_ordersn" property="parentOrdersn" jdbcType="VARCHAR"/>
		<result column="ordersn" property="ordersn" jdbcType="VARCHAR"/>
		<result column="organization_name" property="organizationName" jdbcType="VARCHAR"/>
		<result column="enterprise_name" property="enterpriseName" jdbcType="VARCHAR"/>
		<result column="price" property="price" jdbcType="DECIMAL"/>
		<result column="paytype_name" property="paytypeName" jdbcType="VARCHAR"/>
		<result column="status_name" property="statusName" jdbcType="VARCHAR"/>
		<result column="realname" property="realname" jdbcType="VARCHAR"/>
		<result column="mobile" property="mobile" jdbcType="VARCHAR"/>
		<result column="address_address" property="addressAddress" jdbcType="VARCHAR"/>
		<result column="createtime" property="createtime" jdbcType="TIMESTAMP"/>
		<result column="merch_name" property="merchName" jdbcType="VARCHAR"/>
		<result column="remark" property="remark" jdbcType="VARCHAR"/>
		<result column="other_field1" property="otherField1" jdbcType="VARCHAR"/>
		<result column="taxCode" property="taxcode" jdbcType="VARCHAR"/>
		<result column="optionname" property="optionname" jdbcType="VARCHAR"/>
		<result column="total" property="total" jdbcType="INTEGER"/>
		<result column="unit_price" property="unitPrice" jdbcType="DECIMAL"/>
		<result column="total_price" property="totalPrice" jdbcType="DECIMAL"/>
		<result column="unit" property="unit" jdbcType="VARCHAR"/>
		<result column="address_realname" property="addressRealname" jdbcType="VARCHAR"/>
		<result column="address_mobile" property="addressMobile" jdbcType="VARCHAR"/>
		<result column="invoicetype_name" property="invoicetypeName" jdbcType="VARCHAR"/>
		<result column="sendtime" property="sendtime" jdbcType="TIMESTAMP"/>
		<result column="dispatch_price" property="dispatchPrice" jdbcType="DECIMAL"/>
		<result column="finishtime" property="finishtime" jdbcType="TIMESTAMP"/>

	</resultMap>
	<resultMap id="ExpSysOrderDetailResultMap" type="cn.superdesk.uniorder.dto.vo.accounting.unified.customer.ExpSysOrder">
		<id column="id" property="id" jdbcType="BIGINT"/>
		<result column="parent_ordersn" property="parentOrdersn" jdbcType="VARCHAR"/>
		<result column="ordersn" property="ordersn" jdbcType="VARCHAR"/>
		<result column="organization_name" property="organizationName" jdbcType="VARCHAR"/>
		<result column="enterprise_name" property="enterpriseName" jdbcType="VARCHAR"/>
		<result column="price" property="price" jdbcType="DECIMAL"/>
		<result column="paytype_name" property="paytypeName" jdbcType="VARCHAR"/>
		<result column="status_name" property="statusName" jdbcType="VARCHAR"/>
		<result column="realname" property="realname" jdbcType="VARCHAR"/>
		<result column="mobile" property="mobile" jdbcType="VARCHAR"/>
		<result column="address_address" property="addressAddress" jdbcType="VARCHAR"/>
		<result column="createtime" property="createtime" jdbcType="TIMESTAMP"/>
		<result column="merch_name" property="merchName" jdbcType="VARCHAR"/>
		<result column="remark" property="remark" jdbcType="VARCHAR"/>
		<result column="other_field1" property="otherField1" jdbcType="VARCHAR"/>
		<result column="taxCode" property="taxcode" jdbcType="VARCHAR"/>
		<result column="optionname" property="optionname" jdbcType="VARCHAR"/>
		<result column="total" property="total" jdbcType="INTEGER"/>
		<result column="unit_price" property="unitPrice" jdbcType="DECIMAL"/>
		<result column="total_price" property="totalPrice" jdbcType="DECIMAL"/>
		<result column="unit" property="unit" jdbcType="VARCHAR"/>
		<result column="address_realname" property="addressRealname" jdbcType="VARCHAR"/>
		<result column="address_mobile" property="addressMobile" jdbcType="VARCHAR"/>
		<result column="invoicetype_name" property="invoicetypeName" jdbcType="VARCHAR"/>
		<result column="sendtime" property="sendtime" jdbcType="TIMESTAMP"/>
		<result column="dispatch_price" property="dispatchPrice" jdbcType="DECIMAL"/>
		<result column="finishtime" property="finishtime" jdbcType="TIMESTAMP"/>

		<result column="express_no" property="expressNo" jdbcType="VARCHAR"/>
		<result column="company_name" property="companyName" jdbcType="VARCHAR"/>
		<result column="invoice_number" property="invoiceNumber" jdbcType="VARCHAR"/>
		<result column="invoice_time" property="invoiceTime" jdbcType="TIMESTAMP"/>
		<result column="invoice_status_name" property="invoiceStatusName" jdbcType="VARCHAR"/>
		<result column="invoice_company_name" property="invoiceCompanyName" jdbcType="VARCHAR"/>

	</resultMap>
	<resultMap id="SysGoodResultMap" type="cn.superdesk.uniorder.dto.vo.accounting.unified.customer.ExpSysOrder">
		<id column="sys_order_id" property="SysOrderId" jdbcType="VARCHAR"/>
		<result column="other_field1" property="otherField1" jdbcType="VARCHAR"/>
		<result column="taxCode" property="taxcode" jdbcType="VARCHAR"/>
		<result column="optionname" property="optionname" jdbcType="VARCHAR"/>
		<result column="total" property="total" jdbcType="INTEGER"/>
		<result column="unit_price" property="unitPrice" jdbcType="DECIMAL"/>
		<result column="total_price" property="totalPrice" jdbcType="DECIMAL"/>
		<result column="unit" property="unit" jdbcType="VARCHAR"/>
		<result column="dispatch_price" property="dispatchPrice" jdbcType="DECIMAL"/>
	</resultMap>
	<resultMap id="SysInviceResultMap" type="cn.superdesk.uniorder.dto.vo.sys.SysInvoiceOrder">

		<result column="order_id" property="orderId" jdbcType="BIGINT"/>
		<result column="invoice_number" property="invoiceNumber" jdbcType="VARCHAR"/>
		<result column="invoice_time" property="invoiceTime" jdbcType="TIMESTAMP"/>
		<result column="invoice_status" property="invoiceStatus" jdbcType="INTEGER"/>
		<result column="express_no" property="expressNo" jdbcType="VARCHAR"/>
		<result column="company_name" property="companyName" jdbcType="VARCHAR"/>

	</resultMap>
	<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>

	<sql id="SysGood_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>

	<select id="findAll" resultMap="cn.superdesk.uniorder.dao.mapper.accounting.unified.customer.AccountingUnifiedCustomerOrderMapper.BaseResultMap">
		select
		<include refid="cn.superdesk.uniorder.dao.mapper.accounting.unified.customer.AccountingUnifiedCustomerOrderMapper.Base_Column_List"/>
		from
			accounting_unified_customer_order
		where 1=1
		<if test="dzId != null ">
			and dz_id = #{dzId,jdbcType=BIGINT}
		</if>
		<if test="orderId != null ">
			and order_id = #{orderId,jdbcType=BIGINT}
		</if>
		<if test="orderTableId != null ">
			and id = #{orderTableId,jdbcType=BIGINT}
		</if>
		<if test="myOrderSn != null ">
			and ordersn = #{myOrderSn,jdbcType=BIGINT}
		</if>
	</select>
	<select id="findOrderView" resultMap="SysOrderDetailResultMap">
		SELECT
		sys_order.id,
		sys_order.detail_url,
		sys_order.service_name,
		order_source_type.source_name order_type_name,
		sys_order.parent_ordersn,
		sys_order.ordersn,
		sys_organization.organization_name,
		sys_enterprise.enterprise_name,
		sys_order.price,
		CASE
		WHEN sys_order.paytype = 0 THEN '未支付'
		WHEN sys_order.paytype = 1 THEN '余额支付'
		WHEN sys_order.paytype = 2 THEN '在线支付'
		WHEN sys_order.paytype = 3 THEN '企业月结'
		WHEN sys_order.paytype = 11 THEN '后台付款'
		WHEN sys_order.paytype = 21 THEN '微信支付'
		WHEN sys_order.paytype = 22 THEN '支付宝支付'
		WHEN sys_order.paytype = 23 THEN '银联支付'
		ELSE '未支付' END AS paytype_name,
		CASE
		WHEN sys_order.`status` = -1 THEN '已关闭'
		WHEN sys_order.`status` = 0 THEN '待付款'
		WHEN sys_order.`status` = 1 THEN '待发货'
		WHEN sys_order.`status` = 2 THEN '待收货'
		WHEN sys_order.`status` = 3 THEN '已完成'
		ELSE '已关闭' END AS status_name,
		sys_oder_user.realname,
		sys_oder_user.mobile,
		sys_order.address_address,
		sys_order.createtime,
		sys_order.merch_name,
		sys_order.remark,
		sys_good.other_field1,
		sys_good.tax_code,
		sys_good.optionname,
		sys_good.total,
		sys_good.unit_price,
		sys_good.total_price,
		sys_good.unit,
		sys_order.address_realname,
		sys_order.address_mobile,
		CASE
		WHEN sys_order.invoiceType = 1 THEN '增值税普票'
		WHEN sys_order.invoiceType = 2 THEN '增值税专票'

		ELSE '增值税普票' END AS invoiceType_name,
		sys_order.sendtime,
		sys_good.dispatch_price,
		sys_order.finishtime
		,TB.express_no
		,TB.company_name
		,TB.invoice_number
		,TB.invoice_time,
		CASE
		WHEN TB.invoice_status = 0 THEN '未邮寄'
		WHEN TB.invoice_status = 1 THEN '已邮寄'
		WHEN TB.invoice_status = 2 THEN '已作废'
		ELSE '' END AS invoice_status_name
		FROM
		sys_order
		RIGHT JOIN sys_good ON sys_good.sys_order_id = sys_order.my_order_id
		LEFT JOIN sys_organization ON sys_order.organization_id = sys_organization.organization_id
		LEFT JOIN sys_enterprise ON sys_order.enterprise_id = sys_enterprise.enterprise_id
		LEFT JOIN sys_oder_user ON sys_order.realname_id = sys_oder_user.user_id
		LEFT JOIN order_source_type ON sys_order.service_name = order_source_type.id
		LEFT JOIN
		(
		SELECT
		sys_invoice.invoice_number,sys_invoice.invoice_time,sys_invoice.invoice_status,sys_invoice.express_no,express_company.company_name,accounting_unified_customer_order.order_id
		FROM accounting_unified_customer_order
		LEFT JOIN accounting_unified_customer ON accounting_unified_customer.id=accounting_unified_customer_order.dz_id
		LEFT JOIN sys_invoice ON sys_invoice.dz_order_id = accounting_unified_customer_order.id
		LEFT JOIN express_company ON express_company.id=sys_invoice.express_company_id
		WHERE accounting_unified_customer.dz_status=1
		) TB
		ON TB.order_id = sys_order.id

		where 1=1
		<if test="userId != null ">
			and sys_order.service_name in (
			select sourcetype_id from sys_user_order_sourcetype where user_id=#{userId,jdbcType=BIGINT}
			)
		</if>
		<if test="isGenBill != null ">
			and sys_order.is_gen_bill = #{isGenBill,jdbcType=TINYINT}
		</if>
		<if test="dateType != null ">
			<choose>
				<when test="dateType == 1">
					<if test="startTime != null and startTime != ''">
						and DATE_FORMAT(sys_order.createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,jdbcType=VARCHAR}

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(sys_order.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(sys_order.sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,jdbcType=VARCHAR}
					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(sys_order.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(sys_order.finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,jdbcType=VARCHAR}

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

					</if>
					<if test="endTime != null and endTime != ''">
						and DATE_FORMAT(sys_order.finishtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
					</if>
				</otherwise>
			</choose>
		</if>
		<if test="myOrdersn != null and myOrdersn != '' ">
			and sys_order.my_ordersn like CONCAT('%',#{myOrdersn,jdbcType=VARCHAR},'%')
		</if>
		<if test="ordersn != null and ordersn != '' ">
			and sys_order.ordersn like CONCAT('%',#{ordersn,jdbcType=VARCHAR},'%')
		</if>
		<if test="parentOrdersn != null and parentOrdersn != '' ">
			and sys_order.parent_ordersn like CONCAT('%',#{parentOrdersn,jdbcType=VARCHAR},'%')
		</if>
		<if test="enterpriseName != null and enterpriseName != '' ">
			and sys_order.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 sys_order.dispatchname like CONCAT('%',#{dispatchname,jdbcType=VARCHAR},'%')
		</if>
		<if test="realname != null and realname != '' ">
			and sys_order.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 sys_order.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 sys_order.address_realname like CONCAT('%',#{addressRealname,jdbcType=VARCHAR},'%')
		</if>
		<if test="addressMobile != null and addressMobile != '' ">
			and sys_order.address_mobile like CONCAT('%',#{addressMobile,jdbcType=VARCHAR},'%')
		</if>
		<if test="addressAddress != null and addressAddress != '' ">
			and sys_order.address_address like CONCAT('%',#{addressAddress,jdbcType=VARCHAR},'%')
		</if>
		<if test="merchName != null and merchName != '' ">
			and sys_order.merch_name like CONCAT('%',#{merchName,jdbcType=VARCHAR},'%')
		</if>
		<if test="serviceName != null ">
			and sys_order.service_name = #{serviceName}
		</if>
		<if test="paytype != null ">
			and sys_order.paytype = #{paytype,jdbcType=TINYINT}
		</if>
	</select>
	<select id="findOrderViewExcel" resultMap="ExpSysOrderResultMap">
		SELECT
		sys_order.id,
		sys_order.parent_ordersn,
		sys_order.ordersn,
		sys_organization.organization_name,
		sys_enterprise.enterprise_name,
		sys_order.price,
		CASE
		WHEN sys_order.paytype = 0 THEN '未支付'
		WHEN sys_order.paytype = 1 THEN '余额支付'
		WHEN sys_order.paytype = 2 THEN '在线支付'
		WHEN sys_order.paytype = 3 THEN '企业月结'
		WHEN sys_order.paytype = 11 THEN '后台付款'
		WHEN sys_order.paytype = 21 THEN '微信支付'
		WHEN sys_order.paytype = 22 THEN '支付宝支付'
		WHEN sys_order.paytype = 23 THEN '银联支付'
		ELSE '未支付' END AS paytype_name,
		CASE
		WHEN sys_order.`status` = -1 THEN '已关闭'
		WHEN sys_order.`status` = 0 THEN '待付款'
		WHEN sys_order.`status` = 1 THEN '待发货'
		WHEN sys_order.`status` = 2 THEN '待收货'
		WHEN sys_order.`status` = 3 THEN '已完成'
		ELSE '已关闭' END AS status_name,
		sys_oder_user.realname,
		sys_oder_user.mobile,
		sys_order.address_address,
		sys_order.createtime,
		sys_order.merch_name,
		sys_order.remark,
		sys_good.other_field1,
		sys_good.tax_code,
		sys_good.optionname,
		sys_good.total,
		sys_good.unit_price,
		sys_good.total_price,
		sys_good.unit,
		sys_order.address_realname,
		sys_order.address_mobile,
		CASE
		WHEN sys_order.invoiceType = 1 THEN '增值税普票'
		WHEN sys_order.invoiceType = 2 THEN '增值税专票'

		ELSE '增值税普票' END AS invoicetype_name,
		sys_order.sendtime,
		sys_good.dispatch_price,
		sys_order.finishtime
		FROM
		sys_order
		RIGHT JOIN sys_good ON sys_good.sys_order_id = sys_order.my_order_id
		LEFT JOIN sys_organization ON sys_order.organization_id = sys_organization.organization_id
		LEFT JOIN sys_enterprise ON sys_order.enterprise_id = sys_enterprise.enterprise_id
		LEFT JOIN sys_oder_user ON sys_order.realname_id = sys_oder_user.user_id
		where 1=1
		<if test="oIds !=null and oIds != ''">
			and sys_order.id in
			<foreach collection="oIds" index="index" item="oid" open="(" close=")" separator=",">
				#{oid}
			</foreach>
		</if>
	</select>
	<select id="getOrderViewExcel" resultMap="ExpSysOrderDetailResultMap">
		SELECT
		sys_order.id,
		sys_order.parent_ordersn,
		sys_order.ordersn,
		sys_organization.organization_name,
		sys_enterprise.enterprise_name,
		sys_order.price,
		CASE
		WHEN sys_order.paytype = 0 THEN '未支付'
		WHEN sys_order.paytype = 1 THEN '余额支付'
		WHEN sys_order.paytype = 2 THEN '在线支付'
		WHEN sys_order.paytype = 3 THEN '企业月结'
		WHEN sys_order.paytype = 11 THEN '后台付款'
		WHEN sys_order.paytype = 21 THEN '微信支付'
		WHEN sys_order.paytype = 22 THEN '支付宝支付'
		WHEN sys_order.paytype = 23 THEN '银联支付'
		ELSE '未支付' END AS paytype_name,
		CASE
		WHEN sys_order.`status` = -1 THEN '已关闭'
		WHEN sys_order.`status` = 0 THEN '待付款'
		WHEN sys_order.`status` = 1 THEN '待发货'
		WHEN sys_order.`status` = 2 THEN '待收货'
		WHEN sys_order.`status` = 3 THEN '已完成'
		ELSE '已关闭' END AS status_name,
		sys_oder_user.realname,
		sys_oder_user.mobile,
		sys_order.address_address,
		sys_order.createtime,
		sys_order.merch_name,
		sys_order.remark,
		sys_good.other_field1,
		sys_good.tax_code,
		sys_good.optionname,
		sys_good.total,
		sys_good.unit_price,
		sys_good.total_price,
		sys_good.unit,
		sys_order.address_realname,
		sys_order.address_mobile,
		sys_order.companyName as invoice_company_name,
		CASE
		WHEN sys_order.invoiceType = 1 THEN '增值税普票'
		WHEN sys_order.invoiceType = 2 THEN '增值税专票'

		ELSE '增值税普票' END AS invoicetype_name,
		sys_order.sendtime,
		sys_good.dispatch_price,
		sys_order.finishtime
		,TB.express_no
		,TB.company_name
		,TB.invoice_number
		,TB.invoice_time,
		CASE
		WHEN TB.invoice_status = 0 THEN '未邮寄'
		WHEN TB.invoice_status = 1 THEN '已邮寄'
		WHEN TB.invoice_status = 2 THEN '已作废'
		ELSE '' END AS invoice_status_name
		FROM
		sys_order
		RIGHT JOIN sys_good ON sys_good.sys_order_id = sys_order.my_order_id
		LEFT JOIN sys_organization ON sys_order.organization_id = sys_organization.organization_id
		LEFT JOIN sys_enterprise ON sys_order.enterprise_id = sys_enterprise.enterprise_id
		LEFT JOIN sys_oder_user ON sys_order.realname_id = sys_oder_user.user_id

		LEFT JOIN
		(
		SELECT
		sys_invoice.invoice_number,sys_invoice.invoice_time,sys_invoice.invoice_status,sys_invoice.express_no,express_company.company_name,accounting_unified_customer_order.order_id
		FROM accounting_unified_customer_order
		LEFT JOIN accounting_unified_customer ON accounting_unified_customer.id=accounting_unified_customer_order.dz_id
		LEFT JOIN sys_invoice ON sys_invoice.dz_order_id = accounting_unified_customer_order.id
		LEFT JOIN express_company ON express_company.id=sys_invoice.express_company_id
		WHERE accounting_unified_customer.dz_status=1
		) TB
		ON TB.order_id = sys_order.id

		where 1=1
		and sys_order.id in
		(
		select id
		from sys_order

		where 1=1 and `status` != -1
		<if test="userId != null ">
			and service_name 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_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="enterpriseId != null and enterpriseId != '' ">
			and enterprise_id = #{enterpriseId,jdbcType=BIGINT}
		</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="serviceName != null ">
			and service_name = #{serviceName}
		</if>
		<if test="paytype != null ">
			and paytype = #{paytype,jdbcType=TINYINT}
		</if>
		<if test="getDD != null and getDD != '' ">
			and enterprise_id in (
			SELECT id from temp_daide
			)
		</if>
		)


		<!-- <if test="oIds !=null and oIds != ''">
			and sys_order.id in
			<foreach collection="oIds" index="index" item="oid" open="(" close=")" separator=",">
			#{oid}
			</foreach>
		</if> -->
	</select>
	<select id="findSysOrderGoods" resultMap="SysGoodResultMap">
		select
		sys_order_id,
		other_field1,
		tax_code,
		optionname,
		total,
		unit_price,
		total_price,
		unit,
		dispatch_price
		from sys_good where 1=1
		and sys_order_id in (
		select my_order_id from sys_order where `status` != -1
		)
		<if test="userId != null ">
			and sys_order_id in (
			select my_order_id from sys_order where service_name in (
			select sourcetype_id from sys_user_order_sourcetype where user_id=#{userId,jdbcType=BIGINT}
			)
			)
		</if>
		<if test="isGenBill != null ">
			and sys_order_id in (
			select my_order_id from sys_order where is_gen_bill = #{isGenBill,jdbcType=TINYINT}
			)
		</if>
		<if test="dateType != null ">
			<choose>
				<when test="dateType == 1">
					<if test="startTime != null and startTime != ''">
						and sys_order_id in (
						select my_order_id from sys_order where
						DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,jdbcType=VARCHAR}
						)
					</if>
					<if test="endTime != null and endTime != ''">
						and sys_order_id in (
						select my_order_id from sys_order where
						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 sys_order_id in (
						select my_order_id from sys_order where
						DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,jdbcType=VARCHAR}
						)
					</if>
					<if test="endTime != null and endTime != ''">
						and sys_order_id in (
						select my_order_id from sys_order where
						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 sys_order_id in (
						select my_order_id from sys_order where
						DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,jdbcType=VARCHAR}
						)

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

					</if>
					<if test="endTime != null and endTime != ''">
						and sys_order_id in (
						select my_order_id from sys_order where
						DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
						)
					</if>
				</otherwise>
			</choose>
		</if>
		<if test="myOrdersn != null and myOrdersn != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where my_ordersn like CONCAT('%',#{myOrdersn,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="ordersn != null and ordersn != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where ordersn like CONCAT('%',#{ordersn,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="parentOrdersn != null and parentOrdersn != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where parent_ordersn like
			CONCAT('%',#{parentOrdersn,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="enterpriseName != null and enterpriseName != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where 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 sys_order_id in (
			select my_order_id from sys_order where dispatchname like CONCAT('%',#{dispatchname,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="realname != null and realname != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where 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 sys_order_id in (
			select my_order_id from sys_order where 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 sys_order_id in (
			select my_order_id from sys_order where address_realname like
			CONCAT('%',#{addressRealname,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="addressMobile != null and addressMobile != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where address_mobile like
			CONCAT('%',#{addressMobile,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="addressAddress != null and addressAddress != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where address_address like
			CONCAT('%',#{addressAddress,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="merchName != null and merchName != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where merch_name like CONCAT('%',#{merchName,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="serviceName != null ">
			and sys_order_id in (
			select my_order_id from sys_order where service_name = #{serviceName}
			)
		</if>
		<if test="paytype != null ">
			and sys_order_id in (
			select my_order_id from sys_order where paytype = #{paytype,jdbcType=TINYINT}
			)
		</if>
		ORDER BY id DESC

	</select>
	<select id="findSysOrderGoodsProject" resultMap="SysGoodResultMap">
		select
			sys_order_id,
			other_field1,
			tax_code,
			optionname,
			total,
			unit_price,
			total_price,
			unit,
			dispatch_price
		from
			sys_good
		where 1=1
			and sys_order_id in ( select my_order_id from sys_order where `status` != -1 )
			and sys_order_id in ( select my_order_id from sys_order where enterprise_id in ( SELECT id from temp_daide))
		<if test="userId != null ">
			and sys_order_id in (
			select my_order_id from sys_order where service_name in (
			select sourcetype_id from sys_user_order_sourcetype where user_id=#{userId,jdbcType=BIGINT}
			)
			)
		</if>
		<if test="isGenBill != null ">
			and sys_order_id in (
			select my_order_id from sys_order where is_gen_bill = #{isGenBill,jdbcType=TINYINT}
			)
		</if>
		<if test="dateType != null ">
			<choose>
				<when test="dateType == 1">
					<if test="startTime != null and startTime != ''">
						and sys_order_id in (
						select my_order_id from sys_order where
						DATE_FORMAT(createtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,jdbcType=VARCHAR}
						)
					</if>
					<if test="endTime != null and endTime != ''">
						and sys_order_id in (
						select my_order_id from sys_order where
						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 sys_order_id in (
						select my_order_id from sys_order where
						DATE_FORMAT(sendtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,jdbcType=VARCHAR}
						)
					</if>
					<if test="endTime != null and endTime != ''">
						and sys_order_id in (
						select my_order_id from sys_order where
						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 sys_order_id in (
						select my_order_id from sys_order where
						DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &gt;= #{startTime,jdbcType=VARCHAR}
						)

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

					</if>
					<if test="endTime != null and endTime != ''">
						and sys_order_id in (
						select my_order_id from sys_order where
						DATE_FORMAT(finishtime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime,jdbcType=VARCHAR}
						)
					</if>
				</otherwise>
			</choose>
		</if>
		<if test="myOrdersn != null and myOrdersn != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where my_ordersn like CONCAT('%',#{myOrdersn,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="ordersn != null and ordersn != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where ordersn like CONCAT('%',#{ordersn,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="parentOrdersn != null and parentOrdersn != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where parent_ordersn like
			CONCAT('%',#{parentOrdersn,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="enterpriseName != null and enterpriseName != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where enterprise_id in (
			select enterprise_id from sys_enterprise where enterprise_name like
			CONCAT('%',#{enterpriseName,jdbcType=VARCHAR},'%')
			)
			)
		</if>
		<if test="enterpriseId != null and enterpriseId != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where enterprise_id = #{enterpriseId}
			)
		</if>

		<if test="dispatchname != null and dispatchname != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where dispatchname like CONCAT('%',#{dispatchname,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="realname != null and realname != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where 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 sys_order_id in (
			select my_order_id from sys_order where 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 sys_order_id in (
			select my_order_id from sys_order where address_realname like
			CONCAT('%',#{addressRealname,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="addressMobile != null and addressMobile != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where address_mobile like
			CONCAT('%',#{addressMobile,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="addressAddress != null and addressAddress != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where address_address like
			CONCAT('%',#{addressAddress,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="merchName != null and merchName != '' ">
			and sys_order_id in (
			select my_order_id from sys_order where merch_name like CONCAT('%',#{merchName,jdbcType=VARCHAR},'%')
			)
		</if>
		<if test="serviceName != null ">
			and sys_order_id in (
			select my_order_id from sys_order where service_name = #{serviceName}
			)
		</if>
		<if test="paytype != null ">
			and sys_order_id in (
			select my_order_id from sys_order where paytype = #{paytype,jdbcType=TINYINT}
			)
		</if>
		order by id desc

	</select>
	<select id="findInvByOrderId" resultMap="SysInviceResultMap">
		SELECT
			sys_invoice.invoice_number,
			sys_invoice.invoice_time,
			sys_invoice.invoice_status,
			sys_invoice.express_no,
			express_company.company_name,
			accounting_unified_customer_order.order_id
		FROM
			accounting_unified_customer_order
			LEFT JOIN accounting_unified_customer ON accounting_unified_customer.id=accounting_unified_customer_order.dz_id
			LEFT JOIN sys_invoice ON sys_invoice.dz_order_id = accounting_unified_customer_order.id
			LEFT JOIN express_company ON express_company.id=sys_invoice.express_company_id
		WHERE
			accounting_unified_customer.dz_status=1
			AND accounting_unified_customer_order.order_id = #{_parameter,jdbcType=BIGINT}
		
  	</select>
	<select id="getReportQuantity" resultMap="ReportOrderResultMap">
		select
		count(*) quantity,IFNULL(sum(price),0) amount
		from
		accounting_unified_customer_order
		where
		1=1
		<if test="dzids !=null and dzids != ''">
			and dz_id in
			<foreach collection="dzids" index="index" item="dzid" open="(" close=")" separator=",">
				#{dzid}
			</foreach>
		</if>
	</select>

</mapper>