Commit 1d9b615e by 罗绍泽

集成应用 角色管理bug修复

parent 94de09fd
......@@ -2,7 +2,6 @@ package com.jw.app.apps.action;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -63,12 +62,13 @@ public class dataAction extends BasicAction{
Map<String, Object> query = RequestUtils.getUpdateFieldMap(request,
RequestUtils.UPDATEDATAFIELDPREFIX);
try {
checkGrantApp(business);
query = QueryParamUtil.StringToDate(query);
//设置当前登陆人
//获取当前登录人有访问权限的所有app,USERID属性不为空,则表示该应用已安装
List<Map<String, Object>> listData = business
.list_allApps_by_user(query);
//flag=true表示未安装
Boolean flag = true;
private_putMapByKey("apps",listData);
//查找所有的app类型
Map<String, Object> queryCategory = RequestUtils.getUpdateFieldMap(request,
......@@ -76,46 +76,6 @@ public class dataAction extends BasicAction{
List<Map<String, Object>> listCategory = business
.list_allCategory(queryCategory);
private_putMapByKey("types",listCategory);
for (Map<String, Object> rm : listData) {
if(rm.get("USERID")!=null){
private_putMapByKey("apps",listData);
flag=false;
/*System.out.println("正常");*/
break;
}
}
//2上述结果中的USERID全部为null,表示一个app都没安装
if(flag==true){
//3.根据用户id来验证apps_uninstall有没有数据
List<Map<String, Object>> listUninstallData = business
.list_allUninstallApps_by_user(query);
if(listUninstallData.size()!=0){
//要把所有的应用都返回出去
Map<String, Object> queryApp = RequestUtils.getUpdateFieldMap(request,
RequestUtils.UPDATEDATAFIELDPREFIX);
List<Map<String, Object>> listAllApps = business
.list_AllApps(queryApp);
/*System.out.println("未安装表里有");*/
private_putMapByKey("apps",listAllApps);
}
else{
//4.如果也没有,表示这个用户是新建用户,需要初始化应用
//5.初始化应用
//6.把默认的app应用添加到install表中
//7.把不默认的app应用添加到uninstall表中
Map<String, Object> queryDefaultApp = RequestUtils.getUpdateFieldMap(request,
RequestUtils.UPDATEDATAFIELDPREFIX);
business.init_defaultApps(queryDefaultApp);
//8.重新查询关联表获得数据
List<Map<String, Object>> defaultData = business
.list_allApps_by_user(query);
/*System.out.println("默认");*/
private_putMapByKey("apps",defaultData);
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
......@@ -126,6 +86,87 @@ public class dataAction extends BasicAction{
return "json";
}
/**
* 验证用户有权限的app,数据整理
* @param business
* @date 2018-09-15 下午4:08:37
* @author luosz@jfbrother.com
*/
private void checkGrantApp(AppsBusiness business) {
Map<String, Object> query = new HashMap<String, Object>();
query.put("USER_ID", SessionUtil.getCode());
//查询当前登陆人已安装的应用
List<Map<String, Object>> listInstallApps=business.list_allInstallApps_by_user(query);
//查询当前登陆人未安装的应用
List<Map<String, Object>> listUninstallApps=business.list_allUninstallApps_by_user(query);
//查询当前登陆人所有有权限的应用
List<Map<String, Object>> listAllApps=business.list_AllApps(query);
//当前登录人是否第一次访问应用列表(有权限应用个数>0,而且已安装应用和未安装应用数量都为0)
boolean isInit=listAllApps.size()!=0&&listInstallApps.size()==0&&listUninstallApps.size()==0;
//1.验证有权限的应用是否在已安装或者未安装中有数据
outer:
for(Map<String, Object> grantApp:listAllApps){
for(Map<String, Object> installApp:listInstallApps){
if(grantApp.get("APP_ID").equals(installApp.get("APP_ID"))){
//找到则继续判断下一个有权限的应用
continue outer;
}
}
for(Map<String, Object> uninstallApp:listUninstallApps){
if(grantApp.get("APP_ID").equals(uninstallApp.get("APP_ID"))){
//找到则继续判断下一个有权限的应用
continue outer;
}
}
Map<String, Object> insertApp=new HashMap<String, Object>();
insertApp.put("APP_ID", grantApp.get("APP_ID"));
insertApp.put("USER_ID", SessionUtil.getCode());
//如果都没有找到,则向未安装表/安装表插入该应用
if(isInit){
//如果是第一次初始化,则判断该应用是否需要默认安装
if("0".equals(grantApp.get("IS_DEFAULT"))){
//如果是默认安装则插入安装表,并退出本次循环
business.insert_installApp(insertApp);
continue;
}
}
//如果不是初始化或者是初始化但不是默认安装的,则插入未安装表
business.insert_unInstallApp(insertApp);
}
//2.验证已安装的app,是否有权限
outer:
for(Map<String, Object> installApp:listInstallApps){
for(Map<String, Object> grantApp:listAllApps){
if(grantApp.get("APP_ID").equals(installApp.get("APP_ID"))){
//找到则继续判断下一个已安装的应用
continue outer;
}
}
//没有找到,则删除安装表的数据
Map<String, Object> deleteInstallApp=new HashMap<String, Object>();
deleteInstallApp.put("APP_ID", installApp.get("APP_ID"));
deleteInstallApp.put("USER_ID", SessionUtil.getCode());
business.delete_installApp(deleteInstallApp);
}
//3.验证未安装的app,是否有权限
outer:
for(Map<String, Object> uninstallApp:listUninstallApps){
for(Map<String, Object> grantApp:listAllApps){
if(grantApp.get("APP_ID").equals(uninstallApp.get("APP_ID"))){
//找到则继续判断下一个已安装的应用
continue outer;
}
}
//没有找到,则删除未安装表的数据
Map<String, Object> deleteUninstallApp=new HashMap<String, Object>();
deleteUninstallApp.put("APP_ID", uninstallApp.get("APP_ID"));
deleteUninstallApp.put("USER_ID", SessionUtil.getCode());
business.delete_uninstallApp(deleteUninstallApp);
}
}
private void private_putMapByKey(String key,List<Map<String, Object>> list) throws SQLException {
Map<String, Object> listMap = new HashMap<String, Object>();
listMap.put("rowSet", QueryParamUtil.DateToString(list));
......
......@@ -43,6 +43,13 @@ public interface AppsBusiness {
* @return
*/
List<Map<String, Object>> list_allUninstallApps_by_user(Map<String, Object> query) throws BusinessException ;
/**根据用户id来查找app_install的数据
*
* @param query
* @return
*/
List<Map<String, Object>> list_allInstallApps_by_user(Map<String, Object> query) throws BusinessException ;
/**查找所有的app应用
*
......@@ -56,4 +63,8 @@ public interface AppsBusiness {
* @param queryDefaultApp
*/
void init_defaultApps(Map<String, Object> query) throws BusinessException ;
void delete_installApp(Map<String, Object> query) throws BusinessException ;
void delete_uninstallApp(Map<String, Object> query) throws BusinessException ;
}
......@@ -42,17 +42,8 @@ public class AppsBusinessImpl implements AppsBusiness {
public List<Map<String, Object>> list_allApps_by_user(Map<String, Object> query) throws BusinessException {
List<Map<String, Object>> listData = null;
try {
//根据当前登陆人id获取所有的角色id
Map<String, Object> query2=new HashMap<String, Object>();
query2.put("USER_ID", SessionUtil.getEmid());
List<Map<String, Object>> listRole=appsRoleDAO.list_all_role_by_userId(query2);
List<String> listRoleId=new ArrayList<String>();
for(Map<String, Object> role:listRole){
listRoleId.add("%"+role.get("ROLE_ID").toString()+"%");
}
query.put("USER_ID", SessionUtil.getEmid());
List<String> listRoleId = getRoleIdsByUser();
query.put("USER_ID", SessionUtil.getCode());
query.put("G_IDS", listRoleId);
listData = QueryParamUtil.ClobToString(appsDAO.list_allApps_by_user(query));
} catch (IOException e) {
......@@ -95,7 +86,7 @@ public class AppsBusinessImpl implements AppsBusiness {
private void private_insert_unInstallApp(Map<String, Object> query) {
Map<String, Object> insertQuery = new HashMap<String, Object>();
insertQuery.put("APP_ID", query.get("APP_ID"));
insertQuery.put("USERID", SessionUtil.getEmid());
insertQuery.put("USERID", SessionUtil.getCode());
insertQuery.put("RESOURCE_ID", UUID.randomUUID().toString());
appsDAO.insert_unInstallApp(mapToList(insertQuery));
}
......@@ -118,7 +109,7 @@ public class AppsBusinessImpl implements AppsBusiness {
String now = formatter.format(new Date());
insertQuery.put("APP_ID", query.get("APP_ID"));
insertQuery.put("INSTALL_TIME", now);
insertQuery.put("USERID", SessionUtil.getEmid());
insertQuery.put("USERID", SessionUtil.getCode());
insertQuery.put("RESOURCE_ID", UUID.randomUUID().toString());
appsDAO.insert_installApp(mapToList(insertQuery));
}
......@@ -148,6 +139,21 @@ public class AppsBusinessImpl implements AppsBusiness {
}
return listData;
}
@Override
public List<Map<String, Object>> list_allInstallApps_by_user(Map<String, Object> query) throws BusinessException {
List<Map<String, Object>> listData = null;
try {
listData = QueryParamUtil.ClobToString(appsDAO.list_allInstallApps_by_user(query));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return listData;
}
@Override
public List<Map<String, Object>> list_AllApps(Map<String, Object> query) throws BusinessException {
......@@ -155,7 +161,7 @@ public class AppsBusinessImpl implements AppsBusiness {
try {
//根据当前登陆人id获取所有的角色id
Map<String, Object> query2=new HashMap<String, Object>();
query2.put("USER_ID", SessionUtil.getEmid());
query2.put("USER_ID", SessionUtil.getCode());
List<Map<String, Object>> listRole=appsRoleDAO.list_all_role_by_userId(query2);
List<String> listRoleId=new ArrayList<String>();
for(Map<String, Object> role:listRole){
......@@ -178,8 +184,11 @@ public class AppsBusinessImpl implements AppsBusiness {
@Override
public void init_defaultApps(Map<String, Object> query) throws BusinessException {
try {
//1.先获得所有的apps应用
//1.先获得所有的apps应用(根据用户所属的角色列表查)
List<String> listRoleId = getRoleIdsByUser();
query.put("G_IDS", listRoleId);
List<Map<String, Object>> listData = QueryParamUtil.ClobToString(appsDAO.list_AllApps(query));
for(Map<String, Object> data : listData){
Map<String, Object> defaultQuery = new HashMap<String, Object>();
defaultQuery.put("APP_ID",data.get("APP_ID"));
......@@ -201,4 +210,32 @@ public class AppsBusinessImpl implements AppsBusiness {
}
}
/**
* 获得当前登录人所属的角色列表
* @return
* @date 2018-09-15 下午3:01:42
* @author luosz@jfbrother.com
*/
private List<String> getRoleIdsByUser() {
//根据当前登陆人id获取所有的角色id
Map<String, Object> query2=new HashMap<String, Object>();
query2.put("USER_ID", SessionUtil.getCode());
List<Map<String, Object>> listRole=appsRoleDAO.list_all_role_by_userId(query2);
List<String> listRoleId=new ArrayList<String>();
for(Map<String, Object> role:listRole){
listRoleId.add("%"+role.get("ROLE_ID").toString()+"%");
}
return listRoleId;
}
@Override
public void delete_installApp(Map<String, Object> query) throws BusinessException {
appsDAO.delete_installApp(query);
}
@Override
public void delete_uninstallApp(Map<String, Object> query) throws BusinessException {
appsDAO.delete_unInstallApp(query);
}
}
......@@ -21,6 +21,8 @@ public interface AppsDAO {
void insert_unInstallApp(List<Map<String,Object>> query) throws BusinessException;
List<Map<String,Object>> list_allUninstallApps_by_user(Map<String,Object> query) throws BusinessException ;
List<Map<String,Object>> list_allInstallApps_by_user(Map<String,Object> query) throws BusinessException ;
List<Map<String,Object>> list_AllApps(Map<String,Object> query) throws BusinessException ;
}
......@@ -67,6 +67,11 @@
SELECT * FROM apps_uninstall where USERID=#{USER_ID}
</select>
<select id="list_allInstallApps_by_user" parameterType="map"
resultType="upperCaseKeyMap">
SELECT * FROM app_install where USERID=#{USER_ID}
</select>
<select id="list_AllApps" parameterType="map"
resultType="upperCaseKeyMap">
SELECT * FROM apps_app apps
......
......@@ -136,16 +136,6 @@ public class AppsRoleBusinessImpl implements PortalAppsRoleBusiness {
@Override
public void saveUserByRoleId(String roleId, String users) throws BusinessException {
// 查询该角色下原本有的人员
Map<String, Object> query = new HashMap<String, Object>();
query.put("ROLE_ID", roleId);
List<Map<String, Object>> listUsersOld = appsRoleDAO.list_all_user_by_roleId(query);
// 查询该角色用于哪些app
Map<String, Object> query2 = new HashMap<String, Object>();
query2.put("G_ID", roleId);
List<Map<String, Object>> listApp = appsDAO.list_app(query2);
// 删除原先该角色下所有的用户
appsRoleDAO.delete_apps_role_user_by_roleId(roleId);
......@@ -174,82 +164,8 @@ public class AppsRoleBusinessImpl implements PortalAppsRoleBusiness {
appsRoleDAO.insert_apps_role_user(info);
}
}
if (arrayUser == null) {
arrayUser = new String[] {};
}
// 获取少了哪些用户
List<String> listLessUser = new ArrayList<String>();
outer: for (Map<String, Object> user : listUsersOld) {
for (String userId : arrayUser) {
if (userId.equals(user.get("USER_ID"))) {
continue outer;
}
}
listLessUser.add(user.get("USER_ID").toString());
}
// 获取多了哪些用户
List<String> listMuchUser = new ArrayList<String>();
outer: for (String userId : arrayUser) {
for (Map<String, Object> user : listUsersOld) {
if (userId.equals(user.get("USER_ID"))) {
continue outer;
}
}
listMuchUser.add(userId);
}
// 循环遍历这些app,如果这些app是默认需要安装的,则给多了的用户添加安装数据
List<String> listAppId = new ArrayList<String>();
for (Map<String, Object> app : listApp) {
listAppId.add(app.get("APP_ID").toString());
// 判断是否需要默认安装
if ("1".equals(app.get("IS_DEFAULT"))) {
// 需要安装
for (String userId : listMuchUser) {
Map<String, Object> entityNew = new HashMap<String, Object>();
entityNew.put("APP_ID", app.get("APP_ID").toString());
entityNew.put("USERID", userId);
insert_install(entityNew);
}
}
}
// 删除少了的用户对应这些app的安装记录
Map<String, Object> query4 = new HashMap<String, Object>();
query4.put("USERIDS", listLessUser);
query4.put("APP_IDS", listAppId);
appsDAO.delete_install_app_byuser(query4);
}
private void insert_install(Map<String, Object> entity) throws BusinessException {
if (entity.get("RESOURCE_ID") == null) {
entity.put("RESOURCE_ID", java.util.UUID.randomUUID().toString());
}
if (entity.get("USERID") == null) {
entity.put("USERID", SessionUtil.getCode());
}
if (entity.get("INSTALL_TIME") == null) {
entity.put("INSTALL_TIME", new Date());
}
// 动态传值插入
List<String> infoListKey = new ArrayList<String>();
List<Object> infoList = new ArrayList<Object>();
if (entity.keySet() != null) {
Set<String> key = entity.keySet();
// 将map集合中的key和value 取出来分别放到list集合里
for (String str : key) {
infoList.add(entity.get(str));
infoListKey.add(str);
}
entity.put("infoListKey", infoListKey);
entity.put("infoList", infoList);
// 插入
appsDAO.insert_install(entity);
}
//
}
}
......@@ -66,7 +66,7 @@
delete from apps_role where
UUID in
<trim prefix="(" suffix=")" suffixOverrides=",">
<foreach collection="uuids" item="uuid">
<foreach collection="list" item="uuid">
#{uuid},
</foreach>
</trim>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment