作者 王勇

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

@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.*; @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.*;
7 7
8 import javax.annotation.Resource; 8 import javax.annotation.Resource;
9 import java.io.IOException; 9 import java.io.IOException;
  10 +import java.net.MalformedURLException;
10 import java.net.URISyntaxException; 11 import java.net.URISyntaxException;
11 import java.util.List; 12 import java.util.List;
12 import java.util.concurrent.TimeoutException; 13 import java.util.concurrent.TimeoutException;
@@ -54,10 +55,22 @@ public class UserInfoController { @@ -54,10 +55,22 @@ public class UserInfoController {
54 * @param userInfo {@link UserInfo} 55 * @param userInfo {@link UserInfo}
55 * @return 56 * @return
56 */ 57 */
57 - @PostMapping("/update")  
58 - public ResultJson updateUser(UserInfo userInfo) 58 + @PutMapping("/update")
  59 + public ResultJson updateUser(@RequestBody UserInfo userInfo)
59 { 60 {
60 return userInfoService.updateByPrimaryKeySelective(userInfo); 61 return userInfoService.updateByPrimaryKeySelective(userInfo);
61 } 62 }
62 63
  64 + /**
  65 + * 编辑用户信息
  66 + *
  67 + * @param userInfo {@link UserInfo}
  68 + * @return
  69 + */
  70 + @PutMapping("/updatePassword")
  71 + public ResultJson updatePassword(@RequestBody UserInfo userInfo) throws MalformedURLException, URISyntaxException
  72 + {
  73 + return userInfoService.updatePassword(userInfo);
  74 + }
  75 +
63 } 76 }
@@ -4,6 +4,7 @@ import com.sunyo.wlpt.message.bus.service.domain.UserInfo; @@ -4,6 +4,7 @@ import com.sunyo.wlpt.message.bus.service.domain.UserInfo;
4 import com.sunyo.wlpt.message.bus.service.response.ResultJson; 4 import com.sunyo.wlpt.message.bus.service.response.ResultJson;
5 5
6 import java.io.IOException; 6 import java.io.IOException;
  7 +import java.net.MalformedURLException;
7 import java.net.URISyntaxException; 8 import java.net.URISyntaxException;
8 import java.util.List; 9 import java.util.List;
9 import java.util.concurrent.TimeoutException; 10 import java.util.concurrent.TimeoutException;
@@ -86,7 +87,13 @@ public interface UserInfoService { @@ -86,7 +87,13 @@ public interface UserInfoService {
86 */ 87 */
87 List<UserInfo> selectUserExist(String username); 88 List<UserInfo> selectUserExist(String username);
88 89
89 - 90 + /**
  91 + * 修改密码
  92 + *
  93 + * @param userInfo {@link UserInfo}
  94 + * @return
  95 + */
  96 + ResultJson updatePassword(UserInfo userInfo) throws MalformedURLException, URISyntaxException;
90 } 97 }
91 98
92 99
@@ -127,7 +127,7 @@ public class UserInfoServiceImpl implements UserInfoService { @@ -127,7 +127,7 @@ public class UserInfoServiceImpl implements UserInfoService {
127 .virtualHostId(userInfo.getVirtualHostId()) 127 .virtualHostId(userInfo.getVirtualHostId())
128 .durability(true) 128 .durability(true)
129 .autoDelete(false) 129 .autoDelete(false)
130 - .description(userInfo.getUsername() + ":专属队列") 130 + .description(userInfo.getUsername() + "用户:专属队列")
131 .build(); 131 .build();
132 busQueueService.insertSelective(busQueue); 132 busQueueService.insertSelective(busQueue);
133 } 133 }
@@ -180,7 +180,10 @@ public class UserInfoServiceImpl implements UserInfoService { @@ -180,7 +180,10 @@ public class UserInfoServiceImpl implements UserInfoService {
180 if (StringUtil.isNullOrEmpty(userInfo.getId())) { 180 if (StringUtil.isNullOrEmpty(userInfo.getId())) {
181 return new ResultJson<>("400", "该用户不存在"); 181 return new ResultJson<>("400", "该用户不存在");
182 } 182 }
183 - return userInfoMapper.updateByPrimaryKeySelective(userInfo) > 0 183 + ResultJson validateResult = validateUser(userInfo);
  184 + int num = userInfoMapper.updateByPrimaryKeySelective(userInfo);
  185 +
  186 + return num > 0
184 ? new ResultJson<>("200", "修改用户信息,成功") 187 ? new ResultJson<>("200", "修改用户信息,成功")
185 : new ResultJson<>("500", "修改用户信息,失败"); 188 : new ResultJson<>("500", "修改用户信息,失败");
186 } 189 }
@@ -229,6 +232,34 @@ public class UserInfoServiceImpl implements UserInfoService { @@ -229,6 +232,34 @@ public class UserInfoServiceImpl implements UserInfoService {
229 return userInfoMapper.selectUserExist(username); 232 return userInfoMapper.selectUserExist(username);
230 } 233 }
231 234
  235 + @Override
  236 + public ResultJson updatePassword(UserInfo userInfo) throws MalformedURLException, URISyntaxException
  237 + {
  238 + if (StringUtil.isNullOrEmpty(userInfo.getUsername()) || StringUtil.isNullOrEmpty(userInfo.getPassword())) {
  239 + return new ResultJson<>("400", "用户名和密码,不能为空");
  240 + }
  241 + if (userInfoMapper.selectUserExist(userInfo.getUsername()).size() == 0) {
  242 + return new ResultJson<>("400", "该用户不存在");
  243 + }
  244 + UserInfo oldUserInfo = userInfoMapper.selectByUsername(userInfo.getUsername());
  245 + oldUserInfo.setPassword(DigestUtils.md5DigestAsHex(userInfo.getPassword().getBytes()));
  246 + int num = userInfoMapper.updateByPrimaryKeySelective(oldUserInfo);
  247 + // 在这里修改MQ用户密码
  248 + Client client = connectClient();
  249 + ArrayList<String> tags = new ArrayList<>();
  250 + client.updateUser(userInfo.getUsername(), userInfo.getPassword().toCharArray(), tags);
  251 + return num > 0
  252 + ? new ResultJson<>("200", userInfo.getUsername() + "用户:修改密码成功!")
  253 + : new ResultJson<>("500", userInfo.getUsername() + "用户:修改密码失败!");
  254 + }
  255 +
  256 + public Client connectClient() throws MalformedURLException, URISyntaxException
  257 + {
  258 + String url = "http://" + host + ":15672/api";
  259 + Client client = new Client(url, rabbitUsername, rabbitPassword);
  260 + return client;
  261 + }
  262 +
232 } 263 }
233 264
234 265