You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
521 lines
17 KiB
521 lines
17 KiB
package com.fr.plugin.teshe.services; |
|
|
|
import com.fr.plugin.teshe.entity.TieSheDBAccessProvider; |
|
import com.fr.plugin.teshe.entity.UserInOrganEntity; |
|
import com.fr.plugin.teshe.entity.UserRoleMenuItemDAO; |
|
import com.fr.plugin.teshe.entity.UserRoleMenuItemEntity; |
|
import com.fr.stable.db.action.DBAction; |
|
import com.fr.stable.db.dao.DAOContext; |
|
|
|
import java.util.ArrayList; |
|
import java.util.List; |
|
|
|
public class UserRoleMenuDBAUtil { |
|
private static UserRoleMenuDBAUtil instance; |
|
|
|
public static UserRoleMenuDBAUtil getInstance(){ |
|
if(instance == null){ |
|
instance = new UserRoleMenuDBAUtil(); |
|
} |
|
return instance; |
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
* 获取该用户在所有组织上的工作授权上的管理功能数据 |
|
* @param userId |
|
* @return |
|
*/ |
|
public List<UserRoleMenuItemEntity> getWorkAuthorityManageMenuDatasAndParent(String userId,String orgCode){ |
|
try{ |
|
List<UserRoleMenuItemEntity> entities = TieSheDBAccessProvider.tieSheDbAccessor.runQueryAction(new DBAction<List<UserRoleMenuItemEntity>>() { |
|
|
|
@Override |
|
public List<UserRoleMenuItemEntity> run(DAOContext daoContext) throws Exception { |
|
return daoContext.getDAO(UserRoleMenuItemDAO.class).getWorkAuthorityManageMenuDatasAndParent(userId,orgCode); |
|
} |
|
}); |
|
|
|
return entities; |
|
} |
|
catch(Exception ex){ |
|
ex.printStackTrace(); |
|
return new ArrayList<>(); |
|
} |
|
} |
|
|
|
|
|
/** |
|
* 删除机构上的用户授权数据 |
|
* @param userId |
|
* @param organCode |
|
*/ |
|
public void removeAuthorityDataInOrgan(String userId,String organCode){ |
|
try{ |
|
TieSheDBAccessProvider.tieSheDbAccessor.runDMLAction(new DBAction<UserInOrganEntity>() { |
|
@Override |
|
public UserInOrganEntity run(DAOContext context) throws Exception { |
|
// UserInOrganEntity entity = context.getDAO(UserInOrganDAO.class).getById(id); |
|
context.getDAO(UserRoleMenuItemDAO.class).removeAuthorityDataInOrgan(userId,organCode); |
|
return null; |
|
} |
|
}); |
|
}catch(Throwable e){ |
|
e.printStackTrace(); |
|
} |
|
} |
|
|
|
/** |
|
* 删除授权数据 |
|
* @param id |
|
*/ |
|
public void deleteUserRoleMenuById(String id){ |
|
try{ |
|
TieSheDBAccessProvider.tieSheDbAccessor.runDMLAction(new DBAction<UserInOrganEntity>() { |
|
@Override |
|
public UserInOrganEntity run(DAOContext context) throws Exception { |
|
// UserInOrganEntity entity = context.getDAO(UserInOrganDAO.class).getById(id); |
|
context.getDAO(UserRoleMenuItemDAO.class).removeEntityById(id); |
|
return null; |
|
} |
|
}); |
|
}catch(Throwable e){ |
|
e.printStackTrace(); |
|
} |
|
} |
|
|
|
|
|
|
|
/** |
|
* 根据用户id获取授权数据 |
|
* @param userId |
|
* @return |
|
*/ |
|
public List<UserRoleMenuItemEntity> findAllUserAuthorityDatasByUserId(String userId){ |
|
//查询数据库 |
|
try{ |
|
List<UserRoleMenuItemEntity> entities = TieSheDBAccessProvider.tieSheDbAccessor.runQueryAction(new DBAction<List<UserRoleMenuItemEntity>>() { |
|
|
|
@Override |
|
public List<UserRoleMenuItemEntity> run(DAOContext daoContext) throws Exception { |
|
|
|
|
|
return daoContext.getDAO(UserRoleMenuItemDAO.class).findAllByUserId(userId); |
|
} |
|
}); |
|
|
|
return entities; |
|
} |
|
catch(Exception ex){ |
|
ex.printStackTrace(); |
|
return null; |
|
} |
|
} |
|
|
|
|
|
/** |
|
* 根据用户id,授权数据id来获取授权数据 |
|
* @param userId |
|
* @param menuId |
|
* @return |
|
*/ |
|
public List<UserRoleMenuItemEntity> findAllUserAuthorityDatas(String userId, String menuId){ |
|
//查询数据库 |
|
try{ |
|
List<UserRoleMenuItemEntity> entities = TieSheDBAccessProvider.tieSheDbAccessor.runQueryAction(new DBAction<List<UserRoleMenuItemEntity>>() { |
|
|
|
@Override |
|
public List<UserRoleMenuItemEntity> run(DAOContext daoContext) throws Exception { |
|
|
|
|
|
return daoContext.getDAO(UserRoleMenuItemDAO.class).findAll(userId,menuId); |
|
} |
|
}); |
|
|
|
return entities; |
|
} |
|
catch(Exception ex){ |
|
ex.printStackTrace(); |
|
return null; |
|
} |
|
} |
|
|
|
/** |
|
* 添加授权数据 |
|
* @param entity |
|
* @throws Exception |
|
*/ |
|
public void insertUserRoleMenuItemData(UserRoleMenuItemEntity entity) throws Exception { |
|
TieSheDBAccessProvider.tieSheDbAccessor.runDMLAction(new DBAction<UserRoleMenuItemEntity>() { |
|
@Override |
|
public UserRoleMenuItemEntity run(DAOContext daoContext) throws Exception { |
|
daoContext.getDAO(UserRoleMenuItemDAO.class).addEntityOrUpdate(entity); |
|
return entity; |
|
} |
|
}); |
|
} |
|
|
|
/** |
|
* 更新授权数据, |
|
* @param userId |
|
* @param menuId |
|
* @param authorityValue |
|
*/ |
|
public void updateUserRoleMenuItemDataByUserIdAndMenuId(String userId,String menuId,int authorityValue){ |
|
try{ |
|
TieSheDBAccessProvider.tieSheDbAccessor.runDMLAction(new DBAction<UserRoleMenuItemEntity>() { |
|
@Override |
|
public UserRoleMenuItemEntity run(DAOContext context) throws Exception { |
|
// UserInOrganEntity entity = context.getDAO(UserInOrganDAO.class).getById(id); |
|
context.getDAO(UserRoleMenuItemDAO.class).updateEntityByUserIdAndMenuId(userId,menuId,authorityValue); |
|
return null; |
|
} |
|
}); |
|
}catch(Throwable e){ |
|
e.printStackTrace(); |
|
} |
|
} |
|
|
|
/** |
|
* 删除授权数据 |
|
* @param userId |
|
* @param menuId |
|
*/ |
|
public void deleteUserRoleMenuItemDataByUserIdAndMenuId(String userId,String menuId){ |
|
try{ |
|
TieSheDBAccessProvider.tieSheDbAccessor.runDMLAction(new DBAction<UserRoleMenuItemEntity>() { |
|
@Override |
|
public UserRoleMenuItemEntity run(DAOContext context) throws Exception { |
|
// UserInOrganEntity entity = context.getDAO(UserInOrganDAO.class).getById(id); |
|
context.getDAO(UserRoleMenuItemDAO.class).removeEntityByUserIdAndMenuId(userId,menuId); |
|
return null; |
|
} |
|
}); |
|
}catch(Throwable e){ |
|
e.printStackTrace(); |
|
} |
|
} |
|
|
|
/** |
|
* 根据用户id,授权id来获取授权数据 |
|
* @param userId |
|
* @param menuId |
|
* @return |
|
*/ |
|
public UserRoleMenuItemEntity getUserRoleMenuItemEntityByUserIdAndMenuId(String userId,String menuId){ |
|
//查询数据库 |
|
try{ |
|
UserRoleMenuItemEntity entities = TieSheDBAccessProvider.tieSheDbAccessor.runQueryAction(new DBAction<UserRoleMenuItemEntity>() { |
|
|
|
@Override |
|
public UserRoleMenuItemEntity run(DAOContext daoContext) throws Exception { |
|
return daoContext.getDAO(UserRoleMenuItemDAO.class).getUserRoleMenuItemEntityByUserIdAndMenuId(userId,menuId); |
|
} |
|
}); |
|
|
|
return entities; |
|
} |
|
catch(Exception ex){ |
|
ex.printStackTrace(); |
|
return null; |
|
} |
|
} |
|
|
|
public List<UserRoleMenuItemEntity> getUserAuthorityDataInOrgan(String userId,String orgCode) { |
|
try{ |
|
List<UserRoleMenuItemEntity> entities = TieSheDBAccessProvider.tieSheDbAccessor.runQueryAction(new DBAction<List<UserRoleMenuItemEntity>>() { |
|
|
|
@Override |
|
public List<UserRoleMenuItemEntity> run(DAOContext daoContext) throws Exception { |
|
return daoContext.getDAO(UserRoleMenuItemDAO.class).getUserAuthorityDataInOrgan(userId,orgCode); |
|
} |
|
}); |
|
|
|
return entities; |
|
} |
|
catch(Exception ex){ |
|
ex.printStackTrace(); |
|
return null; |
|
} |
|
} |
|
|
|
|
|
/** |
|
*设置维护授权数据 |
|
* @param userId |
|
* @param menuId |
|
* @param orgCode |
|
* @param authorityValue |
|
* @throws Exception |
|
*/ |
|
public void setMaintainAuthority(String userId, String menuId, String orgCode,int authorityValue) throws Exception { |
|
TieSheDBAccessProvider.tieSheDbAccessor.runDMLAction(new DBAction<UserRoleMenuItemEntity>() { |
|
@Override |
|
public UserRoleMenuItemEntity run(DAOContext daoContext) throws Exception { |
|
daoContext.getDAO(UserRoleMenuItemDAO.class).setMaintainAuthority(userId,menuId,orgCode,authorityValue); |
|
return null; |
|
} |
|
}); |
|
|
|
|
|
} |
|
|
|
/** |
|
*设置管理授权数据 |
|
* @param userId |
|
* @param menuId |
|
* @param orgCode |
|
* @param authorityValue |
|
* @throws Exception |
|
*/ |
|
public void setManageAuthority(String userId, String menuId, String orgCode,int authorityValue) throws Exception { |
|
TieSheDBAccessProvider.tieSheDbAccessor.runDMLAction(new DBAction<UserRoleMenuItemEntity>() { |
|
@Override |
|
public UserRoleMenuItemEntity run(DAOContext daoContext) throws Exception { |
|
daoContext.getDAO(UserRoleMenuItemDAO.class).setManageAuthority(userId,menuId,orgCode,authorityValue); |
|
return null; |
|
} |
|
}); |
|
|
|
|
|
} |
|
|
|
/** |
|
* 设置查看授权数据 |
|
* @param userId |
|
* @param menuId |
|
* @param orgCode |
|
* @param authorityValue |
|
* @throws Exception |
|
*/ |
|
public void setViewAuthority(String userId, String menuId, String orgCode,int authorityValue) throws Exception { |
|
TieSheDBAccessProvider.tieSheDbAccessor.runDMLAction(new DBAction<UserRoleMenuItemEntity>() { |
|
@Override |
|
public UserRoleMenuItemEntity run(DAOContext daoContext) throws Exception { |
|
daoContext.getDAO(UserRoleMenuItemDAO.class).setViewAuthority(userId,menuId,orgCode,authorityValue); |
|
return null; |
|
} |
|
}); |
|
} |
|
|
|
/** |
|
* 删除授权数据 |
|
* @param userId |
|
* @param organCode |
|
* @throws Exception |
|
*/ |
|
public void deleteByUserIdAndOrgCode(String userId,String organCode) throws Exception { |
|
TieSheDBAccessProvider.tieSheDbAccessor.runDMLAction(new DBAction<UserRoleMenuItemEntity>() { |
|
@Override |
|
public UserRoleMenuItemEntity run(DAOContext daoContext) throws Exception { |
|
daoContext.getDAO(UserRoleMenuItemDAO.class).deleteByUserIdAndOrgCode(userId,organCode); |
|
return null; |
|
} |
|
}); |
|
} |
|
|
|
|
|
/** |
|
* 获取该用户在所有组织上该授权菜单的管理权限数据 |
|
* @param userId 用户id |
|
* @param menuId 菜单id |
|
* @param authrotityValue 0 不限制,1 关闭,2 打开 |
|
* @return |
|
* @throws Exception |
|
*/ |
|
public List<UserRoleMenuItemEntity> getAllManageAuthorityByAuthorityId(String userId,String menuId,int authrotityValue) throws Exception { |
|
try{ |
|
List<UserRoleMenuItemEntity> entities = TieSheDBAccessProvider.tieSheDbAccessor.runQueryAction(new DBAction<List<UserRoleMenuItemEntity>>() { |
|
|
|
@Override |
|
public List<UserRoleMenuItemEntity> run(DAOContext daoContext) throws Exception { |
|
return daoContext.getDAO(UserRoleMenuItemDAO.class).getAllManageAuthorityByAuthorityId(userId,menuId,authrotityValue); |
|
} |
|
}); |
|
|
|
return entities; |
|
} |
|
catch(Exception ex){ |
|
ex.printStackTrace(); |
|
return null; |
|
} |
|
|
|
} |
|
|
|
/** |
|
* 获取该用户在所有组织上该授权菜单的查看权限数据 |
|
* @param userId 用户id |
|
* @param menuId 菜单id |
|
* @param authrotityValue 0 不限制,1 关闭,2 打开 |
|
* @return |
|
* @throws Exception |
|
*/ |
|
public List<UserRoleMenuItemEntity> getAllViewAuthorityByAuthorityId(String userId,String menuId,int authrotityValue) throws Exception { |
|
try{ |
|
List<UserRoleMenuItemEntity> entities = TieSheDBAccessProvider.tieSheDbAccessor.runQueryAction(new DBAction<List<UserRoleMenuItemEntity>>() { |
|
|
|
@Override |
|
public List<UserRoleMenuItemEntity> run(DAOContext daoContext) throws Exception { |
|
return daoContext.getDAO(UserRoleMenuItemDAO.class).getAllViewAuthorityByAuthorityId(userId,menuId,authrotityValue); |
|
} |
|
}); |
|
|
|
return entities; |
|
} |
|
catch(Exception ex){ |
|
ex.printStackTrace(); |
|
return null; |
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
* 获取某个用户在某个机构上是否有日志查看的的查看权限 |
|
* @param userId |
|
* @param orgCode |
|
* @return |
|
*/ |
|
public UserRoleMenuItemEntity getViewOperateLogViewInOrgan(String userId,String orgCode){ |
|
try{ |
|
UserRoleMenuItemEntity entities = TieSheDBAccessProvider.tieSheDbAccessor.runQueryAction(new DBAction<UserRoleMenuItemEntity>() { |
|
|
|
@Override |
|
public UserRoleMenuItemEntity run(DAOContext daoContext) throws Exception { |
|
return daoContext.getDAO(UserRoleMenuItemDAO.class).getViewOperateLogViewInOrgan(userId,orgCode); |
|
} |
|
}); |
|
|
|
return entities; |
|
} |
|
catch(Exception ex){ |
|
ex.printStackTrace(); |
|
return null; |
|
} |
|
} |
|
|
|
|
|
/** |
|
* 获取授权数据 |
|
* @param userId |
|
* @param menuId |
|
* @param orgCode |
|
* @return |
|
* @throws Exception |
|
*/ |
|
public List<UserRoleMenuItemEntity> getUserRoleDataInOrgan(String userId,String menuId,String orgCode) throws Exception{ |
|
try{ |
|
List<UserRoleMenuItemEntity> entities = TieSheDBAccessProvider.tieSheDbAccessor.runQueryAction(new DBAction<List<UserRoleMenuItemEntity>>() { |
|
|
|
@Override |
|
public List<UserRoleMenuItemEntity> run(DAOContext daoContext) throws Exception { |
|
return daoContext.getDAO(UserRoleMenuItemDAO.class).getUserRoleDataInOrgan(userId,menuId,orgCode); |
|
} |
|
}); |
|
|
|
return entities; |
|
} |
|
catch(Exception ex){ |
|
ex.printStackTrace(); |
|
return new ArrayList<>(); |
|
} |
|
} |
|
|
|
public List<UserRoleMenuItemEntity> getUserRoleDataInOrganAndParent(String userId, String menuId, String orgCode) throws Exception{ |
|
try{ |
|
List<UserRoleMenuItemEntity> entities = TieSheDBAccessProvider.tieSheDbAccessor.runQueryAction(new DBAction<List<UserRoleMenuItemEntity>>() { |
|
|
|
@Override |
|
public List<UserRoleMenuItemEntity> run(DAOContext daoContext) throws Exception { |
|
return daoContext.getDAO(UserRoleMenuItemDAO.class).getUserRoleDataInOrganAndParent(userId,menuId,orgCode); |
|
} |
|
}); |
|
|
|
return entities; |
|
} |
|
catch(Exception ex){ |
|
ex.printStackTrace(); |
|
return new ArrayList<>(); |
|
} |
|
} |
|
|
|
/** |
|
* 获取管理授权数据 |
|
* @param userId |
|
* @param orgCode |
|
* @return |
|
*/ |
|
public UserRoleMenuItemEntity getManageAuthorityInOrgan(String userId,String orgCode){ |
|
try{ |
|
UserRoleMenuItemEntity entities = TieSheDBAccessProvider.tieSheDbAccessor.runQueryAction(new DBAction<UserRoleMenuItemEntity>() { |
|
|
|
@Override |
|
public UserRoleMenuItemEntity run(DAOContext daoContext) throws Exception { |
|
return daoContext.getDAO(UserRoleMenuItemDAO.class).getManageAuthorityInOrgan(userId,orgCode); |
|
} |
|
}); |
|
|
|
return entities; |
|
} |
|
catch(Exception ex){ |
|
ex.printStackTrace(); |
|
return null; |
|
} |
|
} |
|
|
|
|
|
/** |
|
* 根据用户id,机构code获取查看授权数据 |
|
* @param userId |
|
* @param orgCode |
|
* @return |
|
*/ |
|
public UserRoleMenuItemEntity getViewAuthorityInOrgan(String userId, String orgCode){ |
|
try{ |
|
UserRoleMenuItemEntity entities = TieSheDBAccessProvider.tieSheDbAccessor.runQueryAction(new DBAction<UserRoleMenuItemEntity>() { |
|
|
|
@Override |
|
public UserRoleMenuItemEntity run(DAOContext daoContext) throws Exception { |
|
return daoContext.getDAO(UserRoleMenuItemDAO.class).getViewAuthorityInOrgan(userId,orgCode); |
|
} |
|
}); |
|
|
|
return entities; |
|
} |
|
catch(Exception ex){ |
|
ex.printStackTrace(); |
|
return null; |
|
} |
|
} |
|
|
|
/** |
|
* 获取查看权限数据 |
|
* @param userId |
|
* @param orgCode |
|
* @return |
|
*/ |
|
public static UserRoleMenuItemEntity getViewAuthorityViewInOrgan(String userId,String orgCode){ |
|
try{ |
|
UserRoleMenuItemEntity entities = TieSheDBAccessProvider.tieSheDbAccessor.runQueryAction(new DBAction<UserRoleMenuItemEntity>() { |
|
|
|
@Override |
|
public UserRoleMenuItemEntity run(DAOContext daoContext) throws Exception { |
|
return daoContext.getDAO(UserRoleMenuItemDAO.class).getViewAuthorityViewInOrgan(userId,orgCode); |
|
} |
|
}); |
|
|
|
return entities; |
|
} |
|
catch(Exception ex){ |
|
ex.printStackTrace(); |
|
return null; |
|
} |
|
} |
|
|
|
|
|
|
|
}
|
|
|