package com.trs.ggzyexchange.utils;

import cn.hutool.core.util.StrUtil;
import com.trs.ggzyexchange.entity.TenderDetailsVo;
import com.trs.ggzyexchange.enums.CommonConstant;
import org.apache.commons.lang3.ObjectUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TenderDetailsVoUtils {
    public static TenderDetailsVo isNull(TenderDetailsVo tenderDetailsVo){


        String sourceDataKey = tenderDetailsVo.getSourceDataKey();
        tenderDetailsVo.setSourceDataKey(StrUtil.nullToEmpty(sourceDataKey));

        String projectCode = tenderDetailsVo.getProjectCode();
        tenderDetailsVo.setProjectCode(StrUtil.nullToEmpty(projectCode));

        String projectName = tenderDetailsVo.getProjectName();
        tenderDetailsVo.setProjectName(StrUtil.nullToEmpty(projectName));

        String tenderProjectCode = tenderDetailsVo.getTenderProjectCode();
        tenderDetailsVo.setTenderProjectCode(StrUtil.nullToEmpty(tenderProjectCode));

        String noticeNature = tenderDetailsVo.getNoticeNature();
        tenderDetailsVo.setNoticeNature(StrUtil.nullToEmpty(noticeNature));

        String noticeNatureName = tenderDetailsVo.getNoticeNatureName();
        tenderDetailsVo.setNoticeNatureName(StrUtil.nullToEmpty(noticeNatureName));

        String noticeName = tenderDetailsVo.getNoticeName();
        tenderDetailsVo.setNoticeName(StrUtil.nullToEmpty(noticeName));

        String noticeContent = tenderDetailsVo.getNoticeContent();
        tenderDetailsVo.setNoticeContent(StrUtil.nullToEmpty(noticeContent));

        String noticeSendTime = tenderDetailsVo.getNoticeSendTime();
        try {
            noticeSendTime = passDate(noticeSendTime);
        } catch (ParseException e) {
            e.printStackTrace();
            noticeSendTime = CommonConstant.SET_TIME;
        }
        tenderDetailsVo.setNoticeSendTime(noticeSendTime);

        String regionCode = tenderDetailsVo.getRegionCode();
        tenderDetailsVo.setRegionCode(StrUtil.nullToEmpty(regionCode));

        String regionName = tenderDetailsVo.getRegionName();
        tenderDetailsVo.setRegionName(StrUtil.nullToEmpty(regionName));

        String industriesTypeCode = tenderDetailsVo.getIndustriesTypeCode();
        tenderDetailsVo.setIndustriesTypeCode(StrUtil.nullToEmpty(industriesTypeCode));

        String industriesTypeName = tenderDetailsVo.getIndustriesTypeName();
        tenderDetailsVo.setIndustriesTypeName(StrUtil.nullToEmpty(industriesTypeName));

        String platformCode = tenderDetailsVo.getPlatformCode();
        tenderDetailsVo.setPlatformCode(StrUtil.nullToEmpty(platformCode));

        String platformName = tenderDetailsVo.getPlatformName();
        tenderDetailsVo.setPlatformName(StrUtil.nullToEmpty(platformName));

        String noticeTypeCode = tenderDetailsVo.getNoticeTypeCode();
        tenderDetailsVo.setNoticeTypeCode(StrUtil.nullToEmpty(noticeTypeCode));

        String noticeTypeName = tenderDetailsVo.getNoticeTypeName();
        tenderDetailsVo.setNoticeTypeName(StrUtil.nullToEmpty(noticeTypeName));

        String transactionTypeCode = tenderDetailsVo.getTransactionTypeCode();
        tenderDetailsVo.setTransactionTypeCode(StrUtil.nullToEmpty(transactionTypeCode));

        String transactionTypeName = tenderDetailsVo.getTransactionTypeName();
        tenderDetailsVo.setTransactionTypeName(StrUtil.nullToEmpty(transactionTypeName));

        String bulletinTypeCode = tenderDetailsVo.getBulletinTypeCode();
        tenderDetailsVo.setBulletinTypeCode(StrUtil.nullToEmpty(bulletinTypeCode));

        String bulletinTypeName = tenderDetailsVo.getBulletinTypeName();
        tenderDetailsVo.setBulletinTypeName(StrUtil.nullToEmpty(bulletinTypeName));

        String bulletinDuty = tenderDetailsVo.getBulletinDuty();
        tenderDetailsVo.setBulletinDuty(StrUtil.nullToEmpty(bulletinDuty));

        String dataSourceCode = tenderDetailsVo.getDataSourceCode();
        tenderDetailsVo.setDataSourceCode(StrUtil.nullToEmpty(dataSourceCode));

        String dataSourceName = tenderDetailsVo.getDataSourceName();
        tenderDetailsVo.setDataSourceName(StrUtil.nullToEmpty(dataSourceName));

        String noticeBidNum = tenderDetailsVo.getNoticeBidNum();
        tenderDetailsVo.setNoticeBidNum(StrUtil.nullToEmpty(noticeBidNum));

        String bidSectionCodes = tenderDetailsVo.getBidSectionCodes();
        tenderDetailsVo.setBidSectionCodes(StrUtil.nullToEmpty(bidSectionCodes));

        String docGetStartTime = tenderDetailsVo.getDocGetStartTime();
        try {
            docGetStartTime = passDate(docGetStartTime);
        } catch (ParseException e) {
            e.printStackTrace();
            docGetStartTime = CommonConstant.SET_TIME;
        }
        tenderDetailsVo.setDocGetStartTime(docGetStartTime);

        String docGetEndTime = tenderDetailsVo.getDocGetEndTime();
        try {
            docGetEndTime = passDate(docGetEndTime);
        } catch (ParseException e) {
            e.printStackTrace();
            docGetEndTime = CommonConstant.SET_TIME;
        }
        tenderDetailsVo.setDocGetEndTime(docGetEndTime);
        String bidDocReferEndTime = tenderDetailsVo.getBidDocReferEndTime();
        try {
            bidDocReferEndTime = passDate(bidDocReferEndTime);
        } catch (ParseException e) {
            e.printStackTrace();
            bidDocReferEndTime = CommonConstant.SET_TIME;
        }
        tenderDetailsVo.setBidDocReferEndTime(bidDocReferEndTime);

        String bidOpenTime = tenderDetailsVo.getBidOpenTime();
        try {
            bidOpenTime = passDate(bidOpenTime);
        } catch (ParseException e) {
            e.printStackTrace();
            bidOpenTime = CommonConstant.SET_TIME;
        }
        tenderDetailsVo.setBidOpenTime(bidOpenTime);

        String validPeriod = tenderDetailsVo.getValidPeriod();
        tenderDetailsVo.setValidPeriod(StrUtil.nullToEmpty(validPeriod));
        String clarifyTime = tenderDetailsVo.getClarifyTime();
        try {
            clarifyTime = passDate(clarifyTime);
        } catch (ParseException e) {
            e.printStackTrace();
            clarifyTime = CommonConstant.SET_TIME;
        }
        tenderDetailsVo.setClarifyTime(clarifyTime);

        String submitTime = tenderDetailsVo.getSubmitTime();
        try {
            submitTime = passDate(submitTime);
        } catch (ParseException e) {
            e.printStackTrace();
            submitTime = CommonConstant.SET_TIME;
        }
        tenderDetailsVo.setSubmitTime(submitTime);

        String bidOpeningAddress = tenderDetailsVo.getBidOpeningAddress();
        tenderDetailsVo.setBidOpeningAddress(StrUtil.nullToEmpty(bidOpeningAddress));


        String bidOpeningTime = tenderDetailsVo.getBidOpeningTime();
        try {
            bidOpeningTime = passDate(bidOpeningTime);
        } catch (ParseException e) {
            e.printStackTrace();
            bidOpeningTime = CommonConstant.SET_TIME;
        }
        tenderDetailsVo.setBidOpeningTime(bidOpeningTime);

        String bidFinishTime = tenderDetailsVo.getBidFinishTime();
        try {
            bidFinishTime = passDate(bidFinishTime);
        } catch (ParseException e) {
            e.printStackTrace();
            bidFinishTime = CommonConstant.SET_TIME;
        }
        tenderDetailsVo.setBidFinishTime(bidFinishTime);

        String file = tenderDetailsVo.getFile();
        tenderDetailsVo.setFile(StrUtil.nullToEmpty(file));
        return tenderDetailsVo;
    }

    public static String passDate(String date) throws ParseException {
        SimpleDateFormat sdfylmldlhlmls = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat sdfymdhms = new SimpleDateFormat("yyyyMMddHHmmss");
        SimpleDateFormat sdfymdhm = new SimpleDateFormat("yyyyMMddHHmm");
        SimpleDateFormat sdfymd = new SimpleDateFormat("yyyyMMdd");
        String newDate = CommonConstant.SET_TIME;
        if(!ObjectUtils.isEmpty(date)){
            if(date.length() == 14){
                Date parse = sdfymdhms.parse(date);
                newDate = sdfylmldlhlmls.format(parse);
            }
            if(date.length() == 12){
                Date parse = sdfymdhm.parse(date);
                newDate = sdfylmldlhlmls.format(parse);
            }
            if(date.length() == 8){
                Date parse = sdfymd.parse(date);
                newDate = sdfylmldlhlmls.format(parse);
            }
        }
        return newDate;
    }

}
