From ff28be7173557db496c1ca636e3dab063a1907d4 Mon Sep 17 00:00:00 2001 From: baozhuhui Date: Mon, 1 Apr 2019 21:17:17 +0800 Subject: [PATCH] =?UTF-8?q?baozh:=E4=BF=AE=E6=94=B9=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=9D=83=E9=99=90=E7=9A=84=E5=90=8C=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=AD=A5=E5=BA=94=E7=94=A8=E6=9D=83=E9=99=90?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- erp_web/pages/manage/role.html | 2 +- .../jsh/erp/constants/BusinessConstants.java | 2 + .../com/jsh/erp/service/app/AppService.java | 40 ++++++++++ .../userBusiness/UserBusinessService.java | 74 ++++++++++++++++++- 4 files changed, 116 insertions(+), 2 deletions(-) diff --git a/erp_web/pages/manage/role.html b/erp_web/pages/manage/role.html index abad95c1..b3751071 100644 --- a/erp_web/pages/manage/role.html +++ b/erp_web/pages/manage/role.html @@ -33,7 +33,7 @@ 查询   重置   - 分配应用   + 分配功能   分配按钮 diff --git a/src/main/java/com/jsh/erp/constants/BusinessConstants.java b/src/main/java/com/jsh/erp/constants/BusinessConstants.java index 2f5d9328..4c156438 100644 --- a/src/main/java/com/jsh/erp/constants/BusinessConstants.java +++ b/src/main/java/com/jsh/erp/constants/BusinessConstants.java @@ -197,6 +197,8 @@ public class BusinessConstants { public static final String LOG_MODULE_NAME_ORGANIZATION= "机构"; public static final String LOG_INTERFACE_NAME_ORGANIZATION= "organization"; + public static final String TYPE_NAME_ROLE_APP = "RoleAPP"; + diff --git a/src/main/java/com/jsh/erp/service/app/AppService.java b/src/main/java/com/jsh/erp/service/app/AppService.java index eee6e857..6486bdd9 100644 --- a/src/main/java/com/jsh/erp/service/app/AppService.java +++ b/src/main/java/com/jsh/erp/service/app/AppService.java @@ -3,8 +3,10 @@ package com.jsh.erp.service.app; import com.alibaba.fastjson.JSONObject; import com.jsh.erp.datasource.entities.App; import com.jsh.erp.datasource.entities.AppExample; +import com.jsh.erp.datasource.entities.UserBusiness; import com.jsh.erp.datasource.mappers.AppMapper; import com.jsh.erp.datasource.mappers.AppMapperEx; +import com.jsh.erp.service.userBusiness.UserBusinessService; import com.jsh.erp.utils.StringUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,6 +26,9 @@ public class AppService { @Resource private AppMapperEx appMapperEx; + @Resource + private UserBusinessService userBusinessService; + public List findDock(){ AppExample example = new AppExample(); example.createCriteria().andZlEqualTo("dock").andEnabledEqualTo(true); @@ -106,4 +111,39 @@ public class AppService { List list = appMapper.selectByExample(example); return list; } + + public List findAppByUserId(String userId) { + List roleList = userBusinessService.findRoleByUserId(userId); + String roles = null; + if(roleList!=null && roleList.size()>0 && roleList.get(0)!=null){ + roles = roleList.get(0).getValue(); + } + if(roles!=null) { + roles = roles.replaceAll("\\]\\[",",").replaceAll("\\]","").replaceAll("\\[",""); //转为逗号隔开的 + } + List appList = userBusinessService.findAppByRoles(roles); + String apps = null; + if(appList!=null && appList.size()>0 && appList.get(0)!=null){ + apps = appList.get(0).getValue(); + } + if(apps!=null) { + apps = apps.replaceAll("\\]\\[",",").replaceAll("\\]","").replaceAll("\\[",""); //转为逗号隔开的 + } + + List deskList = findAppInIds(apps,"desk"); + + return deskList; + } + + /** + * 通过number列表查询app list + * @param numberList + * @return + */ + public List findAppByNumber(List numberList) { + + AppExample example = new AppExample(); + example.createCriteria().andEnabledEqualTo(true).andNumberIn(numberList); + return appMapper.selectByExample(example); + } } diff --git a/src/main/java/com/jsh/erp/service/userBusiness/UserBusinessService.java b/src/main/java/com/jsh/erp/service/userBusiness/UserBusinessService.java index e26f5df0..8109082e 100644 --- a/src/main/java/com/jsh/erp/service/userBusiness/UserBusinessService.java +++ b/src/main/java/com/jsh/erp/service/userBusiness/UserBusinessService.java @@ -2,21 +2,30 @@ package com.jsh.erp.service.userBusiness; import com.alibaba.fastjson.JSONObject; import com.jsh.erp.constants.BusinessConstants; +import com.jsh.erp.datasource.entities.App; +import com.jsh.erp.datasource.entities.Functions; import com.jsh.erp.datasource.entities.UserBusiness; import com.jsh.erp.datasource.entities.UserBusinessExample; import com.jsh.erp.datasource.mappers.UserBusinessMapper; +import com.jsh.erp.service.CommonQueryManager; +import com.jsh.erp.service.app.AppService; +import com.jsh.erp.service.functions.FunctionsService; import com.jsh.erp.service.log.LogService; import com.jsh.erp.utils.StringUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; @Service public class UserBusinessService { @@ -27,6 +36,15 @@ public class UserBusinessService { @Resource private LogService logService; + @Resource + private FunctionsService functionsService; + + @Resource + private AppService appService; + + @Resource + private CommonQueryManager configResourceManager; + public UserBusiness getUserBusiness(long id) { return userBusinessMapper.selectByPrimaryKey(id); } @@ -46,7 +64,14 @@ public class UserBusinessService { public int updateUserBusiness(String beanJson, Long id) { UserBusiness userBusiness = JSONObject.parseObject(beanJson, UserBusiness.class); userBusiness.setId(id); - return userBusinessMapper.updateByPrimaryKeySelective(userBusiness); + + int updates = userBusinessMapper.updateByPrimaryKeySelective(userBusiness); + + // 更新应用权限 + if (updates > 0) { + updates = updateAppValue(BusinessConstants.TYPE_NAME_ROLE_APP, userBusiness.getKeyid(), userBusiness.getValue()); + } + return updates; } @Transactional(value = "transactionManager", rollbackFor = Exception.class) @@ -127,4 +152,51 @@ public class UserBusinessService { return list; } + /** + * 通过功能(RoleFunctions)权限更新应用(RoleApp)权限 + * @param type + * @param keyId + * @param functionIds + * @return + */ + public int updateAppValue(String type, String keyId, String functionIds) { + + int updates = 0; + + functionIds = functionIds.replaceAll("\\]\\[", ","). + replaceAll("\\[","").replaceAll("\\]",""); + + List functionsList = functionsService.findByIds(functionIds); + + if (!CollectionUtils.isEmpty(functionsList)) { + + Set appNumbers = new HashSet<>(); + String appNumber; + for (Functions functions : functionsList) { + + appNumber = functions.getNumber().substring(0, 2); + appNumbers.add(appNumber); + } + + List appNumberList = new ArrayList<>(appNumbers); + List appList = appService.findAppByNumber(appNumberList); + + StringBuilder appIdSb = new StringBuilder(); + + if (!CollectionUtils.isEmpty(appList)) { + for (App app : appList) { + appIdSb.append("[" + app.getId() + "]"); + } + + List userBusinessList = getBasicData(keyId, type); + if(userBusinessList.size() > 0) { + UserBusiness userBusiness = userBusinessList.get(0); + userBusiness.setValue(appIdSb.toString()); + + updates = userBusinessMapper.updateByPrimaryKeySelective(userBusiness); + } + } + } + return updates; + } }