Merge remote-tracking branch 'refs/remotes/origin/dev.template'

dev.breakdown
Number7 2024-09-25 21:07:03 +08:00
commit 7a97351e0f
5 changed files with 80 additions and 0 deletions

View File

@ -1,5 +1,6 @@
package com.template.mapper; package com.template.mapper;
import com.template.domain.MessageTemplateType;
import com.template.domain.Template; import com.template.domain.Template;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -20,4 +21,6 @@ public interface TemplateMapper {
Template findTemplateByName(@Param("typeName") String typeName); Template findTemplateByName(@Param("typeName") String typeName);
List<MessageTemplateType> findTemplateById(@Param("templateId") Integer templateId);
} }

View File

@ -1,5 +1,6 @@
package com.template.service; package com.template.service;
import com.template.domain.MessageTemplateType;
import com.template.domain.Template; import com.template.domain.Template;
import org.apache.iotdb.rpc.IoTDBConnectionException; import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException; import org.apache.iotdb.rpc.StatementExecutionException;
@ -20,4 +21,6 @@ public interface TemplateService {
void messageParsing(String templateMessage) throws SQLException, IoTDBConnectionException, ClassNotFoundException, StatementExecutionException; void messageParsing(String templateMessage) throws SQLException, IoTDBConnectionException, ClassNotFoundException, StatementExecutionException;
List<MessageTemplateType> findTemplateById(Integer templateId);
} }

View File

@ -91,6 +91,10 @@ public class TemplateServiceImpl implements TemplateService{
} }
} }
@Override
public List<MessageTemplateType> findTemplateById(Integer templateId) {
return templateMapper.findTemplateById(templateId);
}
public void insertIoTDB(JSONObject jsonObject) throws SQLException, ClassNotFoundException, IoTDBConnectionException, StatementExecutionException { public void insertIoTDB(JSONObject jsonObject) throws SQLException, ClassNotFoundException, IoTDBConnectionException, StatementExecutionException {

View File

@ -0,0 +1,62 @@
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);
}
});
}
}

View File

@ -11,5 +11,13 @@
<select id="findTemplateByName" resultType="com.template.domain.Template"> <select id="findTemplateByName" resultType="com.template.domain.Template">
select * from t_template where template_name=#{typeName} select * from t_template where template_name=#{typeName}
</select> </select>
<select id="findTemplateById" resultType="com.template.domain.MessageTemplateType">
SELECT
*
FROM
message_template_type
WHERE
template_id = #{templateId}
</select>
</mapper> </mapper>