Commit 38797b99 authored by minminyan's avatar minminyan

合并master

parents babf69ae 1c3750ed
...@@ -19,6 +19,7 @@ import cn.quantgroup.xyqb.service.merchant.IMerchantService; ...@@ -19,6 +19,7 @@ import cn.quantgroup.xyqb.service.merchant.IMerchantService;
import cn.quantgroup.xyqb.service.session.ISessionService; import cn.quantgroup.xyqb.service.session.ISessionService;
import cn.quantgroup.xyqb.service.sms.ISmsService; import cn.quantgroup.xyqb.service.sms.ISmsService;
import cn.quantgroup.xyqb.service.user.*; import cn.quantgroup.xyqb.service.user.*;
import cn.quantgroup.xyqb.service.user.vo.UserDetailVO;
import cn.quantgroup.xyqb.service.wechat.IWechatService; import cn.quantgroup.xyqb.service.wechat.IWechatService;
import cn.quantgroup.xyqb.util.PasswordUtil; import cn.quantgroup.xyqb.util.PasswordUtil;
import cn.quantgroup.xyqb.util.ValidationUtil; import cn.quantgroup.xyqb.util.ValidationUtil;
...@@ -27,7 +28,6 @@ import com.fasterxml.jackson.core.type.TypeReference; ...@@ -27,7 +28,6 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.weibo.api.motan.config.springsupport.annotation.MotanService; import com.weibo.api.motan.config.springsupport.annotation.MotanService;
import java.util.concurrent.ThreadLocalRandom;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
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;
...@@ -140,6 +140,10 @@ public class MotanUserServiceImpl implements UserMotanService { ...@@ -140,6 +140,10 @@ public class MotanUserServiceImpl implements UserMotanService {
return userDetail == null ? null : userDetail.toXUserDetail(); return userDetail == null ? null : userDetail.toXUserDetail();
} }
private XUserDetail fromUserDetailVO(UserDetailVO userDetail) {
return userDetail == null ? null : userDetail.toXUserDetail();
}
private XUser fromUser(User user) { private XUser fromUser(User user) {
return user == null ? null : user.toXUser(); return user == null ? null : user.toXUser();
} }
...@@ -501,11 +505,11 @@ public class MotanUserServiceImpl implements UserMotanService { ...@@ -501,11 +505,11 @@ public class MotanUserServiceImpl implements UserMotanService {
@Override @Override
public UserSysResult<List<XUserDetail>> queryUserDetailBySpecification(String name, String phoneNo, String idNo) { public UserSysResult<List<XUserDetail>> queryUserDetailBySpecification(String name, String phoneNo, String idNo) {
List<UserDetail> userDetails = userDetailService.searchUserDetailList(name, phoneNo, idNo); List<UserDetailVO> userDetails = userDetailService.searchUserDetailList(name, phoneNo, idNo);
if (CollectionUtils.isEmpty(userDetails)) { if (CollectionUtils.isEmpty(userDetails)) {
return null; return null;
} }
List<XUserDetail> xUserDetails = userDetails.stream().map(user -> fromUserDetail(user)).collect(Collectors.toList()); List<XUserDetail> xUserDetails = userDetails.stream().map(user -> fromUserDetailVO(user)).collect(Collectors.toList());
return returnSuccessValue(xUserDetails); return returnSuccessValue(xUserDetails);
} }
......
...@@ -83,6 +83,9 @@ public class AppController implements IBaseController { ...@@ -83,6 +83,9 @@ public class AppController implements IBaseController {
if (user == null) { if (user == null) {
return JsonResult.buildErrorStateResult(USER_ERROR_OR_PASSWORD_ERROR, null); return JsonResult.buildErrorStateResult(USER_ERROR_OR_PASSWORD_ERROR, null);
} }
if (!user.getEnable()) {
return JsonResult.buildErrorStateResult("登录失败", null);
}
Merchant merchant = merchantService.findMerchantByName(key); Merchant merchant = merchantService.findMerchantByName(key);
if (merchant == null) { if (merchant == null) {
return JsonResult.buildErrorStateResult("无效的商户", null); return JsonResult.buildErrorStateResult("无效的商户", null);
...@@ -123,6 +126,9 @@ public class AppController implements IBaseController { ...@@ -123,6 +126,9 @@ public class AppController implements IBaseController {
if (user == null) { if (user == null) {
return JsonResult.buildErrorStateResult(USER_ERROR_OR_PASSWORD_ERROR, null); return JsonResult.buildErrorStateResult(USER_ERROR_OR_PASSWORD_ERROR, null);
} }
if (!user.getEnable()) {
return JsonResult.buildErrorStateResult("登录失败", null);
}
Merchant merchant = merchantService.findMerchantByName(key); Merchant merchant = merchantService.findMerchantByName(key);
if (merchant == null) { if (merchant == null) {
return JsonResult.buildErrorStateResult("无效的商户", null); return JsonResult.buildErrorStateResult("无效的商户", null);
......
...@@ -4,15 +4,17 @@ import cn.quantgroup.xyqb.entity.*; ...@@ -4,15 +4,17 @@ import cn.quantgroup.xyqb.entity.*;
import cn.quantgroup.xyqb.entity.enumerate.*; import cn.quantgroup.xyqb.entity.enumerate.*;
import cn.quantgroup.xyqb.model.*; import cn.quantgroup.xyqb.model.*;
import cn.quantgroup.xyqb.service.auth.IIdCardService; import cn.quantgroup.xyqb.service.auth.IIdCardService;
import cn.quantgroup.xyqb.service.session.ISessionService;
import cn.quantgroup.xyqb.service.user.*; import cn.quantgroup.xyqb.service.user.*;
import cn.quantgroup.xyqb.service.user.vo.UserDetailVO;
import cn.quantgroup.xyqb.service.wechat.IWechatService; import cn.quantgroup.xyqb.service.wechat.IWechatService;
import cn.quantgroup.xyqb.util.ValidationUtil; import cn.quantgroup.xyqb.util.ValidationUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -47,6 +49,8 @@ public class InnerController { ...@@ -47,6 +49,8 @@ public class InnerController {
private IWechatService wechatService; private IWechatService wechatService;
@Autowired @Autowired
private IUserSpouseService userSpouseService; private IUserSpouseService userSpouseService;
@Autowired
private ISessionService sessionService;
@RequestMapping("/user/search/phoneNo") @RequestMapping("/user/search/phoneNo")
public JsonResult findByPhoneNo(String phoneNo) { public JsonResult findByPhoneNo(String phoneNo) {
...@@ -101,6 +105,7 @@ public class InnerController { ...@@ -101,6 +105,7 @@ public class InnerController {
user.setUpdatedAt(new Timestamp(updatedAt)); user.setUpdatedAt(new Timestamp(updatedAt));
user.setEnable(true); user.setEnable(true);
user.setRegisteredFrom(registeredFrom); user.setRegisteredFrom(registeredFrom);
user.setUuid(uuid);
user.setPassword(password); user.setPassword(password);
user = userService.saveUser(user); user = userService.saveUser(user);
UserRet userRet = null; UserRet userRet = null;
...@@ -336,7 +341,10 @@ public class InnerController { ...@@ -336,7 +341,10 @@ public class InnerController {
@RequestMapping("/user_detail/search_list") @RequestMapping("/user_detail/search_list")
public JsonResult searchUserDetailList(String name, String phoneNo, String idNo) { public JsonResult searchUserDetailList(String name, String phoneNo, String idNo) {
List<UserDetail> userDetails = userDetailService.searchUserDetailList(name, phoneNo, idNo); if (StringUtils.isBlank(name) && StringUtils.isBlank(phoneNo) && StringUtils.isBlank(idNo)) {
return JsonResult.buildErrorStateResult("至少必须满足一个条件不为空", null);
}
List<UserDetailVO> userDetails = userDetailService.searchUserDetailList(name, phoneNo, idNo);
return JsonResult.buildSuccessResult("success", userDetails); return JsonResult.buildSuccessResult("success", userDetails);
} }
...@@ -376,6 +384,25 @@ public class InnerController { ...@@ -376,6 +384,25 @@ public class InnerController {
return JsonResult.buildSuccessResult(null, null == wechatUserInfo ? null : wechatUserInfo.getOpenId()); return JsonResult.buildSuccessResult(null, null == wechatUserInfo ? null : wechatUserInfo.getOpenId());
} }
@RequestMapping("/user/disable")
public JsonResult disableUser(Long userId) {
if (null == userId || 0L == userId) {
return JsonResult.buildErrorStateResult("userId不能为空", null);
}
User user = userService.findById(userId);
if (null == user) {
return JsonResult.buildErrorStateResult("未查询到该用户,用户id:" + userId, null);
}
user.setEnable(false);
user.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
LOGGER.info("注销用户的信息,userId={}", userId);
user = userService.saveUser(user);
if (!user.getEnable()) {
sessionService.deleteByUserId(userId);
}
return JsonResult.buildSuccessResult("用户已禁用.", user.getEnable() == false);
}
@RequestMapping("/user/spouse/save") @RequestMapping("/user/spouse/save")
public JsonResult saveSpouse(Long userId, MaritalStatus status, String spousePhone, String spouseName) { public JsonResult saveSpouse(Long userId, MaritalStatus status, String spousePhone, String spouseName) {
if (userId == null || userId == 0) { if (userId == null || userId == 0) {
......
...@@ -319,11 +319,8 @@ public class WeChatController implements IBaseController { ...@@ -319,11 +319,8 @@ public class WeChatController implements IBaseController {
LOGGER.error("发生异常", ex); LOGGER.error("发生异常", ex);
throw ex; throw ex;
} }
} }
/** /**
* 通过redirect_url获取code * 通过redirect_url获取code
* *
...@@ -382,7 +379,7 @@ public class WeChatController implements IBaseController { ...@@ -382,7 +379,7 @@ public class WeChatController implements IBaseController {
private String createUserSession(User user, Merchant merchant, String redirect, String schema, Long registerFrom) { private String createUserSession(User user, Merchant merchant, String redirect, String schema, Long registerFrom) {
//TODO 临时紧急上线修改的.下次上线的时候修复一下,不能这样写. //TODO 临时紧急上线修改的.下次上线的时候修复一下,不能这样写.
String url = "http://passport.xyqb.com"; String url = "http://passport.xyqb.com";
if ("https".equals(schema)) { if ("https:".equals(schema)) {
url = "https://passport.xyqb.com"; url = "https://passport.xyqb.com";
} }
if (StringUtils.isEmpty(redirect) || "redirect".equals(redirect)) { if (StringUtils.isEmpty(redirect) || "redirect".equals(redirect)) {
...@@ -399,11 +396,15 @@ public class WeChatController implements IBaseController { ...@@ -399,11 +396,15 @@ public class WeChatController implements IBaseController {
LOGGER.info("微信登录:redirect不为null,创建session跳到指定前端页面."); LOGGER.info("微信登录:redirect不为null,创建session跳到指定前端页面.");
AuthBean authBean = sessionService.createSession(Constants.Channel.WECHAT, Constants.Channel.WECHAT, "", user, merchant); AuthBean authBean = sessionService.createSession(Constants.Channel.WECHAT, Constants.Channel.WECHAT, "", user, merchant);
LOGGER.info("微信登录:跳转地址{}", url + "/weixin/callback?phoneNo=" + user.getPhoneNo() + "&token=" + authBean.getToken()); LOGGER.info("微信登录:跳转地址{}", url + "/weixin/callback?phoneNo=" + user.getPhoneNo() + "&token=" + authBean.getToken());
return url + "/weixin/callback?phoneNo=" + user.getPhoneNo() + "&token=" + authBean.getToken(); Long channelId = "baitiao".equals(merchant.getName()) ? 222L : 1L;
String target = "baitiao".equals(merchant.getName()) ? "cashTarget5" : "cashTarget4";
return url + "/landing?token=" + authBean.getToken() + "&registerFrom=" + registerFrom +
"&channelId=" + channelId + "&key=" + merchant.getName() + "&target=" + target + "&isWechat=true";
} }
return null; return null;
} }
private String loginInWechatWithSessionCreated(User user, Merchant merchant, String target, Long channelId, String url, Long registerFrom) { private String loginInWechatWithSessionCreated(User user, Merchant merchant, String target, Long channelId, String url, Long registerFrom) {
AuthBean authBean = sessionService.createSession(channelId, registerFrom, "", user, merchant); AuthBean authBean = sessionService.createSession(channelId, registerFrom, "", user, merchant);
return url + "/landing?token=" + authBean.getToken() + "&registerFrom=" + registerFrom + "&channelId=" + channelId + "&key=" + merchant.getName() + "&target=" + target; return url + "/landing?token=" + authBean.getToken() + "&registerFrom=" + registerFrom + "&channelId=" + channelId + "&key=" + merchant.getName() + "&target=" + target;
......
...@@ -43,19 +43,22 @@ public class UserController implements IBaseController { ...@@ -43,19 +43,22 @@ public class UserController implements IBaseController {
private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class); private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);
private static final char[] PWD_BASE = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
private final String pwdSalt = "_lkb"; private final String pwdSalt = "_lkb";
@Autowired @Autowired
private IUserService userService; private IUserService userService;
@Autowired @Autowired
@Qualifier("stringRedisTemplate") @Qualifier("stringRedisTemplate")
private RedisTemplate<String, String> stringRedisTemplate; private RedisTemplate<String, String> stringRedisTemplate;
@Autowired @Autowired
private ISmsService smsService; private ISmsService smsService;
@Autowired @Autowired
private ISessionService sessionService; private ISessionService sessionService;
@Autowired @Autowired
private IUserDetailService userDetailService; private IUserDetailService userDetailService;
@Autowired @Autowired
...@@ -63,6 +66,10 @@ public class UserController implements IBaseController { ...@@ -63,6 +66,10 @@ public class UserController implements IBaseController {
@Autowired @Autowired
private IWechatService wechatService; private IWechatService wechatService;
private static final char[] PWD_BASE = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
@RequestMapping("/login") @RequestMapping("/login")
public JsonResult login( public JsonResult login(
@RequestParam(required = false, defaultValue = "1") Long channelId, String appChannel, @RequestParam(required = false, defaultValue = "1") Long channelId, String appChannel,
...@@ -99,6 +106,9 @@ public class UserController implements IBaseController { ...@@ -99,6 +106,9 @@ public class UserController implements IBaseController {
JsonResult successResult = validMap.get("success"); JsonResult successResult = validMap.get("success");
String phoneNo = successResult.getData().toString(); String phoneNo = successResult.getData().toString();
User user = userService.findByPhoneWithCache(phoneNo); User user = userService.findByPhoneWithCache(phoneNo);
if (user != null && !user.getEnable()) {
return JsonResult.buildErrorStateResult("登录失败", null);
}
if (user == null) { if (user == null) {
user = registerFastWhenLogin(phoneNo, channelId, createdFrom, appChannel); user = registerFastWhenLogin(phoneNo, channelId, createdFrom, appChannel);
if (user == null) { if (user == null) {
...@@ -396,7 +406,7 @@ public class UserController implements IBaseController { ...@@ -396,7 +406,7 @@ public class UserController implements IBaseController {
String userName = credentialArr[0]; String userName = credentialArr[0];
String pass = credentialArr[1]; String pass = credentialArr[1];
User user = userService.findByPhoneWithCache(userName); User user = userService.findByPhoneWithCache(userName);
if (user == null) { if (user == null || !user.getEnable()) {
return null; return null;
} }
//验证密码 //验证密码
...@@ -414,7 +424,7 @@ public class UserController implements IBaseController { ...@@ -414,7 +424,7 @@ public class UserController implements IBaseController {
//查询用户,存在则保存用户session信息,userId为uuid //查询用户,存在则保存用户session信息,userId为uuid
User user = userService.findByUuidInDb(userId); User user = userService.findByUuidInDb(userId);
//用户信息存在,更新session中的最后访问时间,重新写入缓存. //用户信息存在,更新session中的最后访问时间,重新写入缓存.
if (null != user) { if (null != user || !user.getEnable()) {
return new JsonResult(sessionService.createSession(channelId, createdFrom, appChannel, user, merchant)); return new JsonResult(sessionService.createSession(channelId, createdFrom, appChannel, user, merchant));
} else { } else {
return JsonResult.buildErrorStateResult("登录失败", null); return JsonResult.buildErrorStateResult("登录失败", null);
......
...@@ -29,7 +29,8 @@ public class RequestFilter implements Filter { ...@@ -29,7 +29,8 @@ public class RequestFilter implements Filter {
"/innerapi/**", "/user/exist", "/motan/**", "/user/register", "/user/login", "/user/register/fast", "/innerapi/**", "/user/exist", "/motan/**", "/user/register", "/user/login", "/user/register/fast",
"/user/login/fast", "/user/reset_password", "/user/exist_check", "/user/login/fast", "/user/reset_password", "/user/exist_check",
"/jr58/**", "/app/login", "/app/login_super", "/wechat/**", "/config/**", "/api/**", "/user/exists_token", "/jr58/**", "/app/login", "/app/login_super", "/wechat/**", "/config/**", "/api/**", "/user/exists_token",
"/platform/api/page/return_url", "/MP_verify_AWiagUn4kZiwmTt0.txt" "/platform/api/page/return_url", "/MP_" +
"verify_AWiagUn4kZiwmTt0.txt"
}; };
private static final String UNAUTH_RESULT = JSONObject.toJSONString(JsonResult.buildErrorStateResult("登录失败", null)); private static final String UNAUTH_RESULT = JSONObject.toJSONString(JsonResult.buildErrorStateResult("登录失败", null));
@Autowired @Autowired
......
...@@ -2,11 +2,12 @@ package cn.quantgroup.xyqb.repository; ...@@ -2,11 +2,12 @@ package cn.quantgroup.xyqb.repository;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/** /**
* Created by Miraculous on 15/7/4. * Created by Miraculous on 15/7/4.
*/ */
public interface IUserRepository extends JpaRepository<User, Long> { public interface IUserRepository extends JpaRepository<User, Long> ,JpaSpecificationExecutor<User>{
User findByPhoneNo(String phoneNo); User findByPhoneNo(String phoneNo);
......
...@@ -26,4 +26,6 @@ public interface ISessionService { ...@@ -26,4 +26,6 @@ public interface ISessionService {
void persistSession(String token, SessionValue sessionValue); void persistSession(String token, SessionValue sessionValue);
SessionStruct findSessionBySessionId(String sessionId); SessionStruct findSessionBySessionId(String sessionId);
void deleteByUserId(long userId);
} }
...@@ -9,16 +9,19 @@ import cn.quantgroup.xyqb.model.session.SessionStruct; ...@@ -9,16 +9,19 @@ import cn.quantgroup.xyqb.model.session.SessionStruct;
import cn.quantgroup.xyqb.model.session.SessionValue; import cn.quantgroup.xyqb.model.session.SessionValue;
import cn.quantgroup.xyqb.service.session.ISessionService; import cn.quantgroup.xyqb.service.session.ISessionService;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.google.common.base.Joiner;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -149,5 +152,15 @@ public class SessionServiceImpl implements ISessionService { ...@@ -149,5 +152,15 @@ public class SessionServiceImpl implements ISessionService {
} }
@Override
public void deleteByUserId(long userId) {
String pattern = Constants.Session.USER_SESSION_ID_CACHE + ":" + String.valueOf(userId) + ":*";
Set<String> keys = stringRedisTemplate.keys(pattern);
if (!CollectionUtils.isEmpty(keys)) {
log.info("删除用户userId={}的缓存信息,个数:{},keys={}", userId,
keys.size(),
Joiner.on(",").join(keys));
}
stringRedisTemplate.delete(keys);
}
} }
package cn.quantgroup.xyqb.service.user; package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.UserDetail; import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.service.user.vo.UserDetailVO;
import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataIntegrityViolationException;
import java.util.List; import java.util.List;
...@@ -17,5 +18,5 @@ public interface IUserDetailService { ...@@ -17,5 +18,5 @@ public interface IUserDetailService {
void updateUserQQ(Long userId, String qq); void updateUserQQ(Long userId, String qq);
List<UserDetail> searchUserDetailList(String name, String phoneNo, String idNo); List<UserDetailVO> searchUserDetailList(String name, String phoneNo, String idNo);
} }
...@@ -65,6 +65,7 @@ public class LkbUserviceImpl implements ILkbUserService { ...@@ -65,6 +65,7 @@ public class LkbUserviceImpl implements ILkbUserService {
LOGGER.warn("向LKB注册用户失败, phoneNo:{}, password:{}", phoneNo, password); LOGGER.warn("向LKB注册用户失败, phoneNo:{}, password:{}", phoneNo, password);
return ""; return "";
} }
//String uid = java.util.UUID.randomUUID().toString().replace("-","");
return result.get("uid"); return result.get("uid");
} }
......
package cn.quantgroup.xyqb.service.user.impl; package cn.quantgroup.xyqb.service.user.impl;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail; import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.repository.IUserDetailRepository; import cn.quantgroup.xyqb.repository.IUserDetailRepository;
import cn.quantgroup.xyqb.repository.IUserRepository;
import cn.quantgroup.xyqb.service.user.IUserDetailService; import cn.quantgroup.xyqb.service.user.IUserDetailService;
import cn.quantgroup.xyqb.service.user.vo.UserDetailVO;
import com.google.common.collect.Maps;
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.dao.DataIntegrityViolationException; import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
...@@ -15,6 +20,8 @@ import javax.persistence.criteria.Predicate; ...@@ -15,6 +20,8 @@ import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* Created by 11 on 2016/12/29. * Created by 11 on 2016/12/29.
...@@ -24,6 +31,8 @@ public class UserDetailServiceImpl implements IUserDetailService { ...@@ -24,6 +31,8 @@ public class UserDetailServiceImpl implements IUserDetailService {
@Autowired @Autowired
private IUserDetailRepository userDetailRepository; private IUserDetailRepository userDetailRepository;
@Autowired
private IUserRepository userRepository;
@Override @Override
public UserDetail findByUserId(Long userId) { public UserDetail findByUserId(Long userId) {
...@@ -46,8 +55,20 @@ public class UserDetailServiceImpl implements IUserDetailService { ...@@ -46,8 +55,20 @@ public class UserDetailServiceImpl implements IUserDetailService {
} }
@Override @Override
public List<UserDetail> searchUserDetailList(String name, String phoneNo, String idNo) { public List<UserDetailVO> searchUserDetailList(String name, String phoneNo, String idNo) {
return userDetailRepository.findAll(getSpecification(name, phoneNo, idNo)); List<UserDetail> details = userDetailRepository.findAll(getSpecification(name, phoneNo, idNo));
Map<Long, User> userMap = Maps.newHashMap();
if (!CollectionUtils.isEmpty(details)) {
List<Long> userIds = details.stream().map(d -> d.getUserId()).collect(Collectors.toList());
List<User> users = userRepository.findAll((root, query, cb) -> {
query.where(root.get("id").in(userIds));
return query.getRestriction();
});
userMap = users.stream().collect(Collectors.toMap(User::getId, o -> o));
}
Map<Long, User> finalUserMap = userMap;
List<UserDetailVO> userDetailVOS = details.stream().map(o -> fromUserDetailAndUserMap(o, finalUserMap)).collect(Collectors.toList());
return userDetailVOS;
} }
private Specification<UserDetail> getSpecification(String name, String phoneNo, String idNo) { private Specification<UserDetail> getSpecification(String name, String phoneNo, String idNo) {
...@@ -70,4 +91,13 @@ public class UserDetailServiceImpl implements IUserDetailService { ...@@ -70,4 +91,13 @@ public class UserDetailServiceImpl implements IUserDetailService {
}; };
return specification; return specification;
} }
private UserDetailVO fromUserDetailAndUserMap(UserDetail userDetail, Map<Long, User> userMap) {
UserDetailVO userDetailVO = UserDetailVO.fromUserDetail(userDetail);
User user = userMap.get(userDetail.getUserId());
if (user != null) {
userDetailVO.setEnable(user.getEnable());
}
return userDetailVO;
}
} }
...@@ -47,6 +47,7 @@ public class UserServiceImpl implements IUserService { ...@@ -47,6 +47,7 @@ public class UserServiceImpl implements IUserService {
} }
@Override @Override
@CacheEvict(value = "usercache", key = "'xyqbuser' + #user.phoneNo", cacheManager = "cacheManager")
public User saveUser(User user) { public User saveUser(User user) {
return userRepository.save(user); return userRepository.save(user);
} }
......
package cn.quantgroup.xyqb.service.user.vo;
import cn.quantgroup.motan.retbean.XUserDetail;
import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.model.Gender;
import cn.quantgroup.xyqb.model.IdType;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.sql.Timestamp;
@Data
@NoArgsConstructor
public class UserDetailVO {
private Long id;
private Long userId;
private String phoneNo;
private String name;
private String idNo;
private IdType idType;
private Boolean isAuthenticated = false;
private Gender gender;
private String email;
private String qq;
private Boolean enable;
private Long createdAt;
private Long updatedAt;
public static UserDetailVO fromUserDetail(UserDetail userDetail) {
UserDetailVO userDetailVO = new UserDetailVO();
userDetailVO.id = userDetail.getId();
userDetailVO.userId = userDetail.getUserId();
userDetailVO.phoneNo = userDetail.getPhoneNo();
userDetailVO.name = userDetail.getName();
userDetailVO.idNo = userDetail.getIdNo();
userDetailVO.idType = userDetail.getIdType();
userDetailVO.isAuthenticated = userDetail.getIsAuthenticated();
userDetailVO.gender = userDetail.getGender();
userDetailVO.email = userDetail.getEmail();
userDetailVO.qq = userDetail.getQq();
if (userDetail.getCreatedAt() != null) {
userDetailVO.createdAt = userDetail.getCreatedAt().getTime();
}
if (userDetail.getUpdatedAt() != null) {
userDetailVO.updatedAt = userDetail.getUpdatedAt().getTime();
}
return userDetailVO;
}
public XUserDetail toXUserDetail() {
XUserDetail xUserDetail = new XUserDetail();
xUserDetail.setId(this.getId());
xUserDetail.setUserId(this.getUserId());
xUserDetail.setPhoneNo(this.getPhoneNo());
xUserDetail.setName(this.getName());
xUserDetail.setIdNo(this.getIdNo());
if (this.getIdType() != null) {
xUserDetail.setIdType(cn.quantgroup.motan.enums.IdType.valueOf(this.getIdType().name()));
}
if (this.getGender() != null) {
xUserDetail.setGender(cn.quantgroup.motan.enums.Gender.valueOf(this.getGender().name()));
}
xUserDetail.setEmail(this.getEmail());
xUserDetail.setQq(this.getQq());
xUserDetail.setId(this.getId());
if (this.getCreatedAt() != null) {
xUserDetail.setCreatedAt(new Timestamp(this.getCreatedAt()));
}
if (this.getUpdatedAt() != null) {
xUserDetail.setUpdatedAt(new Timestamp(this.getUpdatedAt()));
}
xUserDetail.setIsAuthenticated(this.getIsAuthenticated());
xUserDetail.setEnable(this.getEnable());
return xUserDetail;
}
}
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