新火炬后端单体项目初始化代码
lixiangyu
84 分钟以前 345941d946f5a48d31660a58dfc7911d7639a97d
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
package org.jeecg.modules.cms.service.impl;
 
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.cms.entity.CuttingInbound;
import org.jeecg.modules.cms.entity.CuttingInboundDetail;
import org.jeecg.modules.cms.mapper.CuttingInboundMapper;
import org.jeecg.modules.cms.service.ICuttingInboundService;
import org.jeecg.modules.cms.service.ICuttingInboundDetailService;
import org.jeecg.modules.cms.vo.CuttingInboundExportVo;
import org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
import org.springframework.beans.factory.annotation.Autowired;
 
/**
 * @Description: 刀具入库单
 * @Author: jeecg-boot
 * @Date:   2025-07-28
 * @Version: V1.0
 */
@Service
public class CuttingInboundServiceImpl extends ServiceImpl<CuttingInboundMapper, CuttingInbound> implements ICuttingInboundService {
    @Autowired
    private ICuttingInboundDetailService cuttingInboundDetailService; // 注入从表服务
    /**
     * 通过Excel导入刀具入库单数据
     *
     * @param list 待导入的数据列表
     * @return 导入结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result<?> importExcelData(List<CuttingInboundExportVo> list) {
//        try {
//            for (CuttingInboundExportVo exportVo : list) {
//                // 保存主表数据
//                CuttingInbound cuttingInbound = new CuttingInbound();
//                cuttingInbound.setReceiver(exportVo.getReceiver());
//                cuttingInbound.setReceiveTime(exportVo.getReceiveTime());
//                cuttingInbound.setReceiveComment(exportVo.getReceiveComment());
//                cuttingInbound.setConfirmer(exportVo.getConfirmer());
//                cuttingInbound.setConfirmTime(exportVo.getConfirmTime());
//                cuttingInbound.setConfirmComment(exportVo.getConfirmComment());
//                cuttingInbound.setOrderStatus(exportVo.getOrderStatus());
//
//                // 保存主表数据以获取ID
//                this.save(cuttingInbound);
//
//                // 获取主表ID
//                String orderId = cuttingInbound.getId();
//
//                // 处理从表数据
//                List<CuttingInboundDetail> detailList = exportVo.getDetailList();
//                if (detailList != null && !detailList.isEmpty()) {
//                    for (CuttingInboundDetail detail : detailList) {
//                        detail.setOrderId(orderId); // 设置外键关联
//                        cuttingInboundDetailService.save(detail);
//                    }
//                }
//            }
//            return Result.ok("导入成功");
//        } catch (Exception e) {
//            log.error("导入失败", e);
//            return Result.error("导入失败: " + e.getMessage());
//        }
//    }
        for (CuttingInboundExportVo exportVo : list) {
            // 保存主表数据
            CuttingInbound cuttingInbound = new CuttingInbound();
            cuttingInbound.setReceiver(exportVo.getReceiver());
            cuttingInbound.setReceiveTime(exportVo.getReceiveTime());
            cuttingInbound.setReceiveComment(exportVo.getReceiveComment());
            cuttingInbound.setConfirmer(exportVo.getConfirmer());
            cuttingInbound.setConfirmTime(exportVo.getConfirmTime());
            cuttingInbound.setConfirmComment(exportVo.getConfirmComment());
            cuttingInbound.setOrderStatus(exportVo.getOrderStatus());
 
            // 保存主表数据以获取ID
            this.save(cuttingInbound);
 
            // 获取主表ID
            String orderId = cuttingInbound.getId();
 
            // 处理从表数据
            List<CuttingInboundDetail> detailList = exportVo.getDetailList();
            if (detailList != null && !detailList.isEmpty()) {
                for (CuttingInboundDetail detail : detailList) {
                    detail.setOrderId(orderId); // 设置外键关联
                    cuttingInboundDetailService.save(detail);
                }
            }
        }
        return Result.ok("导入成功");
    }
}