baozh:修改角色功能权限的同时,同步应用权限。
This commit is contained in:
@@ -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<Functions> functionsList = functionsService.findByIds(functionIds);
|
||||
|
||||
if (!CollectionUtils.isEmpty(functionsList)) {
|
||||
|
||||
Set<String> appNumbers = new HashSet<>();
|
||||
String appNumber;
|
||||
for (Functions functions : functionsList) {
|
||||
|
||||
appNumber = functions.getNumber().substring(0, 2);
|
||||
appNumbers.add(appNumber);
|
||||
}
|
||||
|
||||
List<String> appNumberList = new ArrayList<>(appNumbers);
|
||||
List<App> appList = appService.findAppByNumber(appNumberList);
|
||||
|
||||
StringBuilder appIdSb = new StringBuilder();
|
||||
|
||||
if (!CollectionUtils.isEmpty(appList)) {
|
||||
for (App app : appList) {
|
||||
appIdSb.append("[" + app.getId() + "]");
|
||||
}
|
||||
|
||||
List<UserBusiness> userBusinessList = getBasicData(keyId, type);
|
||||
if(userBusinessList.size() > 0) {
|
||||
UserBusiness userBusiness = userBusinessList.get(0);
|
||||
userBusiness.setValue(appIdSb.toString());
|
||||
|
||||
updates = userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
|
||||
}
|
||||
}
|
||||
}
|
||||
return updates;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user