<?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.qunzhixinxi.hnqz.admin.mapper.SysDeptSubMapper">

	<resultMap id="sysDeptSubMap" type="com.qunzhixinxi.hnqz.admin.entity.SysDeptSub">
		<id property="deptId" column="dept_id"/>
		<result property="appId" column="app_id"/>
		<result property="appSecret" column="app_secret"/>
		<result property="rsaPublicKey" column="rsa_public_key"/>
		<result property="queryUrl" column="query_url"/>
		<result property="subjectName" column="subject_name"/>
		<result property="subjectType" column="subject_type"/>
		<result property="limitAmount" column="limit_amount"/>
		<result property="enableFlag" column="enable_flag"/>
	</resultMap>

	<select id="getSettleAmountMonitor" resultType="com.qunzhixinxi.hnqz.admin.entity.output.SettleAmountMonitorOutput">
		SELECT
			t.id_card_number,
			sum(t.settle_amount) AS totalAmount
		FROM wm_score_package_settle_note t
		WHERE t.sub_type = #{query.subType,jdbcType=VARCHAR}
		AND t.create_time &gt; #{query.startTime,jdbcType=TIMESTAMP}
		AND t.create_time &lt; #{query.endTime,jdbcType=TIMESTAMP}
		AND t.id_card_number IN
		<foreach item="item" index="index" collection="query.idCard" open="(" separator="," close=")">
			#{item}
		</foreach>
		<if test="query.ids != null and query.ids.size()>0">
			AND t.id NOT IN
			<foreach item="item" index="index" collection="query.ids" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		GROUP BY t.id_card_number
	</select>

	<select id="getDeptAmountMonitor" resultType="com.qunzhixinxi.hnqz.admin.entity.output.SettleAmountMonitorOutput">
		SELECT
		t.user_id,
		sum(t.settle_amount) AS totalAmount
		FROM wm_score_package_settle_note t
		WHERE t.sub_type = #{query.subType,jdbcType=VARCHAR}
		AND t.create_time &gt; #{query.startTime,jdbcType=TIMESTAMP}
		AND t.create_time &lt; #{query.endTime,jdbcType=TIMESTAMP}
		AND t.user_id IN
		<foreach item="item" index="index" collection="query.userIds" open="(" separator="," close=")">
			#{item}
		</foreach>
		<if test="query.ids != null and query.ids.size()>0">
			AND t.id NOT IN
			<foreach item="item" index="index" collection="query.ids" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		GROUP BY t.user_id
	</select>
</mapper>
