作者 王勇

不完善的用户管理,提交做备份

... ... @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.List;
import java.util.concurrent.TimeoutException;
... ... @@ -54,10 +55,22 @@ public class UserInfoController {
* @param userInfo {@link UserInfo}
* @return
*/
@PostMapping("/update")
public ResultJson updateUser(UserInfo userInfo)
@PutMapping("/update")
public ResultJson updateUser(@RequestBody UserInfo userInfo)
{
return userInfoService.updateByPrimaryKeySelective(userInfo);
}
/**
* 编辑用户信息
*
* @param userInfo {@link UserInfo}
* @return
*/
@PutMapping("/updatePassword")
public ResultJson updatePassword(@RequestBody UserInfo userInfo) throws MalformedURLException, URISyntaxException
{
return userInfoService.updatePassword(userInfo);
}
}
... ...
... ... @@ -4,6 +4,7 @@ import com.sunyo.wlpt.message.bus.service.domain.UserInfo;
import com.sunyo.wlpt.message.bus.service.response.ResultJson;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.List;
import java.util.concurrent.TimeoutException;
... ... @@ -86,7 +87,13 @@ public interface UserInfoService {
*/
List<UserInfo> selectUserExist(String username);
/**
* 修改密码
*
* @param userInfo {@link UserInfo}
* @return
*/
ResultJson updatePassword(UserInfo userInfo) throws MalformedURLException, URISyntaxException;
}
... ...
... ... @@ -127,7 +127,7 @@ public class UserInfoServiceImpl implements UserInfoService {
.virtualHostId(userInfo.getVirtualHostId())
.durability(true)
.autoDelete(false)
.description(userInfo.getUsername() + ":专属队列")
.description(userInfo.getUsername() + "用户:专属队列")
.build();
busQueueService.insertSelective(busQueue);
}
... ... @@ -180,7 +180,10 @@ public class UserInfoServiceImpl implements UserInfoService {
if (StringUtil.isNullOrEmpty(userInfo.getId())) {
return new ResultJson<>("400", "该用户不存在");
}
return userInfoMapper.updateByPrimaryKeySelective(userInfo) > 0
ResultJson validateResult = validateUser(userInfo);
int num = userInfoMapper.updateByPrimaryKeySelective(userInfo);
return num > 0
? new ResultJson<>("200", "修改用户信息,成功")
: new ResultJson<>("500", "修改用户信息,失败");
}
... ... @@ -229,6 +232,34 @@ public class UserInfoServiceImpl implements UserInfoService {
return userInfoMapper.selectUserExist(username);
}
@Override
public ResultJson updatePassword(UserInfo userInfo) throws MalformedURLException, URISyntaxException
{
if (StringUtil.isNullOrEmpty(userInfo.getUsername()) || StringUtil.isNullOrEmpty(userInfo.getPassword())) {
return new ResultJson<>("400", "用户名和密码,不能为空");
}
if (userInfoMapper.selectUserExist(userInfo.getUsername()).size() == 0) {
return new ResultJson<>("400", "该用户不存在");
}
UserInfo oldUserInfo = userInfoMapper.selectByUsername(userInfo.getUsername());
oldUserInfo.setPassword(DigestUtils.md5DigestAsHex(userInfo.getPassword().getBytes()));
int num = userInfoMapper.updateByPrimaryKeySelective(oldUserInfo);
// 在这里修改MQ用户密码
Client client = connectClient();
ArrayList<String> tags = new ArrayList<>();
client.updateUser(userInfo.getUsername(), userInfo.getPassword().toCharArray(), tags);
return num > 0
? new ResultJson<>("200", userInfo.getUsername() + "用户:修改密码成功!")
: new ResultJson<>("500", userInfo.getUsername() + "用户:修改密码失败!");
}
public Client connectClient() throws MalformedURLException, URISyntaxException
{
String url = "http://" + host + ":15672/api";
Client client = new Client(url, rabbitUsername, rabbitPassword);
return client;
}
}
... ...