普元EOS中如何往Session的UserObject中设置自定义属性

xiaoyan shuai xiaoyan shuai
1 分钟前

至元数据起始


普元EOS中,如果需要往session中设置属性,该如何操作

这个运算逻辑为coframe登录的运算逻辑,uo.setAttributes(attributes);中的attributes可以是动态属性,比如下面例子中就是将用户的角色信息都放到userObject中

@Bizlet("登录系统,并返回用户对象")

public static UserObject initUserObject(DataObject acOperator) {

UserObject uo = new UserObject();

String userid = acOperator.getString("userid");

HashSet<String> roleSet = new HashSet<String>();

Connection conn = DBUtil.getConnection();

HashMap<String, Object> attributes = new HashMap<String, Object>();

ArrayList<DataObject> roleList = new ArrayList<DataObject>();

ArrayList<HashMap> sybList = new ArrayList<HashMap>();

ArrayList<HashMap> ywdyList = new ArrayList<HashMap>();

PreparedStatement ps = null;

PreparedStatement ps1 = null;

PreparedStatement ps2 = null;

PreparedStatement ps3 = null;

PreparedStatement ps4 = null;

ResultSet rs = null;

ResultSet rs1 = null;

ResultSet rs2 = null;

ResultSet rs3 = null;

ResultSet rs4 = null;

try {

// 查询人员基本信息

ps = conn.prepareStatement(SQLBASEINFO);

ps.setString(1, userid);

rs = ps.executeQuery();

if (rs.next()) {

// 存在操作员

String empid = rs.getString(EMPID);

int operatorid = Integer.parseInt(rs.getString(OPERATORID));

uo.setUserId(rs.getString(USERID));

uo.setUserMail(rs.getString("OEMAIL"));

uo.setUserName(rs.getString(USERNAME));

uo.setUserRealName(rs.getString(EMPNAME));

uo.setUserOrgId(rs.getString(ORGID));

uo.setUserOrgName(rs.getString(ORGNAME));

String skin = rs.getString(MENUTYPE);

// 设置 layout和style的默认值

attributes.put(ABFConfigKey.SKIN_LAYOUTATTR.getConfigValue(), ABFConfigKey.SKIN_DEFAULT_LAYOUT.getConfigValue());

attributes.put(ABFConfigKey.SKIN_STYLEATTR.getConfigValue(), ABFConfigKey.SKIN_DEFAULT_STYLE.getConfigValue());

if (StringUtil.isNotNullAndBlank(skin)) {

String[] tmp = skin.split(",");

if (tmp.length > 0) {

attributes.put(ABFConfigKey.SKIN_LAYOUTATTR.getConfigValue(), tmp[0]);

}

if (tmp.length > 1) {

attributes.put(ABFConfigKey.SKIN_STYLEATTR.getConfigValue(), tmp[1]);

}

}

attributes.put("orgseq", rs.getString(ORGSEQ));

attributes.put("orgcode", rs.getString(ORGCODE));

attributes.put("orgtype", rs.getString(ORGTYPE));

attributes.put("orgdegree", rs.getString("ORGDEGREE"));

attributes.put("empid", empid);

attributes.put("operatorid", rs.getString(OPERATORID));

// 查询角色列表

// 查询操作员角色

ps1 = conn.prepareStatement(SQLROLE);

// 设置参数

ps1.setInt(1, operatorid);

rs1 = ps1.executeQuery();

while (rs1.next()) {

String id = rs1.getString("roleid");

if (!roleSet.contains(id)) {

DataObject role = DataObjectUtil.createDataObject("org.gocom.abframe.dataset.privilege.AcRole");

role.setString("roleid", id);

roleSet.add(id);

roleList.add(role);

}

}

if (StringUtil.isNotNullAndBlank(empid)) {

// 关联员工,查询员工关联机构的角色列表,查询所在事业部、所在业务单元

int iempid = Integer.parseInt(empid);

ps2 = conn.prepareStatement(SQLORGROLE);

// 设置参数

ps2.setInt(1, iempid);

ps2.setInt(2, iempid);

ps2.setInt(3, iempid);

rs2 = ps2.executeQuery();

while (rs2.next()) {

String id = rs2.getString("roleid");

if (!roleSet.contains(id)) {

DataObject role = DataObjectUtil.createDataObject("org.gocom.abframe.dataset.privilege.AcRole");

role.setString("roleid", rs2.getString("roleid"));

roleSet.add(id);

roleList.add(role);

}

}

ps3 = conn.prepareStatement(SQLGETSYB);

ps3.setString(1, userid);

rs3 = ps3.executeQuery();

while (rs3.next()) {

HashMap syb = new HashMap();

syb.put("orgid", rs3.getInt("ORGID"));

syb.put("orgseq", rs3.getString("ORGSEQ"));

syb.put("userid", rs3.getString("USERID"));

sybList.add(syb);

}

ps4 = conn.prepareStatement(SQLGETYWDY);

ps4.setString(1, userid);

ps4.setString(2, userid);

rs4 = ps4.executeQuery();

while (rs4.next()) {

HashMap syb = new HashMap();

syb.put("orgid", rs4.getInt("ORGID"));

syb.put("orgseq", rs4.getString("ORGSEQ"));

syb.put("userid", rs4.getString("USERID"));

ywdyList.add(syb);

}

}

// 设置角色到用户对象中

attributes.put("roles", roleList.toArray(new DataObject[roleList.size()]));

attributes.put("sybs", sybList);

attributes.put("ywdys", ywdyList);

uo.setAttributes(attributes);

} else {

// 无此操作员

uo = null;

}

} catch (Exception e) {

uo = null;

LogUtil.logError("登录出错!", e, (Object) null);

} finally {

DBUtil.closeAll(conn, new PreparedStatement[] { ps, ps1, ps2, ps3, ps4 }, new ResultSet[] { rs, rs1, rs2, rs3, rs4 });

}

return uo;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值