ration-old-record-mapper.xml
5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?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 tongxiaochuan -->
<mapper namespace="com.cjs.cms.dao.ration.RationOldRecordDao">
<sql id="ration_old_record_field">
id, ration_old_config_id, ration_old_quality_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, remark, cost_price_status, create_at, create_by
</sql>
<sql id="searchCondition">
where 1 = 1
<if test="otcName != null and otcName != ''">
and b.otc_name = #{otcName}
</if>
<if test="otcCode!=null and otcCode !=''">
and b.otc_code = #{otcCode}
</if>
<if test="userId!=null and userId !=''">
and a.user_id = #{userId}
</if>
<if test="sellUserId != null and sellUserId != ''">
and a.sell_user_id = #{sellUserId}
</if>
<if test="buyUserId != null and buyUserId != ''">
and a.buy_user_id = #{buyUserId}
</if>
<if test="rationStatus != null and rationStatus != ''">
and a.ration_status = #{rationStatus}
</if>
<if test="startDate != null and startDate != ''">
<![CDATA[ and a.create_at >= #{startDate}]]>
</if>
<if test="endDate != null and endDate != ''">
<![CDATA[ and a.create_at <= #{endDate}]]>
</if>
</sql>
<!-- 查询在托管分配 -->
<select id="search" parameterType="map" resultType="map">
select a.apply_no, b.otc_code, b.otc_name, a.sell_user_id, a.buy_user_id, a.stock_amount, a.remark,
a.fund, a.ration_status, a.registration, a.create_by, DATE_FORMAT(a.create_at,'%Y-%m-%d') create_at
from ration_old_record a
left join ration_old_config b on a.ration_old_config_id = b.id
<include refid="searchCondition" />
<include refid="common.pageLimit" />
</select>
<select id="searchTotal" parameterType="map" resultType="int">
select count(1)
from ration_old_record a
left join ration_old_config b on a.ration_old_config_id=b.id
<include refid="searchCondition" />
</select>
<select id="searchFooter" parameterType="map" resultType="map">
select sum(a.stock_amount) stock_amount, sum(a.fund) fund
from ration_old_record a
left join ration_old_config b on a.ration_old_config_id=b.id
<include refid="searchCondition" />
</select>
<insert id="insert" parameterType="RationOldRecordInfo" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
insert ration_old_record(ration_old_config_id, ration_old_quality_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, remark, cost_price_status, create_at, create_by)
values(#{rationOldConfigId}, #{rationOldQualityId}, #{sellUserId}, #{sellOtcAccount},
#{buyUserId}, #{buyOtcAccount}, #{applyNo}, #{preInStatus}, #{approvalCount}, #{fund}, #{stockAmount},
#{registration}, #{rationStatus}, #{remark}, '0', CURRENT_TIMESTAMP, #{createBy})
</insert>
<update id="updateById" parameterType="RationOldRecordInfo">
update ration_old_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="RationOldRecordInfo">
update ration_old_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(1)
from ration_old_record
where ration_old_config_id = #{rationOldConfigId}
<if test="rationStatus != null and rationStatus != ''">
and ration_status = #{rationStatus}
</if>
</select>
<!-- 查询导出配售记录 -->
<select id="queryRecord" resultType="map" parameterType="map">
select apply_no,buy_user_id,stock_amount
from ration_old_record
where ration_old_config_id = #{rationOldConfigId}
and pre_in_status = #{preInStatus}
and registration = #{registration}
and ration_status = #{rationStatus}
</select>
<!-- 导出状态更新 -->
<update id="updateExport" parameterType="map">
update ration_old_record set registration = 1, export_at = CURRENT_TIMESTAMP
where ration_old_config_id = #{rationOldConfigId}
and pre_in_status = #{preInStatus}
and registration = #{registration}
and ration_status = #{rationStatus}
</update>
<select id="queryReordByCondition" resultType="RationOldRecordInfo">
select <include refid="ration_old_record_field" />
from ration_old_record
where buy_user_id = #{buyUserId} and ration_old_config_id = #{rationOldConfigId}
</select>
<!-- 查询指定用户、指定藏品获得的配售数量 -->
<select id="queryStockAmount" resultType="int">
select sum(stock_amount)
from ration_old_record
where ration_old_config_id = #{rationOldConfigId} and buy_user_id = #{buyUserId}
group by buy_user_id;
</select>
<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_old_record t
inner join ration_old_config r
on t.ration_old_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_old_config_id = #{rationOldConfigId}
</select>
<update id="updateCostPriceStatus" parameterType="int">
update ration_old_record set cost_price_status = '1'
where id = #{id} and cost_price_status = '0'
</update>
</mapper>