yangyang
2025-03-17 9cf4ac9c3f8301f5697f6d12ac4bf32855f0b044
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
package com.vincent.rsf.server.manager.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.server.manager.controller.params.QlyInspectAndItem;
import com.vincent.rsf.server.manager.entity.AsnOrder;
import com.vincent.rsf.server.manager.entity.AsnOrderItem;
import com.vincent.rsf.server.manager.entity.QlyIsptItem;
import com.vincent.rsf.server.manager.mapper.QlyInspectMapper;
import com.vincent.rsf.server.manager.entity.QlyInspect;
import com.vincent.rsf.server.manager.service.AsnOrderItemService;
import com.vincent.rsf.server.manager.service.AsnOrderService;
import com.vincent.rsf.server.manager.service.QlyInspectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vincent.rsf.server.manager.service.QlyIsptItemService;
import com.vincent.rsf.server.system.constant.SerialRuleCode;
import com.vincent.rsf.server.system.utils.SerialRuleUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
 
@Service("qlyInspectService")
public class QlyInspectServiceImpl extends ServiceImpl<QlyInspectMapper, QlyInspect> implements QlyInspectService {
 
    @Autowired
    private AsnOrderItemService asnOrderItemService;
 
    @Autowired
    private AsnOrderService asnOrderService;
 
    @Autowired
    private QlyIsptItemService qlyIsptItemService;
 
    @Override
    public List<AsnOrderItem> listByAsn(Map<String, Object> map) {
        if (Objects.isNull(map.get("asnCode"))) {
            throw new CoolException("收货单据明细编码不能为空!!");
        }
        AsnOrder asnOrder = asnOrderService.getOne(new LambdaQueryWrapper<AsnOrder>()
                .eq(AsnOrder::getCode, map.get("asnCode"))
                .ne(AsnOrder::getNtyStatus, 0));
        if (Objects.isNull(asnOrder)) {
            throw new CoolException("单据不存在!!");
        }
        List<AsnOrderItem> asnOrderItems = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>()
                .eq(AsnOrderItem::getAsnCode, map.get("asnCode"))
                .eq(AsnOrderItem::getNtyStatus, 1));
        if (asnOrderItems.isEmpty()) {
            return new ArrayList<>();
        }
        return asnOrderItems;
    }
 
    @Override
    public R allSave(QlyInspectAndItem params) {
        if (Objects.isNull(params.getQlyInspect())) {
            throw new CoolException("质检单据不能为空!!");
        }
        QlyInspect inspect = params.getQlyInspect();
        if (Objects.isNull(inspect.getWkType())) {
            throw new CoolException("业务类型不能为空!!");
        }
        String code = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_INSPECT_WK_TYPE, inspect);
        inspect.setCode(code);
        if (!this.saveOrUpdate(inspect)) {
            throw new CoolException("质检单保存失败!!");
        }
        List<QlyIsptItem> isptItems = params.getQlyIsptItems();
        if (isptItems.isEmpty()) {
            return R.ok("保存成功!!");
        }
        List<QlyIsptItem> items = new ArrayList<>();
        for (QlyIsptItem isptItem : isptItems) {
            if (Objects.isNull(isptItem.getMatnrCode())) {
                continue;
            }
            isptItem.setIspectId(inspect.getId());
            items.add(isptItem);
        }
        if (!qlyIsptItemService.saveOrUpdateBatch(items)) {
            throw new CoolException("质检明细保存失败!!");
        }
        return R.ok("保存成功!!");
    }
}