package com.ruoyi.wms.service;

import com.cmeim.common.core.utils.DateUtil;
import com.ruoyi.wms.po.ContainerInfo;
import com.ruoyi.wms.repository.ContainerInfoRepository;
import com.ruoyi.wms.repository.ContainerRecoderRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 李俊辉
 * @version 1.0
 * date: 2023/6/28
 */
@Service
@Slf4j
public class ContainerService {
    @Autowired
    private ContainerInfoRepository containerInfoRepository;
    @Autowired
    private ContainerRecoderRepository containerRecoderRepository;

    private String hour="8";

    public List<ContainerInfo> queryGreaterThanEightHours()
    {
        List<ContainerInfo> all = containerInfoRepository.findAll();
        List<ContainerInfo> containerInfoList = new ArrayList<>();
        for (ContainerInfo containerInfo : all) {
            if (containerInfo.getInstoreTime() == null) {
                continue;
            }
            //筛出生产任务单号为空的箱子
            if (containerInfo.getProductionTask() == null) {
                continue;
            }
            //筛出状态不为非空空箱在库的箱子
            if (containerInfo.getContainerStatus() != 30) {
                continue;
            }
            Long end = DateUtil.string2Date(DateUtil.getCurrentDate(), DateUtil.PATTERN_yyyyMMddHHmmss).getTime();
            Long start = DateUtil.string2Date(containerInfo.getInstoreTime(), DateUtil.PATTERN_yyyyMMddHHmmss).getTime();
            long count = end - start;
            int i = Integer.parseInt(hour);
            int j = 3600000;
            long x = (long)i*j;
            //超过8小时则筛选出来出库
            if (count >= x) {
                containerInfoList.add(containerInfo);
            }
        }
        return containerInfoList;
    }
}
