EAS BOS Excel导入功能

1:模板配置(*实现类的名称为实现导入功能类的路径)。

EAS BOS Excel导入功能_第1张图片


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);
	}
}







 

你可能感兴趣的:(EAS,BOS开发(java),金蝶EAS_BOS开发)