Commit 499bdf4a by 李辅翼

v1

parents
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
### VS Code ###
.vscode/
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.Properties;
public class MavenWrapperDownloader {
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL =
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: : " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.hikcreate</groupId>
<artifactId>ftp_pic</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ftp_pic</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/ojdbc6-11.2.0.3.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>1.1.0-cdh5.15.1</version>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
<exclusions>
<exclusion>
<artifactId>log4j-over-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.51</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.hikcreate;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
public class FtpPicApplication {
public static void main(String[] args) {
SpringApplication.run(FtpPicApplication.class, args);
}
}
package com.hikcreate.controller;
import com.alibaba.fastjson.JSONObject;
import com.hikcreate.drv_photo_pic.DrvPhoto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
/**
* @author lifuyi
* @date ${Date}
* @description
*/
@RestController
@RequestMapping("/pic")
@Validated
public class PicController {
@Autowired
private DrvPhoto drvPhoto;
@GetMapping("/drvPhotoHis")
public void getHisDrvPhoto(@RequestParam("time") String time, HttpServletResponse response){
try {
boolean result=drvPhoto.getHisDrvPhoto(time);
JSONObject jsonObject = new JSONObject();
jsonObject.put("result",result);
response.setContentType("application/json;charset=UTF-8");
response.getWriter().write(jsonObject.toJSONString());
}catch (Exception e) {
e.printStackTrace();
}
}
}
package com.hikcreate.drv_photo_pic;
import org.springframework.stereotype.Service;
/**
* @author lifuyi
* @date ${Date}
* @description
*/
public interface DrvPhoto {
boolean getHisDrvPhoto(String time);
}
package com.hikcreate.drv_photo_pic.impl;
import com.hikcreate.drv_photo_pic.DrvPhoto;
import com.hikcreate.utils.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
/**
* @author lifuyi
* @date ${Date}
* @description
*/
@Service("drvPhotoImpl")
public class DrvPhotoImpl implements DrvPhoto {
private static Logger logger = LoggerFactory.getLogger(DrvPhotoImpl.class);
@Value("${url}")
private static String url;
@Value("${username}")
private static String username;
@Value("${password}")
private static String password;
@Value("${roundDay}")
private static int roundDay;
private static String startTime;
private static String endTime;
private static String sfzmhm;
/**
* 同步历史图片,图片同步到time时间
*
* @param time
* @return
*/
@Override
public boolean getHisDrvPhoto(String time) {
try {
endTime = time;
Class.forName("oracle.jdbc.OracleDriver");
Connection connection1 = DriverManager.getConnection(url, username, password);
//获取最小时间
String minTimeSql = "select min(GXSJ) mtime from GYJG.DRV_PHOTO";
PreparedStatement pstm1 = connection1.prepareStatement(minTimeSql);
ResultSet resultSet1 = pstm1.executeQuery();
while (resultSet1.next()) {
startTime = resultSet1.getString("MTIME").substring(0, 10);
}
resultSet1.close();
pstm1.close();
connection1.close();
//循环获取图片
String sql;
String lastTime;
while (endTime.compareTo(startTime) > 0 || endTime.compareTo(startTime) == 0) {
lastTime = DateUtil.formatDate(DateUtil.getPastDate(DateUtil.parseDate(endTime), roundDay));
Connection connection = DriverManager.getConnection(url, username, password);
sql = "select * from GYJG.DRV_PHOTO where to_char(GXSJ,'yyyy-mm-dd')>='" + lastTime + "' and to_char(GXSJ,'yyyy-mm-dd')<'"
+ endTime + "' and ZP is not null and fzjg is not null and sfzmhm is not null";
PreparedStatement pstm = connection.prepareStatement(sql);
ResultSet resultSet = pstm.executeQuery();
while (resultSet.next()) {
}
endTime = lastTime;
resultSet.close();
pstm.close();
connection.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
return true;
}
public static void main(String[] args) {
String s = "2019-07-02";
String s1 = DateUtil.formatDate(DateUtil.getPastDate(DateUtil.parseDate(s), -4));
System.out.println(s1);
String time = "2019-07-02 00:00:00";
System.out.println(time.substring(0, 10));
System.out.println(s.compareTo(time.substring(0, 10)));
}
}
package com.hikcreate.illegalPic;
/**
* @author lifuyi
* @date ${Date}
* @description
*/
public class synchronizationDay {
}
package com.hikcreate.utils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* @author lifuyi
* @date ${Date}
* @description
*/
public class DateUtil extends DateUtils {
private static String[] parsePatterns = {
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
/**
* 得到当前日期字符串 格式(yyyy-MM-dd)
*/
public static String getDate() {
return getDate("yyyy-MM-dd");
}
/**
* 得到当前日期字符串 格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E"
*/
public static String getDate(String pattern) {
return DateFormatUtils.format(new Date(), pattern);
}
/**
* 得到日期字符串 默认格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E"
*/
public static String formatDate(Date date, Object... pattern) {
if (date == null) {
return null;
}
String formatDate = null;
if (pattern != null && pattern.length > 0) {
formatDate = DateFormatUtils.format(date, pattern[0].toString());
} else {
formatDate = DateFormatUtils.format(date, "yyyy-MM-dd");
}
return formatDate;
}
/**
* 得到日期时间字符串,转换格式(yyyy-MM-dd HH:mm:ss)
*/
public static String formatDateTime(Date date) {
return formatDate(date, "yyyy-MM-dd HH:mm:ss");
}
/**
* 得到当前时间字符串 格式(HH:mm:ss)
*/
public static String getTime() {
return formatDate(new Date(), "HH:mm:ss");
}
/**
* 得到当前日期和时间字符串 格式(yyyy-MM-dd HH:mm:ss)
*/
public static String getDateTime() {
return formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
}
/**
* 得到当前年份字符串 格式(yyyy)
*/
public static String getYear() {
return formatDate(new Date(), "yyyy");
}
/**
* 得到当前月份字符串 格式(MM)
*/
public static String getMonth() {
return formatDate(new Date(), "MM");
}
/**
* 得到当天字符串 格式(dd)
*/
public static String getDay() {
return formatDate(new Date(), "dd");
}
/**
* 得到当前星期字符串 格式(E)星期几
*/
public static String getWeek() {
return formatDate(new Date(), "E");
}
/**
* 日期型字符串转化为日期 格式
* { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm",
* "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm",
* "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm" }
*/
public static Date parseDate(Object str) {
if (str == null) {
return null;
}
try {
return parseDate(str.toString(), parsePatterns);
} catch (Exception e) {
return null;
}
}
/**
* 获取过去的天数
*
* @param date
* @return
*/
public static long pastDays(Date date) {
long t = new Date().getTime() - date.getTime();
return t / (24 * 60 * 60 * 1000);
}
/**
* 获取过去的小时
*
* @param date
* @return
*/
public static long pastHour(Date date) {
long t = new Date().getTime() - date.getTime();
return t / (60 * 60 * 1000);
}
/**
* 获取过去的分钟
*
* @param date
* @return
*/
public static long pastMinutes(Date date) {
long t = new Date().getTime() - date.getTime();
return t / (60 * 1000);
}
/**
* 转换为时间(天,时:分:秒.毫秒)
*
* @param timeMillis
* @return
*/
public static String formatDateTime(long timeMillis) {
long day = timeMillis / (24 * 60 * 60 * 1000);
long hour = (timeMillis / (60 * 60 * 1000) - day * 24);
long min = ((timeMillis / (60 * 1000)) - day * 24 * 60 - hour * 60);
long s = (timeMillis / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
long sss = (timeMillis - day * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000 - s * 1000);
return (day > 0 ? day + "," : "") + hour + ":" + min + ":" + s + "." + sss;
}
/**
* 获取两个日期之间的天数
*
* @param before
* @param after
* @return
*/
public static double getDistanceOfTwoDate(Date before, Date after) {
long beforeTime = before.getTime();
long afterTime = after.getTime();
return (afterTime - beforeTime) / (1000 * 60 * 60 * 24);
}
public static String getFirstDayOfMonth() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//获取当前月第一天:
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, 0);
//设置为1号,当前日期既为本月第一天
c.set(Calendar.DAY_OF_MONTH, 1);
String first = format.format(c.getTime());
return first;
}
/**
* 将毫秒转为时间格式字符串
* @param mil
* @param format
* @return
*/
public static String timeStamp2Date(long mil, String format) {
String seconds=(mil/1000)+"";
if (seconds == null || seconds.isEmpty() || seconds.equals("null")) {
return "";
}
if (format == null || format.isEmpty()) {
format = "yyyy-MM-dd HH:mm:ss";
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(new Date(Long.valueOf(seconds + "000")));
}
/**
* 将日期加减固定天数
* @param date
* @param num
* @return
*/
public static Date getPastDate(Date date,int num){
Calendar begin=Calendar.getInstance();
begin.setTime(date);
begin.add(Calendar.DAY_OF_MONTH,num);
return begin.getTime();
}
}
package com.hikcreate.utils.redis;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* @auther: lifuyi
* @date: 2019/1/31 10:55
* @description:
*/
public class PropertyUtil {
private static final Logger logger = LoggerFactory.getLogger(PropertyUtil.class);
private static Properties props;
static {
loadProps("common-config.properties");
}
public static String getProperty(String key) {
if (null == props) {
throw new NullPointerException("props is null");
}
return props.getProperty(key);
}
public static String getProperty(String key, String defaultValue) {
if (null == props) {
throw new NullPointerException("props is null");
}
return props.getProperty(key, defaultValue);
}
private Properties getProps(String path) {
if (props == null) {
loadProps(path);
}
return props;
}
private synchronized static void loadProps(String path) {
props = new Properties();
InputStream in = null;
try {
path = path;
in = PropertyUtil.class.getClassLoader().getResourceAsStream(path);
props.load(in);
} catch (FileNotFoundException e) {
logger.error("loadProps error", e);
} catch (IOException e) {
logger.error("loadProps error", e);
} finally {
try {
if (null != in) {
in.close();
}
} catch (IOException e) {
}
}
}
}
package com.hikcreate.utils.redis;
import org.springframework.util.StringUtils;
import redis.clients.jedis.JedisCluster;
/**
* Copyright (C)
* All rights reserved
* <p>
* 项目名称 : RTComputation
* 项目描述:
* <p>
* com.zcreator.bigdata.rtc.common.redis
* <p>
* created by guangzhong.wgz
* date time 2018/11/22
**/
public class RedisBuilder {
/**
* @param hosts
* @return
*/
public static synchronized RedisClient getRedisClient(String hosts) {
if (StringUtils.isEmpty(hosts)) {
throw new RuntimeException("hosts is empty");
}
JedisCluster jedisCluster = RedisUtils.getClusterClient(hosts);
return new RedisClient(jedisCluster);
}
}
package com.hikcreate.utils.redis;
import redis.clients.jedis.JedisCluster;
import java.util.List;
import java.util.Set;
/**
* @auther: lifuyi
* @date: 2019/1/31 10:53
* @description:
*/
public class RedisClient {
public final static String VIRTUAL_COURSE_PREX = "_lc_vc_";
private JedisCluster jedisCluster;
public RedisClient() {
}
public RedisClient(JedisCluster jedisCluster) {
this.jedisCluster = jedisCluster;
}
/**
* 获取单值
*
* @param key
* @return
*/
public String get(String key) {
return jedisCall((redis) -> redis.get(key));
}
public boolean setList(String key, List<String> deviceIPList){
return jedisCall((redis)->{
redis.del(key);
for(String string:deviceIPList){
redis.lpush(key,string);
}
return true;
});
}
public List<String> getObjectList(String key){
return jedisCall((redis)->redis.lrange(key, 0, -1));
}
/**
* 设置List缓存
* @param key 键
* @param value 值
* @param cacheSeconds 超时时间,0为不超时
* @return
*/
public long setList(String key, List<String> value, int cacheSeconds) {
return jedisCall((redis) -> {
long result = 0;
if(redis.exists(key)){
redis.del(key);
}
String[] strArr = new String[value.size()];
redis.rpush(key, value.toArray(strArr));
if (cacheSeconds != 0) {
redis.expire(key, cacheSeconds);
}
return result;
});
}
/**
* 写入值
*
* @param key
* @param value
* @return
*/
public String set(String key, String value) {
return jedisCall((redis) -> redis.set(key, value));
}
/**
* 自增计数
*
* @param key
* @return
*/
public Long incr(String key) {
return jedisCall((redis) -> redis.incr(key));
}
/**
* 自增计数
*
* @param key
* @param value 初始值
* @return
*/
public Long incrBy(String key, long value) {
return jedisCall((redis) -> redis.incrBy(key, value));
}
/**
* 自减计数
*
* @param key
* @return
*/
public Long decr(String key) {
return jedisCall((redis) -> redis.decr(key));
}
/**
* 自减计数
*
* @param key
* @param value 初始值
* @return
*/
public Long decrBy(String key, long value) {
return jedisCall((redis) -> redis.decrBy(key, value));
}
/**
* 批量获取值
*
* @param keys
* @return
*/
public List<String> mget(String... keys) {
return jedisCall((redis) -> redis.mget(keys));
}
/**
* 存储范围值
*
* @param key
* @param offset
* @param value
* @return
*/
public Long setRange(String key, long offset, String value) {
return jedisCall((redis) -> redis.setrange(key, offset, value));
}
/**
* 获取指定范围的值
*
* @param key
* @param startOffset
* @param endOffset
* @return
*/
public String getRange(String key, int startOffset, int endOffset) {
return jedisCall((redis) -> redis.getrange(key, startOffset, endOffset));
}
/**
* 指定过期时间存储值
*
* @param key
* @param keepaliveLong 单位秒
* @param value
* @return
*/
public String setex(String key, int keepaliveLong, String value) {
return jedisCall((redis) -> redis.setex(key, keepaliveLong, value));
}
/**
* 从左边写入
*
* @param key
* @param value
* @return
*/
public Long lpush(String key, String value) {
return jedisCall((redis) -> redis.lpush(key, value));
}
/**
* 出桡
*
* @param key
* @return
*/
public String lpop(String key) {
return jedisCall((redis) -> redis.lpop(key));
}
/**
* 从左边开始获取
*
* @param key
* @param start
* @param end
* @return
*/
public List<String> lrange(String key, long start, long end) {
return jedisCall((redis) -> redis.lrange(key, start, end));
}
/**
* 删出指定的值
*
* @param key
* @param count 删出的个数
* @param value 指定的值
* @return
*/
public Long lrem(String key, long count, String value) {
return jedisCall((redis) -> redis.lrem(key, count, value));
}
/**
* 返回数据长度
*
* @param key
* @return
*/
public Long lrem(String key) {
return jedisCall((redis) -> redis.llen(key));
}
/**
* 删出下标这外的元数
*
* @param key
* @return
*/
public String ltrim(String key, long start, long end) {
return jedisCall((redis) -> redis.ltrim(key, start, end));
}
/**
* 获取指定下标的元素
*
* @param key
* @param offSet 下标位置
* @return
*/
public String lindex(String key, long offSet) {
return jedisCall((redis) -> redis.lindex(key, offSet));
}
/**
* set集合新增
*
* @param key
* @param value 值
* @return
*/
public Long sadd(String key, String value) {
return jedisCall((redis) -> redis.sadd(key, value));
}
/**
* 返回sets集合所有值
*
* @param key
* @return
*/
public Set<String> smembers(String key) {
return jedisCall((redis) -> redis.smembers(key));
}
/**
* 删出sets集合指定的值
*
* @param key
* @return
*/
public Long srem(String key, String value) {
return jedisCall((redis) -> redis.srem(key, value));
}
/**
* 指定的值是否存在sets集合中
*
* @param key
* @return
*/
public Boolean sismember(String key, String value) {
return jedisCall((redis) -> redis.sismember(key, value));
}
/**
* sets集合求交集
*
* @param keys
* @return
*/
public Set<String> sinter(String... keys) {
return jedisCall((redis) -> redis.sinter(keys));
}
/**
* sets集合求并集
*
* @param keys
* @return
*/
public Set<String> sunion(String... keys) {
return jedisCall((redis) -> redis.sunion(keys));
}
/**
* sets集合求差集
*
* @param keys
* @return
*/
public Set<String> sdiff(String... keys) {
return jedisCall((redis) -> redis.sdiff(keys));
}
/**
* zset中添加元素
*
* @param key
* @param score 权重
* @param value
* @return
*/
public Long zadd(String key, double score, String value) {
return jedisCall((redis) -> redis.zadd(key, score, value));
}
/**
* 按照权重值排序
*
* @param key
* @param start (0, 开始)
* @param end (-1, 取到最后)
* @return
*/
public Set<String> zrange(String key, long start, long end) {
return jedisCall((redis) -> redis.zrange(key, start, end));
}
/**
* 删出指定的值
*
* @param key
* @param value
* @return
*/
public Long zrem(String key, String value) {
return jedisCall((redis) -> redis.zrem(key, value));
}
/**
* 统计zset集合中的元素中
*
* @param key
* @return
*/
public Long zcard(String key) {
return jedisCall((redis) -> redis.zcard(key));
}
/**
* 查看zset集合中value权重
*
* @param key
* @param value
* @return
*/
public double zscore(String key, String value) {
return jedisCall((redis) -> redis.zscore(key, value));
}
/**
* 统计zset集合中权重某个范围内(1.0——5.0),元素的个数
*
* @param key
* @param min
* @param max
* @return
*/
public Long zcount(String key, double min, double max) {
return jedisCall((redis) -> redis.zcount(key, min, max));
}
/**
* hashs中添加元数
*
* @param key
* @param field
* @param value
* @return
*/
public Long hset(String key, String field, String value) {
return jedisCall((redis) -> redis.hset(key, field, value));
}
/**
* hashs中添加整型元数
*
* @param key
* @param field
* @param value
* @return
*/
public Long hincrBy(String key, String field, long value) {
return jedisCall((redis) -> redis.hincrBy(key, field, value));
}
/**
* 返回hashs中的所有值
*
* @param key
* @return
*/
public List<String> hvals(String key) {
return jedisCall((redis) -> redis.hvals(key));
}
/**
* hashs中删除键值对
*
* @param key
* @return
*/
public Long hdel(String key, String field) {
return jedisCall((redis) -> redis.hdel(key, field));
}
/*
根据key进行删除
*/
public Long del(String key) {
return jedisCall((redis) -> redis.del(key));
}
/**
* hashs中判断是否存在
*
* @param key
* @param field
* @return
*/
public Boolean hexists(String key, String field) {
return jedisCall((redis) -> redis.hexists(key, field));
}
/**
* hashs中获取对应的值
*
* @param key
* @param field
* @return
*/
public String hget(String key, String field) {
return jedisCall((redis) -> redis.hget(key, field));
}
/**
* hashs中获取多个对应的值
*
* @param key
* @param field
* @return
*/
public List<String> hmget(String key, String... field) {
return jedisCall((redis) -> redis.hmget(key, field));
}
/**
* 获取hashs中所有的key
*
* @param key
* @return
*/
public Set<String> hkeys(String key) {
return jedisCall((redis) -> redis.hkeys(key));
}
/**
* 指定key有效期
* @param key
* @param seconds
* @return
*/
public Long expire(String key, Integer seconds) {
return jedisCall((redis) -> redis.expire(key, seconds));
}
/**
* 判断指定key是否存在
* @param key
* @return
*/
public boolean exitsKey(String key){
return jedisCall((redis)->redis.exists(key));
}
/**
* 清除所有数据, 慎用
*/
public String flushDatabase() {
return jedisCall((redis) -> redis.flushDB());
}
private String buildKey(String bkey) {
return VIRTUAL_COURSE_PREX + bkey;
}
@FunctionalInterface
interface JedisFunction<R> {
R call(JedisCluster jedis);
}
private <R> R jedisCall(JedisFunction<R> function) {
if (jedisCluster == null) {
String hosts = PropertyUtil.getProperty("redis.cluster");
jedisCluster = RedisUtils.getClusterClient(hosts);
}
try {
return function.call(jedisCluster);
} finally {
}
}
}
package com.hikcreate.utils.redis;
/**
* @auther: lifuyi
* @date: 2019/1/31 10:53
* @description:
*/
public class RedisClientUtil {
private static RedisClient redisClient;
public static RedisClient getRedisClient() {
if (redisClient == null) {
synchronized (RedisClientUtil.class) {
redisClient = RedisBuilder.getRedisClient(PropertyUtil.getProperty("redis.server"));
}
}
return redisClient;
}
}
package com.hikcreate.utils.redis;
import org.springframework.util.StringUtils;
import redis.clients.jedis.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;
public class RedisUtils {
// 非切片连接池
private static JedisPool jedisPool;
// 非切片连接池
private static JedisSentinelPool jedisSentinelPool;
// 切片连接池
private static ShardedJedisPool shardedJedisPool;
private static JedisPoolConfig config;
private static JedisCluster jedisCluster;
static {
config = new JedisPoolConfig();
config.setMaxTotal(20);
config.setMaxIdle(5);
config.setMaxWaitMillis(1000l);
config.setTestOnBorrow(false);
config.setJmxEnabled(true);
}
public static Jedis getJedisSentinelPool() {
if (jedisSentinelPool == null) {
synchronized (RedisUtils.class) {
if (jedisSentinelPool == null) {
// JedisSentinelPool 初始化
String masterName = "cdh6";
//sentinel地址集合
Set<String> set = new HashSet<>();
set.add("10.1.80.4:26379");
set.add("10.1.80.5:26379");
set.add("10.1.80.7:26379");
jedisSentinelPool = new JedisSentinelPool(masterName, set, config);
}
}
}
return jedisSentinelPool.getResource();
}
public static Jedis getJedis() {
if (jedisPool == null) {
synchronized (RedisUtils.class) {
Set<HostAndPort> jedisClusterNodes = new HashSet<>();
jedisClusterNodes.add(new HostAndPort("10.1.80.8", 6379));
JedisCluster jc = new JedisCluster(jedisClusterNodes);
}
}
return jedisPool.getResource();
}
public static ShardedJedis getShardedJedis() {
//初始化非切片池
List<JedisShardInfo> shards = new ArrayList<>();
shards.add(new JedisShardInfo("cd1", 6379, "master"));
shards.add(new JedisShardInfo("cd2", 6379, "master"));
shards.add(new JedisShardInfo("cd3", 6379, "master"));
shards.add(new JedisShardInfo("cd4", 6379, "master"));
shards.add(new JedisShardInfo("cd5", 6379, "master"));
shards.add(new JedisShardInfo("cd6", 6379, "master"));
shards.add(new JedisShardInfo("cd7", 6379, "master"));
shards.add(new JedisShardInfo("cd8", 6379, "master"));
shardedJedisPool = new ShardedJedisPool(config, shards);
ShardedJedis shardedJedis = shardedJedisPool.getResource();
return shardedJedis;
}
public static JedisCluster getClusterClient(String hosts) {
if (jedisCluster == null) {
synchronized (RedisUtils.class) {
if (jedisCluster == null) {
if (StringUtils.isEmpty(hosts)) {
throw new RuntimeException("hosts is empty");
}
Set<HostAndPort> jedisClusterNodes = new HashSet<>();
String[] hostStr = hosts.split(",");
Stream.of(hostStr).forEach(host -> {
String args[] = host.split(":");
if (args.length != 2) {
throw new RuntimeException("host format error");
}
jedisClusterNodes.add(new HostAndPort(args[0], Integer.parseInt(args[1])));
});
jedisCluster = new JedisCluster(jedisClusterNodes);
}
}
}
return jedisCluster;
}
public static void getOne() {
Jedis jedis = new Jedis("cdh1");
jedis.set("foo", "bar");
String value = jedis.get("foo");
}
}
\ No newline at end of file
url=jdbc:oracle:thin:@172.16.17.82:1521:gyjg
username=gyjg_zckj
password=zckj2018
roundDay=-5
redis.cluster=172.16.25.23:7000,172.16.25.23:7001,172.16.25.23:7002,172.16.25.24:7003,172.16.25.24:7004,172.16.25.24:7005
redis.server=172.16.25.23:7000,172.16.25.23:7001,172.16.25.23:7002,172.16.25.24:7003,172.16.25.24:7004,172.16.25.24:7005
package com.hikcreate;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class FtpPicApplicationTests {
@Test
public void contextLoads() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment