Commit 56f8f7ed authored by guangjing.gao's avatar guangjing.gao

批量userIds获取单个用户/批量用户

parent eb095ae9
package cn.quantgroup.xyqb.controller.internal.user.center; package cn.quantgroup.xyqb.controller.internal.user.center;
import cn.quantgroup.user.enums.BizType; import cn.quantgroup.user.enums.*;
import cn.quantgroup.user.enums.EducationEnum;
import cn.quantgroup.user.enums.IncomeRangeEnum;
import cn.quantgroup.user.enums.MaritalStatus;
import cn.quantgroup.user.enums.OccupationEnum;
import cn.quantgroup.xyqb.Constants; import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.aspect.limit.PasswordFreeAccessValidator; import cn.quantgroup.xyqb.aspect.limit.PasswordFreeAccessValidator;
import cn.quantgroup.xyqb.aspect.lock.RedisLock; import cn.quantgroup.xyqb.aspect.lock.RedisLock;
import cn.quantgroup.xyqb.entity.Address; import cn.quantgroup.xyqb.entity.*;
import cn.quantgroup.xyqb.entity.Contact;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserAttached;
import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.entity.UserExtInfo;
import cn.quantgroup.xyqb.event.UserExtInfoSaveEvent; import cn.quantgroup.xyqb.event.UserExtInfoSaveEvent;
import cn.quantgroup.xyqb.model.JsonResult; import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.user.IAddressService; import cn.quantgroup.xyqb.service.user.*;
import cn.quantgroup.xyqb.service.user.IContactService;
import cn.quantgroup.xyqb.service.user.IUserDetailService;
import cn.quantgroup.xyqb.service.user.IUserExtInfoService;
import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.service.user.UserCenterService;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -30,13 +16,8 @@ import org.apache.commons.collections.CollectionUtils; ...@@ -30,13 +16,8 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.sql.Timestamp;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -73,8 +54,13 @@ public class UserCenterController { ...@@ -73,8 +54,13 @@ public class UserCenterController {
return JsonResult.buildSuccessResultGeneric(userAttached); return JsonResult.buildSuccessResultGeneric(userAttached);
} }
/**
* @yapi http://yapi.quantgroups.com/project/17/interface/api/17291
* @param userIds
* @return
*/
@PostMapping("/attach/list") @PostMapping("/attach/list")
public JsonResult queryUserAttachList(@RequestBody List<Long> userIds) { public JsonResult queryUserAttachList(@RequestBody List<Long> userIds, @RequestParam(required = false) Integer tenantId) {
if (CollectionUtils.isEmpty(userIds)) { if (CollectionUtils.isEmpty(userIds)) {
return JsonResult.buildErrorStateResult("用户 ID 不能为空", null); return JsonResult.buildErrorStateResult("用户 ID 不能为空", null);
} }
...@@ -82,7 +68,7 @@ public class UserCenterController { ...@@ -82,7 +68,7 @@ public class UserCenterController {
if (userIds.size() > size) { if (userIds.size() > size) {
return JsonResult.buildErrorStateResult("超出最大条数限制" + size, null); return JsonResult.buildErrorStateResult("超出最大条数限制" + size, null);
} }
List<UserAttached> userAttachedList = userCenterService.searchUserAttachedListByUserId(userIds); List<UserAttached> userAttachedList = userCenterService.searchUserAttachedListByUserId(userIds, tenantId);
return JsonResult.buildSuccessResultGeneric(userAttachedList); return JsonResult.buildSuccessResultGeneric(userAttachedList);
} }
......
...@@ -21,7 +21,7 @@ public interface UserCenterService { ...@@ -21,7 +21,7 @@ public interface UserCenterService {
* @param userIds * @param userIds
* @return * @return
*/ */
List<UserAttached> searchUserAttachedListByUserId(List<Long> userIds); List<UserAttached> searchUserAttachedListByUserId(List<Long> userIds, Integer tenantId);
/** /**
* 保存用户头像 * 保存用户头像
......
...@@ -2,19 +2,22 @@ package cn.quantgroup.xyqb.service.user.impl; ...@@ -2,19 +2,22 @@ package cn.quantgroup.xyqb.service.user.impl;
import cn.quantgroup.tech.db.DSType; import cn.quantgroup.tech.db.DSType;
import cn.quantgroup.tech.db.TargetDataSource; import cn.quantgroup.tech.db.TargetDataSource;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserAttached; import cn.quantgroup.xyqb.entity.UserAttached;
import cn.quantgroup.xyqb.repository.IUserAttachedRepository; import cn.quantgroup.xyqb.repository.IUserAttachedRepository;
import cn.quantgroup.xyqb.repository.IUserRepository;
import cn.quantgroup.xyqb.service.user.ITenantService;
import cn.quantgroup.xyqb.service.user.UserCenterService; import cn.quantgroup.xyqb.service.user.UserCenterService;
import cn.quantgroup.xyqb.util.EmojiUtil; import cn.quantgroup.xyqb.util.EmojiUtil;
import cn.quantgroup.xyqb.util.TenantUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.hibernate.exception.ConstraintViolationException; import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.sql.Timestamp; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
...@@ -29,6 +32,12 @@ public class UserCenterServiceImpl implements UserCenterService { ...@@ -29,6 +32,12 @@ public class UserCenterServiceImpl implements UserCenterService {
@Autowired @Autowired
private IUserAttachedRepository userAttachedRepository; private IUserAttachedRepository userAttachedRepository;
@Autowired
private IUserRepository userRepository;
@Autowired
private ITenantService tenantService;
@Override @Override
@TargetDataSource(type = DSType.SLAVE)//查询从库 @TargetDataSource(type = DSType.SLAVE)//查询从库
// @Cacheable(value = "userAttachedCache", key = "'xyqbUserAttached' + #userId", unless = "#result == null", cacheManager = "cacheManager") // @Cacheable(value = "userAttachedCache", key = "'xyqbUserAttached' + #userId", unless = "#result == null", cacheManager = "cacheManager")
...@@ -37,8 +46,28 @@ public class UserCenterServiceImpl implements UserCenterService { ...@@ -37,8 +46,28 @@ public class UserCenterServiceImpl implements UserCenterService {
} }
@Override @Override
public List<UserAttached> searchUserAttachedListByUserId(List<Long> userIds) { public List<UserAttached> searchUserAttachedListByUserId(List<Long> userIds, Integer tenantId) {
return userAttachedRepository.findByUserIdIn(userIds);
List<UserAttached> userAttacheds = userAttachedRepository.findByUserIdIn(userIds);
if (userAttacheds != null) {
//租户ID校验
if (TenantUtil.checkoutTenantIsDefault(tenantId)) {
List<UserAttached> resultProductUsers = new ArrayList<>();
List<User> users = userRepository.findByIdIn(userIds);
List<User> productUsers = tenantService.selectUsersByTenantId(users, tenantId);
if (productUsers != null) {
userAttacheds.forEach(a->{
productUsers.forEach(b->{
if (a.getUserId().equals(b.getId())) {
resultProductUsers.add(a);
}
});
});
}
return resultProductUsers;
}
}
return userAttacheds;
} }
@Override @Override
......
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