com.baifendian.swordfish.execserver.parameter.SystemParamManager.java Source code

Java tutorial

Introduction

Here is the source code for com.baifendian.swordfish.execserver.parameter.SystemParamManager.java

Source

/*
 * Copyright (C) 2017 Baifendian Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *          http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.baifendian.swordfish.execserver.parameter;

import static com.baifendian.swordfish.common.utils.DateUtils.format;
import static org.apache.commons.lang.time.DateUtils.addDays;

import com.baifendian.swordfish.dao.enums.ExecType;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;

/**
 * ?? <p>
 */
public class SystemParamManager {

    /**
     * yyyyMMdd
     */
    public static final String DATE_FORMAT = "yyyyMMdd";

    /**
     * yyyyMMddHHmmss
     */
    public static final String TIME_FORMAT = "yyyyMMddHHmmss";

    /**
     * ?? yyyyMMdd
     */
    public static final String BIZ_DATE = "sf.system.bizdate";

    /**
     * ? yyyymmdd? ${sf.system.bizdate} + 1
     */
    public static final String BIZ_CUR_DATE = "sf.system.bizcurdate";

    /**
     * ? yyyyMMddHHmmss
     */
    public static final String CYC_TIME = "sf.system.cyctime";

    /**
     *  id
     */
    public static final String EXEC_ID = "sf.system.execId";

    /**
     *  id
     */
    public static final String JOB_ID = "sf.system.jobId";

    /**
     * ?
     */
    public static Map<String, String> buildSystemParam(ExecType execType, Date time) {
        return buildSystemParam(execType, time, null, null);
    }

    /**
     * ?
     *
     * @param execType ?, , ?, 
     * @param time , ?, , , ?, ?
     * @param execId  id
     * @param jobId  id
     */
    public static Map<String, String> buildSystemParam(ExecType execType, Date time, Integer execId, String jobId) {
        Date bizDate;

        switch (execType) {
        case COMPLEMENT_DATA:
            bizDate = time; // ?
            break;
        case DIRECT:
        case SCHEDULER:
        default:
            bizDate = addDays(time, -1); // ??
        }

        Date bizCurDate = addDays(bizDate, 1); // bizDate + 1 

        Map<String, String> valueMap = new HashMap<>();

        valueMap.put(BIZ_DATE, formatDate(bizDate));
        valueMap.put(BIZ_CUR_DATE, formatDate(bizCurDate));
        valueMap.put(CYC_TIME, formatTime(bizCurDate));

        if (execId != null) {
            valueMap.put(EXEC_ID, Long.toString(execId));
        }

        if (StringUtils.isNotEmpty(jobId)) {
            valueMap.put(JOB_ID, jobId);
        }

        return valueMap;
    }

    /**
     * @param date
     * @return
     */
    private static String formatDate(Date date) {
        return format(date, DATE_FORMAT);
    }

    /**
     * @param date
     * @return
     */
    private static String formatTime(Date date) {
        return format(date, TIME_FORMAT);
    }
}