Merge branch 'lyf' of https://e.coding.net/g-cphe0354/shouyinjixitong/wx-cashier-service into lyf
Conflicts: src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java src/main/java/com/chaozhanggui/system/cashierservice/util/RandomUtil.java src/main/resources/application-dev.yml src/main/resources/application-dev2.yml src/main/resources/application-prod.yml src/main/resources/application-prod2.yml src/main/resources/mapper/TbShopInfoMapper.xml
This commit is contained in:
@@ -3,8 +3,14 @@ package com.chaozhanggui.system.cashierservice.util;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
/**
|
||||
* Created by SEELE on 2018/4/19.
|
||||
@@ -244,6 +250,48 @@ public class DateUtils {
|
||||
return date;
|
||||
}
|
||||
|
||||
/**
|
||||
* 今天结束时间
|
||||
* @return
|
||||
*/
|
||||
public static Date getDayEnd() {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.set(Calendar.HOUR_OF_DAY, 23);
|
||||
cal.set(Calendar.MINUTE, 59);
|
||||
cal.set(Calendar.SECOND, 59);
|
||||
cal.set(Calendar.MILLISECOND, 999);
|
||||
return cal.getTime();
|
||||
}
|
||||
public static Long getDayEndLong() {
|
||||
// 获取今天的日期和时间(00:00:00)
|
||||
LocalDateTime todayStart = LocalDateTime.now().toLocalDate().atStartOfDay();
|
||||
|
||||
// 将时间设置为今天的结束时间(23:59:59.999999999)
|
||||
LocalDateTime endOfDay = todayStart.plusDays(1).minusNanos(1);
|
||||
|
||||
// 转换为UTC时间戳(毫秒)
|
||||
long timestampInMillis = endOfDay.toInstant(ZoneOffset.UTC).toEpochMilli();
|
||||
|
||||
return timestampInMillis;
|
||||
}
|
||||
|
||||
public static String getTodayEndTimeAsString() {
|
||||
// 获取今天的日期
|
||||
LocalDate today = LocalDate.now();
|
||||
|
||||
// 创建今天的结束时间(23:59:59.999)
|
||||
LocalTime endTime = LocalTime.of(23, 59, 59, 999_000_000);
|
||||
|
||||
// 组合日期和时间
|
||||
LocalDateTime todayEndTime = LocalDateTime.of(today, endTime);
|
||||
|
||||
// 格式化时间
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
|
||||
// 转换为字符串
|
||||
return todayEndTime.format(formatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到n天之后是周几
|
||||
* @param days
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -172,6 +173,26 @@ public class JSONUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list 某集合
|
||||
* @param clazz 要转成的实体
|
||||
* 需要在目标实体增加注解 忽略未知属性 @JsonIgnoreProperties(ignoreUnknown = true)
|
||||
* @return
|
||||
* @param <T>
|
||||
*/
|
||||
public static <T> List<T> parseListTNewList(List<?> list, Class<T> clazz) {
|
||||
ObjectMapper objectMapper = new ObjectMapper(); // 创建JSON转换器
|
||||
try {
|
||||
// 将List<?>转换为JSON字符串
|
||||
String json = objectMapper.writeValueAsString(list);
|
||||
// 将JSON字符串转换为List<T>
|
||||
return objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class JSONEntity {
|
||||
public JSONEntity() {
|
||||
}
|
||||
|
||||
@@ -9,30 +9,18 @@ import static java.lang.Math.sin;
|
||||
public class LocationUtils {
|
||||
|
||||
public static String district(String keywords) {
|
||||
Map<String, String> param=new HashMap<>();
|
||||
Map<String, String> param = new HashMap<>();
|
||||
//超掌柜生活-用户端
|
||||
param.put("key","7a7f2e4790ea222660a027352ee3af39");
|
||||
param.put("keywords",keywords);
|
||||
param.put("subdistrict","1");
|
||||
param.put("extensions","base");
|
||||
param.put("key", "7a7f2e4790ea222660a027352ee3af39");
|
||||
param.put("keywords", keywords);
|
||||
param.put("subdistrict", "2");
|
||||
param.put("extensions", "base");
|
||||
String s = HttpClientUtil.doGet("https://restapi.amap.com/v3/config/district", param);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将角度转化为弧度
|
||||
*/
|
||||
public static double radians(double d) {
|
||||
return d * Math.PI / 180.0;
|
||||
}
|
||||
/**
|
||||
* 根据两点经纬度坐标计算直线距离
|
||||
* <p>
|
||||
* S = 2arcsin√sin²(a/2)+cos(lat1)*cos(lat2)*sin²(b/2) ̄*6378.137
|
||||
* <p>
|
||||
* 1. lng1 lat1 表示A点经纬度,lng2 lat2 表示B点经纬度;<br>
|
||||
* 2. a=lat1 – lat2 为两点纬度之差 b=lng1 -lng2 为两点经度之差;<br>
|
||||
* 3. 6378.137为地球赤道半径,单位为千米;
|
||||
*
|
||||
* @param lng1 点1经度
|
||||
* @param lat1 点1纬度
|
||||
@@ -43,7 +31,7 @@ public class LocationUtils {
|
||||
*/
|
||||
public static double getDistanceFrom2LngLat(double lng1, double lat1, double lng2, double lat2) {
|
||||
//将角度转化为弧度
|
||||
double radLng1 = radians(lng1);
|
||||
double radLng1 = radians(lng1);//d * Math.PI / 180.0;
|
||||
double radLat1 = radians(lat1);
|
||||
double radLng2 = radians(lng2);
|
||||
double radLat2 = radians(lat2);
|
||||
@@ -54,16 +42,65 @@ public class LocationUtils {
|
||||
return 2 * asin(sqrt(sin(a / 2) * sin(a / 2) + cos(radLat1) * cos(radLat2) * sin(b / 2) * sin(b / 2))) * 6378.137;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param longitude 经度 108
|
||||
* @param latitude 纬度 34
|
||||
* @param distanceInKm 范围(千米)
|
||||
* 大于左下的经度lat,小于右上的经度lat
|
||||
* 大于左下的纬度lng,小于右上的纬度lng
|
||||
* return Map<String, double[]> stringMap
|
||||
* 右上顶点 double[] leftTopPoints = stringMap.get("rightTopPoint");
|
||||
* 左下点 double[] leftBottomPoints = stringMap.get("leftBottomPoint");
|
||||
*/
|
||||
public static Map<String, double[]> returnLLSquarePoint(double longitude, double latitude, double distanceInKm) {
|
||||
Map<String, double[]> squareMap = new HashMap<>();
|
||||
// 地球平均半径,单位:千米
|
||||
double earthRadius = 6378.137;
|
||||
// 将距离转换为弧度
|
||||
double radialDistance = distanceInKm / earthRadius;
|
||||
// 计算纬度上变化对应的角度
|
||||
double dLatitude = Math.toDegrees(2 * Math.asin(Math.sin(radialDistance / 2) / Math.cos(Math.toRadians(latitude))));
|
||||
// 计算经度上变化对应的角度,这里需要考虑纬度对距离的影响
|
||||
// 使用Haversine公式来估算在给定纬度上,距离对应的经度变化
|
||||
double estimatedLongitudeDistance = getDistanceFrom2LngLat(latitude, longitude, latitude, longitude + 0.01); // 假设0.01度经度变化对应的距离
|
||||
double dLongitude = distanceInKm / estimatedLongitudeDistance * 0.0192736; // 根据比例计算经度变化
|
||||
// 正方形四个顶点的坐标
|
||||
double[] rightTopPoint = {latitude + dLatitude / 2, longitude + dLongitude / 2};
|
||||
double[] leftBottomPoint = {latitude - dLatitude / 2, longitude - dLongitude / 2};
|
||||
squareMap.put("rightTopPoint", rightTopPoint);
|
||||
squareMap.put("leftBottomPoint", leftBottomPoint);
|
||||
// 打印结果rightTopPoint[0]纬度lng,rightTopPoint[1]经度lat
|
||||
System.out.println("rightTop:" + rightTopPoint[0] + "======" + rightTopPoint[1]);
|
||||
System.out.println("leftBottom:" + leftBottomPoint[0] + "======" + leftBottomPoint[1]);
|
||||
return squareMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将角度转化为弧度
|
||||
*/
|
||||
public static double radians(double d) {
|
||||
return d * Math.PI / 180.0;
|
||||
}
|
||||
//1KM
|
||||
public static void main(String[] args) {
|
||||
Map<String, double[]> stringMap = returnLLSquarePoint(108.954398, 34.308687, 1);
|
||||
double[] leftTopPoints = stringMap.get("rightTopPoint");
|
||||
double[] leftBottomPoints = stringMap.get("leftBottomPoint");
|
||||
|
||||
double lat2 = 108.975418;
|
||||
double lon2 = 34.280890;
|
||||
double distance3 = getDistanceFrom2LngLat(109.019993, 34.342849, lat2, lon2);
|
||||
System.out.println(distance3);
|
||||
|
||||
// 计算距离
|
||||
double distance1 = getDistanceFrom2LngLat(leftTopPoints[1], leftTopPoints[0], lat2, lon2);
|
||||
double distance2 = getDistanceFrom2LngLat(leftBottomPoints[1], leftBottomPoints[0], lat2, lon2);
|
||||
System.out.println("Distance between the two points is: " + distance1 + " km");
|
||||
System.out.println("Distance between the two points is: " + distance2 + " km");
|
||||
}
|
||||
// public static void main(String[] args) {
|
||||
// // 示例经纬度坐标
|
||||
// double lat1 = 108.954398;
|
||||
// double lon1 = 34.308687;
|
||||
// Map<String, double[]> stringMap = returnLLSquarePoint(34.342849, 109.019993, 1);
|
||||
//
|
||||
// double lat2 = 108.953555;
|
||||
// double lon2 = 34.276169;
|
||||
//
|
||||
// // 计算距离
|
||||
// double distance = getDistanceFrom2LngLat(lat1, lon1, lat2, lon2);
|
||||
// System.out.println("Distance between the two points is: " + distance + " km");
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -23,9 +23,37 @@ public class RandomUtil {
|
||||
Random random = new Random();
|
||||
int randomIndex = random.nextInt(list.size()); // 生成一个随机的索引值
|
||||
TbOrderInfo orderInfo = list.get(randomIndex);
|
||||
if (map.containsKey(orderInfo.getId())){
|
||||
return selectWinner(list,map);
|
||||
if (map.containsKey(orderInfo.getId())) {
|
||||
return selectWinner(list, map);
|
||||
}
|
||||
return list.get(randomIndex); // 返回对应索引的用户
|
||||
}
|
||||
|
||||
public static BigDecimal randomDecimalGenerator(){
|
||||
|
||||
double number = generateRandomInt(2, 40);
|
||||
BigDecimal bdNumber = BigDecimal.valueOf(number);
|
||||
BigDecimal bdMultiplier = BigDecimal.valueOf(5);
|
||||
|
||||
BigDecimal result = bdNumber.setScale(1, RoundingMode.HALF_UP);
|
||||
BigDecimal multiply = result.multiply(bdMultiplier);
|
||||
return multiply;
|
||||
}
|
||||
private static double generateRandomInt(double min, double max) {
|
||||
Random random = new Random();
|
||||
return min + (max-min) * random.nextDouble();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
System.out.println("随机数为"+randomDecimalGenerator());
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer randomInt() {
|
||||
Random random = new Random();
|
||||
|
||||
// 生成1到27之间的随机整数(包括1和27)
|
||||
|
||||
return random.nextInt(46) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,4 +61,26 @@ public class StringUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static final String CHINESE_CHARS = "你我他她它们这里那里多少是否好坏快慢上下左右前后高低大小长短方圆胖瘦黑白红绿蓝黄紫粉红桔红橙黄棕灰褐";
|
||||
|
||||
// 生成随机中文昵称
|
||||
public static String generateRandomNickname(int length) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < length; i++) {
|
||||
int index = random.nextInt(CHINESE_CHARS.length());
|
||||
char randomChar = CHINESE_CHARS.charAt(index);
|
||||
sb.append(randomChar);
|
||||
}
|
||||
return desensitizeNickname(sb.toString());
|
||||
}
|
||||
|
||||
// 对昵称进行脱敏处理
|
||||
public static String desensitizeNickname(String nickname) {
|
||||
if (nickname == null || nickname.length() != 5) {
|
||||
return nickname;
|
||||
}
|
||||
return nickname.charAt(0) + "***" + nickname.charAt(4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user