权限构造

This commit is contained in:
钱涛 2022-04-26 11:26:13 +08:00
parent 6a024cb35b
commit 11241d0b6f
2 changed files with 29 additions and 16 deletions

View File

@ -0,0 +1,7 @@
#??????
log=ture
#??????
isPermission=true
#??????id
salaryAdminRoleId=28

View File

@ -25,19 +25,29 @@ public class ResponseResult<T, R> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private User user; private final User user;
private boolean permission; private boolean permission = true;
HrmCommonService hrmCommonService = new HrmCommonServiceImpl(); private final HrmCommonService hrmCommonService = new HrmCommonServiceImpl();
private final BaseBean baseBean = new BaseBean();
private final String salaryAdminRoleId = baseBean.getPropValue("hrmSalary", "salaryAdminRoleId");
private final Boolean isPermission = baseBean.getPropValue("hrmSalary", "isPermission").equals("true");
public ResponseResult(User user) { public ResponseResult(User user) {
this.user = user; this.user = user;
} }
public ResponseResult(User user, boolean permission) {
this.user = user;
this.permission = permission;
}
private void permission() { private void permission() {
if (permission) { if (isPermission && permission) {
List<Object> roleInfo = hrmCommonService.getRoleInfo(user.getUID()); List<Object> roleInfo = hrmCommonService.getRoleInfo(user.getUID());
roleInfo.stream().map(m -> (Map) m).filter(m -> m.get("roleid") != null && m.get("roleid").toString().equals("28")).findFirst().orElseThrow(() -> new SalaryRunTimeException("无权限")); roleInfo.stream().map(m -> (Map) m).filter(m -> m.get("roleid") != null && m.get("roleid").toString().equals(salaryAdminRoleId)).findFirst().orElseThrow(() -> new SalaryRunTimeException("无权限"));
} }
} }
@ -86,19 +96,18 @@ public class ResponseResult<T, R> {
* 统一返回方法 * 统一返回方法
*/ */
public String run(Function<T, R> f, T m) { public String run(Function<T, R> f, T m) {
BaseBean b = new BaseBean();
try { try {
permission(); permission();
b.writeLog(getJsonString(m)); baseBean.writeLog(getJsonString(m));
return Ok(f.apply(m)); return Ok(f.apply(m));
} catch (SalaryRunTimeException e) { } catch (SalaryRunTimeException e) {
return Error(e.getMessage()); return Error(e.getMessage());
} catch (ECException e) { } catch (ECException e) {
b.writeLog(e); baseBean.writeLog(e);
Throwable cause = e.getCause(); Throwable cause = e.getCause();
return Error(cause.getMessage()); return Error(cause.getMessage());
} catch (Exception e) { } catch (Exception e) {
b.writeLog(e); baseBean.writeLog(e);
return Error(e.getMessage()); return Error(e.getMessage());
} }
} }
@ -107,7 +116,6 @@ public class ResponseResult<T, R> {
* 统一返回方法有参无返回 * 统一返回方法有参无返回
*/ */
public String run(Consumer<T> f, T t) { public String run(Consumer<T> f, T t) {
BaseBean b = new BaseBean();
try { try {
permission(); permission();
f.accept(t); f.accept(t);
@ -115,11 +123,11 @@ public class ResponseResult<T, R> {
} catch (SalaryRunTimeException e) { } catch (SalaryRunTimeException e) {
return Error(e.getMessage()); return Error(e.getMessage());
} catch (ECException e) { } catch (ECException e) {
b.writeLog(e); baseBean.writeLog(e);
Throwable cause = e.getCause(); Throwable cause = e.getCause();
return Error(cause.getMessage()); return Error(cause.getMessage());
} catch (Exception e) { } catch (Exception e) {
b.writeLog(e); baseBean.writeLog(e);
return Error(e.getMessage()); return Error(e.getMessage());
} }
} }
@ -135,13 +143,11 @@ public class ResponseResult<T, R> {
} catch (SalaryRunTimeException e) { } catch (SalaryRunTimeException e) {
return Error(e.getMessage()); return Error(e.getMessage());
} catch (ECException e) { } catch (ECException e) {
BaseBean b = new BaseBean(); baseBean.writeLog(e);
b.writeLog(e);
Throwable cause = e.getCause(); Throwable cause = e.getCause();
return Error(cause.getMessage()); return Error(cause.getMessage());
} catch (Exception e) { } catch (Exception e) {
BaseBean b = new BaseBean(); baseBean.writeLog(e);
b.writeLog(e);
return Error(e.getMessage()); return Error(e.getMessage());
} }
} }