project-car/cloud-modules/cloud-modules-template/src/main/java/com/template/util/SynchronizingTemplate.java

63 lines
2.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.template.util;
import com.template.domain.MessageTemplateType;
import com.template.domain.Template;
import com.template.service.TemplateService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
/**
* @Authorliuxinyue
* @Packagecom.template.util
* @Projectcloud-server
* @nameSynchronizingTemplate
* @Date2024/9/25 20:03
*/
@Component
@Log4j2
public class SynchronizingTemplate {
//调用报文模版列表接口
@Resource
private TemplateService templateService;
//redis
@Resource
private RedisTemplate redisTemplate;
@PostConstruct
public void synchronizeTemplate() {
//获取所有报文模版的ID
log.info("获取所有报文模版的ID");
List<Template> templates = templateService.templateList();
templates.forEach(template -> {
log.info("每个报文模版的ID");
Integer templateId = template.getTemplateId();
log.info("根据模版ID去查报文模版中谁属于这个类型的报文");
List<MessageTemplateType> list=templateService.findTemplateById(templateId);
ListOperations<String,Object> listOperations = redisTemplate.opsForList();
log.info("清除redis中的值");
redisTemplate.delete(template.getTemplateName());
log.info("将报文模版名称作为key,将list作为值");
listOperations.leftPushAll(template.getTemplateName(), list);
List<Object> range = listOperations.range(template.getTemplateName(), 0, -1);
log.info(range);
for (Object o : range) {
log.info("数据为:"+o);
}
});
}
}