| | |
| | | package com.vincent.rsf.server.manager.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.common.domain.BaseParam; |
| | | import com.vincent.rsf.server.common.domain.PageParam; |
| | | import com.vincent.rsf.server.common.domain.PageResult; |
| | | import com.vincent.rsf.server.manager.controller.params.TransferItemParams; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.enums.AsnExceStatus; |
| | | import com.vincent.rsf.server.manager.enums.CheckExceStatus; |
| | | import com.vincent.rsf.server.manager.enums.OrderSourceType; |
| | | import com.vincent.rsf.server.manager.enums.OrderType; |
| | | import com.vincent.rsf.server.manager.mapper.TransferMapper; |
| | | import com.vincent.rsf.server.manager.entity.Transfer; |
| | | import com.vincent.rsf.server.manager.service.AsnOrderItemService; |
| | | import com.vincent.rsf.server.manager.service.TransferItemService; |
| | | import com.vincent.rsf.server.manager.service.TransferService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.vincent.rsf.server.manager.service.WarehouseAreasService; |
| | | 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 java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | @Service("transferService") |
| | | public class TransferServiceImpl extends ServiceImpl<TransferMapper, Transfer> implements TransferService { |
| | | |
| | | @Autowired |
| | | private TransferItemService transferItemService; |
| | | |
| | | @Autowired |
| | | private WarehouseAreasService warehouseAreasService; |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/7/25 |
| | | * @description: 保存调拔单及明细 |
| | | * @version 1.0 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R saveTransfer(TransferItemParams params, Long loginUserId) { |
| | | if (Objects.isNull(params.getTransfer())) { |
| | | throw new CoolException("主单信息不能为空"); |
| | | } |
| | | Transfer transfer = params.getTransfer(); |
| | | if (StringUtils.isBlank(transfer.getType() + "")) { |
| | | throw new CoolException("业务类型不能为空!!"); |
| | | } |
| | | |
| | | String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TRANSFER_ORDER_CODE, transfer); |
| | | if (StringUtils.isBlank(ruleCode)) { |
| | | throw new CoolException("编码规则错误:请检查「SYS_TRANSFER_ORDER_CODE」是否设置正确!!"); |
| | | } |
| | | |
| | | WarehouseAreas orgWarehosue = warehouseAreasService.getById(transfer.getOrgAreaId()); |
| | | if (Objects.isNull(orgWarehosue)) { |
| | | throw new CoolException("所选原库区不存在!!"); |
| | | } |
| | | |
| | | WarehouseAreas tarWarehouse = warehouseAreasService.getById(transfer.getTarAreaId()); |
| | | if (Objects.isNull(tarWarehouse)) { |
| | | throw new CoolException("所选目标库区不存在!!"); |
| | | } |
| | | |
| | | transfer.setCode(ruleCode) |
| | | .setExceStatus(CheckExceStatus.CHECK_ORDER_STATUS_UN_EXCE.val) |
| | | .setSource(OrderSourceType.ORDER_SOURCE_TYPE_SYSTEM.val) |
| | | .setOrgAreaId(orgWarehosue.getId()) |
| | | .setOrgAreaName(orgWarehosue.getName()) |
| | | .setOrgWareId(orgWarehosue.getWarehouseId()) |
| | | .setOrgWareName(orgWarehosue.getWarehouseId$()) |
| | | .setTarAreaId(tarWarehouse.getId()) |
| | | .setTarWareId(tarWarehouse.getWarehouseId()) |
| | | .setTarAreaName(tarWarehouse.getName()) |
| | | .setTarWareName(tarWarehouse.getWarehouseId$()) |
| | | .setUpdateTime(new Date()) |
| | | .setCreateTime(new Date()) |
| | | .setUpdateBy(loginUserId) |
| | | .setCreateBy(loginUserId); |
| | | if (!this.save(transfer)) { |
| | | throw new CoolException("主单保存失败!!"); |
| | | } |
| | | if (params.getItems().isEmpty()) { |
| | | throw new CoolException("收货通知单明细不能为空!!"); |
| | | } |
| | | params.setTransfer(transfer); |
| | | try { |
| | | svaeOrUpdateOrderItem(params, loginUserId); |
| | | } catch (Exception e) { |
| | | throw new CoolException(e.getMessage()); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/7/28 |
| | | * @description: 调拔单据修改 |
| | | * @version 1.0 |
| | | */ |
| | | private void svaeOrUpdateOrderItem(TransferItemParams params, Long loginUserId) { |
| | | Transfer orders = params.getTransfer(); |
| | | params.getItems().forEach(item -> { |
| | | item.put("transferId", orders.getId()); |
| | | item.put("transferCode", orders.getCode()); |
| | | item.put("createBy", loginUserId); |
| | | item.put("updateBy", loginUserId); |
| | | if (!transferItemService.fieldsSave(item, loginUserId)) { |
| | | throw new CoolException("明细保存失败!!"); |
| | | } |
| | | }); |
| | | // List<TransferItem> orderItems = transferItemService.list(new LambdaQueryWrapper<TransferItem>() |
| | | // .eq(TransferItem::getTransferId, params.getTransfer().getId())); |
| | | // Double sum = orderItems.stream().mapToDouble(TransferItem::getAnfme).sum(); |
| | | if (!this.updateById(orders)) { |
| | | throw new CoolException("计划收货数量修改失败!!"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/7/25 |
| | | * @description: 调拔单及明细修改 |
| | | * @version 1.0 |
| | | */ |
| | | @Override |
| | | public R updateTransfer(TransferItemParams params, Long loginUserId) { |
| | | Transfer orders = params.getTransfer(); |
| | | if (Objects.isNull(orders)) { |
| | | throw new CoolException("主单信息不能为空!!"); |
| | | } |
| | | if (Objects.isNull(orders.getId())) { |
| | | throw new CoolException("数据错误:单据ID不能为空!!"); |
| | | } |
| | | if (!this.updateById(orders)) { |
| | | throw new CoolException("主单修改失败!!"); |
| | | } |
| | | if (Objects.isNull(params.getItems()) || params.getItems().isEmpty()) { |
| | | return R.ok("明细参数不能为空!!"); |
| | | } |
| | | |
| | | svaeOrUpdateOrderItem(params, loginUserId); |
| | | |
| | | return R.ok("修改完成!!"); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/7/28 |
| | | * @description: 获取调拔单关联订单 |
| | | * @version 1.0 |
| | | */ |
| | | @Override |
| | | public IPage<WkOrder> transfersPage(PageParam<Transfer, BaseParam> pageParam, QueryWrapper<Transfer> transferQueryWrapper) { |
| | | Transfer one = this.getOne(transferQueryWrapper); |
| | | if (Objects.isNull(one)) { |
| | | throw new CoolException("单据不存在!!"); |
| | | } |
| | | return this.baseMapper.transfersPage(pageParam, one.getId()); |
| | | } |
| | | } |