Commit 934f892d authored by 王亮's avatar 王亮

Merge remote-tracking branch 'origin/feature-migration-20230628' into feature-migration-20230628

parents 9aafd25a aa7ab76f
...@@ -2,14 +2,17 @@ package cn.quantgroup.xyqb.event; ...@@ -2,14 +2,17 @@ package cn.quantgroup.xyqb.event;
import cn.quantgroup.xyqb.config.data.ContractTemplateConfiguration; import cn.quantgroup.xyqb.config.data.ContractTemplateConfiguration;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.util.RedisLock;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
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.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -33,6 +36,9 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg ...@@ -33,6 +36,9 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg
@Autowired @Autowired
private ContractTemplateConfiguration contractTemplateConfiguration; private ContractTemplateConfiguration contractTemplateConfiguration;
@Autowired
@Qualifier("stringRedisTemplate")
private RedisTemplate<String, String> redisTemplate;
@Override @Override
...@@ -44,28 +50,45 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg ...@@ -44,28 +50,45 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg
int day = signDate.getDayOfMonth(); int day = signDate.getDayOfMonth();
List<Long> templates = contractTemplateConfiguration.getByTenantIdAndRegisteredFrom(user.getTenantId(), user.getRegisteredFrom()); List<Long> templates = contractTemplateConfiguration.getByTenantIdAndRegisteredFrom(user.getTenantId(), user.getRegisteredFrom());
if (CollectionUtils.isNotEmpty(templates)) { if (CollectionUtils.isNotEmpty(templates)) {
JSONArray array = new JSONArray(); //补签合同,如果需要补签
templates.forEach(templateId -> { String lockKey = "user:signcontrac:".concat(user.getId().toString());
if (templateId == 8 || templateId == 280) { RedisLock lock = new RedisLock(redisTemplate, lockKey);
JSONObject fields = new JSONObject();
fields.put("phoneNo", user.getPhoneNo()); try {
fields.put("genarateDateStr", dateStr); if (lock.lock()) {
fields.put("day", day); //补签合同,如果需要补签 BlackHoleRegisteredEventListener 签署注册和隐私协议
JSONObject json = new JSONObject(); //此处补签,对于合同中心,可能会重新签署,后续待合同中心处理并发问题或者重复签署逻辑
json.put("userId", user.getId()); Thread.sleep(2000);
json.put("mustReal", false);
json.put("templateId", templateId); JSONArray array = new JSONArray();
json.put("fields", fields); templates.forEach(templateId -> {
array.add(json); if (templateId == 8 || templateId == 280) {
} else { JSONObject fields = new JSONObject();
JSONObject json = new JSONObject(); fields.put("phoneNo", user.getPhoneNo());
json.put("userId", user.getId()); fields.put("genarateDateStr", dateStr);
json.put("templateId", templateId); fields.put("day", day);
array.add(json); JSONObject json = new JSONObject();
json.put("userId", user.getId());
json.put("mustReal", false);
json.put("templateId", templateId);
json.put("fields", fields);
array.add(json);
} else {
JSONObject json = new JSONObject();
json.put("userId", user.getId());
json.put("templateId", templateId);
array.add(json);
}
log.info("注册签合同事件:{},",JSONObject.toJSONString(event));
registeredNotifyBlackHoleRabbitTemplate.convertAndSend(exchange, routingKey,
array.toString());
});
} }
registeredNotifyBlackHoleRabbitTemplate.convertAndSend(exchange, routingKey, } catch (Exception e) {
array.toString()); log.error("注册签合同异常:事件:{},异常:{}",JSONObject.toJSONString(event), e.getMessage(), e);
}); } finally {
lock.unlock();
}
} }
} }
} }
...@@ -4,8 +4,13 @@ import cn.quantgroup.xyqb.entity.User; ...@@ -4,8 +4,13 @@ import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserTag; import cn.quantgroup.xyqb.entity.UserTag;
import cn.quantgroup.xyqb.repository.IUserTagRepository; import cn.quantgroup.xyqb.repository.IUserTagRepository;
import cn.quantgroup.xyqb.service.user.IUserService; import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.util.RedisLock;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -14,6 +19,7 @@ import java.time.LocalDateTime; ...@@ -14,6 +19,7 @@ import java.time.LocalDateTime;
* user_tag表,用来监听 * user_tag表,用来监听
*/ */
@Component @Component
@Slf4j
public class UserTagLoginEventListener implements ApplicationListener<UserLoginEvent> { public class UserTagLoginEventListener implements ApplicationListener<UserLoginEvent> {
@Autowired @Autowired
...@@ -21,6 +27,9 @@ public class UserTagLoginEventListener implements ApplicationListener<UserLoginE ...@@ -21,6 +27,9 @@ public class UserTagLoginEventListener implements ApplicationListener<UserLoginE
@Autowired @Autowired
private IUserService userService; private IUserService userService;
@Autowired
@Qualifier("stringRedisTemplate")
private RedisTemplate<String, String> redisTemplate;
/** /**
* 逻辑 每次登录发送UserLoginEvent,落user_tag表 * 逻辑 每次登录发送UserLoginEvent,落user_tag表
...@@ -49,13 +58,21 @@ public class UserTagLoginEventListener implements ApplicationListener<UserLoginE ...@@ -49,13 +58,21 @@ public class UserTagLoginEventListener implements ApplicationListener<UserLoginE
userTagRepository.save(preTag); userTagRepository.save(preTag);
User user = userService.findById(preTag.getUserId(),preTag.getTenantId()); User user = userService.findById(preTag.getUserId(),preTag.getTenantId());
//补签合同,如果需要补签
String lockKey = "user:signcontrac:".concat(user.getId().toString());
RedisLock lock = new RedisLock(redisTemplate, lockKey);
try { try {
//补签合同,如果需要补签 BlackHoleRegisteredEventListener 签署注册和隐私协议 if (lock.lock()) {
//此处补签,对于合同中心,可能会重新签署,后续待合同中心处理并发问题或者重复签署逻辑 //补签合同,如果需要补签 BlackHoleRegisteredEventListener 签署注册和隐私协议
Thread.sleep(3000); //此处补签,对于合同中心,可能会重新签署,后续待合同中心处理并发问题或者重复签署逻辑
userService.channelUserSignContract(user,userTag.getRegisteredFrom(),userTag.getTenantId()); Thread.sleep(2000);
} catch (InterruptedException e) { userService.channelUserSignContract(user, userTag.getRegisteredFrom(), userTag.getTenantId());
e.printStackTrace(); }
} catch (Exception e) {
log.error("补签合同异常:事件:{},异常:{}", JSONObject.toJSONString(userLoginEvent), e.getMessage(), e);
} finally {
lock.unlock();
} }
} }
} }
......
...@@ -583,5 +583,6 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -583,5 +583,6 @@ public class UserServiceImpl implements IUserService, IBaseController {
array.add(json); array.add(json);
registeredNotifyBlackHoleRabbitTemplate.convertAndSend(exchange, routingKey, array.toString()); registeredNotifyBlackHoleRabbitTemplate.convertAndSend(exchange, routingKey, array.toString());
}); });
log.info("登录补签合同事件:userId:{},templateIds",user.getId(),templates);
} }
} }
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