Merge remote-tracking branch 'refs/remotes/origin/dev.template'
commit
26fded7ed6
|
@ -0,0 +1,22 @@
|
|||
package com.template.domain.resp;
|
||||
|
||||
import com.template.domain.CarType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.template.domain.resp
|
||||
* @Project:cloud-server
|
||||
* @name:CarTypeResp
|
||||
* @Date:2024/9/25 22:09
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CarTypeResp extends CarType{
|
||||
|
||||
private String templateName;
|
||||
|
||||
}
|
|
@ -2,9 +2,12 @@ package com.template.mapper;
|
|||
|
||||
import com.template.domain.CarType;
|
||||
import com.template.domain.SysCar;
|
||||
import com.template.domain.resp.CarTypeResp;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.template.mapper
|
||||
|
@ -19,4 +22,5 @@ public interface CarMapper {
|
|||
|
||||
CarType carMapper(@Param("carTypeId") Long carTypeId);
|
||||
|
||||
List<CarTypeResp> findAllCars();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ package com.template.service;
|
|||
|
||||
import com.template.domain.CarType;
|
||||
import com.template.domain.SysCar;
|
||||
import com.template.domain.resp.CarTypeResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:liuxinyue
|
||||
|
@ -15,4 +18,7 @@ public interface CarService {
|
|||
|
||||
CarType findCarTypeById(Long carTypeId);
|
||||
|
||||
List<CarTypeResp> findAllCars();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,11 +2,14 @@ package com.template.service.impl;
|
|||
|
||||
import com.template.domain.CarType;
|
||||
import com.template.domain.SysCar;
|
||||
import com.template.domain.resp.CarTypeResp;
|
||||
import com.template.mapper.CarMapper;
|
||||
import com.template.service.CarService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.template.service.impl
|
||||
|
@ -31,4 +34,10 @@ public class CarServiceImpl implements CarService {
|
|||
return carMapper.carMapper(carTypeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CarTypeResp> findAllCars() {
|
||||
return carMapper.findAllCars();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -40,9 +40,6 @@ public class TemplateServiceImpl implements TemplateService{
|
|||
@Autowired
|
||||
private MessageTemplateTypeService messageTemplateTypeService;
|
||||
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package com.template.util;
|
||||
import com.template.domain.MessageTemplateType;
|
||||
import com.template.domain.SysCar;
|
||||
import com.template.domain.Template;
|
||||
import com.template.domain.resp.CarTypeResp;
|
||||
import com.template.service.CarService;
|
||||
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;
|
||||
|
@ -29,26 +33,23 @@ public class SynchronizingTemplate {
|
|||
@Resource
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private CarService carService;
|
||||
|
||||
|
||||
@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);
|
||||
}
|
||||
Integer templateId = template.getTemplateId(); //报文模版ID
|
||||
List<MessageTemplateType> list=templateService.findTemplateById(templateId); //根据报文模版ID查询所有的报文模版
|
||||
ListOperations<String,Object> listOperations = redisTemplate.opsForList(); //将报文信息存储到redis中
|
||||
redisTemplate.delete(template.getTemplateName());//因为每一次添加缓存的时候不会覆盖之前的数据 所有将数据先清空
|
||||
List<CarTypeResp> allCars = carService.findAllCars();//查询所有车辆 里面有模版名称
|
||||
redisTemplate.opsForList().leftPushAll("VehicleType", allCars);//将车辆类型放入列表
|
||||
listOperations.leftPushAll(template.getTemplateName(), list); //将报文信息存储到redis中
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,4 +10,14 @@
|
|||
<select id="carMapper" resultType="com.template.domain.CarType">
|
||||
select * from car_type where id=#{carTypeId}
|
||||
</select>
|
||||
<select id="findAllCars" resultType="com.template.domain.resp.CarTypeResp">
|
||||
SELECT
|
||||
car_type.*,
|
||||
t_template.template_name
|
||||
FROM
|
||||
car_type
|
||||
LEFT JOIN t_template ON car_type.template_id = t_template.template_id
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue