天天看點

EAS BOS Excel導入功能

1:模闆配置(*實作類的名稱為實作導入功能類的路徑)。

EAS BOS Excel導入功能

2:  設定導入參數

  /**
     * 配置導入資訊
     * @return
     */
    protected ArrayList getImportParam() {
        DatataskParameter param = new DatataskParameter();
        param.solutionName = "eas.綜合物流.bxgl.ProposalFormImport";
        param.alias = "投保單導入";
        ArrayList paramList = new ArrayList();
        paramList.add(param);
        return paramList;
    }
           

3:實作導入功能類

package com.kingdee.eas.rj.billingandsettle.client;


import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;


import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.eas.base.codingrule.CodingRuleManagerFactory;
import com.kingdee.eas.base.codingrule.ICodingRuleManager;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.framework.ICoreBase;
import com.kingdee.eas.hr.base.CodingRuleManageFacade;
import com.kingdee.eas.rj.billingandsettle.IProposalform;
import com.kingdee.eas.rj.billingandsettle.IProposalformEntry;
import com.kingdee.eas.rj.billingandsettle.ProposalformEntryFactory;
import com.kingdee.eas.rj.billingandsettle.ProposalformEntryInfo;
import com.kingdee.eas.rj.billingandsettle.ProposalformFactory;
import com.kingdee.eas.rj.billingandsettle.ProposalformInfo;
import com.kingdee.eas.rj.billingandsettle.propoType;
import com.kingdee.eas.rj.billingandsettle.basedata.InsuranceTypeFactory;
import com.kingdee.eas.rj.billingandsettle.basedata.InsuranceTypeInfo;
import com.kingdee.eas.rj.billingandsettle.utils.ChargingUtils;
import com.kingdee.eas.rj.container.basedata.BoxTypeFactory;
import com.kingdee.eas.rj.container.basedata.BoxTypeInfo;
import com.kingdee.eas.rj.container.basedata.ContainerFileFactory;
import com.kingdee.eas.rj.container.basedata.ContainerFileInfo;
import com.kingdee.eas.rj.container.basedata.ContainerSize;
import com.kingdee.eas.rj.contract.ContractBaseBillFactory;
import com.kingdee.eas.rj.contract.ContractBaseBillInfo;
import com.kingdee.eas.rj.customersrv.basedata.CustomerFactory;
import com.kingdee.eas.rj.customersrv.basedata.CustomerInfo;
import com.kingdee.eas.rj.sealmanager.basedate.SealFileFactory;
import com.kingdee.eas.rj.sealmanager.basedate.SealFileInfo;
import com.kingdee.eas.rj.shipping.basedata.PortFactory;
import com.kingdee.eas.rj.shipping.basedata.PortInfo;
import com.kingdee.eas.rj.shipping.basedata.ShipBaseFactory;
import com.kingdee.eas.rj.shipping.basedata.ShipBaseInfo;
import com.kingdee.eas.rj.tradingcenter.EmptyFull;
import com.kingdee.eas.tools.datatask.AbstractDataTransmission;
import com.kingdee.eas.tools.datatask.core.TaskExternalException;
import com.kingdee.eas.tools.datatask.runtime.DataToken;
import com.kingdee.util.StringUtils;


public class ProposalFormImport extends AbstractDataTransmission {


	public int getSubmitType() {
		return super.getSubmitType();
	}


	public void submit(CoreBaseInfo arg0, Context ctx) throws TaskExternalException {
		try {
			ProposalformInfo proInfo = (ProposalformInfo) arg0;
			IObjectPK pk = ProposalformFactory.getLocalInstance(ctx).addnew(proInfo);
		} catch (EASBizException e) {
			e.printStackTrace();
			setError("導入失敗!");
		} catch (BOSException e) {
			e.printStackTrace();
			setError("導入失敗!");
		}
	}
	
	/**
	 * 設定業務接口   --投保單表頭
	 */
	protected ICoreBase getController(Context ctx) throws TaskExternalException {
		IProposalform ibill = null;
		try {
			ibill = ProposalformFactory.getLocalInstance(ctx);
		} catch (BOSException e) {
			e.printStackTrace();
		}
		return ibill;
	}


	/**
	 * 業務接口——投保單分錄
	 */
	@SuppressWarnings("unused")
	private ICoreBase getControllerEntry(Context ctx) throws TaskExternalException {
		IProposalformEntry iebill = null;
		try {
			iebill = ProposalformEntryFactory.getLocalInstance(ctx);
		} catch (BOSException e) {
			e.printStackTrace();
		}
		return iebill;
	}
	
	/**
	 * Excel資料分析
	 */
	public CoreBaseInfo transmit(Hashtable paramHashtable, Context ctx) throws TaskExternalException {
		//開始寫入資料~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GO!GO!GO!GO!GO!GO!GO!GO!!!!!!!!!!!
		
		ProposalformInfo proInfo = new ProposalformInfo();
		try {
			ICodingRuleManager codeFactory = CodingRuleManagerFactory.getLocalInstance(ctx); //投保單号
			String number = codeFactory.getNumber(new ProposalformInfo(),com.kingdee.eas.util.app.ContextUtil.getCurrentOrgUnit(ctx).getId().toString());
			proInfo.setNumber(number);
		} catch (BOSException e1) {
			e1.printStackTrace();
		} catch (EASBizException e) {
			e.printStackTrace();
		}
		proInfo.setBusinessNo("xb_0");
		String containernoID = (String) ((DataToken) paramHashtable.get("CFContainernoID")).data; //箱号
		if(!StringUtils.isEmpty(containernoID)){
			try {
				ContainerFileInfo conInfo = ContainerFileFactory.getLocalInstance(ctx).getContainerFileInfo("where number='"+containernoID+"'");
				proInfo.setContainerno(conInfo);
				proInfo.setZlgs(conInfo.getCompany());  // 租賃公司
			} catch (EASBizException e) {
				e.printStackTrace();
				setError("導入失敗,箱号異常!");
			} catch (BOSException e) {
				e.printStackTrace();
				setError("導入失敗,箱号異常!");
			}
		}else{
			setError("導入失敗,箱号為空!");
		}

		String insurancecontrac = (String) ((DataToken) paramHashtable.get("CFInsurancecontrac")).data; //保險合同
		if(!StringUtils.isEmpty(insurancecontrac)){
			try {
				ContractBaseBillInfo ctInfo = ContractBaseBillFactory.getLocalInstance(ctx).getContractBaseBillInfo("where contractName='"+insurancecontrac+"'");

				proInfo.setInsurancecontract(ctInfo);
			} catch (EASBizException e) {
				e.printStackTrace();
				setError("導入失敗,保險合同異常!");
			} catch (BOSException e) {
				e.printStackTrace();
				setError("導入失敗,保險合同異常!");
			}
		}else{
			setError("導入失敗,保險合同為空!");
		}
		String policyUnitID = (String) ((DataToken) paramHashtable.get("CFPolicyUnitID")).data; //投保人機關
		if(!StringUtils.isEmpty(policyUnitID)){
			try {
				CustomerInfo cusInfo = CustomerFactory.getLocalInstance(ctx).getCustomerInfo("where name='"+policyUnitID+"'");
				proInfo.setPolicyUnit(cusInfo);
			} catch (EASBizException e) {
				e.printStackTrace();
				setError("導入失敗,投保人機關異常!");
			} catch (BOSException e) {
				e.printStackTrace();
				setError("導入失敗,投保人機關異常!");
			}
		}else{
			setError("導入失敗,投保人機關為空!");
		}
		String baselimit = (String) ((DataToken) paramHashtable.get("CFBaselimit")).data;   //基準保額
		if(!StringUtils.isEmpty(baselimit)){
			BigDecimal bd = new BigDecimal(baselimit);
			proInfo.setBaselimit(bd.setScale(2, BigDecimal.ROUND_HALF_UP));
		}else{
			setError("導入失敗,基準保額為空!");
		}
		String addlimit = (String) ((DataToken) paramHashtable.get("CFAddlimit")).data;   //追加保額
		if(!StringUtils.isEmpty(addlimit)){
			BigDecimal bd = new BigDecimal(addlimit);
			proInfo.setAddlimit(bd.setScale(2, BigDecimal.ROUND_HALF_UP));
		}
		String totallimit = (String) ((DataToken) paramHashtable.get("CFTotallimit")).data;   //保險總額
		if(!StringUtils.isEmpty(totallimit)){
			BigDecimal bd = new BigDecimal(totallimit);
			proInfo.setTotallimit(bd.setScale(2, BigDecimal.ROUND_HALF_UP));
		}else{
			setError("導入失敗,保險總額為空!");
		}
		String policyerAddress = (String) ((DataToken) paramHashtable.get("CFPolicyerAddress")).data;   //保單人位址
		if(!StringUtils.isEmpty(policyerAddress)){
			proInfo.setPolicyerAddress(policyerAddress);
		}
		String policyerTel = (String) ((DataToken) paramHashtable.get("CFPolicyerTel")).data;   //保單人聯系電話
		if(!StringUtils.isEmpty(policyerTel)){
			proInfo.setPolicyerTel(policyerTel);
		}
		String policyFee = (String) ((DataToken) paramHashtable.get("CFPolicyFee")).data;    //應付保費
		if(!StringUtils.isEmpty(policyFee)){
			BigDecimal bd = new BigDecimal(policyFee);
			proInfo.setPolicyFee(bd.setScale(2, BigDecimal.ROUND_HALF_UP));
		}else{
			setError("導入失敗,應付保費為空!");
		}
		String shipID = ChargingUtils.TYSHIPID;   //通用船名ID
		if(!StringUtils.isEmpty(shipID)){
			try {
				ShipBaseInfo shInfo = ShipBaseFactory.getLocalInstance(ctx).getShipBaseInfo(new ObjectUuidPK(shipID)); 
				proInfo.setShip(shInfo);
			} catch (EASBizException e) {
				e.printStackTrace();
			} catch (BOSException e) {
				e.printStackTrace();
			}
		}
		String voyno = ChargingUtils.TYVOYNO;   //通用航次
		if(!StringUtils.isEmpty(voyno)){
			proInfo.setVoyno(voyno);
		}
		String startportID = "南沙" ;		//預設起始港口
		if(!StringUtils.isEmpty(startportID)){
			try {
				PortInfo spInfo = PortFactory.getLocalInstance(ctx).getPortInfo("where name='"+startportID+"'"); 
				proInfo.setStartport(spInfo);
			} catch (EASBizException e) {
				e.printStackTrace();
			} catch (BOSException e) {
				e.printStackTrace();
			}
		}
		
		String policyDate = (String) ((DataToken) paramHashtable.get("CFPolicyDate")).data;     //投保日期
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		if(!StringUtils.isEmpty(policyDate)){
			try {
				Date date = sdf.parse(policyDate);
				proInfo.setPolicyDate(date);  //投保日期
			} catch (ParseException e) {
				e.printStackTrace();
				setError("投保日期格式錯誤,正确格式'yyyy-mm-dd'!");
			}
		}
		String portID = "南沙" ;			//預設港口
		if(!StringUtils.isEmpty(portID)){
			try {
				PortInfo pInfo = PortFactory.getLocalInstance(ctx).getPortInfo("where name='"+portID+"'"); 
				proInfo.setPort(pInfo);
			} catch (EASBizException e) {
				e.printStackTrace();
			} catch (BOSException e) {
				e.printStackTrace();
			}
		}
		String boxSize = (String) ((DataToken) paramHashtable.get("CFBoxSize")).data;   // 尺寸  
		if(!StringUtils.isEmpty(boxSize)){
			if(boxSize != null){
				if(ContainerSize.R20.toString().equals(boxSize)){
					proInfo.setBoxSize(ContainerSize.R20);
				}
				if(ContainerSize.R40.toString().equals(boxSize)){
					proInfo.setBoxSize(ContainerSize.R40);
				}
				if(ContainerSize.R45.toString().equals(boxSize)){
					proInfo.setBoxSize(ContainerSize.R45);
				}
				if(!(ContainerSize.R20.toString().equals(boxSize) || ContainerSize.R40.toString().equals(boxSize) || ContainerSize.R45.toString().equals(boxSize))){
					setError("導入失敗,尺寸異常!");
				}
			}
		}
		String emptyfull = (String) ((DataToken) paramHashtable.get("CFEmptyfull")).data;   // 空重
		if(!StringUtils.isEmpty(emptyfull)){
			if(emptyfull != null){
				if(EmptyFull.FULL.toString().equals(emptyfull)){
					proInfo.setEmptyfull(EmptyFull.FULL);
				}
				if(EmptyFull.Empty.toString().equals(emptyfull)){
					proInfo.setEmptyfull(EmptyFull.Empty);
				}
				if(!(EmptyFull.FULL.toString().equals(emptyfull) || EmptyFull.Empty.toString().equals(emptyfull))){
					setError("導入失敗,空重異常!");
				}
			}
		}
		String boxTypeID = (String) ((DataToken) paramHashtable.get("CFBoxTypeID")).data;   // 箱型
		if(!StringUtils.isEmpty(boxTypeID)){
			if(boxTypeID != null){
				try {
					BoxTypeInfo boxInfo =  BoxTypeFactory.getLocalInstance(ctx).getBoxTypeInfo("where number='"+boxTypeID+"'");
					proInfo.setBoxType(boxInfo);
				} catch (EASBizException e) {
					e.printStackTrace();
					setError("導入失敗,箱型異常!");
				} catch (BOSException e) {
					e.printStackTrace();
					setError("導入失敗,箱型異常!");
				}
			}
		}
		String propoNumber = (String) ((DataToken) paramHashtable.get("CFPropoNumber")).data;   // 保單号
		if(!StringUtils.isEmpty(propoNumber)){
			if(propoNumber != null){
				proInfo.setPropoNumber(propoNumber);
			}else{
				setError("導入失敗,保單号不能為空!");
			}
		}
		String proType = (String) ((DataToken) paramHashtable.get("CFPropoType")).data;	// 投保類型
		if(proType != null){
			if(propoType.goodsIN.toString().equals(proType)){
				proInfo.setPropoType(propoType.goodsIN);
			}
			if(propoType.boxIN.toString().equals(proType)){
				proInfo.setPropoType(propoType.boxIN);
			}
			if(propoType.shipIN.toString().equals(proType)){
				proInfo.setPropoType(propoType.shipIN);
			}
			if(propoType.carIN.toString().equals(proType)){
				proInfo.setPropoType(propoType.carIN);
			}
			if(!(propoType.goodsIN.toString().equals(proType) || propoType.boxIN.toString().equals(proType) || propoType.shipIN.toString().equals(proType) || propoType.carIN.toString().equals(proType))){
				setError("導入失敗,投保類型異常!");
			}
		}
		String effectDate = (String) ((DataToken) paramHashtable.get("CFEffectDate")).data;     //有效日期
		if(!StringUtils.isEmpty(effectDate)){
			try {
				Date date = sdf.parse(effectDate);
				proInfo.setEffectDate(date);
			} catch (ParseException e) {
				e.printStackTrace();
				setError("有效日期格式錯誤,正确格式'yyyy-mm-dd'!");
			}
		}
		String remarks = (String) ((DataToken) paramHashtable.get("CFRemarks")).data;     //備注
		if(!StringUtils.isEmpty(remarks)){
			if(remarks != null){
				proInfo.setRemarks(remarks);
			}
		}
		return proInfo;
	}
	
	private void setError(String str) throws TaskExternalException
	{
		throw new TaskExternalException(str);
	}
}