|  | @@ -17,10 +17,18 @@
 | 
	
		
			
				|  |  |  		<result column="subject_id_" property="subjectId" />
 | 
	
		
			
				|  |  |  		<result column="question_result_" property="questionResult" />
 | 
	
		
			
				|  |  |  		<result column="instruments_id_" property="instrumentsId" />
 | 
	
		
			
				|  |  | +		<result column="open_flag_" property="openFlag" />
 | 
	
		
			
				|  |  |  		<result column="create_time_" property="createTime" />
 | 
	
		
			
				|  |  |  		<result column="update_time_" property="updateTime" />
 | 
	
		
			
				|  |  |  	</resultMap>
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	<resultMap id="ReplacementInstrumentActivityStatDto" type="com.ym.mec.biz.dal.dto.ReplacementInstrumentActivityStatDto" extends="ReplacementInstrumentActivity">
 | 
	
		
			
				|  |  | +		<result property="subjectName" column="subject_name_"/>
 | 
	
		
			
				|  |  | +		<result property="studentName" column="student_name_"/>
 | 
	
		
			
				|  |  | +		<result property="brand" column="brand_"/>
 | 
	
		
			
				|  |  | +		<result property="specification" column="specification_"/>
 | 
	
		
			
				|  |  | +	</resultMap>
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	<!-- 根据主键查询一条记录 -->
 | 
	
		
			
				|  |  |  	<select id="get" resultMap="ReplacementInstrumentActivity" >
 | 
	
		
			
				|  |  |  		SELECT * FROM replacement_instrument_activity WHERE id_ = #{id} 
 | 
	
	
		
			
				|  | @@ -43,6 +51,9 @@
 | 
	
		
			
				|  |  |  		<if test="subjectId != null">
 | 
	
		
			
				|  |  |  		subject_id_ = #{subjectId},
 | 
	
		
			
				|  |  |  		</if>
 | 
	
		
			
				|  |  | +		<if test="openFlag != null">
 | 
	
		
			
				|  |  | +		open_flag_ = #{openFlag},
 | 
	
		
			
				|  |  | +		</if>
 | 
	
		
			
				|  |  |  		<if test="userId != null">
 | 
	
		
			
				|  |  |  		user_id_ = #{userId},
 | 
	
		
			
				|  |  |  		</if>
 | 
	
	
		
			
				|  | @@ -91,6 +102,66 @@
 | 
	
		
			
				|  |  |  		SELECT * FROM replacement_instrument_activity WHERE user_id_ = #{userId} LIMIT 1
 | 
	
		
			
				|  |  |  	</select>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	<sql id="queryReplacementsCondition">
 | 
	
		
			
				|  |  | +		<where>
 | 
	
		
			
				|  |  | +			<if test="cooperationOrganId!=null">
 | 
	
		
			
				|  |  | +				AND ria.cooperation_organ_id_ = #{cooperationOrganId}
 | 
	
		
			
				|  |  | +			</if>
 | 
	
		
			
				|  |  | +			<if test="subjectId!=null">
 | 
	
		
			
				|  |  | +				AND ria.subject_id_ = #{subjectId}
 | 
	
		
			
				|  |  | +			</if>
 | 
	
		
			
				|  |  | +			<if test="brand!=null and brand!=''">
 | 
	
		
			
				|  |  | +				AND ri.brand_ = #{brand}
 | 
	
		
			
				|  |  | +			</if>
 | 
	
		
			
				|  |  | +			<if test="specification!=null and specification!=''">
 | 
	
		
			
				|  |  | +				AND ri.specification_ = #{specification}
 | 
	
		
			
				|  |  | +			</if>
 | 
	
		
			
				|  |  | +			<if test="search!=null and search!=''">
 | 
	
		
			
				|  |  | +				AND (ria.mobile_no_ LIKE CONCAT('%', #{search}, '%') OR stu.username_ LIKE CONCAT('%', #{search}, '%'))
 | 
	
		
			
				|  |  | +			</if>
 | 
	
		
			
				|  |  | +		</where>
 | 
	
		
			
				|  |  | +	</sql>
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	<select id="queryReplacements" resultMap="ReplacementInstrumentActivityStatDto">
 | 
	
		
			
				|  |  | +		SELECT
 | 
	
		
			
				|  |  | +			ria.subject_id_,
 | 
	
		
			
				|  |  | +			sub.name_ subject_name_,
 | 
	
		
			
				|  |  | +			stu.username_ student_name_,
 | 
	
		
			
				|  |  | +			ria.mobile_no_,
 | 
	
		
			
				|  |  | +			ri.brand_,
 | 
	
		
			
				|  |  | +			ri.specification_
 | 
	
		
			
				|  |  | +		FROM
 | 
	
		
			
				|  |  | +			replacement_instrument_activity ria
 | 
	
		
			
				|  |  | +			LEFT JOIN replacement_instrument ri ON ria.instruments_id_ = ri.id_
 | 
	
		
			
				|  |  | +			LEFT JOIN sys_user stu ON ria.user_id_ = stu.id_
 | 
	
		
			
				|  |  | +			LEFT JOIN `subject` sub ON ria.subject_id_ = sub.id_
 | 
	
		
			
				|  |  | +		<include refid="queryReplacementsCondition" />
 | 
	
		
			
				|  |  | +		ORDER BY ria.update_time_ DESC
 | 
	
		
			
				|  |  | +		<include refid="global.limit"></include>
 | 
	
		
			
				|  |  | +	</select>
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	<select id="countReplacements" resultType="int">
 | 
	
		
			
				|  |  | +		SELECT
 | 
	
		
			
				|  |  | +			COUNT(ria.id_)
 | 
	
		
			
				|  |  | +		FROM
 | 
	
		
			
				|  |  | +		replacement_instrument_activity ria
 | 
	
		
			
				|  |  | +		LEFT JOIN replacement_instrument ri ON ria.instruments_id_ = ri.id_
 | 
	
		
			
				|  |  | +		LEFT JOIN sys_user stu ON ria.user_id_ = stu.id_
 | 
	
		
			
				|  |  | +		LEFT JOIN `subject` sub ON ria.subject_id_ = sub.id_
 | 
	
		
			
				|  |  | +		<include refid="queryReplacementsCondition" />
 | 
	
		
			
				|  |  | +	</select>
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	<select id="countReplacementsInfo"
 | 
	
		
			
				|  |  | +			resultType="com.ym.mec.biz.dal.dto.ReplacementInstrumentActivityStatHead">
 | 
	
		
			
				|  |  | +		SELECT
 | 
	
		
			
				|  |  | +			COUNT(DISTINCT ria.user_id_) surveyNum,
 | 
	
		
			
				|  |  | +			COUNT(DISTINCT IF(ria.instruments_id_ IS NOT NULL, ria.user_id_, NULL)) replacementNum,
 | 
	
		
			
				|  |  | +			TRUNCATE(COUNT(IF(ria.instruments_id_ IS NOT NULL, ria.user_id_, NULL))/COUNT(DISTINCT ria.user_id_)*100, 2) replacementRate
 | 
	
		
			
				|  |  | +		FROM
 | 
	
		
			
				|  |  | +			replacement_instrument_activity ria
 | 
	
		
			
				|  |  | +		WHERE ria.cooperation_organ_id_ = #{cooperationOrganId}
 | 
	
		
			
				|  |  | +	</select>
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	<update id="openPay" parameterType="integer">
 | 
	
		
			
				|  |  |  		UPDATE replacement_instrument_activity SET open_flag_ = 1 WHERE cooperation_organ_id_ = #{cooperationOrganId} AND open_flag_ = 0
 | 
	
		
			
				|  |  |  	</update>
 |