新增客户时给当前用户和租户自动授权(租用也一起授权)

This commit is contained in:
jishenghua
2025-04-29 17:01:01 +08:00
parent 8814917af2
commit ab9d91c89f

View File

@@ -152,7 +152,7 @@ public class SupplierService {
User userInfo=userService.getCurrentUser(); User userInfo=userService.getCurrentUser();
supplier.setCreator(userInfo==null?null:userInfo.getId()); supplier.setCreator(userInfo==null?null:userInfo.getId());
result=supplierMapper.insertSelective(supplier); result=supplierMapper.insertSelective(supplier);
//新增客户时给当前用户自动授权 //新增客户时给当前用户和租户自动授权
setUserCustomerPermission(request, supplier); setUserCustomerPermission(request, supplier);
logService.insertLog("商家", logService.insertLog("商家",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(supplier.getSupplier()).toString(),request); new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(supplier.getSupplier()).toString(),request);
@@ -523,7 +523,7 @@ public class SupplierService {
List<Supplier> list= supplierMapper.selectByExample(example); List<Supplier> list= supplierMapper.selectByExample(example);
if(list.size() <= 0) { if(list.size() <= 0) {
supplierMapper.insertSelective(supplier); supplierMapper.insertSelective(supplier);
//新增客户时给当前用户自动授权 //新增客户时给当前用户和租户自动授权
setUserCustomerPermission(request, supplier); setUserCustomerPermission(request, supplier);
} else { } else {
Long id = list.get(0).getId(); Long id = list.get(0).getId();
@@ -618,16 +618,32 @@ public class SupplierService {
} }
/** /**
* 新增客户时给当前用户自动授权 * 新增客户时给当前用户和租户自动授权
* @param request * @param request
* @param supplier * @param supplier
* @throws Exception * @throws Exception
*/ */
private void setUserCustomerPermission(HttpServletRequest request, Supplier supplier) throws Exception { private void setUserCustomerPermission(HttpServletRequest request, Supplier supplier) throws Exception {
if("客户".equals(supplier.getType())) { if("客户".equals(supplier.getType())) {
Long userId = userService.getUserId(request); User user = userService.getCurrentUser();
Supplier sInfo = supplierMapperEx.getSupplierByNameAndType(supplier.getSupplier(), supplier.getType()); Supplier sInfo = supplierMapperEx.getSupplierByNameAndType(supplier.getSupplier(), supplier.getType());
String ubKey = "[" + sInfo.getId() + "]"; String ubKey = "[" + sInfo.getId() + "]";
//授权当前用户
setPermissionByParam(user.getId(), ubKey);
if(!user.getId().equals(user.getTenantId())) {
//授权当前租户
setPermissionByParam(user.getTenantId(), ubKey);
}
}
}
/**
* 权限授权操作
* @param userId
* @param ubKey
* @throws Exception
*/
private void setPermissionByParam(Long userId, String ubKey) throws Exception {
List<UserBusiness> ubList = userBusinessService.getBasicData(userId.toString(), "UserCustomer"); List<UserBusiness> ubList = userBusinessService.getBasicData(userId.toString(), "UserCustomer");
if(ubList ==null || ubList.size() == 0) { if(ubList ==null || ubList.size() == 0) {
JSONObject ubObj = new JSONObject(); JSONObject ubObj = new JSONObject();
@@ -647,7 +663,6 @@ public class SupplierService {
userBusinessMapper.updateByPrimaryKeySelective(userBusiness); userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
} }
} }
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchSetAdvanceIn(String ids) throws Exception { public int batchSetAdvanceIn(String ids) throws Exception {