Commit 975fb466 authored by 廖旭伟's avatar 廖旭伟

修改bug

parent 6f7a1706
/** /**
* 文件:UserService.java * 文件:UserService.java
* 版本:1.0.0 * 版本:1.0.0
* 日期: * 日期:
* Copyright ® * Copyright ®
* All right reserved. * All right reserved.
*/ */
package com.mortals.xhx.base.system.user.service; package com.mortals.xhx.base.system.user.service;
...@@ -13,7 +13,6 @@ import com.mortals.framework.model.Result; ...@@ -13,7 +13,6 @@ import com.mortals.framework.model.Result;
import com.mortals.framework.service.ICRUDService; import com.mortals.framework.service.ICRUDService;
import com.mortals.framework.service.IUser; import com.mortals.framework.service.IUser;
import com.mortals.xhx.base.system.menu.model.MenuEntity; import com.mortals.xhx.base.system.menu.model.MenuEntity;
import com.mortals.xhx.base.system.user.dao.UserDao;
import com.mortals.xhx.base.system.user.model.UserEntity; import com.mortals.xhx.base.system.user.model.UserEntity;
import java.util.List; import java.util.List;
...@@ -24,7 +23,7 @@ import java.util.Set; ...@@ -24,7 +23,7 @@ import java.util.Set;
* <p>Description: UserService service接口 </p> * <p>Description: UserService service接口 </p>
* <p>Copyright: Copyright &reg; </p> * <p>Copyright: Copyright &reg; </p>
* <p>Company: </p> * <p>Company: </p>
* @author * @author
* @version 1.0.0 * @version 1.0.0
*/ */
...@@ -38,7 +37,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> { ...@@ -38,7 +37,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> {
* @return * @return
* @throws AppException * @throws AppException
*/ */
UserEntity doLogin(String loginName, String password, String loginIp) throws AppException; public UserEntity doLogin(String loginName, String password, String loginIp) throws AppException;
/** /**
* 校验用户名与密码是否正确 * 校验用户名与密码是否正确
...@@ -48,7 +47,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> { ...@@ -48,7 +47,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> {
* @return * @return
* @throws AppException * @throws AppException
*/ */
UserEntity doCheckUser(String loginName, String password) throws AppException; public UserEntity doCheckUser(String loginName, String password) throws AppException;
/** /**
* 检查用户是否存在 * 检查用户是否存在
...@@ -57,7 +56,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> { ...@@ -57,7 +56,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> {
* @param userId 密码 * @param userId 密码
* @return * @return
*/ */
boolean existUser(String loginName, Long userId) throws AppException; public boolean existUser(String loginName, Long userId) throws AppException;
/** /**
* 通过登录用户获取菜单功能权限 * 通过登录用户获取菜单功能权限
...@@ -65,7 +64,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> { ...@@ -65,7 +64,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> {
* @param user * @param user
* @return * @return
*/ */
List<MenuEntity> findOutlookBarList(IUser user); public List<MenuEntity> findOutlookBarList(IUser user);
/** /**
* 查询用户所有有权限的菜单ID * 查询用户所有有权限的菜单ID
...@@ -73,7 +72,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> { ...@@ -73,7 +72,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> {
* @param userEntity * @param userEntity
* @return * @return
*/ */
Set<Long> findAllAuthIds(UserEntity userEntity) throws AppException; public Set<Long> findAllAuthIds(UserEntity userEntity) throws AppException;
/** /**
* 查询用户记录 * 查询用户记录
...@@ -85,7 +84,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> { ...@@ -85,7 +84,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> {
* @return * @return
* @throws AppException * @throws AppException
*/ */
Result<UserEntity> find(Long platformId, UserEntity params, int currPage, int prePageResult) throws AppException; public Result<UserEntity> find(Long platformId, UserEntity params, int currPage, int prePageResult) throws AppException;
/** /**
* 为客户创建用户 * 为客户创建用户
...@@ -100,7 +99,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> { ...@@ -100,7 +99,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> {
* @return * @return
* @throws AppException * @throws AppException
*/ */
UserEntity createUser(IUser currUser, Long customerId, String customerName, String loginName, String password, public UserEntity createUser(IUser currUser, Long customerId, String customerName, String loginName, String password,
String userName, String mobile) throws AppException; String userName, String mobile) throws AppException;
/** /**
...@@ -112,10 +111,5 @@ public interface UserService extends ICRUDService<UserEntity,Long> { ...@@ -112,10 +111,5 @@ public interface UserService extends ICRUDService<UserEntity,Long> {
* @return * @return
* @throws AppException * @throws AppException
*/ */
boolean updateUserPwd(String loginName, String oldPwd, String newPwd) throws AppException; public boolean updateUserPwd(String loginName, String oldPwd, String newPwd) throws AppException;
UserDao getUserDao();
} }
\ No newline at end of file
/**
* 文件:UserController.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.user.web; package com.mortals.xhx.base.system.user.web;
import com.alibaba.fastjson.JSONObject; import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.service.IUser;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.role.model.RoleEntity;
import com.mortals.xhx.base.system.role.service.RoleService;
import com.mortals.xhx.common.code.UserStatus;
import com.mortals.framework.common.IBaseEnum; import com.mortals.framework.common.IBaseEnum;
import com.mortals.framework.common.code.UserType; import com.mortals.framework.common.code.UserType;
import com.mortals.xhx.common.key.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.framework.web.BaseCRUDJsonMappingController; import com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.xhx.base.framework.annotation.Operlog; import com.mortals.xhx.base.framework.annotation.Operlog;
import com.mortals.xhx.base.system.role.model.RoleQuery;
import com.mortals.xhx.base.system.role.model.RoleUserEntity;
import com.mortals.xhx.base.system.role.model.RoleUserQuery;
import com.mortals.xhx.base.system.role.service.RoleService;
import com.mortals.xhx.base.system.role.service.RoleUserService;
import com.mortals.xhx.base.system.user.model.UserEntity; import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.service.UserService; import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.UserStatus;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* 用户信息 * <p>Title: 用户信息</p>
* * <p>Description: UserController </p>
* @author: zxfei * <p>Copyright: Copyright &reg; </p>
* @date: 2022/5/7 15:42 * <p>Company: </p>
* @author
* @version 1.0.0
*/ */
@RestController @RestController
@RequestMapping("user") @RequestMapping("user")
public class UserController extends BaseCRUDJsonBodyMappingController<UserService, UserEntity, Long> { public class UserController extends BaseCRUDJsonBodyMappingController<UserService, UserEntity, Long> {
@Autowired @Autowired
private RoleService roleService; private UserService userService;
@Autowired @Autowired
private RoleUserService roleUserService; private RoleService roleService;
public UserController() { public UserController() {
super.setFormClass(UserForm.class); super.setFormClass(UserForm.class);
...@@ -56,57 +60,33 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic ...@@ -56,57 +60,33 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic
@Override @Override
protected void init(Map<String, Object> model, Context context) { protected void init(Map<String, Object> model, Context context) {
this.addDict(model,"userType", IBaseEnum.getEnumMap(UserType.class)); this.addDict(model,"userType", IBaseEnum.getEnumMap(UserType.class));
this.addDict(model,"status", UserStatus.getEnumMap()); this.addDict(model,"status", UserStatus.getEnumMap());
this.addDict(model, "roleIds", roleService.find(new RoleQuery()).stream().collect(Collectors.toMap(x -> x.getId().toString(), y -> y.getName()))); List<RoleEntity> roleList = roleService.find(new RoleEntity());
this.addDict(model,"roleId", roleList.stream().collect(Collectors.toMap(e->e.getId().toString(), e->e.getName())));
} super.init(model, context);
@Override
protected void doListBefore(UserEntity query, Map<String, Object> model, Context context) throws AppException {
if (!StringUtils.isEmpty(query.getRealName())) {
query.setRealName("%".concat(query.getRealName()).concat("%"));
}
if (!StringUtils.isEmpty(query.getLoginName())) {
query.setLoginName("%".concat(query.getLoginName()).concat("%"));
}
} }
@Override @Override
protected int editAfter(Long id, Map<String, Object> model, UserEntity entity, Context context) throws AppException { protected int editAfter(Long id, Map<String, Object> model, UserEntity entity, Context context) throws AppException {
RoleUserQuery roleUserQuery = new RoleUserQuery(); entity.setLoginPwd(null);
roleUserQuery.setUserId(entity.getId()); entity.setLoginPwd1(null);
String roleIds = roleUserService.find(roleUserQuery).stream().map(RoleUserEntity::getRoleId).map(String::valueOf).collect(Collectors.joining(",")); entity.setLoginPwd2(null);
entity.setRoleIds(roleIds); entity.setLoginPwd3(null);
return super.editAfter(id, model, entity, context); return 1;
}
@Override
protected int saveAfter(UserEntity entity, Map<String, Object> model, Context context) throws AppException {
if (entity.getId() == getCurUser().getId()) {
// TODO: 2022/8/15 更新redis session信息
//saveCurrUserForSession(request, response, userService.get(form.getEntity().getId(), false));
}
return super.saveAfter(entity, model, context);
} }
// @Override
// protected void saveBefore(UserEntity entity, Map<String, Object> model, Context context) throws AppException {
// if (!ObjectUtils.isEmpty(entity.getLoginName()) && service.existUser(entity.getLoginName(), entity.getId())) {
// throw new AppException("登录名已存在!");
// }
// super.saveBefore(entity, model, context);
// }
@RequestMapping(value = "change/password", method = RequestMethod.POST) @RequestMapping(value = "change/password", method = RequestMethod.POST)
@Operlog(msg = "密码修改成功!") public String changePassword(@RequestBody UserEntity entity) {
public String changePassword(@RequestParam String oldPwd, @RequestParam String newPwd) {
IUser user = this.getCurUser();
if(user == null){
return this.createFailJsonResp("请先登录");
}
JSONObject ret = new JSONObject(); JSONObject ret = new JSONObject();
try { try {
service.updateUserPwd(super.getCurUser().getLoginName(), oldPwd, newPwd); service.updateUserPwd(super.getCurUser().getLoginName(), entity.getOldPassword(), entity.getNewPassword());
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS); ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "密码修改成功!"); ret.put(KEY_RESULT_MSG, "密码修改成功!");
} catch (Exception e) { } catch (Exception e) {
...@@ -115,22 +95,4 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic ...@@ -115,22 +95,4 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic
} }
return ret.toJSONString(); return ret.toJSONString();
} }
public static void main(String[] args) {
String token = "eyJhbGciOiJIUzI1NiJ9.eyJsb2dpbl91c2VyX2tleSI6IjIzNGE5NDA5ZDVhOTQ3MWNhMzdkYjZkYmMwY2JjZTc5In0.MWyQW40HYDxyUz7PJRf_nRsFPWx3Hr811Ime984nixs";
String secret = "026db82420614469897fcc2dc1b4ce38";
Claims claims = Jwts.parser()
.setSigningKey(Base64.getEncoder().encodeToString(secret.getBytes()))
.parseClaimsJws(token)
.getBody();
String uuid = (String) claims.get("login_user_key");
System.out.println(uuid);
}
} }
\ 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