zjj
1 天以前 d5540413a0163383b53d33aea1be93390ea9149c
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
package com.vincent.rsf.server.api.service.impl;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.server.api.entity.enums.OrderType;
import com.vincent.rsf.server.manager.entity.PurchaseItem;
import com.vincent.rsf.server.manager.service.PurchaseItemService;
import com.vincent.rsf.server.manager.service.PurchaseService;
import com.vincent.rsf.server.system.constant.SerialRuleCode;
import com.vincent.rsf.server.api.controller.params.OrderParams;
import com.vincent.rsf.server.system.entity.Fields;
import com.vincent.rsf.server.system.service.FieldsItemService;
import com.vincent.rsf.server.system.service.FieldsService;
import com.vincent.rsf.server.system.utils.SerialRuleUtils;
import com.vincent.rsf.server.api.service.ReceiveMsgService;
import com.vincent.rsf.server.manager.entity.Purchase;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.*;
 
/**
 * @author Ryan
 * @version 1.0
 * @title ErpApiServiceImpl
 * @description
 * @create 2025/3/4 16:27
 */
@Slf4j
@Service("erpApiService")
public class ReceiveMsgServiceImpl implements ReceiveMsgService {
 
    @Autowired
    private PurchaseService purchaseService;
    @Autowired
    private PurchaseItemService purchaseItemService;
    @Autowired
    private FieldsService fieldsService;
    @Autowired
    private FieldsItemService fieldsItemService;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean syncPurchasee(List<OrderParams> orders) {
        if (orders.isEmpty()) {
            throw new CoolException("单据内容不能为空!!");
        }
        orders.forEach(ors -> {
            Purchase purchase = new Purchase();
            BeanUtils.copyProperties(ors, purchase);
            String wkVal = SerialRuleUtils.generateRuleCode(SerialRuleCode.PURCHASE_CODE, purchase);
            purchase.setCode(wkVal)
                    .setType(OrderType.ORDER_PURCHASE_IN.type);
            if (!purchaseService.save(purchase)) {
                throw new CoolException("采购单据保存失败");
            }
 
            //查询扩展字段是否存在
            List<Fields> fields = fieldsService.list(new LambdaQueryWrapper<Fields>().eq(Fields::getStatus, 1).eq(Fields::getFlagEnable, 1));
 
            //判断子列表不为空
            if (!ors.getChildren().isEmpty()) {
                ArrayList<PurchaseItem> list = new ArrayList<>();
                ors.getChildren().forEach(orderItem -> {
                    PurchaseItem item = new PurchaseItem();
                    BeanUtils.copyProperties(orderItem, item);
//                    if (!fields.isEmpty()) {
//                        List<String> fieldValue = fields.stream().map(Fields::getFields).collect(Collectors.toList());
//                        fieldValue.forEach(value -> {
//
//                        });
//                    }
                    item.setPurchaseId(purchase.getId());
                    list.add(item);
                });
                if (!purchaseItemService.saveBatch(list)) {
                    throw new CoolException("采购单明细保存失败!!");
                }
            }
        });
 
        return true;
    }
 
 
 
}