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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?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="cn.wisenergy.mapper.AntiFakeMapper">
<resultMap id="antiMap" type="cn.wisenergy.model.app.AntiFake">
<id column="id" property="id"/>
<result column="product_no" property="productNo"/>
<result column="security_code" property="securityCode"/>
<result column="batch_number" property="batchNumber"/>
<result column="sha_value" property="shaValue"/>
<result column="produce_time" property="produceTime"/>
<result column="scan_time" property="scanTime"/>
<result column="status" property="status"/>
<result column="use_status" property="useStatus"/>
<result column="scan_number" property="scanNumber"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<sql id="table">
anti_fake
</sql>
<sql id="cols_all">
id,
<include refid="cols_exclude_id"/>
</sql>
<sql id="cols_exclude_id">
product_no,security_code,batch_number,sha_value,produce_time,scan_time,status,use_status,scan_number,create_time,update_time
</sql>
<sql id="vals">
#{productNo},#{securityCode},#{batchNumber},#{shaValue},#{produceTime},#{scanTime},#{status},#{useStatus},#{scanNumber},now(),now()
</sql>
<sql id="createsVal">
#{i.productNo},#{i.securityCode},#{i.batchNumber},#{i.shaValue},#{i.produceTime},#{i.scanTime},#{i.status},#{i.useStatus},
#{i.scanNumber},now(),now()
</sql>
<sql id="updateCondition">
<if test="productNo != null">product_no = #{productNo},</if>
<if test="securityCode != null">security_code = #{securityCode},</if>
<if test="batchNumber != null">batch_number = #{batchNumber},</if>
<if test="shaValue != null">sha_value = #{shaValue},</if>
<if test="produceTime != null">produce_time = #{produceTime},</if>
<if test="scanTime != null">scan_time = #{scanTime},</if>
<if test="status != null">status = #{status},</if>
<if test="useStatus != null">use_status = #{useStatus},</if>
<if test="scanNumber != null">scan_number = #{scanNumber},</if>
update_time =now()
</sql>
<sql id="criteria">
<if test="id != null">id = #{id}</if>
<if test="productNo != null">and product_no = #{productNo}</if>
<if test="securityCode != null">and security_code = #{securityCode}</if>
<if test="batchNumber != null">and batch_number = #{batchNumber}</if>
<if test="shaValue != null">and sha_value = #{shaValue}</if>
<if test="produceTime != null">and produce_time = #{produceTime}</if>
<if test="scanTime != null">and scan_time = #{scanTime}</if>
<if test="status != null">and status = #{status}</if>
<if test="useStatus != null">and use_status = #{useStatus}</if>
<if test="scaNumber != null">and sca_number = #{scaNumber}</if>
<if test="createTime != null">and create_time >= #{createTime}</if>
<if test="updateTime != null">and #{updateTime} >= update_time</if>
</sql>
<insert id="add" parameterType="cn.wisenergy.model.app.AntiFake" keyProperty="id" useGeneratedKeys="true">
insert into
<include refid="table"/>
(<include refid="cols_exclude_id"/>)
value(
<include refid="vals"/>
)
</insert>
<update id="edit" parameterType="cn.wisenergy.model.app.AntiFake">
UPDATE
<include refid="table"/>
<set>
<include refid="updateCondition"/>
</set>
<where>
id = #{id}
</where>
</update>
<update id="updateUseStatus">
UPDATE
<include refid="table"/>
<set>
use_status=1
</set>
<where>
use_status=1
and batch_number=#{batchNumber}
</where>
</update>
<select id="getByBestBigNumber" resultType="java.lang.String">
select MAX(batch_number)
from
<include refid="table"/>
</select>
<!-- 批量创建接口 -->
<insert id="creates" parameterType="list">
INSERT INTO
<include refid="table"/>
(<include refid="cols_exclude_id"/>)
VALUES
<foreach collection="list" item="i" index="index" separator=",">
(<include refid="createsVal"/>)
</foreach>
</insert>
<select id="getByProductNo" resultMap="antiMap">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
product_no=#{productNo}
</where>
</select>
<select id="count" resultType="java.lang.Integer">
select count(1)
from
<include refid="table"/>
<where>
1=1
<if test="useStatus != null">
and use_status=#{useStatus}
</if>
</where>
</select>
<select id="getList" resultMap="antiMap">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
1=1
<if test="useStatus != null">
and use_status=#{useStatus}
</if>
order by create_time desc
limit #{startNum},#{endNum}
</where>
</select>
<select id="getProductNos" resultMap="antiMap">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
use_status=0
and id IN
<foreach collection="list" index="index" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</where>
</select>
<select id="getByShaValue" resultMap="antiMap">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
sha_value=#{shaValue}
</where>
</select>
<select id="getBatchNumber" resultMap="antiMap">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
use_status=0
and batch_number=#{batchNumber}
</where>
</select>
</mapper>