From 3cbdca0bf36f6f9cab67022b0bbdc11b8ebd4529 Mon Sep 17 00:00:00 2001 From: liuweijw <2429537557@qq.com> Date: Sun, 24 Dec 2017 21:18:18 +0800 Subject: [PATCH] =?UTF-8?q?fw-framework=20=E9=A1=B9=E7=9B=AE=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 9 + fw-aop/pom.xml | 26 + .../com/fw/api/aop/annotation/NoLogin.java | 17 + fw-base/pom.xml | 26 + .../com/fw/api/base/editor/DateEditor.java | 20 + .../com/fw/api/base/editor/StringEditor.java | 26 + .../api/base/exception/BusinessException.java | 20 + .../api/base/exception/SystemException.java | 27 + .../java/com/fw/api/base/util/DateHelper.java | 428 +++++++++ .../com/fw/api/base/util/RandomHelper.java | 106 +++ fw-bean/pom.xml | 22 + .../com/fw/api/bean/version/VersionBean.java | 105 +++ fw-core/pom.xml | 41 + .../java/com/fw/api/core/http/AjaxResult.java | 98 ++ fw-log/pom.xml | 22 + .../main/java/com/fw/api/log/ILogFactory.java | 13 + .../main/java/com/fw/api/log/Lifecycle.java | 28 + fw-log/src/main/java/com/fw/api/log/Log.java | 35 + .../src/main/java/com/fw/api/log/Logger.java | 836 ++++++++++++++++++ .../src/main/java/com/fw/api/log/Logtype.java | 25 + .../main/java/com/fw/api/log/Slf4jLog.java | 398 +++++++++ .../java/com/fw/api/log/Slf4jLogFactory.java | 22 + .../main/java/com/fw/api/log/Slf4jLogger.java | 108 +++ .../api/log/exception/LogConfigException.java | 9 + fw-secure/pom.xml | 31 + .../java/com/fw/api/ex/ExceptionAdvice.java | 212 +++++ .../java/com/fw/api/ex/ServiceException.java | 11 + fw-web/fw_init.sql | 39 + fw-web/pom.xml | 196 ++++ fw-web/readme.md | 14 + .../java/com/fw/api/config/CorsConfig.java | 27 + .../com/fw/api/config/FwFreemarkerView.java | 24 + .../java/com/fw/api/config/RequestConfig.java | 17 + .../com/fw/api/config/RestTemplateConfig.java | 24 + .../com/fw/api/config/Swagger2Config.java | 62 ++ .../com/fw/api/config/WebMvcAutoConfig.java | 32 + .../com/fw/api/secure/LoginInterceptor.java | 45 + .../main/java/com/fw/api/web/Application.java | 45 + .../main/java/com/fw/api/web/bean/FwBean.java | 78 ++ .../java/com/fw/api/web/bean/RetBean.java | 31 + .../api/web/controllers/BaseController.java | 28 + .../ui/version/VersionController.java | 46 + .../java/com/fw/api/web/domain/Version.java | 173 ++++ .../api/web/repository/VersionRepository.java | 11 + .../fw/api/web/service/JPAFactoryImpl.java | 23 + .../main/resources/application-dev.properties | 39 + .../resources/application-proj.properties | 39 + .../src/main/resources/application.properties | 8 + fw-web/src/main/resources/logback-api.xml | 147 +++ pom.xml | 211 +++++ 50 files changed, 4080 insertions(+) create mode 100644 .gitignore create mode 100644 fw-aop/pom.xml create mode 100644 fw-aop/src/main/java/com/fw/api/aop/annotation/NoLogin.java create mode 100644 fw-base/pom.xml create mode 100644 fw-base/src/main/java/com/fw/api/base/editor/DateEditor.java create mode 100644 fw-base/src/main/java/com/fw/api/base/editor/StringEditor.java create mode 100644 fw-base/src/main/java/com/fw/api/base/exception/BusinessException.java create mode 100644 fw-base/src/main/java/com/fw/api/base/exception/SystemException.java create mode 100644 fw-base/src/main/java/com/fw/api/base/util/DateHelper.java create mode 100644 fw-base/src/main/java/com/fw/api/base/util/RandomHelper.java create mode 100644 fw-bean/pom.xml create mode 100644 fw-bean/src/main/java/com/fw/api/bean/version/VersionBean.java create mode 100644 fw-core/pom.xml create mode 100644 fw-core/src/main/java/com/fw/api/core/http/AjaxResult.java create mode 100644 fw-log/pom.xml create mode 100644 fw-log/src/main/java/com/fw/api/log/ILogFactory.java create mode 100644 fw-log/src/main/java/com/fw/api/log/Lifecycle.java create mode 100644 fw-log/src/main/java/com/fw/api/log/Log.java create mode 100644 fw-log/src/main/java/com/fw/api/log/Logger.java create mode 100644 fw-log/src/main/java/com/fw/api/log/Logtype.java create mode 100644 fw-log/src/main/java/com/fw/api/log/Slf4jLog.java create mode 100644 fw-log/src/main/java/com/fw/api/log/Slf4jLogFactory.java create mode 100644 fw-log/src/main/java/com/fw/api/log/Slf4jLogger.java create mode 100644 fw-log/src/main/java/com/fw/api/log/exception/LogConfigException.java create mode 100644 fw-secure/pom.xml create mode 100644 fw-secure/src/main/java/com/fw/api/ex/ExceptionAdvice.java create mode 100644 fw-secure/src/main/java/com/fw/api/ex/ServiceException.java create mode 100644 fw-web/fw_init.sql create mode 100644 fw-web/pom.xml create mode 100644 fw-web/readme.md create mode 100644 fw-web/src/main/java/com/fw/api/config/CorsConfig.java create mode 100644 fw-web/src/main/java/com/fw/api/config/FwFreemarkerView.java create mode 100644 fw-web/src/main/java/com/fw/api/config/RequestConfig.java create mode 100644 fw-web/src/main/java/com/fw/api/config/RestTemplateConfig.java create mode 100644 fw-web/src/main/java/com/fw/api/config/Swagger2Config.java create mode 100644 fw-web/src/main/java/com/fw/api/config/WebMvcAutoConfig.java create mode 100644 fw-web/src/main/java/com/fw/api/secure/LoginInterceptor.java create mode 100644 fw-web/src/main/java/com/fw/api/web/Application.java create mode 100644 fw-web/src/main/java/com/fw/api/web/bean/FwBean.java create mode 100644 fw-web/src/main/java/com/fw/api/web/bean/RetBean.java create mode 100644 fw-web/src/main/java/com/fw/api/web/controllers/BaseController.java create mode 100644 fw-web/src/main/java/com/fw/api/web/controllers/ui/version/VersionController.java create mode 100644 fw-web/src/main/java/com/fw/api/web/domain/Version.java create mode 100644 fw-web/src/main/java/com/fw/api/web/repository/VersionRepository.java create mode 100644 fw-web/src/main/java/com/fw/api/web/service/JPAFactoryImpl.java create mode 100644 fw-web/src/main/resources/application-dev.properties create mode 100644 fw-web/src/main/resources/application-proj.properties create mode 100644 fw-web/src/main/resources/application.properties create mode 100644 fw-web/src/main/resources/logback-api.xml create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..616d281 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.settings + +.project + +target + +.classpath + +.project diff --git a/fw-aop/pom.xml b/fw-aop/pom.xml new file mode 100644 index 0000000..506a6c1 --- /dev/null +++ b/fw-aop/pom.xml @@ -0,0 +1,26 @@ + + + + fw-framework + com.framework + 1.1.1 + + 4.0.0 + fw-aop + com.fw.api + jar + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-data-rest + compile + + + + diff --git a/fw-aop/src/main/java/com/fw/api/aop/annotation/NoLogin.java b/fw-aop/src/main/java/com/fw/api/aop/annotation/NoLogin.java new file mode 100644 index 0000000..b8d8629 --- /dev/null +++ b/fw-aop/src/main/java/com/fw/api/aop/annotation/NoLogin.java @@ -0,0 +1,17 @@ +package com.fw.api.aop.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 当该批注修饰一个controller方法时,在Controller切面中会对请求该方法的 用户进行鉴权。 + */ +@Inherited +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface NoLogin { + +} diff --git a/fw-base/pom.xml b/fw-base/pom.xml new file mode 100644 index 0000000..66fc298 --- /dev/null +++ b/fw-base/pom.xml @@ -0,0 +1,26 @@ + + + + fw-framework + com.framework + 1.1.1 + + 4.0.0 + com.fw.api + fw-base + + + + org.apache.commons + commons-lang3 + compile + + + commons-io + commons-io + compile + + + + diff --git a/fw-base/src/main/java/com/fw/api/base/editor/DateEditor.java b/fw-base/src/main/java/com/fw/api/base/editor/DateEditor.java new file mode 100644 index 0000000..992918e --- /dev/null +++ b/fw-base/src/main/java/com/fw/api/base/editor/DateEditor.java @@ -0,0 +1,20 @@ +package com.fw.api.base.editor; + +import java.beans.PropertyEditorSupport; + +import com.fw.api.base.util.DateHelper; + +/** + * 防止表单注入 + * + * @author LW + * + */ +public class DateEditor extends PropertyEditorSupport { + + @Override + public void setAsText(String text) { + setValue(DateHelper.parseDate(text)); + } + +} diff --git a/fw-base/src/main/java/com/fw/api/base/editor/StringEditor.java b/fw-base/src/main/java/com/fw/api/base/editor/StringEditor.java new file mode 100644 index 0000000..dcc0edb --- /dev/null +++ b/fw-base/src/main/java/com/fw/api/base/editor/StringEditor.java @@ -0,0 +1,26 @@ +package com.fw.api.base.editor; + +import java.beans.PropertyEditorSupport; + +import org.apache.commons.lang3.StringEscapeUtils; + +/** + * 防止表单注入 + * + * @author LW + * + */ +public class StringEditor extends PropertyEditorSupport { + + @Override + public void setAsText(String text) { + setValue(text == null ? null : StringEscapeUtils.escapeHtml4(text.trim())); + } + + @Override + public String getAsText() { + Object value = getValue(); + return value != null ? value.toString() : ""; + } + +} diff --git a/fw-base/src/main/java/com/fw/api/base/exception/BusinessException.java b/fw-base/src/main/java/com/fw/api/base/exception/BusinessException.java new file mode 100644 index 0000000..75c27e5 --- /dev/null +++ b/fw-base/src/main/java/com/fw/api/base/exception/BusinessException.java @@ -0,0 +1,20 @@ +package com.fw.api.base.exception; + +/** + * 业务异常. + * + * @author lw + */ +public class BusinessException extends Exception { + + private static final long serialVersionUID = 6194417822203662894L; + + public BusinessException() { + super(); + } + + public BusinessException(String message) { + super(message); + } + +} \ No newline at end of file diff --git a/fw-base/src/main/java/com/fw/api/base/exception/SystemException.java b/fw-base/src/main/java/com/fw/api/base/exception/SystemException.java new file mode 100644 index 0000000..df402d3 --- /dev/null +++ b/fw-base/src/main/java/com/fw/api/base/exception/SystemException.java @@ -0,0 +1,27 @@ +package com.fw.api.base.exception; + +/** + * 系统业务异常. + * + * @author lw + */ +public class SystemException extends RuntimeException { + + private static final long serialVersionUID = -1312066729114650096L; + + public SystemException() { + super(); + } + + public SystemException(String message) { + super(message); + } + + public SystemException(Throwable cause) { + super(cause); + } + + public SystemException(String message, Throwable cause) { + super(message, cause); + } +} \ No newline at end of file diff --git a/fw-base/src/main/java/com/fw/api/base/util/DateHelper.java b/fw-base/src/main/java/com/fw/api/base/util/DateHelper.java new file mode 100644 index 0000000..22e048d --- /dev/null +++ b/fw-base/src/main/java/com/fw/api/base/util/DateHelper.java @@ -0,0 +1,428 @@ +package com.fw.api.base.util; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.TimeZone; + +import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.commons.lang3.time.DateUtils; + +/** + * 日期工具类, 继承org.apache.commons.lang.time.DateUtils类 + * + * @author lw + */ +public class DateHelper extends DateUtils { + + /** + * 日期格式 + */ + private static final String[] PARSE_PATTERNS = { + "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", + "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", + "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM", + "yyyyMMdd", "yyyyMMddHHmmss", "yyyyMMddHHmm", "yyyyMM" + }; + + /** + * 日期格式 + */ + private static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; + /** + * 日期时间格式 + */ + private static final String DEFAULT_DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; + /** + * 日期时间格式 + */ + public static final String DEFAULT_YYYYMMDDHHMMSS = "yyyyMMddHHmmss"; + + /** + * 得到当前日期字符串 格式(yyyy-MM-dd) + * + * @return the date + */ + public static String getDate() { + return getDate(DEFAULT_DATE_FORMAT); + } + + /** + * 得到当前日期字符串 格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E" + * + * @param pattern the pattern + * @return the date + */ + public static String getDate(String pattern) { + return DateFormatUtils.format(new Date(), pattern); + } + + /** + * 得到日期字符串 默认格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E" + * + * @param date the date + * @param pattern the pattern + * @return the string + */ + public static String formatDate(Date date, Object... pattern) { + String formatDate; + if (pattern != null && pattern.length > 0) { + formatDate = DateFormatUtils.format(date, pattern[0].toString()); + } else { + formatDate = DateFormatUtils.format(date, DEFAULT_DATE_FORMAT); + } + return formatDate; + } + + /** + * 得到日期时间字符串,转换格式(yyyy-MM-dd HH:mm:ss) + * + * @param date the date + * @return the string + */ + public static String formatDateTime(Date date) { + return formatDate(date, DEFAULT_DATETIME_FORMAT); + } + + /** + * 得到当前时间字符串 格式(HH:mm:ss) + * + * @return the time + */ + public static String getTime() { + return formatDate(new Date(), "HH:mm:ss"); + } + + /** + * 得到当前日期和时间字符串 格式(yyyy-MM-dd HH:mm:ss) + * + * @return the date time + */ + public static String getDateTime() { + return formatDate(new Date(), DEFAULT_DATETIME_FORMAT); + } + + /** + * 得到当前年份字符串 格式(yyyy) + * + * @return the year + */ + public static String getYear() { + return formatDate(new Date(), "yyyy"); + } + + /** + * 得到当前月份字符串 格式(MM) + * + * @return the month + */ + public static String getMonth() { + return formatDate(new Date(), "MM"); + } + + /** + * 得到当天字符串 格式(dd) + * + * @return the day + */ + public static String getDay() { + return formatDate(new Date(), "dd"); + } + + /** + * 得到当前星期字符串 格式(E)星期几 + * + * @return the week + */ + public static String getWeek() { + return formatDate(new Date(), "E"); + } + + /** + * 日期型字符串转化为日期 格式 + * { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", + * "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", + * "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", + * "yyyyMMdd", "yyyyMMddHHmmss", "yyyyMMddHHmm", "yyyyMM" + * } + * + * @param str the str + * @return the date + */ + public static Date parseDate(Object str) { + if (str == null) { + return null; + } + try { + return parseDate(str.toString(), PARSE_PATTERNS); + } catch (ParseException e) { + return null; + } + } + + /** + * 获取过去的天数 + * + * @param date 对比日期 + * @return long long + */ + public static long pastDays(Date date) { + long t = new Date().getTime() - date.getTime(); + return t / (24 * 60 * 60 * 1000); + } + + /** + * 获取过去的小时 + * + * @param date 对比日期 + * @return long long + */ + public static long pastHour(Date date) { + long t = new Date().getTime() - date.getTime(); + return t / (60 * 60 * 1000); + } + + /** + * 获取过去的分钟 + * + * @param date 对比日期 + * @return long long + */ + public static long pastMinutes(Date date) { + long t = new Date().getTime() - date.getTime(); + return t / (60 * 1000); + } + + /** + * 转换为时间(天,时:分:秒.毫秒) + * + * @param timeMillis 毫秒数 + * @return 天, 时:分:秒.毫秒 + */ + public static String formatDateTime(long timeMillis) { + long day = timeMillis / (24 * 60 * 60 * 1000); + long hour = timeMillis / (60 * 60 * 1000) - day * 24; + long min = timeMillis / (60 * 1000) - day * 24 * 60 - hour * 60; + long s = timeMillis / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60; + long sss = timeMillis - day * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000 - s * 1000; + return (day > 0 ? day + "," : "") + hour + ":" + min + ":" + s + "." + sss; + } + + /** + * 获取两个日期之间的天数 + * + * @param before 开始日期 + * @param after 结束日期 + * @return 天数 distance of two date + */ + public static double getDistanceOfTwoDate(Date before, Date after) { + long beforeTime = before.getTime(); + long afterTime = after.getTime(); + return (afterTime - beforeTime) / (double) (1000 * 60 * 60 * 24); + } + + /** + * 获取东八区当前时间 + * + * @return Date est 8 date + */ + public static Date getEst8Date() { + TimeZone tz = TimeZone.getTimeZone("GMT+8:00"); + Calendar calendar = Calendar.getInstance(); + Date date = calendar.getTime(); + SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATETIME_FORMAT); + dateFormat.setTimeZone(tz); + return parseDate(dateFormat.format(date)); + } + + /** + * 取得指定日期所在周的第一天 + * + * @param date + * @return + */ + public static Date getFirstDayOfWeek(Date date) { + Calendar c = new GregorianCalendar(); + c.setFirstDayOfWeek(Calendar.MONDAY); + c.setTime(date); + c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); // Monday + return c.getTime(); + } + + /** + * 取得指定日期所在周的最后一天 + * + * @param date + * @return + */ + public static Date getLastDayOfWeek(Date date) { + Calendar c = new GregorianCalendar(); + c.setFirstDayOfWeek(Calendar.MONDAY); + c.setTime(date); + c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6); // Sunday + return c.getTime(); + } + + /** + * 取得指定日期所在月的第一天 + * + * @param date + * @return + */ + public static Date getFirstDayOfMonth(Date date) { + Calendar c = new GregorianCalendar(); + c.setTime(date); + c.set(Calendar.DAY_OF_MONTH, 1); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + return c.getTime(); + } + + /** + * 获得指定日期step月份之后的所在月第一天 + * + * @param date + * @param step + * @return String + */ + public static Date getFirstDayOfStepMonth(Date date, Integer step) { + Calendar c = new GregorianCalendar(); + c.setTime(date); + c.set(Calendar.MONTH, c.get(Calendar.MONTH) + step); + return getFirstDayOfMonth(c.getTime()); + } + + /** + * 获得指定日期step月份之后的日期 + * + * @param date + * @param step + * @return String + */ + public static Date getDayOfStepMonth(Date date, Integer step) { + Calendar c = new GregorianCalendar(); + c.setTime(date); + c.set(Calendar.MONTH, c.get(Calendar.MONTH) + step); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + return c.getTime(); + } + + /** + * 获取指定日期setp年份的日期 + * @param regDate + * @param step + * @return + */ + public static Date getFirstDayOfStepYear(Date regDate, int step) { + Calendar c = new GregorianCalendar(); + c.setTime(regDate); + c.set(Calendar.YEAR, c.get(Calendar.YEAR) + step); + return c.getTime(); + } + + /** + * 获得指定日期step月份之后的所在月最后第一天的日期 + * + * @param date + * @param step + * @return String + */ + public static Date getLastDayOfStepMonth(Date date, Integer step) { + Calendar c = new GregorianCalendar(); + c.setTime(date); + c.set(Calendar.MONTH, c.get(Calendar.MONTH) + step); + return getLastDayOfMonth(c.getTime()); + } + + /** + * 取得指定日期所在月的最后一天 + * + * @param date + * @return + */ + public static Date getLastDayOfMonth(Date date) { + Calendar c = new GregorianCalendar(); + c.setTime(date); + c.set(Calendar.DAY_OF_MONTH, 1); + c.add(Calendar.MONTH, 1); + c.add(Calendar.DAY_OF_MONTH, -1); + c.set(Calendar.HOUR_OF_DAY, 23); + c.set(Calendar.MINUTE, 59); + c.set(Calendar.SECOND, 59); + return c.getTime(); + } + + /** + * 获取当月的最大天数 + * + * @param date + * @return int + */ + public static int getDayOfMonth(Date date) { + Calendar c = new GregorianCalendar(); + c.setTime(date); + return c.getActualMaximum(Calendar.DATE); + } + + public static String formatCurrentDate(String pattern) { + return DateHelper.formatDate(new Date(), pattern); + } + + /** + * 将日期型数据转化为字符串型 + * + * @param formatDate + * @param pattern + * @return + */ + public static String formatDateToStr(Date formatDate, String pattern) { + if (null == formatDate) { + return null; + } + if (pattern == null || pattern.equals("")) { + pattern = DEFAULT_DATETIME_FORMAT; + } + DateFormat format = null; + format = new SimpleDateFormat(pattern); + String dayBefore = format.format(formatDate.getTime()); + return dayBefore; + } + + public static String getAssignedDayWithPattern(Date date, String pattern, + Integer step) { + Calendar c = new GregorianCalendar(); + c.setTime(date); + c.add(Calendar.DATE, step); + DateFormat format = new SimpleDateFormat(pattern); + return format.format(c.getTime()); + } + + public static Date getAssignedDayWithPattern(Date date, Integer step) { + Calendar c = new GregorianCalendar(); + c.setTime(date); + c.add(Calendar.DATE, step); + return c.getTime(); + } + + public static Date formatDateWithString(String date,String pattern) { + pattern = (pattern == null || pattern.equals("")) ? DEFAULT_DATETIME_FORMAT : pattern; + DateFormat format = new SimpleDateFormat(pattern); + try { + return format.parse(date); + } catch (ParseException e) { + e.printStackTrace(); + } + return null; + } + + public static Date formatDateWithString(String date) { + return formatDateWithString(date,null); + } + +} diff --git a/fw-base/src/main/java/com/fw/api/base/util/RandomHelper.java b/fw-base/src/main/java/com/fw/api/base/util/RandomHelper.java new file mode 100644 index 0000000..3111456 --- /dev/null +++ b/fw-base/src/main/java/com/fw/api/base/util/RandomHelper.java @@ -0,0 +1,106 @@ +package com.fw.api.base.util; + +import java.security.SecureRandom; +import java.util.Random; +import java.util.UUID; + +/** + * 封装各种生成唯一性ID算法的工具类. + * + * @author lw + */ +public final class RandomHelper { + + /** + * 随机数生成器 + */ + private static final SecureRandom SECURE_RANDOM = new SecureRandom(); + + private RandomHelper() { + throw new IllegalAccessError("Utility class"); + } + + /** + * 封装JDK自带的UUID, 长度32, 中间无-分割. + * + * @return 一个随机码, 形如:5ec24ed3ff1a41c18d23a37af006bbb3 + */ + public static String uuid() { + return randomStringByUUID().replaceAll("-", ""); + } + + /** + * 生成一个随机码,长度36. + * + * @return 一个随机码, 形如:5ec24ed3-ff1a-41c1-8d23-a37af006bbb3 + */ + public static String randomString() { + return randomStringByUUID(); + } + + /** + * 生成一个随机码,长度32,全大写,无分隔符. + * + * @return 一个随机码, 形如:5EC24ED3-FF1A-41C1-8D23-A37AF006BBB3 + */ + public static String randomStringUpper() { + return randomString().replaceAll("-", "").toUpperCase(); + } + + + /** + * 生成UUID + * + * @return string + */ + private static String randomStringByUUID() { + return UUID.randomUUID().toString(); + } + + /** + * 使用SecureRandom随机生成Long. + * + * @return the long + */ + public static long randomLong() { + long number = SECURE_RANDOM.nextLong(); + if (Long.MIN_VALUE == number) { + return Long.MAX_VALUE; + } else { + return Math.abs(number); + } + } + + /** + * 指定位数数字 + * + * @param charCount 位数 + * @return String rand num + */ + public static String getRandNum(int charCount) { + StringBuilder charValue = new StringBuilder(); + for (int i = 0; i < charCount; i++) { + char c = (char) (randomInt(0, 10) + '0'); + charValue.append(String.valueOf(c)); + } + return charValue.toString(); + } + + /** + * 范围内随机数字 + * + * @param from 开始 + * @param to 结束 + * @return int int + */ + public static int randomInt(int from, int to) { + Random r = new Random(); + return from + r.nextInt(to - from); + } + + public static void main(String[] args) { + System.out.println(RandomHelper.randomStringUpper()); + + System.out.println("123456789012345".replaceAll("\\d{4}(?!$)", "$0 ")); + } +} diff --git a/fw-bean/pom.xml b/fw-bean/pom.xml new file mode 100644 index 0000000..3f262eb --- /dev/null +++ b/fw-bean/pom.xml @@ -0,0 +1,22 @@ + + + + fw-framework + com.framework + 1.1.1 + + 4.0.0 + fw-bean + com.fw.api + jar + + + + com.fw.api + fw-core + compile + + + + diff --git a/fw-bean/src/main/java/com/fw/api/bean/version/VersionBean.java b/fw-bean/src/main/java/com/fw/api/bean/version/VersionBean.java new file mode 100644 index 0000000..f29bb15 --- /dev/null +++ b/fw-bean/src/main/java/com/fw/api/bean/version/VersionBean.java @@ -0,0 +1,105 @@ +package com.fw.api.bean.version; + +public class VersionBean { + + private Integer min_version; + + private Integer new_version; + + private String description; + + private String download_url; + + private Integer status; + + private Integer type = 1; + + private Integer responseId =0; + + private Integer retcode = 0; + + private Integer rettype = 0; + + private String retmsg; + + public Integer getMin_version() { + return min_version; + } + + public void setMin_version(Integer min_version) { + this.min_version = min_version; + } + + public Integer getNew_version() { + return new_version; + } + + public void setNew_version(Integer new_version) { + this.new_version = new_version; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDownload_url() { + return download_url; + } + + public void setDownload_url(String download_url) { + this.download_url = download_url; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public Integer getResponseId() { + return responseId; + } + + public void setResponseId(Integer responseId) { + this.responseId = responseId; + } + + public Integer getRetcode() { + return retcode; + } + + public void setRetcode(Integer retcode) { + this.retcode = retcode; + } + + public Integer getRettype() { + return rettype; + } + + public void setRettype(Integer rettype) { + this.rettype = rettype; + } + + public String getRetmsg() { + return retmsg; + } + + public void setRetmsg(String retmsg) { + this.retmsg = retmsg; + } + +} diff --git a/fw-core/pom.xml b/fw-core/pom.xml new file mode 100644 index 0000000..d2c1a2b --- /dev/null +++ b/fw-core/pom.xml @@ -0,0 +1,41 @@ + + + + fw-framework + com.framework + 1.1.1 + + 4.0.0 + fw-core + com.fw.api + + + + com.fw.api + fw-base + + + + org.hibernate + hibernate-validator + + + + org.springframework.boot + spring-boot-starter-data-jpa + compile + + + + com.alibaba + fastjson + + + + + diff --git a/fw-core/src/main/java/com/fw/api/core/http/AjaxResult.java b/fw-core/src/main/java/com/fw/api/core/http/AjaxResult.java new file mode 100644 index 0000000..cf83edf --- /dev/null +++ b/fw-core/src/main/java/com/fw/api/core/http/AjaxResult.java @@ -0,0 +1,98 @@ +package com.fw.api.core.http; + +/** + * Ajax 请求全局处理 + * + * @author LW + * + */ +public class AjaxResult { + + private boolean result = false; + + private String message = ""; + + private String result_type = "0"; + + private String result_code = "0"; + + private Object data; + + public AjaxResult success() { + this.result = true; + return this; + } + + public AjaxResult success(String message) { + this.result = true; + this.message = message; + return this; + } + + public AjaxResult failure() { + this.result = false; + return this; + } + + public AjaxResult resultType(String result_type) { + this.result_type = result_type; + return this; + } + + public AjaxResult resultCode(String result_code) { + this.result_code = result_code; + return this; + } + + public AjaxResult failure(String message) { + this.result = false; + this.message = message; + return this; + } + + public AjaxResult data(Object data) { + this.data = data; + return this; + } + + public boolean isResult() { + return result; + } + + public void setResult(boolean result) { + this.result = result; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getResult_type() { + return result_type; + } + + public void setResult_type(String result_type) { + this.result_type = result_type; + } + + public String getResult_code() { + return result_code; + } + + public void setResult_code(String result_code) { + this.result_code = result_code; + } + + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + +} diff --git a/fw-log/pom.xml b/fw-log/pom.xml new file mode 100644 index 0000000..b09c19a --- /dev/null +++ b/fw-log/pom.xml @@ -0,0 +1,22 @@ + + + + fw-framework + com.framework + 1.1.1 + + 4.0.0 + fw-log + com.fw.api + jar + + + + org.springframework.boot + spring-boot-starter-data-jpa + compile + + + + diff --git a/fw-log/src/main/java/com/fw/api/log/ILogFactory.java b/fw-log/src/main/java/com/fw/api/log/ILogFactory.java new file mode 100644 index 0000000..1b2d6d4 --- /dev/null +++ b/fw-log/src/main/java/com/fw/api/log/ILogFactory.java @@ -0,0 +1,13 @@ +package com.fw.api.log; + +/** + * + * 获取Logger的接口,可以实现本接口获取其他日志的Logger + * + * @author lw + */ +public interface ILogFactory { + + Logger getLogger(String name); + +} \ No newline at end of file diff --git a/fw-log/src/main/java/com/fw/api/log/Lifecycle.java b/fw-log/src/main/java/com/fw/api/log/Lifecycle.java new file mode 100644 index 0000000..ca2f174 --- /dev/null +++ b/fw-log/src/main/java/com/fw/api/log/Lifecycle.java @@ -0,0 +1,28 @@ +package com.fw.api.log; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +/** + * + * 放入Spring容器中的bean如果需要生命周期回调,则需要实现该接口 + * + * @author:lw + * + */ +public interface Lifecycle { + + /** + * + * 用{@link PostConstruct @PostConstruct}批注修饰则不用在XML文件中配置 + */ + public void initializing(); + + /** + * + * 用{@link PreDestroy @PreDestroy}批注修饰则不用在XML文件中配置 + * + */ + public void cleanup(); + +} diff --git a/fw-log/src/main/java/com/fw/api/log/Log.java b/fw-log/src/main/java/com/fw/api/log/Log.java new file mode 100644 index 0000000..8f1a6f3 --- /dev/null +++ b/fw-log/src/main/java/com/fw/api/log/Log.java @@ -0,0 +1,35 @@ +package com.fw.api.log; + +public class Log { + + /** + * + * 获取Logger + * + * @param name + * 参数名,一般是编码或类名,但不要重复 + * @return + * @example <调用范例> + */ + public static Logger get(String name) { + return getLogFactory(Logtype.COMMON).getLogger(name); + } + + /** + * + * 获取Logger + * + * @param name + * 参数名,一般是编码或类名,但不要重复 + * @return + * @example <调用范例> + */ + public static Logger get(Class clazz) { + return getLogFactory(Logtype.COMMON).getLogger(clazz.getName()); + } + + private static ILogFactory getLogFactory(Logtype type) { + return new Slf4jLogFactory(type); + } + +} diff --git a/fw-log/src/main/java/com/fw/api/log/Logger.java b/fw-log/src/main/java/com/fw/api/log/Logger.java new file mode 100644 index 0000000..10741a3 --- /dev/null +++ b/fw-log/src/main/java/com/fw/api/log/Logger.java @@ -0,0 +1,836 @@ +package com.fw.api.log; + +import org.slf4j.Marker; + +/** + * The org.slf4j.Logger interface is the main user entry point of SLF4J API. It + * is expected that logging takes place through concrete implementations of this + * interface. + * + *

Typical usage pattern:

+ * + *
+ * import org.slf4j.Logger;
+ * import org.slf4j.LoggerFactory;
+ * 
+ * public class Wombat {
+ * 
+ *   final static Logger logger = LoggerFactory.getLogger(Wombat.class);
+ *   Integer t;
+ *   Integer oldT;
+ * 
+ *   public void setTemperature(Integer temperature) {
+ *     oldT = t;        
+ *     t = temperature;
+ *     logger.debug("Temperature set to {}. Old temperature was {}.", t, oldT);
+ *     if(temperature.intValue() > 50) {
+ *       logger.info("Temperature has risen above 50 degrees.");
+ *     }
+ *   }
+ * }
+ * 
+ * + */ +public interface Logger { + + /** + * Case insensitive String constant used to retrieve the name of the root + * logger. + * + * @since 1.3 + */ + final public String ROOT_LOGGER_NAME = "ROOT"; + + /** + * Return the name of this Logger instance. + */ + public String getName(); + + /** + * Is the logger instance enabled for the TRACE level? + * + * @return True if this Logger is enabled for the TRACE level, false + * otherwise. + * + * @since 1.4 + */ + public boolean isTraceEnabled(); + + /** + * Log a message at the TRACE level. + * + * @param msg + * the message string to be logged + * @since 1.4 + */ + public void trace(String msg); + + /** + * Log a message at the TRACE level according to the specified format and + * argument. + * + *

+ * This form avoids superfluous object creation when the logger is disabled + * for the TRACE level. + *

+ * + * @param format + * the format string + * @param arg + * the argument + * + * @since 1.4 + */ + public void trace(String format, Object arg); + + /** + * Log a message at the TRACE level according to the specified format and + * arguments. + * + *

+ * This form avoids superfluous object creation when the logger is disabled + * for the TRACE level. + *

+ * + * @param format + * the format string + * @param arg1 + * the first argument + * @param arg2 + * the second argument + * + * @since 1.4 + */ + public void trace(String format, Object arg1, Object arg2); + + /** + * Log a message at the TRACE level according to the specified format and + * arguments. + * + *

+ * This form avoids superfluous object creation when the logger is disabled + * for the TRACE level. + *

+ * + * @param format + * the format string + * @param argArray + * an array of arguments + * + * @since 1.4 + */ + public void trace(String format, Object... argArray); + + /** + * Log an exception (throwable) at the TRACE level with an accompanying + * message. + * + * @param msg + * the message accompanying the exception + * @param t + * the exception (throwable) to log + * + * @since 1.4 + */ + public void trace(String msg, Throwable t); + + /** + * Similar to {@link #isTraceEnabled()} method except that the marker data + * is also taken into account. + * + * @param marker + * The marker data to take into consideration + * + * @since 1.4 + */ + public boolean isTraceEnabled(Marker marker); + + /** + * Log a message with the specific Marker at the TRACE level. + * + * @param marker + * the marker data specific to this log statement + * @param msg + * the message string to be logged + * + * @since 1.4 + */ + public void trace(Marker marker, String msg); + + /** + * This method is similar to {@link #trace(String, Object)} method except + * that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param format + * the format string + * @param arg + * the argument + * + * @since 1.4 + */ + public void trace(Marker marker, String format, Object arg); + + /** + * This method is similar to {@link #trace(String, Object, Object)} method + * except that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param format + * the format string + * @param arg1 + * the first argument + * @param arg2 + * the second argument + * + * @since 1.4 + */ + public void trace(Marker marker, String format, Object arg1, Object arg2); + + /** + * This method is similar to {@link #trace(String, Object[])} method except + * that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param format + * the format string + * @param argArray + * an array of arguments + * + * @since 1.4 + */ + public void trace(Marker marker, String format, Object... argArray); + + /** + * This method is similar to {@link #trace(String, Throwable)} method except + * that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param msg + * the message accompanying the exception + * @param t + * the exception (throwable) to log + * + * @since 1.4 + */ + public void trace(Marker marker, String msg, Throwable t); + + /** + * Is the logger instance enabled for the DEBUG level? + * + * @return True if this Logger is enabled for the DEBUG level, false + * otherwise. + * + */ + public boolean isDebugEnabled(); + + /** + * Log a message at the DEBUG level. + * + * @param msg + * the message string to be logged + */ + public void debug(String msg); + + /** + * Log a message at the DEBUG level according to the specified format and + * argument. + * + *

+ * This form avoids superfluous object creation when the logger is disabled + * for the DEBUG level. + *

+ * + * @param format + * the format string + * @param arg + * the argument + */ + public void debug(String format, Object arg); + + /** + * Log a message at the DEBUG level according to the specified format and + * arguments. + * + *

+ * This form avoids superfluous object creation when the logger is disabled + * for the DEBUG level. + *

+ * + * @param format + * the format string + * @param arg1 + * the first argument + * @param arg2 + * the second argument + */ + public void debug(String format, Object arg1, Object arg2); + + /** + * Log a message at the DEBUG level according to the specified format and + * arguments. + * + *

+ * This form avoids superfluous object creation when the logger is disabled + * for the DEBUG level. + *

+ * + * @param format + * the format string + * @param argArray + * an array of arguments + */ + public void debug(String format, Object... argArray); + + /** + * Log an exception (throwable) at the DEBUG level with an accompanying + * message. + * + * @param msg + * the message accompanying the exception + * @param t + * the exception (throwable) to log + */ + public void debug(String msg, Throwable t); + + /** + * Similar to {@link #isDebugEnabled()} method except that the marker data + * is also taken into account. + * + * @param marker + * The marker data to take into consideration + */ + public boolean isDebugEnabled(Marker marker); + + /** + * Log a message with the specific Marker at the DEBUG level. + * + * @param marker + * the marker data specific to this log statement + * @param msg + * the message string to be logged + */ + public void debug(Marker marker, String msg); + + /** + * This method is similar to {@link #debug(String, Object)} method except + * that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param format + * the format string + * @param arg + * the argument + */ + public void debug(Marker marker, String format, Object arg); + + /** + * This method is similar to {@link #debug(String, Object, Object)} method + * except that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param format + * the format string + * @param arg1 + * the first argument + * @param arg2 + * the second argument + */ + public void debug(Marker marker, String format, Object arg1, Object arg2); + + /** + * This method is similar to {@link #debug(String, Object[])} method except + * that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param format + * the format string + * @param argArray + * an array of arguments + */ + public void debug(Marker marker, String format, Object... argArray); + + /** + * This method is similar to {@link #debug(String, Throwable)} method except + * that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param msg + * the message accompanying the exception + * @param t + * the exception (throwable) to log + */ + public void debug(Marker marker, String msg, Throwable t); + + /** + * Is the logger instance enabled for the INFO level? + * + * @return True if this Logger is enabled for the INFO level, false + * otherwise. + */ + public boolean isInfoEnabled(); + + /** + * Log a message at the INFO level. + * + * @param msg + * the message string to be logged + */ + public void info(String msg); + + /** + * Log a message at the INFO level according to the specified format and + * argument. + * + *

+ * This form avoids superfluous object creation when the logger is disabled + * for the INFO level. + *

+ * + * @param format + * the format string + * @param arg + * the argument + */ + public void info(String format, Object arg); + + /** + * Log a message at the INFO level according to the specified format and + * arguments. + * + *

+ * This form avoids superfluous object creation when the logger is disabled + * for the INFO level. + *

+ * + * @param format + * the format string + * @param arg1 + * the first argument + * @param arg2 + * the second argument + */ + public void info(String format, Object arg1, Object arg2); + + /** + * Log a message at the INFO level according to the specified format and + * arguments. + * + *

+ * This form avoids superfluous object creation when the logger is disabled + * for the INFO level. + *

+ * + * @param format + * the format string + * @param argArray + * an array of arguments + */ + public void info(String format, Object... argArray); + + /** + * Log an exception (throwable) at the INFO level with an accompanying + * message. + * + * @param msg + * the message accompanying the exception + * @param t + * the exception (throwable) to log + */ + public void info(String msg, Throwable t); + + /** + * Similar to {@link #isInfoEnabled()} method except that the marker data is + * also taken into consideration. + * + * @param marker + * The marker data to take into consideration + */ + public boolean isInfoEnabled(Marker marker); + + /** + * Log a message with the specific Marker at the INFO level. + * + * @param marker + * The marker specific to this log statement + * @param msg + * the message string to be logged + */ + public void info(Marker marker, String msg); + + /** + * This method is similar to {@link #info(String, Object)} method except + * that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param format + * the format string + * @param arg + * the argument + */ + public void info(Marker marker, String format, Object arg); + + /** + * This method is similar to {@link #info(String, Object, Object)} method + * except that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param format + * the format string + * @param arg1 + * the first argument + * @param arg2 + * the second argument + */ + public void info(Marker marker, String format, Object arg1, Object arg2); + + /** + * This method is similar to {@link #info(String, Object[])} method except + * that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param format + * the format string + * @param argArray + * an array of arguments + */ + public void info(Marker marker, String format, Object... argArray); + + /** + * This method is similar to {@link #info(String, Throwable)} method except + * that the marker data is also taken into consideration. + * + * @param marker + * the marker data for this log statement + * @param msg + * the message accompanying the exception + * @param t + * the exception (throwable) to log + */ + public void info(Marker marker, String msg, Throwable t); + + /** + * Is the logger instance enabled for the WARN level? + * + * @return True if this Logger is enabled for the WARN level, false + * otherwise. + */ + public boolean isWarnEnabled(); + + /** + * Log a message at the WARN level. + * + * @param msg + * the message string to be logged + */ + public void warn(String msg); + + /** + * Log a message at the WARN level according to the specified format and + * argument. + * + *

+ * This form avoids superfluous object creation when the logger is disabled + * for the WARN level. + *

+ * + * @param format + * the format string + * @param arg + * the argument + */ + public void warn(String format, Object arg); + + /** + * Log a message at the WARN level according to the specified format and + * arguments. + * + *

+ * This form avoids superfluous object creation when the logger is disabled + * for the WARN level. + *

+ * + * @param format + * the format string + * @param argArray + * an array of arguments + */ + public void warn(String format, Object... argArray); + + /** + * Log a message at the WARN level according to the specified format and + * arguments. + * + *

+ * This form avoids superfluous object creation when the logger is disabled + * for the WARN level. + *

+ * + * @param format + * the format string + * @param arg1 + * the first argument + * @param arg2 + * the second argument + */ + public void warn(String format, Object arg1, Object arg2); + + /** + * Log an exception (throwable) at the WARN level with an accompanying + * message. + * + * @param msg + * the message accompanying the exception + * @param t + * the exception (throwable) to log + */ + public void warn(String msg, Throwable t); + + /** + * Similar to {@link #isWarnEnabled()} method except that the marker data is + * also taken into consideration. + * + * @param marker + * The marker data to take into consideration + */ + public boolean isWarnEnabled(Marker marker); + + /** + * Log a message with the specific Marker at the WARN level. + * + * @param marker + * The marker specific to this log statement + * @param msg + * the message string to be logged + */ + public void warn(Marker marker, String msg); + + /** + * This method is similar to {@link #warn(String, Object)} method except + * that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param format + * the format string + * @param arg + * the argument + */ + public void warn(Marker marker, String format, Object arg); + + /** + * This method is similar to {@link #warn(String, Object, Object)} method + * except that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param format + * the format string + * @param arg1 + * the first argument + * @param arg2 + * the second argument + */ + public void warn(Marker marker, String format, Object arg1, Object arg2); + + /** + * This method is similar to {@link #warn(String, Object[])} method except + * that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param format + * the format string + * @param argArray + * an array of arguments + */ + public void warn(Marker marker, String format, Object... argArray); + + /** + * This method is similar to {@link #warn(String, Throwable)} method except + * that the marker data is also taken into consideration. + * + * @param marker + * the marker data for this log statement + * @param msg + * the message accompanying the exception + * @param t + * the exception (throwable) to log + */ + public void warn(Marker marker, String msg, Throwable t); + + /** + * Is the logger instance enabled for the ERROR level? + * + * @return True if this Logger is enabled for the ERROR level, false + * otherwise. + */ + public boolean isErrorEnabled(); + + /** + * Log a message at the ERROR level. + * + * @param msg + * the message string to be logged + */ + public void error(String msg); + + /** + * Log a message at the ERROR level according to the specified format and + * argument. + * + *

+ * This form avoids superfluous object creation when the logger is disabled + * for the ERROR level. + *

+ * + * @param format + * the format string + * @param arg + * the argument + */ + public void error(String format, Object arg); + + /** + * Log a message at the ERROR level according to the specified format and + * arguments. + * + *

+ * This form avoids superfluous object creation when the logger is disabled + * for the ERROR level. + *

+ * + * @param format + * the format string + * @param arg1 + * the first argument + * @param arg2 + * the second argument + */ + public void error(String format, Object arg1, Object arg2); + + /** + * Log a message at the ERROR level according to the specified format and + * arguments. + * + *

+ * This form avoids superfluous object creation when the logger is disabled + * for the ERROR level. + *

+ * + * @param format + * the format string + * @param argArray + * an array of arguments + */ + public void error(String format, Object... argArray); + + /** + * Log an exception (throwable) at the ERROR level with an accompanying + * message. + * + * @param msg + * the message accompanying the exception + * @param t + * the exception (throwable) to log + */ + public void error(String msg, Throwable t); + + /** + * + * Log an exception (throwable) at the ERROR level (include StackTrace) with + * an accompanying message. + * + * @param msg + * - the message accompanying the exception + * @param t + * the exception (throwable ) to log + * + */ + public void errorDetail(String msg, Throwable t); + + /** + * Similar to {@link #isErrorEnabled()} method except that the marker data + * is also taken into consideration. + * + * @param marker + * The marker data to take into consideration + */ + public boolean isErrorEnabled(Marker marker); + + /** + * Log a message with the specific Marker at the ERROR level. + * + * @param marker + * The marker specific to this log statement + * @param msg + * the message string to be logged + */ + public void error(Marker marker, String msg); + + /** + * This method is similar to {@link #error(String, Object)} method except + * that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param format + * the format string + * @param arg + * the argument + */ + public void error(Marker marker, String format, Object arg); + + /** + * This method is similar to {@link #error(String, Object, Object)} method + * except that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param format + * the format string + * @param arg1 + * the first argument + * @param arg2 + * the second argument + */ + public void error(Marker marker, String format, Object arg1, Object arg2); + + /** + * This method is similar to {@link #error(String, Object[])} method except + * that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param format + * the format string + * @param argArray + * an array of arguments + */ + public void error(Marker marker, String format, Object... argArray); + + /** + * This method is similar to {@link #error(String, Throwable)} method except + * that the marker data is also taken into consideration. + * + * @param marker + * the marker data specific to this log statement + * @param msg + * the message accompanying the exception + * @param t + * the exception (throwable) to log + */ + public void error(Marker marker, String msg, Throwable t); + +} diff --git a/fw-log/src/main/java/com/fw/api/log/Logtype.java b/fw-log/src/main/java/com/fw/api/log/Logtype.java new file mode 100644 index 0000000..d2c6c6f --- /dev/null +++ b/fw-log/src/main/java/com/fw/api/log/Logtype.java @@ -0,0 +1,25 @@ +package com.fw.api.log; + +/** + * 日志类型 + * + * @author lw + * + */ +public enum Logtype { + + /** 默认值,用于正常的开发输出,相当于log4j */ + COMMON, + + /** 后台统计日志志用 */ + STAT, + + /** 异常统计专用 */ + THROWS, + + /** 系统排查定位写日志用 */ + SYSTEM, + + /** 普通的用于写文件用 */ + FILE +} diff --git a/fw-log/src/main/java/com/fw/api/log/Slf4jLog.java b/fw-log/src/main/java/com/fw/api/log/Slf4jLog.java new file mode 100644 index 0000000..4d75645 --- /dev/null +++ b/fw-log/src/main/java/com/fw/api/log/Slf4jLog.java @@ -0,0 +1,398 @@ +package com.fw.api.log; + +import org.slf4j.Marker; + +/** + * 日志接口的实现类 + * + * @author lw + */ +public class Slf4jLog implements Logger { + + /** 是否输出堆栈信息,默认不输出 */ + protected boolean printStackTrace = false; + + org.slf4j.Logger log; + + public Slf4jLog(org.slf4j.Logger log, boolean printStackTrace) { + this.log = log; + this.printStackTrace = printStackTrace; + } + + @Override + public void debug(String msg) { + this.log.debug(msg); + } + + @Override + public void debug(String format, Object arg) { + this.log.debug(format, arg); + + } + + @Override + public void debug(String format, Object... argArray) { + this.log.debug(format, argArray); + } + + @Override + public void debug(String msg, Throwable t) { + if (printStackTrace) { + this.log.debug(msg, t); + } else { + this.log.debug(msg, t.toString()); + } + } + + @Override + public void debug(Marker marker, String msg) { + this.log.debug(marker, msg); + + } + + @Override + public void debug(String format, Object arg1, Object arg2) { + this.log.debug(format, arg1, arg2); + + } + + @Override + public void debug(Marker marker, String format, Object arg) { + this.log.debug(marker, format, arg); + + } + + @Override + public void debug(Marker marker, String format, Object... argArray) { + this.log.debug(marker, format, argArray); + + } + + @Override + public void debug(Marker marker, String msg, Throwable t) { + if (printStackTrace) { + this.log.debug(marker, msg, t); + } else { + this.log.debug(marker, msg, t.toString()); + } + } + + @Override + public void debug(Marker marker, String format, Object arg1, Object arg2) { + this.log.debug(marker, format, arg1, arg2); + } + + @Override + public void error(String msg) { + this.log.error(msg); + + } + + @Override + public void error(String format, Object arg) { + this.log.error(format, arg); + + } + + @Override + public void error(String format, Object... argArray) { + this.log.error(format, argArray); + + } + + @Override + public void error(String msg, Throwable t) { + if (printStackTrace) { + this.log.error(msg, t); + } else { + this.log.error(msg, t.toString()); + } + } + + @Override + public void errorDetail(String msg, Throwable t) { + this.log.error(msg, t); + } + + @Override + public void error(Marker marker, String msg) { + this.log.error(marker, msg); + + } + + @Override + public void error(String format, Object arg1, Object arg2) { + this.log.error(format, arg1, arg2); + + } + + @Override + public void error(Marker marker, String format, Object arg) { + this.log.error(marker, format, arg); + + } + + @Override + public void error(Marker marker, String format, Object... argArray) { + this.log.error(marker, format, argArray); + + } + + @Override + public void error(Marker marker, String msg, Throwable t) { + if (printStackTrace) { + this.error(marker, msg, t); + } else { + this.error(marker, msg, t.toString()); + } + } + + @Override + public void error(Marker marker, String format, Object arg1, Object arg2) { + this.error(marker, format, arg1, arg2); + } + + @Override + public String getName() { + return this.log.getName(); + } + + @Override + public void info(String msg) { + this.log.info(msg); + } + + @Override + public void info(String format, Object arg) { + this.log.info(format, arg); + + } + + @Override + public void info(String format, Object... argArray) { + this.log.info(format, argArray); + + } + + @Override + public void info(String msg, Throwable t) { + if (printStackTrace) { + this.log.info(msg, t); + } else { + this.log.info(msg, t.toString()); + } + } + + @Override + public void info(Marker marker, String msg) { + this.log.info(marker, msg); + + } + + @Override + public void info(String format, Object arg1, Object arg2) { + this.log.info(format, arg1, arg2); + + } + + @Override + public void info(Marker marker, String format, Object arg) { + this.log.info(marker, format, arg); + + } + + @Override + public void info(Marker marker, String format, Object... argArray) { + this.log.info(marker, format, argArray); + + } + + @Override + public void info(Marker marker, String msg, Throwable t) { + if (printStackTrace) { + this.log.info(marker, msg, t); + } else { + this.log.info(marker, msg, t.toString()); + } + } + + @Override + public void info(Marker marker, String format, Object arg1, Object arg2) { + this.log.info(marker, format, arg1, arg2); + + } + + @Override + public boolean isDebugEnabled() { + return this.log.isDebugEnabled(); + } + + @Override + public boolean isDebugEnabled(Marker marker) { + return this.log.isDebugEnabled(marker); + } + + @Override + public boolean isErrorEnabled() { + return this.log.isErrorEnabled(); + } + + @Override + public boolean isErrorEnabled(Marker marker) { + return this.log.isDebugEnabled(marker); + } + + @Override + public boolean isInfoEnabled() { + return this.log.isInfoEnabled(); + } + + @Override + public boolean isInfoEnabled(Marker marker) { + return this.log.isInfoEnabled(marker); + } + + @Override + public boolean isTraceEnabled() { + return this.log.isTraceEnabled(); + } + + @Override + public boolean isTraceEnabled(Marker marker) { + return this.log.isTraceEnabled(marker); + } + + @Override + public boolean isWarnEnabled() { + return this.log.isWarnEnabled(); + } + + @Override + public boolean isWarnEnabled(Marker marker) { + return this.isWarnEnabled(marker); + } + + @Override + public void trace(String msg) { + this.log.trace(msg); + } + + @Override + public void trace(String format, Object arg) { + this.log.trace(format, arg); + } + + @Override + public void trace(String format, Object... argArray) { + this.log.trace(format, argArray); + } + + @Override + public void trace(String msg, Throwable t) { + if (printStackTrace) { + this.log.trace(msg, t); + } else { + this.log.trace(msg, t.toString()); + } + } + + @Override + public void trace(Marker marker, String msg) { + this.log.trace(marker, msg); + } + + @Override + public void trace(String format, Object arg1, Object arg2) { + this.log.trace(format, arg1, arg2); + } + + @Override + public void trace(Marker marker, String format, Object arg) { + this.log.trace(marker, format, arg); + } + + @Override + public void trace(Marker marker, String format, Object... argArray) { + this.log.trace(marker, format, argArray); + } + + @Override + public void trace(Marker marker, String msg, Throwable t) { + if (printStackTrace) { + this.log.trace(marker, msg, t); + } else { + this.log.trace(marker, msg, t.toString()); + } + } + + @Override + public void trace(Marker marker, String format, Object arg1, Object arg2) { + this.log.trace(marker, format, arg1, arg2); + } + + @Override + public void warn(String msg) { + this.log.warn(msg); + } + + @Override + public void warn(String format, Object arg) { + this.log.warn(format, arg); + } + + @Override + public void warn(String format, Object... argArray) { + this.log.warn(format, argArray); + + } + + @Override + public void warn(String msg, Throwable t) { + if (printStackTrace) { + this.log.warn(msg, t.toString()); + } else { + this.log.warn(msg, t.toString()); + } + } + + @Override + public void warn(Marker marker, String msg) { + this.log.warn(marker, msg); + + } + + @Override + public void warn(String format, Object arg1, Object arg2) { + this.log.warn(format, arg1, arg2); + + } + + @Override + public void warn(Marker marker, String format, Object arg) { + this.log.warn(marker, format, arg); + + } + + @Override + public void warn(Marker marker, String format, Object... argArray) { + this.log.warn(marker, format, argArray); + + } + + @Override + public void warn(Marker marker, String msg, Throwable t) { + if (printStackTrace) { + this.log.warn(marker, msg, t); + } else { + this.log.warn(marker, msg, t.toString()); + } + + } + + @Override + public void warn(Marker marker, String format, Object arg1, Object arg2) { + this.log.warn(marker, format, arg1, arg2); + + } + +} diff --git a/fw-log/src/main/java/com/fw/api/log/Slf4jLogFactory.java b/fw-log/src/main/java/com/fw/api/log/Slf4jLogFactory.java new file mode 100644 index 0000000..ae87c51 --- /dev/null +++ b/fw-log/src/main/java/com/fw/api/log/Slf4jLogFactory.java @@ -0,0 +1,22 @@ +package com.fw.api.log; + +/** + * 一个调用slf4j来实现日志的工厂类 + * + * @author lw + */ +public class Slf4jLogFactory implements ILogFactory { + + @SuppressWarnings("unused") + private Logtype logtype; + + public Slf4jLogFactory(Logtype logtype) { + this.logtype = logtype; + } + + @Override + public Logger getLogger(String name) { + return new Slf4jLog(Slf4jLogger.get(name), Slf4jLogger.isStack()); + } + +} diff --git a/fw-log/src/main/java/com/fw/api/log/Slf4jLogger.java b/fw-log/src/main/java/com/fw/api/log/Slf4jLogger.java new file mode 100644 index 0000000..a77d6cb --- /dev/null +++ b/fw-log/src/main/java/com/fw/api/log/Slf4jLogger.java @@ -0,0 +1,108 @@ +package com.fw.api.log; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.Resource; + +import com.fw.api.log.exception.LogConfigException; + +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.joran.JoranConfigurator; + +/** + * 加载Slf4j的配置文件,详细的可见类org.slf4j.LoggerFactory + * + * @author lw + */ +public class Slf4jLogger implements Lifecycle { + + /** + * 初始化失败异常ErrorID + */ + private String errorid = "fw.logging.ex.init"; + + /** + * Logback配置文件,可以在Classpath或者在FileSystem中 + */ + private Resource logback; + + /** 是否输出堆栈信息,默认不输出,接口属性 */ + private static boolean isStack = false; + + /** 是否输出堆栈信息,默认不输出,spring注入属性 */ + private boolean printStackTrace = false; + + @Override + public void cleanup() { + // nothing to do. + } + + @Override + public void initializing() { + if (printStackTrace) { + isStack = true; + } + if (logback != null) { + LoggerContext loggerContext = (LoggerContext) LoggerFactory + .getILoggerFactory(); + loggerContext.reset(); + JoranConfigurator configurator = new JoranConfigurator(); + configurator.setContext(loggerContext); + try { + configurator.doConfigure(logback.getInputStream()); + } catch (Exception e) { + new LogConfigException(errorid, e, "Initializing logger configuration faile!"); + } + } + } + + /** + * + * @description: 获得log对象 + * @param: name Logger对象的名字,即Log.get("name")的name,可以是类名,也可以普通的编码 + * @return: @see org.slf4j.Logger + * @throws: < 抛出异常列表,格式: 异常类型 - 描述 > + */ + public static Logger get(String name) { + return LoggerFactory.getLogger(name); + } + + /** + * + * @description: 获得log对象 + * @param: name Logger对象的名字,类Class + * @return: @see org.slf4j.Logger + * @throws: < 抛出异常列表,格式: 异常类型 - 描述 > + */ + public static Logger get(Class clazz) { + return LoggerFactory.getLogger(clazz); + } + + // ///////////////////////////////////Getter and + // Setter///////////////////////////////////// + + public String getErrorid() { + return errorid; + } + + public Resource getLogback() { + return logback; + } + + public void setLogback(Resource logback) { + this.logback = logback; + } + + public void setErrorid(String errorid) { + this.errorid = errorid; + } + + public void setPrintStackTrace(boolean printStackTrace) { + this.printStackTrace = printStackTrace; + } + + /** 是否输出堆栈信息,默认不输出 */ + public static boolean isStack() { + return isStack; + } +} diff --git a/fw-log/src/main/java/com/fw/api/log/exception/LogConfigException.java b/fw-log/src/main/java/com/fw/api/log/exception/LogConfigException.java new file mode 100644 index 0000000..e3b350e --- /dev/null +++ b/fw-log/src/main/java/com/fw/api/log/exception/LogConfigException.java @@ -0,0 +1,9 @@ +package com.fw.api.log.exception; + +public class LogConfigException { + + public LogConfigException(String errorId, Throwable cause, String debugMsg, Object... errorArgs) { + + } + +} diff --git a/fw-secure/pom.xml b/fw-secure/pom.xml new file mode 100644 index 0000000..7076b22 --- /dev/null +++ b/fw-secure/pom.xml @@ -0,0 +1,31 @@ + + + + fw-framework + com.framework + 1.1.1 + + 4.0.0 + fw-secure + com.fw.api + + + + com.fw.api + fw-bean + compile + + + com.fw.api + fw-core + compile + + + com.fw.api + fw-aop + compile + + + + diff --git a/fw-secure/src/main/java/com/fw/api/ex/ExceptionAdvice.java b/fw-secure/src/main/java/com/fw/api/ex/ExceptionAdvice.java new file mode 100644 index 0000000..97f2f11 --- /dev/null +++ b/fw-secure/src/main/java/com/fw/api/ex/ExceptionAdvice.java @@ -0,0 +1,212 @@ +package com.fw.api.ex; + +import java.io.IOException; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; +import javax.validation.ValidationException; + +import org.hibernate.service.spi.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.http.HttpStatus; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.validation.BindException; +import org.springframework.validation.BindingResult; +import org.springframework.validation.FieldError; +import org.springframework.web.HttpMediaTypeNotSupportedException; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.MissingServletRequestParameterException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; + +import com.fw.api.core.http.AjaxResult; + +/** + * 全局异常处理 + * + * @author LW + * + */ +@ControllerAdvice +@ResponseBody +public class ExceptionAdvice { + + private static Logger logger = LoggerFactory.getLogger(ExceptionAdvice.class); + + private static final int SYS_ERROR = -99999; + + /** + * 400 - Bad Request + * @throws IOException + */ + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(MissingServletRequestParameterException.class) + public AjaxResult handleMissingServletRequestParameterException(HttpServletRequest request, HttpServletResponse response, + MissingServletRequestParameterException e) { + logger.error("缺少请求参数"+request.getRequestURI(), e.getMessage()); + AjaxResult ajaxResult = buildRedirectUrl(request,response,HttpStatus.BAD_REQUEST,"请求参数不正确!",e.getMessage()); + return ajaxResult; + } + + /** + * 400 - Bad Request + */ + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(HttpMessageNotReadableException.class) + public AjaxResult handleHttpMessageNotReadableException(HttpServletRequest request, HttpServletResponse response, + HttpMessageNotReadableException e) { + logger.error("参数解析失败"+request.getRequestURI(), e.getMessage()); + + AjaxResult ajaxResult = buildRedirectUrl(request,response,HttpStatus.BAD_REQUEST,"服务请求参数解析失败!",e.getMessage()); + return ajaxResult; + } + + /** + * 400 - Bad Request + */ + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(MethodArgumentNotValidException.class) + public AjaxResult handleMethodArgumentNotValidException(HttpServletRequest request, HttpServletResponse response, + MethodArgumentNotValidException e) { + BindingResult result = e.getBindingResult(); + FieldError error = result.getFieldError(); + String field = error.getField(); + String code = error.getDefaultMessage(); + String message = String.format("%s:%s:%s", field, code,error.getRejectedValue()); + logger.error("参数验证失败"+request.getRequestURI(), message); + + AjaxResult ajaxResult = buildRedirectUrl(request,response,HttpStatus.BAD_REQUEST,code,e.getMessage()); + return ajaxResult; + } + + /** + * 400 - Bad Request + */ + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(BindException.class) + public AjaxResult handleBindException(HttpServletRequest request, HttpServletResponse response, + BindException e) { + BindingResult result = e.getBindingResult(); + FieldError error = result.getFieldError(); + String field = error.getField(); + String code = error.getDefaultMessage(); + String message = String.format("%s:%s", field, code); + logger.error("参数绑定失败"+request.getRequestURI(), message); + + AjaxResult ajaxResult = buildRedirectUrl(request,response,HttpStatus.BAD_REQUEST,code,e.getMessage()); + return ajaxResult; + } + + /** + * 400 - Bad Request + */ + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(ConstraintViolationException.class) + public AjaxResult handleServiceException(HttpServletRequest request, HttpServletResponse response, + ConstraintViolationException e) { + Set> violations = e.getConstraintViolations(); + ConstraintViolation violation = violations.iterator().next(); + String message = violation.getMessage(); + logger.error("参数验证失败"+request.getRequestURI(), "parameter:" + message); + + AjaxResult ajaxResult = buildRedirectUrl(request,response,HttpStatus.BAD_REQUEST,message,e.getMessage()); + return ajaxResult; + } + + /** + * 400 - Bad Request + */ + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(ValidationException.class) + public AjaxResult handleValidationException(HttpServletRequest request, HttpServletResponse response, + ValidationException e) { + logger.error("参数验证失败"+request.getRequestURI(), e.getMessage()); + + AjaxResult ajaxResult = buildRedirectUrl(request,response,HttpStatus.BAD_REQUEST,"服务参数校验失败!",e.getMessage()); + return ajaxResult; + } + + /** + * 405 - Method Not Allowed + */ + @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) + public AjaxResult handleHttpRequestMethodNotSupportedException(HttpServletRequest request, HttpServletResponse response, + HttpRequestMethodNotSupportedException e) { + logger.error("不支持当前请求方法"+request.getRequestURI(), e.getMessage()); + + AjaxResult ajaxResult = buildRedirectUrl(request,response,HttpStatus.METHOD_NOT_ALLOWED,"服务不支持当前请求!",e.getMessage()); + return ajaxResult; + } + + /** + * 415 - Unsupported Media Type + */ + @ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE) + @ExceptionHandler(HttpMediaTypeNotSupportedException.class) + public AjaxResult handleHttpMediaTypeNotSupportedException(HttpServletRequest request, HttpServletResponse response, + Exception e) { + logger.error("不支持当前媒体类型"+request.getRequestURI(), e.getMessage()); + + AjaxResult ajaxResult = buildRedirectUrl(request,response,HttpStatus.UNSUPPORTED_MEDIA_TYPE,"服务不支持当前媒体类型!",e.getMessage()); + return ajaxResult; + } + + /** + * 500 - Internal Server Error + */ + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + @ExceptionHandler(ServiceException.class) + public AjaxResult handleServiceException(HttpServletRequest request, HttpServletResponse response, + ServiceException e) { + logger.error("业务逻辑异常"+request.getRequestURI(), e.getMessage()); + + AjaxResult ajaxResult = buildRedirectUrl(request,response,HttpStatus.INTERNAL_SERVER_ERROR,"请求服务失败,请稍后再试!",e.getMessage()); + return ajaxResult; + } + + /** + * 500 - Internal Server Error + */ + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + @ExceptionHandler(Exception.class) + public AjaxResult handleException(HttpServletRequest request, HttpServletResponse response, + Exception e) { + logger.error("通用异常"+request.getRequestURI(), e.getMessage()); + + AjaxResult ajaxResult = buildRedirectUrl(request,response,HttpStatus.INTERNAL_SERVER_ERROR,"服务开小差了,请稍后再试!",e.getMessage()); + return ajaxResult; + } + + /** + * 500 - 操作数据库出现异常:名称重复,外键关联 + */ + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + @ExceptionHandler(DataIntegrityViolationException.class) + public AjaxResult handleException(HttpServletRequest request, HttpServletResponse response, + DataIntegrityViolationException e) { + logger.error("操作数据库出现异常:"+request.getRequestURI(), e.getMessage()); + + AjaxResult ajaxResult = buildRedirectUrl(request,response,HttpStatus.INTERNAL_SERVER_ERROR,"操作数据库出现异常:字段重复、有外键关联等!",e.getMessage()); + return ajaxResult; + } + + private AjaxResult buildRedirectUrl(HttpServletRequest request, HttpServletResponse response, + HttpStatus status,String message,String e){ + + AjaxResult ajaxResult = new AjaxResult().resultCode(String.valueOf(status)) + .resultType(String.valueOf(SYS_ERROR)) + .failure(message) + .data(e); + + return ajaxResult; + } +} diff --git a/fw-secure/src/main/java/com/fw/api/ex/ServiceException.java b/fw-secure/src/main/java/com/fw/api/ex/ServiceException.java new file mode 100644 index 0000000..21d651f --- /dev/null +++ b/fw-secure/src/main/java/com/fw/api/ex/ServiceException.java @@ -0,0 +1,11 @@ +package com.fw.api.ex; + +public class ServiceException extends RuntimeException { + + private static final long serialVersionUID = -3140138114629995495L; + + public ServiceException(String msg) { + super(msg); + } + +} diff --git a/fw-web/fw_init.sql b/fw-web/fw_init.sql new file mode 100644 index 0000000..472f259 --- /dev/null +++ b/fw-web/fw_init.sql @@ -0,0 +1,39 @@ +-- -------------------------------------------------------- +-- 主机: 127.0.0.1 +-- 服务器版本: 5.6.21 - MySQL Community Server (GPL) +-- 服务器操作系统: Win64 +-- HeidiSQL 版本: 8.0.0.4396 +-- -------------------------------------------------------- + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; + +-- 导出 fw_init 的数据库结构 +DROP DATABASE IF EXISTS `fw_init`; +CREATE DATABASE IF NOT EXISTS `fw_init` /*!40100 DEFAULT CHARACTER SET utf8 */; +USE `fw_init`; + + +-- 导出 表 fw_init.t_fw_version 结构 +DROP TABLE IF EXISTS `t_fw_version`; +CREATE TABLE IF NOT EXISTS `t_fw_version` ( + `sid` bigint(20) NOT NULL AUTO_INCREMENT, + `aboutinfo` varchar(255) DEFAULT NULL, + `ctime` datetime DEFAULT NULL, + `cuser` varchar(255) DEFAULT NULL, + `description` varchar(255) DEFAULT NULL, + `download_url` varchar(255) DEFAULT NULL, + `memo` varchar(255) DEFAULT NULL, + `min_version` int(11) DEFAULT NULL, + `new_version` int(11) DEFAULT NULL, + `status` int(11) DEFAULT NULL, + `type` int(11) DEFAULT NULL, + PRIMARY KEY (`sid`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; + +-- 正在导出表 fw_init.t_fw_version 的数据:~0 rows (大约) +DELETE FROM `t_fw_version`; +/*!40000 ALTER TABLE `t_fw_version` DISABLE KEYS */; +/*!40000 ALTER TABLE `t_fw_version` ENABLE KEYS */; diff --git a/fw-web/pom.xml b/fw-web/pom.xml new file mode 100644 index 0000000..05abd77 --- /dev/null +++ b/fw-web/pom.xml @@ -0,0 +1,196 @@ + + + + 4.0.0 + fw-web + com.fw.api + war + + + fw-framework + com.framework + 1.1.1 + + + + + com.fw.api + fw-bean + + + com.fw.api + fw-core + + + com.fw.api + fw-aop + + + com.fw.api + fw-secure + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + org.springframework.boot + spring-boot-starter-freemarker + + + org.springframework.boot + spring-boot-devtools + + + org.springframework.boot + spring-boot-starter-aop + + + org.springframework.boot + spring-boot-starter-logging + + + mysql + mysql-connector-java + + + + javax.servlet + javax.servlet-api + + + javax.inject + javax.inject + 1 + + + + com.alibaba + fastjson + + + + com.querydsl + querydsl-core + + + com.querydsl + querydsl-apt + provided + + + com.querydsl + querydsl-jpa + + + + org.apache.commons + commons-lang3 + + + commons-io + commons-io + + + + io.springfox + springfox-swagger2 + + + io.springfox + springfox-swagger-ui + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + ${java.version} + ${java.version} + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-war-plugin + 2.2 + + api + false + + + + org.apache.tomcat.maven + tomcat8-maven-plugin + 2.0 + + + com.mysema.maven + apt-maven-plugin + 1.1.3 + + + generate-sources + + process + + + target/generated-sources + com.querydsl.apt.jpa.JPAAnnotationProcessor + + + + + + + + + + spring-snapshots + http://repo.spring.io/snapshot + + true + + + + spring-milestones + http://repo.spring.io/milestone + + true + + + + jcenter-snapshots + jcenter + https://jcenter.bintray.com/ + + + + + spring-snapshots + http://repo.spring.io/snapshot + + + spring-milestones + http://repo.spring.io/milestone + + + jcenter-snapshots + https://jcenter.bintray.com/ + + + \ No newline at end of file diff --git a/fw-web/readme.md b/fw-web/readme.md new file mode 100644 index 0000000..e5a6b89 --- /dev/null +++ b/fw-web/readme.md @@ -0,0 +1,14 @@ +## Spring Boot basic web application + +Basic Spring Boot web application serving static content. + +### Build and run + +#### Prerequisites + +- Java 8 +- Maven 3.0+ + +### Usage + +- Launch the application and go on [http://localhost:8081/api/version/init](http://localhost:8081/api/version/init) diff --git a/fw-web/src/main/java/com/fw/api/config/CorsConfig.java b/fw-web/src/main/java/com/fw/api/config/CorsConfig.java new file mode 100644 index 0000000..30bee1b --- /dev/null +++ b/fw-web/src/main/java/com/fw/api/config/CorsConfig.java @@ -0,0 +1,27 @@ +package com.fw.api.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +@Configuration +public class CorsConfig { + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + corsConfiguration.addAllowedOrigin("*"); // 1 + corsConfiguration.addAllowedHeader("*"); // 2 + corsConfiguration.addAllowedMethod("*"); // 3 + return corsConfiguration; + } + + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); // 4 + return new CorsFilter(source); + } + +} diff --git a/fw-web/src/main/java/com/fw/api/config/FwFreemarkerView.java b/fw-web/src/main/java/com/fw/api/config/FwFreemarkerView.java new file mode 100644 index 0000000..84ce852 --- /dev/null +++ b/fw-web/src/main/java/com/fw/api/config/FwFreemarkerView.java @@ -0,0 +1,24 @@ +package com.fw.api.config; + +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.web.servlet.view.freemarker.FreeMarkerView; + +/** + * 自定义配置Freemarker全局变量 + * + * @author LW + * + */ +public class FwFreemarkerView extends FreeMarkerView { + + @Override + protected void exposeHelpers(Map model, + HttpServletRequest request) throws Exception { + model.put("context", request.getContextPath()); + super.exposeHelpers(model, request); + } + +} diff --git a/fw-web/src/main/java/com/fw/api/config/RequestConfig.java b/fw-web/src/main/java/com/fw/api/config/RequestConfig.java new file mode 100644 index 0000000..9d4631f --- /dev/null +++ b/fw-web/src/main/java/com/fw/api/config/RequestConfig.java @@ -0,0 +1,17 @@ +package com.fw.api.config; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.validation.beanvalidation.MethodValidationPostProcessor; + +@Configuration +@EnableAutoConfiguration +public class RequestConfig { + + @Bean + public MethodValidationPostProcessor methodValidationPostProcessor() { + return new MethodValidationPostProcessor(); + } + +} diff --git a/fw-web/src/main/java/com/fw/api/config/RestTemplateConfig.java b/fw-web/src/main/java/com/fw/api/config/RestTemplateConfig.java new file mode 100644 index 0000000..72e7f8b --- /dev/null +++ b/fw-web/src/main/java/com/fw/api/config/RestTemplateConfig.java @@ -0,0 +1,24 @@ +package com.fw.api.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.ClientHttpRequestFactory; +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class RestTemplateConfig { + + @Bean + public RestTemplate restTemplate(ClientHttpRequestFactory factory){ + return new RestTemplate(factory); + } + + @Bean + public ClientHttpRequestFactory simpleClientHttpRequestFactory(){ + SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); + factory.setReadTimeout(5000);//ms + factory.setConnectTimeout(5000);//ms + return factory; + } +} diff --git a/fw-web/src/main/java/com/fw/api/config/Swagger2Config.java b/fw-web/src/main/java/com/fw/api/config/Swagger2Config.java new file mode 100644 index 0000000..147f3f9 --- /dev/null +++ b/fw-web/src/main/java/com/fw/api/config/Swagger2Config.java @@ -0,0 +1,62 @@ +package com.fw.api.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class Swagger2Config { + + @Bean + public Docket petApi() { + return new Docket(DocumentationType.SWAGGER_2) + .groupName("full-petstore-api") + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("com.fw.api.web.controllers")) + //.paths(petstorePaths()) + .paths(PathSelectors.any()) + .build() + //.securitySchemes(newArrayList(oauth())) + //.securityContexts(newArrayList(securityContext())) + ; + } + + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("利用Springboot和Swagger2构建的RESTful APIs") + .description("前端使用此Api的应用:https://github.com/liuweijw/Vue2-All") + .termsOfServiceUrl("https://github.com/liuweijw/") + .contact(new Contact("liuweijw", "", "")) + .version("1.0") + .build(); + } + + /* + private static String [] paths = new String [] { + "/version/","/users/" + }; + + private Predicate petstorePaths() { + return new Predicate(){ + @Override + public boolean apply(String input) { + for(String path : paths){ + if(input.contains(path)) return true; + } + return false; + } + }; + }*/ + +} diff --git a/fw-web/src/main/java/com/fw/api/config/WebMvcAutoConfig.java b/fw-web/src/main/java/com/fw/api/config/WebMvcAutoConfig.java new file mode 100644 index 0000000..fe0aefc --- /dev/null +++ b/fw-web/src/main/java/com/fw/api/config/WebMvcAutoConfig.java @@ -0,0 +1,32 @@ +package com.fw.api.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +import com.fw.api.secure.LoginInterceptor; + +@Configuration +public class WebMvcAutoConfig extends WebMvcConfigurerAdapter { + + @Autowired + private LoginInterceptor loginInterceptor; + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/static/**") + .addResourceLocations("classpath:/static/"); + super.addResourceHandlers(registry); + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + // 注册监控拦截器 + registry.addInterceptor(loginInterceptor) + .addPathPatterns("/**"); + super.addInterceptors(registry); + } + +} diff --git a/fw-web/src/main/java/com/fw/api/secure/LoginInterceptor.java b/fw-web/src/main/java/com/fw/api/secure/LoginInterceptor.java new file mode 100644 index 0000000..4366395 --- /dev/null +++ b/fw-web/src/main/java/com/fw/api/secure/LoginInterceptor.java @@ -0,0 +1,45 @@ +package com.fw.api.secure; + +import java.lang.reflect.Method; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; + +import com.fw.api.aop.annotation.NoLogin; +import com.fw.api.web.bean.FwBean; + +@Component +public class LoginInterceptor extends HandlerInterceptorAdapter { + + @Autowired + private FwBean fwBean; + + // private final static Logger logger = LoggerFactory.getLogger(LoginInterceptor.class); + + @Override + public boolean preHandle(HttpServletRequest request, + HttpServletResponse response, Object handler) throws Exception { + + if (!handler.getClass().isAssignableFrom(HandlerMethod.class)) { + return true; + } + + final HandlerMethod handlerMethod = (HandlerMethod) handler; + final Method method = handlerMethod.getMethod(); + final Class clazz = method.getDeclaringClass(); + + //无须登录的请求 clazz.isAnnotationPresent(NoLogin.class) + if (method.isAnnotationPresent(NoLogin.class)) return true; + if (clazz.isAnnotationPresent(NoLogin.class) || clazz.getAnnotatedSuperclass().isAnnotationPresent(NoLogin.class)) return true; + + // 此处做业务逻辑处理 + + return true; + } + +} \ No newline at end of file diff --git a/fw-web/src/main/java/com/fw/api/web/Application.java b/fw-web/src/main/java/com/fw/api/web/Application.java new file mode 100644 index 0000000..628f818 --- /dev/null +++ b/fw-web/src/main/java/com/fw/api/web/Application.java @@ -0,0 +1,45 @@ +package com.fw.api.web; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver; + +import com.fw.api.config.FwFreemarkerView; + +@EnableTransactionManagement // 启注解事务管理,等同于xml配置方式的 +@SpringBootApplication +@EnableScheduling +@ComponentScan(value = { + "com.fw.api.logger","com.fw.api.config","com.fw.api.ex","com.fw.api.secure","com.fw.api.web" +}) +public class Application extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(Application.class); + } + + @Bean + public CommandLineRunner customFreemarker(FreeMarkerViewResolver resolver) { + return new CommandLineRunner() { + @Override + public void run(String... strings) throws Exception { + //增加视图 + resolver.setViewClass(FwFreemarkerView.class); + //添加自定义解析器 + } + }; + } + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/fw-web/src/main/java/com/fw/api/web/bean/FwBean.java b/fw-web/src/main/java/com/fw/api/web/bean/FwBean.java new file mode 100644 index 0000000..5d04521 --- /dev/null +++ b/fw-web/src/main/java/com/fw/api/web/bean/FwBean.java @@ -0,0 +1,78 @@ +package com.fw.api.web.bean; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class FwBean { + + @Value("${server.context-path}") + private String contextPath; + + @Value("${fw.server.request.api.baseurl}") + private String url; + + @Value("${fw.server.request.api.img}") + private String imgContextPath; + + @Value("${fw.server.request.api.opentoken}") + private boolean openToken; + + @Value("${fw.server.request.api.ex.show}") + private boolean exShow; + + @Value("${fw.server.request.api.token.times}") + private int tokenTimes; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getContextPath() { + return contextPath; + } + + public void setContextPath(String contextPath) { + this.contextPath = contextPath; + } + + public String getImgContextPath() { + return imgContextPath; + } + + public void setImgContextPath(String imgContextPath) { + this.imgContextPath = imgContextPath; + } + + public String getBaseReqUrl(){ + return this.url + this.contextPath; + } + + public boolean isOpenToken() { + return openToken; + } + + public void setOpenToken(boolean openToken) { + this.openToken = openToken; + } + + public boolean isExShow() { + return exShow; + } + + public void setExShow(boolean exShow) { + this.exShow = exShow; + } + + public int getTokenTimes() { + return tokenTimes; + } + + public void setTokenTimes(int tokenTimes) { + this.tokenTimes = tokenTimes; + } +} diff --git a/fw-web/src/main/java/com/fw/api/web/bean/RetBean.java b/fw-web/src/main/java/com/fw/api/web/bean/RetBean.java new file mode 100644 index 0000000..cb904c9 --- /dev/null +++ b/fw-web/src/main/java/com/fw/api/web/bean/RetBean.java @@ -0,0 +1,31 @@ +package com.fw.api.web.bean; + +public class RetBean { + + private int key; + + private String msg; + + public RetBean(int key,String msg){ + this.key = key; + this.msg = msg; + } + + public int getKey() { + return key; + } + + public void setKey(int key) { + this.key = key; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + +} diff --git a/fw-web/src/main/java/com/fw/api/web/controllers/BaseController.java b/fw-web/src/main/java/com/fw/api/web/controllers/BaseController.java new file mode 100644 index 0000000..dabe604 --- /dev/null +++ b/fw-web/src/main/java/com/fw/api/web/controllers/BaseController.java @@ -0,0 +1,28 @@ +package com.fw.api.web.controllers; + +import java.util.Date; + +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.InitBinder; + +import com.fw.api.base.editor.DateEditor; +import com.fw.api.base.editor.StringEditor; + +public abstract class BaseController { + + /** + * 初始化数据绑定 + * 1. 将所有传递进来的String进行HTML编码,防止XSS攻击 + * 2. 将字段中Date类型转换为String类型 + * + * @param binder the binder + */ + @InitBinder + protected void initBinder(WebDataBinder binder) { + // String类型转换,将所有传递进来的String进行HTML编码,防止XSS攻击 + binder.registerCustomEditor(String.class, new StringEditor()); + // Date 类型转换 + binder.registerCustomEditor(Date.class, new DateEditor()); + } + +} diff --git a/fw-web/src/main/java/com/fw/api/web/controllers/ui/version/VersionController.java b/fw-web/src/main/java/com/fw/api/web/controllers/ui/version/VersionController.java new file mode 100644 index 0000000..e9303c9 --- /dev/null +++ b/fw-web/src/main/java/com/fw/api/web/controllers/ui/version/VersionController.java @@ -0,0 +1,46 @@ +package com.fw.api.web.controllers.ui.version; + +import io.swagger.annotations.ApiOperation; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import com.fw.api.aop.annotation.NoLogin; +import com.fw.api.bean.version.VersionBean; +import com.fw.api.core.http.AjaxResult; +import com.fw.api.web.controllers.BaseController; +import com.fw.api.web.domain.Version; +import com.fw.api.web.repository.VersionRepository; + +@RestController +@RequestMapping(value="/version") +public class VersionController extends BaseController { + + @Autowired + private VersionRepository versionRepository; + + @RequestMapping(value="/init",method={RequestMethod.GET,RequestMethod.POST}) + @ApiOperation(value="获取版本号", notes="根据type获取版本号信息") + @NoLogin + @ResponseBody public AjaxResult versionInit(Integer type) { + type = null == type ? 1 : type; + Version version = versionRepository.findByType(type); + VersionBean vBean = null; + if(null != version){ + vBean = new VersionBean(); + vBean.setDescription(version.getDescription()); + vBean.setDownload_url(version.getDownload_url()); + vBean.setMin_version(version.getMin_version()); + vBean.setNew_version(version.getNew_version()); + vBean.setStatus(version.getStatus()); + vBean.setType(version.getType()); + + return new AjaxResult().success().data(vBean); + } + return new AjaxResult().failure().data(vBean); + } + +} diff --git a/fw-web/src/main/java/com/fw/api/web/domain/Version.java b/fw-web/src/main/java/com/fw/api/web/domain/Version.java new file mode 100644 index 0000000..87f030d --- /dev/null +++ b/fw-web/src/main/java/com/fw/api/web/domain/Version.java @@ -0,0 +1,173 @@ +package com.fw.api.web.domain; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = Version.TABLE_NAME) +public class Version implements Serializable { + + private static final long serialVersionUID = 8080157712721873L; + + public static final String TABLE_NAME = "t_fw_version"; + + @Id + @GeneratedValue + @Column(name = "sid") + private Long sid; + + /** + * 类型 1: android 0:ios + */ + @Column(name = "type") + private Integer type = 1; + + /** + * 最低版本号 + */ + @Column(name = "min_version") + private Integer min_version; + + /** + * 最新版本号 + */ + @Column(name = "new_version") + private Integer new_version; + + /** + * 本次升级描述 + */ + @Column(name = "description") + private String description; + + /** + * 下载地址 + */ + @Column(name = "download_url") + private String download_url; + + /** + * 状态 + */ + @Column(name = "status") + private Integer status; + + /** + * 创建人 + */ + @Column(name = "cuser") + private String cuser; + + /** + * 创建时间 + */ + @Column(name = "ctime") + private Date ctime; + + /** + * 备注 + */ + @Column(name = "memo") + private String memo; + + /** + * 关于信息 + */ + @Column(name = "aboutinfo") + private String aboutinfo; + + public Long getSid() { + return sid; + } + + public void setSid(Long sid) { + this.sid = sid; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public Integer getMin_version() { + return min_version; + } + + public void setMin_version(Integer min_version) { + this.min_version = min_version; + } + + public Integer getNew_version() { + return new_version; + } + + public void setNew_version(Integer new_version) { + this.new_version = new_version; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDownload_url() { + return download_url; + } + + public void setDownload_url(String download_url) { + this.download_url = download_url; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public String getCuser() { + return cuser; + } + + public void setCuser(String cuser) { + this.cuser = cuser; + } + + public Date getCtime() { + return ctime; + } + + public void setCtime(Date ctime) { + this.ctime = ctime; + } + + public String getMemo() { + return memo; + } + + public void setMemo(String memo) { + this.memo = memo; + } + + public String getAboutinfo() { + return aboutinfo; + } + + public void setAboutinfo(String aboutinfo) { + this.aboutinfo = aboutinfo; + } + +} diff --git a/fw-web/src/main/java/com/fw/api/web/repository/VersionRepository.java b/fw-web/src/main/java/com/fw/api/web/repository/VersionRepository.java new file mode 100644 index 0000000..fd8c9ab --- /dev/null +++ b/fw-web/src/main/java/com/fw/api/web/repository/VersionRepository.java @@ -0,0 +1,11 @@ +package com.fw.api.web.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QueryDslPredicateExecutor; + +import com.fw.api.web.domain.Version; + +public interface VersionRepository extends JpaRepository, QueryDslPredicateExecutor { + + Version findByType(Integer type); +} diff --git a/fw-web/src/main/java/com/fw/api/web/service/JPAFactoryImpl.java b/fw-web/src/main/java/com/fw/api/web/service/JPAFactoryImpl.java new file mode 100644 index 0000000..8ec1566 --- /dev/null +++ b/fw-web/src/main/java/com/fw/api/web/service/JPAFactoryImpl.java @@ -0,0 +1,23 @@ +package com.fw.api.web.service; + +import javax.annotation.PostConstruct; +import javax.persistence.EntityManager; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.querydsl.jpa.impl.JPAQueryFactory; + +public abstract class JPAFactoryImpl { + + //JPA查询工厂 + protected JPAQueryFactory queryFactory; + + @Autowired + private EntityManager em; + + @PostConstruct + public void initFactory(){ + queryFactory = new JPAQueryFactory(em); + } + +} diff --git a/fw-web/src/main/resources/application-dev.properties b/fw-web/src/main/resources/application-dev.properties new file mode 100644 index 0000000..cb33723 --- /dev/null +++ b/fw-web/src/main/resources/application-dev.properties @@ -0,0 +1,39 @@ +# ======================== +# APPLICATION +# ======================== +server.port=8081 +server.context-path=/api +server.tomcat.max-threads=500 +server.tomcat.uri-encoding=UTF-8 + +# =============================== +# = FW CONFIG +# =============================== +fw.server.request.api.ex.show=true +fw.server.request.api.baseurl=http://localhost:8081 +fw.server.request.api.img= +fw.server.request.api.opentoken=false +fw.server.request.api.token.times=86400 + +# ======================== +# SPRING +# ======================== +spring.resources.chain.strategy.content.enabled=true +spring.resources.chain.strategy.content.paths=/** +spring.resources.cachePeriod=2592000 + +# =============================== +# = DATA SOURCE +# =============================== +spring.datasource.url = jdbc:mysql://localhost:3306/fw_init?characterEncoding=utf8 +spring.datasource.username = root +spring.datasource.password = admin +spring.datasource.driverClassName = com.mysql.jdbc.Driver +# =============================== +# = JPA SETTINGS +# =============================== +spring.jpa.database = MYSQL +spring.jpa.show-sql = true +spring.jpa.hibernate.ddl-auto = update +spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy +spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect \ No newline at end of file diff --git a/fw-web/src/main/resources/application-proj.properties b/fw-web/src/main/resources/application-proj.properties new file mode 100644 index 0000000..61c6e37 --- /dev/null +++ b/fw-web/src/main/resources/application-proj.properties @@ -0,0 +1,39 @@ +# ======================== +# APPLICATION +# ======================== +server.port=8081 +server.context-path=/api +server.tomcat.max-threads=500 +server.tomcat.uri-encoding=UTF-8 + +# =============================== +# = FW CONFIG +# =============================== +fw.server.request.api.ex.show=false +fw.server.request.api.baseurl=http://localhost:8081 +fw.server.request.api.img= +fw.server.request.api.opentoken=false +fw.server.request.api.token.times=86400 + +# ======================== +# SPRING +# ======================== +spring.resources.chain.strategy.content.enabled=true +spring.resources.chain.strategy.content.paths=/** +spring.resources.cachePeriod=2592000 + +# =============================== +# = DATA SOURCE +# =============================== +spring.datasource.url = jdbc:mysql://localhost:3306/fw_init?characterEncoding=utf8 +spring.datasource.username = root +spring.datasource.password = admin +spring.datasource.driverClassName = com.mysql.jdbc.Driver +# =============================== +# = JPA SETTINGS +# =============================== +spring.jpa.database = MYSQL +spring.jpa.show-sql = true +spring.jpa.hibernate.ddl-auto = update +spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy +spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect \ No newline at end of file diff --git a/fw-web/src/main/resources/application.properties b/fw-web/src/main/resources/application.properties new file mode 100644 index 0000000..4f8e71b --- /dev/null +++ b/fw-web/src/main/resources/application.properties @@ -0,0 +1,8 @@ +spring.profiles.active=dev + +spring.jackson.date-format=yyyy-MM-dd HH:mm:ss +spring.jackson.time-zone=GMT+8 +spring.mvc.view.prefix=/WEB-INF/resouces/ +spring.mvc.view.suffix=.html + +logging.config=classpath:logback-api.xml \ No newline at end of file diff --git a/fw-web/src/main/resources/logback-api.xml b/fw-web/src/main/resources/logback-api.xml new file mode 100644 index 0000000..dccc333 --- /dev/null +++ b/fw-web/src/main/resources/logback-api.xml @@ -0,0 +1,147 @@ + + + + FwApi + + + + + + + + ${LOG_PATH}/${APPDIR}/log_error.log + + + + ${LOG_PATH}/${APPDIR}/error/log-error-%d{yyyy-MM-dd}.%i.log + + 30 + + + 2MB + + + + true + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger Line:%-3L - %msg%n + utf-8 + + + + error + ACCEPT + DENY + + + + + + + ${LOG_PATH}/${APPDIR}/log_warn.log + + + + ${LOG_PATH}/${APPDIR}/warn/log-warn-%d{yyyy-MM-dd}.%i.log + + 30 + + + 2MB + + + + true + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger Line:%-3L - %msg%n + utf-8 + + + + warn + ACCEPT + DENY + + + + + + + ${LOG_PATH}/${APPDIR}/log_info.log + + + + ${LOG_PATH}/${APPDIR}/info/log-info-%d{yyyy-MM-dd}.%i.log + + 30 + + + 2MB + + + + true + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger Line:%-3L - %msg%n + utf-8 + + + + info + ACCEPT + DENY + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger Line:%-3L - %msg%n + utf-8 + + + + debug + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..4a77fe8 --- /dev/null +++ b/pom.xml @@ -0,0 +1,211 @@ + + 4.0.0 + com.framework + fw-framework + 1.1.1 + pom + ${project.groupId}:${project.artifactId} + + + The Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + fw-aop + fw-base + fw-bean + fw-core + fw-log + fw-secure + fw-web + + + + + ${project.version} + ${java.version} + 1.5.9.RELEASE + 2.7.0 + UTF-8 + zh_CN + 1.8 + 5.1.41 + 1.2.28 + 3.5 + 2.5 + 2.6 + 1.10 + 1.3.1 + 1.9.3 + 4.1.4 + 3.3 + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.plugin.version} + + ${java.version} + ${java.version} + ${project.build.sourceEncoding} + + + + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + + com.querydsl + querydsl-root + ${querydsl.version} + + + + mysql + mysql-connector-java + ${mysql.version} + + + + com.fw.api + fw-aop + ${project.version} + + + com.fw.api + fw-base + ${project.version} + + + com.fw.api + fw-bean + ${project.version} + + + com.fw.api + fw-core + ${project.version} + + + com.fw.api + fw-log + ${project.version} + + + com.fw.api + fw-secure + ${project.version} + + + com.fw.api + fw-web + ${project.version} + + + + com.alibaba + fastjson + ${fastjson-version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + commons-io + commons-io + ${commons-io.version} + + + commons-codec + commons-codec + ${commons-codec.version} + + + commons-fileupload + commons-fileupload + ${commons-fileupload.version} + + + commons-io + commons-io + + + + + commons-beanutils + commons-beanutils + ${commons-beanutils} + + + commons-logging + commons-logging + + + + + commons-lang + commons-lang + ${commons.lang.version} + + + com.querydsl + querydsl-core + ${querydsl.version} + + + com.querydsl + querydsl-apt + provided + ${querydsl.version} + + + com.querydsl + querydsl-jpa + ${querydsl.version} + + + com.querydsl + querydsl-sql + ${querydsl.version} + + + + io.springfox + springfox-swagger2 + ${springfox.swagger.version} + + + io.springfox + springfox-swagger-ui + ${springfox.swagger.version} + + + + \ No newline at end of file