<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yifu.cloud.plus.v1.yifu.order.mapper.TOrderMapper">
		<resultMap id="BaseResultMap" type="com.yifu.cloud.plus.v1.yifu.order.entity.TOrder">
			<result property="id" column="ID" jdbcType="VARCHAR"/>
			<result property="orderNo" column="ORDER_NO" jdbcType="VARCHAR"/>
			<result property="customerName" column="CUSTOMER_NAME" jdbcType="VARCHAR"/>
			<result property="deptId" column="DEPT_ID" jdbcType="VARCHAR"/>
			<result property="deptName" column="DEPT_NAME" jdbcType="VARCHAR"/>
			<result property="deptNo" column="DEPT_NO" jdbcType="VARCHAR"/>
			<result property="orderStatus" column="ORDER_STATUS" jdbcType="TINYINT"/>
			<result property="orderContent" column="ORDER_CONTENT" jdbcType="VARCHAR"/>
			<result property="createName" column="CREATE_NAME" jdbcType="VARCHAR"/>
			<result property="createTime" column="CREATE_TIME" jdbcType="TIMESTAMP"/>
			<result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
			<result property="updateName" column="UPDATE_NAME" jdbcType="VARCHAR"/>
			<result property="updateTime" column="UPDATE_TIME" jdbcType="TIMESTAMP"/>
			<result property="deleteFlag" column="DELETE_FLAG" jdbcType="TINYINT"/>
			<result property="level" column="LEVEL" jdbcType="VARCHAR"/>
			<result property="department" column="DEPARTMENT" jdbcType="VARCHAR"/>
			<result property="customerGrade" column="CUSTOMER_GRADE" jdbcType="VARCHAR"/>
			<result property="urgencyExtent" column="URGENCY_EXTENT" jdbcType="VARCHAR"/>
			<result property="serviceType" column="SERVICE_TYPE" jdbcType="VARCHAR"/>
			<result property="serviceProject" column="SERVICE_PROJECT" jdbcType="VARCHAR"/>
			<result property="demand" column="DEMAND" jdbcType="VARCHAR"/>
			<result property="handleUser" column="HANDLE_USER" jdbcType="VARCHAR"/>
			<result property="status" column="STATUS" jdbcType="VARCHAR"/>
			<result property="salaryFlag" column="SALARY_FLAG" jdbcType="VARCHAR"/>
			<result property="salaryName" column="SALARY_NAME" jdbcType="VARCHAR"/>
			<result property="salaryIdcard" column="SALARY_IDCARD" jdbcType="VARCHAR"/>
			<result property="salaryExpenses" column="SALARY_EXPENSES" jdbcType="VARCHAR"/>
			<result property="wageFlag" column="WAGE_FLAG" jdbcType="VARCHAR"/>
			<result property="wageName" column="WAGE_NAME" jdbcType="VARCHAR"/>
			<result property="wageIdcard" column="WAGE_IDCARD" jdbcType="VARCHAR"/>
			<result property="wageExpenses" column="WAGE_EXPENSES" jdbcType="VARCHAR"/>
			<result property="socialFlag" column="SOCIAL_FLAG" jdbcType="VARCHAR"/>
			<result property="socialName" column="SOCIAL_NAME" jdbcType="VARCHAR"/>
			<result property="socialIdcard" column="SOCIAL_IDCARD" jdbcType="VARCHAR"/>
			<result property="socialExpenses" column="SOCIAL_EXPENSES" jdbcType="VARCHAR"/>
			<result property="fundFlag" column="FUND_FLAG" jdbcType="VARCHAR"/>
			<result property="fundName" column="FUND_NAME" jdbcType="VARCHAR"/>
			<result property="fundIdcard" column="FUND_IDCARD" jdbcType="VARCHAR"/>
			<result property="fundExpenses" column="FUND_EXPENSES" jdbcType="VARCHAR"/>
			<result property="insuranceFlag" column="INSURANCE_FLAG" jdbcType="VARCHAR"/>
			<result property="insuranceName" column="INSURANCE_NAME" jdbcType="VARCHAR"/>
			<result property="insuranceIdcard" column="INSURANCE_IDCARD" jdbcType="VARCHAR"/>
			<result property="insuranceExpenses" column="INSURANCE_EXPENSES" jdbcType="VARCHAR"/>
			<result property="withholdingFlag" column="WITHHOLDING_FLAG" jdbcType="VARCHAR"/>
			<result property="withholdingName" column="WITHHOLDING_NAME" jdbcType="VARCHAR"/>
			<result property="withholdingIdcard" column="WITHHOLDING_IDCARD" jdbcType="VARCHAR"/>
			<result property="withholdingExpenses" column="WITHHOLDING_EXPENSES" jdbcType="VARCHAR"/>
			<result property="collectionFlag" column="COLLECTION_FLAG" jdbcType="VARCHAR"/>
			<result property="collectionName" column="COLLECTION_NAME" jdbcType="VARCHAR"/>
			<result property="collectionIdcard" column="COLLECTION_IDCARD" jdbcType="VARCHAR"/>
			<result property="collectionExpenses" column="COLLECTION_EXPENSES" jdbcType="VARCHAR"/>
			<result property="noTaxFlag" column="NO_TAX_FLAG" jdbcType="VARCHAR"/>
			<result property="noTaxName" column="NO_TAX_NAME" jdbcType="VARCHAR"/>
			<result property="noTaxIdcard" column="NO_TAX_IDCARD" jdbcType="VARCHAR"/>
			<result property="noTaxExpenses" column="NO_TAX_EXPENSES" jdbcType="VARCHAR"/>
			<result property="otherFlag" column="OTHER_FLAG" jdbcType="VARCHAR"/>
			<result property="otherName" column="OTHER_NAME" jdbcType="VARCHAR"/>
			<result property="otherIdcard" column="OTHER_IDCARD" jdbcType="VARCHAR"/>
			<result property="otherExpenses" column="OTHER_EXPENSES" jdbcType="VARCHAR"/>
		</resultMap>

		<sql id="Base_Column_List">
			ID,ORDER_NO,CUSTOMER_NAME,
			DEPT_ID,DEPT_NAME,DEPT_NO,
			ORDER_STATUS,ORDER_CONTENT,CREATE_NAME,
			CREATE_TIME,UPDATE_BY,UPDATE_NAME,
			UPDATE_TIME,DELETE_FLAG,LEVEL,
			DEPARTMENT,CUSTOMER_GRADE,URGENCY_EXTENT,
			SERVICE_TYPE,SERVICE_PROJECT,DEMAND,
			HANDLE_USER,STATUS,SALARY_FLAG,
			SALARY_NAME,SALARY_IDCARD,SALARY_EXPENSES,
			WAGE_FLAG,WAGE_NAME,WAGE_IDCARD,
			WAGE_EXPENSES,SOCIAL_FLAG,SOCIAL_NAME,
			SOCIAL_IDCARD,SOCIAL_EXPENSES,FUND_FLAG,
			FUND_NAME,FUND_IDCARD,FUND_EXPENSES,
			INSURANCE_FLAG,INSURANCE_NAME,INSURANCE_IDCARD,
			INSURANCE_EXPENSES,WITHHOLDING_FLAG,WITHHOLDING_NAME,
			WITHHOLDING_IDCARD,WITHHOLDING_EXPENSES,COLLECTION_FLAG,
			COLLECTION_NAME,COLLECTION_IDCARD,COLLECTION_EXPENSES,
			NO_TAX_FLAG,NO_TAX_NAME,NO_TAX_IDCARD,
			NO_TAX_EXPENSES,OTHER_FLAG,OTHER_NAME,
			OTHER_IDCARD,OTHER_EXPENSES
		</sql>

	<select id="getOrderPageList" resultType="com.yifu.cloud.plus.v1.yifu.order.vo.OrderListVO">
		select a.id as id,
		a.ORDER_NO as orderNo,
		a.CREATE_TIME as createTime,
		a.CREATE_NAME as createName,
		a.CUSTOMER_NAME as customerName,
		a.DEPT_NAME as deptName,
		a.DEPT_NO as deptNo,
		a.LEVEL as level,
		a.ORDER_STATUS as orderStatus
		from t_order a
		left join t_order_handler h on h.ORDER_NO = a.ORDER_NO
		where a.DELETE_FLAG = 0
		<if test="param.orderNo != null and param.orderNo.trim() != ''">
			and a.ORDER_NO = #{param.orderNo}
		</if>
		<if test="param.startDate != null and param.startDate.trim() != '' and param.endDate != null and param.endDate.trim() != ''">
			and a.CREATE_TIME <![CDATA[ >= ]]>  concat(#{param.startDate}, ' 00:00:00') and a.CREATE_TIME <![CDATA[ <= ]]> concat(#{param.endDate}, ' 23:59:59')
		</if>
		<if test="param.createName != null and param.createName.trim() != ''">
			and a.CREATE_NAME like concat('%',replace(replace(#{param.createName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.customerName != null and param.customerName.trim() != ''">
			and a.CUSTOMER_NAME = #{param.customerName}
		</if>
		<if test="param.deptName != null and param.deptName.trim() != ''">
			and a.DEPT_NAME = #{param.deptName}
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and a.DEPT_NO like concat('%',replace(replace(#{param.deptNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.orderStatus != null">
			and a.ORDER_STATUS = #{param.orderStatus}
		</if>
		<if test="param.level != null and param.level.trim() != ''">
			and a.LEVEL = #{param.level}
		</if>
		<if test="param.authSql != null and param.authSql.trim() != ''">
			${param.authSql}
		</if>
		GROUP BY a.ID
		ORDER BY a.CREATE_TIME DESC
	</select>

	<select id="getOrderListBySelect" resultType="com.yifu.cloud.plus.v1.yifu.order.vo.OrderListVO">
		select t.id as id,
		t.ORDER_NO as orderNo,
		t.CREATE_TIME as createTime,
		t.CREATE_NAME as createName,
		t.CUSTOMER_NAME as customerName,
		t.DEPT_NAME as deptName,
		t.DEPT_NO as deptNo,
		t.LEVEL as level,
		t.ORDER_STATUS as orderStatus
		from t_order t
		where t.DELETE_FLAG = 0 and t.id in
		<foreach collection="idList" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>
		ORDER BY t.CREATE_TIME DESC
	</select>

	<select id="getOrderList" resultType="com.yifu.cloud.plus.v1.yifu.order.vo.OrderListVO">
		select a.id as id,
		a.ORDER_NO as orderNo,
		a.CREATE_TIME as createTime,
		a.CREATE_NAME as createName,
		a.CUSTOMER_NAME as customerName,
		a.DEPT_NAME as deptName,
		a.DEPT_NO as deptNo,
		a.LEVEL as level,
		a.ORDER_STATUS as orderStatus
		from t_order a
		left join t_order_handler h on h.ORDER_NO = a.ORDER_NO
		where a.DELETE_FLAG = 0
		<if test="param.orderNo != null and param.orderNo.trim() != ''">
			and a.ORDER_NO = #{param.orderNo}
		</if>
		<if test="param.startDate != null and param.startDate.trim() != '' and param.endDate != null and param.endDate.trim() != ''">
			and a.CREATE_TIME <![CDATA[ >= ]]>  concat(#{param.startDate}, ' 00:00:00') and a.CREATE_TIME <![CDATA[ <= ]]> concat(#{param.endDate}, ' 23:59:59')
		</if>
		<if test="param.createName != null and param.createName.trim() != ''">
			and a.CREATE_NAME like concat('%',replace(replace(#{param.createName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.customerName != null and param.customerName.trim() != ''">
			and a.CUSTOMER_NAME = #{param.customerName}
		</if>
		<if test="param.deptName != null and param.deptName.trim() != ''">
			and a.DEPT_NAME = #{param.deptName}
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and a.DEPT_NO like concat('%',replace(replace(#{param.deptNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.orderStatus != null">
			and a.ORDER_STATUS = #{param.orderStatus}
		</if>
		<if test="param.level != null and param.level.trim() != ''">
			and a.LEVEL = #{param.level}
		</if>
		<if test="param.authSql != null and param.authSql.trim() != ''">
			${param.authSql}
		</if>
		GROUP BY a.ID
		ORDER BY a.CREATE_TIME DESC
	</select>

	<select id="getOrderDetailById" resultType="com.yifu.cloud.plus.v1.yifu.order.vo.OrderDetailVO">
		select
			  t.*
		from t_order t
		where t.ID = #{id}
	</select>

	<select id="getOrderReplyPageList" resultType="com.yifu.cloud.plus.v1.yifu.order.vo.OrderReplyListVO">
		select
		    t.ID as id,
			t.ORDER_NO as orderNo,
			t.CREATE_NAME as createName,
			t.CREATE_TIME as createTime,
			t.REPLY_CONTENT as replyContent
		from t_order_reply t
		where t.DELETE_FLAG = 0
		and t.ORDER_NO = #{orderNo}
		ORDER BY t.CREATE_TIME DESC
	</select>

</mapper>