⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autogeneratepreadviceprocessor.java

📁 对于定时触发的backend service
💻 JAVA
字号:
/*
 * Created on 2005-3-29
 *
 * OOCL
 */
package com.oocllogistics.threepl.preadvice.service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import com.oocllogistics.common.base.basic.domain.BusinessType;
import com.oocllogistics.common.base.basic.domain.MilestoneConstants;
import com.oocllogistics.common.base.supp.domain.geo.AbstractLocation;
import com.oocllogistics.common.llcp.task.service.exception.TaskServiceException;
import com.oocllogistics.common.llcp.task.service.taskGenerator.MilestoneSet;
import com.oocllogistics.common.subapp.srr.domain.PreAdviceReceivingOption;
import com.oocllogistics.common.subapp.srr.domain.exception.SpecTimeMalformException;
import com.oocllogistics.common.util.DateHelper;
import com.oocllogistics.common.util.task.SessionContext;
import com.oocllogistics.framework.util.exception.ServiceException;
import com.oocllogistics.threepl.preadvice.domain.PreAdviceConstants;
import com.oocllogistics.threepl.preadvice.service.exception.UnSupportGenerateOptionException;
import com.oocllogistics.threepl.shipment.domain.AbstractSO;

/**
 * Class helps to auto-generate pre-advice when SO confirm/revise/cancel
 * 
 * @author Joy Ge
 * @version 2.0
 */
public class AutoGeneratePreAdviceProcessor {

	private static final String logFileName = "AutoGeneratePreAdvice";

	/**
	 * Generate corresponding task when so acknowleged or confirmed
	 * 
	 * @param so
	 * @param genOption
	 * @param ds
	 * @throws SpecTimeMalformException
	 * @throws RuleNotFoundException
	 * @throws MissingInformationException
	 * @throws UnSupportGenerateOptionException
	 * @throws ServiceException
	 */
	public static void generateTask(AbstractSO so, Boolean isRevised, String genOption, SessionContext sessionContext, MilestoneSet milestoneSet) throws SpecTimeMalformException,
			UnSupportGenerateOptionException, ServiceException {
		PreAdviceRuleBroker prb = new PreAdviceRuleBroker(sessionContext);
		PreAdviceBackendTaskService pbts = new PreAdviceBackendTaskServiceImpl(sessionContext);
		// get pre-advice receiving pattern
		BigDecimal soOid = so.getOid();
		String custCode = so.getCustCode();
		BusinessType bizType = so.getBizType();
		StringBuffer logMsg = new StringBuffer();
		logMsg.append(custCode);
		logMsg.append(",");
		logMsg.append(bizType.getAbbreviation());
		logMsg.append(",");
		logMsg.append(isRevised.toString());
		PreAdviceLogger.log(logFileName, so.getSoNumber(), logMsg.toString(), null);
		PreAdviceUtil.logMileStone(milestoneSet, MilestoneConstants.PARAM_MS_PRE_ADVICESENT);
		Date etd = null;
		AbstractLocation refLoc = null;
		if (genOption.equals(PreAdviceServiceConstants.GENERATE_OPTION_WHOLE_ROUTE)) {
			etd = PreAdviceUtil.getETD(so);
			refLoc = PreAdviceUtil.getPOL(so);
		} else {
			throw new UnSupportGenerateOptionException();
		}
		PreAdviceReceivingOption revPatternRule = prb.getRevPatternRule(custCode, bizType, etd);
		if (revPatternRule != null) {
			// Due Date
			String revPattern = "";
			Date expectGenTime = null;

			if (revPatternRule.getReceivingOptionOnDueDate().booleanValue()) {
				PreAdviceLogger.log(logFileName, "DueDate", revPattern, null);
				expectGenTime = PreAdviceTimeCalculator.calculateDueDateGenPreAdviceTime(so, sessionContext, refLoc, milestoneSet);
				if (expectGenTime != null) {
					// Exception Only
					revPattern = revPatternRule.getReceivingExceptionOnly().booleanValue() ? PreAdviceConstants.REVPATTERN_DUEDATE_EXCEPTION : PreAdviceConstants.REVPATTERN_DUEDATE_ALL;
					if (!isRevised.booleanValue()) {
						generateScheduleTask(soOid, revPattern, genOption, expectGenTime, pbts);
					} else {
						reviseScheduleTask(soOid, revPattern, genOption, expectGenTime, pbts, sessionContext);
					}
				} else {
					PreAdviceLogger.log(logFileName, "Due date generate time is null", "", null);
				}
			}
			// // Daily Acc
			// if (!isRevised.booleanValue() &&
			// revPatternRule.getReceivingOptionDailyAcc().booleanValue()) {
			// PreAdviceLogger.log(logFileName, "DailyAcc", revPattern, null);
			// expectGenTime =
			// PreAdviceTimeCalculator.calculateDailyGenPreAdviceTime(so,
			// revPatternRule.getDailyAccReceivingSpecificTime(),
			// sessionContext);
			//					
			// revPattern = PreAdviceConstants.REVPATTERN_DAILY_ACC;
			// generateScheduleTask(soOid, revPattern, genOption, expectGenTime,
			// pbts);
			// }
			// // Daily Non Acc
			// if (!isRevised.booleanValue() &&
			// revPatternRule.getReceivingOptionDailyNonAcc().booleanValue()) {
			// PreAdviceLogger.log(logFileName, "DailyNonAcc", revPattern,
			// null);
			// expectGenTime =
			// PreAdviceTimeCalculator.calculateDailyGenPreAdviceTime(so,
			// revPatternRule.getDailyNonAccReceivingSpecificTime(),
			// sessionContext);
			// revPattern = PreAdviceConstants.REVPATTERN_DAILY_NONACC;
			// generateScheduleTask(soOid, revPattern, genOption, expectGenTime,
			// pbts);
			// }
			//			
			//			
			// // VB confirm
			// if (!isRevised.booleanValue() &&
			// revPatternRule.getReceivingOptionOnOrderCreation().booleanValue())
			// {
			// // submit a immediate task
			// revPattern = PreAdviceConstants.REVPATTERN_ON_CREATION;
			// PreAdviceLogger.log(logFileName, "", revPattern, null);
			// pbts.submitImmediateGenPreAdviceTask(soOid, revPattern,
			// genOption);
			// }
//		} else { // if no revPatternRule, auto generate Preadivce immediately
//			if (!isRevised.booleanValue()) {
//				PreAdviceLogger.log(logFileName, "no receiving pattern rule", "", null);
//				pbts.submitImmediateGenPreAdviceTask(soOid, PreAdviceConstants.REVPATTERN_ON_CREATION, genOption);
//			}
		}
	}

	public static void generateScheduleTask(BigDecimal soOid, String revPattern, String genOption, Date expectGenTime, PreAdviceBackendTaskService pbts) throws TaskServiceException {
		PreAdviceLogger.log(logFileName, "Receive Pattern", revPattern, null);
		PreAdviceLogger.log(logFileName, "Expected run time", expectGenTime.toString(), null);
		PreAdviceLogger.log(logFileName, "Current time", DateHelper.getDateInGMT().toString(), null);
		String bizKey = PreAdviceUtil.constructBizKey(soOid, revPattern, genOption);
		if (expectGenTime.after(DateHelper.getDateInGMT())) {
			pbts.createScheduleGenPreAdviceTask(bizKey, expectGenTime);
		} else {
			pbts.submitImmediateGenPreAdviceTask(soOid, revPattern, genOption);
		}
	}

	private static void reviseScheduleTask(BigDecimal soOid, String revPattern, String genOption, Date expectGenTime, PreAdviceBackendTaskService pbts, SessionContext sc) throws TaskServiceException {
		PreAdviceLogger.log(logFileName, "Receive Pattern", revPattern, null);
		PreAdviceLogger.log(logFileName, "Expected run time", expectGenTime.toString(), null);
		PreAdviceLogger.log(logFileName, "Current time", DateHelper.getDateInGMT().toString(), null);
		String bizKey = PreAdviceUtil.constructBizKey(soOid, revPattern, genOption);
		if (expectGenTime.after(DateHelper.getDateInGMT())) {
			pbts.reviseScheduleGenPreAdviceTask(bizKey, expectGenTime);
		} else {
			PreAdviceService ps = new PreAdviceServiceImpl(sc);
			List sos = ps.getPreAdviceBySO(soOid);
			if (sos == null || sos.size() == 0) {
				pbts.submitImmediateGenPreAdviceTask(soOid, revPattern, genOption);
			}
		}
	}

	// private static String constructBizKey(BigDecimal soOid, String
	// revPattern, String genOption) {
	// String[] bizKey = new String[PreAdviceServiceConstants.BIZKEY_SIZE];
	// bizKey[PreAdviceServiceConstants.MODULE] =
	// PreAdviceServiceConstants.PREADV_APP_ID;
	// bizKey[PreAdviceServiceConstants.BIZKEY_OID] = soOid.toString();
	// bizKey[PreAdviceServiceConstants.BIZKEY_PATTERN] = revPattern;
	// bizKey[PreAdviceServiceConstants.BIZKEY_OPTION] = genOption;
	// return StringHelper.arrayToString(bizKey,
	// PreAdviceServiceConstants.BIZKEY_SEPERATOR);
	// }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -