You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virtual-patient/virtual-patient-web/src/main/java/com/supervision/service/impl/UserManageServiceImpl.java

62 lines
1.9 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.supervision.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.supervision.model.User;
import com.supervision.pojo.vo.UserInfoReqVo;
import com.supervision.pojo.vo.UserInfoResVo;
import com.supervision.service.UserManageService;
import com.supervision.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
@RequiredArgsConstructor
public class UserManageServiceImpl implements UserManageService {
private final UserService userService;
@Override
public boolean updateUserInfo(UserInfoReqVo userInfo) {
Assert.notEmpty(userInfo.getId(),"用户id不能为空");
if (StrUtil.isNotEmpty(userInfo.getNewPassword())){
//todo密码复杂度规则匹配
Assert.notEmpty(userInfo.getOldPassword(),"旧密码不允许为空");
}
User user = userService.getById(userInfo.getId());
Assert.notNull(user,"用户信息不存在");
boolean change = false;
if (StrUtil.isNotEmpty(userInfo.getName())){
user.setName(userInfo.getName());
change = true;
}
String newPassword = userInfo.getNewPassword();
String oldPassword = userInfo.getOldPassword();
if (StrUtil.isAllNotEmpty(newPassword,oldPassword)){
Assert.isTrue(user.getPassword().equals(oldPassword),"密码不正确");
user.setPassword(newPassword);
change = true;
}
if (!change){
return false;
}
return userService.updateById(user);
}
@Override
public UserInfoResVo getUserAccountInfo(String userId) {
User user = userService.getById(userId);
Assert.notNull(user,"未查询到用户信息");
return BeanUtil.toBean(user,UserInfoResVo.class);
}
}