| | |
| | | package com.vincent.rsf.server.manager.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.manager.controller.params.ReviseLogParams; |
| | | import com.vincent.rsf.server.manager.entity.LocRevise; |
| | | import com.vincent.rsf.server.manager.entity.ReviseLogItem; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.enums.CommonExceStatus; |
| | | import com.vincent.rsf.server.manager.enums.OrderType; |
| | | import com.vincent.rsf.server.manager.mapper.ReviseLogMapper; |
| | | import com.vincent.rsf.server.manager.entity.ReviseLog; |
| | | import com.vincent.rsf.server.manager.service.LocReviseService; |
| | | import com.vincent.rsf.server.manager.service.ReviseLogService; |
| | | import com.vincent.rsf.server.manager.service.*; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | 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.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service("reviseLogService") |
| | | public class ReviseLogServiceImpl extends ServiceImpl<ReviseLogMapper, ReviseLog> implements ReviseLogService { |
| | |
| | | @Autowired |
| | | private ReviseLogService reviseLogService; |
| | | |
| | | @Autowired |
| | | private LocItemService locItemService; |
| | | |
| | | @Autowired |
| | | private LocService locService; |
| | | @Autowired |
| | | private ReviseLogItemService reviseLogItemService; |
| | | |
| | | /** |
| | | * 库存调整单明细添加 |
| | | * @param revise |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public List<ReviseLog> reviseLoc(ReviseLogParams revise, Long loginUserId) { |
| | | LocRevise locRevise = locReviseService.getById(revise.getReviseId()); |
| | | if (Objects.isNull(locRevise)) { |
| | | throw new RuntimeException("调整单据不存在!!"); |
| | | throw new CoolException("调整单据不存在!!"); |
| | | } |
| | | List<ReviseLog> items = revise.getItems(); |
| | | if (items.isEmpty()) { |
| | | throw new RuntimeException("调整单明细参数为空!!"); |
| | | throw new CoolException("调整单明细参数为空!!"); |
| | | } |
| | | items.forEach(item -> { |
| | | ReviseLog reviseLog = new ReviseLog(); |
| | | BeanUtils.copyProperties(item, reviseLog); |
| | | reviseLog.setAreaId(locRevise.getAreaId()) |
| | | .setReviseId(locRevise.getId()) |
| | | .setCreateBy(loginUserId) |
| | | .setUpdateBy(loginUserId) |
| | | .setReviseCode(locRevise.getCode()) ; |
| | | if (!reviseLogService.save(reviseLog)) { |
| | | throw new RuntimeException("调整单明细保存失败!!"); |
| | | throw new CoolException("调整单明细保存失败!!"); |
| | | } |
| | | }); |
| | | locRevise.setExceStatus(CommonExceStatus.COMMON_EXCE_STATUS_UN_EXCE.val); |
| | | |
| | | if (!locReviseService.updateById(locRevise)) { |
| | | throw new CoolException("状态更新失败!!"); |
| | | } |
| | | return items; |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/8/18 |
| | | * @description: 确认调整库存 |
| | | * @version 1.0 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R complete(Long id, Long loginUserId) { |
| | | LocRevise revise = locReviseService.getById(id); |
| | | if (Objects.isNull(revise)) { |
| | | throw new CoolException("调整单不存在!!"); |
| | | } |
| | | if (!revise.getExceStatus().equals(CommonExceStatus.COMMON_EXCE_STATUS_EXCE_ING.val)) { |
| | | throw new CoolException("单据状态未执行或已完成,无法执行完成操作!!"); |
| | | } |
| | | ReviseLog logs = reviseLogService.getOne(new LambdaQueryWrapper<ReviseLog>().eq(ReviseLog::getReviseId, revise.getId())); |
| | | if (Objects.isNull(logs)) { |
| | | throw new CoolException("库存日志不存在!!"); |
| | | } |
| | | List<ReviseLogItem> logItems = reviseLogItemService.list(new LambdaQueryWrapper<ReviseLogItem>().eq(ReviseLogItem::getReviseLogId, logs.getId())); |
| | | Map<Long, List<ReviseLogItem>> listMap = logItems.stream().collect(Collectors.groupingBy(ReviseLogItem::getLocId)); |
| | | listMap.keySet().forEach(items -> { |
| | | Loc loc = locService.getById(items); |
| | | if (Objects.isNull(loc)) { |
| | | throw new CoolException("库位不存在!!"); |
| | | } |
| | | listMap.get(items).forEach(logItem -> { |
| | | LocItem one = locItemService.getOne(new LambdaQueryWrapper<LocItem>() |
| | | .eq(LocItem::getMatnrId, logItem.getMatnrId()) |
| | | .eq(StringUtils.isNotBlank(logItem.getBatch()), LocItem::getBatch, logItem.getBatch()) |
| | | .eq(StringUtils.isNotBlank(logItem.getFieldsIndex()), LocItem::getFieldsIndex, logItem.getFieldsIndex()) |
| | | .eq(LocItem::getLocCode, logItem.getLocCode())); |
| | | if (Objects.isNull(one)) { |
| | | LocItem locDetl = new LocItem(); |
| | | BeanUtils.copyProperties(logItem, locDetl); |
| | | locDetl.setLocId(loc.getId()) |
| | | .setType(OrderType.ORDER_REVISE.type) |
| | | .setLocCode(loc.getCode()) |
| | | .setAnfme(logItem.getReviseQty()) |
| | | .setUpdateBy(loginUserId) |
| | | .setId(null) |
| | | .setCreateBy(loginUserId); |
| | | if (!locItemService.save(locDetl)) { |
| | | throw new CoolException("库存明细保存失败!!"); |
| | | } |
| | | } else { |
| | | one.setAnfme(logItem.getReviseQty()); |
| | | if (!locItemService.updateById(one)) { |
| | | throw new CoolException("库存明细修改失败!!"); |
| | | } |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | revise.setExceStatus(CommonExceStatus.COMMON_EXCE_STATUS_TASK_DONE.val); |
| | | if (!locReviseService.updateById(revise)) { |
| | | throw new CoolException("调整单修改失败!!"); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | } |