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