Commit 8b97a22d authored by 唐峰's avatar 唐峰

合同签署

parent 5175d8a5
...@@ -3,4 +3,9 @@ package cn.quantgroup.xyqb.constant;/** ...@@ -3,4 +3,9 @@ package cn.quantgroup.xyqb.constant;/**
* @Created by tangfeng 2023/7/27 18:23 * @Created by tangfeng 2023/7/27 18:23
*/ */
public class RedisKeyConstant { public class RedisKeyConstant {
// 注册登录签署合同 userId-contractId
public static final String USER_REGISTER_LOGIN_CONTRACT = "user:register.login.contract:sign:%s-%s";
public static final String USER_REGISTER_LOGIN_CONTRACT_LOCK = "user:register.login.contract:lock:%s";
} }
package cn.quantgroup.xyqb.event; package cn.quantgroup.xyqb.event;
import cn.quantgroup.xyqb.config.data.ContractTemplateConfiguration; import cn.quantgroup.xyqb.config.data.ContractTemplateConfiguration;
import cn.quantgroup.xyqb.constant.RedisKeyConstant;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.util.RedisLock; import cn.quantgroup.xyqb.util.RedisLock;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
...@@ -19,6 +20,7 @@ import javax.annotation.Resource; ...@@ -19,6 +20,7 @@ import javax.annotation.Resource;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
/** /**
* 用户注册发送给合同中心事件监听 * 用户注册发送给合同中心事件监听
...@@ -51,7 +53,7 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg ...@@ -51,7 +53,7 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg
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)) {
//补签合同,如果需要补签 //补签合同,如果需要补签
String lockKey = "user:signcontrac:".concat(user.getId().toString()); String lockKey = RedisKeyConstant.USER_REGISTER_LOGIN_CONTRACT_LOCK.concat(user.getId().toString());
RedisLock lock = new RedisLock(redisTemplate, lockKey); RedisLock lock = new RedisLock(redisTemplate, lockKey);
try { try {
...@@ -62,6 +64,12 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg ...@@ -62,6 +64,12 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg
templates.forEach(templateId -> { templates.forEach(templateId -> {
String redisKey = String.format(RedisKeyConstant.USER_REGISTER_LOGIN_CONTRACT, user.getId(), templateId);
String redisValue = redisTemplate.opsForValue().get(redisKey);
if (org.apache.commons.lang3.StringUtils.isEmpty(redisValue)) {
return;
}
JSONArray array = new JSONArray(); JSONArray array = new JSONArray();
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
if (templateId == 8 || templateId == 280) { if (templateId == 8 || templateId == 280) {
...@@ -83,6 +91,9 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg ...@@ -83,6 +91,9 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg
log.info("注册签合同事件:{},模板:{}",JSONObject.toJSONString(event),templateId); log.info("注册签合同事件:{},模板:{}",JSONObject.toJSONString(event),templateId);
registeredNotifyBlackHoleRabbitTemplate.convertAndSend(exchange, routingKey, registeredNotifyBlackHoleRabbitTemplate.convertAndSend(exchange, routingKey,
array.toString()); array.toString());
redisTemplate.opsForValue().set(redisKey, array.toJSONString());
redisTemplate.expire(redisKey, 1L, TimeUnit.MINUTES);
}); });
} }
} catch (Exception e) { } catch (Exception e) {
......
...@@ -3,6 +3,7 @@ package cn.quantgroup.xyqb.service.user.impl; ...@@ -3,6 +3,7 @@ package cn.quantgroup.xyqb.service.user.impl;
import cn.quantgroup.xyqb.Constants; import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.aspect.lock.RedisLock; import cn.quantgroup.xyqb.aspect.lock.RedisLock;
import cn.quantgroup.xyqb.config.data.ContractTemplateConfiguration; import cn.quantgroup.xyqb.config.data.ContractTemplateConfiguration;
import cn.quantgroup.xyqb.constant.RedisKeyConstant;
import cn.quantgroup.xyqb.constant.UserConstant; import cn.quantgroup.xyqb.constant.UserConstant;
import cn.quantgroup.xyqb.constant.enums.LoginType; import cn.quantgroup.xyqb.constant.enums.LoginType;
import cn.quantgroup.xyqb.controller.IBaseController; import cn.quantgroup.xyqb.controller.IBaseController;
...@@ -567,22 +568,40 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -567,22 +568,40 @@ public class UserServiceImpl implements IUserService, IBaseController {
return; return;
} }
templates.forEach(templateId -> { String lockKey = RedisKeyConstant.USER_REGISTER_LOGIN_CONTRACT_LOCK.concat(user.getId().toString());
ContractRecordReq contractRecordReq = new ContractRecordReq(); cn.quantgroup.xyqb.util.RedisLock lock = new cn.quantgroup.xyqb.util.RedisLock(stringRedisTemplate, lockKey);
contractRecordReq.setTemplateId(templateId);
contractRecordReq.setUserId(user.getId()); try {
JsonResult<ContractsRes> result = pdfRemoteService.getContractRecord(contractRecordReq); if (lock.lock()) {
ContractsRes data = result.getData(); templates.forEach(templateId -> {
if (Objects.nonNull(data)) { String redisKey = String.format(RedisKeyConstant.USER_REGISTER_LOGIN_CONTRACT, user.getId(), templateId);
return; String redisValue = stringRedisTemplate.opsForValue().get(redisKey);
if (org.apache.commons.lang3.StringUtils.isEmpty(redisValue)) {
return;
}
ContractRecordReq contractRecordReq = new ContractRecordReq();
contractRecordReq.setTemplateId(templateId);
contractRecordReq.setUserId(user.getId());
JsonResult<ContractsRes> result = pdfRemoteService.getContractRecord(contractRecordReq);
ContractsRes data = result.getData();
if (Objects.nonNull(data)) {
return;
}
JSONObject json = new JSONObject();
json.put("userId", user.getId());
json.put("templateId", templateId);
JSONArray array = new JSONArray();
array.add(json);
registeredNotifyBlackHoleRabbitTemplate.convertAndSend(exchange, routingKey, array.toString());
log.info("登录补签合同事件:userId:{},templateIds:{}",user.getId(),templateId);
stringRedisTemplate.opsForValue().set(redisKey, array.toJSONString());
stringRedisTemplate.expire(redisKey, 1L, TimeUnit.MINUTES);
});
} }
JSONObject json = new JSONObject(); } catch (Exception e) {
json.put("userId", user.getId()); log.error("补签合同事件异常:事件:user:{},loginFrom:{},tenantId:{},异常:{}",user.getId(),loginFrom,tenantId, e.getMessage(), e);
json.put("templateId", templateId); } finally {
JSONArray array = new JSONArray(); lock.unlock();
array.add(json); }
registeredNotifyBlackHoleRabbitTemplate.convertAndSend(exchange, routingKey, array.toString());
log.info("登录补签合同事件:userId:{},templateIds:{}",user.getId(),templateId);
});
} }
} }
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