• eas之服务端常用代码


    服务端代码的编写主要针对App目录下的 PurOrderControllerBean 实现类,典型的代码有新增、修改、检验等操作

    1.提交控制
    用户在编辑界面上点击‘保存’按钮时应用框架会调用 PurOrderControllerBean的submit方法,通过重载PurOrderControllerBean父类的submit方法,
    可以对要新增、修改的数据进行校验、修正或做一些相关的判断:
    protected IObjectPK _submit(Context ctx, IObjectValue model)throws BOSException, EASBizException
    {
    PurOrderInfo purOrderInfo = (PurOrderInfo) model;
    //记录是否是新增,false表示是修改,据此可以作相关操作
    boolean isAddNew = true;
    if(purOrderInfo.getId()!=null&&_exists(ctx,new ObjectUuidPK(purOrderInfo.getId())))
    {isAddNew = false;}
    //检查是否设置number
    //checkNumber(ctx, otherBillInfo);
    //调用父类的方法检查是否有重号
    //super._checkNumberDup(ctx, null, purOrderInfo );
    //设置值对象中的一些默认值
    setDefaultValue(ctx, purOrderInfo);
    //校验值对象中的属性是否合法
    checkValid(purOrderInfo);
    //调用框架的提交方法
    return super._submit(ctx, purOrderInfo);
    }
    对于用户编辑界面上点击'暂存'按钮时调用 protected IObjectPK _save(Context ctx, IObjectValue model){}方法,其操作过程与调用_submit方法类似.

    对于服务端的submit方法在实际应用中对应新增addNew或修改update,所以在服务端的架构中submit方法是根据pk是否为空进一步调用update方法,然后在服务端的
    实现类中可以重载addNew及update来做具体的处理.例如CoreBaseControllerBean类中的submit方法实现:
    protected void _submit(Context ctx,IObjectPK pk,IObjectValue model)throws BOSException,EASBizException{
    CoreBaseInfo coreBaseInfo=(CoreBaseInfo)model;
    if(isExistPropertyName(ctx,coreBaseInfo,IFWStatus.effectedStatus)){
    coreBaseInfo.setInt(IFWStatus.effectedStatus,EffectedStatusEnum.EFFECTED_VALUE);
    }
    ServiceStateManager.getInstance().enableNextCallServices();
    if(coreBaseInfo.getId()!=null&&this.exists(ctx,pk)){
    super.update(ctx,pk,coreBaseInfo);
    }else{
    super.addNew(ctx,pk,coreBaseInfo);
    }
    }

    protected IObjectPK _submit(Context ctx,IObjecrtValue model)throws BOSException,EASBizException{
    CoreBaseInfo coreBaseInfo=(CoreBaseInfo)model;
    if(isExistPropertyName(ctx,coreBaseInfo,IFWStatus,effectedStatus)){
    coreBaseInfo.setInt(IFWStatus.effectedStatus,EffectedStatusEnum.EFFECTED_VALUE);
    }
    IObjectPK retValue;
    ServiceStateManager.getInstance().enableNextCallService();
    if(coreBaseInfo.getId!null && this.exists(ctx,new ObjectUuidPK(coreBaseInfo.getId()))){
    retValue=new ObjectUuidPK(coreBaseInfo.getId()){
    super.update(ctx,retValue,coreBaseInfo);
    return retValue;
    }
    }else{
    retValue=super.addNew(ctx,coreBaseInfo);
    return retValue;
    }
    }

    在用户的服务端的实现类中的代码如下:
    protected void _addNew(Context ctx,IObject pk,IObjectValue model)BizeException{
    PurOrderInfp purOrderInfo=(PurOrderInfo)model;
    //检查是否设置number
    checkNumber(ctx,otherBillInfo);
    //检查是否有重号;
    checkNumberDup(ctx,null,purOrerInfo);
    //设置值对象中的一些默认值
    setDefaultValue(ctx,purOrderInfo);
    //校验值对象中的属性是否合法
    checkValid(purOrderInfo);
    //调用框架的提交方法
    return super.addNew(ctx,pk,purOrderInfo);
    }


    2.


    3.生成凭证前的控制
    通过重载父类的createVoucher方法实现其他控制
    protected void createVoucher(Context ctx,String billId)throws BOSException,EASBizException{
    IPurOrder purOrder=PurOrderFactory.getLocalInstance(ctx);
    //创建pk对象
    ObjectUuiPK pk=new ObjectUuidPK(billId);
    //在客户端获取用户信息
    UserInfo currentUser=(UserInfo)ctx.get(SysContextConstant.USERINFO);
    //根据ID返回当前的值对象
    PurOrderInfo purOrderInfo;
    purOrderInfo=getPurOrderInfo(ctx,pk);
    //作相关判断
    if(purOrderInfo!=null){
    Date billDate=purOrderInfo.getBillDate();
    if(billDate!=null){
    //作相应处理
    }
    }

    //已生成凭证,不能重复生成凭证
    if(purOrderInfo.isFiVouchered()){
    throw new IBizException("..............");
    }
    if(BillStatusEnum.AUDITED.equals(purOrderInfo.getBillStatus())){
    //此过程中自动生成凭证
    purOrderInfo.setFiVouchered(true);
    purOrderInfo.update(pk,otherBillInfo);
    }
    }

    4.生成凭证
    protected IObjectValue _genVoucher(Context ctx,String billId)throws BOSException,EASBizException{
    //生成凭证 并返回集合
    IOjectCollection tmpCollection=null;
    //dep动态会计平台
    IDAPTransformer iDAPTransformer=DAPTransformerFactory.getLocalInstance(ctx);
    CoreBaseInfooCollection coreTransCollection =new CoreBillBaseCollection();
    ObjectUuidPK pk=new ObjectUuidPK(billId);
    //获取值对象
    PurOrderInfo model=(PurOrderInfo)this.getValue(ctx,pk);
    coreTransCollection.add(model);

    //获取转换后的凭证值对象
    tmpCollection=iDAPTransformer.transformAuto(coreTransCollection,DAPVoucherTypeEnum.FIVoucher);
    //创建凭证实体对象接口
    IVoucher vchCtrl=(IVoucher)VoucherFactory.getLocalInstance(ctx);
    //从集合中取出转换后的凭证值对象
    VoucherInfo vch=(VoucherInfo)tmpCollection.getObject(0);
    VoucherInfo vch1=new VoucherInfo();
    vch1=vchCtrl.exteriorLazyLoad(vch,VoucherInfo.getDefaultSelector());
    return vch1;
    }

    5.审核操作
    重载父类的_audit方法实现审核控制
    protected void _audit(Context ctx,IObjectPK pk)throws BOSException,EASBizException{
    //对参数的常用判断
    if(pk==null){
    throw new IllegalArgumentException();
    }
    //当前用户
    UserInfo currentUser=(UserInfo)ctx.get(SysContextConstant.USERINFO);
    //当前日期
    Date currentDate=new Date();
    //检查单据是否存在, PurOrderBizException 是用户定义的异常类 BillStatusEnum自定义枚举项
    boolean exist=exists(ctx,pk);
    if(!exist){
    throw new PurOrderBizException(PurOrderBizException.BILL_NOTEXIST);
    }
    PurOrderInfo purOrderInfo=getPurOrderInfo(ctx,pk);
    //设置审核人
    purOrderInfo.setAuditor(currentUser);
    //设置审核日期
    purOrderInfo.setAuditDate(currentDate);
    //设置单据的状态为--己审核
    purOrderInfo.setBillStatus(BillStatusEnum.AUDITD);
    //更新实体
    完成审核标记
    update(ctx,pk,purOrderInfo);
    }

  • 相关阅读:
    【Java POI】POI基于事件驱动解析大数据量2007版本Excel,空值导致列错位问题
    【Java MyBatis Generator】使用generator自动生成Dao,Mapping和实体文件
    Java连接MQ的实例, 测试类
    与MQ通讯的完整JAVA程序
    MQ中将消息发送至远程队列的配置
    IBM MQ 使用指南
    Java调用MQ队列
    IBM MQ介绍
    HttpWebRequest和HttpWebResponse
    SQL SERVER中DBLINK的实现
  • 原文地址:https://www.cnblogs.com/luojiabao/p/11091512.html
Copyright © 2020-2023  润新知