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.CarType;
|
||||||
import com.template.domain.SysCar;
|
import com.template.domain.SysCar;
|
||||||
|
import com.template.domain.resp.CarTypeResp;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author:liuxinyue
|
* @Author:liuxinyue
|
||||||
* @Package:com.template.mapper
|
* @Package:com.template.mapper
|
||||||
|
@ -19,4 +22,5 @@ public interface CarMapper {
|
||||||
|
|
||||||
CarType carMapper(@Param("carTypeId") Long carTypeId);
|
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.CarType;
|
||||||
import com.template.domain.SysCar;
|
import com.template.domain.SysCar;
|
||||||
|
import com.template.domain.resp.CarTypeResp;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author:liuxinyue
|
* @Author:liuxinyue
|
||||||
|
@ -15,4 +18,7 @@ public interface CarService {
|
||||||
|
|
||||||
CarType findCarTypeById(Long carTypeId);
|
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.CarType;
|
||||||
import com.template.domain.SysCar;
|
import com.template.domain.SysCar;
|
||||||
|
import com.template.domain.resp.CarTypeResp;
|
||||||
import com.template.mapper.CarMapper;
|
import com.template.mapper.CarMapper;
|
||||||
import com.template.service.CarService;
|
import com.template.service.CarService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author:liuxinyue
|
* @Author:liuxinyue
|
||||||
* @Package:com.template.service.impl
|
* @Package:com.template.service.impl
|
||||||
|
@ -31,4 +34,10 @@ public class CarServiceImpl implements CarService {
|
||||||
return carMapper.carMapper(carTypeId);
|
return carMapper.carMapper(carTypeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CarTypeResp> findAllCars() {
|
||||||
|
return carMapper.findAllCars();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,6 @@ public class TemplateServiceImpl implements TemplateService{
|
||||||
@Autowired
|
@Autowired
|
||||||
private MessageTemplateTypeService messageTemplateTypeService;
|
private MessageTemplateTypeService messageTemplateTypeService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisTemplate redisTemplate;
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
package com.template.util;
|
package com.template.util;
|
||||||
import com.template.domain.MessageTemplateType;
|
import com.template.domain.MessageTemplateType;
|
||||||
|
import com.template.domain.SysCar;
|
||||||
import com.template.domain.Template;
|
import com.template.domain.Template;
|
||||||
|
import com.template.domain.resp.CarTypeResp;
|
||||||
|
import com.template.service.CarService;
|
||||||
import com.template.service.TemplateService;
|
import com.template.service.TemplateService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
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.ListOperations;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -29,26 +33,23 @@ public class SynchronizingTemplate {
|
||||||
@Resource
|
@Resource
|
||||||
private RedisTemplate redisTemplate;
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CarService carService;
|
||||||
|
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void synchronizeTemplate() {
|
public void synchronizeTemplate() {
|
||||||
//获取所有报文模版的ID
|
//获取所有报文模版的ID
|
||||||
log.info("获取所有报文模版的ID");
|
log.info("获取所有报文模版的ID");
|
||||||
List<Template> templates = templateService.templateList();
|
List<Template> templates = templateService.templateList();
|
||||||
templates.forEach(template -> {
|
templates.forEach(template -> {
|
||||||
log.info("每个报文模版的ID");
|
Integer templateId = template.getTemplateId(); //报文模版ID
|
||||||
Integer templateId = template.getTemplateId();
|
List<MessageTemplateType> list=templateService.findTemplateById(templateId); //根据报文模版ID查询所有的报文模版
|
||||||
log.info("根据模版ID去查报文模版中谁属于这个类型的报文");
|
ListOperations<String,Object> listOperations = redisTemplate.opsForList(); //将报文信息存储到redis中
|
||||||
List<MessageTemplateType> list=templateService.findTemplateById(templateId);
|
redisTemplate.delete(template.getTemplateName());//因为每一次添加缓存的时候不会覆盖之前的数据 所有将数据先清空
|
||||||
ListOperations<String,Object> listOperations = redisTemplate.opsForList();
|
List<CarTypeResp> allCars = carService.findAllCars();//查询所有车辆 里面有模版名称
|
||||||
log.info("清除redis中的值");
|
redisTemplate.opsForList().leftPushAll("VehicleType", allCars);//将车辆类型放入列表
|
||||||
redisTemplate.delete(template.getTemplateName());
|
listOperations.leftPushAll(template.getTemplateName(), list); //将报文信息存储到redis中
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,4 +10,14 @@
|
||||||
<select id="carMapper" resultType="com.template.domain.CarType">
|
<select id="carMapper" resultType="com.template.domain.CarType">
|
||||||
select * from car_type where id=#{carTypeId}
|
select * from car_type where id=#{carTypeId}
|
||||||
</select>
|
</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>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue