<?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.goafanti.common.dao.AchievementOrderMapper" >
  <select id="selectAchievementOrderByUidAndAchievementId" resultMap="BaseResultMap" >
  	select 
    <include refid="Base_Column_List" />
    from achievement_order
   where 
   	uid = #{0} and achievement_id = #{1} and deleted_sign = 0
  </select>
  
   <select id="findAchievementOrderListByPage" parameterType="String" resultType="com.goafanti.achievement.bo.AchievementOrderListBo">
  	select 
  		ao.id, ao.serial_number as serialNumber, ao.achievement_id as achievementId,
  		ao.create_time as createTime,ao.status,
  		ao.payment_value as paymentValue, ao.payment_type as paymentType, ao.payment_id as paymentId,
  		ao.payment_time as paymentTime, a.name, a.serial_number as achievementSerialNumber,
  		a.deleted_sign as deletedSign, a.audit_status as auditStatus, a.bargaining_mode as bargainingMode,
  		a.transfer_price as transferPrice
  	from achievement_order ao
  	left join achievement a on a.id = ao.achievement_id
  	where ao.deleted_sign = 0 
  	and   a.deleted_sign = 0 
  	and   ao.uid = #{uid,jdbcType=VARCHAR}
  	<if test="status != null">
  		and ao.status = #{status,jdbcType=INTEGER}
  	</if>
  	order by ao.serial_number desc
  	<if test="page_sql!=null">
		${page_sql}
	</if>
  </select>
  
  <select id="findAchievementOrderCount" parameterType="String" resultType="java.lang.Integer">
  	select 
  		count(1)
  	from achievement_order ao
  	left join achievement a on a.id = ao.achievement_id
  	where ao.deleted_sign = 0 
  	and   a.deleted_sign 
  	and   ao.uid = #{uid,jdbcType=VARCHAR}
  	<if test="status != null">
  		and ao.status = #{status,jdbcType=INTEGER}
  	</if>
  </select>
  
  <select id="selectAchievementOrderByAchievementId" parameterType="java.lang.String" resultMap="BaseResultMap">
  	 select 
    <include refid="Base_Column_List" />
    from achievement_order
    where achievement_id = #{achievementId,jdbcType=VARCHAR}
  </select>
  
  
   <select id="findUserAchievementOrderListByPage" parameterType="String" resultType="com.goafanti.achievement.bo.UserAchievementOrderListBo">
  	select 
  		ao.id, ao.serial_number as serialNumber, ao.achievement_id as achievementId,
  		ao.create_time as createTime,ao.status,
  		ao.payment_value as paymentValue, ao.payment_type as paymentType, ao.payment_id as paymentId,
  		ao.payment_time as paymentTime, a.name, a.serial_number as achievementSerialNumber,
  		a.deleted_sign as deletedSign, a.audit_status as auditStatus, ui.username,
  		ao.uid, a.bargaining_mode as bargainingMode,
  		a.transfer_price as transferPrice
  	from achievement_order ao
  	left join achievement a on a.id = ao.achievement_id
  	left join user_identity ui on ui.uid = ao.uid
  	where ao.deleted_sign = 0 
  	and   a.deleted_sign = 0 
  	and  ui.username is not null
  	<if test="techBrokerId != null">
  		and a.tech_broker_id = #{techBrokerId,jdbcType=VARCHAR}
  	</if>
  	<if test="status != null">
  		and ao.status = #{status,jdbcType=INTEGER}
  	</if>
  	<if test="uid != null">
  		and ao.uid = #{uid,jdbcType=VARCHAR}
  	</if>
  	<if test="username != null">
  		and ui.username = #{username,jdbcType=VARCHAR}
  	</if>
  	order by ao.serial_number desc
  	<if test="page_sql!=null">
		${page_sql}
	</if>
  </select>
  
  <select id="findUserAchievementOrderCount" parameterType="String" resultType="java.lang.Integer">
  	select 
  		count(1)
  	from achievement_order ao
  	left join achievement a on a.id = ao.achievement_id
  	left join user_identity ui on ui.uid = ao.uid
  	where ao.deleted_sign = 0 
  	and   a.deleted_sign = 0 
  	and  ui.username is not null
  	<if test="techBrokerId != null">
  		and a.tech_broker_id = #{techBrokerId,jdbcType=VARCHAR}
  	</if>
  	<if test="status != null">
  		and ao.status = #{status,jdbcType=INTEGER}
  	</if>
  	<if test="uid != null">
  		and ao.uid = #{uid,jdbcType=VARCHAR}
  	</if>
  	<if test="username != null">
  		and ui.username = #{username,jdbcType=VARCHAR}
  	</if>
  </select>
  
  
  <select id="findOrgAchievementOrderListByPage" parameterType="String" resultType="com.goafanti.achievement.bo.OrgAchievementOrderListBo">
  	select 
  		ao.id, ao.serial_number as serialNumber, ao.achievement_id as achievementId,
  		ao.create_time as createTime,ao.status,
  		ao.payment_value as paymentValue, ao.payment_type as paymentType, ao.payment_id as paymentId,
  		ao.payment_time as paymentTime,  a.name, a.serial_number as achievementSerialNumber,
  		a.deleted_sign as deletedSign, a.audit_status as auditStatus, ao.uid,
  		oi.unit_name as unitName, a.bargaining_mode as bargainingMode,
  		a.transfer_price as transferPrice
  	from achievement_order ao
  	left join achievement a on a.id = ao.achievement_id
  	left join organization_identity oi on oi.uid = ao.uid
  	where ao.deleted_sign = 0 
  	and   a.deleted_sign = 0 
  	and  oi.unit_name is not null
  	<if test="techBrokerId != null">
  		and a.tech_broker_id = #{techBrokerId,jdbcType=VARCHAR}
  	</if>
  	<if test="status != null">
  		and ao.status = #{status,jdbcType=INTEGER}
  	</if>
  	<if test="uid != null">
  		and ao.uid = #{uid,jdbcType=VARCHAR}
  	</if>
  	<if test="unitName != null">
  		and oi.unit_name = #{unitName,jdbcType=VARCHAR}
  	</if>
  	order by ao.serial_number desc
  	<if test="page_sql!=null">
		${page_sql}
	</if>
  </select>
  
  <select id="findOrgAchievementOrderCount" parameterType="String" resultType="java.lang.Integer">
  	select 
  		count(1)
  	from achievement_order ao
  	left join achievement a on a.id = ao.achievement_id
  	left join organization_identity oi on oi.uid = ao.uid
  	where ao.deleted_sign = 0 
  	and   a.deleted_sign = 0 
  	and  oi.unit_name is not null
  	<if test="techBrokerId != null">
  		and a.tech_broker_id = #{techBrokerId,jdbcType=VARCHAR}
  	</if>
  	<if test="status != null">
  		and ao.status = #{status,jdbcType=INTEGER}
  	</if>
  	<if test="uid != null">
  		and ao.uid = #{uid,jdbcType=VARCHAR}
  	</if>
  	<if test="unitName != null">
  		and oi.unit_name = #{unitName,jdbcType=VARCHAR}
  	</if>
  </select>
</mapper>