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.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 : DUT0597
 * @Description : 转出记录未在转出前完成
 * @Author : 胡敬
 * @Date: 2020-03-30 15:06
 */
@Component
public class DUT0597 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        TransferRecordDoc transferRecordDoc = inputInfo.getTransferRecordDocs();
        if (transferRecordDoc == null) {
            return;
        }
        String rollOutRecordDateStr = "", recordDateStr = "";
        List<TransferOutDoc> transferOutDocs = transferRecordDoc.getTransferOutDocs();
        for (TransferOutDoc transferOutDoc : transferOutDocs) {
            Map<String, String> transferOutStructureMap = transferOutDoc.getStructureMap();
            rollOutRecordDateStr = transferOutStructureMap.get("转科日期");
            recordDateStr = transferOutStructureMap.get("记录日期");
            if (CatalogueUtil.isEmpty(rollOutRecordDateStr) || CatalogueUtil.isEmpty(recordDateStr)) {
                continue;
            }
            Date rollOutRecordDate = StringUtil.parseDateTime(rollOutRecordDateStr);
            Date recordDate = StringUtil.parseDateTime(recordDateStr);
            if (rollOutRecordDate != null && recordDate != null && rollOutRecordDate.before(recordDate)) {
                status.set("-1");
                return;
            }
        }

    }
}