Browse Source

修改获取登录用户信息相关接口

tags/v1.0.0^2
chengwang 1 year ago
parent
commit
ba3495247c
7 changed files with 127 additions and 45 deletions
  1. +2
    -19
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/DeptServiceImpl.java
  2. +5
    -4
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/IUserServiceImpl.java
  3. +3
    -3
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/InspectionFileHandleServiceImpl.java
  4. +13
    -3
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/InspectionFileServiceImpl.java
  5. +4
    -5
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/InspectionServiceImpl.java
  6. +18
    -11
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WorkOrderServiceImpl.java
  7. +82
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/utils/CurrentUserUtil.java

+ 2
- 19
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/DeptServiceImpl.java View File

@@ -35,12 +35,8 @@ public class DeptServiceImpl implements IDeptService {
filter(dept -> dept.getPid().equals("1"))
.peek(dept -> dept.setItemList(getChildren(dept, list))).sorted(Comparator.comparingInt(dept -> (dept.getSort() == null ? 0 : dept.getSort())))
.collect(Collectors.toList());
//List<Dept> deptList = new ArrayList<>();

return JsonResult.success(result);



return JsonResult.success(result);
// List<Dept> deptList = new ArrayList<>();
// List<Dept> deptTreeVoList = new ArrayList<>();
// Map<String, Dept> deptVoMap = new HashMap<>();
// for (Dept dept : list) {
@@ -56,7 +52,6 @@ public class DeptServiceImpl implements IDeptService {
// }
// }
// return JsonResult.success(deptTreeVoList);

}

@Override
@@ -67,18 +62,6 @@ public class DeptServiceImpl implements IDeptService {
}


//查询出所有部门
// List all;
// addAll(1,all,new ArrayList());
//
// private void addAll(Integer id,List all,List res){
// all.stream().filter(x->Objects.equals(x.getparentId,id)).forEach(x->{
// res.add(x.getid());
// addAll(x.getid(),all,res);
// });
// }


/**
* 递归获取部门的子集
*

+ 5
- 4
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/IUserServiceImpl.java View File

@@ -20,6 +20,7 @@ import com.tuoheng.miniprogram.entity.User;
import com.tuoheng.miniprogram.entity.query.OidcUpdatePassRequest;
import com.tuoheng.miniprogram.enums.UserCodeEnum;
import com.tuoheng.miniprogram.service.IUserService;
import com.tuoheng.miniprogram.utils.CurrentUserUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
@@ -45,14 +46,14 @@ public class IUserServiceImpl extends ServiceImpl<UserMapper, User> implements I

@Override
public JsonResult getUserInfo() {
//获取登录用户名称
//String username = SecurityUserUtils.username();
String username = "admin";
//登录用户信息
User userInfo = CurrentUserUtil.getUserInfo();
String username = userInfo.getUsername();
if(StringUtils.isEmpty(username)){
return JsonResult.error(UserCodeEnum.USER_NAME_IS_NULL.getCode(),UserCodeEnum.USER_NAME_IS_NULL.getMsg());
}
User user = userMapper.selectOne(new LambdaQueryWrapper<User>()
.eq(null != username, User::getUsername, username));
.eq(User::getUsername, username).eq(User::getMark,1));
if(ObjectUtil.isNull(user)){
return JsonResult.error(UserCodeEnum.USER_IS_NULL.getCode(),UserCodeEnum.USER_IS_NULL.getMsg());
}

+ 3
- 3
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/InspectionFileHandleServiceImpl.java View File

@@ -14,6 +14,7 @@ import com.tuoheng.miniprogram.entity.dto.UploadResultDto;
import com.tuoheng.miniprogram.enums.InspectionFileHandleEnum;
import com.tuoheng.miniprogram.enums.ServiceExceptionEnum;
import com.tuoheng.miniprogram.service.IInspectionFileHandleService;
import com.tuoheng.miniprogram.utils.CurrentUserUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -43,7 +44,6 @@ public class InspectionFileHandleServiceImpl implements IInspectionFileHandleSer

@Autowired
private WorkOrderFileMapper workOrderFileMapper;

/**
* 上传结果
* @param dto
@@ -52,8 +52,8 @@ public class InspectionFileHandleServiceImpl implements IInspectionFileHandleSer
@Override
public JsonResult uploadResult(UploadResultDto dto) {
//登录用户信息
//String username = SecurityUserUtils.username();
String username = "admin";
User userInfo = CurrentUserUtil.getUserInfo();
String username = userInfo.getUsername();
if(StringUtils.isEmpty(username)){
return JsonResult.error(InspectionFileHandleEnum.USER_NAME_IS_NULL.getCode(),InspectionFileHandleEnum.USER_NAME_IS_NULL.getMsg());
}

+ 13
- 3
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/InspectionFileServiceImpl.java View File

@@ -23,6 +23,7 @@ import com.tuoheng.miniprogram.entity.query.InspectionFileQuery;
import com.tuoheng.miniprogram.enums.InspectionFileEnum;
import com.tuoheng.miniprogram.enums.UserTypeEnum;
import com.tuoheng.miniprogram.service.IInspectionFileService;
import com.tuoheng.miniprogram.utils.CurrentUserUtil;
import com.tuoheng.miniprogram.vo.InspectionFileCountVo;
import com.tuoheng.miniprogram.vo.InspectionFileInfoVo;
import com.tuoheng.miniprogram.vo.SeeQuestionVo;
@@ -68,6 +69,9 @@ public class InspectionFileServiceImpl implements IInspectionFileService {
if(null == query.getLimit() && null == query.getPage()){
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//登录用户信息
String tenantId = CurrentUserUtil.getTenantId();
query.setTenantId(tenantId);
if(StringUtils.isEmpty(query.getInspectionId())){
return JsonResult.error("任务id为空");
}
@@ -105,6 +109,9 @@ public class InspectionFileServiceImpl implements IInspectionFileService {
if(null==query.getLimit() && null == query.getPage()){
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//登录用户信息
String tenantId = CurrentUserUtil.getTenantId();
query.setTenantId(tenantId);
if(StringUtils.isEmpty(query.getInspectionId())){
return JsonResult.error("任务id为空");
}
@@ -143,6 +150,9 @@ public class InspectionFileServiceImpl implements IInspectionFileService {
if(null==query.getLimit() && null == query.getPage()){
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//登录用户信息
String tenantId = CurrentUserUtil.getTenantId();
query.setTenantId(tenantId);
if(StringUtils.isEmpty(query.getInspectionId())){
return JsonResult.error("任务id为空");
}
@@ -306,9 +316,9 @@ public class InspectionFileServiceImpl implements IInspectionFileService {
*/
@Override
public JsonResult handleCount() {
//获取当前登录人信息
//String username = SecurityUserUtils.username();
String username = "admin";
//登录用户信息
User userInfo = CurrentUserUtil.getUserInfo();
String username = userInfo.getUsername();
if(StringUtils.isEmpty(username)){
return JsonResult.error(InspectionFileEnum.USER_NAME_IS_NULL.getCode(),InspectionFileEnum.USER_NAME_IS_NULL.getMsg());
}

+ 4
- 5
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/InspectionServiceImpl.java View File

@@ -14,6 +14,7 @@ import com.tuoheng.miniprogram.entity.*;
import com.tuoheng.miniprogram.entity.query.InspectionQuery;
import com.tuoheng.miniprogram.enums.UserTypeEnum;
import com.tuoheng.miniprogram.service.IInspectionService;
import com.tuoheng.miniprogram.utils.CurrentUserUtil;
import com.tuoheng.miniprogram.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
@@ -57,11 +58,9 @@ public class InspectionServiceImpl implements IInspectionService {
if(null==query.getLimit() && null == query.getPage()){
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//获取登录人信息,登录人用户名
// String username = SecurityUserUtils.username();
//获取租户id
//String tenantId = ShiroUtils.getTenantId();
String username = "admin";
//登录用户信息
User userInfo = CurrentUserUtil.getUserInfo();
String username = userInfo.getUsername();
User user = userMapper.selectOne(Wrappers.<User>lambdaQuery()
.eq(StringUtils.isNotEmpty(username), User::getUsername, username)
.eq(User::getStatus, 1).eq(User::getMark, 1));

+ 18
- 11
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WorkOrderServiceImpl.java View File

@@ -24,6 +24,7 @@ import com.tuoheng.miniprogram.entity.query.HandleQuery;
import com.tuoheng.miniprogram.entity.query.WorkOrderQuery;
import com.tuoheng.miniprogram.enums.*;
import com.tuoheng.miniprogram.service.IWorkOrderService;
import com.tuoheng.miniprogram.utils.CurrentUserUtil;
import com.tuoheng.miniprogram.vo.WorkOrderCountVo;
import com.tuoheng.miniprogram.vo.WorkOrderHandleVo;
import com.tuoheng.miniprogram.vo.WorkOrderInfoVo;
@@ -72,6 +73,9 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO

@Override
public JsonResult addInfo(WorkOrderDto dto) {
//登录用户信息
String tenantId = CurrentUserUtil.getTenantId();
dto.setTenantId(tenantId);
if(StringUtils.isEmpty(dto.getTenantId())){
return JsonResult.error(WorkOrderEnum.TENANT_ID_IS_NULL.getCode(),WorkOrderEnum.TENANT_ID_IS_NULL.getMsg());
}
@@ -81,8 +85,9 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
// if(StringUtils.isEmpty(dto.getUserId())){
// return JsonResult.error(WorkOrderEnum.USER_ID_IS_NULL.getCode(),WorkOrderEnum.USER_ID_IS_NULL.getMsg());
// }
//String username = SecurityUserUtils.username();
String username ="admin";
//登录用户信息
User userInfo = CurrentUserUtil.getUserInfo();
String username = userInfo.getUsername();
if(StringUtils.isEmpty(username)){
return JsonResult.error(WorkOrderEnum.USER_NAME_IS_NULL.getCode(),WorkOrderEnum.USER_NAME_IS_NULL.getMsg());
}
@@ -143,8 +148,9 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
if(query.getLimit()==null && query.getPage()==null){
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//String username = SecurityUserUtils.username();
String username = "admin";
//登录用户信息
User userInfo1 = CurrentUserUtil.getUserInfo();
String username = userInfo1.getUsername();
if(null ==username){
return JsonResult.error(WorkOrderEnum.USER_NAME_IS_NULL.getCode(),WorkOrderEnum.USER_NAME_IS_NULL.getMsg());
}
@@ -154,7 +160,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
if(ObjectUtil.isNull(user)){
return JsonResult.error(WorkOrderEnum.USER_IS_NOT_EXIST.getCode(),WorkOrderEnum.USER_IS_NOT_EXIST.getMsg());
}
String tenantId = user.getTenantId();
String tenantId = userInfo1.getTenantId();
if(null == tenantId){
return JsonResult.error(WorkOrderEnum.DEPT_ID_IS_NULL.getCode(),WorkOrderEnum.DEPT_ID_IS_NULL.getMsg());
}
@@ -345,8 +351,9 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
if(query.getLimit()==null && query.getPage()==null){
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//String username = SecurityUserUtils.username();
String username = "admin";
//获取登录用户信息
User userInfo1 = CurrentUserUtil.getUserInfo();
String username = userInfo1.getUsername();
if(null ==username){
return JsonResult.error(WorkOrderEnum.USER_NAME_IS_NULL.getCode(),WorkOrderEnum.USER_NAME_IS_NULL.getMsg());
}
@@ -548,8 +555,8 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
@Override
public JsonResult weekCount() {
//获取登录用户信息
//String username = SecurityUserUtils.username();
String username = "admin";
User userInfo = CurrentUserUtil.getUserInfo();
String username = userInfo.getUsername();
if(StringUtils.isEmpty(username)){
return JsonResult.error(WorkOrderEnum.USER_NAME_IS_NULL.getCode(),WorkOrderEnum.USER_NAME_IS_NULL.getMsg());
}
@@ -628,8 +635,8 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
@Override
public JsonResult mothCount() {
//获取登录用户信息
//String username = SecurityUserUtils.username();
String username = "admin";
User userInfo = CurrentUserUtil.getUserInfo();
String username = userInfo.getUsername();
if(StringUtils.isEmpty(username)){
return JsonResult.error(WorkOrderEnum.USER_NAME_IS_NULL.getCode(),WorkOrderEnum.USER_NAME_IS_NULL.getMsg());
}

+ 82
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/utils/CurrentUserUtil.java View File

@@ -0,0 +1,82 @@
package com.tuoheng.miniprogram.utils;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.common.core.exception.ServiceException;
import com.tuoheng.miniprogram.dao.TenantMapper;
import com.tuoheng.miniprogram.dao.UserMapper;
import com.tuoheng.miniprogram.entity.Tenant;
import com.tuoheng.miniprogram.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Optional;

/**
* 直接从该工具类中获取当前登录用户信息
*/
@Component
public class CurrentUserUtil {

@Autowired
private UserMapper userMapper;

@Autowired
private TenantMapper tenantMapper;

private static CurrentUserUtil currentUserUtil;

@PostConstruct
public void init() {
currentUserUtil = this;
currentUserUtil.userMapper = this.userMapper;
currentUserUtil.tenantMapper = this.tenantMapper;
}

/**
* 私有构造器
**/
private CurrentUserUtil() {
}

/**
* 获取当前用户信息
*
* @return
*/
public static User getUserInfo() {
// String username = SecurityUserUtils.username();
String username = "admin";
User user = currentUserUtil.userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getMark, 1).eq(User::getStatus, 1).eq(User::getUsername, username));
if (null == user) {
Tenant tenant = currentUserUtil.tenantMapper.selectOne(Wrappers.<Tenant>lambdaQuery().eq(Tenant::getMark, 1).eq(Tenant::getStatus, 1).eq(Tenant::getUsername, username));
if (null == tenant) {
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "该用户并未创建");
}
}
return user;
}

/**
* 获取用户编号
*
* @return
*/
public static String getUserId() {
User user = getUserInfo();
return Optional.ofNullable(user.getId()).orElseThrow(() ->
new ServiceException(HttpStatus.BAD_REQUEST.value(), "未获取到当前用户信息!"));
}

/**
* 租户ID
*
* @return
*/
public static String getTenantId() {
User user = getUserInfo();
return Optional.ofNullable(user.getTenantId()).orElseThrow(() ->
new ServiceException(HttpStatus.BAD_REQUEST.value(), "未获取到当前租户信息!"));
}
}

Loading…
Cancel
Save