处理异常问题

This commit is contained in:
wanggeng 2021-11-04 00:08:20 +08:00
parent f6953704bc
commit 1075fb2eff
5 changed files with 19 additions and 18 deletions

View File

@ -2,7 +2,6 @@ package ink.wgink.interfaces.role;
import ink.wgink.pojo.dtos.department.DepartmentUserDTO;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
/**
@ -22,7 +21,7 @@ public interface IRoleDepartmentUserBaseService {
* @param areaCode 地区编码
* @return
*/
List<DepartmentUserDTO> listUserByRoleIdAndAreaCode(String roleId, String areaCode) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException;
List<DepartmentUserDTO> listUserByRoleIdAndAreaCode(String roleId, String areaCode);
/**
* 获取指定部门中指定角色的用户列表接口

View File

@ -1,5 +1,6 @@
package ink.wgink.util;
import ink.wgink.exceptions.base.SystemException;
import ink.wgink.util.string.WStringUtil;
import java.io.*;
@ -44,19 +45,23 @@ public class ArrayListUtil {
* @param beanClass
* @param <T>
* @return
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalAccessException
*/
public static <T> List<String> listBeanStringIdValue(List<T> beans, String propertyName, Class<T> beanClass) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
public static <T> List<String> listBeanStringIdValue(List<T> beans, String propertyName, Class<T> beanClass) {
if (beans.isEmpty()) {
return new ArrayList<>();
}
Set<String> beanStringIdSet = new HashSet<>();
for (Object bean : beans) {
Method method = bean.getClass().getMethod("get" + WStringUtil.firstToUpper(propertyName));
Object result = method.invoke(bean);
if (result == null) {
continue;
try {
for (Object bean : beans) {
Method method = bean.getClass().getMethod("get" + WStringUtil.firstToUpper(propertyName));
Object result = method.invoke(bean);
if (result == null) {
continue;
}
beanStringIdSet.add(result.toString());
}
beanStringIdSet.add(result.toString());
} catch (Exception e) {
throw new SystemException(e);
}
return new ArrayList<>(beanStringIdSet);
}

View File

@ -12,7 +12,6 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
@ -36,7 +35,7 @@ public class RoleDepartmentUserServiceImpl extends DefaultBaseService implements
private IDepartmentUserBaseService departmentUserBaseService;
@Override
public List<DepartmentUserDTO> listUserByRoleIdAndAreaCode(String roleId, String areaCode) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
public List<DepartmentUserDTO> listUserByRoleIdAndAreaCode(String roleId, String areaCode) {
// 地区下所有组织机构
List<DepartmentPO> departmentPOs = departmentBaseService.listPOByAreaCode(areaCode);
if (departmentPOs.isEmpty()) {

View File

@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
/**
@ -38,7 +37,7 @@ public class RoleDepartmentUserController extends DefaultBaseController {
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("list-user/{roleId}/{areaCode}")
public List<DepartmentUserDTO> listUserByRoleIdAndAreaCode(@PathVariable("roleId") String roleId,
@PathVariable("areaCode") String areaCode) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
@PathVariable("areaCode") String areaCode) {
return roleDepartmentUserService.listUserByRoleIdAndAreaCode(roleId, areaCode);
}

View File

@ -12,7 +12,6 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
@ -34,7 +33,7 @@ public class RoleDepartmentUserServiceImpl extends DefaultBaseService implements
private IDepartmentUserService departmentUserService;
@Override
public List<DepartmentUserDTO> listUserByRoleIdAndAreaCode(String roleId, String areaCode) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
public List<DepartmentUserDTO> listUserByRoleIdAndAreaCode(String roleId, String areaCode) {
// 地区下所有组织机构
List<DepartmentPO> departmentPOs = departmentService.listPOByAreaCode(areaCode);
if (departmentPOs.isEmpty()) {