模版信息同步到redis中

master
kezhen0805 2 years ago
parent dde026fb50
commit b882a41e5e

@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -38,5 +39,4 @@ public class CacheController {
} }
} }

@ -8,6 +8,29 @@ public class ClientTemplate {
private String templateText; private String templateText;
private long templateType; private long templateType;
private long templateState; private long templateState;
@Override
public String toString() {
return "ClientTemplate{" +
"id=" + id +
", signId=" + signId +
", templateText='" + templateText + '\'' +
", templateType=" + templateType +
", templateState=" + templateState +
", useId=" + useId +
", useWeb='" + useWeb + '\'' +
", created=" + created +
", createId=" + createId +
", updated=" + updated +
", updateId=" + updateId +
", isDelete=" + isDelete +
", extend1='" + extend1 + '\'' +
", extend2='" + extend2 + '\'' +
", extend3='" + extend3 + '\'' +
", extend4='" + extend4 + '\'' +
'}';
}
private long useId; private long useId;
private String useWeb; private String useWeb;
private java.sql.Timestamp created; private java.sql.Timestamp created;

@ -14,4 +14,6 @@ import java.util.List;
public interface ClientTemplateMapper { public interface ClientTemplateMapper {
@Select("select * from client_template where sign_id = #{signId}") @Select("select * from client_template where sign_id = #{signId}")
List<ClientTemplate> findBySignId(@Param("signId") Long signId); List<ClientTemplate> findBySignId(@Param("signId") Long signId);
} }

@ -0,0 +1,52 @@
package com.mashibing.test.mapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mashibing.test.client.CacheClient;
import com.mashibing.test.entity.ClientTemplate;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static org.junit.Assert.*;
/**
* @author kezhen
* @date 2022/12/28
* @description
*/
@SpringBootTest
@RunWith(SpringRunner.class)
public class ClientTemplateMapperTest {
@Autowired
private ClientTemplateMapper clientTemplateMapper;
@Autowired
private CacheClient cacheClient;
@Test
public void findBySignId() {
List<ClientTemplate> clientTemplateList = clientTemplateMapper.findBySignId(15L);
List<ClientTemplate> clientTemplateList2 = clientTemplateMapper.findBySignId(24L);
for (ClientTemplate clientTemplate : clientTemplateList) {
System.out.println("clientTemplate = " + clientTemplate);
}
ObjectMapper objectMapper = new ObjectMapper();
List<Map> value = clientTemplateList.stream().map(clientTemplate -> {
try {
return objectMapper.readValue(objectMapper.writeValueAsString(clientTemplate), Map.class);
} catch (JsonProcessingException e) {
e.printStackTrace();
return null;
}
}).collect(Collectors.toList());
cacheClient.sadd("client_template:15", value.toArray(new Map[]{}));
}
}
Loading…
Cancel
Save