mapper/rule特定字段必须当前用户 “type”: “user”,

,
    "userId": [
      {
        "type": "required",
        "required": true,
        "isAdd": true,
        "isEdit": true,
        "message": "【{user_id}】值必须填写。"
      },
      {
        "type": "user",
        "required": true,
        "isAdd": true,
        "isEdit": true,
        "message": "【{user_id}】只能操作自己数据。"
      },
      {
        "type": "maxlength",
        "required": false,
        "isAdd": true,
        "isEdit": true,
        "max": 36,
        "message": "【{user_id}】值最大长度为36。"
      }
    ]

多字段 or 字段

,
    "userId": [
      {
        "type": "required",
        "required": true,
        "isAdd": true,
        "isEdit": true,
        "message": "【{user_id}】值必须填写。"
      },
      {
        "type": "userOr",
        "required": true,
        "isAdd": true,
        "isEdit": true,
        "orField": "mergeUserId",
        "message": "【{user_id}】只能操作自己数据。"
      },
      {
        "type": "maxlength",
        "required": false,
        "isAdd": true,
        "isEdit": true,
        "max": 36,
        "message": "【{user_id}】值最大长度为36。"
      }
    ]
             case RuleType.UserOr:
                        if (!dictionaryUrl.ContainsKey("_userId") || dictionaryUrl["_userId"] == null)
                        {
                            throw new BizException(string.Format(message, rule.Min, rule.Max));
                        }
                        if (!dic.ContainsKey(rule.OrField) || dic[rule.OrField] == null)
                        {
                            throw new BizException(string.Format(message, rule.Min, rule.Max));
                        }
                      else if (dictionaryUrl["_userId"].ToString() != valueTemp.ToString() && dictionaryUrl["_userId"].ToString() != dic[rule.OrField].ToString())
                        {
                            throw new BizException(string.Format(message, rule.Min, rule.Max));
                        }
                        break;

mapper/rule 特定字段必须特定参数值 “type”: “fromParam”,

,
    "userId": [
      {
        "type": "required",
        "required": true,
        "isAdd": true,
        "isEdit": true,
        "message": "【{user_id}】值必须填写。"
      },
      {
        "type": "fromParam",
        "param":"_userId",
        "required": true,
        "isAdd": true,
        "isEdit": true,
        "message": "【{user_id}】只能操作自己数据。"
      },
      {
        "type": "maxlength",
        "required": false,
        "isAdd": true,
        "isEdit": true,
        "max": 36,
        "message": "【{user_id}】值最大长度为36。"
      }
    ]

DbExecuteRepository$Rule.cs

      //验证当前字段必须和系统内部用户一致(如自己操作自己数据)
                    case RuleType.User:
                        if (!dictionaryUrl.ContainsKey("_userId") || dictionaryUrl["_userId"] == null)
                        {
                            throw new BizException(string.Format(message, rule.Min, rule.Max));
                        }
                        else if (dictionaryUrl["_userId"].ToString() != valueTemp.ToString())
                        {
                            throw new BizException(string.Format(message, rule.Min, rule.Max));
                        }
                        break;
                    case RuleType.FromParam:
                        if (rule.Param == null || !dictionaryUrl.ContainsKey(rule.Param) || dictionaryUrl[rule.Param] == null)
                        {
                            throw new BizException(string.Format(message, rule.Min, rule.Max));
                        }
                        else if (dictionaryUrl[rule.Param].ToString() != valueTemp.ToString())
                        {
                            throw new BizException(string.Format(message, rule.Min, rule.Max));
                        }
                        break;

引用说明

RG3.BO.DB/DbExecuteService$BatSave.cs
RG3.BO.DB/AddService.cs
RG3.BO.DB/EditService.cs
RG3.BO.DB/ModifyService.cs

文档更新时间: 2022-01-09 20:59   作者:admin