Commit e06828ab authored by 王亮's avatar 王亮

sign contracts after login.

parent 6f33ba2a
package cn.quantgroup.xyqb.config.data;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.ctrip.framework.apollo.ConfigService;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class ContractTemplateConfiguration {
private final Map<String, List<Long>> templateMap;
public ContractTemplateConfiguration() {
String data = ConfigService.getAppConfig().getProperty("template.data", "[]");
templateMap = JSON.parseObject(data, new TypeReference<HashMap<String, List<Long>>>() {
});
}
/**
* 获取指定租户下指定registeredFrom的合同模版,如果没有配置,那么取租户下默认模板
* @param tenantId 租户id
* @param registeredFrom 来源
* @return List<Long>
*/
public List<Long> getByTenantIdAndRegisteredFrom(Integer tenantId, Long registeredFrom) {
String key = tenantId + "_" + registeredFrom;
List<Long> result = new ArrayList<>();
if (templateMap.containsKey(key)) {
result = templateMap.get(key);
} else {
if (templateMap.containsKey(tenantId.toString())) {
result = templateMap.get(tenantId.toString());
}
}
return result;
}
}
...@@ -3,13 +3,11 @@ package cn.quantgroup.xyqb.config.data; ...@@ -3,13 +3,11 @@ package cn.quantgroup.xyqb.config.data;
import cn.quantgroup.xyqb.exception.BizException; import cn.quantgroup.xyqb.exception.BizException;
import cn.quantgroup.xyqb.exception.BizExceptionEnum; import cn.quantgroup.xyqb.exception.BizExceptionEnum;
import cn.quantgroup.xyqb.model.WechatConfigBean; import cn.quantgroup.xyqb.model.WechatConfigBean;
import cn.quantgroup.xyqb.util.StringUtils;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.ctrip.framework.apollo.ConfigService; import com.ctrip.framework.apollo.ConfigService;
import lombok.Getter; import lombok.Getter;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.persistence.criteria.CriteriaBuilder;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
......
package cn.quantgroup.xyqb.event; package cn.quantgroup.xyqb.event;
import cn.quantgroup.xyqb.config.data.ContractTemplateConfiguration;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.service.user.IUserService;
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.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.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -29,12 +31,8 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg ...@@ -29,12 +31,8 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg
@Resource @Resource
private RabbitTemplate registeredNotifyBlackHoleRabbitTemplate; private RabbitTemplate registeredNotifyBlackHoleRabbitTemplate;
// 用户注册合同中心模版id @Autowired
@Value("#{'${register.templateids}'.split(',')}") private ContractTemplateConfiguration contractTemplateConfiguration;
private List<Long> templateIds;
@Resource
private IUserService userService;
@Override @Override
...@@ -44,8 +42,11 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg ...@@ -44,8 +42,11 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg
LocalDate signDate = LocalDate.now(); LocalDate signDate = LocalDate.now();
String dateStr = signDate.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日")); String dateStr = signDate.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"));
int day = signDate.getDayOfMonth(); int day = signDate.getDayOfMonth();
// 信用钱包服务与隐私协议 List<Long> templates = contractTemplateConfiguration.getByTenantIdAndRegisteredFrom(user.getTenantId(), user.getRegisteredFrom());
templateIds.forEach(id -> { if (CollectionUtils.isNotEmpty(templates)) {
JSONArray array = new JSONArray();
templates.forEach(templateId -> {
if (templateId == 8 || templateId == 280) {
JSONObject fields = new JSONObject(); JSONObject fields = new JSONObject();
fields.put("phoneNo", user.getPhoneNo()); fields.put("phoneNo", user.getPhoneNo());
fields.put("genarateDateStr", dateStr); fields.put("genarateDateStr", dateStr);
...@@ -53,14 +54,18 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg ...@@ -53,14 +54,18 @@ public class BlackHoleRegisteredEventListener implements ApplicationListener<Reg
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("userId", user.getId()); json.put("userId", user.getId());
json.put("mustReal", false); json.put("mustReal", false);
json.put("templateId", id); json.put("templateId", templateId);
json.put("fields", fields); json.put("fields", fields);
JSONArray array = new JSONArray();
array.add(json); array.add(json);
} else {
JSONObject json = new JSONObject();
json.put("userId", user.getId());
json.put("templateId", templateId);
array.add(json);
}
registeredNotifyBlackHoleRabbitTemplate.convertAndSend(exchange, routingKey, registeredNotifyBlackHoleRabbitTemplate.convertAndSend(exchange, routingKey,
array.toString()); array.toString());
}); });
// 不同渠道签署不同的合同模板 }
userService.channelUserSignContract(user, null, user.getTenantId());
} }
} }
package cn.quantgroup.xyqb.event; package cn.quantgroup.xyqb.event;
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 org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -17,9 +19,13 @@ public class UserTagLoginEventListener implements ApplicationListener<UserLoginE ...@@ -17,9 +19,13 @@ public class UserTagLoginEventListener implements ApplicationListener<UserLoginE
@Autowired @Autowired
private IUserTagRepository userTagRepository; private IUserTagRepository userTagRepository;
@Autowired
private IUserService userService;
/** /**
* 逻辑 每次登录发送UserLoginEvent,落user_tag表 * 逻辑 每次登录发送UserLoginEvent,落user_tag表
* 如果没有就新增,如果有就更新 * 如果没有就新增,如果有就更新;
* 新增一个逻辑:合同补签,登录的时候跟注册渠道不同,判断是否需要补签合同,如果需要,则补签
* *
* @param userLoginEvent UserLoginEvent * @param userLoginEvent UserLoginEvent
*/ */
...@@ -41,6 +47,10 @@ public class UserTagLoginEventListener implements ApplicationListener<UserLoginE ...@@ -41,6 +47,10 @@ public class UserTagLoginEventListener implements ApplicationListener<UserLoginE
preTag.setUpdatedAt(userTag.getUpdatedAt() == null ? LocalDateTime.now() : userTag.getUpdatedAt()); preTag.setUpdatedAt(userTag.getUpdatedAt() == null ? LocalDateTime.now() : userTag.getUpdatedAt());
userTagRepository.save(preTag); userTagRepository.save(preTag);
User user = userService.findById(preTag.getUserId(),preTag.getTenantId());
//补签合同,如果需要补签
userService.channelUserSignContract(user,userTag.getRegisteredFrom(),userTag.getTenantId());
} }
} }
} }
...@@ -2,6 +2,7 @@ package cn.quantgroup.xyqb.service.user.impl; ...@@ -2,6 +2,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.constant.enums.LoginType; import cn.quantgroup.xyqb.constant.enums.LoginType;
import cn.quantgroup.xyqb.controller.IBaseController; import cn.quantgroup.xyqb.controller.IBaseController;
import cn.quantgroup.xyqb.controller.internal.user.resp.UserFullResp; import cn.quantgroup.xyqb.controller.internal.user.resp.UserFullResp;
...@@ -109,8 +110,8 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -109,8 +110,8 @@ public class UserServiceImpl implements IUserService, IBaseController {
@Value("${sc.is.open:false}") @Value("${sc.is.open:false}")
private Boolean scIsOpen; private Boolean scIsOpen;
@Value("${channel.register.template:null}") @Autowired
private String channelTemplate; private ContractTemplateConfiguration contractTemplateConfiguration;
@Resource @Resource
private RabbitTemplate registeredNotifyBlackHoleRabbitTemplate; private RabbitTemplate registeredNotifyBlackHoleRabbitTemplate;
...@@ -549,26 +550,21 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -549,26 +550,21 @@ public class UserServiceImpl implements IUserService, IBaseController {
* @param loginFrom * @param loginFrom
*/ */
public void channelUserSignContract(User user, Long loginFrom, Integer tenantId) { public void channelUserSignContract(User user, Long loginFrom, Integer tenantId) {
if (Objects.isNull(user) || StringUtils.isBlank(channelTemplate)) { if (Objects.isNull(user)) {
return; return;
} }
// 如果登录来源和注册来源相同,不用补签合同 // 如果登录来源和注册来源相同,不用补签合同
if (Objects.nonNull(loginFrom) && Objects.equals(user.getRegisteredFrom(), loginFrom)) { if (Objects.nonNull(loginFrom) && Objects.equals(user.getRegisteredFrom(), loginFrom)) {
return; return;
} }
Map<String, Long> channelMap = JSON.parseObject(channelTemplate, new TypeReference<HashMap<String, Long>>() { List<Long> templates = contractTemplateConfiguration.getByTenantIdAndRegisteredFrom(tenantId,loginFrom);
});
Long templateId = channelMap.get(String.valueOf(user.getRegisteredFrom()));
boolean needCheck = false;
if (Objects.nonNull(loginFrom) && !Objects.equals(user.getRegisteredFrom(), loginFrom)) {
templateId = channelMap.get(String.valueOf(loginFrom));
needCheck = true;
}
if (Objects.isNull(templateId)) { if(CollectionUtils.isEmpty(templates)){
return; return;
} }
if (needCheck) {
templates.forEach(templateId->{
ContractRecordReq contractRecordReq = new ContractRecordReq(); ContractRecordReq contractRecordReq = new ContractRecordReq();
contractRecordReq.setTemplateId(templateId); contractRecordReq.setTemplateId(templateId);
contractRecordReq.setUserId(user.getId()); contractRecordReq.setUserId(user.getId());
...@@ -577,12 +573,12 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -577,12 +573,12 @@ public class UserServiceImpl implements IUserService, IBaseController {
if (Objects.nonNull(data)) { if (Objects.nonNull(data)) {
return; return;
} }
}
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("userId", user.getId()); json.put("userId", user.getId());
json.put("templateId", templateId); json.put("templateId", templateId);
JSONArray array = new JSONArray(); JSONArray array = new JSONArray();
array.add(json); array.add(json);
registeredNotifyBlackHoleRabbitTemplate.convertAndSend(exchange, routingKey, array.toString()); registeredNotifyBlackHoleRabbitTemplate.convertAndSend(exchange, routingKey, array.toString());
});
} }
} }
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