package com.lantone.qc.kernel.catalogue.dutyshiftsystem;

import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.kernel.util.CatalogueUtil;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import com.lantone.qc.pub.model.doc.transferrecord.TransferIntoDoc;
import com.lantone.qc.pub.model.doc.transferrecord.TransferOutDoc;
import com.lantone.qc.pub.model.doc.transferrecord.TransferRecordDoc;
import com.lantone.qc.pub.util.ListUtil;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ClassName : DUT0598
 * @Description : 接科记录未在24h内完成
 * @Author : 胡敬
 * @Date: 2020-03-30 15:06
 */
@Component
public class DUT0598 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        TransferRecordDoc transferRecordDoc = inputInfo.getTransferRecordDocs();
        if (transferRecordDoc == null) {
            return;
        }
        List<TransferIntoDoc> transferIntoDocs = transferRecordDoc.getTransferIntoDocs();
        String rollInRecordDateStr = "", recordDateStr = "";
        for (TransferIntoDoc transferIntoDoc : transferIntoDocs) {
            Map<String, String> transferOutStructureMap = transferIntoDoc.getStructureMap();
            rollInRecordDateStr = transferOutStructureMap.get("转科日期");
            recordDateStr = transferOutStructureMap.get("记录日期");
            if (CatalogueUtil.isEmpty(rollInRecordDateStr) || CatalogueUtil.isEmpty(recordDateStr)) {
                continue;
            }
            Date rollOutRecordDate = StringUtil.parseDateTime(rollInRecordDateStr);
            Date recordDate = StringUtil.parseDateTime(recordDateStr);
            if (rollOutRecordDate != null && recordDate != null && rollOutRecordDate.before(recordDate)) {
                boolean compareTime = CatalogueUtil.compareTime(rollOutRecordDate, recordDate, (long) 24 * 60);
                if (compareTime) {
                    status.set("-1");
                    return;
                }
            }
        }
    }
}