gdg
2020-12-01 7f01ee9b40b5ee18f53caed2132bbe6150975b3f
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<?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.nanometer.smartlab.dao.SysReagentDao">
  <resultMap id="SysReagent" type="com.nanometer.smartlab.entity.SysReagent">
    <id property="id" column="id"/>
    <result property="name" column="name"></result>
    <result property="cas" column="cas"></result>
    <result property="reagentType" column="reagent_type"></result>
    <result property="reagentCharacter" column="reagent_character"></result>
    <result property="supplierId" column="supplier_id"></result>
    <result property="reagentFormat" column="reagent_format"></result>
    <result property="mainMetering" column="main_metering"></result>
    <result property="reagentUnit" column="reagent_unit"></result>
    <result property="price" column="price"></result>
    <result property="perBox" column="per_box"></result>
    <result property="memo" column="memo"></result>
    <result property="validFlag" column="valid_flag" typeHandler="com.nanometer.smartlab.entity.handler.ValidFlagHandler"></result>
    <result property="createTime" column="create_time"></result>
    <result property="updateTime" column="update_time"></result>
    <result property="supplierName" column="supplierName"></result>
    <result property="deadline" column="deadline"></result>
    <result property="reserve" column="reserve"></result>
    <result property="productSn" column="product_sn"></result>
    <result property="dangerousFlag" column="dangerous_flag" typeHandler="com.nanometer.smartlab.entity.handler.DangerousFlagHandler"></result>
    <result property="controlProducts" column="control_products"></result>
    <result property="controlProductsName" column="control_products_name"></result>
    <result property="productHome" column="product_home"></result>
    <result property="productHomeName" column="product_home_name"></result>
    <result property="type" column="type"></result>
    <result property="unitName" column="unitName"></result>
    <result property="formatName" column="formatName"></result>
  </resultMap>
 
  <sql id="queryWhereSql">
    <if test="name != null and name != ''">
      and sr.name like #{name}
    </if>
    <if test="cas != null and cas != ''">
      and sr.cas like #{cas}
    </if>
    <if test="supplierId != null and supplierId != ''">
      and sr.supplier_id = #{supplierId}
    </if>
    <if test="editId != null and editId != ''">
      and sr.id != #{editId}
    </if>
    <if test="deadline != null and deadline != ''">
      and sr.name = #{deadline}
    </if>
    <if test="productSn != null and productSn != ''">
      and sr.product_sn like #{productSn}
    </if>
    <if test="type != null ">
      and sr.type = #{type}
    </if>
  </sql>
<select id="query" resultMap="SysReagent">
    select a.name,a.id,cas,main_metering,reagent_unit,reagent_format,product_home,b.meta_value unitName,c.meta_value formatName,d.meta_value product_home_name,a.price from sys_reagent a
left join base_meta b on b.id=a.reagent_unit
left join base_meta c on c.id=a.reagent_format
left join base_meta d on d.id=a.product_home
where a.valid_flag = 1
</select>
  <select id="getSysReagent" parameterType="java.lang.String"  resultMap="SysReagent" >
    select * from sys_reagent
    where id = #{id} and valid_flag = 1
  </select>
 
  <select id="getSysReagentDetail" parameterType="java.lang.String" resultType="java.util.Map">
    select sr.name ,sr.main_metering,sr.memo  memo,sr.product_sn productCode,bm.meta_value reagentFormat  ,sm.meta_value controlProducts,am.meta_value unit
        from sys_reagent sr
    left join base_meta  bm on bm.id = sr.reagent_format
        LEFT JOIN base_meta sm  on sr.control_products = sm.id
        LEFT JOIN base_meta am on sr.reagent_unit = am.id
    where sr.id = #{id} and sr.valid_flag = 1
  </select>
 
  <select id="getSysReagentList" parameterType="java.util.Map" resultMap="SysReagent">
    select sr.*, ss.meta_value as product_home_name, ifnull(w.reserve,0)  as reserve, bm.meta_value as control_products_name,supplier.name as supplierName,f.id favor,f.create_time favortime
    from sys_reagent as sr
    left join base_meta as ss on sr.product_home = ss.id
    left join base_meta bm    on bm.id = sr.control_products
    left join (select reagent_id, sum(reserve) reserve from ope_warehouse_reserve where valid_flag = 1 group by reagent_id) w on w.reagent_id = sr.id
 
    left join sys_supplier supplier on supplier.id = sr.supplier_id
    LEFT JOIN favor f on f.reagent_id = sr.id AND f.user_id = #{user}
    where sr.valid_flag = 1
    <include refid="queryWhereSql"/>
    <if test="favor != null and favor != '' ">
      and f.id is not null
    </if>
    order by favortime desc,price,LENGTH(sr.name),sr.name ASC
    <if test="first != null and pageSize != null">
      limit #{first}, #{pageSize}
    </if>
  </select>
 
  <select id="reagentList" parameterType="java.util.Map" resultType="int">
    select sr.*, ss.meta_value as product_home_name, bm.meta_value as control_products_name,supplier.name as supplierName,f.id favor,f.create_time favortime
    from sys_reagent as sr
    left join base_meta as ss on sr.product_home = ss.id
    left join base_meta bm    on bm.id = sr.control_products
    left join sys_supplier supplier on supplier.id = sr.supplier_id
    LEFT JOIN favor f on f.reagent_id = sr.id AND f.user_id = #{user}
    where sr.valid_flag = 1
    <if test="cas != null and cas != ''">
      and sr.cas = #{cas}
    </if>
    <if test="supplierId != null and supplierId != ''">
      and sr.supplier_id = #{supplierId}
    </if>
    <if test="name != null and name != ''">
      and sr.name like concat("%", #{name} ,"%")
    </if>
    <if test="productSn != null and productSn != ''">
      and sr.product_sn = #{productSn}
    </if>
    ORDER BY sr.create_time desc
    <if test="first != null and pageSize != null">
      limit #{first}, #{pageSize}
    </if>
  </select>
 
 
  <select id="favorList" parameterType="java.util.Map" resultMap="SysReagent">
    select sr.*, ss.meta_value as product_home_name, bm.meta_value as control_products_name,supplier.name as supplierName,f.id favor,f.create_time favortime
    from sys_reagent as sr
    left join base_meta as ss on sr.product_home = ss.id
    left join base_meta bm    on bm.id = sr.control_products
    left join sys_supplier supplier on supplier.id = sr.supplier_id
    LEFT JOIN favor f on f.reagent_id = sr.id AND f.user_id = #{user}
    where sr.valid_flag = 1
    <choose>
      <when test="favorFlag != ''">
        and f.id is not null
      </when>
      <otherwise>
        and f.id is  null
      </otherwise>
    </choose>
    <if test="cas != null and cas != ''">
      and sr.cas = #{cas}
    </if>
    <if test="supplierId != null and supplierId != ''">
      and sr.supplier_id = #{supplierId}
    </if>
    <if test="name != null and name != ''">
      and sr.name like concat("%", #{name} ,"%")
    </if>
    <if test="productSn != null and productSn != ''">
      and sr.product_sn = #{productSn}
    </if>
    <choose>
      <when test="favorFlag != ''">
        ORDER BY  favortime desc
      </when>
      <otherwise>
        ORDER BY  sr.create_time desc
      </otherwise>
    </choose>
    <if test="first != null and pageSize != null">
      limit #{first}, #{pageSize}
    </if>
  </select>
 
  <select id="favorCount" parameterType="java.util.Map" resultType="int">
    select count(1)
    from sys_reagent as sr
    left join base_meta as ss on sr.product_home = ss.id
    left join base_meta bm    on bm.id = sr.control_products
    left join sys_supplier supplier on supplier.id = sr.supplier_id
    LEFT JOIN favor f on f.reagent_id = sr.id AND f.user_id = #{user}
    where sr.valid_flag = 1
    <choose>
      <when test="favorFlag != ''">
       and f.id is not null
      </when>
      <otherwise>
       and f.id is  null
      </otherwise>
    </choose>
    <if test="cas != null and cas != ''">
      and sr.cas = #{cas}
    </if>
    <if test="supplierId != null and supplierId != ''">
      and sr.supplier_id = #{supplierId}
    </if>
    <if test="name != null and name != ''">
      and sr.name like concat("%", #{name} ,"%")
    </if>
    <if test="productSn != null and productSn != ''">
      and sr.product_sn = #{productSn}
    </if>
  </select>
 
  <select id="getSysReagentListNew" parameterType="java.util.Map" resultMap="SysReagent">
    select sr.*, ss.meta_value as product_home_name, ifnull(w.reserve,0)  as reserve, bm.meta_value as control_products_name,supplier.name as supplierName
    from sys_reagent as sr
 
    left join base_meta as ss on sr.product_home = ss.id
    left join base_meta bm    on bm.id = sr.control_products
    left join (select reagent_id, sum(reserve) reserve from ope_warehouse_reserve where valid_flag = 1 group by reagent_id) w on w.reagent_id = sr.id
 
    left join sys_supplier supplier on supplier.id = sr.supplier_id
    where sr.valid_flag = 1
    <if test="cas != null and cas != ''">
      and sr.cas = #{cas}
    </if>
    <if test="supplierId != null and supplierId != ''">
      and sr.supplier_id = #{supplierId}
    </if>
    <if test="name != null and name != ''">
      and sr.name like concat("%", #{name} ,"%")
    </if>
    <if test="type != null">
      and sr.type = #{type}
    </if>
    ORDER BY sr.create_time desc
    <if test="first != null and pageSize != null">
      limit #{first}, #{pageSize}
    </if>
  </select>
 
  <select id="getSysReagentTotalCount" parameterType="java.util.Map" resultType="int">
    select count(1)
    from sys_reagent as sr
    left join base_meta as ss on sr.product_home = ss.id
    left join base_meta bm    on bm.id = sr.control_products
    left join (select reagent_id, sum(reserve) reserve from ope_warehouse_reserve where valid_flag = 1 group by reagent_id) w on w.reagent_id = sr.id
 
    left join sys_supplier supplier on supplier.id = sr.supplier_id
    LEFT JOIN favor f on f.reagent_id = sr.id AND f.user_id = #{user}
    where sr.valid_flag = 1
    <include refid="queryWhereSql"/>
    <if test="favor != null and favor != '' ">
      and f.id is not null
    </if>
  </select>
 
  <select id="reagentCount" parameterType="java.util.Map" resultType="int">
    select count(1)
    from sys_reagent as sr
    left join base_meta as ss on sr.product_home = ss.id
    left join base_meta bm    on bm.id = sr.control_products
    left join (select reagent_id, sum(reserve) reserve from ope_warehouse_reserve where valid_flag = 1 group by reagent_id) w on w.reagent_id = sr.id
 
    left join sys_supplier supplier on supplier.id = sr.supplier_id
    LEFT JOIN favor f on f.reagent_id = sr.id AND f.user_id = #{user}
    where sr.valid_flag = 1
    <include refid="queryWhereSql"/>
    <if test="favor != null and favor != '' ">
      and f.id is not null
    </if>
  </select>
 
  <select id="getSysReagentTotalCountNew" parameterType="java.util.Map" resultType="int">
    select count(1)
    from sys_reagent as sr
    where sr.valid_flag = 1
    <if test="cas != null and cas != ''">
        and sr.cas = #{cas}
    </if>
    <if test="supplierId != null and supplierId != ''">
        and sr.supplier_id = #{supplierId}
    </if>
    <if test="name != null and name != ''">
        and sr.name like concat("%", #{name} ,"%")
    </if>
    <if test="type != null">
      and sr.type = #{type}
    </if>
 
  </select>
 
 
  <select id="getSysReagentByCas2" parameterType="com.nanometer.smartlab.entity.SysReagent" resultMap="SysReagent">
    select * From sys_reagent where type=0 and valid_flag = 1
    <if test="cas!=null and cas!=''">
      and cas = #{cas}
    </if>
    <if test="cas==null or cas==''">
      and cas is null
    </if>
  </select>
 
  <select id="getSysReagentByCas" parameterType="com.nanometer.smartlab.entity.SysReagent" resultMap="SysReagent">
    select * From sys_reagent where type=1 and  valid_flag = 1
    <if test="cas!=null and cas!=''">
      and cas = #{cas}
    </if>
    <if test="cas==null or cas==''">
      and cas is null
    </if>
    <if test="mainMetering!=null and mainMetering!=''">
      and main_metering = #{mainMetering}
    </if>
    <if test="mainMetering==null or mainMetering==0">
      and main_metering is null
    </if>
    <if test="reagentUnit!=null and reagentUnit!=''">
      and reagent_unit=#{reagentUnit}
    </if>
    <if test="reagentUnit==null or reagentUnit==''">
      and  reagent_unit is null
    </if>
    <if test="reagentFormat!=null and reagentFormat!=''">
      and reagent_format=#{reagentFormat}
    </if>
    <if test="reagentFormat==null or reagentFormat==''">
      and  reagent_format is null
    </if>
    <if test="productHome!=null and productHome!=''">
      and product_home = #{productHome}
    </if>
    <if test="productHome==null or productHome==''">
      and  product_home is null
    </if>
  </select>
 
 
 
  <insert id="insertSysReagent" parameterType="com.nanometer.smartlab.entity.SysReagent">
    insert into sys_reagent(id, name, cas, reagent_type, reagent_character, supplier_id, reagent_format, main_metering, reagent_unit, price, per_box, memo, valid_flag, create_time, update_time,deadline, product_sn, dangerous_flag,control_products,product_home,type)
    values (#{id}, #{name}, #{cas}, #{reagentType}, #{reagentCharacter}, #{supplierId}, #{reagentFormat}, #{mainMetering}, #{reagentUnit}, #{price}, #{perBox}, #{memo}, 1, now(), now(),#{deadline}, #{productSn}, #{dangerousFlag},#{controlProducts},#{productHome},#{type})
  </insert>
 
  <update id="updateSysReagent" parameterType="com.nanometer.smartlab.entity.SysReagent">
    update sys_reagent set name=#{name}, cas=#{cas}, reagent_type=#{reagentType}, reagent_character=#{reagentCharacter}, supplier_id=#{supplierId}, reagent_format=#{reagentFormat},
    main_metering=#{mainMetering}, reagent_unit=#{reagentUnit}, price=#{price}, per_box=#{perBox}, memo=#{memo}, update_time=now(), deadline = #{deadline}, product_sn = #{productSn}, dangerous_flag = #{dangerousFlag}, control_products = #{controlProducts}
    ,product_home=#{productHome},type=#{type}
    where id=#{id}
  </update>
 
  <update id="updateSysReagentForExport" parameterType="com.nanometer.smartlab.entity.SysReagent">
    update sys_reagent set name=#{name}, reagent_type=#{reagentType}, reagent_character=#{reagentCharacter}, supplier_id=#{supplierId}, reagent_format=#{reagentFormat},type=#{type},
    main_metering=#{mainMetering}, reagent_unit=#{reagentUnit}, price=#{price}, per_box=#{perBox}, memo=#{memo}, update_time=now(), deadline = #{deadline}, product_sn = #{productSn}, dangerous_flag = #{dangerousFlag}, control_products = #{controlProducts}
    where
    <if test="cas!=null and cas!=''">
      cas = #{cas}
    </if>
    <if test="cas==null or cas==''">
      cas is null
    </if>
    <if test="mainMetering!=null and mainMetering!=''">
      and main_metering = #{mainMetering}
    </if>
    <if test="mainMetering==null or mainMetering==0">
      and main_metering is null
    </if>
    <if test="reagentUnit!=null and reagentUnit!=''">
      and reagent_unit=#{reagentUnit}
    </if>
    <if test="reagentUnit==null or reagentUnit==''">
     and  reagent_unit is null
    </if>
    <if test="reagentFormat!=null and reagentFormat!=''">
      and reagent_format=#{reagentFormat}
    </if>
    <if test="reagentFormat==null or reagentFormat==''">
      and  reagent_format is null
    </if>
    <if test="productHome!=null and productHome!=''">
      and product_home = #{productHome}
    </if>
    <if test="productHome==null or productHome==''">
     and  product_home is null
    </if>
  </update>
 
  <update id="deleteSysReagent" parameterType="java.util.List">
    update sys_reagent set valid_flag=0, update_time=now()
    where id in
    <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
      #{item}
    </foreach>
  </update>
</mapper>