如果值addField值在在addValue里面,enableAdd=true

//#region 操作前验证
  "ruleDb": {
    //和field关联的字段,新增时候使用
    "addRefField": "objectId",
    "addShowField": "objectName",
    "selectSql": "select object_id app_id,object_name app_name from bo_app_config_user where user_ref_id=@userRefId",
    "sql": "select app_name name,app_id value from bo_app_config where app_id=@appId and (@_developer=1 or create_user_id=@_userId or create_user_id in @_mergeUserId or app_id in (select object_id from bo_app_config_user where (user_id=@_userId or user_id in @_mergeUserId) and user_type=2 and is_enabled=1))",
    "where": " or user_ref_id=@userRefId",
    "field": "appId",
    "showField": "appName",
    //添加新增验证
    "addEnabled": true,
    //如果值addField值在在addValue里面,addEnabled=true
    "addValue": [ "2" ],
    "addField": "userType",
    //如果上面数据存在,表示有权限
    "reverse": true,
    "value": null,
    "messageD": "无权限【{0}】,一定要删除,请联系管理员",
    "messageI": "无权限【{0}】,一定要添加,请联系管理员",
    "messageU": "无权限【{0}】,一定要修改,请联系管理员"
  },
  //#endregion 操作前验证

主表情况使用,如bo-app-config

{
  //#region 操作前验证
  "ruleDb": {
    "addRefField": "appId",
    "addShowField": "appName",
    "selectSql": "select app_id,app_name from bo_app_config where app_id=@appId",
    "sql": "select app_name name,app_id value from bo_app_config where ({primary_where_sql}) and (@_developer=1 or create_user_id=@_userId or create_user_id in @_mergeUserId or app_id in (select object_id from bo_app_config_user where (user_id=@_userId or user_id in @_mergeUserId) and user_type=2 and is_enabled=1))",
    "where": " or app_id=@appId",
    "field": "appId",
    "showField": "appName",
    //添加新增验证
    //"addEnabled": true,
    //如果上面数据存在,表示有权限
    "reverse": true,
    "value": null,
    "messageD": "无权限【{0}】,一定要删除,请联系管理员",
    "messageI": "无权限【{0}】,一定要添加,请联系管理员",
    "messageU": "无权限【{0}】,一定要修改,请联系管理员"
  },
  //#endregion 操作前验证
  "rules": {}
}

子表情况使用,如bo-app-config-user

{
  //#region 操作前验证
  "ruleDb": {
    //和field关联的字段,新增时候使用
    "addRefField": "objectId",
    "addShowField": "objectName",
    "selectSql": "select object_id app_id,object_name app_name from bo_app_config_user where user_ref_id=@userRefId",
    "sql": "select app_name name,app_id value from bo_app_config where app_id=@appId and (@_developer=1 or create_user_id=@_userId or create_user_id in @_mergeUserId or app_id in (select object_id from bo_app_config_user where (user_id=@_userId or user_id in @_mergeUserId) and user_type=2 and is_enabled=1))",
    "where": " or user_ref_id=@userRefId",
    "field": "appId",
    "showField": "appName",
    //添加新增验证
    "addEnabled": true,
    //如果上面数据存在,表示有权限
    "reverse": true,
    "value": null,
    "messageD": "无权限【{0}】,一定要删除,请联系管理员",
    "messageI": "无权限【{0}】,一定要添加,请联系管理员",
    "messageU": "无权限【{0}】,一定要修改,请联系管理员"
  },
  //#endregion 操作前验证
  "rules": {}
}

添加用户唯一验证


{
  //#region 操作前验证
  "ruleDb": {
    //和field关联的字段,新增时候使用
    "addRefField": "objectId",
    "addShowField": "objectName",
    "selectSql": "select object_id app_id,object_name app_name from bo_app_config_user where user_ref_id=@userRefId",
    "sql": "select app_name name,app_id value from bo_app_config where app_id=@appId and (@_developer=1 or create_user_id=@_userId or create_user_id in @_mergeUserId or app_id in (select object_id from bo_app_config_user where (user_id=@_userId or user_id in @_mergeUserId) and user_type=2 and is_enabled=1))",
    "where": " or user_ref_id=@userRefId",
    "field": "appId",
    "showField": "appName",
    //添加新增验证
    //"addEnabled": true,
    //如果上面数据存在,表示有权限
    "reverse": true,
    "value": null,
    "messageD": "无权限【{0}】,一定要删除,请联系管理员",
    "messageI": "无权限【{0}】,一定要添加,请联系管理员",
    "messageU": "无权限【{0}】,一定要修改,请联系管理员"
  },
  //#endregion 操作前验证
  "rules": {
    "userId": [
      {
        "type": "required",
        "required": true,
        "isAdd": true,
        "isEdit": true,
        "message": "【{user_id}】值必须填写。"
      },
      {
        "type": "maxlength",
        "required": false,
        "isAdd": true,
        "isEdit": true,
        "max": 36,
        "message": "【{user_id}】值最大长度为36。"
      },
      {
        "type": "db", //remote db  远程验证 rule 和 sql必须填写;  db:sql必须填写
        "url": "~/bo/api/v3/remote/unique/{mkey}/{resField}?ownerId={ownerId}&sysId={sysId}&rule={rule}&{params}",
        "sql": "select count(user_id) from bo_app_config_user where object_id=@objectId and user_id=@userId",
        "isAdd": true,
        "isEdit": false,
        "message": "【{user_id}】已存在。"
      }
    ]
  }
}
文档更新时间: 2023-02-19 17:52   作者:admin