| | |
| | | import com.vincent.rsf.server.manager.entity.excel.AsnOrderTemplate; |
| | | import com.vincent.rsf.server.manager.entity.excel.DeliveryTemplate; |
| | | import com.vincent.rsf.server.manager.enums.*; |
| | | import com.vincent.rsf.server.manager.mapper.DeliveryMapper; |
| | | import com.vincent.rsf.server.manager.mapper.DeliveryItemMapper; |
| | | import com.vincent.rsf.server.manager.service.CompanysService; |
| | | import com.vincent.rsf.server.manager.service.DeliveryItemService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.vincent.rsf.server.manager.service.DeliveryService; |
| | | import com.vincent.rsf.server.manager.service.MatnrService; |
| | | import com.vincent.rsf.server.system.constant.SerialRuleCode; |
| | | import com.vincent.rsf.server.system.utils.SerialRuleUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | |
| | | public class DeliveryItemServiceImpl extends ServiceImpl<DeliveryItemMapper, DeliveryItem> implements DeliveryItemService { |
| | | |
| | | @Autowired |
| | | private DeliveryService deliveryService; |
| | | private DeliveryMapper deliveryMapper; |
| | | @Autowired |
| | | private MatnrService matnrService; |
| | | @Autowired |
| | | private CompanysService companysService; |
| | | @Autowired |
| | | private DeliveryItemService deliveryItemService; |
| | | |
| | | /** |
| | | * excel DO单导入 |
| | | * |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R excelImport(MultipartFile file, Map<String, Object> hashMap, Long loginUserId) throws Exception { |
| | | ExcelImportResult result = ExcelImportUtil.importExcelMore(file.getInputStream(), DeliveryTemplate.class, ExcelUtil.getDefaultImportParams()); |
| | | if (result.getList().isEmpty()) { |
| | |
| | | throw new CoolException("单号不能为空!!"); |
| | | } |
| | | DeliveryTemplate template = listMap.get(key).stream().findFirst().get(); |
| | | Delivery order = deliveryService.getOne(new LambdaQueryWrapper<Delivery>().eq(Delivery::getCode, key)); |
| | | Delivery order = deliveryMapper.selectOne(new LambdaQueryWrapper<Delivery>().eq(Delivery::getCode, key)); |
| | | if (!Objects.isNull(order)) { |
| | | sbFaild.append(template.getDoCode()).append(",已添加!!"); |
| | | throw new CoolException(sbFaild.toString()); |
| | |
| | | .setAnfme(Double.parseDouble(template.getAnfme())) |
| | | .setUpdateBy(loginUserId) |
| | | .setCreateBy(loginUserId); |
| | | if (!deliveryService.save(order)) { |
| | | if (deliveryMapper.insert(order) <= 0) { |
| | | throw new CoolException("单据保存失败!!"); |
| | | } |
| | | List<DeliveryItem> items = new ArrayList<>(); |
| | |
| | | if (Objects.isNull(matnr)) { |
| | | sbFaild.append(orderTemplate.getMatnrCode()).append("物料不存在"); |
| | | throw new CoolException(sbFaild.toString()); |
| | | } |
| | | if (!matnr.getName().equals(orderTemplate.getMaktx())) { |
| | | throw new CoolException("导入物料名称与库内名称不一致!!"); |
| | | } |
| | | orderItem.setDeliveryId(order.getId()) |
| | | .setDeliveryCode(order.getCode()) |
| | |
| | | } |
| | | items.add(orderItem); |
| | | |
| | | if (!deliveryItemService.save(orderItem)) { |
| | | if (!this.save(orderItem)) { |
| | | throw new CoolException("单据明细保存失败!!"); |
| | | } |
| | | } |
| | | if (!items.isEmpty()) { |
| | | Double anfme = items.stream().mapToDouble(DeliveryItem::getAnfme).sum(); |
| | | if (!deliveryService.update(new LambdaUpdateWrapper<Delivery>() |
| | | if (deliveryMapper.update(null, new LambdaUpdateWrapper<Delivery>() |
| | | .set(Delivery::getAnfme, anfme) |
| | | .eq(Delivery::getId, order.getId()))) { |
| | | .eq(Delivery::getId, order.getId())) <= 0) { |
| | | throw new CoolException("单据数量修改失败!!"); |
| | | } |
| | | } |