| | |
| | | package com.vincent.rsf.server.manager.schedules; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.vincent.rsf.framework.common.Cools; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.api.entity.dto.ReceiptDetlsDto; |
| | | import com.vincent.rsf.server.common.config.SysStockProperties; |
| | | import com.vincent.rsf.server.common.utils.CommonUtil; |
| | | import com.vincent.rsf.server.common.utils.DateUtils; |
| | | import com.vincent.rsf.server.manager.controller.params.WarehouseAreaParam; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.enums.AsnExceStatus; |
| | | import com.vincent.rsf.server.manager.enums.POExceStatus; |
| | | import com.vincent.rsf.server.manager.enums.PakinIOStatus; |
| | | import com.vincent.rsf.server.manager.enums.WarehouseAreasType; |
| | | import com.vincent.rsf.server.manager.service.*; |
| | | import com.vincent.rsf.server.manager.service.impl.WarehouseAreasItemServiceImpl; |
| | | import com.vincent.rsf.server.system.constant.GlobalConfigCode; |
| | | import com.vincent.rsf.server.system.constant.SerialRuleCode; |
| | | import com.vincent.rsf.server.system.entity.Config; |
| | | import com.vincent.rsf.server.system.service.ConfigService; |
| | | import com.vincent.rsf.server.system.utils.SerialRuleUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | private PurchaseService purchaseService; |
| | | @Autowired |
| | | private PurchaseItemService purchaseItemService; |
| | | |
| | | @Autowired |
| | | private AsnOrderService asnOrderService; |
| | | |
| | | @Autowired |
| | | private MatnrService matnrService; |
| | | |
| | | @Autowired |
| | | private AsnOrderItemService asnOrderItemService; |
| | | |
| | | @Resource |
| | | private SysStockProperties flowProperties; |
| | | @Autowired |
| | |
| | | private WaitPakinLogService waitPakinLogService; |
| | | @Autowired |
| | | private WaitPakinItemLogService waitPakinItemLogService; |
| | | @Autowired |
| | | private ConfigService configService; |
| | | @Autowired |
| | | private WarehouseAreasService warehouseAreasService; |
| | | @Autowired |
| | | private WarehouseAreasItemServiceImpl warehouseAreasItemService; |
| | | |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @description 根据PO单据生成ASN单,自动生成ASN单为全量生成 |
| | | * @throws |
| | | * @date 2025/5/9 |
| | | * @description: 直接组托开关为true,将收货单直接加入临时库存 |
| | | * @version 1.0 |
| | | */ |
| | | // @Scheduled(cron = "0 0/05 * * * ? ") |
| | | @Scheduled(cron = "0/25 * * * * ?") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public synchronized void IgnoreReceipt() { |
| | | Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.DIRECT_WAIT_PAKIN)); |
| | | if (Objects.isNull(config)) { |
| | | return; |
| | | } |
| | | |
| | | if (!Boolean.parseBoolean(config.getVal())) { |
| | | return; |
| | | } |
| | | List<AsnOrder> orders = asnOrderService.list(new LambdaQueryWrapper<AsnOrder>().eq(AsnOrder::getExceStatus, AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val)); |
| | | if (!orders.isEmpty()) { |
| | | for (AsnOrder order : orders) { |
| | | List<AsnOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getAsnId, order.getId())); |
| | | if (orderItems.isEmpty()) { |
| | | return; |
| | | } |
| | | List<WarehouseAreasItem> items = new ArrayList<>(); |
| | | for (AsnOrderItem item : orderItems) { |
| | | WarehouseAreas one = warehouseAreasService.getOne(new LambdaQueryWrapper<WarehouseAreas>() |
| | | .eq(WarehouseAreas::getType, WarehouseAreasType.WAREHOUSE_AREAS_TYPE_RECEIPT.type), false); |
| | | Long areaId = Objects.isNull(one) ? null : one.getId(); |
| | | String areaName = Objects.isNull(one) ? null : one.getName(); |
| | | |
| | | WarehouseAreasItem param = new WarehouseAreasItem(); |
| | | BeanUtils.copyProperties(item, param); |
| | | param.setAreaId(one.getId()) |
| | | .setAsnCode(order.getCode()) |
| | | .setAreaId(areaId) |
| | | .setAreaName(areaName) |
| | | .setAsnId(order.getId()); |
| | | items.add(param); |
| | | Matnr matnr = matnrService.getOne(new LambdaQueryWrapper<Matnr>().eq(Matnr::getId, item.getMatnrId())); |
| | | if (Objects.isNull(matnr)) { |
| | | throw new CoolException("物料不存在!!"); |
| | | } |
| | | //更新收货区库存 |
| | | extracted(one, item, order, matnr); |
| | | |
| | | if (!asnOrderItemService.update(new LambdaUpdateWrapper<AsnOrderItem>().set(AsnOrderItem::getQty, item.getAnfme()).eq(AsnOrderItem::getId, item.getId()))) { |
| | | throw new CoolException("收货单明细完成数量修改失败!!"); |
| | | } |
| | | } |
| | | // if (!warehouseAreasItemService.saveBatch(items)) { |
| | | // throw new CoolException("收货单保存至收货区执行失败!!"); |
| | | // } |
| | | |
| | | if (!asnOrderService.update(new LambdaUpdateWrapper<AsnOrder>() |
| | | .set(AsnOrder::getQty, order.getAnfme()) |
| | | .set(AsnOrder::getExceStatus, AsnExceStatus.ASN_EXCE_STATUS_RECEIPT_DONE.val) |
| | | .eq(AsnOrder::getId, order.getId()))) { |
| | | throw new CoolException("收货单状态修改失败!!"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/5/12 |
| | | * @description: 收货区库存更新 |
| | | * @version 1.0 |
| | | */ |
| | | private void extracted(WarehouseAreas areasItem, AsnOrderItem orderItem, AsnOrder asnOrder, Matnr matnr) { |
| | | WarehouseAreasItem item = new WarehouseAreasItem(); |
| | | item.setTrackCode(orderItem.getBarcode()) |
| | | .setAreaName(areasItem.getName()) |
| | | .setAreaId(areasItem.getId()) |
| | | .setAsnItemId(orderItem.getId()) |
| | | .setAsnCode(asnOrder.getCode()) |
| | | .setAsnId(asnOrder.getId()) |
| | | .setProdTime(orderItem.getProdTime()) |
| | | //库存单位为最小单位 |
| | | .setUnit(orderItem.getStockUnit()) |
| | | .setStockUnit(orderItem.getStockUnit()) |
| | | .setMatnrCode(matnr.getCode()) |
| | | .setAnfme(orderItem.getAnfme()) |
| | | .setMatnrId(matnr.getId()) |
| | | .setIsptResult(orderItem.getIsptResult()) |
| | | .setMaktx(matnr.getName()) |
| | | .setSplrBatch(orderItem.getSplrBatch()) |
| | | .setWeight(matnr.getWeight()) |
| | | .setFieldsIndex(orderItem.getFieldsIndex()) |
| | | .setShipperId(matnr.getShipperId()); |
| | | |
| | | LambdaQueryWrapper<WarehouseAreasItem> queryWrapper = new LambdaQueryWrapper<WarehouseAreasItem>() |
| | | .eq(WarehouseAreasItem::getMatnrCode, orderItem.getMatnrCode()) |
| | | .eq(!Cools.isEmpty(orderItem.getFieldsIndex()), WarehouseAreasItem::getFieldsIndex, orderItem.getFieldsIndex()) |
| | | .eq(WarehouseAreasItem::getAsnCode, orderItem.getAsnCode()) |
| | | .eq(StringUtils.isNotBlank(orderItem.getSplrBatch()), WarehouseAreasItem::getSplrBatch, orderItem.getSplrBatch()); |
| | | if (Objects.isNull(orderItem.getIsptResult())) { |
| | | queryWrapper.isNull(WarehouseAreasItem::getIsptResult); |
| | | } else { |
| | | queryWrapper.eq(WarehouseAreasItem::getIsptResult, orderItem.getIsptResult()); |
| | | } |
| | | WarehouseAreasItem serviceOne = warehouseAreasItemService.getOne(queryWrapper); |
| | | if (!Objects.isNull(serviceOne)) { |
| | | item.setId(serviceOne.getId()); |
| | | item.setAnfme(item.getAnfme() + serviceOne.getAnfme()); |
| | | } |
| | | //未质检 |
| | | if (!warehouseAreasItemService.saveOrUpdate(item)) { |
| | | throw new CoolException("收货失败!!"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @return |
| | | * @throws |
| | | * @author Ryan |
| | | * @description 根据PO单据生成ASN单, 自动生成ASN单为全量生成 |
| | | * @time 2025/3/3 15:44 |
| | | */ |
| | | @Scheduled(cron = "0 0/05 * * * ? ") |
| | |
| | | return; |
| | | } |
| | | //获取未生成ASN单据 |
| | | List<Purchase> purchases = purchaseService.list(new LambdaQueryWrapper<Purchase>().eq(Purchase::getStatus, 0)); |
| | | List<Purchase> purchases = purchaseService.list(new LambdaQueryWrapper<Purchase>().eq(Purchase::getExceStatus, 0)); |
| | | //PO单为空,直接跳出当前任务 |
| | | if (purchases.isEmpty()) { |
| | | return; |
| | |
| | | } |
| | | |
| | | //任务执行完成,修改已完成数量和PO单执行状态 |
| | | purchase.setQty(purchase.getAnfme()).setStatus(1); |
| | | purchase.setQty(purchase.getAnfme()) |
| | | .setExceStatus(POExceStatus.PO_EXCE_STATUS_EXCE_ING.val); |
| | | |
| | | if (!purchaseService.saveOrUpdate(purchase)) { |
| | | throw new CoolException("PO单执行完成后,保存失败!!"); |
| | |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @description 生成物料标签 |
| | | * @param |
| | | * @return |
| | | * @author Ryan |
| | | * @description 生成物料标签 |
| | | * @time 2025/3/29 12:35 |
| | | */ |
| | | @Scheduled(cron = "0 0/05 * * * ? ") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void generateMatnrLabel() { |
| | | List<AsnOrderItem> list = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>() |
| | | .isNull(AsnOrderItem::getTrackCode) |
| | | .isNull(AsnOrderItem::getTrackCode) |
| | | .select(AsnOrderItem::getId)); |
| | | if (Objects.isNull(list) || list.isEmpty()) { |
| | | return; |
| | |
| | | if (StringUtils.isBlank(trackCode)) { |
| | | throw new CoolException("单据跟踪码生成失败:请检查「sys_asn_mantr_label」是否配置完成!!"); |
| | | } |
| | | item.setTrackCode(trackCode); |
| | | // item.setTrackCode(trackCode); |
| | | item.setBarcode(trackCode); |
| | | items.add(item); |
| | | }); |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @description 组拖历史档 |
| | | * @param |
| | | * @return |
| | | * @author Ryan |
| | | * @description 组拖历史档 |
| | | * @time 2025/3/29 12:36 |
| | | */ |
| | | @Scheduled(cron = "0/5 * * * * ?") |
| | | @Scheduled(cron = "0/25 * * * * ?") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void pakinLog() { |
| | | List<WaitPakin> pakinIds = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getIoStatus, 2).select(WaitPakin::getId)); |
| | | List<WaitPakin> pakinIds = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>() |
| | | .eq(WaitPakin::getIoStatus, Short.valueOf(PakinIOStatus.PAKIN_IO_STATUS_TASK_DONE.val)) |
| | | .select(WaitPakin::getId)); |
| | | if (pakinIds.isEmpty()) { |
| | | return; |
| | | } |
| | |
| | | throw new CoolException("组拖单为空!!"); |
| | | } |
| | | List<WaitPakinLog> pakinLogs = new ArrayList<>(); |
| | | pakins.forEach(pakin ->{ |
| | | pakins.forEach(pakin -> { |
| | | WaitPakinLog log = new WaitPakinLog(); |
| | | BeanUtils.copyProperties(pakin, log); |
| | | log.setPakinId(pakin.getId()).setIoStatus(Short.parseShort("2")); |
| | |
| | | if (!waitPakinItemLogService.saveBatch(itemLogs)) { |
| | | throw new CoolException("历史明细档保存失败!!"); |
| | | } |
| | | if (!waitPakinService.removeByIds(pakins)) { |
| | | if (!waitPakinService.removeByIds(list)) { |
| | | throw new CoolException("原单据删除失败!!"); |
| | | } |
| | | if (!waitPakinItemService.removeByIds(pakinItems)) { |
| | | if (!waitPakinItemService.remove(new LambdaQueryWrapper<WaitPakinItem>().in(WaitPakinItem::getPakinId, list))) { |
| | | throw new CoolException("原单据明细删除失败!!"); |
| | | } |
| | | } |