Commit 2e49972b authored by 王亮's avatar 王亮

Feature temp 20230615

parent 5b8ef268
......@@ -46,11 +46,6 @@
<artifactId>SensorsAnalyticsSDK</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
......@@ -224,11 +219,7 @@
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
......@@ -306,11 +297,6 @@
<artifactId>sentry-spring</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
<version>0.0.20131108.vaadin1</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
......@@ -327,8 +313,8 @@
<version>2.1.0</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
</exclusion>
</exclusions>
</dependency>
......@@ -353,6 +339,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.9.3</version>
</dependency>
</dependencies>
<build>
......
package cn.quantgroup.xyqb.config.mq;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
/**
* //马甲包 xuran
*/
@Primary
@Configuration
public class LoanVestMqConfig {
@Value("${loanvest.rabbitmq.queue}")
private String queueName;
@Value("${loanvest.rabbitmq.exchange}")
private String loanVestExchange;
@Value("${loanvest.rabbitmq.connection.host}")
private String host;
@Value("${loanvest.rabbitmq.connection.port}")
private Integer port;
@Value("${loanvest.rabbitmq.connection.user}")
private String user;
@Value("${loanvest.rabbitmq.connection.password}")
private String password;
@Value("${loanvest.rabbitmq.connection.virtual-host}")
private String virtualHost;
@Primary
@Bean(name = "vestFactory")
public ConnectionFactory vestFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);
connectionFactory.setChannelCacheSize(1024);
connectionFactory.setCacheMode(CachingConnectionFactory.CacheMode.CONNECTION);
connectionFactory.setChannelCacheSize(180 * 1000);
connectionFactory.setConnectionCacheSize(1024);
connectionFactory.setUsername(user);
connectionFactory.setPassword(password);
connectionFactory.setVirtualHost(virtualHost);
connectionFactory.setPublisherReturns(false);
connectionFactory.setPublisherConfirms(false);
return connectionFactory;
}
@Primary
@Bean(name = "loanVestAmqpAdmin")
public AmqpAdmin loanVestAdmin(@Qualifier("vestFactory") ConnectionFactory vestFactory) {
return new RabbitAdmin(vestFactory);
}
@Primary
@Bean(name = "loanVestExchange")
public FanoutExchange loanVestExchange() {
return new FanoutExchange(loanVestExchange);
}
@Primary
@Bean(name = "loanVestQueue")
public Queue loanVestQueue() {
return new Queue(queueName);
}
@Primary
@Bean(name = "loanVestBinding")
public Binding bindingLoanVest(@Qualifier("loanVestAmqpAdmin") AmqpAdmin loanVestAdmin, @Qualifier("loanVestQueue") Queue loanVestQueue, @Qualifier("loanVestExchange") FanoutExchange loanVestExchange) {
Binding binding = BindingBuilder.bind(loanVestQueue).to(loanVestExchange);
loanVestAdmin.declareBinding(binding);
return binding;
}
@Primary
@Bean(name = "rabbitTemplate")
public RabbitTemplate loanVestTemplate(@Qualifier("vestFactory") ConnectionFactory vestFactory) {
RabbitTemplate template = new RabbitTemplate(vestFactory);
template.setExchange(loanVestExchange);
return template;
}
}
......@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import java.util.HashMap;
import java.util.Map;
......@@ -42,6 +43,89 @@ public class RegisterMqConfig {
@Value("${register.rabbitmq.connection.virtual-host}")
private String virtualHost;
@Value("${registered.notify.black.hole.rabbitmq.connection.virtual-host}")
private String BlackVirtualHost;
@Value("${loanvest.rabbitmq.connection.virtual-host}")
private String loanVirtualHost;
@Value("${loanvest.rabbitmq.exchange}")
private String loanVestExchange;
@Value("${loanvest.rabbitmq.queue}")
private String loanQueueName;
@Primary
@Bean(name = "loanVestQueue")
public Queue loanVestQueue() {
return new Queue(loanQueueName);
}
@Primary
@Bean(name = "loanVestBinding")
public Binding bindingLoanVest(@Qualifier("loanVestAmqpAdmin") AmqpAdmin loanVestAdmin, @Qualifier("loanVestQueue") Queue loanVestQueue, @Qualifier("loanVestExchange") FanoutExchange loanVestExchange) {
Binding binding = BindingBuilder.bind(loanVestQueue).to(loanVestExchange);
loanVestAdmin.declareBinding(binding);
return binding;
}
@Primary
@Bean(name = "rabbitTemplate")
public RabbitTemplate loanVestTemplate(@Qualifier("vestFactory") ConnectionFactory vestFactory) {
RabbitTemplate template = new RabbitTemplate(vestFactory);
template.setExchange(loanVestExchange);
return template;
}
@Primary
@Bean(name = "loanVestAmqpAdmin")
public AmqpAdmin loanVestAdmin(@Qualifier("vestFactory") ConnectionFactory vestFactory) {
return new RabbitAdmin(vestFactory);
}
@Primary
@Bean(name = "loanVestExchange")
public FanoutExchange loanVestExchange() {
return new FanoutExchange(loanVestExchange);
}
@Primary
@Bean(name = "vestFactory")
public ConnectionFactory vestFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);
connectionFactory.setChannelCacheSize(1024);
connectionFactory.setCacheMode(CachingConnectionFactory.CacheMode.CONNECTION);
connectionFactory.setChannelCacheSize(180 * 1000);
connectionFactory.setConnectionCacheSize(1024);
connectionFactory.setUsername(user);
connectionFactory.setPassword(password);
connectionFactory.setVirtualHost(loanVirtualHost);
connectionFactory.setPublisherReturns(false);
connectionFactory.setPublisherConfirms(false);
return connectionFactory;
}
@Bean(name = "registeredNotifyBlackHoleFactory")
public ConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);
connectionFactory.setChannelCacheSize(1024);
connectionFactory.setCacheMode(CachingConnectionFactory.CacheMode.CONNECTION);
connectionFactory.setChannelCacheSize(180 * 1000);
connectionFactory.setConnectionCacheSize(1024);
connectionFactory.setUsername(user);
connectionFactory.setPassword(password);
connectionFactory.setVirtualHost(BlackVirtualHost);
connectionFactory.setPublisherReturns(true);
connectionFactory.setPublisherConfirms(true);
return connectionFactory;
}
@Bean(name = "registeredNotifyBlackHoleRabbitTemplate")
public RabbitTemplate registeredNotifyBlackHoleRabbitTemplate(@Qualifier("registeredNotifyBlackHoleFactory") ConnectionFactory connectionFactory) {
return new RabbitTemplate(connectionFactory);
}
@Bean(name = "registerMqFactory")
public ConnectionFactory registerMqFactory() {
......@@ -138,7 +222,6 @@ public class RegisterMqConfig {
queueArgs.put("x-message-ttl", 24 * 60 * 60 * 1000);
Queue wechatBind = new Queue(queueName, true, false, false, queueArgs);
rabbitAdmin.declareQueue(wechatBind);
// rabbitTemplate.setQueue(queueName);
rabbitTemplate.setRoutingKey(queueName);
return rabbitTemplate;
}
......
package cn.quantgroup.xyqb.config.mq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Date: 2020/1/15
* Time: 下午2:20
*
* @author: yangrui
*/
@Slf4j
@Configuration
public class RegisteredNotifyBlackHoleMqConfig {
@Value("${rabbitmq.connection.host}")
private String host;
@Value("${rabbitmq.connection.port}")
private Integer port;
@Value("${rabbitmq.connection.user}")
private String user;
@Value("${rabbitmq.connection.password}")
private String password;
@Value("${registered.notify.black.hole.rabbitmq.connection.virtual-host}")
private String virtualHost;
@Bean(name = "registeredNotifyBlackHoleFactory")
public ConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);
connectionFactory.setChannelCacheSize(1024);
connectionFactory.setCacheMode(CachingConnectionFactory.CacheMode.CONNECTION);
connectionFactory.setChannelCacheSize(180 * 1000);
connectionFactory.setConnectionCacheSize(1024);
connectionFactory.setUsername(user);
connectionFactory.setPassword(password);
connectionFactory.setVirtualHost(virtualHost);
connectionFactory.setPublisherReturns(true);
connectionFactory.setPublisherConfirms(true);
return connectionFactory;
}
@Bean(name = "registeredNotifyBlackHoleRabbitTemplate")
public RabbitTemplate rabbitTemplate(@Qualifier("registeredNotifyBlackHoleFactory") ConnectionFactory connectionFactory) {
RabbitTemplate template = new RabbitTemplate(connectionFactory);
return template;
}
}
......@@ -681,7 +681,7 @@ public class UserController implements IBaseController {
String token = request.getHeader("x-auth-token");
if (null == token || "".equals(token)) {
if (org.apache.commons.lang3.StringUtils.isEmpty(token)) {
return JsonResult.buildErrorStateResult("服务器异常,请稍后再试", null);
}
......@@ -905,7 +905,7 @@ public class UserController implements IBaseController {
@RequestMapping(value = "/kdsp/loginRecord", method = RequestMethod.POST)
public JsonResult loginRecord(@RequestParam(required = true) String deviceId) {
if (null == deviceId || "".equals(deviceId)) {
if (org.apache.commons.lang3.StringUtils.isEmpty(deviceId)) {
return JsonResult.buildErrorStateResult("请传入正确的设备ID", null);
}
......
package cn.quantgroup.xyqb.controller.external;
import cn.quantgroup.xyqb.controller.IBaseController;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.model.IdCardInfo;
import cn.quantgroup.xyqb.model.IdType;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.auth.IIdCardService;
import cn.quantgroup.xyqb.service.user.IUserDetailService;
import cn.quantgroup.xyqb.util.ValidationUtil;
import cn.quantgroup.xyqb.validator.ChineseName;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Objects;
/**
* Created by Miraculous on 2017/1/3.
*/
@Slf4j
@RestController
@RequestMapping("/user_detail")
@Validated
public class UserDetailController implements IBaseController {
@Autowired
private IUserDetailService userDetailService;
@Autowired
private IIdCardService idCardService;
/**
* 保存/更新用户实名信息
* 注:
* 本接口会验证用户登录状态,仅用于用户个人补全实名信息操作
* 产品逻辑是不允许用户重复设置实名信息的,但历史存在导流数据创建不完整实名信息的场景(可理解为和渠道有关)
* 故此本处保留修改逻辑,仍依赖业务端控制产品行为
*
* @param idNo
* @param name
* @return
* @yapi unknown
* @Deprecated 20210318
* @see cn.quantgroup.xyqb.controller.internal.user.InnerController#saveUserDetail(Long, String, String, String, String, String)
*/
@Deprecated
@RequestMapping("/save")
public JsonResult saveUserDetail(String idNo,
@ChineseName @RequestParam String name) {
if (!ValidationUtil.validateChinese(name)) {
log.error("姓名错误,name:{}", name);
return JsonResult.buildErrorStateResult("姓名错误", null);
}
User user = getCurrentUserFromRedis();
if (user == null) {
return JsonResult.buildErrorStateResult("系统错误", null);
}
IdCardInfo info = idCardService.getIdCardInfo(idNo);
if (info == null || !info.isValid()) {
log.error("身份证号错误,userId:{}, idNo: {}", user.getId(), idNo);
return JsonResult.buildErrorStateResult("身份证号码错误", null);
}
/* 保存或更新 */
UserDetail userDetail = userDetailService.findByUserId(user.getId());
if (Objects.isNull(userDetail)) {
userDetail = new UserDetail();
}
userDetail.setPhoneNo(user.getPhoneNo());
userDetail.setUserId(user.getId());
userDetail.setName(name);
userDetail.setGender(info.getGender());
userDetail.setIsAuthenticated(false);
log.info("UserDetailController saveUserDetail, userId:{}, phoneNo:{}, name:{}", user.getId(), user.getPhoneNo(), name);
try {
userDetailService.saveUserDetail(userDetail);
} catch (DataIntegrityViolationException ex) {
return JsonResult.buildSuccessResult("", null);
}
return JsonResult.buildSuccessResult("", null);
}
}
......@@ -15,6 +15,7 @@ import cn.quantgroup.xyqb.util.IdcardValidator;
import cn.quantgroup.xyqb.util.ValidationUtil;
import cn.quantgroup.xyqb.util.encrypt.Md5Util;
import cn.quantgroup.xyqb.util.encrypt.Rsa;
import com.alibaba.fastjson.JSON;
import com.google.gson.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*;
......@@ -206,7 +207,7 @@ public class UserQueryLogController {
HashMap<String, Object> ha = new HashMap<>();
ha.put("type", "1");
ha.put("phones", phoneNos);
String phoneNoStr = new Gson().toJson(ha);
String phoneNoStr = JSON.toJSONString(ha);
String data = "";
String sign = "";
......
......@@ -162,7 +162,7 @@ public class AppController implements IBaseController {
log.info("第三方用户登录 [AppController] login --> loginFrom:{},channelId:{},btRegisterChannelId:{} requestIp:{},idNo:{},name:{}", registerFrom, channelId, btRegisterChannelId, IpUtil.getRemoteIP(request), idNo, name);
User user = userService.findByPhoneInDb(phoneNo);
if (user == null) {
user = userRegisterService.register(registerFrom, phoneNo, idNo, name, channelId, btRegisterChannelId);
user = userRegisterService.register(registerFrom, phoneNo, name, channelId, btRegisterChannelId);
}
if (user == null) {
return JsonResult.buildErrorStateResult(USER_ERROR_OR_PASSWORD_ERROR, null);
......@@ -222,7 +222,7 @@ public class AppController implements IBaseController {
boolean isRegister=false;
if (user == null) {
try {
user = userRegisterService.register(registerFrom, phoneNo, idNo, name, channelId, btRegisterChannelId);
user = userRegisterService.register(registerFrom, phoneNo, name, channelId, btRegisterChannelId);
isRegister=true;
} catch (PersistenceException e) {
user = userService.findByPhoneInDb(phoneNo);
......@@ -349,26 +349,4 @@ public class AppController implements IBaseController {
return JsonResult.buildSuccessResult("登录成功", bean);
}
// @RequestMapping("/login33")
// public JsonResult login233() {
// User user = new User();
// user.setUuid("3213213321");
// user.setRegisteredFrom(221L);
// try {
// EventRecord userRecord = EventRecord.builder().setDistinctId(user.getUuid()).isLoginId(Boolean.TRUE)
// .setEventName("PD_WUXIEC_UserLoginVccCash")
// .addProperty("son_channel_id", user.getRegisteredFrom())
// .addProperty("parent_channel_id",-1L)
// .addProperty("vcc_uuid", user.getUuid())
// .build();
// iSensorsAnalytics.track(userRecord);
// iSensorsAnalytics.flush();
// log.info("神策上报成功");
// } catch (Exception e) {
// log.info("神策埋点出现问题", e);
// }
// return JsonResult.buildSuccessResult("登录成功", null);
//
// }
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,11 +3,8 @@ package cn.quantgroup.xyqb.controller.internal.user;
import cn.quantgroup.xyqb.aspect.accessable.IpValidator;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.model.IdCardInfo;
import cn.quantgroup.xyqb.model.IdType;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.model.UserModel;
import cn.quantgroup.xyqb.service.auth.IIdCardService;
import cn.quantgroup.xyqb.service.user.IUserDetailService;
import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.util.ValidationUtil;
......@@ -38,8 +35,7 @@ public class SyncUserController {
private IUserService userService;
@Autowired
private IUserDetailService userDetailService;
@Autowired
private IIdCardService idCardService;
@RequestMapping("/save_detail")
public JsonResult saveUserDetail(String key, String phoneNo, String idNo,
......@@ -55,11 +51,7 @@ public class SyncUserController {
log.error("姓名错误,name:{}", name);
return JsonResult.buildErrorStateResult("姓名错误", name);
}
IdCardInfo info = idCardService.getIdCardInfo(idNo);
if (Objects.isNull(info) || !info.isValid()) {
log.error("身份证号错误,idNo:{}", idNo);
return JsonResult.buildErrorStateResult("身份证号码错误", idNo);
}
User user = userService.findByPhoneWithCache(phoneNo);
if (Objects.isNull(user)) {
log.error("用户不存在,phoneNo:{}", phoneNo);
......@@ -73,7 +65,6 @@ public class SyncUserController {
userDetail.setUserId(user.getId());
userDetail.setPhoneNo(phoneNo);
userDetail.setName(name);
userDetail.setGender(info.getGender());
userDetail.setIsAuthenticated(false);
log.info("SyncUserController saveUserDetail, userId:{}, phoneNo:{}, name:{}", user.getId(), phoneNo, name);
try {
......
......@@ -62,9 +62,6 @@ public class UserCenterController {
@PostMapping("/attach/list")
public JsonResult queryUserAttachList(@RequestBody List<Long> userIds, @RequestParam(required = false) Integer tenantId) {
//默认羊小咩租户
if (TenantUtil.validationTenantIdIsNullOrZero(tenantId)) {
tenantId = TenantUtil.TENANT_DEFAULT;
}
if (CollectionUtils.isEmpty(userIds)) {
return JsonResult.buildErrorStateResult("用户 ID 不能为空", null);
}
......@@ -72,6 +69,11 @@ public class UserCenterController {
if (userIds.size() > size) {
return JsonResult.buildErrorStateResult("超出最大条数限制" + size, null);
}
if (TenantUtil.validationTenantIdIsNullOrZero(tenantId)) {
tenantId = TenantUtil.TENANT_DEFAULT;
}
List<UserAttached> userAttachedList = userCenterService.searchUserAttachedListByUserId(userIds, tenantId);
return JsonResult.buildSuccessResultGeneric(userAttachedList);
}
......
......@@ -3,10 +3,7 @@ package cn.quantgroup.xyqb.controller.middleoffice.userdetail;
import cn.quantgroup.xyqb.controller.middleoffice.userdetail.req.UserDetailReq;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.model.IdCardInfo;
import cn.quantgroup.xyqb.model.IdType;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.auth.IIdCardService;
import cn.quantgroup.xyqb.service.user.IUserDetailService;
import cn.quantgroup.xyqb.service.user.IUserService;
import lombok.extern.slf4j.Slf4j;
......@@ -29,8 +26,6 @@ public class UserDetailController {
@Resource
private IUserService userService;
@Resource
private IIdCardService idCardService;
/**
* 修改用户实名信息
......@@ -68,13 +63,12 @@ public class UserDetailController {
return JsonResult.buildSuccessResultGeneric(userDetail);
}
User user = userService.findById(userId);
IdCardInfo idCardInfo = idCardService.getIdCardInfo(userDetailReq.getIdNo());
userDetail = new UserDetail();
userDetail.setUserId(userId);
userDetail.setName(userDetailReq.getName());
userDetail.setPhoneNo(user.getPhoneNo());
userDetail.setGender(idCardInfo.getGender());
userDetail.setGender(userDetail.getGender());
userDetail = userDetailService.saveUserDetail(userDetail);
log.info("UserDetailController save, userId:{}, phoneNo:{}, name:{}", user.getId(), user.getPhoneNo(), userDetailReq.getName());
return JsonResult.buildSuccessResultGeneric(userDetail);
......
package cn.quantgroup.xyqb.controller.middleoffice.userdetail.req;
import cn.quantgroup.xyqb.validator.ChineseName;
import cn.quantgroup.xyqb.validator.IdCard;
import lombok.Data;
@Data
public class UserDetailReq {
@ChineseName
private String name;
@IdCard
private String idNo;
}
......@@ -35,56 +35,51 @@ public class WxController {
private IUserService userService;
/**
* @ yapi http://open.quantgroups.com/project/59/interface/api/693
* @ yapi http://yapi.quantgroups.com/project/17/interface/api/30122
* @param userId
* @return
* @ yapi http://open.quantgroups.com/project/59/interface/api/693
* @ yapi http://yapi.quantgroups.com/project/17/interface/api/30122
*/
@GetMapping("/userId/{userId}")
public JsonResult openId(@PathVariable Long userId, @RequestParam(required = false) Integer tenantId) {
//默认羊小咩租户
if (TenantUtil.validationTenantIdIsNullOrZero(tenantId)) {
tenantId = TenantUtil.TENANT_DEFAULT;
}
if (tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
String openId = null;
if (TenantUtil.validationTenantIdIsNullOrZero(tenantId) || tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
WechatUserInfo wechatUserInfo = wechatService.queryByUserId(userId);
if (wechatUserInfo == null) {
return JsonResult.buildSuccessResult();
if (wechatUserInfo != null) {
openId = wechatUserInfo.getOpenId();
}
return JsonResult.buildSuccessResultGeneric(wechatUserInfo.getOpenId());
}else {
} else {
User user = userService.findById(userId);
if (user == null) {
return JsonResult.buildSuccessResult();
}
CustomerInfoEntity tenantCustomerInfo = tenantService.getTenantCustomerInfo(user, tenantId);
if (tenantCustomerInfo == null) {
return JsonResult.buildSuccessResult();
if (user != null) {
CustomerInfoEntity tenantCustomerInfo = tenantService.getTenantCustomerInfo(user, tenantId);
if (tenantCustomerInfo != null) {
openId = tenantCustomerInfo.getSourceOpenId();
}
}
return JsonResult.buildSuccessResultGeneric(tenantCustomerInfo.getSourceOpenId());
}
return JsonResult.buildSuccessResultGeneric(openId);
}
/**
* @ yapi http://yapi.quantgroups.com/project/17/interface/api/30122
* @param userId
* @param appName
* @param tenantId
* @return
* @ yapi http://yapi.quantgroups.com/project/17/interface/api/30122
*/
@GetMapping("/userId/{userId}/{appName}")
public JsonResult openId(@PathVariable Long userId,@PathVariable String appName, @RequestParam(required = false) Integer tenantId) {
public JsonResult openId(@PathVariable Long userId, @PathVariable String appName, @RequestParam(required = false) Integer tenantId) {
//默认羊小咩租户
if (TenantUtil.validationTenantIdIsNullOrZero(tenantId)) {
tenantId = TenantUtil.TENANT_DEFAULT;
}
if (tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
WechatUserInfo wechatUserInfo = wechatService.queryByUserId(userId,appName);
WechatUserInfo wechatUserInfo = wechatService.queryByUserId(userId, appName);
if (wechatUserInfo == null) {
return JsonResult.buildSuccessResult();
}
return JsonResult.buildSuccessResultGeneric(wechatUserInfo.getOpenId());
}else {
} else {
User user = userService.findById(userId);
if (user == null) {
return JsonResult.buildSuccessResult();
......@@ -99,10 +94,10 @@ public class WxController {
}
/**
* @yapi http://open.quantgroups.com/project/59/interface/api/693
* @yapi http://yapi.quantgroups.com/project/17/interface/api/30122
* @param phoneNo
* @return
* @yapi http://open.quantgroups.com/project/59/interface/api/693
* @yapi http://yapi.quantgroups.com/project/17/interface/api/30122
*/
@GetMapping("/phoneNo/{phoneNo}")
public JsonResult openId(@PathVariable String phoneNo, @RequestParam(required = false) Integer tenantId) {
......@@ -115,7 +110,7 @@ public class WxController {
return JsonResult.buildSuccessResult();
}
return JsonResult.buildSuccessResultGeneric(wechatUserInfo.getOpenId());
}else {
} else {
User user = userService.findByPhoneInDb(phoneNo);
if (user == null) {
return JsonResult.buildSuccessResult();
......@@ -141,6 +136,7 @@ public class WxController {
}
/**
*
*/
@PostMapping("/v1/getByOpenIdToUserIds")
public JsonResult getByOpenIdToUserIds(@RequestBody Map<String, Object> params, @RequestParam(required = false, defaultValue = "wuxi") String appName) {
......@@ -150,7 +146,7 @@ public class WxController {
return JsonResult.buildErrorStateResult("用户Id不能为空", null);
}
if (userIds.size() > 500) {
userIds = userIds.subList(0,500);
userIds = userIds.subList(0, 500);
}
List<Long> userIdList = userIds.stream().map(userId -> Long.parseLong(userId.toString())).collect(Collectors.toList());
......
......@@ -2,7 +2,6 @@ package cn.quantgroup.xyqb.controller.modifyphoneno.req;
import cn.quantgroup.xyqb.entity.ModifyPhoneNo;
import cn.quantgroup.xyqb.util.ValidationUtil;
import cn.quantgroup.xyqb.validator.IdCard;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
......@@ -34,7 +33,6 @@ public class Step1Req implements Serializable {
*/
//@ApiModelProperty("注册人身份证件号")
@NotBlank(message = "注册人身份证件号不能为空")
@IdCard
private String idCard;
/**
......
......@@ -2,10 +2,7 @@ package cn.quantgroup.xyqb.event;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.model.IdCardInfo;
import cn.quantgroup.xyqb.model.IdType;
import cn.quantgroup.xyqb.model.UserRegisterParam;
import cn.quantgroup.xyqb.service.auth.IIdCardService;
import cn.quantgroup.xyqb.service.user.IUserDetailService;
import cn.quantgroup.xyqb.util.ValidationUtil;
import lombok.extern.slf4j.Slf4j;
......@@ -19,8 +16,7 @@ import javax.annotation.Resource;
@Component
public class DetailRegisteredEventListener implements ApplicationListener<RegisterEvent> {
@Resource
private IIdCardService idCardService;
@Resource
private IUserDetailService userDetailService;
......@@ -29,23 +25,16 @@ public class DetailRegisteredEventListener implements ApplicationListener<Regist
UserRegisterParam userRegisterParam = event.getUserRegisterParam();
User user = userRegisterParam.getUser();
if (StringUtils.isAnyBlank(userRegisterParam.getIdNo(), userRegisterParam.getName()) ||
if (StringUtils.isAnyBlank(userRegisterParam.getName()) ||
!ValidationUtil.validateChinese(userRegisterParam.getName())) {
return;
}
String phoneNo = userRegisterParam.getPhoneNo();
String name = userRegisterParam.getName();
String idNo = userRegisterParam.getIdNo();
IdCardInfo cardInfo = idCardService.getIdCardInfo(idNo);
if (cardInfo == null || !cardInfo.isValid()) {
log.info("用户身份证号验证失败,userId:{},idNo:{}", user.getId(), idNo);
return;
}
UserDetail userDetail = new UserDetail();
userDetail.setPhoneNo(phoneNo);
userDetail.setName(name);
userDetail.setUserId(user.getId());
userDetail.setGender(cardInfo.getGender());
log.info("DetailRegisteredEventListener saveUserDetail, userId:{}, phoneNo:{}, name:{}", user.getId(), phoneNo, name);
userDetailService.saveUserDetail(userDetail);
}
......
......@@ -28,7 +28,7 @@ public class LkbRegisteredEventListener implements ApplicationListener<RegisterE
User user = userRegisterParam.getUser();
String uuid = user.getUuid();
boolean pushResult = lkbUserService.pushUser(uuid, userRegisterParam.getPhoneNo(),
userRegisterParam.getName(), userRegisterParam.getIdNo());
userRegisterParam.getName());
if (!pushResult) {
log.error("[userRegisterHandler][baseUserRegisterHandler]同步用户至Lkb出错,userRegisterParam:{}", JsonUtil.toJson(userRegisterParam));
throw new PushUserToLkbException("同步用户至Lkb出错");
......
......@@ -21,7 +21,6 @@ public class UserRegisterParam {
private Long registerFrom; // 注册渠道
private String phoneNo; // 手机号
private String password; // 密码
private String idNo; // 身份证号
private String name; // 姓名
private Long channelId; // 业务渠道
private Long btRegisterChannelId; // 白条渠道
......
package cn.quantgroup.xyqb.service.auth;
import cn.quantgroup.xyqb.model.IdCardInfo;
import java.text.ParseException;
/**
* Created by Miraculous on 15/7/10.
*/
public interface IIdCardService {
boolean isIdCardValid(String idCard) throws ParseException;
IdCardInfo getIdCardInfo(String idCardStr);
// 当身份证不合法,直接抛出异常。
IdCardInfo getIdCardInfoWithExceptions(String idCardStr) throws ParseException;
}
......@@ -2,10 +2,12 @@ package cn.quantgroup.xyqb.service.captcha;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.util.encrypt.Md5Util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpStatus;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
......@@ -162,7 +164,7 @@ public class GeetestLib {
}
gtlog("result:" + result_str);
JSONObject jsonObject = new JSONObject(result_str);
JSONObject jsonObject = JSON.parseObject(result_str);
String return_challenge = jsonObject.getString("challenge");
this.challenge = return_challenge;
......@@ -295,7 +297,7 @@ public class GeetestLib {
}
String return_seccode = "";
try {
JSONObject return_map = new JSONObject(response);
JSONObject return_map = JSONObject.parseObject(response);
return_seccode = return_map.getString("seccode");
gtlog("md5: " + Md5Util.build(return_seccode));
if (return_seccode.equals(Md5Util.build(seccode))) {
......
......@@ -17,15 +17,13 @@ public interface IUserRegisterService {
*
* @param registerFrom
* @param phoneNo
* @param idNo
* @param name
* @param channelId
* @param btRegisterChannelId
* @return
*/
User register(Long registerFrom, String phoneNo, String idNo, String name, Long channelId, Long btRegisterChannelId);
User register(Long registerFrom, String phoneNo,String name, Long channelId, Long btRegisterChannelId);
User register(Long registerFrom, String phoneNo, String idNo, String name, Long channelId, Long btRegisterChannelId, Integer tenantId);
User register(Long registerFrom, String phoneNo, String name, Long channelId, Long btRegisterChannelId, Integer tenantId);
......@@ -68,7 +66,7 @@ public interface IUserRegisterService {
* @author jinsong.zhu 2018年05月16日14:22:13
* 处理对address和contact的非必要兼容
*/
User register(Long registeredFrom, Long channelId, String phoneNo, String name, String idNo,String contacts, Long btRegisterChannelId);
User register(Long registeredFrom, Long channelId, String phoneNo, String name,String contacts, Long btRegisterChannelId);
}
......@@ -13,7 +13,6 @@ public interface ILkbUserService {
* @param uuid
* @param phoneNo
* @param name
* @param idNo
*/
boolean pushUser(String uuid, String phoneNo, String name, String idNo);
boolean pushUser(String uuid, String phoneNo, String name);
}
......@@ -9,7 +9,7 @@ import java.util.List;
*/
public interface IProductLoginService {
ProductLoginEntity findSlaveByPloginInfo(String institutionId, String productId, Long userId);
List<ProductLoginEntity> findSlaveByPloginInfos(String institutionId, String productId, List<Long> userId);
List<ProductLoginEntity> findSlaveByProductLoginInfoList(String institutionId, String productId, List<Long> userId);
List<ProductLoginEntity> findSlaveByUserId(Long userId);
List<ProductLoginEntity> findSlaveByUserIds(List<Long> userIds);
......
......@@ -34,7 +34,7 @@ public class LkbUserviceImpl implements ILkbUserService {
private String clientUrl;
@Override
public boolean pushUser(String uuid, String phoneNo, String name, String idNo) {
public boolean pushUser(String uuid, String phoneNo, String name) {
String timeunit = System.currentTimeMillis() + "";
String token = PasswordUtil.MD5(String.format(TOKEN_PATTERN, timeunit));
Map<String, String> parameters = Maps.newHashMap();
......@@ -46,9 +46,7 @@ public class LkbUserviceImpl implements ILkbUserService {
if (StringUtils.isNotBlank(name)) {
parameters.put("realName", name);
}
if (StringUtils.isNotBlank(idNo)) {
parameters.put("idCardNo", idNo);
}
String response = httpService.post(clientUrl + "/user/push.json", parameters);
Optional<Map> resultOptional = JsonUtil.fromJson(response, Map.class);
if (!resultOptional.isPresent() || !Constants.SUCCESS_CODE.equals(resultOptional.get().get(Constants.RESULT_CODE))) {
......
......@@ -4,12 +4,15 @@ import cn.quantgroup.xyqb.entity.OauthClientDetailsEntity;
import cn.quantgroup.xyqb.entity.ProductLoginEntity;
import cn.quantgroup.xyqb.repository.IOauthClientDetailsRepository;
import cn.quantgroup.xyqb.service.user.IOauthClientDetailsService;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* Created by 11 on 2016/12/29.
......@@ -18,13 +21,22 @@ import java.util.List;
@Service
public class OauthClientDetailsServiceImpl implements IOauthClientDetailsService {
@Autowired
private IOauthClientDetailsRepository oauthClientDetailsRepository;
private final IOauthClientDetailsRepository oauthClientDetailsRepository;
private final LoadingCache<Integer, OauthClientDetailsEntity> cache;
public OauthClientDetailsServiceImpl(IOauthClientDetailsRepository oauthClientDetailsRepository) {
this.oauthClientDetailsRepository = oauthClientDetailsRepository;
cache = Caffeine.newBuilder()
.expireAfterWrite(8, TimeUnit.HOURS)
.maximumSize(1_000)
.build(this.oauthClientDetailsRepository::findFirstByClientId);
}
@Override
public OauthClientDetailsEntity findFirstByClientId(Integer clientId) {
OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsRepository.findFirstByClientId(clientId);
return oauthClientDetailsEntity;
return cache.get(clientId);
}
@Override
......@@ -40,5 +52,4 @@ public class OauthClientDetailsServiceImpl implements IOauthClientDetailsService
}
}
......@@ -6,6 +6,7 @@ import cn.quantgroup.xyqb.repository.ICustomerInfoRepository;
import cn.quantgroup.xyqb.repository.ICustomerLoginRepository;
import cn.quantgroup.xyqb.repository.IOauthClientDetailsRepository;
import cn.quantgroup.xyqb.repository.IProductLoginRepository;
import cn.quantgroup.xyqb.service.user.IOauthClientDetailsService;
import cn.quantgroup.xyqb.service.user.IOauthLoginInfoService;
import cn.quantgroup.xyqb.service.user.IProductLoginService;
import cn.quantgroup.xyqb.util.AtomicSequencer;
......@@ -25,7 +26,7 @@ import java.util.Date;
@Service
public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
@Autowired
private IOauthClientDetailsRepository oauthClientDetailsRepository;
private IOauthClientDetailsService oauthClientDetailsService;
@Autowired
private IProductLoginRepository productLoginRepository;
......@@ -45,7 +46,7 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void addLoginInfo(User user, Integer tenantId) {
OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsRepository.findFirstByClientId(tenantId);
OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsService.findFirstByClientId(tenantId);
if (oauthClientDetailsEntity != null) {
String institutionId = oauthClientDetailsEntity.getInstitutionId();
String productId = oauthClientDetailsEntity.getProductId();
......@@ -61,7 +62,6 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
long id = atomicSequencer.nextId();
String customerName = customerId + "";
uuid = RandomSequencer.randomUUID(customerId);
ProductLoginEntity entity = new ProductLoginEntity();
Integer partitionKey = atomicSequencer.partitionKey(customerId);
ProductLoginEntity productLoginEntity = EntityBuilder.productLogin(productId, institutionId, phoneNo, customerId, customerName, partitionKey, id);
productLoginEntity.setExtensionAccountId(userId);
......@@ -105,7 +105,7 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void addRegisterInfo(User user, AppletParamEntry appletParamEntry) {
OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsRepository.findFirstByClientId(appletParamEntry.getTenantId());
OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsService.findFirstByClientId(appletParamEntry.getTenantId());
if (oauthClientDetailsEntity != null) {
String institutionId = oauthClientDetailsEntity.getInstitutionId();
String productId = oauthClientDetailsEntity.getProductId();
......@@ -114,13 +114,12 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
ProductLoginEntity productLoginEntity = productLoginService.findTenantAndPhoneNo(institutionId, productId, phoneNo);
long uuid = 0L;
// 如果找不到该用户就创建
if ("".equals(productLoginEntity) || productLoginEntity == null) {
if (productLoginEntity == null) {
// 添加用户到产品登录表
long customerId = atomicSequencer.nextId();
long id = atomicSequencer.nextId();
String customerName = customerId + "";
uuid = RandomSequencer.randomUUID(customerId);
ProductLoginEntity entity = new ProductLoginEntity();
Integer partitionKey = atomicSequencer.partitionKey(customerId);
productLoginEntity = EntityBuilder.productLogin(productId, institutionId, phoneNo, customerId, customerName, partitionKey, id);
productLoginEntity.setExtensionAccountId(userId);
......
......@@ -25,9 +25,8 @@ public class ProductLoginServiceImpl implements IProductLoginService {
}
@Override
public List<ProductLoginEntity> findSlaveByPloginInfos(String institutionId, String productId, List<Long> userIds) {
List<ProductLoginEntity> list = productLoginRepository.findByInstitutionIdAndProductIdAndExtensionAccountIdIn(institutionId, productId, userIds);
return list;
public List<ProductLoginEntity> findSlaveByProductLoginInfoList(String institutionId, String productId, List<Long> userIds) {
return productLoginRepository.findByInstitutionIdAndProductIdAndExtensionAccountIdIn(institutionId, productId, userIds);
}
@Override
......@@ -38,8 +37,7 @@ public class ProductLoginServiceImpl implements IProductLoginService {
@Override
public List<ProductLoginEntity> findSlaveByUserIds(List<Long> userIds) {
List<ProductLoginEntity> productLoginEntityList = productLoginRepository.findAllByExtensionAccountIdIn(userIds);
return productLoginEntityList;
return productLoginRepository.findAllByExtensionAccountIdIn(userIds);
}
@Override
......
......@@ -7,6 +7,7 @@ import cn.quantgroup.xyqb.service.user.IOauthClientDetailsService;
import cn.quantgroup.xyqb.service.user.IProductLoginService;
import cn.quantgroup.xyqb.service.user.ITenantService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -37,11 +38,10 @@ public class TenantServiceImpl implements ITenantService {
if (oauthClientDetails != null) {
ProductLoginEntity productLogin = productLoginService.findSlaveByPloginInfo(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), user.getId());
if (productLogin != null) {
if (!user.getEncryptedPhoneNo().equals(productLogin.getEncryptedPhoneNo())) {
return null;
if (user.getEncryptedPhoneNo().equals(productLogin.getEncryptedPhoneNo())) {
user.setPassword(productLogin.getPassword());
return user;
}
user.setPassword(productLogin.getPassword());
return user;
}
}
return null;
......@@ -107,15 +107,9 @@ public class TenantServiceImpl implements ITenantService {
if (oauthClientDetails != null) {
ProductLoginEntity productLogin = productLoginService.findSlaveByPloginInfo(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), user.getId());
if (productLogin != null) {
if (!user.getPhoneNo().equals(productLogin.getPhoneNo())) {
return null;
}
CustomerInfoEntity customerInfo = customerInfoService.findSlaveByCustomerId(productLogin.getCustomerId());
if (customerInfo == null) {
return null;
if (user.getPhoneNo().equals(productLogin.getPhoneNo())) {
return customerInfoService.findSlaveByCustomerId(productLogin.getCustomerId());
}
return customerInfo;
}
}
return null;
......@@ -124,18 +118,14 @@ public class TenantServiceImpl implements ITenantService {
@Override
public List<User> selectUsersByTenantId(List<User> users, Integer tenantId) {
List<User> result = new ArrayList<>();
if (users != null) {
if (CollectionUtils.isNotEmpty(users)) {
OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsService.findFirstByClientId(tenantId);
if (oauthClientDetails != null) {
List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
List<ProductLoginEntity> productLoginEntities = productLoginService.findSlaveByPloginInfos(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), userIds);
if (productLoginEntities != null && productLoginEntities.size()>0) {
List<ProductLoginEntity> productLoginEntities = productLoginService.findSlaveByProductLoginInfoList(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), userIds);
if (CollectionUtils.isNotEmpty(productLoginEntities)) {
List<String> phoneNos = productLoginEntities.stream().map(ProductLoginEntity::getPhoneNo).collect(Collectors.toList());
users.forEach(a->{
if (phoneNos.contains(a.getPhoneNo())) {
result.add(a);
}
});
result = users.stream().filter(i -> phoneNos.contains(i.getPhoneNo())).collect(Collectors.toList());
}
}
}
......@@ -148,11 +138,11 @@ public class TenantServiceImpl implements ITenantService {
OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsService.findFirstByClientId(tenantId);
if (oauthClientDetails != null) {
CustomerInfoEntity customerInfo = customerInfoService.findSlaveByOpenId(openId, oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId());
if (customerInfo != null ) {
ProductLoginEntity productLogin = productLoginService.findSlaveByCustomerInfo(customerInfo.getCustomerId(), oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId());
if (productLogin != null) {
return productLogin.getExtensionAccountId();
}
if (customerInfo != null) {
ProductLoginEntity productLogin = productLoginService.findSlaveByCustomerInfo(customerInfo.getCustomerId(), oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId());
if (productLogin != null) {
return productLogin.getExtensionAccountId();
}
}
}
return null;
......@@ -161,31 +151,24 @@ public class TenantServiceImpl implements ITenantService {
@Override
public List<User> validationTentIdByTentId(List<User> users, Integer tenantId) {
List<User> result = new ArrayList<>();
if (users != null) {
List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(users)) {
OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsService.findFirstByClientId(tenantId);
List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
if (oauthClientDetails != null) {
List<ProductLoginEntity> slaveByPloginInfos = productLoginService.findSlaveByPloginInfos(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), userIds);
users.forEach(a->{
if (slaveByPloginInfos != null && slaveByPloginInfos.size()>0) {
List<String> phoneNos = slaveByPloginInfos.stream().map(ProductLoginEntity::getPhoneNo).collect(Collectors.toList());
if (phoneNos.contains(a.getPhoneNo())) {
result.add(a);
}
}
});
}
//1、查询出在product_login手机号码相同的用户
List<ProductLoginEntity> productLoginEntities = productLoginService.findSlaveByProductLoginInfoList(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), userIds);
List<String> phoneNos = productLoginEntities.stream().map(ProductLoginEntity::getPhoneNo).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(productLoginEntities)) {
result = users.stream().filter(i -> phoneNos.contains(i.getPhoneNo())).collect(Collectors.toList());
}
} else {
//2、查询用户id不在product_login的扩展账户ID的用户
List<ProductLoginEntity> slaveByUserIds = productLoginService.findSlaveByUserIds(userIds);
List<Long> extensionAccountIds = slaveByUserIds.stream().map(ProductLoginEntity::getExtensionAccountId).collect(Collectors.toList());
List<ProductLoginEntity> slaveByUserIds = productLoginService.findSlaveByUserIds(userIds);
if (slaveByUserIds != null) {
List<Long> collect = slaveByUserIds.stream().map(ProductLoginEntity::getExtensionAccountId).collect(Collectors.toList());
users.forEach(a->{
if (collect != null) {
if (!collect.contains(a.getId())) {
result.add(a);
}
}
});
if (CollectionUtils.isNotEmpty(slaveByUserIds)) {
result = users.stream().filter(i -> extensionAccountIds.contains(i.getId())).collect(Collectors.toList());
}
}
}
return result;
......
......@@ -9,6 +9,7 @@ import cn.quantgroup.xyqb.service.user.UserCenterService;
import cn.quantgroup.xyqb.util.EmojiUtil;
import cn.quantgroup.xyqb.util.TenantUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -41,37 +42,23 @@ public class UserCenterServiceImpl implements UserCenterService {
// @Cacheable(value = "userAttachedCache", key = "'xyqbUserAttached' + #userId", unless = "#result == null", cacheManager = "cacheManager")
public UserAttached searchUserAttachedByUserId(long userId) {
return userAttachedRepository.findByUserId(userId);
}
}
@Override
public List<UserAttached> searchUserAttachedListByUserId(List<Long> userIds, Integer tenantId) {
List<UserAttached> resultProductUsers = new ArrayList<>();
List<UserAttached> userAttacheds = userAttachedRepository.findByUserIdIn(userIds);
List<UserAttached> userAttachedList = userAttachedRepository.findByUserIdIn(userIds);
List<User> users = userRepository.findByIdIn(userIds);
List<User> productUsers;
if (!tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
if (userAttacheds != null) {
List<User> users = userRepository.findByIdIn(userIds);
List<User> productUsers = tenantService.selectUsersByTenantId(users, tenantId);
if (productUsers != null) {
List<Long> collect = productUsers.stream().map(User::getId).collect(Collectors.toList());
userAttacheds.forEach(a->{
if (collect.contains(a.getUserId())) {
resultProductUsers.add(a);
}
});
}
return resultProductUsers;
}
}else {
List<User> users = userRepository.findByIdIn(userIds);
List<User> productUsers = tenantService.validationTentIdByTentId(users, tenantId);
if (productUsers != null) {
List<Long> collect = productUsers.stream().map(User::getId).collect(Collectors.toList());
userAttacheds.forEach(a->{
if (collect.contains(a.getUserId())) {
resultProductUsers.add(a);
}
});
}
productUsers = tenantService.selectUsersByTenantId(users, tenantId);
} else {
productUsers = tenantService.validationTentIdByTentId(users, tenantId);
}
if (CollectionUtils.isNotEmpty(userAttachedList) && CollectionUtils.isNotEmpty(productUsers)) {
List<Long> productUserIds = productUsers.stream().map(User::getId).collect(Collectors.toList());
resultProductUsers = userAttachedList.stream().filter(i -> productUserIds.contains(i.getUserId())).collect(Collectors.toList());
}
return resultProductUsers;
}
......@@ -80,10 +67,10 @@ public class UserCenterServiceImpl implements UserCenterService {
@CacheEvict(value = "userAttachedCache", key = "'xyqbUserAttached' + #userId", cacheManager = "cacheManager")
public UserAttached saveUserAvatar(long userId, String avatar) {
UserAttached userAttached = userAttachedRepository.findByUserId(userId);
if(Objects.isNull(userAttached)){
if (Objects.isNull(userAttached)) {
userAttached = createUserAttached(userId, avatar, null);
}
if(!Objects.equals(avatar, userAttached.getAvatar())){
if (!Objects.equals(avatar, userAttached.getAvatar())) {
userAttached.setAvatar(avatar);
userAttached = userAttachedRepository.save(userAttached);
}
......@@ -96,14 +83,14 @@ public class UserCenterServiceImpl implements UserCenterService {
UserAttached userAttached = userAttachedRepository.findByUserId(userId);
// 替换所有,UTF-8编码时4字节的Emoji表情字符
nick = EmojiUtil.filterUnicode4(nick);
if(Objects.isNull(userAttached)){
if (Objects.isNull(userAttached)) {
userAttached = createUserAttached(userId, null, nick);
}
if(!Objects.equals(nick, userAttached.getNick())){
if (!Objects.equals(nick, userAttached.getNick())) {
userAttached.setNick(nick);
try {
userAttached = userAttachedRepository.save(userAttached);
}catch (ConstraintViolationException e){
} catch (ConstraintViolationException e) {
// Sql唯一约束异常(诱因是Form重复提交,因为该操作是幂等的,故此不需额外处理,可返回成功)
log.error("Sql约束异常[uni_idx_user_id]重复提交Form是幂等操作,不影响处理结果", e);
}
......@@ -121,7 +108,7 @@ public class UserCenterServiceImpl implements UserCenterService {
*
* @param userId - 用户主键
* @param avatar - 头像url地址
* @param nick - 昵称
* @param nick - 昵称
* @return
*/
private synchronized UserAttached createUserAttached(Long userId, String avatar, String nick) {
......@@ -129,10 +116,10 @@ public class UserCenterServiceImpl implements UserCenterService {
// 更新实例
userAttached = Optional.ofNullable(userAttached).orElse(new UserAttached());
userAttached.setUserId(userId);
if(StringUtils.isBlank(userAttached.getAvatar())){
if (StringUtils.isBlank(userAttached.getAvatar())) {
userAttached.setAvatar(avatar);
}
if(StringUtils.isBlank(userAttached.getNick())){
if (StringUtils.isBlank(userAttached.getNick())) {
userAttached.setNick(nick);
}
return userAttachedRepository.save(userAttached);
......
......@@ -4,11 +4,9 @@ import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.event.UserDetailUpdateEvent;
import cn.quantgroup.xyqb.model.Gender;
import cn.quantgroup.xyqb.model.IdCardInfo;
import cn.quantgroup.xyqb.model.IdType;
import cn.quantgroup.xyqb.repository.IUserDetailRepository;
import cn.quantgroup.xyqb.repository.IUserRepository;
import cn.quantgroup.xyqb.service.auth.IIdCardService;
import cn.quantgroup.xyqb.service.user.IUserDetailService;
import cn.quantgroup.xyqb.service.user.vo.UserDetailVO;
import cn.quantgroup.xyqb.util.AddressFilter;
......@@ -42,8 +40,7 @@ public class UserDetailServiceImpl implements IUserDetailService {
private IUserDetailRepository userDetailRepository;
@Autowired
private IUserRepository userRepository;
@Autowired
private IIdCardService idCardService;
@Resource
private ApplicationEventPublisher applicationEventPublisher;
@Resource
......
......@@ -5,7 +5,10 @@ import cn.quantgroup.xyqb.aspect.lock.RedisLock;
import cn.quantgroup.xyqb.constant.enums.LoginType;
import cn.quantgroup.xyqb.controller.IBaseController;
import cn.quantgroup.xyqb.controller.internal.user.resp.UserFullResp;
import cn.quantgroup.xyqb.entity.*;
import cn.quantgroup.xyqb.entity.Merchant;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.entity.UserHashMapping;
import cn.quantgroup.xyqb.event.PhoneNoUpdateEvent;
import cn.quantgroup.xyqb.exception.DataException;
import cn.quantgroup.xyqb.exception.UserNotExistException;
......@@ -154,7 +157,6 @@ public class UserServiceImpl implements IUserService, IBaseController {
if (CollectionUtils.isEmpty(userIds)) {
return Maps.newHashMap();
}
Map<Long, String> userIdAndPhoneMap = Maps.newHashMap();
List<User> users = userRepository.findByIdIn(userIds);
//校验租户ID
if (!TenantUtil.TENANT_DEFAULT.equals(tenantId)) {
......@@ -162,8 +164,7 @@ public class UserServiceImpl implements IUserService, IBaseController {
} else {
users = tenantService.validationTentIdByTentId(users, tenantId);
}
users.forEach(user -> userIdAndPhoneMap.put(user.getId(), user.getPhoneNo()));
return userIdAndPhoneMap;
return users.stream().collect(Collectors.toMap(User::getId, User::getPhoneNo));
}
@Override
......@@ -213,7 +214,6 @@ public class UserServiceImpl implements IUserService, IBaseController {
}
@Override
// @Cacheable(value = "usercache", key = "'xyqbuser' + #phone", unless = "#result == null", cacheManager = "cacheManager")
public User findByPhoneWithCache(String phone) {
if (StringUtils.isBlank(phone)) {
return null;
......@@ -510,33 +510,29 @@ public class UserServiceImpl implements IUserService, IBaseController {
@Override
public List<User> findByUuidsOrUserIds(List<String> vals, Integer type, Integer tenantId) {
if (CollectionUtils.isEmpty(vals)) {
return Collections.EMPTY_LIST;
return new ArrayList<>();
}
List<User> users;
if (type == 1) {//1是userids
List<Long> collect = vals.stream()
.map(Long::valueOf)
.collect(Collectors.toList());
List<User> users = userRepository.findByIdIn(collect);
if (!tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
return tenantService.selectUsersByTenantId(users, tenantId);
} else {
return tenantService.validationTentIdByTentId(users, tenantId);
}
users = userRepository.findByIdIn(collect);
} else { //不是1 就是 uuids
List<User> users = userRepository.findByUuidIn(vals);
if (!tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
return tenantService.selectUsersByTenantId(users, tenantId);
} else {
return tenantService.validationTentIdByTentId(users, tenantId);
}
users = userRepository.findByUuidIn(vals);
}
if (!tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
users = tenantService.selectUsersByTenantId(users, tenantId);
} else {
users = tenantService.validationTentIdByTentId(users, tenantId);
}
return users;
}
@Override
public void logout(String token) {
sessionService.deleteSession(token);
}
......@@ -616,6 +612,7 @@ public class UserServiceImpl implements IUserService, IBaseController {
/**
* 不同渠道用户签署不同合同模板
*
* @param user
* @param loginFrom
*/
......@@ -627,7 +624,8 @@ public class UserServiceImpl implements IUserService, IBaseController {
if (Objects.nonNull(loginFrom) && Objects.equals(user.getRegisteredFrom(), loginFrom)) {
return;
}
Map<String, Long> channelMap = JSON.parseObject(channelTemplate, new TypeReference<HashMap<String, Long>>() {});
Map<String, Long> channelMap = JSON.parseObject(channelTemplate, new TypeReference<HashMap<String, Long>>() {
});
Long templateId = channelMap.get(String.valueOf(user.getRegisteredFrom()));
boolean needCheck = false;
if (Objects.nonNull(loginFrom) && !Objects.equals(user.getRegisteredFrom(), loginFrom)) {
......
......@@ -52,21 +52,16 @@ public class XyqbSessionContextHolder {
}
public static SessionStruct getXSessionFromRedis(String token) {
if ( Objects.isNull(redisTemplate)) {
return null;
}
String linkToken = Constants.Session.USER_SESSION_CACHE + token;
String result = redisTemplate.opsForValue().get(linkToken);
if (StringUtils.isEmpty(result)) {
log.warn("[XyqbSessionContextHolder][getXSessionFromRedis] Tokekn:{},linkTokekn:{}", token, linkToken);
log.warn("[XyqbSessionContextHolder][getXSessionFromRedis] session data 未找到:sid:{},sessionValue:{}", token, result);
log.warn("[XyqbSessionContextHolder][getXSessionFromRedis] session data 未找到:Tokekn:{},linkTokekn:{},sessionValue:{}", token,linkToken, result);
return null;
}
try {
SessionValue values = JSON.parseObject(result, SessionValue.class);
if (values == null) {
log.warn("[XyqbSessionContextHolder][getXSessionFromRedis] Tokekn:{},linkTokekn:{}", token, linkToken);
log.warn("[XyqbSessionContextHolder][getXSessionFromRedis] session data 序列化失败:sid:{},sessionValue:{}", token, result);
log.warn("[XyqbSessionContextHolder][getXSessionFromRedis] session data 序列化失败:token:{},linkTokekn:{},sessionValue:{}", token, linkToken,result);
return null;
}
SessionStruct sessionStruct = new SessionStruct();
......@@ -75,8 +70,7 @@ public class XyqbSessionContextHolder {
sessionStruct.setExpire(redisTemplate.getExpire(Constants.Session.USER_SESSION_CACHE + token));
return sessionStruct;
} catch (Exception e) {
log.warn("[XyqbSessionContextHolder][getXSessionFromRedis] Tokekn:{},linkTokekn:{}", token, linkToken);
log.warn("[XyqbSessionContextHolder][getXSessionFromRedis] 序列化SessionValue出错:sid:{},sessionValue:{}", token, result, e);
log.warn("[XyqbSessionContextHolder][getXSessionFromRedis] 序列化SessionValue出错:Tokekn:{},linkTokekn:{},sessionValue:{}", token, linkToken,result, e);
return null;
}
}
......
......@@ -8,19 +8,14 @@ import java.util.Objects;
* Created by Miraculous on 15/7/5.
*/
public class BctyptPasswordUtil {
public static void main(String[] args) {
System.out.println(BCryptWithSalt("123456"));
System.out.println(BCryptCheckPw("123456", BCryptWithSalt("123456")));
}
public final static String BCryptWithSalt(String password) {
public static String BCryptWithSalt(String password) {
if(Objects.isNull(password)){
return null;
}
return BCrypt.hashpw(password, BCrypt.gensalt());
}
public final static Boolean BCryptCheckPw(String password, String hashe) {
public static Boolean BCryptCheckPw(String password, String hashe) {
return BCrypt.checkpw(password, hashe);
}
......
......@@ -17,7 +17,6 @@ import java.util.Date;
*/
public class DateUtils {
public static final String YMD_FORMAT = "yyyy-MM-dd";
public static final String YMD_HMS_FORMAT = "yyyy-MM-dd HH:mm:ss";
/**
......
......@@ -26,7 +26,7 @@ import java.util.Random;
*/
@Slf4j
public class RedisLock {
private RedisTemplate redisTemplate;
private final RedisTemplate redisTemplate;
/**
* Lock key path.
*/
......
......@@ -53,17 +53,4 @@ public abstract class ServerUtils {
return port == null || port.equals("") ? null : Integer.valueOf(port);
}
public static Integer getIntegerPort() throws MalformedObjectNameException {
return getIntegerPort(null);
}
public static void main(String[] args) {
try {
System.out.println(ServerUtils.getLongHostAddress());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
......@@ -99,45 +99,4 @@ public class SnowflakeIdentitySequencer implements IdentitySequencer {
", workerId=" + workerId +
'}';
}
public static void main(String[] args) {
SnowflakeIdentitySequencer snowflakeIdWorker = new SnowflakeIdentitySequencer(255255255255L ^ 8000, 8);
// SnowflakeIdentitySequencer snowflakeIdWorker = new SnowflakeIdentitySequencer(1099511627775L, 8, TWEPOCH_PLUS);
// SnowflakeIdWorker snowflakeIdWorker = new SnowflakeIdWorker(255255255255L, 16, 8);
// SnowflakeIdWorker snowflakeIdWorker = new SnowflakeIdWorker(255255255255L, 16, 8);
// SnowflakeIdWorker snowflakeIdWorker = new SnowflakeIdWorker(17202801560208L);
Long nextId = snowflakeIdWorker.nextId(245);
System.out.println(nextId);
// for(int i=0; i<300;i++){
// System.out.println(i+":"+(i&255));
// }
// for (int i = 0; i < 100; i++) {
// new Thread(new Running(snowflakeIdWorker)).start();
// }
// System.out.println(73361139375145112L ^ (73361139375145112L >> 8 << 8));
// System.out.println((nextId >> 8 << 8) ^ nextId);
// for (int i = 0; i < 10000; i++) {
// System.out.println(snowflakeIdWorker.nextId());
// }
}
public static class Running implements Runnable {
SnowflakeIdentitySequencer sequencer;
public Running(SnowflakeIdentitySequencer sequencer) {
this.sequencer = sequencer;
}
@Override
public void run() {
System.out.println(this.sequencer.nextId(255));
}
}
}
......@@ -10,16 +10,10 @@ import org.slf4j.helpers.MessageFormatter;
import java.io.Serializable;
public class StringUtils extends org.springframework.util.StringUtils {
public static final char DELIMITED_ID_SEP = '$';
public static final char DELIMITED_ID_WCHAR = '*';
public StringUtils() {
}
public static String defaultIfNull(String object, String defaultValue) {
return object == null ? defaultValue : object;
}
public static <T extends Serializable> String toDelimitedString(T... ids) {
return toDelimitedString('$', ids);
}
......@@ -49,8 +43,5 @@ public class StringUtils extends org.springframework.util.StringUtils {
return builder.toString();
}
public static String format(String msg, Object... args) {
return MessageFormatter.arrayFormat(msg, args).getMessage();
}
}
......@@ -4,7 +4,6 @@ public class TenantUtil {
/* 租户羊小咩 */
public static final Integer TENANT_DEFAULT = 560761;
public static final String TENANT_USER_ERROR = "该租户下未找到此用户";
/* 验证租户ID是否为空或0 */
public static boolean validationTenantIdIsNullOrZero(Integer tenantId) {
......
package cn.quantgroup.xyqb.util;
import com.xxl.job.core.executor.XxlJobExecutor;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import java.util.Iterator;
import java.util.Map;
public class XxlJobSpringExecutor extends XxlJobExecutor implements ApplicationContextAware {
private static ApplicationContext applicationContext;
public void start() throws Exception {
this.initJobHandlerRepository(applicationContext);
super.start();
}
private void initJobHandlerRepository(ApplicationContext applicationContext) {
if (applicationContext != null) {
Map<String, Object> serviceBeanMap = applicationContext
.getBeansWithAnnotation(JobHandler.class);
if (serviceBeanMap != null && serviceBeanMap.size() > 0) {
Iterator var3 = serviceBeanMap.values().iterator();
while (var3.hasNext()) {
Object serviceBean = var3.next();
if (serviceBean instanceof IJobHandler) {
String name = ((JobHandler) serviceBean.getClass().getAnnotation(JobHandler.class))
.value();
IJobHandler handler = (IJobHandler) serviceBean;
if (loadJobHandler(name) != null) {
throw new RuntimeException("xxl-job jobhandler naming conflicts.");
}
registJobHandler(name, handler);
}
}
}
}
}
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
XxlJobSpringExecutor.applicationContext = applicationContext;
}
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
}
package cn.quantgroup.xyqb.validator;
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author 徐小光
*/
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = IdCardValidator.class)
public @interface IdCard {
/**
* 出错提示
*
* @return
*/
String message() default "身份证号码错误";
/**
* 啥玩意?
*
* @return
*/
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
package cn.quantgroup.xyqb.validator;
import cn.quantgroup.xyqb.util.IdcardValidator;
import org.apache.commons.lang3.StringUtils;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
/**
* 身份证验证器, <IdCard,String> String 对应的是可以对哪些类型校验
*
* @author 徐小光
*/
public class IdCardValidator implements ConstraintValidator<IdCard, String> {
/**
* 这个方法在初始化的时候调用. 如果配置错了, 你可以抛一个异常. 启动就报错了
*
* @param constraint
*/
@Override
public void initialize(IdCard constraint) {
}
/**
* 这....true = 校验通过. false = 校验失败
*
* @param idCard 就是那个String
* @param context
* @return
*/
@Override
public boolean isValid(String idCard, ConstraintValidatorContext context) {
if (StringUtils.isNotBlank(idCard)) {
return IdcardValidator.isValidate18Idcard(idCard);
}
return true;
}
}
package cn.quantgroup.xyqb.xxlJob;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import cn.quantgroup.xyqb.util.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
......@@ -32,7 +32,7 @@ public class XxlJobConfig {
@Bean(initMethod = "start", destroyMethod = "destroy")
public XxlJobSpringExecutor xxlJobExecutor() {
public XxlJobSpringExecutor xxlJobSpringExecutor() {
log.info(">>>>>>>>>>> xxl-job config init.");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
......
......@@ -8,7 +8,6 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.junit.Test;
......@@ -20,7 +19,6 @@ import java.sql.Timestamp;
@Slf4j
@RunWith(JUnit4.class)
public class JsonTest {
private static final Gson GSON = new Gson();
private static final ObjectMapper MAPPER = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(SerializationFeature.WRITE_ENUMS_USING_INDEX, true)
......@@ -34,7 +32,7 @@ public class JsonTest {
userData.setId(131L);
userData.setUserId(119L);
userData.setCreatedAt(new Timestamp(1));
log.info("序列化--GSON--成功!data:{}", GSON.toJson(userData));
log.info("序列化--GSON--成功!data:{}", JSON.toJSONString(userData));
log.info("序列化--MAPPER--成功!data:{}", MAPPER.writeValueAsString(userData));
log.info("序列化--JSON--成功!data:{}", JSON.toJSONString(userData, SerializerFeature.config(JSON.DEFAULT_GENERATE_FEATURE, SerializerFeature.WriteEnumUsingName, false)));
log.info("序列化--JSONObject--成功!data:{}", JSONObject.toJSONString(userData));
......@@ -46,7 +44,7 @@ public class JsonTest {
@Test
public void gsonGson(){
try {
UserDetail userData = GSON.fromJson(body, UserDetail.class);
UserDetail userData = JSON.parseObject(body, UserDetail.class);
log.info("GSON--成功!data:{}", userData);
}catch (Exception e){
log.error("GSON--失败!", e);
......
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