| | |
| | | package com.vincent.rsf.server.manager.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.vincent.rsf.server.manager.controller.params.ReviseLogItemParams; |
| | | import com.vincent.rsf.server.manager.entity.Loc; |
| | | import com.vincent.rsf.server.manager.entity.LocItem; |
| | | import com.vincent.rsf.server.manager.entity.ReviseLog; |
| | | import com.vincent.rsf.server.manager.mapper.ReviseLogItemMapper; |
| | | import com.vincent.rsf.server.manager.entity.ReviseLogItem; |
| | | import com.vincent.rsf.server.manager.service.LocItemService; |
| | | import com.vincent.rsf.server.manager.service.LocService; |
| | | import com.vincent.rsf.server.manager.service.ReviseLogItemService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.vincent.rsf.server.manager.service.ReviseLogService; |
| | | 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.List; |
| | | import java.util.Objects; |
| | | |
| | | @Service("reviseLogItemService") |
| | | public class ReviseLogItemServiceImpl extends ServiceImpl<ReviseLogItemMapper, ReviseLogItem> implements ReviseLogItemService { |
| | | |
| | | @Autowired |
| | | private ReviseLogService reviseLogService; |
| | | @Autowired |
| | | private LocItemService locItemService; |
| | | @Autowired |
| | | private LocService locService; |
| | | |
| | | |
| | | /** |
| | | * 保存库存调整历史单明细 |
| | | * @param reviseLogItem |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public List<ReviseLogItem> itemSave(ReviseLogItemParams reviseLogItem, Long userId) { |
| | | ReviseLog reviseLog = reviseLogService.getById(reviseLogItem.getReviseLogId()); |
| | | if (Objects.isNull(reviseLog)) { |
| | | throw new RuntimeException("库存历史单据不存在!!"); |
| | | } |
| | | Loc locItem = locService.getOne(new LambdaQueryWrapper<Loc>() |
| | | .eq(Loc::getCode, reviseLog.getLocCode())); |
| | | if (Objects.isNull(locItem)) { |
| | | throw new RuntimeException("库位库存不存在!!"); |
| | | } |
| | | List<ReviseLogItem> items = reviseLogItem.getItems(); |
| | | items.forEach(item -> { |
| | | ReviseLogItem logItem = new ReviseLogItem(); |
| | | BeanUtils.copyProperties(item, logItem); |
| | | logItem.setReviseLogId(reviseLogItem.getReviseLogId()) |
| | | .setUpdateBy(userId) |
| | | .setCreateBy(userId) |
| | | .setLocId(locItem.getId()) |
| | | .setLocCode(locItem.getCode()); |
| | | if (Objects.isNull(item.getAnfme())) { |
| | | item.setAnfme(0.0); |
| | | } |
| | | if (!this.save(logItem)) { |
| | | throw new RuntimeException("库存明细调整失败"); |
| | | } |
| | | |
| | | LocItem one = locItemService.getOne(new LambdaQueryWrapper<LocItem>() |
| | | .eq(LocItem::getMatnrId, logItem.getMatnrId()) |
| | | .eq(LocItem::getBatch, logItem.getBatch()) |
| | | .eq(LocItem::getFieldsIndex, logItem.getFieldsIndex()) |
| | | .eq(LocItem::getLocCode, logItem.getLocCode())); |
| | | if (Objects.isNull(one)) { |
| | | throw new RuntimeException("库存明细不存在!!"); |
| | | } |
| | | |
| | | one.setAnfme(logItem.getReviseQty()); |
| | | |
| | | if (!locItemService.updateById(one)) { |
| | | throw new RuntimeException("库存明细修改失败!!"); |
| | | } |
| | | }); |
| | | return items; |
| | | } |
| | | } |