Commit 5105394e authored by minminyan's avatar minminyan

合并代码

parents dfe94022 32f74a41
......@@ -25,6 +25,7 @@ import java.sql.Timestamp;
import java.text.ParseException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* Created by Miraculous on 2016/12/19.
......@@ -74,6 +75,18 @@ public class InnerController implements IBaseController {
return JsonResult.buildSuccessResult("", userRet);
}
@RequestMapping("/user/getPhoneByUserIds")
public JsonResult findByIds(@RequestParam(value = "userIds") String userIdsString) {
LOGGER.info("批量查询用户的手机号列表, userIdsString:" + userIdsString);
if (StringUtils.isEmpty(userIdsString)) {
return JsonResult.buildErrorStateResult(null, null);
}
List<Long> userIds = JSONObject.parseObject(userIdsString, new TypeReference<List<Long>>() {
});
Map<Long, String> userIdAndPhoneMap = userService.findPhoneByIdsInDb(userIds);
return JsonResult.buildSuccessResult("", userIdAndPhoneMap);
}
@RequestMapping("/user/save")
public JsonResult saveUser(
String phoneNo, Long registeredFrom, Long createdAt, Long updatedAt,
......
......@@ -4,14 +4,18 @@ import cn.quantgroup.xyqb.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List;
/**
* Created by Miraculous on 15/7/4.
*/
public interface IUserRepository extends JpaRepository<User, Long> ,JpaSpecificationExecutor<User>{
public interface IUserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
User findByPhoneNo(String phoneNo);
User findByUuid(String uuid);
List<User> findByIdIn(List<Long> ids);
User findById(Long id);
}
......@@ -2,6 +2,9 @@ package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.User;
import java.util.List;
import java.util.Map;
/**
* Created by Miraculous on 15/7/5.
*/
......@@ -23,6 +26,8 @@ public interface IUserService {
User findByUuidInDb(String uuid);
Map<Long, String> findPhoneByIdsInDb(List<Long> userIds);
User saveUser(User user);
User findById(Long userId);
......
......@@ -7,21 +7,27 @@ import cn.quantgroup.xyqb.service.sms.ISmsService;
import cn.quantgroup.xyqb.service.user.ILkbUserService;
import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.util.PasswordUtil;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.transaction.Transactional;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* Created by Miraculous on 15/7/5.
*/
@Service
@Slf4j
public class UserServiceImpl implements IUserService {
@Autowired
......@@ -41,6 +47,31 @@ public class UserServiceImpl implements IUserService {
return userRepository.findByPhoneNo(phone);
}
@Override
public Map<Long, String> findPhoneByIdsInDb(List<Long> userIds) {
if (CollectionUtils.isEmpty(userIds)) {
return Maps.newHashMap();
}
Map<Long, String> userIdAndPhoneMap = Maps.newHashMap();
int pageSize = 1000;
int idSize = userIds.size();
for (int i = 0; i < idSize; i += pageSize) {
List<Long> subList = userIds.subList(i, Math.min(idSize, i + pageSize));
List<User> users = userRepository.findByIdIn(subList);
users.stream().forEach(user -> {
userIdAndPhoneMap.put(user.getId(), user.getPhoneNo());
});
if (i + pageSize < idSize) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
log.error("线程sleep失败", e);
}
}
}
return userIdAndPhoneMap;
}
@Override
public User findByUuidInDb(String uuid) {
return userRepository.findByUuid(uuid);
......
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