Java代码优化:修改参数名并调整代码顺序
/**
- 设置为管理员或普通成员(role)
- 1:普通成员 2:管理员 */ @PutMapping("/admin/set/administrator/{userid}/{role}") @ResponseBody public CommonResult setRole(@PathVariable("userid") String userId, @PathVariable("role") Integer role) { if (role == 2) { Integer i = loginService.updateLogin(new Login().setUserid(userId).setRoleid(role)); if (i == 1) { userRoleService.UpdateUserRole(new UserRole().setUserid(userId).setRoleid(2).setIdentity('网站管理员')); /*发出设置为管理员的系统通知/ Notices notices = new Notices().setId(KeyUtil.getKey()).setUserid(userId).setTpname('系统通知') .setWhys('恭喜您已被设置为网站管理员,努力维护网站的良好氛围。'); noticesService.insertNotices(notices); return new CommonResult(true, StatusNum.OK, '设置管理员成功'); } return new CommonResult(true, StatusNum.ERROR, '设置管理员失败'); } else if (role == 1) { Integer i = loginService.updateLogin(new Login().setUserid(userId).setRoleid(role)); if (i == 1) { userRoleService.UpdateUserRole(new UserRole().setUserid(userId).setRoleid(1).setIdentity('网站用户')); /*发出设置为网站用户的系统通知/ Notices notices = new Notices().setId(KeyUtil.getKey()).setUserid(userId).setTpname('系统通知') .setWhys('您已被设置为网站用户,希望您再接再厉。'); noticesService.insertNotices(notices); return new CommonResult(true, StatusNum.OK, '设置成员成功'); } return new CommonResult(true, StatusNum.ERROR, '设置成员失败'); } return new CommonResult(false, StatusNum.UNAUTHORIZED, '违规操作'); }
原文地址: https://www.cveoy.top/t/topic/ocGY 著作权归作者所有。请勿转载和采集!