数据拦截
<h2>数据拦截</h2>
<p>目前存在的拦截器有: </p>
<table>
<thead>
<tr>
<th>名称</th>
<th>场景</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>OfficeIntercept</td>
<td>Office数据拦截器</td>
<td>菜单配置(必须)</td>
</tr>
<tr>
<td>SingleIntercept</td>
<td>单表视图导入数据时候用</td>
<td>菜单配置(可选)</td>
</tr>
<tr>
<td>MetaObjectIntercept</td>
<td>对象拦截(包括查询前后,数据操作前后)</td>
<td>元对象配置(可选)</td>
</tr>
</tbody>
</table>
<p>我们以MetaObjectIntercept为主看下怎么操作,其他的两种类似,
我们说一个场景:新增数据的时候添加的时候需要检测是否重复、新增以后需要在其他业务表记录相关记录,其实这个业务就是我们实现的我们 系统管理=》用户管理。
我们来看下操作步骤:</p>
<ol>
<li>实现自己的业务类:UserInfoIntercept ,继承自MetaObjectIntercept</li>
<li>
<p>添加新增前业务 和 新增后业务,代码片段如下:</p>
<p>public String addBefore(AopContext ac) throws Exception {
super.addBefore(ac);</p>
<pre><code>//登录名不能重复
String login_id = ac.record.getStr("login_id");
Record user = Db.use(EovaConst.DS_MAIN).findFirst("select * from users where login_id=?", login_id);
if(user != null)
return "用户名重复";
//存第一角色
ac.record.set("rid", ac.record.getStr("rids").split(",")[0]);
return null;</code></pre>
<p>}
<br></p>
<p>public String addAfter(AopContext ac) throws Exception {</p>
<pre><code>String psw = xx.getConfig("user_df_psw", "000000");
User lUser = new User();
lUser.set("login_id", ac.record.get("login_id"));
lUser.set("login_pwd", EncryptUtil.getSM32(psw));
lUser.set("rid", ac.record.get("rid"));
lUser.set("id", ac.record.get("id"));
lUser.save();
return null;</code></pre>
<p>}</p>
</li>
<li>在此元对象添加:业务拦截器(平台维护=》元数据管理=》修改(选择此元对象)):com.oss.user.UserInfoIntercept ,保存即可完成。</li>
<li>可以在用户管理模块 <strong>添加重复的登录名的检测执行情况</strong>,以及添加用户完成 <strong>新增后业务是否执行(从属表也添加一条数据)</strong></li>
</ol>