单据类型个性化处理原创
金蝶云社区-周立思
周立思
2人赞赏了该文章 363次浏览 未经作者许可,禁止转载编辑于2024年01月31日 18:46:13

这种方法在处理 v6.0 星瀚表单时会有问题,暂时还没找到原因


指定单据类型布局

@Override
public void preOpenForm(PreOpenFormEventArgs e) {
    super.preOpenForm(e);
    BillShowParameter showParameter=(BillShowParameter)e.getFormShowParameter();
    String billTypeNumber="xxx_demo_billtype_BT_1";
    DynamicObject billType = QueryServiceHelper.queryOne("bos_billtype", "id",
            new QFilter("number", QCP.equals, billTypeNumber).toArray());
    showParameter.setBillTypeId(String.valueOf(billType.get("id")));
}


单据类型个性化处理

主要干预当组织等字段修改时导致页面会重新加载默认单据类型布局

public static class MyBillTypeProp extends BillTypeProp{
   private String customBillTypeId;

   public void setCustomBillTypeId(String billTypeId){
       this.customBillTypeId=billTypeId;
   }

    @Override
    public Long queryDefaultBillType(String billformId) {
        QFilter[] filters;
       if(StringUtils.isNotBlank(customBillTypeId)){
           //此处主要处理:组织字段变更导致的页面重载导致的布局变更为单据类型默认布局
           filters=new QFilter("id",QCP.equals,Long.parseLong(customBillTypeId)).toArray();
       }else{
           filters = new QFilter[]{new QFilter("billformid", "=", billformId), new QFilter("enable", "=", "1"), new QFilter("status", "=", "C"), new QFilter("isdefault", "=", Boolean.TRUE)};
       }
        DynamicObject billTypeObj = ORM.create().queryOne("bos_billtype", "id", filters);
        return billTypeObj != null ? (Long)billTypeObj.getPkValue() : null;
    }
}

表单插件重写 getEntityType()

@Override
public void getEntityType(GetEntityTypeEventArgs e) {
    super.getEntityType(e);
   MainEntityType entityType=e.getOriginalEntityType();
    try {
        IDataEntityProperty property= entityType.findProperty("xxx_billtypefield");
        if(property!=null) {
            MainEntityType newEntityType=(MainEntityType)entityType.clone();
            newEntityType.getProperties().remove(property);
            MyBillTypeProp newBillTypeProp = new MyBillTypeProp();
            newBillTypeProp.setName("xxx_billtypefield");
            newBillTypeProp.setDisplayName(new LocaleString("单据类型"));
            BillShowParameter showParameter = (BillShowParameter) this.getView().getFormShowParameter();
            newBillTypeProp.setCustomBillTypeId(showParameter.getBillTypeId());
            EntityType billTypeEntityType = EntityMetadataCache.getDataEntityType("bos_billtype");
            newBillTypeProp.setComplexType(billTypeEntityType);
            newEntityType.registerComplexProperty(newBillTypeProp);
            e.setNewEntityType(newEntityType);
        }
    } catch (CloneNotSupportedException ex) {
        throw new RuntimeException(ex);
    }
}


赞 2