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

修改bug

parent 6f7a1706
/**
* 文件:UserService.java
* 版本:1.0.0
* 日期:
* Copyright ®
* All right reserved.
*/
* 文件:UserService.java
* 版本:1.0.0
* 日期:
* Copyright ®
* All right reserved.
*/
package com.mortals.xhx.base.system.user.service;
......@@ -13,7 +13,6 @@ import com.mortals.framework.model.Result;
import com.mortals.framework.service.ICRUDService;
import com.mortals.framework.service.IUser;
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 java.util.List;
......@@ -24,7 +23,7 @@ import java.util.Set;
* <p>Description: UserService service接口 </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @author
* @version 1.0.0
*/
......@@ -38,7 +37,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> {
* @return
* @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> {
* @return
* @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> {
* @param userId 密码
* @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> {
* @param user
* @return
*/
List<MenuEntity> findOutlookBarList(IUser user);
public List<MenuEntity> findOutlookBarList(IUser user);
/**
* 查询用户所有有权限的菜单ID
......@@ -73,7 +72,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> {
* @param userEntity
* @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> {
* @return
* @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> {
* @return
* @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;
/**
......@@ -112,10 +111,5 @@ public interface UserService extends ICRUDService<UserEntity,Long> {
* @return
* @throws AppException
*/
boolean updateUserPwd(String loginName, String oldPwd, String newPwd) throws AppException;
UserDao getUserDao();
public boolean updateUserPwd(String loginName, String oldPwd, String newPwd) throws AppException;
}
\ No newline at end of file
/**
* 文件:UserController.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
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.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.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
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.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;
/**
* 用户信息
*
* @author: zxfei
* @date: 2022/5/7 15:42
* <p>Title: 用户信息</p>
* <p>Description: UserController </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @version 1.0.0
*/
@RestController
@RequestMapping("user")
public class UserController extends BaseCRUDJsonBodyMappingController<UserService, UserEntity, Long> {
@Autowired
private RoleService roleService;
private UserService userService;
@Autowired
private RoleUserService roleUserService;
private RoleService roleService;
public UserController() {
super.setFormClass(UserForm.class);
......@@ -56,57 +60,33 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic
@Override
protected void init(Map<String, Object> model, Context context) {
this.addDict(model,"userType", IBaseEnum.getEnumMap(UserType.class));
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())));
}
@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("%"));
}
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 int editAfter(Long id, Map<String, Object> model, UserEntity entity, Context context) throws AppException {
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(entity.getId());
String roleIds = roleUserService.find(roleUserQuery).stream().map(RoleUserEntity::getRoleId).map(String::valueOf).collect(Collectors.joining(","));
entity.setRoleIds(roleIds);
return super.editAfter(id, model, entity, context);
}
@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);
entity.setLoginPwd(null);
entity.setLoginPwd1(null);
entity.setLoginPwd2(null);
entity.setLoginPwd3(null);
return 1;
}
// @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)
@Operlog(msg = "密码修改成功!")
public String changePassword(@RequestParam String oldPwd, @RequestParam String newPwd) {
public String changePassword(@RequestBody UserEntity entity) {
IUser user = this.getCurUser();
if(user == null){
return this.createFailJsonResp("请先登录");
}
JSONObject ret = new JSONObject();
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_MSG, "密码修改成功!");
} catch (Exception e) {
......@@ -115,22 +95,4 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic
}
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