skyouc
2025-04-10 b5e8045d5f5b5401b696db12f62fdbcc86dc5c5d
rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/ScheduleJobs.java
@@ -6,10 +6,12 @@
import com.vincent.rsf.server.common.utils.CommonUtil;
import com.vincent.rsf.server.common.utils.DateUtils;
import com.vincent.rsf.server.manager.entity.*;
import com.vincent.rsf.server.manager.enums.PakinIOStatus;
import com.vincent.rsf.server.manager.service.*;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -20,6 +22,7 @@
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
 * @author Ryan
@@ -47,6 +50,16 @@
    @Resource
    private SysStockProperties flowProperties;
    @Autowired
    private WaitPakinService waitPakinService;
    @Autowired
    private WaitPakinItemService waitPakinItemService;
    @Autowired
    private WaitPakinLogService waitPakinLogService;
    @Autowired
    private WaitPakinItemLogService waitPakinItemLogService;
    /**
     * @author Ryan
     * @description  根据PO单据生成ASN单,自动生成ASN单为全量生成
@@ -55,9 +68,8 @@
     * @time 2025/3/3 15:44
     */
    @Scheduled(cron = "0 0/05 * * * ?  ")
//    @Scheduled(cron = "0/5 * * * * ?")
    @Transactional(rollbackFor = Exception.class)
    public void genAsnOrder() {
    public synchronized void genAsnOrder() {
        //判断是否开启自动生成ASN单据
        if (!flowProperties.getFlagAutoAsn()) {
            return;
@@ -118,7 +130,7 @@
                        .setPurUnit(item.getUnit())
                        .setMatnrCode(matnr.getCode())
                        .setMaktx(matnr.getName())
                        .setMatnrId(matnr.getId() + "");
                        .setMatnrId(matnr.getId());
                orderItems.add(orderItem);
            });
            if (!asnOrderItemService.saveBatch(orderItems)) {
@@ -131,13 +143,15 @@
            if (!purchaseService.saveOrUpdate(purchase)) {
                throw new CoolException("PO单执行完成后,保存失败!!");
            }
        });
    }
    /**
     * 生成物料标签
     * @author Ryan
     * @description 生成物料标签
     * @param
     * @return
     * @time 2025/3/29 12:35
     */
    @Scheduled(cron = "0 0/05 * * * ?  ")
    @Transactional(rollbackFor = Exception.class)
@@ -163,4 +177,60 @@
        }
    }
    /**
     * @author Ryan
     * @description 组拖历史档
     * @param
     * @return
     * @time 2025/3/29 12:36
     */
//    @Scheduled(cron = "0 0/05 * * * ?  ")
    @Scheduled(cron = "0/25 * * * * ?")
    @Transactional(rollbackFor = Exception.class)
    public void pakinLog() {
        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;
        }
        List<Long> list = pakinIds.stream().map(WaitPakin::getId).collect(Collectors.toList());
        List<WaitPakin> pakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().in(WaitPakin::getId, list));
        if (pakins.isEmpty()) {
            throw new CoolException("组拖单为空!!");
        }
        List<WaitPakinLog> pakinLogs = new ArrayList<>();
        pakins.forEach(pakin ->{
            WaitPakinLog log = new WaitPakinLog();
            BeanUtils.copyProperties(pakin, log);
            log.setPakinId(pakin.getId()).setIoStatus(Short.parseShort("2"));
            pakinLogs.add(log);
        });
        if (!waitPakinLogService.saveBatch(pakinLogs)) {
            throw new CoolException("历史档保存失败!!");
        }
        List<WaitPakinItemLog> itemLogs = new ArrayList<>();
        List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().in(WaitPakinItem::getPakinId, list));
        if (pakinItems.isEmpty()) {
            throw new CoolException("组拖明细为空!!");
        }
        pakinItems.forEach(item -> {
            WaitPakinItemLog itemLog = new WaitPakinItemLog();
            BeanUtils.copyProperties(item, itemLog);
            itemLog.setPakinItemId(item.getId())
                    .setPakinId(item.getPakinId());
            itemLogs.add(itemLog);
        });
        if (!waitPakinItemLogService.saveBatch(itemLogs)) {
            throw new CoolException("历史明细档保存失败!!");
        }
        if (!waitPakinService.removeByIds(list)) {
            throw new CoolException("原单据删除失败!!");
        }
        if (!waitPakinItemService.remove(new LambdaQueryWrapper<WaitPakinItem>().in(WaitPakinItem::getPakinId, list))) {
            throw new CoolException("原单据明细删除失败!!");
        }
    }
}