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