去除多余
parent
48df1cb55f
commit
062264caa7
|
@ -1,67 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -11,23 +11,18 @@ 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.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
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 {
|
||||||
|
|
||||||
@Resource
|
|
||||||
private SingleTonRedisUtil redisUtil;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean save(FirmInfo entity) {
|
public boolean save(FirmInfo entity) {
|
||||||
|
@ -95,11 +90,7 @@ public class FirmServiceImpl extends ServiceImpl<FirmMapper, FirmInfo> implement
|
||||||
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());
|
||||||
|
@ -135,11 +126,6 @@ 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())
|
||||||
|
|
Loading…
Reference in New Issue