1.添加按时间段更新功能接口

2.调整redis配置
zhairh
x_z 2 years ago
parent 986eb2132a
commit f4774578fb

@ -107,6 +107,11 @@
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--热部署插件-->
<dependency>
<groupId>org.springframework.boot</groupId>
@ -120,11 +125,6 @@
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
@ -138,6 +138,12 @@
<artifactId>fastjson</artifactId>
<version>2.0.2</version>
</dependency>
<!--GSON-->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10</version>
</dependency>
<!--JWT-->
<dependency>
@ -152,6 +158,11 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.9</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
@ -161,12 +172,6 @@
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.5.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
@ -174,12 +179,6 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>4.2.3</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>

@ -35,4 +35,14 @@ public interface Constant {
*/
String LOG_TYPE_ERROR = "error";
/**
* -
*/
Integer TASK_TYPE_DOWNLOAD = 0;
/**
* -
*/
Integer TASK_TYPE_UPDATE = 1;
}

@ -10,4 +10,6 @@ public interface CompanyMapper extends BaseMapper<CompanyEntity> {
boolean modifyCompany(CompanyEntity companyEntity);
boolean insertCompany(CompanyEntity companyEntity);
CompanyEntity findByTaskType(Integer taskType);
}

@ -81,7 +81,8 @@ public class DeviceDownloadService {
public String getToken() {
token = redisUtil.get("UDISYNC_TOKEN");
if (StrUtil.isEmpty(token)) {
companyEntity = companyService.findCompany();
//查询下载数据使用的appid
companyEntity = companyService.findByTaskType(Constant.TASK_TYPE_DOWNLOAD);
TokenRequest tokenRequest = new TokenRequest();
tokenRequest.setAppId(companyEntity.getAppId());
tokenRequest.setAppSecret(companyEntity.getAppSecret());
@ -106,7 +107,7 @@ public class DeviceDownloadService {
}
} catch (Exception e) {
e.printStackTrace();
log.error("国家库网络服务器异常", e);
return "国家库网络服务器异常!";
}
}
@ -604,7 +605,7 @@ public class DeviceDownloadService {
jobLog.setCreateTime(new Date());
jobLogService.insert(jobLog);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(), e);
JobLog jobLog = new JobLog();
jobLog.setDownloadType(Constant.DOWNLOAD_TYPE_MANUAL);
jobLog.setType(Constant.LOG_TYPE_ERROR);

@ -9,6 +9,8 @@ public interface CompanyService {
CompanyEntity findCompany();
CompanyEntity findByTaskType(Integer taskType);
CompanyEntity findByTyshxydm(String tyshxydm);
boolean modifyCompany(CompanyEntity companyEntity);

@ -28,6 +28,11 @@ public class CompanyServiceImpl implements CompanyService {
return companyDao.findCompany();
}
@Override
public CompanyEntity findByTaskType(Integer taskType) {
return companyDao.findByTaskType(taskType);
}
@Override
public CompanyEntity findByTyshxydm(String tyshxydm) {
return companyDao.selectOne(new QueryWrapper<CompanyEntity>().eq("tyshxydm", tyshxydm));

@ -19,6 +19,7 @@ import java.util.List;
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class JobLogServiceImpl implements JobLogService {
@Resource
@ -41,18 +42,16 @@ public class JobLogServiceImpl implements JobLogService {
return jobLogMapper.selectById(jobId);
}
@Transactional(rollbackFor = Exception.class)
public int insert(JobLog jobLog) {
return jobLogMapper.insert(jobLog);
}
@Transactional(rollbackFor = Exception.class)
public int update(JobLog jobLog) {
return jobLogMapper.updateById(jobLog);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int insertLog(JobLog jobLog) {
int insert = jobLogMapper.insert(jobLog);
return insert;

@ -1,11 +1,11 @@
package com.glxp.udidl.admin.util;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.db.nosql.redis.RedisDS;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import javax.annotation.Resource;
import java.util.Set;
/**
@ -13,32 +13,96 @@ import java.util.Set;
*/
@Slf4j
@Component
public class RedisUtil {
public class RedisUtil<T> {
private final Jedis jedis = RedisDS.create().getJedis();
@Resource
private RedisTemplate<String, Object> redisTemplate;
/**
* key
*
* @param key
* @return
*/
public String get(String key) {
return jedis.get(key);
return String.valueOf(redisTemplate.opsForValue().get(key));
}
public String setEx(String key, String value, long expireTime) {
return jedis.setex(key, expireTime, value);
/**
* Objectkey
*
* @param key
* @return
*/
public Object getObj(String key) {
return redisTemplate.opsForValue().get(key);
}
/**
* key
*
* @param key
* @param value
* @param expireTime
* @return
*/
public boolean setEx(String key, String value, long expireTime) {
boolean result = false;
try {
redisTemplate.opsForValue().set(key, value, expireTime);
result = true;
} catch (Exception e) {
log.error("RedisUtil setEx 发生异常参数列表key {} value {}", key, value, e);
}
return result;
}
/**
* key
*
* @param key
* @return
*/
public boolean exist(String key) {
return jedis.exists(key);
return redisTemplate.hasKey(key);
}
/**
*
*
* @param key
* @return
*/
public long getExpireTime(String key) {
return jedis.ttl(key);
return redisTemplate.getExpire(key);
}
public String set(String key, String value) {
return jedis.set(key, value);
/**
* key
*
* @param key
* @param value
* @return
*/
public boolean set(String key, T value) {
boolean result = false;
try {
redisTemplate.opsForValue().set(key, value);
result = true;
} catch (Exception e) {
log.error("RedisUtil set 发生异常参数列表key {} value {}", key, value, e);
}
return result;
}
/**
*
*
* @param key
* @return
*/
public boolean getLock(String key) {
if (jedis.exists(key)) {
if (exist(key)) {
long expireTime = getExpireTime(key);
try {
Thread.sleep(expireTime * 1000);
@ -49,13 +113,43 @@ public class RedisUtil {
return true;
}
/**
* key
*
* @param key
* @return
*/
public Set<String> keys(String key) {
return redisTemplate.keys(key);
}
/**
* key
*
* @param key
* @return
*/
public boolean del(String key) {
boolean result = false;
try {
redisTemplate.delete(key);
result = true;
} catch (Exception e) {
log.error("RedisUtil del 删除key值key {} ", key, e);
}
return result;
}
//模糊匹配删除
/**
*
*
* @param prex
*/
public void deleteByPrex(String prex) {
Set<String> keys = jedis.keys(prex);
Set<String> keys = keys(prex);
if (CollUtil.isNotEmpty(keys)) {
for (String str : keys) {
jedis.del(str);
for (String key : keys) {
del(key);
}
}
}

@ -4,7 +4,7 @@ spring:
matching-strategy: ant_path_matcher
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.0.66:3360/udidl_test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
url: jdbc:mysql://127.0.0.1:3306/udidl_test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: root
hikari:
@ -12,6 +12,17 @@ spring:
connection-timeout: 100000 #设置等待超时时间为10秒
maximum-pool-size: 60
minimum-idle: 10
redis:
host: 127.0.0.1
port: 6379
password:
connect-timeout: 5000ms
lettuce:
pool:
max-active: 60
max-idle: 10
min-idle: 5
max-wait: 5000ms
servlet:
multipart:

@ -38,5 +38,7 @@
#{tyshxydm})
</insert>
<select id="findByTaskType" resultType="com.glxp.udidl.admin.entity.info.CompanyEntity">
select * from company where taskType = #{taskType}
</select>
</mapper>

@ -1,13 +0,0 @@
package com.glxp.udidl.admin;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ApiAdminApplicationTests {
@Test
void contextLoads() {
}
}
Loading…
Cancel
Save