zhangfeng
2022-11-08 f241a39f07acc5d5ede28b4152d74cbb84e4885b
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
package com.gkhy.safePlatform.equipment.service.impl;
 
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gkhy.safePlatform.account.rpc.apimodel.AccountUserService;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.UserInfoRPCRespDTO;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.query.PageQuery;
import com.gkhy.safePlatform.commons.utils.StringUtils;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import com.gkhy.safePlatform.commons.vo.SearchResultVO;
import com.gkhy.safePlatform.equipment.common.RocketMQTemplateHelper;
import com.gkhy.safePlatform.equipment.entity.*;
import com.gkhy.safePlatform.equipment.enums.*;
import com.gkhy.safePlatform.equipment.excepiton.EquipmentException;
import com.gkhy.safePlatform.equipment.model.dto.req.*;
import com.gkhy.safePlatform.equipment.model.dto.resp.SafeMaterialDetailDto;
import com.gkhy.safePlatform.equipment.mq.msg.SafeMaterialMsg;
import com.gkhy.safePlatform.equipment.service.SafeMaterialDetailService;
import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialClassifyInfoService;
import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialDetailInfoService;
import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialInfoService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
@Service("SafeMaterialDetailService")
public class SafeMaterialDetailServiceImpl implements SafeMaterialDetailService {
    @Autowired
    private SafeMaterialInfoService safeMaterialInfoService;
    @Autowired
    private SafeMaterialDetailInfoService safeMaterialDetailInfoService;
 
    @Autowired
    private SafeMaterialClassifyInfoService safeMaterialClassifyInfoService;
 
    @Value("${rocketmq.topic.safeMaterialTopic}")
    private String safeMaterialTopic;
 
    @DubboReference(check = false)
    private AccountUserService accountUserService;
 
    @Autowired
    private RocketMQTemplateHelper rocketMQTemplateHelper;
 
    @Override
    public ResultVO save(SafeMaterialDetailAddReq req) {
        //判断物资是否存在
        SafeMaterialInfo materialInfo = safeMaterialInfoService.queryById(req.getSmId());
        if(null == materialInfo){
            throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST,"该种物资不存在!");
        }
        if(null == ValidTypeEnum.getByCode(req.getValidType())){
            throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"有效期类型不合法!");
        }
        if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null == req.getValidTime()){
            throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL,"有效期时间不可为空!");
        }
        //获取数据量
        Integer totalCount = safeMaterialDetailInfoService.getTotalCount();
        List<SafeMaterialDetailInfo> list = new ArrayList<>();
 
        //RFID起始不为空计算一下
        if(StringUtils.isNotBlank(req.getStartRfid()) && StringUtils.isNotBlank(req.getEndRfid())){
            int start = 0;
            int end = 0;
            String prefix = "";
            try{
                prefix = req.getStartRfid().substring(0,req.getStartRfid().length()-8);
                start = Integer.parseInt(req.getStartRfid().substring(req.getStartRfid().length()-8));
                end = Integer.parseInt(req.getEndRfid().substring(req.getEndRfid().length()-8));
            }catch (Exception e){
                throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"起始RFID不合法!");
            }
            if((end-start+1) != req.getWareHousingCount()){
                throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"RFID起始和入库数量不能对应!");
            }
            for(int i = 0;i < req.getWareHousingCount();i++){
                String countStr = String.valueOf(start+i);
                String rfid = "0000000".substring(0,(8 - countStr.length()))+countStr;
                SafeMaterialDetailInfo materialDetailInfo = new SafeMaterialDetailInfo();
                materialDetailInfo.setId(IdUtil.getSnowflake(0,0).nextId());
                materialDetailInfo.setMaterialClassifyId(materialInfo.getMaterialClassifyId());
                materialDetailInfo.setName(materialInfo.getMaterialName()+"(ID"+materialInfo.getId()+")");
                materialDetailInfo.setSmId(req.getSmId());
                materialDetailInfo.setConsumable(materialInfo.getConsumable());
                materialDetailInfo.setValidType(req.getValidType());
                if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode())){
                    materialDetailInfo.setValidTime(req.getValidTime());
                }
                materialDetailInfo.setValidStatus(ValidStatusEnum.YES.getCode());
                materialDetailInfo.setIrStatus(IssueReceiptEnum.IN_THE_LIBRARY.getCode());
                materialDetailInfo.setWareHousingTime(LocalDateTime.now());
                materialDetailInfo.setRfid(prefix+rfid);
                materialDetailInfo.setMaterialNo(generateMaterialNo(totalCount+i));
                list.add(materialDetailInfo);
            }
        }else{
            //不分配FRID
            for(int i = 0;i < req.getWareHousingCount();i++){
                SafeMaterialDetailInfo materialDetailInfo = new SafeMaterialDetailInfo();
                materialDetailInfo.setId(IdUtil.getSnowflake(0,0).nextId());
                materialDetailInfo.setMaterialClassifyId(materialInfo.getMaterialClassifyId());
                materialDetailInfo.setName(materialInfo.getMaterialName()+"(ID"+materialInfo.getId()+")");
                materialDetailInfo.setSmId(req.getSmId());
                materialDetailInfo.setConsumable(materialInfo.getConsumable());
                materialDetailInfo.setValidType(req.getValidType());
                if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode())){
                    materialDetailInfo.setValidTime(req.getValidTime());
                }
                materialDetailInfo.setValidStatus(ValidStatusEnum.YES.getCode());
                materialDetailInfo.setIrStatus(IssueReceiptEnum.IN_THE_LIBRARY.getCode());
                materialDetailInfo.setWareHousingTime(LocalDateTime.now());
                materialDetailInfo.setMaterialNo(generateMaterialNo(totalCount+i));
                list.add(materialDetailInfo);
            }
        }
 
        //批量入库
        safeMaterialDetailInfoService.saveBatch(list);
 
        //发送消息
        if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null != req.getValidTime()){
            for(SafeMaterialDetailInfo materialDetailInfo:list){
                SafeMaterialMsg safeMaterialMsg = new SafeMaterialMsg();
                safeMaterialMsg.setId(materialDetailInfo.getId());
                safeMaterialMsg.setValidTime(conversionTimeType(materialDetailInfo.getValidTime()));
                rocketMQTemplateHelper.syncSend(safeMaterialTopic,safeMaterialMsg);
            }
        }
        return new ResultVO<>(ResultCodes.OK);
    }
 
    /**
     * 批量入库
     * @param req
     * @return
     */
    @Override
    public ResultVO saveBatch(SafeMaterialDetailAddReq req) {
        //判断物资是否存在
        SafeMaterialInfo materialInfo = safeMaterialInfoService.queryById(req.getSmId());
        if(null == materialInfo){
            throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST,"该种物资不存在!");
        }
        if(null == ValidTypeEnum.getByCode(req.getValidType())){
            throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"有效期类型不合法!");
        }
        if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null == req.getValidTime()){
            throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL,"有效期时间不可为空!");
        }
        //获取数据量
        Integer totalCount = safeMaterialDetailInfoService.getTotalCount();
        List<SafeMaterialDetailInfo> list = new ArrayList<>();
 
        for(int i = 0;i < req.getWareHousingCount();i++){
            SafeMaterialDetailInfo materialDetailInfo = new SafeMaterialDetailInfo();
            materialDetailInfo.setId(IdUtil.getSnowflake(0,0).nextId());
            materialDetailInfo.setMaterialClassifyId(materialInfo.getMaterialClassifyId());
            materialDetailInfo.setName(materialInfo.getMaterialName()+"(ID"+materialInfo.getId()+")");
            materialDetailInfo.setSmId(req.getSmId());
            materialDetailInfo.setConsumable(materialInfo.getConsumable());
            materialDetailInfo.setValidType(req.getValidType());
            if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode())){
                materialDetailInfo.setValidTime(req.getValidTime());
            }
            materialDetailInfo.setValidStatus(ValidStatusEnum.YES.getCode());
            materialDetailInfo.setIrStatus(IssueReceiptEnum.IN_THE_LIBRARY.getCode());
            materialDetailInfo.setWareHousingTime(LocalDateTime.now());
            materialDetailInfo.setRfid(req.getRfid());
            materialDetailInfo.setMaterialNo(generateMaterialNo(totalCount+i));
            list.add(materialDetailInfo);
        }
        //批量入库
        safeMaterialDetailInfoService.saveBatch(list);
        //发送消息
        if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null != req.getValidTime()){
            for(SafeMaterialDetailInfo materialDetailInfo:list){
                //发送消息
                SafeMaterialMsg safeMaterialMsg = new SafeMaterialMsg();
                safeMaterialMsg.setId(materialInfo.getId());
                safeMaterialMsg.setValidTime(conversionTimeType(materialDetailInfo.getValidTime()));
                rocketMQTemplateHelper.syncSend(safeMaterialTopic,safeMaterialMsg);
            }
        }
        return new ResultVO<>(ResultCodes.OK);
    }
 
    /**
     * 编辑
     * @param req
     * @return
     */
    @Transactional
    @Override
    public ResultVO update(SafeMaterialDetailReq req) {
        //获取该条数据
        SafeMaterialDetailInfo vo = safeMaterialDetailInfoService.queryById(req.getId());
        if(null == vo){
            throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST);
        }
        //有效类型不为空
        if(null != req.getValidType()){
            if(null == ValidTypeEnum.getByCode(req.getValidType())){
                throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"有效期类型不合法!");
            }else{
                if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null == req.getValidTime()){
                    throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL,"有效期时间不可为空!");
                }
            }
        }
        //填充数据
        SafeMaterialDetailInfo safeMaterialDetailInfo = new SafeMaterialDetailInfo();
        safeMaterialDetailInfo.setId(req.getId());
        safeMaterialDetailInfo.setRfid(req.getRfid());
        safeMaterialDetailInfo.setSmId(req.getSmId());
        safeMaterialDetailInfo.setValidType(req.getValidType());
        safeMaterialDetailInfo.setValidTime(req.getValidTime());
        //修改
        safeMaterialDetailInfoService.updateById(safeMaterialDetailInfo);
        //如果是非常期
        if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null != req.getValidTime()){
            //发送消息
            SafeMaterialMsg safeMaterialMsg = new SafeMaterialMsg();
            safeMaterialMsg.setId(req.getId());
            safeMaterialMsg.setValidTime(conversionTimeType(req.getValidTime()));
            rocketMQTemplateHelper.syncSend(safeMaterialTopic,safeMaterialMsg);
        }
        return new ResultVO(ResultCodes.OK);
    }
 
    /**
     * 批量-重新入库
     * @param ids
     * @return
     */
    @Override
    public ResultVO receiptBatch(Long[] ids) {
        if (ids.length == 0) {
            throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
        }
        List<Long> idList = new ArrayList<>();
        Collections.addAll(idList,ids);
        //验证
        List<SafeMaterialDetailInfo> list = safeMaterialDetailInfoService.getListByIds(idList);
        List<SafeMaterialDetailInfo> selectList = list
                .stream()
                .filter(item -> item.getIrStatus().equals(IssueReceiptEnum.OUT_OF_LIBRARY.getCode()))
                .collect(Collectors.toList());
        if(selectList.size() != ids.length){
            throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"已入库物资不可重复入库!");
        }
        //修改为入库状态
        safeMaterialDetailInfoService.updateReceiptStatusByIds(idList,IssueReceiptEnum.IN_THE_LIBRARY.getCode());
        return new ResultVO(ResultCodes.OK);
    }
 
    /**
     * 逻辑删除 -批量删除
     * @param
     * @return
     */
    @Override
    public ResultVO deleteBatch(Long[] ids) {
        if (ids.length == 0) {
            throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
        }
        safeMaterialDetailInfoService.deleteBatch(ids);
        return new ResultVO(ResultCodes.OK);
    }
 
    /**
     * 批量出库 - 根据ids
     * @param req
     * @return
     */
    @Override
    public ResultVO deliveryBatchByIds(MterialDeliveryReq req) {
        //获取认领人信息
        UserInfoRPCRespDTO userInfo = getUserInfo(req.getClaimantId());
        //验证
        List<SafeMaterialDetailInfo> list = safeMaterialDetailInfoService.getListByIds(req.getIds());
        List<SafeMaterialDetailInfo> selectList = list
                .stream()
                .filter(item -> item.getIrStatus().equals(IssueReceiptEnum.IN_THE_LIBRARY.getCode()) && item.getValidStatus().equals(ValidStatusEnum.YES.getCode()))
                .collect(Collectors.toList());
        if(selectList.size() != req.getIds().size()){
            throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"已出库物资或无效物资,不可出库!");
        }
        SafeMaterialDetailBO detailBO = new SafeMaterialDetailBO();
        detailBO.setIds(req.getIds());
        detailBO.setClaimantName(userInfo.getUsername());
        detailBO.setClaimantId(req.getClaimantId());
        safeMaterialDetailInfoService.updateDeliveryStatusByIds(detailBO);
        return new ResultVO(ResultCodes.OK);
    }
 
    @Override
    public ResultVO deliveryBatchRandom(MterialRandomDeliveryReq req) {
        UserInfoRPCRespDTO userInfo = getUserInfo(req.getClaimantId());
        //获取有效数量
        Integer validStockCount = safeMaterialDetailInfoService.getValidStockCount(req.getSmId());
        if(req.getCount() > validStockCount){
            throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"出库数量不可大于有效库存数量!");
        }
 
        SafeMaterialDetailBO detailBO = new SafeMaterialDetailBO();
        detailBO.setCount(req.getCount());
        detailBO.setClaimantName(userInfo.getUsername());
        detailBO.setClaimantId(req.getClaimantId());
        safeMaterialDetailInfoService.deliveryBatchRandom(detailBO);
        return new ResultVO(ResultCodes.OK);
    }
 
    @Override
    public SearchResultVO<List<SafeMaterialDetailDto>> listByPage(PageQuery<SafeMatetrialDetailQuery> pageQuery) {
        Page<SafeMaterialDetailInfo> page = new Page(pageQuery.getPageIndex(),pageQuery.getPageSize());
        List<SafeMaterialDetailInfoDO> safeMaterialDetailInfoDOS = safeMaterialDetailInfoService.listByPage(page, pageQuery.getSearchParams());
        List<SafeMaterialDetailDto> detailDtoList = new ArrayList<>();
        for(SafeMaterialDetailInfoDO materialDetailInfoDO : safeMaterialDetailInfoDOS){
            SafeMaterialDetailDto materialDetailDto = new SafeMaterialDetailDto();
            BeanUtils.copyProperties(materialDetailInfoDO,materialDetailDto);
            materialDetailDto.setConsumableName(ConsumableEnum.getByCode(materialDetailInfoDO.getConsumable()).getValue());
            materialDetailDto.setValidStatusName(ValidStatusEnum.getByCode(materialDetailInfoDO.getValidStatus()).getValue());
            materialDetailDto.setValidTypeName(ValidTypeEnum.getByCode(materialDetailInfoDO.getValidType()).getValue());
            materialDetailDto.setIrStatusName(IssueReceiptEnum.getByCode(materialDetailInfoDO.getIrStatus()).getValue());
 
            detailDtoList.add(materialDetailDto);
        }
        return new SearchResultVO<>(true, page.getCurrent(),page.getSize(), page.getPages(),page.getTotal(),detailDtoList,ResultCodes.OK);
    }
 
    @Override
    public ResultVO queryById(Long id) {
        if(null == id){
            throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
        }
        SafeMaterialDetailInfo materialDetailInfo = safeMaterialDetailInfoService.queryById(id);
        SafeMaterialDetailDto detailDto = new SafeMaterialDetailDto();
        if(materialDetailInfo != null){
            SafeMaterialInfo materialInfo = safeMaterialInfoService.queryById(materialDetailInfo.getSmId());
            SafeMaterialClassifyInfo classifyInfo = safeMaterialClassifyInfoService.queryById(materialDetailInfo.getMaterialClassifyId());
            BeanUtils.copyProperties(materialDetailInfo,detailDto);
            detailDto.setConsumableName(ConsumableEnum.getByCode(materialDetailInfo.getConsumable()).getValue());
            detailDto.setValidStatusName(ValidStatusEnum.getByCode(materialDetailInfo.getValidStatus()).getValue());
            detailDto.setValidTypeName(ValidTypeEnum.getByCode(materialDetailInfo.getValidType()).getValue());
            detailDto.setIrStatusName(IssueReceiptEnum.getByCode(materialDetailInfo.getIrStatus()).getValue());
            if(materialInfo != null){
              detailDto.setDepName(materialInfo.getDepName());
            }
            if(classifyInfo != null){
                detailDto.setMaterialClassifyName(classifyInfo.getMaterialClassifyName());
            }
 
        }
        return new ResultVO(ResultCodes.OK,detailDto);
    }
 
    /**
     * 单条-出库
     * @param req
     * @return
     */
    @Override
    public ResultVO singleDelivery(SafeMaterialDetailReq req) {
        //获取该条数据
        SafeMaterialDetailInfo vo = safeMaterialDetailInfoService.queryById(req.getId());
        if(null == vo){
            throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST);
        }
        if(vo.getValidStatus().equals(ValidStatusEnum.NO.getCode())){
            throw new EquipmentException(EquipmentResultCodes.MATERIAL_INVALID,"无效物资不可出库");
        }
        if(vo.getIrStatus().equals(IssueReceiptEnum.OUT_OF_LIBRARY.getCode())){
            throw new EquipmentException(EquipmentResultCodes.MATERIAL_OUT_OF_LIBRARY);
        }
        //检查认领人
        UserInfoRPCRespDTO userInfo = getUserInfo(req.getClaimantId());
        SafeMaterialDetailInfo materialDetailInfo = new SafeMaterialDetailInfo();
        materialDetailInfo.setId(req.getId());
        materialDetailInfo.setIrStatus(IssueReceiptEnum.OUT_OF_LIBRARY.getCode());
        materialDetailInfo.setClaimantId(req.getClaimantId());
        materialDetailInfo.setClaimantName(userInfo.getUsername());
        materialDetailInfo.setDeliveryTime(LocalDateTime.now());
        //修改出入库状态为出库
        safeMaterialDetailInfoService.updateById(materialDetailInfo);
        return new ResultVO<>(ResultCodes.OK);
    }
 
    /**
     * 单条-重新入库
     * @param id
     * @return
     */
 
    @Override
    public ResultVO singleReceipt(Long id) {
        if(null == id){
            throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
        }
        //获取该条数据
        SafeMaterialDetailInfo vo = safeMaterialDetailInfoService.queryById(id);
        if(null == vo){
            throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST);
        }
        if(vo.getIrStatus().equals(IssueReceiptEnum.IN_THE_LIBRARY.getCode())){
            throw new EquipmentException(EquipmentResultCodes.MATERIAL_IN_THE_LIBRARY);
        }
        //修改出入库状态为入库
        safeMaterialDetailInfoService.updateReceiptStatus(id,IssueReceiptEnum.IN_THE_LIBRARY.getCode());
        return new ResultVO<>(ResultCodes.OK);
    }
 
    @Override
    public ResultVO singleDdelivery0rReceipt(SafeMaterialDetailReq req) {
        if(null == IssueReceiptEnum.getByCode(req.getIrStatus())){
            throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"物资状态不合法");
        }
 
        //获取该条数据
        SafeMaterialDetailInfo vo = safeMaterialDetailInfoService.queryById(req.getId());
        if(null == vo){
            throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST);
        }
        if(null == IssueReceiptEnum.getByCode(req.getIrStatus())){
            throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"出入库状态不合法");
        }
 
        if(IssueReceiptEnum.IN_THE_LIBRARY.getCode().equals(req.getIrStatus())){
            //重新入库
            if(vo.getIrStatus().equals(req.getIrStatus())){
                throw new EquipmentException(EquipmentResultCodes.MATERIAL_IN_THE_LIBRARY);
            }
 
            //修改出入库状态为入库
            safeMaterialDetailInfoService.updateReceiptStatus(req.getId(), req.getIrStatus());
        }else{
            //出库
            if(vo.getValidStatus().equals(ValidStatusEnum.NO.getCode())){
                throw new EquipmentException(EquipmentResultCodes.MATERIAL_INVALID,"无效物资不可出库");
            }
            if(vo.getIrStatus().equals(req.getIrStatus())){
                throw new EquipmentException(EquipmentResultCodes.MATERIAL_OUT_OF_LIBRARY);
            }
            if(null == req.getClaimantId()){
                throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL,"认领人不可为空!");
            }
            //检查认领人
            UserInfoRPCRespDTO userInfo = getUserInfo(req.getClaimantId());
            //出库
            SafeMaterialDetailInfo materialDetailInfo = new SafeMaterialDetailInfo();
            materialDetailInfo.setId(req.getId());
            materialDetailInfo.setIrStatus(req.getIrStatus());
            materialDetailInfo.setClaimantId(req.getClaimantId());
            materialDetailInfo.setClaimantName(userInfo.getUsername());
            materialDetailInfo.setDeliveryTime(LocalDateTime.now());
            //修改出入库状态为入库
            safeMaterialDetailInfoService.updateById(materialDetailInfo);
        }
        return new ResultVO<>(ResultCodes.OK);
    }
 
 
 
    /**
     * 逻辑删除 -单条
     * @param
     * @return
     */
    public ResultVO delete(Long id){
        if(null == id){
            throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
        }
        //获取该条数据
        SafeMaterialDetailInfo vo = safeMaterialDetailInfoService.queryById(id);
        if(null == vo){
            throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST);
        }
        SafeMaterialDetailInfo materialDetailInfo = new SafeMaterialDetailInfo();
        materialDetailInfo.setId(id);
        materialDetailInfo.setDelFlag(1);
        //删除一条数据
        safeMaterialDetailInfoService.updateById(materialDetailInfo);
 
        return new ResultVO<>(ResultCodes.OK);
    }
 
 
 
 
 
 
    private UserInfoRPCRespDTO getUserInfo(Long uid) {
        UserInfoRPCRespDTO userInfo = new UserInfoRPCRespDTO();
        ResultVO<UserInfoRPCRespDTO> rpcResult = accountUserService.getUserInfoByUid(uid);
        if (rpcResult != null && rpcResult.getCode().equals(ResultCodes.OK.getCode())) {
            if (rpcResult.getData() != null) {
                userInfo = (UserInfoRPCRespDTO) rpcResult.getData();
            }else {
                throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST,"认领人员不存在!");
            }
        } else {
            throw new EquipmentException(ResultCodes.RPC_RESULT_NULL);
        }
        return userInfo;
    }
 
    private String generateMaterialNo(int count){
        if(count < 0){
            return null;
        }
        String serialCode = null;
        if(count >= 10000){
            serialCode = "" + (count+1);
        }else if(count >=0){
            String countStr = String.valueOf(count+1);
            serialCode = "10000".substring(0,(5 - countStr.length()))+countStr;
        }
        return serialCode;
    }
    private Date conversionTimeType(LocalDateTime localDateTime){
        ZoneId zoneId = ZoneId.systemDefault();
        ZonedDateTime zdt = localDateTime.atZone(zoneId);
        Date date = Date.from(zdt.toInstant());
        return date;
    }
 
}