提交代码

dev
胡锐 7 months ago
parent e68d35300a
commit a6d7dc8ffd
  1. 14
      bweb/src/main/java/com/bweb/controller/SecRoleController.java
  2. 76
      bweb/src/main/java/com/bweb/controller/SecUserController.java
  3. 13
      service/src/main/java/com/hfkj/service/SecUserService.java
  4. 22
      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
private SecUserLoginLogService secUserLoginLogService;
@RequestMapping(value="/create",method = RequestMethod.POST)
@RequestMapping(value="/editUser",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "创建用户")
public ResponseData create(@RequestBody JSONObject body) {
@ApiOperation(value = "编辑用户")
public ResponseData editUser(@RequestBody JSONObject body) {
try {
if (body == null
|| StringUtils.isBlank(body.getString("userName"))
|| StringUtils.isBlank(body.getString("loginName"))
|| StringUtils.isBlank(body.getString("telephone"))
|| body.getLong("roleId") == null
) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 校验重复登录账户
if (secUserService.getDetailByLoginName(body.getString("loginName")) != null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_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) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "登录账户已存在");
}
}
SecUser secUser = new SecUser();
secUser.setUserName(body.getString("userName"));
secUser.setLoginName(body.getString("loginName"));
secUser.setPassword(MD5Util.encode("123456".getBytes()));
secUser.setTelephone(body.getString("telephone"));
secUser.setRoleId(body.getLong("roleId"));
secUserService.create(secUser);
secUserService.editUser(secUser);
return ResponseMsgUtil.success("操作成功");
@ -72,17 +82,12 @@ public class SecUserController {
}
}
@RequestMapping(value="/update",method = RequestMethod.POST)
@RequestMapping(value="/delete",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "修改用户")
public ResponseData update(@RequestBody JSONObject body) {
@ApiOperation(value = "删除用户")
public ResponseData delete(@RequestBody JSONObject body) {
try {
if (body == null
|| body.getLong("userId") == null
|| StringUtils.isBlank(body.getString("userName"))
|| StringUtils.isBlank(body.getString("telephone"))
|| body.getLong("roleId") == null
) {
if (body == null || body.getLong("userId") == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
@ -91,10 +96,8 @@ public class SecUserController {
if (secUser == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
secUser.setUserName(body.getString("userName"));
secUser.setTelephone(body.getString("telephone"));
secUser.setRoleId(body.getLong("roleId"));
secUserService.update(secUser);
secUser.setStatus(SecUserStatusEnum.status0.getCode());
secUserService.editUser(secUser);
return ResponseMsgUtil.success("操作成功");
@ -106,8 +109,8 @@ public class SecUserController {
@RequestMapping(value="/restore",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "删除用户")
public ResponseData delete(@RequestBody JSONObject body) {
@ApiOperation(value = "恢复")
public ResponseData restore(@RequestBody JSONObject body) {
try {
if (body == null || body.getLong("userId") == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
@ -118,7 +121,7 @@ public class SecUserController {
if (secUser == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
secUser.setStatus(SecUserStatusEnum.status0.getCode());
secUser.setStatus(SecUserStatusEnum.status1.getCode());
secUserService.editUser(secUser);
return ResponseMsgUtil.success("操作成功");
@ -129,22 +132,16 @@ public class SecUserController {
}
}
@RequestMapping(value="/restore1",method = RequestMethod.POST)
@RequestMapping(value="/resetPwd",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "恢复")
public ResponseData restore1(@RequestBody JSONObject body) {
@ApiOperation(value = "账户密码重置")
public ResponseData resetPwd(@RequestBody JSONObject body) {
try {
if (body == null || body.getLong("userId") == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 查询用户详情
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);
secUserService.resetPwd(body.getLong("userId"));
return ResponseMsgUtil.success("操作成功");
@ -154,6 +151,7 @@ public class SecUserController {
}
}
@RequestMapping(value="/disable",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "禁用")
@ -200,6 +198,7 @@ public class SecUserController {
@ResponseBody
@ApiOperation(value = "查询列表")
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 = "status", required = false) Integer status,
@RequestParam(value = "pageNum", required = true) Integer pageNum,
@ -208,11 +207,12 @@ public class SecUserController {
Map<String,Object> param = new HashMap<>();
param.put("userName", userName);
param.put("loginName", loginName);
param.put("telephone", telephone);
param.put("status", status);
PageHelper.startPage(pageNum, pageSize);
return ResponseMsgUtil.success(secUserService.getList(param));
return ResponseMsgUtil.success(new PageInfo<>(secUserService.getList(param)));
} catch (Exception e) {
log.error("error!",e);

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

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

Loading…
Cancel
Save