Commit 5359d0ff339e03a0e1c04da6761bb371b63f33d6

Authored by 张志伟
1 parent cf7e3bc9

:tada: 初始化项目

Showing 22 changed files with 1593 additions and 31 deletions
fw-hestia-common/pom.xml
@@ -14,6 +14,13 @@ @@ -14,6 +14,13 @@
14 <packaging>jar</packaging> 14 <packaging>jar</packaging>
15 <name>fw-hestia-common</name> 15 <name>fw-hestia-common</name>
16 16
  17 + <dependencies>
  18 + <dependency>
  19 + <groupId>com.alibaba</groupId>
  20 + <artifactId>fastjson</artifactId>
  21 + </dependency>
  22 + </dependencies>
  23 +
17 <build> 24 <build>
18 <plugins> 25 <plugins>
19 <plugin> 26 <plugin>
fw-hestia-common/src/main/java/cn/fw/hestia/common/constant/MessageStr.java 0 → 100644
  1 +package cn.fw.hestia.common.constant;
  2 +
  3 +/**
  4 + * @author : kurisu
  5 + * @className : MessageStr
  6 + * @description : 返回的信息
  7 + * @date: 2020-08-13 10:09
  8 + */
  9 +public interface MessageStr {
  10 + String QUERY_FAILURE = "查询失败";
  11 + String SAVE_FAILURE = "操作失败";
  12 +}
fw-hestia-common/src/main/java/cn/fw/hestia/common/utils/CoordinateTransformUtil.java 0 → 100644
  1 +package cn.fw.hestia.common.utils;
  2 +
  3 +import lombok.AccessLevel;
  4 +import lombok.NoArgsConstructor;
  5 +
  6 +/**
  7 + * 百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换的工具
  8 + * <p>
  9 + * create at 2018-10-09
  10 + *
  11 + * @author kurisu
  12 + */
  13 +@NoArgsConstructor(access = AccessLevel.PRIVATE)
  14 +public final class CoordinateTransformUtil {
  15 +
  16 + // π
  17 + private static double PI = Math.PI;
  18 + private static double X_PI = PI * 3000.0 / 180.0;
  19 + // 长半轴
  20 + private static double A = 6378245.0;
  21 + // 扁率
  22 + private static double EE = 0.00669342162296594323;
  23 +
  24 + /**
  25 + * 百度坐标系(BD-09)转WGS坐标
  26 + *
  27 + * @param lng 百度坐标纬度
  28 + * @param lat 百度坐标经度
  29 + * @return WGS84坐标数组
  30 + */
  31 + public static double[] bd09toWgs84(double lng, double lat) {
  32 + double[] gcj = bd09toGcj02(lng, lat);
  33 + return gcj02toWgs84(gcj[0], gcj[1]);
  34 + }
  35 +
  36 + /**
  37 + * WGS坐标转百度坐标系(BD-09)
  38 + *
  39 + * @param lng WGS84坐标系的经度
  40 + * @param lat WGS84坐标系的纬度
  41 + * @return 百度坐标数组
  42 + */
  43 + public static double[] wgs84toBd09(double lng, double lat) {
  44 + double[] gcj = wgs84toGcj02(lng, lat);
  45 + return gcj02toBd09(gcj[0], gcj[1]);
  46 + }
  47 +
  48 + /**
  49 + * 火星坐标系(GCJ-02)转百度坐标系(BD-09)
  50 + * 谷歌、高德——>百度
  51 + *
  52 + * @param lng 火星坐标经度
  53 + * @param lat 火星坐标纬度
  54 + * @return 百度坐标数组
  55 + */
  56 + public static double[] gcj02toBd09(double lng, double lat) {
  57 + double z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * X_PI);
  58 + double theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * X_PI);
  59 + double bd_lng = z * Math.cos(theta) + 0.0065;
  60 + double bd_lat = z * Math.sin(theta) + 0.006;
  61 + return new double[]{bd_lng, bd_lat};
  62 + }
  63 +
  64 + /**
  65 + * 百度坐标系(BD-09)转火星坐标系(GCJ-02)
  66 + * 百度——>谷歌、高德
  67 + *
  68 + * @param bd_lon 百度坐标纬度
  69 + * @param bd_lat 百度坐标经度
  70 + * @return 火星坐标数组
  71 + */
  72 + public static double[] bd09toGcj02(double bd_lon, double bd_lat) {
  73 + double x = bd_lon - 0.0065;
  74 + double y = bd_lat - 0.006;
  75 + double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);
  76 + double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI);
  77 + double gg_lng = z * Math.cos(theta);
  78 + double gg_lat = z * Math.sin(theta);
  79 + return new double[]{gg_lng, gg_lat};
  80 + }
  81 +
  82 + /**
  83 + * WGS84转GCJ02(火星坐标系)
  84 + *
  85 + * @param lng WGS84坐标系的经度
  86 + * @param lat WGS84坐标系的纬度
  87 + * @return 火星坐标数组
  88 + */
  89 + public static double[] wgs84toGcj02(double lng, double lat) {
  90 + if (out_of_china(lng, lat)) {
  91 + return new double[]{lng, lat};
  92 + }
  93 + double dlat = transformLat(lng - 105.0, lat - 35.0);
  94 + double dlng = transformLng(lng - 105.0, lat - 35.0);
  95 + double radlat = lat / 180.0 * PI;
  96 + double magic = Math.sin(radlat);
  97 + magic = 1 - EE * magic * magic;
  98 + double sqrtmagic = Math.sqrt(magic);
  99 + dlat = (dlat * 180.0) / ((A * (1 - EE)) / (magic * sqrtmagic) * PI);
  100 + dlng = (dlng * 180.0) / (A / sqrtmagic * Math.cos(radlat) * PI);
  101 + double mglat = lat + dlat;
  102 + double mglng = lng + dlng;
  103 + return new double[]{mglng, mglat};
  104 + }
  105 +
  106 + /**
  107 + * GCJ02(火星坐标系)转GPS84
  108 + *
  109 + * @param lng 火星坐标系的经度
  110 + * @param lat 火星坐标系纬度
  111 + * @return WGS84坐标数组
  112 + */
  113 + public static double[] gcj02toWgs84(double lng, double lat) {
  114 + if (out_of_china(lng, lat)) {
  115 + return new double[]{lng, lat};
  116 + }
  117 + double dlat = transformLat(lng - 105.0, lat - 35.0);
  118 + double dlng = transformLng(lng - 105.0, lat - 35.0);
  119 + double radlat = lat / 180.0 * PI;
  120 + double magic = Math.sin(radlat);
  121 + magic = 1 - EE * magic * magic;
  122 + double sqrtmagic = Math.sqrt(magic);
  123 + dlat = (dlat * 180.0) / ((A * (1 - EE)) / (magic * sqrtmagic) * PI);
  124 + dlng = (dlng * 180.0) / (A / sqrtmagic * Math.cos(radlat) * PI);
  125 + double mglat = lat + dlat;
  126 + double mglng = lng + dlng;
  127 + return new double[]{lng * 2 - mglng, lat * 2 - mglat};
  128 + }
  129 +
  130 + /**
  131 + * 纬度转换
  132 + *
  133 + * @param lng 经度
  134 + * @param lat 纬度
  135 + * @return 纬度
  136 + */
  137 + public static double transformLat(double lng, double lat) {
  138 + double ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
  139 + ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
  140 + ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
  141 + ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
  142 + return ret;
  143 + }
  144 +
  145 + /**
  146 + * 经度转换
  147 + *
  148 + * @param lng 经度
  149 + * @param lat 纬度
  150 + * @return 经度
  151 + */
  152 + public static double transformLng(double lng, double lat) {
  153 + double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
  154 + ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
  155 + ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
  156 + ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
  157 + return ret;
  158 + }
  159 +
  160 + /**
  161 + * 判断是否在国内,不在国内不做偏移
  162 + *
  163 + * @param lng 经度
  164 + * @param lat 纬度
  165 + * @return 是否
  166 + */
  167 + public static boolean out_of_china(double lng, double lat) {
  168 + if (lng < 72.004 || lng > 137.8347) {
  169 + return true;
  170 + } else {
  171 + return lat < 0.8293 || lat > 55.8271;
  172 + }
  173 + }
  174 +
  175 +}
fw-hestia-common/src/main/java/cn/fw/hestia/common/utils/DateUtil.java 0 → 100644
  1 +package cn.fw.hestia.common.utils;
  2 +
  3 +import java.sql.Timestamp;
  4 +import java.text.ParseException;
  5 +import java.text.SimpleDateFormat;
  6 +import java.time.*;
  7 +import java.time.temporal.TemporalAdjusters;
  8 +import java.util.Calendar;
  9 +import java.util.Date;
  10 +import java.util.Objects;
  11 +
  12 +/**
  13 + * 日期处理工具
  14 + * <p>
  15 + *
  16 + * @author kurisu
  17 + */
  18 +public final class DateUtil {
  19 +
  20 + static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  21 +
  22 + /**
  23 + * 默认构造器
  24 + */
  25 + private DateUtil() {
  26 + throw new UnsupportedOperationException();
  27 + }
  28 +
  29 +
  30 + public static Date parse(String date) {
  31 + try {
  32 + return sdf.parse(date);
  33 + } catch (Exception e) {
  34 + e.printStackTrace();
  35 + }
  36 + return null;
  37 + }
  38 +
  39 + /**
  40 + * 开始日期处理
  41 + */
  42 + public static Date startDate(final Date date) {
  43 + if (date == null) {
  44 + return null;
  45 + }
  46 + return localDateTime2Date(date2LocalDate(date).atStartOfDay());
  47 + }
  48 +
  49 + /**
  50 + * 最结束日期处理
  51 + */
  52 + public static Date endDate(final Date date) {
  53 + if (date == null) {
  54 + return null;
  55 + }
  56 + return localDateTime2Date(date2LocalDate(date).plusDays(1).atStartOfDay());
  57 + }
  58 +
  59 + /**
  60 + * 处理日期,保留年月日
  61 + */
  62 + public static LocalDate date2LocalDate(final Date date) {
  63 + if (date == null) {
  64 + return null;
  65 + }
  66 + return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()).toLocalDate();
  67 + }
  68 +
  69 + public static LocalTime date2LocalTime(final Date date) {
  70 + if (date == null) {
  71 + return null;
  72 + }
  73 + return LocalTime.of(date.getHours(), date.getMinutes(), date.getSeconds());
  74 + }
  75 +
  76 + public static LocalDateTime date2LocalDateTime(final Date date) {
  77 + Instant instant = date.toInstant();
  78 + ZoneId zoneId = ZoneId.systemDefault();
  79 + return instant.atZone(zoneId).toLocalDateTime();
  80 + }
  81 +
  82 + /**
  83 + * convert LocalDateTime to Date
  84 + */
  85 + public static Date localDateTime2Date(final LocalDateTime dateTime) {
  86 + return Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());
  87 + }
  88 +
  89 + /**
  90 + * convert LocalDate to Date
  91 + */
  92 + public static Date localDate2Date(final LocalDate localDate) {
  93 + if (localDate == null) {
  94 + return null;
  95 + }
  96 + return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
  97 + }
  98 +
  99 + public static Date getBeginInTime(Date inTime) {
  100 + if (inTime == null) {
  101 + return null;
  102 + }
  103 + Calendar c = Calendar.getInstance();
  104 + c.setTime(inTime);
  105 + c.set(Calendar.HOUR_OF_DAY, 0);
  106 + c.set(Calendar.MINUTE, 0);
  107 + c.set(Calendar.SECOND, 0);
  108 + return c.getTime();
  109 + }
  110 +
  111 + public static Date getEndInTime(Date inTime) {
  112 + if (inTime == null) {
  113 + return null;
  114 + }
  115 + Calendar c = Calendar.getInstance();
  116 + c.setTime(inTime);
  117 + c.set(Calendar.HOUR_OF_DAY, 23);
  118 + c.set(Calendar.MINUTE, 59);
  119 + c.set(Calendar.SECOND, 59);
  120 + return c.getTime();
  121 + }
  122 +
  123 + /**
  124 + * 得到本周周一
  125 + *
  126 + * @return
  127 + */
  128 + public static Date getMondayOfThisWeek(Date inTime) {
  129 + Calendar c = Calendar.getInstance();
  130 + c.setTime(inTime);
  131 + int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
  132 + if (day_of_week == 0) {
  133 + day_of_week = 7;
  134 + }
  135 + c.add(Calendar.DATE, -day_of_week + 1);
  136 + return c.getTime();
  137 + }
  138 +
  139 + /**
  140 + * 得到本周周日
  141 + *
  142 + * @return
  143 + */
  144 + public static Date getSundayOfThisWeek(Date inTime) {
  145 + Calendar c = Calendar.getInstance();
  146 + c.setTime(inTime);
  147 + int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
  148 + if (day_of_week == 0) {
  149 + day_of_week = 7;
  150 + }
  151 + c.add(Calendar.DATE, -day_of_week + 7);
  152 + return c.getTime();
  153 + }
  154 +
  155 + /**
  156 + * 得到月初
  157 + *
  158 + * @return
  159 + */
  160 + public static Date getMonthFirstDay(Date inTime) {
  161 + Calendar c = Calendar.getInstance();
  162 + c.setTime(inTime);
  163 + c.add(Calendar.MONTH, 0);
  164 + c.set(Calendar.DAY_OF_MONTH, 1);
  165 + return c.getTime();
  166 + }
  167 +
  168 + /**
  169 + * 获取当月月初时间
  170 + */
  171 + public static Date getMonthFirstDay() {
  172 + return DateUtil.localDate2Date(LocalDateTime.now()
  173 + .with(TemporalAdjusters.firstDayOfMonth()).toLocalDate());
  174 + }
  175 +
  176 + /**
  177 + * 得到月末
  178 + *
  179 + * @return
  180 + */
  181 + public static Date getMonthEndDay(Date inTime) {
  182 + Calendar c = Calendar.getInstance();
  183 + c.setTime(inTime);
  184 + c.add(Calendar.MONTH, 1);
  185 + c.set(Calendar.DAY_OF_MONTH, 0);
  186 + return c.getTime();
  187 + }
  188 +
  189 + /**
  190 + * 得到月末
  191 + *
  192 + * @return
  193 + */
  194 + public static Date getMonthEndDay() {
  195 + return DateUtil.localDate2Date(LocalDateTime.now()
  196 + .with(TemporalAdjusters.lastDayOfMonth()).toLocalDate());
  197 + }
  198 +
  199 + /**
  200 + * 得到年初
  201 + *
  202 + * @return
  203 + */
  204 + public static Date getYearFirstDay(Date inTime) {
  205 + Calendar c = Calendar.getInstance();
  206 + c.setTime(inTime);
  207 + int x = c.get(Calendar.YEAR);
  208 + try {
  209 + return sdf.parse(x + "-01" + "-01");
  210 + } catch (Exception e) {
  211 +
  212 + }
  213 + return null;
  214 + }
  215 +
  216 + /**
  217 + * 得到年末
  218 + *
  219 + * @return
  220 + */
  221 + public static Date getYearEndDay(Date inTime) {
  222 + Calendar c = Calendar.getInstance();
  223 + c.setTime(inTime);
  224 + int x = c.get(Calendar.YEAR);
  225 + try {
  226 + return sdf.parse(x + "-12" + "-31");
  227 + } catch (Exception e) {
  228 +
  229 + }
  230 + return null;
  231 + }
  232 +
  233 + public static Date getThisHourStartTime(Date time) {
  234 + final LocalDateTime thisHourStart = LocalDateTime.of(DateUtil.date2LocalDateTime(time).getYear(),
  235 + DateUtil.date2LocalDateTime(time).getMonth(),
  236 + DateUtil.date2LocalDateTime(time).getDayOfMonth(),
  237 + DateUtil.date2LocalDateTime(time).getHour(),
  238 + 0, 0);
  239 + return DateUtil.localDateTime2Date(thisHourStart);
  240 + }
  241 +
  242 + public static Date getThisHourEndTime(Date time) {
  243 + final LocalDateTime thisHourEnd = LocalDateTime.of(DateUtil.date2LocalDateTime(time).getYear(),
  244 + DateUtil.date2LocalDateTime(time).getMonth(),
  245 + DateUtil.date2LocalDateTime(time).getDayOfMonth(),
  246 + DateUtil.date2LocalDateTime(time).getHour(),
  247 + 59, 59);
  248 + return DateUtil.localDateTime2Date(thisHourEnd);
  249 + }
  250 +
  251 + /**
  252 + * 获取当天起始时间
  253 + *
  254 + * @return 当天起始时间
  255 + */
  256 + public static Date getCurrentDayStartTime() {
  257 + LocalDateTime now = LocalDateTime.now();
  258 + LocalDateTime start = LocalDateTime.of(now.getYear(), now.getMonth(), now.getDayOfMonth(), 0, 0, 0);
  259 + ZoneId zone = ZoneId.systemDefault();
  260 + Instant instant = start.atZone(zone).toInstant();
  261 + return Date.from(instant);
  262 + }
  263 +
  264 + /**
  265 + * 获取当天结束时间
  266 + *
  267 + * @return 当天结束时间
  268 + */
  269 + public static Date getCurrentDayEndTime() {
  270 + LocalDateTime now = LocalDateTime.now();
  271 + LocalDateTime end = LocalDateTime.of(now.getYear(), now.getMonth(), now.getDayOfMonth(), 23, 59, 59);
  272 + ZoneId zone = ZoneId.systemDefault();
  273 + Instant instant = end.atZone(zone).toInstant();
  274 + return Date.from(instant);
  275 + }
  276 +
  277 +
  278 + /**
  279 + * 获取短时间字符串
  280 + *
  281 + * @param date 需要转换格式的日期
  282 + * @return 返回短时间字符串格式 yyyy-MM-dd
  283 + */
  284 + public static String getStringDateShort(Date date) {
  285 + if (date == null) {
  286 + return null;
  287 + }
  288 + String dateString = sdf.format(date);
  289 + return dateString;
  290 + }
  291 +
  292 + /**
  293 + * 获取时间字符串
  294 + *
  295 + * @param date 需要转换格式的日期
  296 + * @return 返回短时间字符串格式 yyyy-MM-dd HH:mm:ss
  297 + */
  298 + public static String getFullDateString(Date date) {
  299 + if (date == null) {
  300 + return "";
  301 + }
  302 + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  303 + return format.format(date);
  304 + }
  305 +
  306 + /**
  307 + * 获取时间字符串
  308 + *
  309 + * @param date 需要转换格式的日期
  310 + * @return 返回短时间字符串格式 yyyy-MM
  311 + */
  312 + public static String getMonthString(Date date) {
  313 + if (date == null) {
  314 + return "";
  315 + }
  316 + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
  317 + return format.format(date);
  318 + }
  319 +
  320 + /**
  321 + * 获取时间字符串
  322 + *
  323 + * @param date 需要转换格式的日期
  324 + * @param pattern 时间字符串格式
  325 + * @return 返回时间字符串
  326 + */
  327 + public static String getFormatString(Date date, String pattern) {
  328 + if (date == null) {
  329 + return "";
  330 + }
  331 + SimpleDateFormat format = new SimpleDateFormat(pattern);
  332 + return format.format(date);
  333 + }
  334 +
  335 + /**
  336 + * 获取下月月初时间
  337 + */
  338 + public static Date getNextMonthStartTime() {
  339 + return DateUtil.localDate2Date(LocalDateTime.now()
  340 + .with(TemporalAdjusters.lastDayOfMonth()).plusDays(1L).toLocalDate());
  341 + }
  342 +
  343 + /**
  344 + * @param offsetYear
  345 + * @return 当前时间 + offsetYear
  346 + */
  347 + public static Timestamp getNowExpiredYear(int offsetYear) {
  348 + Calendar now = Calendar.getInstance();
  349 + now.add(Calendar.YEAR, offsetYear);
  350 + return new Timestamp(now.getTime().getTime());
  351 + }
  352 +
  353 + /**
  354 + * @param offset
  355 + * @return 当前时间 + offsetMonth
  356 + */
  357 + public static Timestamp getNowExpiredMonth(int offset) {
  358 + Calendar now = Calendar.getInstance();
  359 + now.add(Calendar.MONTH, offset);
  360 + return new Timestamp(now.getTime().getTime());
  361 + }
  362 +
  363 + /**
  364 + * @param offset
  365 + * @return 当前时间 + offsetDay
  366 + */
  367 + public static Timestamp getNowExpiredDay(int offset) {
  368 + Calendar now = Calendar.getInstance();
  369 + now.add(Calendar.DATE, offset);
  370 + return new Timestamp(now.getTime().getTime());
  371 + }
  372 +
  373 + /**
  374 + * @param offset
  375 + * @return 当前时间 + offsetDay
  376 + */
  377 + public static Timestamp getNowExpiredHour(int offset) {
  378 + Calendar now = Calendar.getInstance();
  379 + now.add(Calendar.HOUR, offset);
  380 + return new Timestamp(now.getTime().getTime());
  381 + }
  382 +
  383 + /**
  384 + * @param offsetSecond
  385 + * @return 当前时间 + offsetSecond
  386 + */
  387 + public static Timestamp getNowExpiredSecond(int offsetSecond) {
  388 + Calendar now = Calendar.getInstance();
  389 + now.add(Calendar.SECOND, offsetSecond);
  390 + return new Timestamp(now.getTime().getTime());
  391 + }
  392 +
  393 + /**
  394 + * @param offset
  395 + * @return 当前时间 + offset
  396 + */
  397 + public static Timestamp getNowExpiredMinute(int offset) {
  398 + Calendar now = Calendar.getInstance();
  399 + now.add(Calendar.MINUTE, offset);
  400 + return new Timestamp(now.getTime().getTime());
  401 + }
  402 +
  403 + /**
  404 + * @param offset
  405 + * @return 指定时间 + offsetDay
  406 + */
  407 + public static Timestamp getExpiredDay(Date givenDate, int offset) {
  408 + Calendar date = Calendar.getInstance();
  409 + date.setTime(givenDate);
  410 + date.add(Calendar.DATE, offset);
  411 + return new Timestamp(date.getTime().getTime());
  412 + }
  413 +
  414 + /**
  415 + * 实现ORACLE中ADD_MONTHS函数功能
  416 + *
  417 + * @param offset
  418 + * @return 指定时间 + offsetMonth
  419 + */
  420 + public static Timestamp getExpiredMonth(Date givenDate, int offset) {
  421 + Calendar date = Calendar.getInstance();
  422 + date.setTime(givenDate);
  423 + date.add(Calendar.MONTH, offset);
  424 + return new Timestamp(date.getTime().getTime());
  425 + }
  426 +
  427 + /**
  428 + * @param
  429 + * @return 指定时间 + offsetYear
  430 + */
  431 + public static Timestamp getExpiredYear(Date givenDate, int offsetYear) {
  432 + Calendar date = Calendar.getInstance();
  433 + date.setTime(givenDate);
  434 + date.add(Calendar.YEAR, offsetYear);
  435 + return new Timestamp(date.getTime().getTime());
  436 + }
  437 +
  438 + /**
  439 + * @param second
  440 + * @return 指定时间 + offsetSecond
  441 + */
  442 + public static Timestamp getExpiredSecond(Date givenDate, int second) {
  443 + Calendar date = Calendar.getInstance();
  444 + date.setTime(givenDate);
  445 + date.add(Calendar.SECOND, second);
  446 + return new Timestamp(date.getTime().getTime());
  447 + }
  448 +
  449 + /**
  450 + * 计算时间差
  451 + *
  452 + * @param givenDate 日期
  453 + * @param offset 2
  454 + * @param type 日期字段类型
  455 + * @return
  456 + */
  457 + public static Timestamp getExpired(Date givenDate, int offset, Integer type) {
  458 + Calendar date = Calendar.getInstance();
  459 + date.setTime(givenDate);
  460 + date.add(type, offset);
  461 + return new Timestamp(date.getTime().getTime());
  462 + }
  463 +
  464 + /**
  465 + * 计算日期差
  466 + *
  467 + * @param d1 开始日期
  468 + * @param d2 截止日期
  469 + * @param type 类型
  470 + * @return 计算结果
  471 + */
  472 + public static Integer sub(Date d1, Date d2, String type) {
  473 + if (d1 == null || d2 == null) {
  474 + return null;
  475 + }
  476 + long result = 0L;
  477 + long DAY = 24 * 60 * 60 * 1000;
  478 + long sub = d1.getTime() - d2.getTime();
  479 + long daysub = (sub / DAY);
  480 + long y1 = d1.getYear(), y2 = d2.getYear();
  481 + long m1 = d1.getMonth(), m2 = d2.getMonth();
  482 + long monthsub = (y1 - y2) * 12 + (m1 - m2);
  483 + //月
  484 + if ("m".equals(type)) {
  485 + result = monthsub;
  486 + //年
  487 + } else if ("y".equals(type)) {
  488 + result = monthsub / 12;
  489 + //天
  490 + } else if ("d".equals(type)) {
  491 + result = daysub;
  492 + }
  493 + return (int) result;
  494 + }
  495 +
  496 + /**
  497 + * 判断是否是凌晨
  498 + *
  499 + * @param date
  500 + * @return
  501 + */
  502 + public static boolean isBeforeDawn(Date date) {
  503 + if (Objects.isNull(date)) {
  504 + return false;
  505 + }
  506 + LocalDateTime dateTime = date2LocalDateTime(date);
  507 + SimpleDateFormat df = new SimpleDateFormat("HH");
  508 + String str = df.format(localDateTime2Date(dateTime));
  509 + int a = Integer.parseInt(str);
  510 + return a >= 0 && a <= 6;
  511 + }
  512 +
  513 + /**
  514 + * 判断是否是上午
  515 + *
  516 + * @param date
  517 + * @return
  518 + */
  519 + public static boolean isMorning(Date date) {
  520 + if (Objects.isNull(date)) {
  521 + return false;
  522 + }
  523 + LocalDateTime dateTime = date2LocalDateTime(date);
  524 + SimpleDateFormat df = new SimpleDateFormat("HH");
  525 + String str = df.format(localDateTime2Date(dateTime));
  526 + int a = Integer.parseInt(str);
  527 + return a > 6 && a <= 12;
  528 + }
  529 +
  530 + /**
  531 + * 判断是否是下午
  532 + *
  533 + * @param date
  534 + * @return
  535 + */
  536 + public static boolean isAfternoon(Date date) {
  537 + if (Objects.isNull(date)) {
  538 + return false;
  539 + }
  540 + LocalDateTime dateTime = date2LocalDateTime(date);
  541 + SimpleDateFormat df = new SimpleDateFormat("HH");
  542 + String str = df.format(localDateTime2Date(dateTime));
  543 + int a = Integer.parseInt(str);
  544 + return a > 12 && a <= 18;
  545 + }
  546 +
  547 + /**
  548 + * 判断是否是晚上
  549 + *
  550 + * @param date
  551 + * @return
  552 + */
  553 + public static boolean isEvening(Date date) {
  554 + if (Objects.isNull(date)) {
  555 + return false;
  556 + }
  557 + LocalDateTime dateTime = date2LocalDateTime(date);
  558 + SimpleDateFormat df = new SimpleDateFormat("HH");
  559 + String str = df.format(localDateTime2Date(dateTime));
  560 + int a = Integer.parseInt(str);
  561 + return a > 18 && a <= 23;
  562 + }
  563 +
  564 + public static void main(String[] args) throws ParseException {
  565 + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  566 + Date date = format.parse("2020-09-19 15:45:30");
  567 +
  568 + Timestamp expired = DateUtil.getExpired(date, 3, Calendar.DATE);
  569 + if (!isBeforeDawn(expired)) {
  570 + expired = getExpired(startDate(expired), 1, Calendar.DATE);
  571 + System.out.println(expired);
  572 + }
  573 + System.out.println(getEndInTime(getMonthEndDay()));
  574 + System.out.println(expired);
  575 + System.out.println(startDate(DateUtil.getMonthFirstDay(date)));
  576 + ;
  577 + }
  578 +}
fw-hestia-common/src/main/java/cn/fw/hestia/common/utils/MessageFormatUtil.java 0 → 100644
  1 +package cn.fw.hestia.common.utils;
  2 +
  3 +import java.text.MessageFormat;
  4 +import java.util.ArrayList;
  5 +import java.util.Date;
  6 +import java.util.List;
  7 +
  8 +/**
  9 + * @author kurisu
  10 + * @description 占位符转换工具
  11 + * @date 2019/5/30.
  12 + */
  13 +public class MessageFormatUtil {
  14 +
  15 + public static String MessageFormatTransfer(String pattern, Object... arguments) {
  16 + List<Object> param = new ArrayList<>();
  17 + for (int i = 0; i < arguments.length; i++) {
  18 + if (arguments[i] instanceof Number) {
  19 + param.add(String.valueOf(arguments[i]));
  20 + }else {
  21 + param.add(arguments[i]);
  22 + }
  23 + }
  24 + return MessageFormat.format(pattern, param.toArray());
  25 + }
  26 +
  27 + public static void main(String[] args) {
  28 + System.out.println("示例:" + MessageFormatTransfer("crm:valhalla:save:lock:key:{0}:{1}", 11111L, new Date()));
  29 + }
  30 +
  31 +}
fw-hestia-common/src/main/java/cn/fw/hestia/common/utils/StringUtils.java 0 → 100644
  1 +package cn.fw.hestia.common.utils;
  2 +
  3 +
  4 +import java.io.IOException;
  5 +import java.io.UnsupportedEncodingException;
  6 +import java.util.ArrayList;
  7 +import java.util.Arrays;
  8 +import java.util.List;
  9 +import java.util.UUID;
  10 +import java.util.regex.Matcher;
  11 +import java.util.regex.Pattern;
  12 +
  13 +/**
  14 + * 字符串工具
  15 + *
  16 + * @author: kurisu
  17 + * @version: 1.0
  18 + */
  19 +public final class StringUtils {
  20 +
  21 + /**
  22 + * 空字符串
  23 + */
  24 + public static final String EMPTY = "";
  25 + /**
  26 + * 特殊字符正则表达式
  27 + */
  28 + public static final String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
  29 +
  30 + public static final String regNo = "^[-\\+]?[\\d]*$";
  31 +
  32 + private StringUtils() {
  33 + }
  34 +
  35 + /**
  36 + * 首字母小写
  37 + *
  38 + * @param s String
  39 + * @return String
  40 + */
  41 + public static String firstCharLowerCase(String s) {
  42 + if (isValid(s)) {
  43 + return s.substring(0, 1).toLowerCase() + s.substring(1);
  44 + }
  45 + return s;
  46 + }
  47 +
  48 + /**
  49 + * 删除前缀
  50 + *
  51 + * @param s
  52 + * @param prefix
  53 + * @return
  54 + */
  55 + public static String removePrefix(String s, String prefix) {
  56 + int index = s.indexOf(prefix);
  57 + return index == 0 ? s.substring(prefix.length()) : s;
  58 + }
  59 +
  60 + /**
  61 + * 删除后缀
  62 + *
  63 + * @param s
  64 + * @param suffix
  65 + * @return
  66 + */
  67 + public static String removeSuffix(String s, String suffix) {
  68 + return s.endsWith(suffix) ? s.substring(0, s.length() - suffix.length()) : s;
  69 + }
  70 +
  71 + /**
  72 + * 首字母大写
  73 + *
  74 + * @param s String
  75 + * @return String
  76 + */
  77 + public static String firstCharUpperCase(String s) {
  78 + if (isValid(s)) {
  79 + return s.substring(0, 1).toUpperCase() + s.substring(1);
  80 + }
  81 + return s;
  82 + }
  83 +
  84 + /**
  85 + * 检查对象是否有效 obj != null && obj.toString().length() > 0
  86 + *
  87 + * @param obj
  88 + * @return boolean
  89 + */
  90 + public static boolean isValid(Object obj) {
  91 + return obj != null && obj.toString().length() > 0;
  92 + }
  93 +
  94 + /**
  95 + * 是否是空的
  96 + *
  97 + * @param obj
  98 + * @return
  99 + */
  100 + public static boolean isEmpty(Object obj) {
  101 + return obj == null || obj.toString().length() == 0;
  102 + }
  103 +
  104 + /**
  105 + * 是否是数字
  106 + *
  107 + * @param obj
  108 + * @return
  109 + */
  110 + public static boolean isNumber(Object obj) {
  111 + if (isEmpty(obj)) {
  112 + return false;
  113 + }
  114 + Pattern compile = Pattern.compile(regNo);
  115 + return compile.matcher(obj.toString()).matches();
  116 + }
  117 +
  118 + /**
  119 + * 转化为String对象
  120 + *
  121 + * @param obj
  122 + * @return boolean
  123 + */
  124 + public static String asString(Object obj) {
  125 + return obj != null ? obj.toString() : "";
  126 + }
  127 +
  128 + /**
  129 + * 返回其中一个有效的对象 value != null && value.toString().length() > 0
  130 + *
  131 + * @param values
  132 + */
  133 + public static String tryThese(Object... values) {
  134 + for (int i = 0; i < values.length; i++) {
  135 + String value = StringUtils.asString(values[i]);
  136 + if (!value.isEmpty()) {
  137 + return value;
  138 + }
  139 + }
  140 + return "";
  141 + }
  142 +
  143 + /**
  144 + * EL表达式提供的定义方法
  145 + *
  146 + * @param v1
  147 + * @param v2
  148 + * @return
  149 + */
  150 + public static String tryThese(String v1, String v2) {
  151 + return tryThese(new Object[]{v1, v2});
  152 + }
  153 +
  154 + /**
  155 + * 连接字符串
  156 + *
  157 + * @param list
  158 + * @param split
  159 + * @return 字符串
  160 + */
  161 + public static <T> String join(T[] list, String split) {
  162 + return join(list, split, "");
  163 + }
  164 +
  165 + /**
  166 + * 连接字符串
  167 + *
  168 + * @param list
  169 + * @param split
  170 + * @return 字符串
  171 + */
  172 + public static <T> String join(T[] list, String split, String wrap) {
  173 + if (list == null) {
  174 + return null;
  175 + }
  176 + StringBuilder s = new StringBuilder(128);
  177 + for (int i = 0; i < list.length; i++) {
  178 + if (i > 0) {
  179 + s.append(split);
  180 + }
  181 + s.append(wrap + list[i] + wrap);
  182 + }
  183 + return s.toString();
  184 + }
  185 +
  186 + /**
  187 + * 连接
  188 + *
  189 + * @param list
  190 + * @param split
  191 + * @param wrap
  192 + * @return
  193 + */
  194 + public static <T> String join(List<T> list, String split, String wrap) {
  195 + return join(list.toArray(), split, wrap);
  196 + }
  197 +
  198 + /**
  199 + * 连接字符串
  200 + *
  201 + * @param list
  202 + * @param split
  203 + * @return 字符串
  204 + */
  205 + public static String join(List<?> list, String split) {
  206 + return join(list.toArray(), split);
  207 + }
  208 +
  209 + /**
  210 + * 包裹字符串 id:12, {, } 输出 {id:12}
  211 + *
  212 + * @param input 输入串
  213 + * @param begin {
  214 + * @param end }
  215 + * @return String
  216 + */
  217 + public static String wrap(String begin, String input, String end) {
  218 + if (!input.startsWith(begin)) {
  219 + input = begin + input;
  220 + }
  221 + if (!input.endsWith(end)) {
  222 + input = input + end;
  223 + }
  224 + return input;
  225 + }
  226 +
  227 + /**
  228 + * 取得匹配的字符串
  229 + *
  230 + * @param input
  231 + * @param regex
  232 + * @return
  233 + */
  234 + public static List<String> matchs(String input, String regex) {
  235 + return matchs(input, regex, 0);
  236 + }
  237 +
  238 + /**
  239 + * 取得匹配的字符串
  240 + *
  241 + * @param input
  242 + * @param regex
  243 + * @return
  244 + */
  245 + public static List<String> matchs(String input, String regex, int group) {
  246 + Pattern pattern = Pattern.compile(regex);
  247 + Matcher match = pattern.matcher(input);
  248 + List<String> matches = new ArrayList<String>();
  249 + while (match.find()) {
  250 + matches.add(match.group(group));
  251 + }
  252 + return matches;
  253 + }
  254 +
  255 + /**
  256 + * 找到匹配的第一个字符串
  257 + *
  258 + * @param input
  259 + * @param regex
  260 + * @param group
  261 + * @return
  262 + */
  263 + public static String matchFirst(String input, String regex, int group) {
  264 + List<String> matches = matchs(input, regex, group);
  265 + return matches.isEmpty() ? null : matches.get(0);
  266 + }
  267 +
  268 + /**
  269 + * 截取指定长度字符串
  270 + *
  271 + * @return
  272 + */
  273 + public static String getShorterString(String str, int maxLength) {
  274 + return getShorterString(str, "...", maxLength);
  275 + }
  276 +
  277 + /**
  278 + * 截取指定长度字符串
  279 + *
  280 + * @param input
  281 + * @param tail
  282 + * @param length
  283 + * @return
  284 + */
  285 + public static String getShorterString(String input, String tail, int length) {
  286 + tail = isValid(tail) ? tail : "";
  287 + StringBuffer buffer = new StringBuffer(512);
  288 + try {
  289 + int len = input.getBytes("GBK").length;
  290 + if (len > length) {
  291 + int ln = 0;
  292 + for (int i = 0; ln < length; i++) {
  293 + String temp = input.substring(i, i + 1);
  294 + if (temp.getBytes("GBK").length == 2) {
  295 + ln += 2;
  296 + } else {
  297 + ln++;
  298 + }
  299 +
  300 + if (ln <= length) {
  301 + buffer.append(temp);
  302 + }
  303 + }
  304 + } else {
  305 + return input;
  306 + }
  307 + buffer.append(tail);
  308 + } catch (UnsupportedEncodingException e) {
  309 + e.printStackTrace();
  310 + }
  311 + return buffer.toString();
  312 + }
  313 +
  314 + /**
  315 + * 取得GBK编码
  316 + *
  317 + * @return
  318 + */
  319 + public static String getBytesString(String input, String code) {
  320 + try {
  321 + byte[] b = input.getBytes(code);
  322 + return Arrays.toString(b);
  323 + } catch (UnsupportedEncodingException e) {
  324 + return String.valueOf(code.hashCode());
  325 + }
  326 + }
  327 +
  328 + /**
  329 + * 转换格式 CUST_INFO_ID - > custInfoId
  330 + *
  331 + * @param input
  332 + * @return
  333 + */
  334 + public static String getFieldString(String input) {
  335 + if (input == null) {
  336 + return null;
  337 + }
  338 + String field = input.toLowerCase();
  339 + String[] values = field.split("\\_");
  340 + StringBuffer b = new StringBuffer(input.length());
  341 + for (int i = 0; i < values.length; i++) {
  342 + if (i == 0) {
  343 + b.append(values[i]);
  344 + } else {
  345 + b.append(firstCharUpperCase(values[i]));
  346 + }
  347 + }
  348 + return b.toString();
  349 + }
  350 +
  351 + /**
  352 + * 转换格式 CUST_INFO_ID - > custInfoId
  353 + *
  354 + * @param columnName
  355 + * @return
  356 + */
  357 + public static String toFieldName(String columnName) {
  358 + return getFieldString(columnName);
  359 + }
  360 +
  361 + /**
  362 + * 转换格式 custInfoId - > CUST_INFO_ID
  363 + *
  364 + * @param field
  365 + * @return
  366 + */
  367 + public static String toColumnName(String field) {
  368 + if (field == null) {
  369 + return null;
  370 + }
  371 + StringBuffer b = new StringBuffer(field.length() + 3);
  372 + for (int i = 0; i < field.length(); i++) {
  373 + Character char1 = field.charAt(i);
  374 + if (Character.isUpperCase(char1) && i != 0) {
  375 + b.append("_");
  376 + }
  377 + b.append(char1);
  378 + }
  379 + return b.toString();
  380 + }
  381 +
  382 + /**
  383 + * 转化为JSON值
  384 + *
  385 + * @param value
  386 + * @return
  387 + * @throws IOException
  388 + */
  389 + public static String toJsonValue(Object value) throws IOException {
  390 + if (value instanceof Number) {
  391 + return value.toString();
  392 + } else {
  393 + return "'" + value.toString() + "'";
  394 + }
  395 + }
  396 +
  397 + /**
  398 + * 字符串转化为UUID
  399 + *
  400 + * @param value
  401 + * @return
  402 + */
  403 + public static String toUUID(String value) {
  404 + if (value == null) {
  405 + throw new RuntimeException("value is null!");
  406 + }
  407 + return UUID.nameUUIDFromBytes(value.getBytes()).toString();
  408 + }
  409 +
  410 + /**
  411 + * 获取Style样式中样式的值
  412 + *
  413 + * @param styleString
  414 + * @param styleName
  415 + * @return 相应的值
  416 + */
  417 + public static String getStyleValue(String styleString, String styleName) {
  418 + String[] styles = styleString.split(";");
  419 + for (int i = 0; i < styles.length; i++) {
  420 + String tempValue = styles[i].trim();
  421 + if (tempValue.startsWith(styleName)) {
  422 + String[] style = tempValue.split(":");
  423 + return style[1];
  424 + }
  425 + }
  426 + return "";
  427 + }
  428 +
  429 + /**
  430 + * 生成重复次字符
  431 + *
  432 + * @param charactor
  433 + * @param repeat
  434 + * @return
  435 + */
  436 + public static String getRepeat(String charactor, int repeat) {
  437 + return repeat(charactor, repeat, "");
  438 + }
  439 +
  440 + /**
  441 + * 生成重复次字符
  442 + *
  443 + * @param charactor
  444 + * @param repeat
  445 + * @return
  446 + */
  447 + public static String repeat(String charactor, int repeat, String split) {
  448 + StringBuilder s = new StringBuilder(charactor.length() * repeat);
  449 + for (int i = 0; i < repeat; i++) {
  450 + if (i != 0) {
  451 + s.append(split != null ? split : "");
  452 + }
  453 + s.append(charactor);
  454 + }
  455 + return s.toString();
  456 + }
  457 +
  458 + /**
  459 + * 取得长度
  460 + *
  461 + * @param text
  462 + * @return
  463 + */
  464 + public static int length(String text) {
  465 + int len = text.length();
  466 + try {
  467 + len = text.getBytes("GBK").length;//SQLServer数据库用的GBK编码
  468 + } catch (UnsupportedEncodingException e) {
  469 + e.printStackTrace();
  470 + }
  471 + return len;
  472 + }
  473 +
  474 + /**
  475 + * 字符串替换函数
  476 + *
  477 + * @param data 字符串
  478 + * @param data from 旧值
  479 + * @param to from 新值
  480 + */
  481 + public static String replaceString(String data, String from, String to) {
  482 + StringBuffer buf = new StringBuffer(data.length());
  483 + int pos = -1;
  484 + int i = 0;
  485 + while ((pos = data.indexOf(from, i)) != -1) {
  486 + buf.append(data.substring(i, pos)).append(to);
  487 + i = pos + from.length();
  488 + }
  489 + buf.append(data.substring(i));
  490 + return buf.toString();
  491 + }
  492 +
  493 + /**
  494 + * 转义特殊字符
  495 + *
  496 + * @param s
  497 + * @return
  498 + */
  499 + public static String escapeQueryChars(String s) {
  500 + if (StringUtils.isEmpty(s)) {
  501 + return s;
  502 + }
  503 + StringBuilder sb = new StringBuilder();
  504 + //查询字符串一般不会太长,挨个遍历也花费不了多少时间
  505 + for (int i = 0; i < s.length(); i++) {
  506 + char c = s.charAt(i);
  507 + if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')'
  508 + || c == ':' || c == '^' || c == '[' || c == ']' || c == '\"'
  509 + || c == '{' || c == '}' || c == '~' || c == '*' || c == '?'
  510 + || c == '|' || c == '&' || c == ';' || c == '/' || c == '.'
  511 + || c == '$' || c == '%' || c == '<' || c == '>' || Character.isWhitespace(c)) {
  512 + sb.append('\\');
  513 + }
  514 + sb.append(c);
  515 + }
  516 + return sb.toString();
  517 + }
  518 +
  519 +
  520 + /**
  521 + * 获取默认值
  522 + * @param str
  523 + * @param defaultStr
  524 + * @return
  525 + */
  526 + public static String getStrWithDefault(CharSequence str, String defaultStr) {
  527 + if (isEmpty(defaultStr)) {
  528 + defaultStr = "";
  529 + }
  530 + if (isEmpty(str)) {
  531 + return defaultStr;
  532 + }
  533 + return str.toString();
  534 + }
  535 +
  536 + public static void main(String[] args) {
  537 + System.out.println(toUUID("1"));
  538 + System.out.println(removePrefix("abcd123", "ab"));
  539 + System.out.println(removeSuffix("abcd123", "123"));
  540 + System.out.println(toColumnName("usernameId"));
  541 + System.out.println(getFieldString("user_name_id"));
  542 + System.out.println(repeat("?", 10, ","));
  543 + length("AAA中国()111222bb");
  544 + }
  545 +}
0 \ No newline at end of file 546 \ No newline at end of file
fw-hestia-dao/src/main/java/cn/fw/hestia/dao/DemoDao.java 0 → 100644
  1 +package cn.fw.hestia.dao;
  2 +
  3 +/**
  4 + * @author : kurisu
  5 + * @className : DemoDao
  6 + * @description :
  7 + * @date: 2021-09-23 15:23
  8 + */
  9 +public interface DemoDao {
  10 +}
fw-hestia-dao/src/main/resources/mapper/DemoMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="cn.fw.hestia.dao.DemoDao">
  4 +
  5 +</mapper>
fw-hestia-domain/src/main/java/Demo.java renamed to fw-hestia-domain/src/main/java/cn/fw/hestia/domain/db/Demo.java
  1 +package cn.fw.hestia.domain.db;
  2 +
1 /** 3 /**
2 * @author : kurisu 4 * @author : kurisu
3 * @className : Demo 5 * @className : Demo
4 * @description : 6 * @description :
5 - * @date: 2021-09-23 14:45 7 + * @date: 2021-09-23 15:26
6 */ 8 */
7 public class Demo { 9 public class Demo {
8 } 10 }
fw-hestia-sdk/src/main/java/Demo.java renamed to fw-hestia-domain/src/main/java/cn/fw/hestia/domain/vo/Demo.java
  1 +package cn.fw.hestia.domain.vo;
  2 +
1 /** 3 /**
2 * @author : kurisu 4 * @author : kurisu
3 * @className : Demo 5 * @className : Demo
4 * @description : 6 * @description :
5 - * @date: 2021-09-23 14:59 7 + * @date: 2021-09-23 15:26
6 */ 8 */
7 public class Demo { 9 public class Demo {
8 } 10 }
fw-hestia-rpc/pom.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5 + <parent>
  6 + <artifactId>fw-hestia</artifactId>
  7 + <groupId>cn.fw</groupId>
  8 + <version>1.0.0</version>
  9 + <relativePath>../pom.xml</relativePath>
  10 + </parent>
  11 + <modelVersion>4.0.0</modelVersion>
  12 +
  13 + <artifactId>fw-hestia-rpc</artifactId>
  14 + <packaging>jar</packaging>
  15 + <name>fw-hestia-rpc</name>
  16 +
  17 + <dependencies>
  18 + <dependency>
  19 + <groupId>org.springframework</groupId>
  20 + <artifactId>spring-context</artifactId>
  21 + </dependency>
  22 + <dependency>
  23 + <groupId>cn.fw</groupId>
  24 + <artifactId>fw-hestia-common</artifactId>
  25 + </dependency>
  26 + <!-- fw common -->
  27 + <dependency>
  28 + <groupId>cn.fw</groupId>
  29 + <artifactId>fw-common-core</artifactId>
  30 + <optional>true</optional>
  31 + </dependency>
  32 + <dependency>
  33 + <groupId>org.springframework.data</groupId>
  34 + <artifactId>spring-data-redis</artifactId>
  35 + <optional>true</optional>
  36 + </dependency>
  37 + </dependencies>
  38 +
  39 +</project>
0 \ No newline at end of file 40 \ No newline at end of file
fw-hestia-rpc/src/main/java/cn/fw/hestia/rpc/AbsBaseRpcService.java 0 → 100644
  1 +package cn.fw.hestia.rpc;
  2 +
  3 +import cn.fw.hestia.common.utils.StringUtils;
  4 +import com.alibaba.fastjson.JSON;
  5 +import com.alibaba.fastjson.JSONObject;
  6 +import lombok.extern.slf4j.Slf4j;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.data.redis.core.BoundListOperations;
  9 +import org.springframework.data.redis.core.BoundValueOperations;
  10 +import org.springframework.data.redis.core.StringRedisTemplate;
  11 +import org.springframework.lang.NonNull;
  12 +import org.springframework.lang.Nullable;
  13 +
  14 +import java.util.ArrayList;
  15 +import java.util.List;
  16 +import java.util.Objects;
  17 +import java.util.Optional;
  18 +import java.util.concurrent.TimeUnit;
  19 +
  20 +/**
  21 + * @author : kurisu
  22 + * @className : AbsBaseRpcService
  23 + * @description : 公共方法
  24 + * @date: 2020-12-17 14:13
  25 + */
  26 +@Slf4j
  27 +public abstract class AbsBaseRpcService {
  28 + /**
  29 + * Redis工具
  30 + */
  31 + @Autowired
  32 + protected StringRedisTemplate redisTemplate;
  33 +
  34 + /**
  35 + * 缓存KEY前缀
  36 + *
  37 + * @return
  38 + */
  39 + protected abstract String getKeyPrefix();
  40 +
  41 + /**
  42 + * 从缓存获取对象
  43 + *
  44 + * @param key
  45 + * @param clazz
  46 + * @param <E> 获取的对象
  47 + * @return
  48 + */
  49 + @Nullable
  50 + protected <E> E getFromCache(@NonNull final String key, Class<E> clazz) {
  51 + String cache = getFromCache(key);
  52 + if (StringUtils.isEmpty(cache)) {
  53 + return null;
  54 + }
  55 + return JSON.parseObject(cache, clazz);
  56 + }
  57 +
  58 + protected String getFromCache(@NonNull final String key) {
  59 + String json = null;
  60 + try {
  61 + BoundValueOperations<String, String> ops = redisTemplate.boundValueOps(key);
  62 + json = ops.get();
  63 + } catch (Exception e) {
  64 + log.error("从缓存获信息失败[{}]", key, e);
  65 + }
  66 + return json;
  67 + }
  68 +
  69 + protected void setToCache(@NonNull final String key, @NonNull final String value) {
  70 + setToCache(key, value, 30);
  71 + }
  72 +
  73 + /**
  74 + * 缓存信息
  75 + * @param key
  76 + * @param value
  77 + * @param timeout 缓存时间(秒)
  78 + */
  79 + protected void setToCache(@NonNull final String key, @NonNull final String value, long timeout) {
  80 + try {
  81 + redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS);
  82 + } catch (Exception e) {
  83 + log.error("缓存信息失败[{}][{}]", key, value, e);
  84 + }
  85 + }
  86 +
  87 + protected <E> List<E> getListFromCache(final String key, Class<E> clazz) {
  88 + try {
  89 + BoundListOperations<String, String> queue = getQueue(key);
  90 + final long size = Optional.ofNullable(queue.size()).orElse(0L);
  91 + if (size > 0) {
  92 + final List<E> dtos = new ArrayList<>();
  93 + for (long i = 0; i < size; i++) {
  94 + final String json = Objects.requireNonNull(queue.index(i));
  95 + dtos.add(JSONObject.parseObject(json, clazz));
  96 + }
  97 + return dtos;
  98 + }
  99 + } catch (Exception e) {
  100 + log.error("从缓存获取信息失败[{}]", key, e);
  101 + }
  102 + return null;
  103 + }
  104 +
  105 + protected void setListToCache(@NonNull final String key, @NonNull final String value) {
  106 + try {
  107 + getQueue(key).rightPush(value);
  108 + } catch (Exception e) {
  109 + log.error("缓存息失败[{}][{}]", key, value, e);
  110 + }
  111 + }
  112 +
  113 + protected BoundListOperations<String, String> getQueue(@NonNull final String key) {
  114 + return redisTemplate.boundListOps(key);
  115 + }
  116 +}
fw-hestia-server/src/main/java/Demo.java renamed to fw-hestia-sdk/src/main/java/cn/fw/hestia/sdk/api/Demo.java
  1 +package cn.fw.hestia.sdk.api;
  2 +
1 /** 3 /**
2 * @author : kurisu 4 * @author : kurisu
3 * @className : Demo 5 * @className : Demo
4 * @description : 6 * @description :
5 - * @date: 2021-09-23 14:47 7 + * @date: 2021-09-23 15:27
6 */ 8 */
7 public class Demo { 9 public class Demo {
8 } 10 }
fw-hestia-server/pom.xml
@@ -67,7 +67,7 @@ @@ -67,7 +67,7 @@
67 <!-- fw-local --> 67 <!-- fw-local -->
68 <dependency> 68 <dependency>
69 <groupId>cn.fw</groupId> 69 <groupId>cn.fw</groupId>
70 - <artifactId>fw-pstn-service</artifactId> 70 + <artifactId>fw-hestia-service</artifactId>
71 </dependency> 71 </dependency>
72 <!-- fw-remote --> 72 <!-- fw-remote -->
73 <dependency> 73 <dependency>
@@ -108,15 +108,11 @@ @@ -108,15 +108,11 @@
108 <groupId>io.micrometer</groupId> 108 <groupId>io.micrometer</groupId>
109 <artifactId>micrometer-registry-prometheus</artifactId> 109 <artifactId>micrometer-registry-prometheus</artifactId>
110 </dependency> 110 </dependency>
111 - <dependency>  
112 - <groupId>cn.hutool</groupId>  
113 - <artifactId>hutool-all</artifactId>  
114 - </dependency>  
115 111
116 </dependencies> 112 </dependencies>
117 113
118 <build> 114 <build>
119 - <finalName>fw-pstn-server</finalName> 115 + <finalName>fw-hestia-server</finalName>
120 <resources> 116 <resources>
121 <resource> 117 <resource>
122 <directory>src/main/resources</directory> 118 <directory>src/main/resources</directory>
fw-hestia-server/src/main/java/cn/fw/hestia/server/Application.java 0 → 100644
  1 +package cn.fw.hestia.server;
  2 +
  3 +import cn.fw.security.auth.client.EnableAuthClient;
  4 +import org.mybatis.spring.annotation.MapperScan;
  5 +import org.springframework.boot.SpringApplication;
  6 +import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  7 +import org.springframework.cache.annotation.EnableCaching;
  8 +import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  9 +import org.springframework.cloud.openfeign.EnableFeignClients;
  10 +import org.springframework.context.annotation.ComponentScan;
  11 +import org.springframework.context.annotation.Configuration;
  12 +import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
  13 +import org.springframework.scheduling.annotation.EnableScheduling;
  14 +
  15 +/**
  16 + * 启动类
  17 + *
  18 + * @author kurisu
  19 + */
  20 +@EnableCaching
  21 +@EnableAuthClient
  22 +@EnableScheduling
  23 +@EnableDiscoveryClient
  24 +@EnableAutoConfiguration
  25 +@Configuration
  26 +@EnableRedisRepositories
  27 +@MapperScan("cn.fw.**.mapper")
  28 +@ComponentScan({"cn.fw.hestia.*"})
  29 +@EnableFeignClients({"cn.fw.**.sdk"})
  30 +public class Application {
  31 + public static void main(final String[] args) {
  32 + SpringApplication.run(Application.class, args);
  33 + }
  34 +}
fw-hestia-common/src/main/java/Demo.java renamed to fw-hestia-server/src/main/java/cn/fw/hestia/server/controller/api/Demo.java
  1 +package cn.fw.hestia.server.controller.api;
  2 +
1 /** 3 /**
2 * @author : kurisu 4 * @author : kurisu
3 * @className : Demo 5 * @className : Demo
4 - * @description : demo  
5 - * @date: 2021-09-23 14:29 6 + * @description :
  7 + * @date: 2021-09-23 15:39
6 */ 8 */
7 public class Demo { 9 public class Demo {
8 } 10 }
fw-hestia-server/src/main/resources/application.yml
@@ -54,7 +54,7 @@ auth: @@ -54,7 +54,7 @@ auth:
54 fastdfs: 54 fastdfs:
55 charset: UTF-8 55 charset: UTF-8
56 connectTimeout: 2 56 connectTimeout: 2
57 - group: pstndfs 57 + group: hestiadfs
58 networkTimeout: 30 58 networkTimeout: 30
59 port: 8080 59 port: 8080
60 secretKey: FastDFS1234567890 60 secretKey: FastDFS1234567890
fw-hestia-server/src/main/resources/logfile.xml
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <included> 2 <included>
3 - <property name="filePrefix" value="fw-pstn"/> 3 + <property name="filePrefix" value="fw_hestia"/>
4 <property name="logMaxHistory" value="2"/> 4 <property name="logMaxHistory" value="2"/>
5 <property name="logfileMaxSize" value="512MB"/> 5 <property name="logfileMaxSize" value="512MB"/>
6 <property name="logTotalSizeCap" value="512MB"/> 6 <property name="logTotalSizeCap" value="512MB"/>
fw-hestia-service/pom.xml
@@ -10,6 +10,8 @@ @@ -10,6 +10,8 @@
10 <modelVersion>4.0.0</modelVersion> 10 <modelVersion>4.0.0</modelVersion>
11 11
12 <artifactId>fw-hestia-service</artifactId> 12 <artifactId>fw-hestia-service</artifactId>
  13 + <packaging>jar</packaging>
  14 + <name>fw-hestia-service</name>
13 15
14 <dependencies> 16 <dependencies>
15 <dependency> 17 <dependency>
@@ -48,7 +50,7 @@ @@ -48,7 +50,7 @@
48 </dependency> 50 </dependency>
49 <dependency> 51 <dependency>
50 <groupId>cn.fw</groupId> 52 <groupId>cn.fw</groupId>
51 - <artifactId>fw-pstn-dao</artifactId> 53 + <artifactId>fw-hestia-dao</artifactId>
52 </dependency> 54 </dependency>
53 <dependency> 55 <dependency>
54 <groupId>org.slf4j</groupId> 56 <groupId>org.slf4j</groupId>
@@ -68,7 +70,7 @@ @@ -68,7 +70,7 @@
68 </dependency> 70 </dependency>
69 <dependency> 71 <dependency>
70 <groupId>cn.fw</groupId> 72 <groupId>cn.fw</groupId>
71 - <artifactId>fw-pstn-sdk</artifactId> 73 + <artifactId>fw-hestia-sdk</artifactId>
72 </dependency> 74 </dependency>
73 <dependency> 75 <dependency>
74 <groupId>org.apache.rocketmq</groupId> 76 <groupId>org.apache.rocketmq</groupId>
@@ -88,10 +90,6 @@ @@ -88,10 +90,6 @@
88 <groupId>org.redisson</groupId> 90 <groupId>org.redisson</groupId>
89 <artifactId>redisson</artifactId> 91 <artifactId>redisson</artifactId>
90 </dependency> 92 </dependency>
91 - <dependency>  
92 - <groupId>com.google.zxing</groupId>  
93 - <artifactId>javase</artifactId>  
94 - </dependency>  
95 </dependencies> 93 </dependencies>
96 94
97 <build> 95 <build>
fw-hestia-service/src/main/java/cn/fw/hestia/service/Demo.java 0 → 100644
  1 +package cn.fw.hestia.service;
  2 +
  3 +/**
  4 + * @author : kurisu
  5 + * @className : Demo
  6 + * @description :
  7 + * @date: 2021-09-23 15:40
  8 + */
  9 +public interface Demo {
  10 +}
fw-hestia-dao/src/main/java/Demo.java renamed to fw-hestia-service/src/main/java/cn/fw/hestia/service/impl/Demo.java
  1 +package cn.fw.hestia.service.impl;
  2 +
1 /** 3 /**
2 * @author : kurisu 4 * @author : kurisu
3 * @className : Demo 5 * @className : Demo
4 - * @description : demo  
5 - * @date: 2021-09-23 14:34 6 + * @description :
  7 + * @date: 2021-09-23 15:41
6 */ 8 */
7 public class Demo { 9 public class Demo {
8 } 10 }
@@ -22,6 +22,8 @@ @@ -22,6 +22,8 @@
22 <module>fw-hestia-dao</module> 22 <module>fw-hestia-dao</module>
23 <module>fw-hestia-domain</module> 23 <module>fw-hestia-domain</module>
24 <module>fw-hestia-sdk</module> 24 <module>fw-hestia-sdk</module>
  25 + <module>fw-hestia-rpc</module>
  26 + <module>fw-hestia-rpc</module>
25 </modules> 27 </modules>
26 28
27 <properties> 29 <properties>
@@ -34,8 +36,7 @@ @@ -34,8 +36,7 @@
34 <fw.hestia.sdk.version>1.0.0</fw.hestia.sdk.version> 36 <fw.hestia.sdk.version>1.0.0</fw.hestia.sdk.version>
35 <rocketmq-spring-boot-starter.version>2.1.0</rocketmq-spring-boot-starter.version> 37 <rocketmq-spring-boot-starter.version>2.1.0</rocketmq-spring-boot-starter.version>
36 <redis.spring.boot.starter>1.0</redis.spring.boot.starter> 38 <redis.spring.boot.starter>1.0</redis.spring.boot.starter>
37 - <javase>3.0.0</javase>  
38 - <hutool.all>5.2.5</hutool.all> 39 + <fastjson>1.2.51</fastjson>
39 </properties> 40 </properties>
40 41
41 <dependencyManagement> 42 <dependencyManagement>
@@ -100,14 +101,9 @@ @@ -100,14 +101,9 @@
100 <version>${redis.spring.boot.starter}</version> 101 <version>${redis.spring.boot.starter}</version>
101 </dependency> 102 </dependency>
102 <dependency> 103 <dependency>
103 - <groupId>com.google.zxing</groupId>  
104 - <artifactId>javase</artifactId>  
105 - <version>${javase}</version>  
106 - </dependency>  
107 - <dependency>  
108 - <groupId>cn.hutool</groupId>  
109 - <artifactId>hutool-all</artifactId>  
110 - <version>${hutool.all}</version> 104 + <groupId>com.alibaba</groupId>
  105 + <artifactId>fastjson</artifactId>
  106 + <version>${fastjson}</version>
111 </dependency> 107 </dependency>
112 </dependencies> 108 </dependencies>
113 </dependencyManagement> 109 </dependencyManagement>