use of com.qlangtech.tis.manage.biz.dal.pojo.RoleCriteria in project tis by qlangtech.
the class RoleAction method doUpdateRole.
/**
* 更新角色
*
* @param context
*/
@Func(PermissionConstant.AUTHORITY_ROLE_UPDATE)
public void doUpdateRole(Context context) {
// 用户选中的func功能集合
final List<Integer> funcids = Arrays.asList(this.getIntAry("funcid"));
final Role role = this.getRoleDAO().loadFromWriteDB(this.getInt("roleid"));
String roleName = this.getString("rolename");
role.setRoleName(roleName);
context.put("role", role);
context.put(selfuncidKEY, Collections.unmodifiableCollection(funcids));
if (StringUtils.isBlank(roleName)) {
this.addErrorMessage(context, "请添写角色名称");
return;
}
RoleCriteria criteria = new RoleCriteria();
criteria.createCriteria().andRoleNameEqualTo(roleName).andRIdNotEqualTo(role.getrId());
if (this.getRoleDAO().countByExample(criteria) > 0) {
this.addErrorMessage(context, "角色名称:“" + roleName + "”已经创建");
return;
}
if (funcids.size() < 1) {
this.addErrorMessage(context, "请为新添加的角色设置相应的功能");
return;
}
FuncRoleRelationCriteria fcriteria = new FuncRoleRelationCriteria();
fcriteria.createCriteria().andRIdEqualTo(role.getrId());
List<FuncRoleRelation> rellist = this.getFuncRoleRelationDAO().selectByExample(fcriteria);
List<Integer> orignfunclist = new ArrayList<Integer>();
for (FuncRoleRelation rel : rellist) {
orignfunclist.add(rel.getFuncId());
}
List<Integer> addfuncs = new ArrayList<Integer>();
// 需要删除的
for (Integer funcid : funcids) {
if (orignfunclist.contains(funcid)) {
orignfunclist.remove(funcid);
} else {
addfuncs.add(funcid);
}
}
for (Integer funcid : orignfunclist) {
fcriteria = new FuncRoleRelationCriteria();
fcriteria.createCriteria().andRIdEqualTo(role.getrId()).andFuncIdEqualTo(funcid);
this.getFuncRoleRelationDAO().deleteByExample(fcriteria);
}
Role update = new Role();
update.setRoleName(roleName);
RoleCriteria rcriteria = new RoleCriteria();
rcriteria.createCriteria().andRIdEqualTo(role.getrId());
this.getRoleDAO().updateByExampleSelective(update, rcriteria);
// 需要添加的
createRelation(addfuncs, role);
this.addActionMessage(context, "成功更新角色:“" + role.getRoleName() + "”");
}
use of com.qlangtech.tis.manage.biz.dal.pojo.RoleCriteria in project tis by qlangtech.
the class RoleAction method doAddRole.
@Func(PermissionConstant.AUTHORITY_ROLE_ADD)
public void doAddRole(Context context) {
String roleName = this.getString("rolename");
final Integer[] funcids = (Integer[]) getSelfuncid().toArray();
if (StringUtils.isBlank(roleName)) {
this.addErrorMessage(context, "请添写角色名称");
return;
}
RoleCriteria criteria = new RoleCriteria();
criteria.createCriteria().andRoleNameEqualTo(roleName);
if (this.getRoleDAO().countByExample(criteria) > 0) {
this.addErrorMessage(context, "角色名称:“" + roleName + "”已经创建");
return;
}
if (funcids.length < 1) {
this.addErrorMessage(context, "请为新添加的角色设置相应的功能");
return;
}
Role role = new Role();
role.setGmtCreate(new Date());
role.setGmtModified(new Date());
role.setRoleName(roleName);
Integer newRoleId = this.getRoleDAO().insertSelective(role);
role.setrId(newRoleId);
createRelation(Arrays.asList(funcids), role);
this.addActionMessage(context, "成功添加角色:“" + roleName + "”");
}
Aggregations