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

📄 preadviceinstructionhandler.java

📁 this Class help handle different pre-advice instruction, such as "ok to ship"/"hold shipment"
💻 JAVA
字号:
/*
 * Created on 2005-3-30
 *
 * OOCL
 */
package com.oocllogistics.threepl.preadvice.service;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import com.oocllogistics.common.subapp.user.domain.SystemUser;
import com.oocllogistics.common.subapp.user.service.SystemUserService;
import com.oocllogistics.common.subapp.user.service.SystemUserServiceImpl;
import com.oocllogistics.common.util.task.SessionContext;
import com.oocllogistics.framework.util.exception.ServiceException;
import com.oocllogistics.framework.util.tool.StringHelper;
import com.oocllogistics.threepl.preadvice.domain.PreAdvice;
import com.oocllogistics.threepl.preadvice.domain.PreAdviceConstants;
import com.oocllogistics.threepl.preadvice.domain.PreAdviceInstruction;
import com.oocllogistics.threepl.shipment.domain.AbstractSO;
import com.oocllogistics.threepl.shipment.service.so.SOException;
import com.oocllogistics.threepl.shipment.service.so.SOService;
import com.oocllogistics.threepl.shipment.service.so.SOServiceImpl;

/**
 * Class help handle different pre-advice instruction "ok to ship"/"hold
 * shipment"
 * 
 * @author Joy Ge
 * @version 2.0
 */
public class PreAdviceInstructionHandler {

	public static void sendPreAdviceInstructionToCustomer(PreAdvice preAdvice, String sendBy, SessionContext sessionContext) throws ServiceException {
		// write notes-log
		List lclSuggestions = getCSULCLSuggestion(preAdvice);
		if (lclSuggestions.size() > 0) {
			String notesLogContent = getCSULCLSuggestionNotesLogContent(lclSuggestions);
			SystemUserService sysSrv = new SystemUserServiceImpl(sessionContext);
			SystemUser user = sysSrv.findSystemUserByID(sendBy);
			PreAdviceUtil.writeNotesLog(preAdvice, user, notesLogContent, false, sessionContext);
		}
		// mark all "DRAFT" LCL Suggestion to be "SENT-Approved"
		List instructions = preAdvice.getPreAdviceInstruction();
		for (Iterator iter = instructions.iterator(); iter.hasNext();) {
			PreAdviceInstruction instruction = (PreAdviceInstruction) iter.next();
			if (instruction.getIsSuggestedLCL().booleanValue() && instruction.getStatus().equals(PreAdviceConstants.PREADV_INSTRUCTIN_STATUS_DRAFT)) {
				if (!hasCustomerLCLExist(preAdvice, instruction.getAbstractSO())) {
					instruction.setStatus(PreAdviceConstants.PREADV_INSTRUCTIN_STATUS_SENT_APPROVE);
					instruction.setTextInstruction("");
				} else {
					iter.remove();
				}
			}
		}
	}

	private static boolean hasCustomerLCLExist(PreAdvice preAdvice, AbstractSO so) {
		boolean hasExist = false;
		List preInstruction = preAdvice.getPreAdviceInstruction();
		for (Iterator iter = preInstruction.iterator(); iter.hasNext();) {
			PreAdviceInstruction instruction = (PreAdviceInstruction) iter.next();
			if (instruction.getIsSuggestedLCL().booleanValue() && !instruction.getStatus().equals(PreAdviceConstants.PREADV_INSTRUCTIN_STATUS_DRAFT) && instruction.getAbstractSO().equals(so)) {
				hasExist = true;
				break;
			}
		}
		return hasExist;
	}

	public static void replyPreAdviceInstructionToCSU(PreAdvice preAdvice, String replyBy, SessionContext sessionContext, boolean needLock) throws ServiceException {
		// write notes-log
		SystemUserService sysSrv = new SystemUserServiceImpl(sessionContext);
		SystemUser user = sysSrv.findSystemUserByID(replyBy);
		PreAdviceUtil.writeNotesLog(preAdvice, user, getCustomerReplyNotesLogContent(preAdvice), true, sessionContext);
		// customer confirm instruction(Ok to ship some SO)
		customerConfirmInstruction(preAdvice, sessionContext, needLock);
		// delete all "Not-Draft" pre-advice instruction
		List instructions = preAdvice.getPreAdviceInstruction();
		for (Iterator iter = instructions.iterator(); iter.hasNext();) {
			PreAdviceInstruction instruction = (PreAdviceInstruction) iter.next();
			if (!instruction.getIsSuggestedLCL().booleanValue()
					|| (instruction.getIsSuggestedLCL().booleanValue() && !instruction.getStatus().equals(PreAdviceConstants.PREADV_INSTRUCTIN_STATUS_DRAFT))) {
				iter.remove();
			}
		}
	}

	public static List customerConfirmInstruction(PreAdvice preAdvice, SessionContext sessionContext, boolean needLock) throws SOException {
		// find all OkToShipSO
		List lclSOs = new Vector();
		List okToShipSOs = new Vector();
		//SOService sos = new SOServiceImpl(sessionContext);
		List adviceSOs = preAdvice.getAbstractSO();
		okToShipSOs.addAll(adviceSOs);
		List instructions = preAdvice.getPreAdviceInstruction();
		for (Iterator iter = instructions.iterator(); iter.hasNext();) {
			PreAdviceInstruction instruction = (PreAdviceInstruction) iter.next();
			// for LCL Suggestions
			//AbstractSO so = instruction.getAbstractSO();
			// TODO: DecCut preAdvice01
			// if
			// ((BusinessTypeOidConstants.CRD).equals(so.getBizType().getOid()))
			// {
			if (instruction.getIsSuggestedLCL().booleanValue()) {
				if (instruction.getStatus().equals(PreAdviceConstants.PREADV_INSTRUCTIN_STATUS_SENT_APPROVE)) {
					try {
						// if
						// (sos.canChangeMoveTypeForCRD(instruction.getAbstractSO())
						// &&
						// !instruction.getAbstractSO().getTypeOfMovement().equals(TypeOfMovementConstant.CFS_CFS))
						// {
						// set typeOfMovement to be "CFS-CFS"
						// instruction.getAbstractSO().setTypeOfMovement(
						// TypeOfMovementConstant.CFS_CFS);
						lclSOs.add(instruction.getAbstractSO());
						// }
					} catch (Exception e) {
						throw new SOException(e);
					}
					// okToShipSOs.remove(instruction.getPreAdviceCargo().getAbstractSO());
				} else if (instruction.getStatus().equals(PreAdviceConstants.PREADV_INSTRUCTIN_STATUS_SENT_REJECT)) {
					okToShipSOs.remove(instruction.getAbstractSO());
				}
			} else {
				okToShipSOs.remove(instruction.getAbstractSO());
			}
			// }
		}
		// SOService soService = new SOServiceImpl(sessionContext);
		SOService soService = new SOServiceImpl(sessionContext);
		// perfrom OkToShip on SO
		try {
			//soService.performOkToShip(okToShipSOs, needLock);
		} catch (Exception e) {
			throw new SOException(e);
		}
		return lclSOs;
	}

	private static List getCSULCLSuggestion(PreAdvice preAdvice) {
		List lclSuggestions = new Vector();
		List instructions = preAdvice.getPreAdviceInstruction();
		for (Iterator iter = instructions.iterator(); iter.hasNext();) {
			PreAdviceInstruction instruction = (PreAdviceInstruction) iter.next();
			if (instruction.getIsSuggestedLCL().booleanValue() && instruction.getStatus().equals(PreAdviceConstants.PREADV_INSTRUCTIN_STATUS_DRAFT)) {
				lclSuggestions.add(instruction);
			}
		}
		return lclSuggestions;
	}

	private static String getCSULCLSuggestionNotesLogContent(List lclSuggestions) {
		StringBuffer content = new StringBuffer();
		content.append("Suggest LCL\n");
		for (Iterator iter = lclSuggestions.iterator(); iter.hasNext();) {
			PreAdviceInstruction lclSuggestion = (PreAdviceInstruction) iter.next();
			String soNumber = lclSuggestion.getAbstractSO().getSoNumber();
			String remark = lclSuggestion.getTextInstruction();
			content.append("SO ").append(soNumber).append("\n");
			if (!StringHelper.isEmpty(remark)) {
				content.append(remark).append("\n");
			}
			// content.append("\n");
		}
		return content.toString();
	}

	private static String getCustomerReplyNotesLogContent(PreAdvice preAdvice) {
		StringBuffer content = new StringBuffer();
		String customerGeneralInstruction = getCustomerGeneralInstruction(preAdvice);
		String customerLCLInstruction = getCustomerLCLInstructionNotesLogContent(preAdvice);
		if (!StringHelper.isEmpty(customerGeneralInstruction)) {
			content.append("All OK To Ship except\n").append(customerGeneralInstruction).append("\n").append("\n");
		}
		content.append(customerLCLInstruction);
		return content.toString();
	}

	private static String getCustomerGeneralInstruction(PreAdvice preAdvice) {
		StringBuffer content = new StringBuffer();
		List preInstructions = preAdvice.getPreAdviceInstruction();
		for (Iterator iter = preInstructions.iterator(); iter.hasNext();) {
			PreAdviceInstruction instruction = (PreAdviceInstruction) iter.next();
			if (!instruction.getIsSuggestedLCL().booleanValue()) {
				String soNumber = instruction.getAbstractSO().getSoNumber();
				content.append("SO ").append(soNumber).append("\n");
				if (!StringHelper.isEmpty(instruction.getTextInstruction())) {
					content.append(instruction.getTextInstruction()).append("\n");
				}
			}
		}
		return content.toString();
	}

	private static String getCustomerLCLInstructionNotesLogContent(PreAdvice preAdvice) {
		StringBuffer content = new StringBuffer();
		List preInstructions = preAdvice.getPreAdviceInstruction();
		for (Iterator iter = preInstructions.iterator(); iter.hasNext();) {
			PreAdviceInstruction instruction = (PreAdviceInstruction) iter.next();
			StringBuffer remark = new StringBuffer();
			if (instruction.getIsSuggestedLCL().booleanValue() && !instruction.getStatus().equals(PreAdviceConstants.PREADV_INSTRUCTIN_STATUS_DRAFT)) {
				String soNumber = instruction.getAbstractSO().getSoNumber();
				if (instruction.getStatus().equals(PreAdviceConstants.PREADV_INSTRUCTIN_STATUS_SENT_APPROVE)) {
					remark.append("LCL Approved\n");
				} else {
					remark.append("LCL Rejected\n");
				}
				if (!StringHelper.isEmpty(instruction.getTextInstruction())) {
					remark.append(instruction.getTextInstruction()).append("\n");
				}
				content.append("SO ").append(soNumber).append("\n");
				content.append(remark).append("\n");
			}
		}
		return content.toString();
	}

}

⌨️ 快捷键说明

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