gdg
2021-01-18 12714c71c7737e21c3268b44a39f8f02befc5cb5
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
package com.nanometer.smartlab.service;
 
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
 
import javax.annotation.Resource;
 
import com.nanometer.smartlab.dao.OpeApplyDao;
import com.nanometer.smartlab.entity.*;
import com.nanometer.smartlab.entity.enumtype.ValidFlag;
import com.nanometer.smartlab.exception.AlarmCode;
import com.nanometer.smartlab.exception.AlarmException;
import com.nanometer.smartlab.util.IDUtils;
 
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
 
import com.nanometer.smartlab.dao.BaseMetaDao;
import com.nanometer.smartlab.dao.OpeWarehouseReserveDao;
import com.nanometer.smartlab.entity.enumtype.ArrivalStatus;
import com.nanometer.smartlab.entity.enumtype.OperateStatus;
import com.nanometer.smartlab.entity.enumtype.StoreType;
import com.nanometer.smartlab.exception.BusinessException;
import com.nanometer.smartlab.exception.ExceptionEnumCode;
import com.nanometer.smartlab.util.MessageUtil;
 
/**
 * Created by maweiqing on 17/12/12.
 */
@Service("opeWarehouseReserveService")
public class OpeWarehouseReserveServiceImpl implements OpeWarehouseReserveService {
 
    private static Logger logger = Logger.getLogger(OpeWarehouseReserveService.class);
 
    @Resource(name = "opeWarehouseReserveDao")
    OpeWarehouseReserveDao opeWarehouseReserveDao;
 
    @Resource
    private OpeReagentStatusService opeReagentStatusService;
 
    @Resource
    private OpeUseFlowService opeUseFlowService;
    @Resource
    private OpeWarehouseReserveService opeWarehouseReserveService;
 
    @Resource(name="baseMetaDao")
    private BaseMetaDao baseMetaDao;
 
    @Resource(name="opeApplyDao")
    private OpeApplyDao opeApplyDao;
 
    @Transactional(propagation = Propagation.REQUIRED)
    public List<OpeWarehouseReserve> getOpeWarehouseReserveList(String reagentId, String supplierId, Integer first,
            Integer pageSize) {
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("reagentId", reagentId);
            params.put("supplierId", supplierId);
            params.put("first", first);
            params.put("pageSize", pageSize);
            return this.opeWarehouseReserveDao.getOpeWarehouseReserveList(params);
        } catch (DataAccessException e) {
            logger.error(e.getMessage(), e);
            throw new BusinessException(ExceptionEnumCode.DB_ERR,
                    MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e);
        }
    }
 
    @Transactional(propagation = Propagation.REQUIRED)
    public int getOpeWarehouseReserveTotalCount(String reagentId, String supplierId) {
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("reagentId", reagentId);
            params.put("supplierId", supplierId);
            return this.opeWarehouseReserveDao.getOpeWarehouseReserveTotalCount(params);
        } catch (DataAccessException e) {
            logger.error(e.getMessage(), e);
            throw new BusinessException(ExceptionEnumCode.DB_ERR,
                    MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e);
        }
    }
 
    @Transactional(propagation = Propagation.REQUIRED)
    public List<OpeWarehouseReserve> getOpeWarehouseReserveListByName(String reagentId, String supplierId, Integer first,
            Integer pageSize) {
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("reagentName", reagentId);
            params.put("supplierId", supplierId);
            params.put("first", first);
            params.put("pageSize", pageSize);
            return this.opeWarehouseReserveDao.getOpeWarehouseReserveList(params);
        } catch (DataAccessException e) {
            logger.error(e.getMessage(), e);
            throw new BusinessException(ExceptionEnumCode.DB_ERR,
                    MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e);
        }
    }
 
    @Transactional(propagation = Propagation.REQUIRED)
    public int getOpeWarehouseReserveTotalCountByName(String reagentId, String supplierId) {
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("reagentName", reagentId);
            params.put("supplierId", supplierId);
            return this.opeWarehouseReserveDao.getOpeWarehouseReserveTotalCount(params);
        } catch (DataAccessException e) {
            logger.error(e.getMessage(), e);
            throw new BusinessException(ExceptionEnumCode.DB_ERR,
                    MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e);
        }
    }
 
    @Transactional(propagation = Propagation.REQUIRED)
    public OpeWarehouseReserve getOpeWarehouseReserveBy(String reagentId, String articleNumber){
        OpeWarehouseReserve ope=new OpeWarehouseReserve();
        ope.setReagentId(reagentId);
        ope.setArticleNumber(articleNumber);
        return this.opeWarehouseReserveDao.getOpeWarehouseReserve(ope);
    }
 
    @Transactional(propagation = Propagation.REQUIRED)
    public OpeWarehouseReserve getOpeWarehouseReserve(String reagentId, String articleNumber) {
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("reagentId", reagentId);
            params.put("articleNumber", articleNumber);
            List<OpeWarehouseReserve> list = this.opeWarehouseReserveDao.getOpeWarehouseReserveList(params);
            if (list != null && list.size() > 0) {
                return list.get(0);
            }
 
            return null;
        } catch (DataAccessException e) {
            logger.error(e.getMessage(), e);
            throw new BusinessException(ExceptionEnumCode.DB_ERR,
                    MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e);
        }
    }
    @Transactional(propagation = Propagation.REQUIRED)
    public OpeWarehouseReserve getOpeWarehouseReserve2(String reagentId, String articleNumber,String warehouseId) {
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("reagentId", reagentId);
            params.put("articleNumber", articleNumber);
            params.put("warehouseId", warehouseId);
            List<OpeWarehouseReserve> list = this.opeWarehouseReserveDao.getOpeWarehouseReserveList(params);
            if (list != null && list.size() > 0) {
                return list.get(0);
            }
 
            return null;
        } catch (DataAccessException e) {
            logger.error(e.getMessage(), e);
            throw new BusinessException(ExceptionEnumCode.DB_ERR,
                    MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e);
        }
    }
    @Transactional(propagation = Propagation.REQUIRED)
    public OpeWarehouseReserve insertOpeWarehouseReserve(OpeWarehouseReserve opeWarehouseReserve) {
        try {
            if (opeWarehouseReserve.getId() == null) {
                opeWarehouseReserve.setId(IDUtils.uuid());
            }
            this.opeWarehouseReserveDao.insertOpeWarehouseReserve(opeWarehouseReserve);
            return opeWarehouseReserve;
        } catch (DuplicateKeyException ex) {
            logger.warn(ex.getMessage(), ex);
            throw new AlarmException(AlarmCode.DATA_DUPLICATE,
                    MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode()));
        } catch (DataIntegrityViolationException ex) {
            logger.warn(ex.getMessage(), ex);
            throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode()));
        } catch (DataAccessException ex) {
            logger.error(ex.getMessage(), ex);
            throw new BusinessException(ExceptionEnumCode.DB_ERR,
                    MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex);
        }
    }
 
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean updateOpeWarehouseReserve(OpeWarehouseReserve opeWarehouseReserve) {
        try {
            int row = this.opeWarehouseReserveDao.updateOpeWarehouseReserve(opeWarehouseReserve);
 
            return row != 0;
        } catch (DuplicateKeyException ex) {
            logger.warn(ex.getMessage(), ex);
            throw new AlarmException(AlarmCode.DATA_DUPLICATE,
                    MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode()));
        } catch (DataIntegrityViolationException ex) {
            logger.warn(ex.getMessage(), ex);
            throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode()));
        } catch (DataAccessException ex) {
            logger.error(ex.getMessage(), ex);
            throw new BusinessException(ExceptionEnumCode.DB_ERR,
                    MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex);
        }
    }
 
    @Transactional(propagation = Propagation.REQUIRED)
    public void claimForPerson(List<OpeApplyReserve> selectedListForPerson,String userId,String projectNum){
        try{
            for(OpeApplyReserve app:selectedListForPerson){
                List<String> reagentCodes = app.getReagentCode();
                if (reagentCodes != null && reagentCodes.size() > 0) {
                    List<OpeReagentStatus> ss=new ArrayList<>();
                    for (String opeReagentStatusId : reagentCodes) {
                        OpeReagentStatus opeReagentStatus = this.opeReagentStatusService.getOpeReagentStatus(opeReagentStatusId);
                        opeReagentStatus.setUserId(userId);
                        opeReagentStatus.setProjectNum(projectNum);
                        //boolean flag = this.opeReagentStatusService.updateReagentStatus(opeReagentStatus);
                        this.opeReagentStatusService.updateReagentStatus(opeReagentStatus);
                        ss.add(opeReagentStatus);
                    }
                    /*HashSet<String> set=new HashSet<>();//存放批号
                    for(int i=0;i<ss.size();i++){
                        set.add(ss.get(i).getArticleNumber());
                    }
                    for(String string: set){
                        int count=0;//相同批号出现的次数
                        String reid="";
                        for(int j=0;j<ss.size();j++){
                            if(string.equals(ss.get(j).getArticleNumber())){
                                count++;
                                reid=ss.get(j).getReagentId();
                            }
                        }
                        OpeWarehouseReserve wa=opeWarehouseReserveService.getOpeWarehouseReserveBy(reid,string);
                        System.out.println("原库存="+wa.getReserve());
                        System.out.println("领用数量="+count);
                        wa.setReserve(wa.getReserve()-count);
                        opeWarehouseReserveDao.updateOpeWarehouseReserve(wa);
                    }*/
                }
                //OpeWarehouseReserve wa=opeWarehouseReserveService.getOpeWarehouseReserveBy(app.getReagent().getId(),app.getArticleNumber());
                OpeApplyReserve re=new OpeApplyReserve();
                re.setUsed(app.getSelectNum()+app.getUsed());
                re.setId(app.getId());
                //System.out.println(wa.getReserve());
                //wa.setReserve(wa.getReserve()-app.getSelectNum());
                opeApplyDao.updateOpeApplyUsed(re);//修改已领数量
                //opeWarehouseReserveDao.updateOpeWarehouseReserve(wa);
            }
 
        } catch (DuplicateKeyException ex) {
            logger.warn(ex.getMessage(), ex);
            throw new AlarmException(AlarmCode.DATA_DUPLICATE,
                    MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode()));
        } catch (DataIntegrityViolationException ex) {
            logger.warn(ex.getMessage(), ex);
            throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode()));
        } catch (DataAccessException ex) {
            logger.error(ex.getMessage(), ex);
            throw new BusinessException(ExceptionEnumCode.DB_ERR,
                    MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex);
        }
    }
 
    // 仓库领用
    @Transactional(propagation = Propagation.REQUIRED)
    public void claim(List<OpeWarehouseReserve> selectedList, String userId,String projectNum) {
        try {
            for (OpeWarehouseReserve opeWarehouseReserve : selectedList) {
                List<String> reagentCodes = opeWarehouseReserve.getReagentCodes();
                if (reagentCodes != null && reagentCodes.size() > 0) {
                    for (String opeReagentStatusId : reagentCodes) {
                        OpeReagentStatus opeReagentStatus = this.opeReagentStatusService
                                .getOpeReagentStatus(opeReagentStatusId);
                        opeReagentStatus.setUserId(userId);
                        opeReagentStatus.setProjectNum(projectNum);
                        //boolean flag = this.opeReagentStatusService.updateReagentStatus(opeReagentStatus);
                        this.opeReagentStatusService.updateReagentStatus(opeReagentStatus);
                        //if (flag) {
                            //opeWarehouseReserve.setReserve(opeWarehouseReserve.getReserve() - 1);
                            //opeWarehouseReserve.setSelectNum(0);
                        //}
                    }
                }
                opeWarehouseReserve.setReserve(opeWarehouseReserve.getReserve()-opeWarehouseReserve.getSelectNum());
                opeWarehouseReserveDao.updateOpeWarehouseReserve(opeWarehouseReserve);
            }
        } catch (DuplicateKeyException ex) {
            logger.warn(ex.getMessage(), ex);
            throw new AlarmException(AlarmCode.DATA_DUPLICATE,
                    MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode()));
        } catch (DataIntegrityViolationException ex) {
            logger.warn(ex.getMessage(), ex);
            throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode()));
        } catch (DataAccessException ex) {
            logger.error(ex.getMessage(), ex);
            throw new BusinessException(ExceptionEnumCode.DB_ERR,
                    MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex);
        }
    }
 
    public void reagentDStore2(List<OpeApply> reagentDStoreList, String loginUserId){
        if (reagentDStoreList == null) {
            return;
        }
        OpeReagentStatus opeReagentStatus = null;
        BigInteger startReagentCode = null;
        BigInteger endReagentCode = null;
        String reagentCode = null;
        OpeWarehouseReserve opeWarehouseReserve = null;
        OpeUseFlow opeUseFlow = null;
        for (OpeApply opeApply : reagentDStoreList) {
            startReagentCode = new BigInteger(opeApply.getStartReagentCode());
            endReagentCode = new BigInteger(opeApply.getEndReagentCode());
 
            // 条形码可能以0开头,所以需要补0
            int len = opeApply.getStartReagentCode().length() - String.valueOf(startReagentCode).length();
            /*System.out.println("aaaaaaaaaa="+opeApply.getStartReagentCode());
            System.out.println("bbbbbbbbbb="+String.valueOf(startReagentCode));
            if(1==1){
                return;
            }*/
            String temp = "";
            for (int i = 0; i < len; i++) {
                temp += "0";
            }
            for (BigInteger i = startReagentCode; i.compareTo(endReagentCode) < 1; i = i.add(BigInteger.ONE)) {
                reagentCode = temp + String.valueOf(i);
                if (this.opeReagentStatusService.isOpeReagentStatusExist(reagentCode)) {//条码存在
                    //throw new BusinessException(ExceptionEnumCode.REAGENT_CODE_EXIST, "入库试剂:" + opeApply.getReagent().getName() + "的试剂条形码[" + reagentCode + "]已存在。");
                    // 试剂最新状态update
                    opeReagentStatus=this.opeReagentStatusService.getOpeReagentStatusByReagentCode(reagentCode);
                    //opeReagentStatus = new OpeReagentStatus();
                    //opeReagentStatus.setId(id);
                    //opeReagentStatus.setReagentId(opeApply.getReagent().getId());
                    opeReagentStatus.setArticleNumber(opeApply.getArticleNumber());
                    opeReagentStatus.setReagentCode(reagentCode);
                    opeReagentStatus.setStatus(ArrivalStatus.NOREGISTER);
                    opeReagentStatus.setHouseId(opeApply.getHouseId());
                    opeReagentStatus.setContainerId(opeApply.getContainerId());
                    opeReagentStatus.setUserId(loginUserId);
                    //opeReagentStatus.setPlace(opeApply.getPlaceId());
                    //opeReagentStatus.setRemainder(opeApply.getReagent().getMainMetering()!=null?(new BigDecimal(opeApply.getReagent().getMainMetering())):new BigDecimal(0));
                    //opeReagentStatus.setStoreType(StoreType.DIRECTSTORE);
                    this.opeReagentStatusService.updateReagentStatus2(opeReagentStatus);
 
                    // 试剂使用情况领用insert
                    /*OpeUseFlow ouf=new OpeUseFlow();
                    ouf.setReagentCode(opeReagentStatus.getReagentCode());
                    ouf.setStatus(opeReagentStatus.getStatus());
                    ouf.setHouseId(opeReagentStatus.getHouseId());
                    ouf.setContainerId(opeReagentStatus.getContainerId());
                    ouf.setUserId(opeReagentStatus.getUserId());
                    ouf.setPlace(opeReagentStatus.getPlace());
                    ouf.setRemainder(opeApply.getReagent().getMainMetering()!=null?(new BigDecimal(opeApply.getReagent().getMainMetering())):new BigDecimal(0));
                    ouf.setStoreType(StoreType.DIRECTSTORE);
 
                    Map<String, String> metaMap2 = new HashMap<>();
                    metaMap2.put("groupId", "operate_status");
                    metaMap2.put("metaKey", String.valueOf(OperateStatus.WAREHOUSEOUT.getKey()));
                    List<BaseMeta> baseMetaList2 = baseMetaDao.getBaseMetaList(metaMap2);
                    ouf.setOperateState(baseMetaList2.get(0).getId());
                    this.opeUseFlowService.insertOpeUseFlow(ouf);*/
                }else{//条码不存在
                    // 试剂最新状态insert
                    opeReagentStatus = new OpeReagentStatus();
                    opeReagentStatus.setReagentId(opeApply.getReagent().getId());
                    opeReagentStatus.setArticleNumber(opeApply.getArticleNumber());
                    opeReagentStatus.setReagentCode(reagentCode);
                    opeReagentStatus.setStatus(ArrivalStatus.NOREGISTER);
                    opeReagentStatus.setHouseId(opeApply.getHouseId());
                    opeReagentStatus.setContainerId(opeApply.getContainerId());
                    opeReagentStatus.setUserId(loginUserId);
                    //opeReagentStatus.setPlace(opeApply.getPlaceId());
                    //opeReagentStatus.setRemainder(opeApply.getReagent().getMainMetering()!=null?(new BigDecimal(opeApply.getReagent().getMainMetering())):new BigDecimal(0));
                    opeReagentStatus.setStoreType(StoreType.DIRECTSTORE);
                    this.opeReagentStatusService.insertOpeReagentStatus(opeReagentStatus);
 
                    // 试剂使用情况入库insert
                    opeUseFlow = new OpeUseFlow();
                    opeUseFlow.setReagentCode(opeReagentStatus.getReagentCode());
                    opeUseFlow.setStatus(opeReagentStatus.getStatus());
                    opeUseFlow.setHouseId(opeReagentStatus.getHouseId());
                    opeUseFlow.setContainerId(opeReagentStatus.getContainerId());
                    opeUseFlow.setUserId(opeReagentStatus.getUserId());
                    opeUseFlow.setPlace(opeReagentStatus.getPlace());
                    opeUseFlow.setRemainder(opeApply.getReagent().getMainMetering()!=null?opeApply.getReagent().getMainMetering():new BigDecimal(0));
                    opeUseFlow.setStoreType(StoreType.DIRECTSTORE);
 
                    Map<String, String> metaMap = new HashMap<>();
                    metaMap.put("groupId", "operate_status");
                    metaMap.put("metaKey", String.valueOf(OperateStatus.WAREHOUSEIN.getKey()));
                    List<BaseMeta> baseMetaList = baseMetaDao.getBaseMetaList(metaMap);
                    opeUseFlow.setOperateState(baseMetaList.get(0).getId());
                    this.opeUseFlowService.insertOpeUseFlow(opeUseFlow);
                    // 试剂使用情况领用insert
                    OpeUseFlow ouf=new OpeUseFlow();
                    ouf.setReagentCode(opeReagentStatus.getReagentCode());
                    ouf.setStatus(opeReagentStatus.getStatus());
                    ouf.setHouseId(opeReagentStatus.getHouseId());
                    ouf.setContainerId(opeReagentStatus.getContainerId());
                    ouf.setUserId(opeReagentStatus.getUserId());
                    ouf.setPlace(opeReagentStatus.getPlace());
                    ouf.setRemainder(opeApply.getReagent().getMainMetering()!=null?opeApply.getReagent().getMainMetering():new BigDecimal(0));
                    ouf.setStoreType(StoreType.DIRECTSTORE);
 
                    Map<String, String> metaMap2 = new HashMap<>();
                    metaMap2.put("groupId", "operate_status");
                    metaMap2.put("metaKey", String.valueOf(OperateStatus.WAREHOUSEOUT.getKey()));
                    List<BaseMeta> baseMetaList2 = baseMetaDao.getBaseMetaList(metaMap2);
                    ouf.setOperateState(baseMetaList2.get(0).getId());
                    this.opeUseFlowService.insertOpeUseFlow(ouf);
                }
            }
 
        }
    }
 
    @Override
    public List<OpeWarehouseReserve> selectByReId(String id) {
        return this.opeWarehouseReserveDao.selectByReId(id);
    }
 
    @Override
    public void updateByReId(String newReId, String oldReId) {
        Map<String, Object> params=new HashMap();
        params.put("newReId",newReId);
        params.put("oldReId",oldReId);
        this.opeWarehouseReserveDao.updateByReId(params);
    }
 
    @Override
    @Transactional
    public void insertOpeWarehouseReserve2(OpeApplyReserve opeApplyReserve, OpeOrder oo) {
 
        OpeWarehouseReserve ope = new OpeWarehouseReserve();
        //库存为到货数量
        ope.setReserve(opeApplyReserve.getArrivalNum());
        //仓库
        ope.setWarehouseId(opeApplyReserve.getHouseId());
        //试剂
        ope.setReagentId(opeApplyReserve.getReagent().getId());
        //订单编号
        ope.setOrderCode(oo.getOrderCode());
        // 申购编号
        ope.setApplyCode(opeApplyReserve.getApplyCode());
        //批号
        ope.setArticleNumber(opeApplyReserve.getArticleNumber());
        ope.setId(IDUtils.uuid());
        opeWarehouseReserveDao.insertOpeWarehouseReserve2(ope);
 
    }
 
    @Transactional(propagation = Propagation.REQUIRED)
    public void reagentDStore(List<OpeApply> reagentDStoreList, String loginUserId) {
 
        if (reagentDStoreList == null) {
            return;
        }
 
        OpeReagentStatus opeReagentStatus = null;
        BigInteger startReagentCode = null;
        BigInteger endReagentCode = null;
        String reagentCode = null;
        OpeWarehouseReserve opeWarehouseReserve = null;
        OpeUseFlow opeUseFlow = null;
        for (OpeApply opeApply : reagentDStoreList) {
            //不输入条形码
            if(opeApply.getStartReagentCode()==null ||
                    opeApply.getStartReagentCode().equals("") ||
            opeApply.getEndReagentCode()==null ||
            opeApply.getEndReagentCode().equals("")){
            }else{//输入条形码
 
                startReagentCode = new BigInteger(opeApply.getStartReagentCode());
                endReagentCode = new BigInteger(opeApply.getEndReagentCode());
 
                // 条形码可能以0开头,所以需要补0
                int len = opeApply.getStartReagentCode().length() - String.valueOf(startReagentCode).length();
                String temp = "";
                for (int i = 0; i < len; i++) {
                    temp += "0";
                }
 
                for (BigInteger i = startReagentCode; i.compareTo(endReagentCode) < 1; i = i.add(BigInteger.ONE)) {
                    reagentCode = temp + String.valueOf(i);
                    if (this.opeReagentStatusService.isOpeReagentStatusExist(reagentCode)) {
                        throw new BusinessException(ExceptionEnumCode.REAGENT_CODE_EXIST, "入库试剂:" + opeApply.getReagent().getName() + "的试剂条形码[" + reagentCode + "]已存在。");
                    }
 
                    // 试剂最新状态insert
                    opeReagentStatus = new OpeReagentStatus();
                    opeReagentStatus.setReagentId(opeApply.getReagent().getId());
                    opeReagentStatus.setArticleNumber(opeApply.getArticleNumber());
                    opeReagentStatus.setReagentCode(reagentCode);
                    opeReagentStatus.setStatus(ArrivalStatus.WAREHOUSE);
                    opeReagentStatus.setHouseId(opeApply.getHouseId());
                    opeReagentStatus.setContainerId(opeApply.getContainerId());
                    opeReagentStatus.setUserId(loginUserId);
                    opeReagentStatus.setPlace(opeApply.getPlaceId());
                    opeReagentStatus.setRemainder(opeApply.getReagent().getMainMetering()!=null?(opeApply.getReagent().getMainMetering()):new BigDecimal(0));
                    opeReagentStatus.setStoreType(StoreType.DIRECTSTORE);
                    this.opeReagentStatusService.insertOpeReagentStatus(opeReagentStatus);
 
                    // 试剂使用情况insert
                    opeUseFlow = new OpeUseFlow();
                    opeUseFlow.setReagentCode(opeReagentStatus.getReagentCode());
                    opeUseFlow.setStatus(opeReagentStatus.getStatus());
                    opeUseFlow.setHouseId(opeReagentStatus.getHouseId());
                    opeUseFlow.setContainerId(opeReagentStatus.getContainerId());
                    opeUseFlow.setUserId(opeReagentStatus.getUserId());
                    opeUseFlow.setPlace(opeReagentStatus.getPlace());
                    opeUseFlow.setRemainder(opeApply.getReagent().getMainMetering()!=null?(opeApply.getReagent().getMainMetering()):new BigDecimal(0));
                    opeUseFlow.setStoreType(StoreType.DIRECTSTORE);
 
                    Map<String, String> metaMap = new HashMap<>();
                    metaMap.put("groupId", "operate_status");
                    metaMap.put("metaKey", String.valueOf(OperateStatus.WAREHOUSEIN.getKey()));
                    List<BaseMeta> baseMetaList = baseMetaDao.getBaseMetaList(metaMap);
                    opeUseFlow.setOperateState(baseMetaList.get(0).getId());
 
 
                    this.opeUseFlowService.insertOpeUseFlow(opeUseFlow);
                }
            }
 
 
            // 仓库库存update
            opeWarehouseReserve = this.opeWarehouseReserveService.getOpeWarehouseReserve2(opeApply.getReagent().getId(), opeApply.getArticleNumber(),opeApply.getHouseId());
            if (opeWarehouseReserve == null) {
                opeWarehouseReserve = new OpeWarehouseReserve();
                opeWarehouseReserve.setReagentId(opeApply.getReagent().getId());
                opeWarehouseReserve.setArticleNumber(opeApply.getArticleNumber());
                opeWarehouseReserve.setReserve(0);
                opeWarehouseReserve.setWarehouseId(opeApply.getHouseId());
            }
            opeWarehouseReserve.setReserve(opeWarehouseReserve.getReserve() + opeApply.getArrivalNum());
            if (StringUtils.isBlank(opeWarehouseReserve.getId())) {
                this.opeWarehouseReserveService.insertOpeWarehouseReserve(opeWarehouseReserve);
            } else {
                this.opeWarehouseReserveService.updateOpeWarehouseReserve(opeWarehouseReserve);
            }
        }
    }
 
}