APL函数代码开放场景-范围规则Java接口说明

2024-12-31 17:19:07 297 本站

1. 返回类型为List

package fx.custom.apl.example.scope_rule;
import com.fxiaoke.functions.FunctionContext;
import com.fxiaoke.functions.Fx;
import com.fxiaoke.functions.client.DebugHelper;
import com.fxiaoke.functions.model.*;
import com.fxiaoke.functions.template.IQueryListAction;
import com.fxiaoke.functions.tools.QueryOperator;
import com.fxiaoke.functions.utils.Lists;
import com.fxiaoke.functions.utils.Maps;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.fxiaoke.functions.Fx.log;
/**
* 使用集合(List)返回值类型,在新建对象数据时,查找关联字段可以选择出其它对象中符合函数条件的数据
* 在新建对象数据时,查找关联字段可以选择出其它对象中符合函数条件的数据
* 注:List返回类型函数,用此方法返回的数据有上限500条在新建对象数据时,查找关联字段可以选择出其它对象中符合函数条件的数据
*/
public class QueryListExample implements IQueryListAction {

   /**
    * 范围规则函数(List)的运行方法
    */
   @Override
   public List execute(FunctionContext context, Map<String, Object> args) {
       /* 在新建对象数据时,查找关联字段可以选择出其它对象中符合函数条件的数据
        * 注:List返回类型函数,用此方法返回的数据有上限500条
        */

       //获取当前操作对象数据的字段值
       String name = (String) context.getData().get("field_cG001__c");
       log.info(name);
       //根据条件查找数据,本案例即查找另一对象中性别为男生的数据
       APIResult ret = Fx.object.find("object_M4WK7__c", //查询对象apiname
               FQLAttribute.builder()
                       .columns(Lists.newArrayList("_id")) //返回数据id
                       //匹配条件,关联对象字段=当前操作对象字段
                       .queryTemplate(QueryTemplate.AND(Maps.of("field_54cCg__c", QueryOperator.EQ(name))))
                       .build(),
               SelectAttribute.builder()
                       .build());
       if (ret.isError()) {
           log.info(ret.message());
       }

       //定义id List
       List objectIds = Lists.newArrayList();
       QueryResult result = (QueryResult) ret.getData();
       //遍历查询结果,将所有Id添加到objectIds中
       result.getDataList().forEach(item -> {
           Map map = (Map) item;
           objectIds.add(map.get("_id"));
       });
       //最后返回objectIds
       return objectIds;
   }

   public static void main(String[] args) throws IOException {
       //调试器
       DebugHelper helper = new DebugHelper();
       helper.init();
       Map<String, Object> param = new HashMap<>();
       //模拟调试的上下文,例如开发时想模拟一个客户对象的上下文,以方便开发
       FunctionContext context = helper.context("object_zBB6O__c", "63fd7a30ffd89f00013c7be3");
       List execute = new QueryListExample().execute(context, param);
       log.info(execute);
   }}
       Copied!

#2. 返回类型为QueryTemplate

package fx.custom.apl.example.scope_rule;
import com.fxiaoke.functions.FunctionContext;
import com.fxiaoke.functions.Fx;
import com.fxiaoke.functions.client.DebugHelper;
import com.fxiaoke.functions.model.QueryTemplate;
import com.fxiaoke.functions.template.IQueryTemplateAction;
import com.fxiaoke.functions.tools.QueryOperator;
import com.fxiaoke.functions.utils.Maps;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* QueryTemplate范围规则样例
* 使用QueryTemplate限制查找关联字段的选择范围
*/
public class QueryTemplateExample implements IQueryTemplateAction {
   /**
    * 范围规则函数(QueryTemplate)的运行方法
    */
   @Override
   public QueryTemplate execute(FunctionContext context, Map<String, Object> args) {

       //关联的字段
       String type = (String) context.getData().get("field_cG001__c");
       String name = (String) context.getData().get("name");

       //构造QueryTemplate --- //关联对象的字段
       QueryTemplate template1 = QueryTemplate.AND(
               Maps.of("name", QueryOperator.EQ(name)),
               Maps.of("field_g7Zeh__c", QueryOperator.EQ(type))
       );

       QueryTemplate template2 = QueryTemplate.AND(
               Maps.of("owner", QueryOperator.EQ("100")),
               Maps.of("record_type", QueryOperator.EQ("default__c"))
       );

       //QueryTemplate使用OR条件需要单独开通,请联系销售人员下订单开通产品:【对象列表筛选支持或者】
       QueryTemplate template3 = QueryTemplate.AND(template1, template2);

       return template3;
   }


   public static void main(String[] args) throws IOException {
       //调试器
       DebugHelper helper = new DebugHelper();
       helper.init();
       Map<String, Object> param = new HashMap<>();
       //模拟调试的上下文,例如开发时想模拟一个客户对象的上下文,以方便开发
       FunctionContext context = helper.context("object_zBB6O__c", "63fd7a30ffd89f00013c7be3");
       QueryTemplate execute = new QueryTemplateExample().execute(context, param);
       Fx.log.info(execute);
   }}
       Copied!

#3. 返回类型为RangeRule

package fx.custom.apl.example.scope_rule;
import com.fxiaoke.functions.FunctionContext;
import com.fxiaoke.functions.Fx;
import com.fxiaoke.functions.client.DebugHelper;
import com.fxiaoke.functions.model.QueryTemplate;
import com.fxiaoke.functions.model.RangeRule;
import com.fxiaoke.functions.template.IRangeRuleAction;
import com.fxiaoke.functions.tools.QueryOperator;
import com.fxiaoke.functions.utils.Maps;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* @type functions
* @returntype RangeRule
* @namespace scope_rule
* @targetmethod execute
*/
public class RangeRuleExample implements IRangeRuleAction {

   /**
    * 范围规则函数(rangeRule)函数的运行方法
    */
   @Override
   public RangeRule execute(FunctionContext context, Map<String, Object> args) {

       //关联的字段
       String type = (String) context.getData().get("field_cG001__c");
       String name = (String) context.getData().get("name");

       //构造QueryTemplate --- //关联对象的字段
       QueryTemplate template1 = QueryTemplate.AND(
               Maps.of("name", QueryOperator.EQ(name)),
               Maps.of("field_g7Zeh__c", QueryOperator.EQ(type))
       );

       QueryTemplate template2 = QueryTemplate.AND(
               Maps.of("owner", QueryOperator.EQ("100")),
               Maps.of("record_type", QueryOperator.EQ("default__c"))
       );

       //QueryTemplate使用OR条件需要单独开通,请联系销售人员下订单开通产品:【对象列表筛选支持或者】
       QueryTemplate template3 = QueryTemplate.AND(template1, template2);

       //构造RangeRule
       RangeRule rangeRule = RangeRule.builder()
               .queryTemplate(template3)
               .recordType("record_q6iJ7__c") // 查找关联新建时默认用该业务类型
               .build();
       return rangeRule;
   }


   public static void main(String[] args) throws IOException {
       //调试器
       DebugHelper helper = new DebugHelper();
       helper.init();
       Map<String, Object> param = new HashMap<>();
       //模拟调试的上下文,例如开发时想模拟一个客户对象的上下文,以方便开发
       FunctionContext context = helper.context("object_zBB6O__c", "63fd7a30ffd89f00013c7be3");
       RangeRule execute = new RangeRuleExample().execute(context, param);
       Fx.log.info(execute);
   }}


部分内容来源于互联网,如有侵权,请联系客服删除处理。
在线咨询 拨打电话