You've already forked FrameTour-BE
删除无用内容
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
package com.ycwl.basic.constant;
|
package com.ycwl.basic.constant;
|
||||||
|
|
||||||
import com.ycwl.basic.utils.StringUtil;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -40,7 +40,13 @@ public class BaseContextHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getToken() {
|
public static String getToken() {
|
||||||
return StringUtil.a(get("currentUserToken"));
|
if (get("currentUserToken") == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(get("currentUserToken").toString())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return get("currentUserToken").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getAccount() {
|
public static String getAccount() {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.ycwl.basic.service.mobile.impl;
|
package com.ycwl.basic.service.mobile.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateField;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.ycwl.basic.enums.StatisticEnum;
|
import com.ycwl.basic.enums.StatisticEnum;
|
||||||
import com.ycwl.basic.mapper.StatisticsMapper;
|
import com.ycwl.basic.mapper.StatisticsMapper;
|
||||||
import com.ycwl.basic.model.jwt.JwtInfo;
|
import com.ycwl.basic.model.jwt.JwtInfo;
|
||||||
@ -11,7 +13,6 @@ import com.ycwl.basic.model.mobile.statistic.resp.AppSta3VO;
|
|||||||
import com.ycwl.basic.model.mobile.statistic.resp.AppStatisticsFunnelVO;
|
import com.ycwl.basic.model.mobile.statistic.resp.AppStatisticsFunnelVO;
|
||||||
import com.ycwl.basic.service.mobile.AppStatisticsService;
|
import com.ycwl.basic.service.mobile.AppStatisticsService;
|
||||||
import com.ycwl.basic.utils.ApiResponse;
|
import com.ycwl.basic.utils.ApiResponse;
|
||||||
import com.ycwl.basic.utils.DateUtils;
|
|
||||||
import com.ycwl.basic.utils.JwtTokenUtil;
|
import com.ycwl.basic.utils.JwtTokenUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -395,26 +396,25 @@ public class AppStatisticsServiceImpl implements AppStatisticsService {
|
|||||||
*/
|
*/
|
||||||
private void standardToNewSpecificTime(CommonQueryReq query) {
|
private void standardToNewSpecificTime(CommonQueryReq query) {
|
||||||
Integer standard = query.getStandard();
|
Integer standard = query.getStandard();
|
||||||
Date newDate = new Date();
|
Date newDate = DateUtil.beginOfDay(new Date());
|
||||||
Date startDate = new Date();
|
Date startDate = new Date();
|
||||||
Date endDate = new Date();
|
Date endDate = new Date();
|
||||||
switch (standard) {
|
switch (standard) {
|
||||||
case 4://年
|
case 4://年
|
||||||
startDate = DateUtils.addDateYears(newDate, -1);
|
startDate = DateUtil.offset(newDate, DateField.YEAR, -1);
|
||||||
break;
|
break;
|
||||||
case 3://月
|
case 3://月
|
||||||
startDate = DateUtils.addDateMonths(newDate, -1);
|
startDate = DateUtil.offset(newDate, DateField.MONTH, -1);
|
||||||
break;
|
break;
|
||||||
case 2://周
|
case 2://周
|
||||||
startDate = DateUtils.addDateWeeks(newDate, -1);
|
startDate = DateUtil.offsetWeek(newDate, -1);
|
||||||
break;
|
break;
|
||||||
case 1://昨天
|
case 1://昨天
|
||||||
Date yesterday = DateUtils.addDateDays(newDate, -1);
|
startDate = DateUtil.offsetDay(newDate, -1);
|
||||||
startDate = DateUtils.getStartOfDay(yesterday);
|
endDate = DateUtil.endOfDay(startDate);
|
||||||
endDate = DateUtils.getEndOfDay(yesterday);
|
|
||||||
break;
|
break;
|
||||||
case 0://今天
|
case 0://今天
|
||||||
startDate = DateUtils.getStartOfDay(newDate);
|
startDate = DateUtil.beginOfDay(newDate);
|
||||||
break;
|
break;
|
||||||
case 9://历史累计
|
case 9://历史累计
|
||||||
startDate = null;
|
startDate = null;
|
||||||
@ -433,31 +433,29 @@ public class AppStatisticsServiceImpl implements AppStatisticsService {
|
|||||||
*/
|
*/
|
||||||
private void standardToPreviousSpecificTime(CommonQueryReq query) {
|
private void standardToPreviousSpecificTime(CommonQueryReq query) {
|
||||||
Integer standard = query.getStandard();
|
Integer standard = query.getStandard();
|
||||||
Date newDate = new Date();
|
Date newDate = DateUtil.beginOfDay(new Date());
|
||||||
Date startDate = new Date();
|
Date startDate = new Date();
|
||||||
Date endDate = new Date();
|
Date endDate = new Date();
|
||||||
switch (standard) {
|
switch (standard) {
|
||||||
case 4://年,近一年的前一年
|
case 4://年,近一年的前一年
|
||||||
startDate = DateUtils.addDateYears(newDate, -2);
|
startDate = DateUtil.offset(newDate, DateField.YEAR, -2);
|
||||||
endDate = DateUtils.addDateYears(newDate, -1);
|
endDate = DateUtil.offset(newDate, DateField.YEAR, -1);
|
||||||
break;
|
break;
|
||||||
case 3://月,近一月的前一个月
|
case 3://月,近一月的前一个月
|
||||||
startDate = DateUtils.addDateMonths(newDate, -2);
|
startDate = DateUtil.offset(newDate, DateField.MONTH, -2);
|
||||||
endDate = DateUtils.addDateMonths(newDate, -1);
|
endDate = DateUtil.offset(newDate, DateField.MONTH, -1);
|
||||||
break;
|
break;
|
||||||
case 2://周,近一周的前一周
|
case 2://周,近一周的前一周
|
||||||
startDate = DateUtils.addDateWeeks(newDate, -2);
|
startDate = DateUtil.offsetWeek(newDate, -2);
|
||||||
endDate = DateUtils.addDateWeeks(newDate, -1);
|
endDate = DateUtil.offsetWeek(newDate, -1);
|
||||||
break;
|
break;
|
||||||
case 1://昨天,昨天的前一天
|
case 1://昨天,昨天的前一天
|
||||||
Date theDayBeforeYesterday = DateUtils.addDateDays(newDate, -2);
|
startDate = DateUtil.offsetDay(newDate, -2);
|
||||||
startDate = DateUtils.getStartOfDay(theDayBeforeYesterday);
|
endDate = DateUtil.offsetDay(newDate, -1);
|
||||||
endDate = DateUtils.getEndOfDay(theDayBeforeYesterday);
|
|
||||||
break;
|
break;
|
||||||
case 0://今天,今天的前一天
|
case 0://今天,今天的前一天
|
||||||
Date yesterday = DateUtils.addDateDays(newDate, -1);
|
startDate = DateUtil.offsetDay(newDate, -1);
|
||||||
startDate = DateUtils.getStartOfDay(yesterday);
|
endDate = DateUtil.endOfDay(startDate);
|
||||||
endDate = DateUtils.getEndOfDay(yesterday);
|
|
||||||
break;
|
break;
|
||||||
case 9://历史累计
|
case 9://历史累计
|
||||||
startDate = null;
|
startDate = null;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.ycwl.basic.service.mobile.impl;
|
package com.ycwl.basic.service.mobile.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.extra.qrcode.QrCodeUtil;
|
import cn.hutool.extra.qrcode.QrCodeUtil;
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
@ -40,14 +41,11 @@ import com.ycwl.basic.storage.StorageFactory;
|
|||||||
import com.ycwl.basic.storage.adapters.IStorageAdapter;
|
import com.ycwl.basic.storage.adapters.IStorageAdapter;
|
||||||
import com.ycwl.basic.storage.enums.StorageAcl;
|
import com.ycwl.basic.storage.enums.StorageAcl;
|
||||||
import com.ycwl.basic.utils.ApiResponse;
|
import com.ycwl.basic.utils.ApiResponse;
|
||||||
import com.ycwl.basic.utils.DateUtils;
|
|
||||||
import com.ycwl.basic.utils.WxMpUtil;
|
import com.ycwl.basic.utils.WxMpUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
@ -190,7 +188,7 @@ public class GoodsServiceImpl implements GoodsService {
|
|||||||
for (SourceRespVO sourceRespVO : list) {
|
for (SourceRespVO sourceRespVO : list) {
|
||||||
GoodsDetailVO goodsDetailVO = new GoodsDetailVO();
|
GoodsDetailVO goodsDetailVO = new GoodsDetailVO();
|
||||||
goodsDetailVO.setGoodsId(sourceRespVO.getId());
|
goodsDetailVO.setGoodsId(sourceRespVO.getId());
|
||||||
String shootingTime = DateUtils.format(sourceRespVO.getCreateTime(), "yyyy.MM.dd HH:mm:ss");
|
String shootingTime = DateUtil.format(sourceRespVO.getCreateTime(), "yyyy.MM.dd HH:mm:ss");
|
||||||
if (i < 10) {
|
if (i < 10) {
|
||||||
goodsDetailVO.setGoodsName(goodsNamePrefix + "0" + i + " " + shootingTime);
|
goodsDetailVO.setGoodsName(goodsNamePrefix + "0" + i + " " + shootingTime);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.ycwl.basic.service.pc.impl;
|
package com.ycwl.basic.service.pc.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.ycwl.basic.biz.OrderBiz;
|
import com.ycwl.basic.biz.OrderBiz;
|
||||||
@ -129,7 +129,7 @@ public class FaceServiceImpl implements FaceService {
|
|||||||
public FaceRecognizeResp faceUpload(MultipartFile file, Long scenicId, Long userId) {
|
public FaceRecognizeResp faceUpload(MultipartFile file, Long scenicId, Long userId) {
|
||||||
//1、上传人脸照片
|
//1、上传人脸照片
|
||||||
IStorageAdapter adapter = StorageFactory.use("faces");
|
IStorageAdapter adapter = StorageFactory.use("faces");
|
||||||
String filePath = StorageUtil.joinPath("user-faces", DateUtils.format(new Date(),"yyyy-MM-dd"));
|
String filePath = StorageUtil.joinPath("user-faces", DateUtil.format(new Date(),"yyyy-MM-dd"));
|
||||||
String originalFilename = file.getOriginalFilename();
|
String originalFilename = file.getOriginalFilename();
|
||||||
String suffix = originalFilename.split("\\.", 2)[1];
|
String suffix = originalFilename.split("\\.", 2)[1];
|
||||||
String fileName = UUID.randomUUID().toString() + "." + suffix;
|
String fileName = UUID.randomUUID().toString() + "." + suffix;
|
||||||
|
@ -46,7 +46,6 @@ import com.ycwl.basic.service.mobile.WxPayService;
|
|||||||
import com.ycwl.basic.service.pc.OrderService;
|
import com.ycwl.basic.service.pc.OrderService;
|
||||||
import com.ycwl.basic.service.task.impl.TaskTaskServiceImpl;
|
import com.ycwl.basic.service.task.impl.TaskTaskServiceImpl;
|
||||||
import com.ycwl.basic.utils.ApiResponse;
|
import com.ycwl.basic.utils.ApiResponse;
|
||||||
import com.ycwl.basic.utils.BigDecimalUtil;
|
|
||||||
import com.ycwl.basic.utils.SnowFlakeUtil;
|
import com.ycwl.basic.utils.SnowFlakeUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -55,6 +54,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -258,7 +258,7 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
wxPayOrderReqVO.setOpenId(order.getOpenId())
|
wxPayOrderReqVO.setOpenId(order.getOpenId())
|
||||||
.setMemberId(order.getMemberId())
|
.setMemberId(order.getMemberId())
|
||||||
.setOrderSn(order.getId())
|
.setOrderSn(order.getId())
|
||||||
.setTotalPrice(BigDecimalUtil.convertToCents(order.getPayPrice()))
|
.setTotalPrice(order.getPayPrice().setScale(2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).intValueExact())
|
||||||
.setGoodsName(goodsName)
|
.setGoodsName(goodsName)
|
||||||
.setDescription(goodsName);
|
.setDescription(goodsName);
|
||||||
|
|
||||||
|
@ -33,11 +33,7 @@ import com.ycwl.basic.repository.FaceRepository;
|
|||||||
import com.ycwl.basic.repository.ScenicRepository;
|
import com.ycwl.basic.repository.ScenicRepository;
|
||||||
import com.ycwl.basic.service.pc.ScenicService;
|
import com.ycwl.basic.service.pc.ScenicService;
|
||||||
import com.ycwl.basic.service.task.TaskFaceService;
|
import com.ycwl.basic.service.task.TaskFaceService;
|
||||||
import com.ycwl.basic.storage.StorageFactory;
|
|
||||||
import com.ycwl.basic.storage.adapters.IStorageAdapter;
|
|
||||||
import com.ycwl.basic.storage.utils.StorageUtil;
|
|
||||||
import com.ycwl.basic.task.VideoPieceGetter;
|
import com.ycwl.basic.task.VideoPieceGetter;
|
||||||
import com.ycwl.basic.utils.DateUtils;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
package com.ycwl.basic.utils;
|
|
||||||
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: songmingsong
|
|
||||||
* @CreateTime: 2024-12-06
|
|
||||||
* @Description: 小数转换
|
|
||||||
* @Version: 1.0
|
|
||||||
*/
|
|
||||||
public class BigDecimalUtil {
|
|
||||||
public static int convertToCents(BigDecimal price) {
|
|
||||||
if (price == null) {
|
|
||||||
throw new IllegalArgumentException("Price cannot be null");
|
|
||||||
}
|
|
||||||
return price
|
|
||||||
.setScale(2, RoundingMode.HALF_UP) // 保留两位小数
|
|
||||||
.multiply(new BigDecimal(100)) // 转换为分
|
|
||||||
.intValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,186 +0,0 @@
|
|||||||
package com.ycwl.basic.utils;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author wenshijia
|
|
||||||
* @date 2021年05月26日 23:02
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class CommonUtil {
|
|
||||||
/**
|
|
||||||
* 生成指定长度随机字母和数字
|
|
||||||
*/
|
|
||||||
private static final String ALL_CHAR_NUM = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
||||||
|
|
||||||
private static SecureRandom random;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
random = SecureRandom.getInstance("SHA1PRNG");
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取ip
|
|
||||||
*
|
|
||||||
* @param request
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String getIpAddr(HttpServletRequest request) {
|
|
||||||
String ipAddress = null;
|
|
||||||
try {
|
|
||||||
ipAddress = request.getHeader("x-forwarded-for");
|
|
||||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
|
||||||
ipAddress = request.getHeader("Proxy-Client-IP");
|
|
||||||
}
|
|
||||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
|
||||||
ipAddress = request.getHeader("WL-Proxy-Client-IP");
|
|
||||||
}
|
|
||||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
|
||||||
ipAddress = request.getRemoteAddr();
|
|
||||||
if ("127.0.0.1".equals(ipAddress)) {
|
|
||||||
// 根据网卡取本机配置的IP
|
|
||||||
InetAddress inet = null;
|
|
||||||
try {
|
|
||||||
inet = InetAddress.getLocalHost();
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
ipAddress = inet.getHostAddress();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
|
|
||||||
if (ipAddress != null && ipAddress.length() > 15) {
|
|
||||||
// "***.***.***.***".length()
|
|
||||||
// = 15
|
|
||||||
if (ipAddress.indexOf(",") > 0) {
|
|
||||||
ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
ipAddress = "";
|
|
||||||
}
|
|
||||||
return ipAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* md5加密
|
|
||||||
*
|
|
||||||
* @param data 需要加密的字符串
|
|
||||||
* @return java.lang.String
|
|
||||||
* @author wenshijia
|
|
||||||
* @date 2021/5/26 23:02
|
|
||||||
*/
|
|
||||||
public static String MD5(String data) {
|
|
||||||
try {
|
|
||||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
|
||||||
byte[] array = md.digest(data.getBytes(StandardCharsets.UTF_8));
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (byte item : array) {
|
|
||||||
sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.toString().toUpperCase();
|
|
||||||
} catch (Exception exception) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成随机数
|
|
||||||
*
|
|
||||||
* @param length 生成的随机数的长度
|
|
||||||
* @return java.lang.String
|
|
||||||
* @author wenshijia
|
|
||||||
* @date 2021/5/27 16:38
|
|
||||||
*/
|
|
||||||
public static String getRandomCode(int length) {
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
stringBuilder.append(random.nextInt(10));
|
|
||||||
}
|
|
||||||
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前时间的时间戳
|
|
||||||
*
|
|
||||||
* @return long
|
|
||||||
* @author wenshijia
|
|
||||||
* @date 2021/5/27 22:02
|
|
||||||
*/
|
|
||||||
public static long getCurrentTimestamp() {
|
|
||||||
return System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* UUID生成
|
|
||||||
*
|
|
||||||
* @return java.lang.String
|
|
||||||
* @author wenshijia
|
|
||||||
* @date 2021/5/30 21:16
|
|
||||||
*/
|
|
||||||
public static String generateUUID() {
|
|
||||||
return UUID.randomUUID().toString().replace("-", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成指定长度随机字母和数字
|
|
||||||
*
|
|
||||||
* @param length 需要生成的字符串长度
|
|
||||||
* @return java.lang.String
|
|
||||||
* @author wenshijia
|
|
||||||
* @date 2021/5/31 16:43
|
|
||||||
*/
|
|
||||||
public static String getStringNumRandom(int length) {
|
|
||||||
ThreadLocalRandom random = ThreadLocalRandom.current();
|
|
||||||
//生成随机数字和字母,
|
|
||||||
StringBuilder saltString = new StringBuilder(length);
|
|
||||||
for (int i = 1; i <= length; ++i) {
|
|
||||||
saltString.append(ALL_CHAR_NUM.charAt(random.nextInt(ALL_CHAR_NUM.length())));
|
|
||||||
}
|
|
||||||
return saltString.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param response 返回response
|
|
||||||
* @param obj 返回的数据
|
|
||||||
* @author wenshijia
|
|
||||||
* @date 2021/6/2 21:11
|
|
||||||
*/
|
|
||||||
public static void sendJsonMessage(HttpServletResponse response, Object obj) {
|
|
||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
response.setContentType("application/json; charset=utf-8");
|
|
||||||
|
|
||||||
try (PrintWriter writer = response.getWriter()) {
|
|
||||||
writer.print(objectMapper.writeValueAsString(obj));
|
|
||||||
|
|
||||||
response.flushBuffer();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.warn("响应json数据给前端异常 -> {}", e.getMessage(), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,511 +0,0 @@
|
|||||||
|
|
||||||
package com.ycwl.basic.utils;
|
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.LocalTime;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.temporal.TemporalAdjusters;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 日期处理
|
|
||||||
*/
|
|
||||||
public class DateUtils {
|
|
||||||
/**
|
|
||||||
* 时间格式(yyyy-MM-dd)
|
|
||||||
*/
|
|
||||||
public final static String DATE_PATTERN = "yyyy-MM-dd";
|
|
||||||
public final static String DATE_PATTERN_NYR = "yyyy年MM月dd日";
|
|
||||||
public final static String DATE_NO_PATTERN = "yyyyMMdd";
|
|
||||||
public final static String DATE_NO_TIME = "HHmmss";
|
|
||||||
public final static String DATE_PATTERN_YYDD = "MM月dd日 HH:mm";
|
|
||||||
public final static String YYYY_MM = "yyyyMM";
|
|
||||||
public final static String YYYY_MM_DD_HH_MM_SS_SSS = "yyyyMMddHHmmssSSS";
|
|
||||||
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
|
||||||
public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
|
|
||||||
public final static String CRON_DATE_TIME_PATTERN = "ss mm HH dd MM ? yyyy";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 日期格式化 日期格式为:yyyy-MM-dd
|
|
||||||
* @param date 日期
|
|
||||||
* @return 返回yyyy-MM-dd格式日期
|
|
||||||
*/
|
|
||||||
public static String format(Date date) {
|
|
||||||
return format(date, DATE_PATTERN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 日期格式化 自定义格式
|
|
||||||
* @param date 日期
|
|
||||||
* @param pattern 格式,如:DateUtils.DATE_TIME_PATTERN
|
|
||||||
* @return 返回yyyy-MM-dd格式日期
|
|
||||||
*/
|
|
||||||
public static String format(Date date, String pattern) {
|
|
||||||
if (date != null) {
|
|
||||||
SimpleDateFormat df = new SimpleDateFormat(pattern);
|
|
||||||
return df.format(date);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 日期解析 日期格式为:yyyy-MM-dd HH:mm:ss
|
|
||||||
* @param dataStr 日期字符串
|
|
||||||
* @return 返回yyyy-MM-dd HH:mm:ss格式日期
|
|
||||||
*/
|
|
||||||
public static Date parse(String dataStr) throws ParseException {
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat(DATE_TIME_PATTERN);
|
|
||||||
return sdf.parse(dataStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 日期解析 自定义格式
|
|
||||||
* @param date 日期字符串
|
|
||||||
* @param pattern 格式,如:DateUtils.DATE_TIME_PATTERN
|
|
||||||
* @return 返回Date
|
|
||||||
*/
|
|
||||||
public static Date parse(String date, String pattern) {
|
|
||||||
try {
|
|
||||||
return new SimpleDateFormat(pattern).parse(date);
|
|
||||||
} catch (ParseException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 返回0时0分0秒的date
|
|
||||||
*
|
|
||||||
* @param date 日期
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@SneakyThrows
|
|
||||||
public static Date startOfDay(Date date) {
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(date);
|
|
||||||
// 将时间部分设置为00:00:00.000
|
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
||||||
calendar.set(Calendar.MINUTE, 0);
|
|
||||||
calendar.set(Calendar.SECOND, 0);
|
|
||||||
calendar.set(Calendar.MILLISECOND, 0);
|
|
||||||
return calendar.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 这个月的第一天
|
|
||||||
* @param date 日期
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Date startOfMonth(Date date) {
|
|
||||||
Date date1 = startOfDay(date);
|
|
||||||
Calendar cal = Calendar.getInstance();
|
|
||||||
cal.setTime(date1);
|
|
||||||
cal.set(Calendar.DAY_OF_MONTH,1);
|
|
||||||
return cal.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取某个月有多少天
|
|
||||||
*
|
|
||||||
* @param yearMonth
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String getLastDayOfMonth(String yearMonth) {
|
|
||||||
int year = Integer.parseInt(yearMonth.split("-")[0]); //年
|
|
||||||
int month = Integer.parseInt(yearMonth.split("-")[1]); //月
|
|
||||||
Calendar cal = Calendar.getInstance();
|
|
||||||
// 设置年份
|
|
||||||
cal.set(Calendar.YEAR, year);
|
|
||||||
// 设置月份
|
|
||||||
// cal.set(Calendar.MONTH, month - 1);
|
|
||||||
cal.set(Calendar.MONTH, month); //设置当前月的上一个月
|
|
||||||
// 获取某月最大天数
|
|
||||||
//int lastDay = cal.getActualMaximum(Calendar.DATE);
|
|
||||||
int lastDay = cal.getMinimum(Calendar.DATE); //获取月份中的最小值,即第一天
|
|
||||||
// 设置日历中月份的最大天数
|
|
||||||
//cal.set(Calendar.DAY_OF_MONTH, lastDay);
|
|
||||||
cal.set(Calendar.DAY_OF_MONTH, lastDay - 1); //上月的第一天减去1就是当月的最后一天
|
|
||||||
// 格式化日期
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("dd");
|
|
||||||
return sdf.format(cal.getTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得某月最大时间
|
|
||||||
* @param date
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Date getEndMonthOfDay(Date date) {
|
|
||||||
if (date == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());
|
|
||||||
LocalDateTime endOfDay = localDateTime.with(TemporalAdjusters.lastDayOfMonth());
|
|
||||||
return getEndOfDay(localDateTimeToDate(endOfDay));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得某天最大时间
|
|
||||||
* @param date
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Date getStartMonthOfDay(Date date) {
|
|
||||||
if (date == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());
|
|
||||||
LocalDateTime endOfDay = localDateTime.with(TemporalAdjusters.firstDayOfMonth());
|
|
||||||
return getStartOfDay(localDateTimeToDate(endOfDay));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Date getMonthLastDay(Date date) {
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(date);
|
|
||||||
calendar.set(Calendar.DAY_OF_MONTH, 0);
|
|
||||||
calendar.add(Calendar.MONTH, 1);
|
|
||||||
return calendar.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断当天和传入的时间是否是同一天
|
|
||||||
*
|
|
||||||
* @param thatDay 另一个日期
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static boolean isSameDay(Date thatDay) {
|
|
||||||
return isSameDay(thatDay, new Date());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断两个日期是否为同一天
|
|
||||||
*
|
|
||||||
* @param date1 一个日期
|
|
||||||
* @param date2 另一个日期
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static boolean isSameDay(Date date1, Date date2) {
|
|
||||||
if (date1 == null || date2 == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Calendar thisDat = Calendar.getInstance();
|
|
||||||
thisDat.setTime(date1);
|
|
||||||
Calendar thatDay = Calendar.getInstance();
|
|
||||||
thatDay.setTime(date2);
|
|
||||||
return (
|
|
||||||
thatDay.get(Calendar.YEAR) == thisDat.get(Calendar.YEAR) &&
|
|
||||||
thatDay.get(Calendar.MONTH) == thisDat.get(Calendar.MONTH) &&
|
|
||||||
thatDay.get(Calendar.DAY_OF_MONTH) == thisDat.get(Calendar.DAY_OF_MONTH)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断两个日期相差多少天
|
|
||||||
*
|
|
||||||
* @param endTime
|
|
||||||
* @param startTime
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static int dateMinus(Date endTime, Date startTime) {
|
|
||||||
return (int) ((endTime.getTime() - startTime.getTime()) / (1000 * 60 * 60 * 24));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 时间戳转字符串
|
|
||||||
*
|
|
||||||
* @param timeStamp
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
//传入时间戳即可
|
|
||||||
public static String conversionTime(String timeStamp) {
|
|
||||||
//yyyy-MM-dd HH:mm:ss 转换的时间格式 可以自定义
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
//转换
|
|
||||||
String time = sdf.format(new Date(Long.parseLong(timeStamp)));
|
|
||||||
return time;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断两个日期相差多少秒
|
|
||||||
*
|
|
||||||
* @param endTime
|
|
||||||
* @param startTime
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static int dateSeconds(Date endTime, Date startTime) {
|
|
||||||
return (int) ((endTime.getTime() - startTime.getTime()) / (1000));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得某天最小时间
|
|
||||||
* @param date
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Date getStartOfDay(Date date) {
|
|
||||||
if (date == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());
|
|
||||||
LocalDateTime startOfDay = localDateTime.with(LocalTime.MIN);
|
|
||||||
return localDateTimeToDate(startOfDay);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得某天最大时间
|
|
||||||
* @param date
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Date getEndOfDay(Date date) {
|
|
||||||
if (date == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());
|
|
||||||
LocalDateTime endOfDay = localDateTime.with(LocalTime.MAX);
|
|
||||||
return localDateTimeToDate(endOfDay);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* localDateTime 转date
|
|
||||||
* @param localDateTime
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Date localDateTimeToDate(LocalDateTime localDateTime) {
|
|
||||||
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将秒转为时分秒格式【01:01:01】
|
|
||||||
* @param second 需要转化的秒数
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String secondConvertHourMinSecond(Long second) {
|
|
||||||
String str = "00:00:00";
|
|
||||||
if (second == null || second < 0) {
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 得到小时
|
|
||||||
long h = second / 3600;
|
|
||||||
str = h > 0 ? ((h < 10 ? ("0" + h) : h) + ":") : "00:";
|
|
||||||
|
|
||||||
// 得到分钟
|
|
||||||
long m = (second % 3600) / 60;
|
|
||||||
str += (m < 10 ? ("0" + m) : m) + ":";
|
|
||||||
|
|
||||||
//得到剩余秒
|
|
||||||
long s = second % 60;
|
|
||||||
str += (s < 10 ? ("0" + s) : s);
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param date
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String getWeekOfDate(Date date) {
|
|
||||||
String[] weekDays = {"7", "1", "2", "3", "4", "5", "6"}; // "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"
|
|
||||||
Calendar cal = Calendar.getInstance();
|
|
||||||
cal.setTime(date);
|
|
||||||
int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 将星期日转换为7
|
|
||||||
return weekDays[w]; // 直接返回对应的星期数
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取两个日期之间的所有年
|
|
||||||
* @param startDate
|
|
||||||
* @param endDate
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static List<String> getAllYearsBetweenDates(Date startDate, Date endDate) {
|
|
||||||
List<String> years = new ArrayList<>();
|
|
||||||
Calendar startCal = Calendar.getInstance();
|
|
||||||
startCal.setTime(startDate);
|
|
||||||
int startYear = startCal.get(Calendar.YEAR);
|
|
||||||
|
|
||||||
Calendar endCal = Calendar.getInstance();
|
|
||||||
endCal.setTime(endDate);
|
|
||||||
int endYear = endCal.get(Calendar.YEAR);
|
|
||||||
|
|
||||||
for (int year = startYear; year <= endYear; year++) {
|
|
||||||
years.add(String.valueOf(year));
|
|
||||||
}
|
|
||||||
return years;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取两个日期之间的所有月份
|
|
||||||
* @param startDate
|
|
||||||
* @param endDate
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static List<String> getAllMonthsBetweenDates(Date startDate, Date endDate) {
|
|
||||||
List<String> months = new ArrayList<>();
|
|
||||||
//具体逻辑
|
|
||||||
Calendar startCal = Calendar.getInstance();
|
|
||||||
startCal.setTime(startDate);
|
|
||||||
startCal.set(Calendar.DAY_OF_MONTH, 1); // 设置为每个月的第一天
|
|
||||||
|
|
||||||
Calendar endCal = Calendar.getInstance();
|
|
||||||
endCal.setTime(endDate);
|
|
||||||
endCal.set(Calendar.DAY_OF_MONTH, 1); // 设置为每个月的第一天
|
|
||||||
|
|
||||||
while (startCal.before(endCal) || startCal.equals(endCal)) {
|
|
||||||
int year = startCal.get(Calendar.YEAR);
|
|
||||||
int month = startCal.get(Calendar.MONTH) + 1; // Calendar中月份从0开始,所以要加1
|
|
||||||
months.add(String.format("%d-%02d", year, month)); // 格式化年份和月份为 yyyy-MM
|
|
||||||
|
|
||||||
startCal.add(Calendar.MONTH, 1); // 增加一个月
|
|
||||||
}
|
|
||||||
return months;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取两个日期间所有的日期
|
|
||||||
* @param startDate
|
|
||||||
* @param endDate
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static List<String> getAllDaysBetweenDates(Date startDate, Date endDate){
|
|
||||||
List<String> days = new ArrayList<>();
|
|
||||||
//具体实现
|
|
||||||
Calendar startCal = Calendar.getInstance();
|
|
||||||
startCal.setTime(startDate);
|
|
||||||
|
|
||||||
Calendar endCal = Calendar.getInstance();
|
|
||||||
endCal.setTime(endDate);
|
|
||||||
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
||||||
|
|
||||||
while (startCal.before(endCal) || startCal.equals(endCal)) {
|
|
||||||
days.add(sdf.format(startCal.getTime()));
|
|
||||||
startCal.add(Calendar.DATE, 1);
|
|
||||||
}
|
|
||||||
return days;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 获取两个时间点之间的所有的整点时间
|
|
||||||
* @param startDate
|
|
||||||
* @param endDate
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static List<String> getAllTimesBetweenDates(Date startDate, Date endDate,String format){
|
|
||||||
// 创建一个字符串列表用来存放整点时间
|
|
||||||
List<String> timesList = new ArrayList<>();
|
|
||||||
// 使用日历类来处理时间
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(startDate);
|
|
||||||
|
|
||||||
// 格式化时间为 "yyyy-MM-dd HH:mm"
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
|
||||||
|
|
||||||
// 逐小时遍历
|
|
||||||
// while (calendar.getTime().before(endDate) || calendar.getTime().equals(endDate)) {
|
|
||||||
while (calendar.getTime().before(endDate)) {
|
|
||||||
// 将当前时间格式化为字符串并加入列表
|
|
||||||
timesList.add(sdf.format(calendar.getTime()));
|
|
||||||
// 增加一个小时
|
|
||||||
calendar.add(Calendar.HOUR_OF_DAY, 1);
|
|
||||||
}
|
|
||||||
return timesList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取24小时制的时间
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static List<String> getAllTimesBetweenDates(){
|
|
||||||
// 创建一个字符串数组,容量为24
|
|
||||||
String[] times24 = new String[24];
|
|
||||||
// 设置格式化器为24小时制
|
|
||||||
java.time.format.DateTimeFormatter formatter = java.time.format.DateTimeFormatter.ofPattern("HH");
|
|
||||||
// 获取0点到23点的每一个小时
|
|
||||||
for (int i = 0; i < 24; i++) {
|
|
||||||
LocalTime time = LocalTime.of(i, 0);
|
|
||||||
times24[i] = time.format(formatter);
|
|
||||||
}
|
|
||||||
return new ArrayList<>(Arrays.asList(times24));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 在指定日期上增加i年,负数为减少i年
|
|
||||||
* @param date 指定的日期
|
|
||||||
* @param i 增加/减少的年数
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Date addDateYears(Date date, int i) {
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(date);
|
|
||||||
calendar.add(Calendar.YEAR, i);
|
|
||||||
return calendar.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 在指定日期上增加i月,负数为减少i月
|
|
||||||
* @param date
|
|
||||||
* @param i
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Date addDateMonths(Date date, int i) {
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(date);
|
|
||||||
calendar.add(Calendar.MONTH, i);
|
|
||||||
return calendar.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 在指定日期上增加i周,负数为减少i周
|
|
||||||
* @param date
|
|
||||||
* @param i
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Date addDateWeeks(Date date, int i) {
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(date);
|
|
||||||
calendar.add(Calendar.WEEK_OF_YEAR, i);
|
|
||||||
return calendar.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 在指定日期上增加i天,负数为减少i天
|
|
||||||
* @param date
|
|
||||||
* @param i
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Date addDateDays(Date date, int i) {
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(date);
|
|
||||||
calendar.add(Calendar.DAY_OF_YEAR, i);
|
|
||||||
return calendar.getTime();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 在指定日期上增加i分钟,负数为减少i分钟
|
|
||||||
* @param date
|
|
||||||
* @param i
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Date addDateMinute(Date date, int i) {
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(date);
|
|
||||||
calendar.add(Calendar.MINUTE, i);
|
|
||||||
return calendar.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Date date = new Date();
|
|
||||||
Date yesterday = DateUtils.addDateMinute(date, 10);
|
|
||||||
System.out.println(format(yesterday, "yyyy-MM-dd HH:mm:ss"));
|
|
||||||
// Date startDate = DateUtils.getStartOfDay(yesterday);
|
|
||||||
// Date endDate = DateUtils.getEndOfDay(yesterday);
|
|
||||||
// System.out.println(format(startDate, "yyyy-MM-dd HH:mm:ss"));
|
|
||||||
// System.out.println(format(endDate, "yyyy-MM-dd HH:mm:ss"));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,8 +3,7 @@ package com.ycwl.basic.utils;
|
|||||||
|
|
||||||
import com.ycwl.basic.model.snowFlake.UniqueId;
|
import com.ycwl.basic.model.snowFlake.UniqueId;
|
||||||
import com.ycwl.basic.model.snowFlake.UniqueIdMetaData;
|
import com.ycwl.basic.model.snowFlake.UniqueIdMetaData;
|
||||||
import org.slf4j.Logger;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -13,10 +12,10 @@ import java.util.Date;
|
|||||||
* @author Created by liuhongguang
|
* @author Created by liuhongguang
|
||||||
* @Description
|
* @Description
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class SnowFlakeUtil {
|
public class SnowFlakeUtil {
|
||||||
|
|
||||||
private Logger log = LoggerFactory.getLogger(com.ycwl.basic.utils.SnowFlakeUtil.class);
|
|
||||||
/**
|
/**
|
||||||
* 记录上一毫秒数
|
* 记录上一毫秒数
|
||||||
*/
|
*/
|
||||||
|
@ -76,6 +76,6 @@ public class WxMpUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
generateWXAQRCode("wxe7ff26af70bfc37c", "5252fbbc68513bc77b7cc0052b9f9695", "trial", "pages/home/index?scenicId=3972138108618674176", "ljh_t.jpg");
|
generateWXAQRCode("wxe7ff26af70bfc37c", "5252fbbc68513bc77b7cc0052b9f9695", "trial", "pages/home/index?scenicId=3978838215909052416", "dhg_t.jpg");
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user