提交代码

master
胡锐 7 months ago
parent e68d35300a
commit a6d7dc8ffd
  1. 14
      bweb/src/main/java/com/bweb/controller/SecRoleController.java
  2. 68
      bweb/src/main/java/com/bweb/controller/SecUserController.java
  3. 13
      service/src/main/java/com/hfkj/service/SecUserService.java
  4. 20
      service/src/main/java/com/hfkj/service/impl/SecUserServiceImpl.java

@ -126,5 +126,19 @@ public class SecRoleController {
} }
} }
@RequestMapping(value="/queryAllRole",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询全部角色")
public ResponseData queryAllRole() {
try {
return ResponseMsgUtil.success(secRoleService.getList(new HashMap<>()));
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
} }

@ -37,32 +37,42 @@ public class SecUserController {
@Resource @Resource
private SecUserLoginLogService secUserLoginLogService; private SecUserLoginLogService secUserLoginLogService;
@RequestMapping(value="/create",method = RequestMethod.POST) @RequestMapping(value="/editUser",method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "创建用户") @ApiOperation(value = "编辑用户")
public ResponseData create(@RequestBody JSONObject body) { public ResponseData editUser(@RequestBody JSONObject body) {
try { try {
if (body == null if (body == null
|| StringUtils.isBlank(body.getString("userName")) || StringUtils.isBlank(body.getString("userName"))
|| StringUtils.isBlank(body.getString("loginName")) || StringUtils.isBlank(body.getString("loginName"))
|| StringUtils.isBlank(body.getString("telephone"))
|| body.getLong("roleId") == null || body.getLong("roleId") == null
) { ) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
SecUser secUser;
if (body.getLong("id") != null) {
// 查询账户
secUser = secUserService.getDetail(body.getLong("id"));
// 校验重复登录账户
SecUser user = secUserService.getDetailByLoginName(body.getString("loginName"));
if (user != null && !user.getId().equals(body.getLong("id"))) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "登录账户已存在");
}
} else {
secUser = new SecUser();
secUser.setPassword(MD5Util.encode("123456".getBytes()));
// 校验重复登录账户 // 校验重复登录账户
if (secUserService.getDetailByLoginName(body.getString("loginName")) != null) { if (secUserService.getDetailByLoginName(body.getString("loginName")) != null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "登录账户已存在"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "登录账户已存在");
} }
}
SecUser secUser = new SecUser();
secUser.setUserName(body.getString("userName")); secUser.setUserName(body.getString("userName"));
secUser.setLoginName(body.getString("loginName")); secUser.setLoginName(body.getString("loginName"));
secUser.setPassword(MD5Util.encode("123456".getBytes()));
secUser.setTelephone(body.getString("telephone")); secUser.setTelephone(body.getString("telephone"));
secUser.setRoleId(body.getLong("roleId")); secUser.setRoleId(body.getLong("roleId"));
secUserService.create(secUser); secUserService.editUser(secUser);
return ResponseMsgUtil.success("操作成功"); return ResponseMsgUtil.success("操作成功");
@ -72,17 +82,12 @@ public class SecUserController {
} }
} }
@RequestMapping(value="/update",method = RequestMethod.POST) @RequestMapping(value="/delete",method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "修改用户") @ApiOperation(value = "删除用户")
public ResponseData update(@RequestBody JSONObject body) { public ResponseData delete(@RequestBody JSONObject body) {
try { try {
if (body == null if (body == null || body.getLong("userId") == null) {
|| body.getLong("userId") == null
|| StringUtils.isBlank(body.getString("userName"))
|| StringUtils.isBlank(body.getString("telephone"))
|| body.getLong("roleId") == null
) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
@ -91,10 +96,8 @@ public class SecUserController {
if (secUser == null) { if (secUser == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
secUser.setUserName(body.getString("userName")); secUser.setStatus(SecUserStatusEnum.status0.getCode());
secUser.setTelephone(body.getString("telephone")); secUserService.editUser(secUser);
secUser.setRoleId(body.getLong("roleId"));
secUserService.update(secUser);
return ResponseMsgUtil.success("操作成功"); return ResponseMsgUtil.success("操作成功");
@ -106,8 +109,8 @@ public class SecUserController {
@RequestMapping(value="/restore",method = RequestMethod.POST) @RequestMapping(value="/restore",method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "删除用户") @ApiOperation(value = "恢复")
public ResponseData delete(@RequestBody JSONObject body) { public ResponseData restore(@RequestBody JSONObject body) {
try { try {
if (body == null || body.getLong("userId") == null) { if (body == null || body.getLong("userId") == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
@ -118,7 +121,7 @@ public class SecUserController {
if (secUser == null) { if (secUser == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
secUser.setStatus(SecUserStatusEnum.status0.getCode()); secUser.setStatus(SecUserStatusEnum.status1.getCode());
secUserService.editUser(secUser); secUserService.editUser(secUser);
return ResponseMsgUtil.success("操作成功"); return ResponseMsgUtil.success("操作成功");
@ -129,22 +132,16 @@ public class SecUserController {
} }
} }
@RequestMapping(value="/restore1",method = RequestMethod.POST) @RequestMapping(value="/resetPwd",method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "恢复") @ApiOperation(value = "账户密码重置")
public ResponseData restore1(@RequestBody JSONObject body) { public ResponseData resetPwd(@RequestBody JSONObject body) {
try { try {
if (body == null || body.getLong("userId") == null) { if (body == null || body.getLong("userId") == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
// 查询用户详情 secUserService.resetPwd(body.getLong("userId"));
SecUser secUser = secUserService.getDetail(body.getLong("userId"));
if (secUser == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
secUser.setStatus(SecUserStatusEnum.status1.getCode());
secUserService.editUser(secUser);
return ResponseMsgUtil.success("操作成功"); return ResponseMsgUtil.success("操作成功");
@ -154,6 +151,7 @@ public class SecUserController {
} }
} }
@RequestMapping(value="/disable",method = RequestMethod.POST) @RequestMapping(value="/disable",method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "禁用") @ApiOperation(value = "禁用")
@ -200,6 +198,7 @@ public class SecUserController {
@ResponseBody @ResponseBody
@ApiOperation(value = "查询列表") @ApiOperation(value = "查询列表")
public ResponseData queryList(@RequestParam(value = "userName", required = false) String userName, public ResponseData queryList(@RequestParam(value = "userName", required = false) String userName,
@RequestParam(value = "loginName", required = false) String loginName,
@RequestParam(value = "telephone", required = false) String telephone, @RequestParam(value = "telephone", required = false) String telephone,
@RequestParam(value = "status", required = false) Integer status, @RequestParam(value = "status", required = false) Integer status,
@RequestParam(value = "pageNum", required = true) Integer pageNum, @RequestParam(value = "pageNum", required = true) Integer pageNum,
@ -208,11 +207,12 @@ public class SecUserController {
Map<String,Object> param = new HashMap<>(); Map<String,Object> param = new HashMap<>();
param.put("userName", userName); param.put("userName", userName);
param.put("loginName", loginName);
param.put("telephone", telephone); param.put("telephone", telephone);
param.put("status", status); param.put("status", status);
PageHelper.startPage(pageNum, pageSize); PageHelper.startPage(pageNum, pageSize);
return ResponseMsgUtil.success(secUserService.getList(param)); return ResponseMsgUtil.success(new PageInfo<>(secUserService.getList(param)));
} catch (Exception e) { } catch (Exception e) {
log.error("error!",e); log.error("error!",e);

@ -21,17 +21,10 @@ public interface SecUserService {
void editUser(SecUser data); void editUser(SecUser data);
/** /**
* 创建 * 重置密码
* @param secUser 账户 * @param userId
*/ */
void create(SecUser secUser); void resetPwd(Long userId) throws Exception;
/**
* 创建
* @param secUser 账户
*/
void update(SecUser secUser);
/** /**
* 查询详情 * 查询详情
* @param id * @param id

@ -67,13 +67,13 @@ public class SecUserServiceImpl implements SecUserService {
} }
@Override @Override
public void create(SecUser secUser) { public void resetPwd(Long userId) throws Exception {
secUser.setStatus(SecUserStatusEnum.status1.getCode()); // 查询账户
editUser(secUser); SecUser secUser = getDetail(userId);
if (secUser == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的账户");
} }
secUser.setPassword(MD5Util.encode("123456".getBytes()));
@Override
public void update(SecUser secUser) {
editUser(secUser); editUser(secUser);
} }
@ -102,12 +102,16 @@ public class SecUserServiceImpl implements SecUserService {
criteria.andUserNameLike("%"+MapUtils.getString(param, "userName")+"%"); criteria.andUserNameLike("%"+MapUtils.getString(param, "userName")+"%");
} }
if (StringUtils.isNotBlank(MapUtils.getString(param, "loginName"))) {
criteria.andLoginNameLike("%"+MapUtils.getString(param, "loginName")+"%");
}
if (StringUtils.isNotBlank(MapUtils.getString(param, "telephone"))) { if (StringUtils.isNotBlank(MapUtils.getString(param, "telephone"))) {
criteria.andTelephoneLike("%"+MapUtils.getString(param, "telephone")+"%"); criteria.andTelephoneLike("%"+MapUtils.getString(param, "telephone")+"%");
} }
if (MapUtils.getInteger(param, "userName") != null) { if (MapUtils.getInteger(param, "status") != null) {
criteria.andStatusEqualTo(MapUtils.getInteger(param, "userName")); criteria.andStatusEqualTo(MapUtils.getInteger(param, "status"));
} }
example.setOrderByClause("create_time desc"); example.setOrderByClause("create_time desc");

Loading…
Cancel
Save