Commit 322c2240 authored by gaoliwei's avatar gaoliwei

修改新增用户部分接口

parent c3510a46
......@@ -5,8 +5,12 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.rcisoft.business.system.user.entity.SysUser;
import org.rcisoft.business.system.user.service.UserService;
import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.controller.PaginationController;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.Result;
import org.rcisoft.core.util.ResultGenerator;
import org.rcisoft.core.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
......@@ -16,6 +20,8 @@ import org.springframework.web.servlet.support.JstlUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* @Author: GaoLiWei
......@@ -23,7 +29,7 @@ import javax.servlet.http.HttpServletResponse;
*/
@Controller
@RequestMapping("/login")
public class LoginController {
public class LoginController extends PaginationController<SysUser> {
@Autowired
private UserService userService;
......@@ -44,6 +50,30 @@ public class LoginController {
return result;
}
@ApiOperation(value = "修改密码")
@ApiImplicitParams({@ApiImplicitParam(name = "newPassWord", value = "新密码", required = true, dataType = "varchar",paramType = "body"),
@ApiImplicitParam(name = "oldPassWord", value = "旧密码", required = true, dataType = "varchar",paramType = "body")})
@PutMapping(value = "/updatePassWord")
@ResponseBody
public Result updatePassWord(@RequestBody String newPassWord, @RequestBody String oldPassWord){
String userId = UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID);
int flag = userService.updatePassWord(newPassWord, oldPassWord, userId);
return Result.builder(new PersistModel(flag));
}
@ApiOperation(value = "重置密码")
@ApiImplicitParams({@ApiImplicitParam(name = "needUserId", value = "需要修改密码的用户的ID", required = true, dataType = "varchar",paramType = "body")})
@ResponseBody
@PutMapping(value = "/resetPassWord")
public Result resetPassWord(@RequestBody String needUserId){
String userId = UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID);
int flag = userService.resetPassWord(userId, needUserId);
return Result.builder(new PersistModel(flag));
}
......
......@@ -16,6 +16,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* @Author: GaoLiWei
* @Date: Created in 10:422018/5/2
......@@ -60,12 +63,14 @@ public class UserController extends PaginationController<SysUser> {
@PutMapping(value = "updateUser")
@ResponseBody
public Result updateUser(@RequestBody UserDto userDto){
String userId = UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID);
SysUser sysUser = userDto.getSysUser();
sysUser.setUserId(userId);
SysAdmins sysAdmins = userDto.getSysAdmins();
SysOwner sysOwner = userDto.getSysOwner();
SysPrincipal sysPrincipal = userDto.getSysPrincipal();
String data = userService.updateUser(sysUser,sysAdmins,sysOwner,sysPrincipal);
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR,data);
int flag = userService.updateUser(sysUser,sysAdmins,sysOwner,sysPrincipal);
return Result.builder(new PersistModel(flag));
}
@ApiOperation(value = "通过用户ID查找用户信息")
......@@ -104,6 +109,21 @@ public class UserController extends PaginationController<SysUser> {
}
@ApiOperation(value = "查看某个用户信息")
@ResponseBody
@GetMapping(value = "/getUserInfo")
public Result getUserInfo(){
String userId = UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID);
List<Map<String, Object>> userInfo = userService.getUserInfo(userId);
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR,userInfo);
}
@ApiOperation(value = "查詢所有菜單")
@ResponseBody
......
......@@ -22,6 +22,12 @@ public interface UserRepository extends BaseMapper<SysUser>{
*/
List<SysUser> listByUserName(@Param("userName") String userName);
/** 根据用户ID查看用户信息
* @param userId
* @return
*/
List<Map<String,Object>> getUserInfo(@Param("userId") String userId);
/**
* 查询所有用户
......
......@@ -38,7 +38,7 @@ public interface UserService {
* @param sysPrincipal
* @return
*/
String updateUser(SysUser sysUser, SysAdmins sysAdmins, SysOwner sysOwner,SysPrincipal sysPrincipal);
int updateUser(SysUser sysUser, SysAdmins sysAdmins, SysOwner sysOwner,SysPrincipal sysPrincipal);
/** 根据userId删除用户
* @param userId
......@@ -65,6 +65,26 @@ public interface UserService {
*/
int updateRoleMenu(RelRoleMenu relRoleMenu);
/** 查看某个用户的信息
* @return
*/
List<Map<String,Object>> getUserInfo(String userId);
/** 修改密码
* @param newPassWord
* @param oldPassWord
* @return
*/
int updatePassWord(String newPassWord, String oldPassWord,String userId);
/** 重置密码
* @param userId
* @return
*/
int resetPassWord(String userId, String needUserId);
List<Map<String,Object>> listMenuAll();
List<Map<String,Object>> listRoleAll();
......
......@@ -14,6 +14,7 @@ import org.rcisoft.common.constants.UserTpConstant;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.util.IdGen;
import org.rcisoft.core.util.JwtUtil;
import org.rcisoft.core.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
......@@ -140,8 +141,8 @@ public class UserServiceImpl implements UserService {
}
@Override
public String updateUser(SysUser sysUser, SysAdmins sysAdmins, SysOwner sysOwner, SysPrincipal sysPrincipal) {
String result = "修改失败";
public int updateUser(SysUser sysUser, SysAdmins sysAdmins, SysOwner sysOwner, SysPrincipal sysPrincipal) {
int flag = 0;
String userId = sysUser.getUserId();
String userTp = sysUser.getUserTp();
try {
......@@ -150,7 +151,7 @@ public class UserServiceImpl implements UserService {
if (null != sysAdminsByUserId){
sysAdmins.setAdminId(sysAdminsByUserId.getAdminId());
adminRepository.updateByPrimaryKeySelective(sysAdmins);
result = "修改管理员信息成功";
flag = 1;
}
}
if (UserTpConstant.TP_OWNER.equals(userTp)) {
......@@ -158,7 +159,7 @@ public class UserServiceImpl implements UserService {
if (null != sysOwnerByUserId) {
sysOwner.setOwnId(sysOwnerByUserId.getOwnId());
ownerRepository.updateByPrimaryKeySelective(sysOwner);
result = "修改业主信息成功";
flag = 1;
}
}
if (UserTpConstant.TP_PRINCIPAL.equals(userTp)) {
......@@ -166,14 +167,14 @@ public class UserServiceImpl implements UserService {
if (null != sysPrincipalByUserId) {
sysPrincipal.setPriId(sysPrincipalByUserId.getPriId());
principalRepository.updateByPrimaryKeySelective(sysPrincipal);
result = "修改团队负责人信息成功";
flag = 1;
}
}
return result;
return flag;
} catch (Exception e) {
e.printStackTrace();
}
return "修改失败";
return flag;
}
@Override
......@@ -254,6 +255,38 @@ public class UserServiceImpl implements UserService {
return flag;
}
@Override
public List<Map<String, Object>> getUserInfo(String userId) {
return userRepository.getUserInfo(userId);
}
@Override
public int updatePassWord(String newPassWord, String oldPassWord,String userId) {
int flag = 0;
SysUser sysUser = userRepository.selectByPrimaryKey(userId);
String encodedPassword = sysUser.getUserPwd();
boolean matches = passwordEncoder.matches(oldPassWord, encodedPassword);
if (matches){
sysUser.setUserPwd(passwordEncoder.encode(newPassWord));
int i = userRepository.updateByPrimaryKeySelective(sysUser);
flag = i;
}
return flag;
}
@Override
public int resetPassWord(String userId, String needUserId) {
int flag = 0;
SysUser sysUser = userRepository.selectByPrimaryKey(userId);
if (UserTpConstant.TP_SUPER_ADMIN.equals(sysUser.getUserTp())){
SysUser needSysUser = userRepository.selectByPrimaryKey(needUserId);
needSysUser.setUserPwd(passwordEncoder.encode(UserPassWordConstant.PASSWORD));
userRepository.updateByPrimaryKeySelective(needSysUser);
flag = 1;
}
return flag;
}
@Override
public List<Map<String, Object>> listMenuAll() {
List<Map<String, Object>> list = relUserRoleRepository.listMenuAll();
......
......@@ -7,5 +7,11 @@
SELECT USER_ID AS userId, USER_NM AS userNm, USER_PWD AS userPwd, USER_TP AS userTp FROM sys_user
WHERE USER_NM = #{userName}
</select>
<select id="getUserInfo" resultType="map">
SELECT su.USER_NM,su.USER_TP,sa.*, so.*,sp.* FROM sys_user su LEFT JOIN sys_admins sa ON su.USER_ID = sa.USER_ID
LEFT JOIN sys_owner so ON su.USER_ID = so.USER_ID
LEFT JOIN sys_principal sp ON su.USER_ID = sp.USER_ID
WHERE su.USER_ID=#{userId}
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment