| | |
| | | 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: 刀具入库单 |
| | |
| | | */ |
| | | @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("导入成功"); |
| | | } |
| | | } |