ration-new-record-mapper.xml 5.15 KB
<?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">

<!-- 新品配售记录 @author 仝玉甫 -->
<mapper namespace="com.cjs.cms.dao.ration.RationNewRecordDao">

	<insert id="save" parameterType="RationNewRecordInfo" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
		insert into ration_new_record 
			(ration_new_config_id, ration_new_user_id, sell_user_id, sell_otc_account, buy_user_id, 
			buy_otc_account, apply_no, pre_in_status, approval_count, fund, stock_amount, 
			registration, ration_status, cost_price_status, remark, create_at, create_by)
		values (#{rationNewConfigId}, #{rationNewUserId}, #{sellUserId}, #{sellOtcAccount}, #{buyUserId}, 
			#{buyOtcAccount}, #{applyNo}, #{preInStatus}, #{approvalAcount}, #{fund}, #{stockAmount}, 
			#{registration}, #{rationStatus}, '0', #{remark}, now(), #{createBy})
	</insert>
	
	<update id="updateById" parameterType="RationNewRecordInfo">
		update ration_new_record set 
		<if test="preInStatus != null and preInStatus != ''"> pre_in_status = #{preInStatus}, </if>
		<if test="rationStatus != null and rationStatus != ''"> ration_status = #{rationStatus}, </if>
		<if test="remark != null and remark != ''"> remark = #{remark}, </if>
		create_by = create_by
		where id = #{id}
	</update>
	
	<!-- 修改-->
	<update id="updateByApplyNo" parameterType="RationNewRecordInfo">
		update ration_new_record set 
		<if test="preInStatus != null and preInStatus != ''"> pre_in_status = #{preInStatus}, </if>
		<if test="rationStatus != null and rationStatus != ''"> ration_status = #{rationStatus}, </if>
		<if test="remark != null and remark != ''"> remark = #{remark}, </if>
		create_by = create_by
		where apply_no = #{applyNo}
	</update>
	
	<!-- 配售记录数量 -->
	<select id="queryRecordCount" resultType="int">
		select count(*)
		from ration_new_record
		where ration_new_config_id = #{rationNewConfigId}
		<if test="rationStatus != null and rationStatus != ''">
			and ration_status = #{rationStatus}
		</if>
	</select>
	
	<!-- 查询导出配售记录 -->
	<select id="queryRecord" resultType="map">
		select apply_no, buy_user_id, stock_amount 
		from ration_new_record
		where ration_new_config_id = #{rationNewConfigId}
			and pre_in_status = #{preInStatus} 
			and registration = #{registration} 
			and ration_status = #{rationStatus} 
	</select>
	
	<!-- 导出状态更新 -->
	<update id="updateExport" parameterType="map">
		update ration_new_record set registration = 1, export_at = CURRENT_TIMESTAMP  
		where ration_new_config_id = #{rationNewConfigId} 
			and pre_in_status = #{preInStatus} 
			and registration = #{registration} 
			and ration_status = #{rationStatus} 	
	</update>
	
	<!-- 配售详情查询 -->
	<select id="queryRationDetail" parameterType="map" resultType="map">
		select t.id,t.apply_no,r.otc_code,r.otc_name,t.sell_user_id,t.ration_status,
			t.buy_user_id,t.registration,t.approval_count,t.stock_amount,t.fund,t.create_at,t.create_by,t.remark 
			from ration_new_record t inner join ration_new_config r 
			on t.ration_new_config_id = r.id
			<include refid="queryCondition" />
			order by t.apply_no, t.id
			<include refid="common.pageLimit" />
	</select>
	
	<select id="queryRationDetailTotal" parameterType="map" resultType="int">
		select count(1) 
		from ration_new_record t 
		inner join ration_new_config r on t.ration_new_config_id = r.id 
		<include refid="queryCondition" />
	</select>
	
	<select id="queryRationDetailSum" parameterType="map" resultType="map">
		select '汇总' buy_user_id, sum(approval_count) approval_count, sum(fund) fund, sum(stock_amount) stock_amount 
		from ration_new_record t 
		inner join ration_new_config r on t.ration_new_config_id = r.id 
		<include refid="queryCondition" />
	</select>
	
	<sql id="queryCondition">
		where 1=1 
		<if test="otcCode != null and otcCode != ''">
			and r.otc_code = #{otcCode} 
		</if>
		<if test="otcName != null and otcName != ''">
			and r.otc_name = #{otcName} 
		</if>
		<if test="sellUserId != null and sellUserId != ''">
			and t.sell_user_id = #{sellUserId} 
		</if>
		<if test="buyUserId != null and buyUserId != ''">
			and t.buy_user_id = #{buyUserId} 
		</if>
		<if test="startDate != null and startDate != ''">
			<![CDATA[and t.create_at >= #{startDate} ]]>
		</if>
		<if test="endDate != null and endDate != ''">
			<![CDATA[and t.create_at <= #{endDate} ]]>
		</if>
		<if test="rationStatus != null and rationStatus != ''">
			and t.ration_status = #{rationStatus} 
		</if>
		<if test="applyNo != null and applyNo != ''">
			and t.apply_no = #{applyNo} 
		</if>
	</sql>
	
	<select id="queryForCostPrice" parameterType="int" resultType="map">
		select t.id,r.otc_code otcCode,r.price,t.buy_user_id userId,t.stock_amount stockAmount 
		from ration_new_record t 
		inner join ration_new_config r 
		on t.ration_new_config_id = r.id 
		where t.pre_in_status = '1' and t.registration = '1' and cost_price_status = '0' 
		and t.ration_status = '1' and t.ration_new_config_id = #{rationNewConfigId}
	</select>
	
	<update id="updateCostPriceStatus" parameterType="int">
		update ration_new_record set cost_price_status = '1' 
		where id = #{id} and cost_price_status = '0'
	</update>
</mapper>