| | |
| | | package com.vincent.rsf.server.manager.service.impl; |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelImportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; |
| | | 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.common.utils.ExcelUtil; |
| | | import com.vincent.rsf.server.manager.entity.AsnOrder; |
| | | import com.vincent.rsf.server.manager.entity.excel.AsnOrderTemplate; |
| | | import com.vincent.rsf.server.manager.entity.excel.MatnrsTemplate; |
| | | import com.vincent.rsf.server.manager.mapper.AsnOrderItemMapper; |
| | | import com.vincent.rsf.server.manager.entity.AsnOrderItem; |
| | | import com.vincent.rsf.server.manager.mapper.AsnOrderMapper; |
| | | import com.vincent.rsf.server.manager.service.AsnOrderItemService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | @Service("asnOrderItemService") |
| | | public class AsnOrderItemServiceImpl extends ServiceImpl<AsnOrderItemMapper, AsnOrderItem> implements AsnOrderItemService { |
| | | |
| | | @Resource |
| | | private AsnOrderMapper asnOrderMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R excelImport(MultipartFile file, HashMap<String, Object> hashMap) throws Exception { |
| | | |
| | | ExcelImportResult<AsnOrderTemplate> result = ExcelImportUtil.importExcelMore(file.getInputStream(), MatnrsTemplate.class, ExcelUtil.getDefaultImportParams()); |
| | | if (result.getList().isEmpty()) { |
| | | throw new CoolException("物料导入失败!!"); |
| | | } |
| | | if (!Objects.isNull(hashMap.get("asnId"))) { |
| | | throw new CoolException("主单ID为空,无法操作!!"); |
| | | } |
| | | |
| | | AsnOrder order = asnOrderMapper.selectOne(new LambdaQueryWrapper<AsnOrder>().eq(AsnOrder::getId, hashMap.get("asnId"))); |
| | | if (Objects.isNull(order)) { |
| | | throw new CoolException("ASN单据不存在!!"); |
| | | } |
| | | List<AsnOrderItem> itemList = new ArrayList<>(); |
| | | result.getList().forEach(template -> { |
| | | AsnOrderItem orderItem = new AsnOrderItem(); |
| | | BeanUtils.copyProperties(template, orderItem); |
| | | orderItem.setAsnId(order.getId()) |
| | | .setAsnCode(order.getCode()); |
| | | itemList.add(orderItem); |
| | | }); |
| | | if (!this.saveBatch(itemList)) { |
| | | throw new CoolException("保存失败!!"); |
| | | } |
| | | return R.ok("操作成功!!"); |
| | | } |
| | | } |