代码提交
parent
acaf482a71
commit
08c163fad8
|
|
@ -3,6 +3,7 @@ package com.whdc.controller;
|
|||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.whdc.model.dto.LoginDto;
|
||||
import com.whdc.model.dto.UserDto;
|
||||
import com.whdc.model.entity.User;
|
||||
import com.whdc.model.group.Insert;
|
||||
import com.whdc.model.group.Update;
|
||||
|
|
@ -139,5 +140,13 @@ public class UserController {
|
|||
return ResultJson.ok(service.removeById(id));
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改密码")
|
||||
@PostMapping(value = "updatePw")
|
||||
public ResultJson updatePwd(@RequestBody UserDto dto) {
|
||||
|
||||
return service.updatePwd(dto);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
package com.whdc.model.dto;
|
||||
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* @author 李赛
|
||||
* @date 2022-07-01 1:21
|
||||
*/
|
||||
@Data
|
||||
public class UserDto {
|
||||
|
||||
|
||||
@ApiParam(value = "用户编号")
|
||||
@NotEmpty(message = "用户编号不能为空")
|
||||
private String id;
|
||||
|
||||
|
||||
@ApiParam(value = "登录名")
|
||||
@NotEmpty(message = "登录名不能为空")
|
||||
private String loginName;
|
||||
|
||||
@ApiParam(value = "旧密码")
|
||||
@NotEmpty(message = "旧密码不能为空")
|
||||
private String oldPassword;
|
||||
|
||||
@ApiParam(value = "新密码")
|
||||
@NotEmpty(message = "新密码不能为空")
|
||||
private String newPassword;
|
||||
}
|
||||
|
|
@ -2,11 +2,11 @@ package com.whdc.service;
|
|||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||
import com.whdc.model.dto.LoginDto;
|
||||
import com.whdc.model.dto.UserDto;
|
||||
import com.whdc.model.entity.User;
|
||||
import com.whdc.model.vo.LoginVo;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import com.whdc.utils.ResultJson;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -34,5 +34,6 @@ public interface IUserService extends IService<User> {
|
|||
boolean register(String phone, Integer abId, String role);
|
||||
|
||||
boolean updateLastDate(Integer id);
|
||||
ResultJson updatePwd(UserDto dto);
|
||||
|
||||
}
|
||||
|
|
@ -6,11 +6,13 @@ import com.whdc.exception.MyException;
|
|||
import com.whdc.mapper.AddressBookMapper;
|
||||
import com.whdc.mapper.UserMapper;
|
||||
import com.whdc.model.dto.LoginDto;
|
||||
import com.whdc.model.dto.UserDto;
|
||||
import com.whdc.model.entity.AddressBook;
|
||||
import com.whdc.model.entity.User;
|
||||
import com.whdc.model.vo.LoginVo;
|
||||
import com.whdc.service.IUserService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.whdc.utils.ResultJson;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -18,6 +20,7 @@ import org.springframework.util.DigestUtils;
|
|||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
|
|
@ -63,7 +66,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|||
BeanUtils.copyProperties(sysUser, out);
|
||||
|
||||
AddressBook book = addressBookMapper.selectById(sysUser.getAbId());
|
||||
out.setName(book.getName());
|
||||
if (Objects.nonNull(book)){
|
||||
out.setName(book.getName());
|
||||
}
|
||||
return out;
|
||||
|
||||
}
|
||||
|
|
@ -109,6 +114,32 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|||
.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultJson updatePwd(UserDto dto) {
|
||||
|
||||
|
||||
User byId = this.getById(dto.getId());
|
||||
if (Objects.isNull(byId)) {
|
||||
|
||||
return ResultJson.error("当前数据不存在");
|
||||
|
||||
}
|
||||
|
||||
User sysUser = findByLoginName(dto.getLoginName());
|
||||
|
||||
if (!dto.getLoginName().equals(byId.getUsername())) {
|
||||
throw new MyException("用户名或密码错误");
|
||||
}
|
||||
|
||||
if (getPassword(sysUser.getSalt() ,dto.getOldPassword()).equals(sysUser.getPassword())) {
|
||||
// 更新密码
|
||||
byId.setPassword(getPassword(sysUser.getSalt() ,dto.getNewPassword()));
|
||||
return ResultJson.ok(byId.updateById());
|
||||
}
|
||||
|
||||
return ResultJson.error("密码错误");
|
||||
}
|
||||
|
||||
private User findByLoginName(String loginName) {
|
||||
if (loginName == null) {
|
||||
throw new MyException("登录名不能为空");
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@
|
|||
|
||||
<select id="page" resultType="com.whdc.model.vo.AddressBookVo">
|
||||
SELECT
|
||||
AB.*,F.SORT FSORT,F.ID FCID,U.ROLE,F.TYPE FTYPE,O.NAME ONAME
|
||||
AB.*,F.SORT FSORT,F.ID FCID,U.ROLE,F.TYPE FTYPE,IF(O.NAME IS NULL,UD.NAME,O.NAME,) ONAME
|
||||
FROM
|
||||
ADDRESS_BOOK AB
|
||||
LEFT JOIN ORGANIZATION O ON AB.ORGANIZATION = O.ID
|
||||
LEFT JOIN UNIT_DICT UD ON AB.ORGANIZATION = UD.ID
|
||||
LEFT JOIN AB_UD_R R ON R.AD_ID = AB.ID
|
||||
LEFT JOIN USERS U ON U.AB_ID = AB.ID
|
||||
LEFT JOIN FC F ON F.AB_ID = AB.ID AND F.USER_ID = #{dto.userId}
|
||||
|
|
|
|||
Loading…
Reference in New Issue