| | |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.api.controller.params.*; |
| | | import com.vincent.rsf.server.api.entity.dto.*; |
| | | import com.vincent.rsf.server.api.entity.enums.OrderType; |
| | | import com.vincent.rsf.server.api.entity.enums.OrderWorkType; |
| | | import com.vincent.rsf.server.api.service.MobileService; |
| | | import com.vincent.rsf.server.common.config.ConfigProperties; |
| | |
| | | import com.vincent.rsf.server.system.mapper.TenantMapper; |
| | | import com.vincent.rsf.server.system.mapper.UserMapper; |
| | | import com.vincent.rsf.server.system.service.FieldsItemService; |
| | | import com.vincent.rsf.server.system.service.FieldsService; |
| | | import com.vincent.rsf.server.system.service.UserLoginService; |
| | | import com.vincent.rsf.server.system.utils.SerialRuleUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | List<ReceiptDetlsDto> receipts = params.getReceipts(); |
| | | List<WarehouseAreasItem> allOrders = new ArrayList<>(); |
| | | |
| | | double receiptQty = receipts.stream().mapToDouble(ReceiptDetlsDto::getReceiptQty).sum(); |
| | | Double receiptQty = receipts.stream().mapToDouble(ReceiptDetlsDto::getReceiptQty).sum(); |
| | | |
| | | String asnCode = receipts.stream().findFirst().get().getAsnCode(); |
| | | |
| | |
| | | if (Objects.isNull(asnOrder)) { |
| | | throw new CoolException("数据错误:主单不存在!!"); |
| | | } |
| | | asnOrder.setQty(receiptQty); |
| | | /**收货数量累加,1. 会出超收情况 2. 会有收货不足情况*/ |
| | | Double rcptedQty = asnOrder.getQty() + receiptQty; |
| | | asnOrder.setQty(rcptedQty); |
| | | |
| | | if (!asnOrderMapper.updateById(asnOrder)) { |
| | | throw new CoolException("已收货数量修改失败!!"); |
| | |
| | | if (!warehouseAreasItemService.saveBatch(allOrders)) { |
| | | throw new CoolException("收货失败!!"); |
| | | } |
| | | |
| | | //获取采购数量 |
| | | double purQty = receipts.stream().mapToDouble(ReceiptDetlsDto::getPurQty).sum(); |
| | | |
| | | BigDecimal subtract = BigDecimal.valueOf(receiptQty).subtract(BigDecimal.valueOf(purQty)); |
| | | //判断已收货数量是否小于等于采购数量 |
| | | if (subtract.compareTo(new BigDecimal("0.0")) <= 0) { |
| | | asnOrder.setRleStatus(Short.valueOf("1")); |
| | | //日志表操作 |
| | | operateOrderLogs(asnOrder); |
| | | } |
| | | |
| | | // //获取采购数量 |
| | | // double purQty = receipts.stream().mapToDouble(ReceiptDetlsDto::getPurQty).sum(); |
| | | // |
| | | // BigDecimal subtract = BigDecimal.valueOf(receiptQty).subtract(BigDecimal.valueOf(purQty)); |
| | | // //判断已收货数量是否小于等于采购数量 |
| | | // if (subtract.compareTo(new BigDecimal("0.0")) <= 0) { |
| | | // asnOrder.setRleStatus(Short.valueOf("1")); |
| | | // //日志表操作 |
| | | // operateOrderLogs(asnOrder); |
| | | // } |
| | | return R.ok("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @description 删除原主单及明细,加入历史档 |
| | | * @param |
| | | * @return |
| | | * @time 2025/3/19 19:53 |
| | | */ |
| | | private void operateOrderLogs(AsnOrder asnOrder) { |
| | | if (!asnOrderMapper.removeById(asnOrder.getId())) { |
| | | throw new CoolException("原单据删除失败!!"); |
| | | } |
| | | |
| | | AsnOrderLog orderLog = new AsnOrderLog(); |
| | | BeanUtils.copyProperties(asnOrder, orderLog); |
| | | orderLog.setAsnId(asnOrder.getId()); |
| | | |
| | | if (!asnOrderLogService.save(orderLog)) { |
| | | throw new CoolException("主单历史档添加失败!!"); |
| | | } |
| | | |
| | | List<AsnOrderItemLog> logs = new ArrayList<>(); |
| | | List<AsnOrderItem> items = asnOrderItemMapper.selectList(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getAsnId, asnOrder.getId())); |
| | | items.forEach(item -> { |
| | | AsnOrderItemLog itemLog = new AsnOrderItemLog(); |
| | | BeanUtils.copyProperties(item, itemLog); |
| | | itemLog.setAsnItemId(itemLog.getId()) |
| | | .setAsnId(item.getAsnId()); |
| | | logs.add(itemLog); |
| | | }); |
| | | |
| | | if (!asnOrderItemLogService.saveBatch(logs)) { |
| | | throw new CoolException("通知单明细历史档保存失败!!"); |
| | | } |
| | | |
| | | if (asnOrderItemMapper.delete(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getAsnId, asnOrder.getId())) < 1) { |
| | | throw new CoolException("原单据明细删除失败!!"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @author Ryan |
| | |
| | | if (!waitPakins.isEmpty()) { |
| | | throw new CoolException("拖盘已使用!!"); |
| | | } |
| | | List<AsnOrderItem> orderItems = asnOrderItemMapper.selectList(new LambdaQueryWrapper<AsnOrderItem>() |
| | | AsnOrderItem orderItems = asnOrderItemMapper.selectOne(new LambdaQueryWrapper<AsnOrderItem>() |
| | | .eq(AsnOrderItem::getAsnId, asnOrders.getId()) |
| | | .eq(AsnOrderItem::getMatnrCode, params.getMatnrCode())); |
| | | if (orderItems.isEmpty()) { |
| | | throw new CoolException("单据明细不存在!!"); |
| | | if (Objects.isNull(orderItems)) { |
| | | return R.ok(null); |
| | | } |
| | | List<AsnOrderItem> stocks = new ArrayList<>(); |
| | | orderItems.forEach(item -> { |
| | | item.setBarcode(params.getBarcode()); |
| | | stocks.add(item); |
| | | }); |
| | | return R.ok(stocks); |
| | | orderItems.setBarcode(params.getBarcode()); |
| | | |
| | | return R.ok(orderItems); |
| | | } |
| | | |
| | | /** |
| | | * 人工上架入库 |
| | | * |
| | | * @param params |
| | | * @param loginUserId |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R publicToStock(PublicToStockParams params) { |
| | | public R publicToStock(PublicToStockParams params, Long loginUserId) { |
| | | if (Objects.isNull(params.getLocCode()) || StringUtils.isBlank(params.getLocCode())) { |
| | | throw new CoolException("库位不能为空!!"); |
| | | } |
| | |
| | | throw new CoolException("单据明细不能为空!!"); |
| | | } |
| | | Long OrderId = params.getItemList().stream().findFirst().get().getAsnId(); |
| | | AsnOrder order = asnOrderMapper.getOne(new LambdaQueryWrapper<AsnOrder>().eq(AsnOrder::getId, OrderId)); |
| | | /**获取平库订单*/ |
| | | AsnOrder order = asnOrderMapper.getOne(new LambdaQueryWrapper<AsnOrder>() |
| | | .eq(AsnOrder::getId, OrderId) |
| | | .eq(AsnOrder::getType, OrderType.ORDER_PLAT_IN.type)); |
| | | if (Objects.isNull(order)) { |
| | | throw new CoolException("单据不存在!!"); |
| | | } |
| | |
| | | stock.setAsnId(OrderId).setAsnCode(order.getCode()); |
| | | if (!Objects.isNull(order.getPoCode()) && StringUtils.isNotBlank(order.getPoCode())) { |
| | | Purchase purchase = purchaseService.getOne(new LambdaQueryWrapper<Purchase>().eq(Purchase::getCode, order.getPoCode())); |
| | | if (!Objects.isNull(purchase)) { |
| | | stock.setPlatOrderNo(purchase.getPlatCode()).setPlatToken(purchase.getPlatId()); |
| | | } |
| | | } |
| | | String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_STOCK_CODE, null); |
| | | if (StringUtils.isBlank(ruleCode)) { |
| | |
| | | if (!stockService.save(stock)) { |
| | | throw new CoolException("库存保存失败!!"); |
| | | } |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, params.getLocCode())); |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, params.getLocCode())); |
| | | if (Objects.isNull(loc)) { |
| | | throw new CoolException("库位不存在!!"); |
| | | } |
| | |
| | | stockItem.setAsnItemId(orderItem.getId()) |
| | | .setBarcode(orderItem.getBarcode()) |
| | | .setLocId(loc.getId()) |
| | | .setUpdateBy(loginUserId) |
| | | .setId(null) |
| | | .setStockId(stock.getId()); |
| | | stockItems.add(stockItem); |
| | |
| | | throw new CoolException("拖盘任务不存在!!"); |
| | | } |
| | | List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId())); |
| | | if (!taskItems.isEmpty()) { |
| | | if (taskItems.isEmpty()) { |
| | | throw new CoolException("拖盘任务明细不存在!!"); |
| | | } |
| | | TaskQueueDto queueDto = new TaskQueueDto(); |