upd
parent
1f8d0d4626
commit
0d67b74f99
|
@ -18,6 +18,18 @@
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- 1、 Jedis-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>redis.clients</groupId>
|
||||||
|
<artifactId>jedis</artifactId>
|
||||||
|
<version>2.9.0</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- 2、 Junit测试-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.12</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baidu.aip</groupId>
|
<groupId>com.baidu.aip</groupId>
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
package com.dragon.vehicle.company.common.utils;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.JavaType;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JsonUtils工具类
|
||||||
|
*
|
||||||
|
* @author HuZhiYong
|
||||||
|
* @version 2023/11/21 - 21:27
|
||||||
|
*/
|
||||||
|
public class JsonUtils {
|
||||||
|
private static final ObjectMapper MAPPER =new ObjectMapper();
|
||||||
|
private static JavaType JavaType;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将对象转换成json字符串
|
||||||
|
* @param data
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String objectToJson(Object data){
|
||||||
|
try {
|
||||||
|
String string = MAPPER.writeValueAsString(data);
|
||||||
|
return string;
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将json结果集转化为对象
|
||||||
|
* @param jsonData
|
||||||
|
* @param beanType
|
||||||
|
* @return
|
||||||
|
* @param <T>
|
||||||
|
*/
|
||||||
|
public static <T> T jsonToPojo(String jsonData,Class<T> beanType){
|
||||||
|
try {
|
||||||
|
T t=MAPPER.readValue(jsonData,beanType);
|
||||||
|
return t;
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static <T>List<T> jsonToList(String jsonData,Class<T> beanType){
|
||||||
|
MAPPER.getTypeFactory().constructParametricType(List.class,beanType);
|
||||||
|
try {
|
||||||
|
List<T> list=MAPPER.readValue(jsonData, JavaType);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.dragon.vehicle.company.common.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* redis
|
||||||
|
*
|
||||||
|
* @author HuZhiYong
|
||||||
|
* @version 2023/11/21 - 21:09
|
||||||
|
*/
|
||||||
|
public interface RedisUtils {
|
||||||
|
public void hest(String key,String filed,String value);
|
||||||
|
public String hget(String key,String field);
|
||||||
|
public void set(String key,String value);
|
||||||
|
public String get(String key);
|
||||||
|
public void expire(String key,int seconds);
|
||||||
|
public long ttl(String key);
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.dragon.vehicle.company.common.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RedisUtils工具实现类
|
||||||
|
*
|
||||||
|
* @author HuZhiYong
|
||||||
|
* @version 2023/11/21 - 21:14
|
||||||
|
*/
|
||||||
|
public class SingleTonRedisUtil implements RedisUtils{
|
||||||
|
|
||||||
|
private Jedis jedis;
|
||||||
|
|
||||||
|
public SingleTonRedisUtil(Jedis jedis){
|
||||||
|
this.jedis=jedis;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hest(String key, String filed, String value) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String hget(String key, String field) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(String key, String value) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String get(String key) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void expire(String key, int seconds) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long ttl(String key) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,7 +13,7 @@ import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/firm")
|
@RequestMapping("/firm/company")
|
||||||
public class FirmController {
|
public class FirmController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -66,4 +66,7 @@ public class FirmController {
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,17 +11,24 @@ import com.dragon.common.core.web.page.TableDataInfo;
|
||||||
import com.dragon.vehicle.company.common.domain.FirmInfo;
|
import com.dragon.vehicle.company.common.domain.FirmInfo;
|
||||||
import com.dragon.vehicle.company.common.domain.req.FirmQueryReq;
|
import com.dragon.vehicle.company.common.domain.req.FirmQueryReq;
|
||||||
import com.dragon.vehicle.company.common.utils.BaiDuAiCheck;
|
import com.dragon.vehicle.company.common.utils.BaiDuAiCheck;
|
||||||
|
import com.dragon.vehicle.company.common.utils.JsonUtils;
|
||||||
|
import com.dragon.vehicle.company.common.utils.SingleTonRedisUtil;
|
||||||
import com.dragon.vehicle.company.server.mapper.FirmMapper;
|
import com.dragon.vehicle.company.server.mapper.FirmMapper;
|
||||||
import com.dragon.vehicle.company.server.service.FirmService;
|
import com.dragon.vehicle.company.server.service.FirmService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@Service
|
@Service
|
||||||
public class FirmServiceImpl extends ServiceImpl<FirmMapper, FirmInfo> implements FirmService {
|
public class FirmServiceImpl extends ServiceImpl<FirmMapper, FirmInfo> implements FirmService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SingleTonRedisUtil redisUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean save(FirmInfo entity) {
|
public boolean save(FirmInfo entity) {
|
||||||
|
|
||||||
|
@ -87,6 +94,12 @@ public class FirmServiceImpl extends ServiceImpl<FirmMapper, FirmInfo> implement
|
||||||
@Override
|
@Override
|
||||||
public TableDataInfo<FirmInfo> selectFirmList(FirmQueryReq firmQueryReq) {
|
public TableDataInfo<FirmInfo> selectFirmList(FirmQueryReq firmQueryReq) {
|
||||||
|
|
||||||
|
|
||||||
|
String firm = redisUtil.hget("firm", "0");
|
||||||
|
if (firm!=null){
|
||||||
|
log.info("get firm from redis");
|
||||||
|
List<FirmInfo> firmInfos= JsonUtils.jsonToList(firm, FirmInfo.class);
|
||||||
|
}
|
||||||
LambdaQueryWrapper<FirmInfo> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<FirmInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
if (StringUtils.isNotEmpty(firmQueryReq.getFirmName())){
|
if (StringUtils.isNotEmpty(firmQueryReq.getFirmName())){
|
||||||
queryWrapper.like(FirmInfo::getFirmName, firmQueryReq.getFirmName());
|
queryWrapper.like(FirmInfo::getFirmName, firmQueryReq.getFirmName());
|
||||||
|
@ -122,9 +135,15 @@ public class FirmServiceImpl extends ServiceImpl<FirmMapper, FirmInfo> implement
|
||||||
|
|
||||||
|
|
||||||
Page<FirmInfo> page = this.page(firmQueryReq.buildPage(), queryWrapper);
|
Page<FirmInfo> page = this.page(firmQueryReq.buildPage(), queryWrapper);
|
||||||
|
log.info("get frim from db");
|
||||||
|
String s = JsonUtils.objectToJson(page);
|
||||||
|
|
||||||
|
redisUtil.hest("firm","0",s);
|
||||||
|
log.info("set data to redis");
|
||||||
return TableDataInfo.<FirmInfo>builder()
|
return TableDataInfo.<FirmInfo>builder()
|
||||||
.rows(page.getRecords())
|
.rows(page.getRecords())
|
||||||
.total(page.getTotal())
|
.total(page.getTotal())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue