diff --git a/.gitignore b/.gitignore index a1c2a23..82eca33 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,25 @@ -# Compiled class file -*.class +/target/ +!.mvn/wrapper/maven-wrapper.jar -# Log file -*.log +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache -# BlueJ files -*.ctxt +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..9cc84ea Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..6c8c0e0 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip diff --git a/README.md b/README.md deleted file mode 100644 index 09a59dd..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -个人图片日记网站,仅限个人使用 diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..5bf251c --- /dev/null +++ b/mvnw @@ -0,0 +1,225 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..86c3a62 --- /dev/null +++ b/pom.xml @@ -0,0 +1,411 @@ + + + 4.0.0 + + com.krt-dairy + image-dairy + 0.0.1-SNAPSHOT + war + image_dairy_Webapp + image-dairy-project + + + + + UTF-8 + UTF-8 + 1.8 + 4.1.1.RELEASE + 1.2.2 + + + + + + + + + + org.apache.poi + poi + 3.7 + + + + org.apache.poi + poi-ooxml + 3.7 + + + + org.apache.poi + poi-ooxml-schemas + 3.7 + + + + + + + mysql + mysql-connector-java + runtime + + + + + + com.qiniu + qiniu-java-sdk + 7.2.0 + + + + + + + + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + + junit + junit + + 4.10 + + + + + org.aspectj + aspectjweaver + 1.6.2 + + + + commons-pool + commons-pool + 1.6 + + + commons-collections + commons-collections + 3.2.1 + + + commons-logging + commons-logging + 1.2 + + + commons-beanutils + commons-beanutils + 1.9.2 + + + commons-lang + commons-lang + 2.6 + + + commons-fileupload + commons-fileupload + 1.3.1 + + + commons-io + commons-io + 2.4 + + + commons-codec + commons-codec + 1.9 + + + + log4j + log4j + 1.2.17 + + + org.slf4j + slf4j-api + 1.7.2 + + + org.slf4j + slf4j-log4j12 + 1.7.12 + + + + org.mybatis + mybatis + 3.2.8 + + + org.mybatis + mybatis-spring + 1.2.2 + + + org.springframework + spring-core + ${spring.version} + + + org.springframework + spring-aop + ${spring.version} + + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + org.springframework + spring-beans + ${spring.version} + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-context-support + ${spring.version} + + + org.springframework + spring-tx + ${spring.version} + + + org.springframework + spring-jdbc + ${spring.version} + + + org.springframework + spring-expression + ${spring.version} + + + org.springframework + spring-orm + ${spring.version} + + + org.springframework + spring-test + ${spring.version} + + + + org.apache.shiro + shiro-core + ${shiro.version} + + + org.apache.shiro + shiro-web + ${shiro.version} + + + org.apache.shiro + shiro-cas + ${shiro.version} + + + org.apache.shiro + shiro-spring + ${shiro.version} + + + + org.freemarker + freemarker + 2.3.20 + + + + javax.persistence + persistence-api + 1.0.2 + + + + org.codehaus.jackson + jackson-mapper-asl + 1.9.12 + + + + org.codehaus.jackson + jackson-core-asl + 1.9.12 + + + com.googlecode.xmemcached + xmemcached + 2.0.0 + + + net.sf.json-lib + json-lib + 2.4 + jdk15 + + + + dom4j + dom4j + 1.6.1 + + + + org.apache.ws.commons.schema + XmlSchema + 1.4.7 + + + + com.thoughtworks.xstream + xstream + 1.4.2 + + + + + mysql + mysql-connector-java + 5.1.46 + + + + c3p0 + c3p0 + 0.9.1 + + + + com.google.guava + guava + 18.0 + + + + org.quartz-scheduler + quartz + 2.2.1 + + + + + org.aspectj + aspectjrt + 1.8.3 + runtime + + + org.aspectj + aspectjtools + 1.8.3 + + + + + + image_dairy + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.7 + 1.7 + + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.3.7 + + + src/main/resources/generatorConfig.xml + true + true + + + + Generate MyBatis Artifacts + + generate + + + + + + org.mybatis.generator + mybatis-generator-core + 1.3.7 + + + mysql + mysql-connector-java + 5.1.46 + + + + + + + + src/main/resources + + + src/main/java + + **/*.xml + + + + + + + diff --git a/src/main/java/com.krt.dairy.common.page/AbstractPage.java b/src/main/java/com.krt.dairy.common.page/AbstractPage.java new file mode 100644 index 0000000..b60b967 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.page/AbstractPage.java @@ -0,0 +1,170 @@ +package com.krt.dairy.common.page; + +import com.krt.dairy.common.util.BeanUtil; +import org.apache.commons.lang.StringUtils; + +import java.util.*; + +public abstract class AbstractPage implements Page { + + public static final int DEFAULT_FIRST_PAGE_NUM = 1; + public static final int DEFAULT_PAGE_SIZE = 10; + + protected int pageSize = DEFAULT_PAGE_SIZE; + protected int pageNum = DEFAULT_FIRST_PAGE_NUM; + + protected int itemsTotalCount = 0;//总记录数 + protected int pageTotalCount = 0;//总页数 + protected List items; + protected boolean firstPage;//是否是第一页 + protected boolean lastPage;//是否是最后一页 + protected int startIndex; + + private String sortField="update_time";//排序 + private String sortDirection = "DESC";//排序方向 + + + @Override + public int getFirstPageNum() { + return DEFAULT_FIRST_PAGE_NUM; + } + + @Override + public int getPageSize() { + return pageSize; + } + + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + } + + @Override + public int getPageNum() { + return pageNum; + } + + public void setPageNum(int pageNum) { + if (pageNum < DEFAULT_FIRST_PAGE_NUM) pageNum = DEFAULT_FIRST_PAGE_NUM; + this.pageNum = pageNum; + } + + @Override + public List getItems() { + return items; + } + + public void setItems(Collection items) { + if (items == null) items = Collections.emptyList(); + this.items = new ArrayList(items); + this.lastPage = this.pageNum == this.pageTotalCount; + this.firstPage = this.pageNum == DEFAULT_FIRST_PAGE_NUM; + } + + @Override + public boolean isFirstPage() { + firstPage = (getPageNum() <= getFirstPageNum()); + return firstPage; + } + + @Override + public boolean isLastPage() { + return lastPage; + } + + public int getPrePageNum() { + return isFirstPage() ? getFirstPageNum() : getPageNum() - 1; + } + + public int getNextPageNum() { + return isLastPage() ? getPageNum() : getPageNum() + 1; + } + + @Override + public Iterator iterator() { + return this.items.iterator(); + } + + @Override + public boolean isEmpty() { + return items.isEmpty(); + } + + public void setItemsTotalCount(int itemsTotalCount) { + this.itemsTotalCount = itemsTotalCount; + if(itemsTotalCount % this.pageSize == 0){ + this.pageTotalCount = itemsTotalCount/this.pageSize; + }else{ + this.pageTotalCount = itemsTotalCount/this.pageSize + 1; + } + if(this.pageNum > this.pageTotalCount){ + this.pageNum = DEFAULT_FIRST_PAGE_NUM; + } + if(this.itemsTotalCount <= this.pageSize){ + this.firstPage = true; + this.lastPage = true; + } + } + + @Override + public int getItemsTotalCount() { + return itemsTotalCount; + } + + @Override + public int getLastPageNum() { + return itemsTotalCount; + } + + public int getStartIndex() { + this.startIndex = (this.pageNum - 1) * this.pageSize; + if(this.startIndex <= 0){ + this.startIndex = 0; + } + return this.startIndex; + } + + /** + * 按照sortField升序 + * @param sortField:指java bean中的属性 + */ + public void ascSortField(String sortField) { + if(StringUtils.isNotEmpty(sortField)){ + this.sortField = BeanUtil.fieldToColumn(sortField); + this.sortDirection = " ASC "; + } + } + + /** + * 按照sortField降序 + * @param sortField :指java bean中的属性 + */ + public void descSortField(String sortField) { + if(StringUtils.isNotEmpty(sortField)){ + this.sortField = BeanUtil.fieldToColumn(sortField); + this.sortDirection = " DESC "; + } + } + + public String getSortDirection() { + return sortDirection; + } + + public void setSortDirection(String sortDirection) { + this.sortDirection = sortDirection; + } + + public String getSortField() { + return sortField; + } + + public void setSortField(String sortField) { + this.sortField = sortField; + } + + @Override + public String toString() { + return "Page[" + this.getPageNum() + "]:" + items.toString(); + } + + +} diff --git a/src/main/java/com.krt.dairy.common.page/Page.java b/src/main/java/com.krt.dairy.common.page/Page.java new file mode 100644 index 0000000..6b96f0e --- /dev/null +++ b/src/main/java/com.krt.dairy.common.page/Page.java @@ -0,0 +1,71 @@ +package com.krt.dairy.common.page; + +import java.util.List; + +/** + * 分页接口 + */ +public interface Page extends Iterable { + + /** + * 起始页号 + * @return + */ + int getFirstPageNum(); + + /** + * 终止页号 + * @return + */ + int getLastPageNum(); + + /** + * 当前页号 + * @return + */ + int getPageNum(); + + /** + * 分页大小 + * @return + */ + int getPageSize(); + + /** + * 分页数据 + * @return + */ + List getItems(); + + /** + * 获取总记录数 + * @return + */ + int getItemsTotalCount(); + + /** + * 获取总页数 + */ + int getPageTotalCount(); + + /** + * 是第一页 + * @return + */ + boolean isFirstPage(); + + /** + * 是最后一页 + * @return + */ + boolean isLastPage(); + + /** + * 是否为空内容 + * @return + */ + boolean isEmpty(); + +} + + diff --git a/src/main/java/com.krt.dairy.common.page/TailPage.java b/src/main/java/com.krt.dairy.common.page/TailPage.java new file mode 100644 index 0000000..9cbe534 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.page/TailPage.java @@ -0,0 +1,88 @@ +package com.krt.dairy.common.page; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * 分页 + */ +public class TailPage extends AbstractPage { + + protected int showPage = 10;//显示10个页码 + protected List showNums = new ArrayList(); + protected boolean showDot = true; + public TailPage() {} + + /** + * 构造函数,将一个已有的分页对象中的分页参数,设置给自己,items需独立设置 + * @param page + * @param items + */ + public TailPage(Page page, Collection items ,int itemsTotalCount) { + this(page.getPageNum(), page.getPageSize(), itemsTotalCount , items); + } + + public TailPage(int pageNum, int pageSize , int itemsTotalCount , Collection items) { + this.setItemsTotalCount(itemsTotalCount); + this.setPageNum(pageNum); + this.setPageSize(pageSize); + this.setItems(items); + this.initShowNum(); + } + + public int getShowPage() { + return showPage; + } + + public void setShowPage(int showPage) { + this.showPage = showPage; + } + + @Override + public void setItemsTotalCount(int itemsTotalCount) { + super.setItemsTotalCount(itemsTotalCount); + initShowNum(); + } + + private void initShowNum(){ + int startIndex; + int endIndex; + if(pageNum - showPage/2 > 1){ + startIndex = pageNum-showPage/2; + endIndex = pageNum + showPage/2 - 1; + if(endIndex > pageTotalCount){ + endIndex = pageTotalCount; + startIndex = endIndex - showPage + 1; + } + }else{ + startIndex = 1; + endIndex = pageTotalCount<=showPage?pageTotalCount:showPage; + } + for(int i = startIndex; i <= endIndex ; i++){ + this.showNums.add(Integer.valueOf(i)); + } + if(this.firstPage||this.lastPage){ + showDot = false; + }else{ + if(showNums.size() > 0){ + if(showNums.get(showNums.size()-1) == this.pageTotalCount){ + showDot = false; + } + } + } + } + + public List getShowNums() { + return showNums; + } + + public boolean getShowDot() { + return showDot; + } + + public int getPageTotalCount(){ + return this.pageTotalCount; + } +} + diff --git a/src/main/java/com.krt.dairy.common.storage/FileType.java b/src/main/java/com.krt.dairy.common.storage/FileType.java new file mode 100644 index 0000000..db1fab4 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.storage/FileType.java @@ -0,0 +1,27 @@ +package com.krt.dairy.common.storage; + +/** + * 定义文件类型及其对应魔数 + */ +public enum FileType { + JPEG("FFD8FF"), + + PNG("89504E47"), + + GIF("47494638"); + + private String value = ""; + + private FileType(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + +} \ No newline at end of file diff --git a/src/main/java/com.krt.dairy.common.storage/FileTypeHelper.java b/src/main/java/com.krt.dairy.common.storage/FileTypeHelper.java new file mode 100644 index 0000000..165fa82 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.storage/FileTypeHelper.java @@ -0,0 +1,45 @@ +package com.krt.dairy.common.storage; + +import org.springframework.util.Assert; + +import java.util.Arrays; + +public class FileTypeHelper { + + public static FileType getType(byte[] buff){ + Assert.isTrue(buff!=null &&buff.length>28); + byte[] bytes= Arrays.copyOfRange(buff, 0, 28); + String magic = bytesToHex(bytes); + + for(FileType type:FileType.values()){ + if(magic.startsWith(type.getValue())) return type; + } + return null; + } + + /** + * 判断是否为图片,是图片返回true,否则返回false + * + * @param buff + * @return 图片返回true,否则返回false + */ + public static boolean isImage(byte[] buff){ + FileType type = getType(buff); + return FileType.JPEG.equals(type)||FileType.PNG.equals(type); + } + + private static String bytesToHex(byte[] src) { + StringBuilder stringBuilder = new StringBuilder(); + if (src == null || src.length <= 0) return null; + for (int i = 0; i < src.length; i++) { + int v = src[i] & 0xFF; + String hv = Integer.toHexString(v); + if (hv.length() < 2) { + stringBuilder.append(0); + } + stringBuilder.append(hv); + } + return stringBuilder.toString().toUpperCase(); + } + +} diff --git a/src/main/java/com.krt.dairy.common.storage/QiniuImg.java b/src/main/java/com.krt.dairy.common.storage/QiniuImg.java new file mode 100644 index 0000000..63ecd0d --- /dev/null +++ b/src/main/java/com.krt.dairy.common.storage/QiniuImg.java @@ -0,0 +1,133 @@ +package com.krt.dairy.common.storage; + +import org.springframework.util.StringUtils; + +import java.io.Serializable; + +/** + * 七牛图片类 + */ +public class QiniuImg implements Serializable{ + private static final long serialVersionUID = -68217983332179128L; + + private String key;//七牛返回的key + private String url;//原图片的url + + private String url16;// + private String url32;// + private String url48;// + private String url64;// + private String url128;// + private String url256;// + private String url512;// + + + public String getKey() { + return key; + } + public void setKey(String key) { + this.key = key; + } + + public String getUrl() { + if(StringUtils.isEmpty(key)) return null; + if(this.url==null){ + this.url = QiniuWrapper.getUrl(key); + } + return url; + } + public void setUrl(String url) { + this.url = url; + } + + + public String getUrl16() { + if(StringUtils.isEmpty(key)) return null; + if(this.url16==null){ + this.url16 = QiniuWrapper.getUrl(key, ThumbModel.THUMB_16.getValue()); + } + return this.url16; + } + public void setUrl16(String url16) { + this.url16 = url16; + } + + + public String getUrl32() { + if(StringUtils.isEmpty(key)) return null; + if(this.url32==null){ + this.url32 = QiniuWrapper.getUrl(key, ThumbModel.THUMB_32.getValue()); + } + return this.url32; + } + public void setUrl32(String url32) { + this.url32 = url32; + } + + + public String getUrl48() { + if(StringUtils.isEmpty(key)) return null; + if(this.url48==null){ + this.url48 = QiniuWrapper.getUrl(key, ThumbModel.THUMB_48.getValue()); + } + return this.url48; + } + public void setUrl48(String url48) { + this.url48 = url48; + } + + + public String getUrl64() { + if(StringUtils.isEmpty(key)) return null; + if(this.url64==null){ + this.url64 = QiniuWrapper.getUrl(key, ThumbModel.THUMB_64.getValue()); + } + return this.url64; + } + public void setUrl64(String url64) { + this.url64 = url64; + } + + + public String getUrl128() { + if(StringUtils.isEmpty(key)) return null; + if(this.url128==null){ + this.url128 = QiniuWrapper.getUrl(key, ThumbModel.THUMB_128.getValue()); + } + return this.url128; + } + public void setUrl128(String url128) { + this.url128 = url128; + } + + + public String getUrl256() { + if(StringUtils.isEmpty(key)) return null; + if(this.url256==null){ + this.url256 = QiniuWrapper.getUrl(key, ThumbModel.THUMB_256.getValue()); + } + return this.url256; + } + public void setUrl256(String url256) { + this.url256 = url256; + } + + + public String getUrl512() { + if(StringUtils.isEmpty(key)) return null; + if(this.url512==null){ + this.url512 = QiniuWrapper.getUrl(key, ThumbModel.THUMB_512.getValue()); + } + return this.url512; + } + public void setUrl512(String url512) { + this.url512 = url512; + } + + //七牛上传key,然后七牛会返回一个key,将返回的key保存到数据库 + public String getUploadKey(){ + return QiniuKeyGenerator.generateKey(); + } + +} + diff --git a/src/main/java/com.krt.dairy.common.storage/QiniuKeyGenerator.java b/src/main/java/com.krt.dairy.common.storage/QiniuKeyGenerator.java new file mode 100644 index 0000000..00f6643 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.storage/QiniuKeyGenerator.java @@ -0,0 +1,20 @@ +package com.krt.dairy.common.storage; + +import com.krt.dairy.common.util.CommonUtil; + +import java.text.MessageFormat; + +/** + * 资源在七牛云存储的key生成器 + * 注:资源是七牛云存储服务中的逻辑存储单元。对于每一个账号, + * 该账号里存放的每个资源都有唯一的一对属主空间(Bucket)与键名(Key),作为识别标识 + */ +public class QiniuKeyGenerator { + + public static final String KEY = "/{0}/{1}/{2}/{3}";// 多图片可以按照:/表名/字段名/业务值(refId)/时间戳 处理 + + public static String generateKey(){ + return MessageFormat.format(KEY, "default", "all", "0", CommonUtil.getUID()); + } + +} diff --git a/src/main/java/com.krt.dairy.common.storage/QiniuStorage.java b/src/main/java/com.krt.dairy.common.storage/QiniuStorage.java new file mode 100644 index 0000000..2d1f98e --- /dev/null +++ b/src/main/java/com.krt.dairy.common.storage/QiniuStorage.java @@ -0,0 +1,91 @@ +package com.krt.dairy.common.storage; + + + +/** + * 七牛云存储管理器 + * 上传图像和查看图像 + */ +public class QiniuStorage { + + /** + * 上传单张图片;返回上传图片的key + * @param buff + */ + public static String uploadImage(byte[] buff){ + String key = QiniuKeyGenerator.generateKey(); + key = QiniuWrapper.upload(buff, key,false); + return key; + } + + /** + * 上传单张图片;返回上传图片的url,此url会过期,切记不要存储在数据库中; + * @param buff + * @param img + * @return QiniuImg + */ + public static QiniuImg uploadImage(byte[] buff,QiniuImg img){ + String key = QiniuWrapper.upload(buff, img.getUploadKey(),false); + img.setKey(key); + return img; + } + + + /** + * 上传多个图片 + * @param imageBuffs 图片字节数组 + * @param img 分组图片的属性 + * @return + */ + public static QiniuImg[] uploadImages(byte[][] imageBuffs,QiniuImg img){ + QiniuImg[] images = new QiniuImg[imageBuffs.length]; + for(int i = 0; i < imageBuffs.length; i++){ + QiniuImg newImg = new QiniuImg(); + uploadImage(imageBuffs[i],img); + newImg.setKey(img.getKey()); + images[i] = newImg; + } + return images; + } + + + /** + * 获取图片链接 + * @param key + * @return + */ + public static String getUrl(String key){ + return QiniuWrapper.getUrl(key); + } + + /** + * 获取有有效期的图片链接 + * @param key + * @param expires 单位:秒 + * @return + */ + public static String getUrl(String key,long expires){ + return QiniuWrapper.getUrl(key,expires); + } + + + /** + * 获取图片链接 + * @param key + * @return + */ + public static String getUrl(String key,ThumbModel model){ + return QiniuWrapper.getUrl(key,model.getValue()); + } + + /** + * 获取有有效期的图片链接 + * @param key + * @param expires 单位:秒 + * @return + */ + public static String getUrl(String key,ThumbModel model,long expires){ + return QiniuWrapper.getUrl(key,model.getValue(),expires); + } + +} diff --git a/src/main/java/com.krt.dairy.common.storage/QiniuWrapper.java b/src/main/java/com.krt.dairy.common.storage/QiniuWrapper.java new file mode 100644 index 0000000..808402e --- /dev/null +++ b/src/main/java/com.krt.dairy.common.storage/QiniuWrapper.java @@ -0,0 +1,154 @@ +package com.krt.dairy.common.storage; + +import com.krt.dairy.common.util.PropertiesUtil; +import com.qiniu.common.QiniuException; +import com.qiniu.common.Zone; +import com.qiniu.http.Response; +import com.qiniu.storage.Configuration; +import com.qiniu.storage.UploadManager; +import com.qiniu.storage.model.DefaultPutRet; +import com.qiniu.util.Auth; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.StringUtils; + +import java.util.*; + +/** + * 七牛SDK的包装类,以便于业务使用 + */ +public class QiniuWrapper { + + private static final Logger logger = LoggerFactory.getLogger(QiniuWrapper.class); + + private static final String CONFIG_BUCKET="qiniu.bucket"; + + private static final String CONFIG_AK="qiniu.accesskey"; + private static final String CONFIG_SK="qiniu.secretkey"; + private static final String CONFIG_CDN="qiniu.cdns"; + + private static final Auth auth; + private static final UploadManager uploadManager; + + private static final String bucketName; + private static final List cdns; + + /** + * 从外部文件中初始化七牛存储相关的配置信息 + */ + static{ + Properties properties =PropertiesUtil.getDefaultProperties(); + auth = Auth.create(properties.getProperty(CONFIG_AK), properties.getProperty(CONFIG_SK)); + Configuration cfg = new Configuration(Zone.zone2());//设置空间上传域名 + uploadManager = new UploadManager(cfg); + bucketName=properties.getProperty(CONFIG_BUCKET); + String cdn = properties.getProperty(CONFIG_CDN); + cdns = Arrays.asList(cdn.split(",")); + } + + /** + * 获取上传资源的token + * @return + */ + public static String getUploadToken(){ + return auth.uploadToken(bucketName); + } + + /** + * 获取更新资源的token,只能用于更新参数key所代表的资源 + * @param key 存储空间中已存在的资源key + * @return + */ + public static String getUploadToken(String key){ + return auth.uploadToken(bucketName,key); + } + + /** + * 上传文件 + * @param data 二进制格式的文件内容 + * @param key 文件在七牛中的key + * @param update 是否是更新 + * @return + */ + public static String upload(byte[] data,String key,boolean update){ + try { + String token = update?auth.uploadToken(bucketName,key):auth.uploadToken(bucketName); + Response response = uploadManager.put(data, getFullKey(data, key), token); + DefaultPutRet ret = response.jsonToObject(DefaultPutRet.class); + return ret.key; + } catch (QiniuException e) { + logger.error("upload file to qiniu cloud storage failed",e); + } + return null; + } + + private static String getFullKey(byte[] data,String key){ + FileType type= FileTypeHelper.getType(data); + if(type!=null){ + return key+"."+type.name().toLowerCase(); + }else{ + return key; + } + } + + public static String getUrl(String key,String model){ + return getUrl(key, model, 3600); + } + + /** + * 获取多个key图片; + * @param keys 逗号隔开的多个key; + * @param model + * @return + */ + public static List getUrls(String keys,String model){ + List list = null; + if (org.apache.commons.lang.StringUtils.isNotBlank(keys)) { + list = new ArrayList(); + for (String key : keys.split(",")) { + list.add(getUrl(key, model, 3600)); + } + } + return list; + } + + public static String getUrl(String key){ + if(!StringUtils.isEmpty(key)){ + return auth.privateDownloadUrl("http://"+getCDN()+"/@"+key); + } + return null; + } + + /** + * @param key + * @param expires 单位:秒 + * @return + */ + public static String getUrl(String key,long expires){ + if(!StringUtils.isEmpty(key)){ + long time = System.currentTimeMillis()/1000+expires; + return auth.privateDownloadUrl("http://"+getCDN()+"/@"+key,time); + } + return null; + } + + public static String getUrl(String key,String model,long expires){ + if(StringUtils.hasText(model)){ + return auth.privateDownloadUrl("http://"+getCDN()+"/@"+key+"?"+model,expires); + }else{ + return auth.privateDownloadUrl("http://"+getCDN()+"/@"+key,expires); + } + } + + /** + * 从多条CDN路径中随机选择一条 + * @return + */ + private static String getCDN(){ + Random random= new Random(); + int num=random.nextInt(cdns.size()); + return cdns.get(num); + } + + +} diff --git a/src/main/java/com.krt.dairy.common.storage/ThumbModel.java b/src/main/java/com.krt.dairy.common.storage/ThumbModel.java new file mode 100644 index 0000000..92fb4ce --- /dev/null +++ b/src/main/java/com.krt.dairy.common.storage/ThumbModel.java @@ -0,0 +1,29 @@ +package com.krt.dairy.common.storage; + +/** + * 文件的缩略图及其模式字符串定义 + */ +public enum ThumbModel { + + THUMB_16("imageView2/2/w/16/h/16"), + THUMB_32("imageView2/2/w/32/h/32"), + THUMB_48("imageView2/2/w/48/h/48"), + THUMB_64("imageView2/2/w/64/h/64"), + THUMB_128("imageView2/2/w/128/h/128"), + THUMB_256("imageView2/2/w/256/h/256"), + THUMB_512("imageView2/2/w/512/h/512"); + + + private String value; + + private ThumbModel(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + +} + + diff --git a/src/main/java/com.krt.dairy.common.util/BeanField.java b/src/main/java/com.krt.dairy.common.util/BeanField.java new file mode 100644 index 0000000..e5eb64a --- /dev/null +++ b/src/main/java/com.krt.dairy.common.util/BeanField.java @@ -0,0 +1,22 @@ +package com.krt.dairy.common.util; + +import java.lang.reflect.Field; + +public class BeanField { + private String columnName; + private Field field; + + public String getColumnName() { + return columnName; + } + public void setColumnName(String columnName) { + this.columnName = columnName; + } + public Field getField() { + return field; + } + public void setField(Field field) { + this.field = field; + } + +} diff --git a/src/main/java/com.krt.dairy.common.util/BeanUtil.java b/src/main/java/com.krt.dairy.common.util/BeanUtil.java new file mode 100644 index 0000000..8c0f8d2 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.util/BeanUtil.java @@ -0,0 +1,385 @@ +package com.krt.dairy.common.util; + +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.log4j.Logger; +import org.springframework.util.Assert; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Transient; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.*; + +/** + * Bean 转换工具 + */ +@SuppressWarnings("rawtypes") +public class BeanUtil { + + private static Logger log = Logger.getLogger(BeanUtil.class); // 日志 + + //将map list转换为bean list + public static List mapListToBeanList(Class clazz, List> mapList){ + List rstList = new ArrayList(); + for(Map map : mapList){ + rstList.add(mapToBean(clazz,map)); + } + return rstList; + } + + //将map转换为bean + public static T mapToBean(Class clazz, Map map) { + if(map == null){ + return null; + } + // 创建对象 + T instance = null; + try { + instance = clazz.newInstance(); + if (instance == null) { + throw new Exception(); + } + } catch (Exception e) { + log.error("类型实例化对象失败,类型:" + clazz); + return null; + } + Map newMap = new HashMap(); + for (Map.Entry en : map.entrySet()) { + newMap.put(columnSetMethod(en.getKey().toLowerCase()),en.getValue()); + } + Method[] methods = clazz.getMethods(); + for (Method method : methods) { + String mname = method.getName(); + if (mname.startsWith("set")) { + Class[] ptypes = method.getParameterTypes(); + Object v = newMap.get(mname); + if (v != null && ptypes.length == 1) { + try { + method.invoke(instance, v); + } catch (Exception e) { + log.error("属性值装入失败,装入方法:" + ptypes + "." + + method.getName() + ".参数类型" + ptypes[0] + + ";装入值的类型:" + v.getClass()); + } + } + } + } + return instance; + } + + /** + * 将map中的column key 转换为 field key + */ + public static Map columnToFieldKey(Map map){ + Map newMap = new HashMap(); + for (Map.Entry en : map.entrySet()) { + newMap.put(columnSetMethod(en.getKey()),en.getValue()); + } + return newMap; + } + + /** + * 返回表名 + * @param clazz + * @param + * @return + */ + public static String getTableName(Class clazz) { + Assert.isTrue(isEntity(clazz)); + Table table = clazz.getAnnotation(Table.class); + if (table != null && !table.name().equals("")) + return table.name(); + + Entity entity = clazz.getAnnotation(Entity.class); + if (entity != null && !entity.name().equals("")) + return entity.name(); + return clazz.getSimpleName(); + } + /** + * 检测是否为可持久化的实体 + * @param clazz + * @param + * @return + */ + public static boolean isEntity(Class clazz) { + return clazz.getAnnotation(Entity.class) != null || clazz.getAnnotation(Table.class) != null; + } + + /** + * 获取所有的属性和值,包括父类的 + * @param bean + * @return + */ + public static Map getAllFields(Object bean) { + return getAllFields(bean,bean.getClass()); + } + + /** + * 获取所有的属性和值,包括父类的 + * @param bean + * @param clazz + * @return + */ + public static Map getAllFields(Object bean,Class clazz) { + if (clazz == null) { + return null; + } + try{ + Map map = new LinkedHashMap(); + Field[] fields = clazz.getDeclaredFields(); + if (fields != null) { + for (Field field : fields) { + //排除肯定不持久化的部分 + if (Modifier.isTransient(field.getModifiers())) continue; + if (Modifier.isStatic(field.getModifiers())) continue; + if (field.getAnnotation(Transient.class) != null) continue; + if (field.getAnnotation(Id.class) != null) continue; + map.put(field.getName(), PropertyUtils.getProperty(bean, field.getName())); + } + } + Class superClass = clazz.getSuperclass();//递归获取父类的Field + Map superMap = getAllFields(bean,superClass); + if (superMap != null) { + map.putAll(superMap); + } + if (map.size() == 0) { + return null; + } + return map; + }catch(Exception e){ + e.printStackTrace(); + return null; + } + } + + //获取属性的值 + public static Object getProperty(Object bean, String fieldName)throws Exception{ + Class fieldType = PropertyUtils.getPropertyType(bean, fieldName.trim()); + if(fieldType != null){ + return PropertyUtils.getProperty(bean, fieldName.trim()); + } + return null; + } + + /** + * 设置property的值 + * @param bean + * @param fieldName + * @param value + * @throws Exception + */ + public static void setProperty(Object bean, String fieldName, Object value) throws Exception{ + Class fieldType = PropertyUtils.getPropertyType(bean, fieldName); + + if(value == null || "".equals(value)){ + PropertyUtils.setProperty(bean, fieldName, null); + }else{ + Object tmpValue = null; + if(fieldType == String.class){ + tmpValue = value.toString(); + }else if(fieldType == Double.class){ + tmpValue = new Double(value.toString()); + }else if(fieldType == Double.TYPE){ + tmpValue = Double.valueOf(new Double(value.toString()).doubleValue()); + }else if(fieldType == Float.class){ + tmpValue = new Float(value.toString()); + }else if(fieldType == Float.TYPE){ + tmpValue = Float.valueOf(new Float(value.toString()).floatValue()); + }else if(fieldType == Integer.class){ + tmpValue = new Integer(value.toString()); + }else if(fieldType == Integer.TYPE){ + tmpValue = Integer.valueOf(new Integer(value.toString()).intValue()); + }else if(fieldType == Long.class){ + tmpValue = Long.valueOf(value.toString()); + }else if(fieldType == Long.TYPE){ + tmpValue = Long.valueOf(Long.valueOf(value.toString()).longValue()); + }else if(fieldType == Boolean.class){ + tmpValue = Boolean.valueOf(value.toString()); + }else if(fieldType == Boolean.TYPE){ + tmpValue = Boolean.valueOf(Boolean.valueOf(value.toString()).booleanValue()); + }else if (fieldType == java.util.Date.class) { + tmpValue = DateUtil.COMPAT.getTextDate((String) value); + }else{ + tmpValue = null; + } + + PropertyUtils.setProperty(bean, fieldName, tmpValue); + } + } + + /** + * 获取属性类型 + * @param bean + * @param property + * @return + * @throws Exception + */ + public static Class getPropertyType(Object bean,String property)throws Exception{ + try { + Field field = bean.getClass().getDeclaredField(property); + if(field != null) + return PropertyUtils.getPropertyType(bean, property); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchFieldException e) { + return null; + } + return null; + } + + /** + * 数据库字段转换为set方法 + * @param column + * @return + */ + public static String columnSetMethod(String column){ + return "set" + columnToField2(column); + } + + /** + * 转换属性到数据库字段 + * @param clazz + * @return + */ + public static Map getAllFieldColumns(Class clazz) { + if (clazz == null) { + return null; + } + try { + Map map = new LinkedHashMap(); + Field[] fields = clazz.getDeclaredFields(); + if (fields != null) { + for (Field field : fields) { + if (!"serialVersionUID".equals(field.getName())) {// 序列化ID不需要 + String fieldName = field.getName(); + String colName = BeanUtil.fieldToColumn(fieldName); + map.put(fieldName, colName); + } + } + } + Class superClass = clazz.getSuperclass();// 递归获取父类的Field + Map superMap = getAllFieldColumns(superClass); + if (superMap != null) { + map.putAll(superMap); + } + if (map.size() == 0) { + return null; + } + return map; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * @param clazz + * @return + */ + public static Map getAllFields(Class clazz) { + if (clazz == null) { + return null; + } + try { + Map map = new LinkedHashMap(); + Field[] fields = clazz.getDeclaredFields(); + if (fields != null) { + for (Field field : fields) { + if (!"serialVersionUID".equals(field.getName())) {// 序列化ID不需要 + String fieldName = field.getName(); + String colName = BeanUtil.fieldToColumn(fieldName); + BeanField beanField = new BeanField(); + beanField.setColumnName(colName); + beanField.setField(field); + map.put(fieldName, beanField); + } + } + } + Class superClass = clazz.getSuperclass();// 递归获取父类的Field + Map superMap = getAllFields(superClass); + if (superMap != null) { + map.putAll(superMap); + } + if (map.size() == 0) { + return null; + } + return map; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 转换有下划线的String,下划线的后一个字母大写 + * @param str + * @return + */ + public static String columnToField(String str) { + String[] arr = str.split("_"); + if (arr != null && arr.length > 1) { + String rstStr = arr[0]; + for (int i = 1; i < arr.length; i++) { + rstStr += arr[i].substring(0, 1).toUpperCase() + arr[i].substring(1); + } + return rstStr; + } else { + return str; + } + } + + /** + * 转换有下划线的String,第一个字母大写,下划线的后一个字母大写 + * @param str + * @return + */ + public static String columnToField2(String str) { + String[] arr = str.split("_"); + if (arr != null && arr.length > 1) { + String rstStr = arr[0].substring(0, 1).toUpperCase() + arr[0].substring(1); + for (int i = 1; i < arr.length; i++) { + rstStr += arr[i].substring(0, 1).toUpperCase() + arr[i].substring(1); + } + return rstStr; + } else { + return str.substring(0, 1).toUpperCase() + str.substring(1); + } + } + + /** + * 转换将第一个字母大写变成小写,并在前面加下划线 + * @param args + */ + public static String fieldToColumn(String str) { + char[] chars = str.toCharArray(); + String rstStr = ""; + for (int i = 0; i < chars.length; i++) { + if (chars[i] > 64 && chars[i] < 94) { + rstStr += ("_" + chars[i]).toLowerCase(); + } else { + rstStr += chars[i]; + } + } + return rstStr; + } + + /** + * 首字母变大写 + * @param args + */ + public static String upperCaseFirst(String str) { + return Character.toUpperCase(str.charAt(0))+str.substring(1, str.length()); + } + + /** + * 首字母变小写 + * @param args + */ + public static String lowerCaseFirst(String str) { + return Character.toLowerCase(str.charAt(0))+str.substring(1, str.length()); + } + +} diff --git a/src/main/java/com.krt.dairy.common.util/CalendarUtil.java b/src/main/java/com.krt.dairy.common.util/CalendarUtil.java new file mode 100644 index 0000000..24dddea --- /dev/null +++ b/src/main/java/com.krt.dairy.common.util/CalendarUtil.java @@ -0,0 +1,453 @@ +package com.krt.dairy.common.util; + +import java.text.ParseException; +import java.util.*; + +/** + * 日期工具类 + */ +public class CalendarUtil { + + public static final String YEAR = "year"; + public static final String MONTH = "month"; + public static final String MONTH_FIRST_DAY_TIME = "month_first_day_time"; + public static final String MONTH_LAST_DAY_TIME = "month_last_day_time"; + + //获取当前年的前5年数据 + public static List getPre5Years(){ + List years = new ArrayList(); + Calendar calendar = Calendar.getInstance(); + int year = calendar.get(Calendar.YEAR); + for(int i = 0; i < 5; i++){ + years.add((year - i) + ""); + } + return years; + } + + //获取12个月的数据 + public static List get12MonthStr(){ + List months = new ArrayList(); + for(int i = 1 ;i < 13 ;i++){ + months.add(i+""); + } + return months; + } + + //获取当前明天的数据 + public static String getNextDay(String format){ + Calendar calendar = Calendar.getInstance(); + Calendar tmpCalendar = Calendar.getInstance(); + tmpCalendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));//设置本月最大日期 + int maxDate = tmpCalendar.get(Calendar.DATE); + + int month = calendar.get(Calendar.MONTH); + int year = calendar.get(Calendar.YEAR); + int date = calendar.get(Calendar.DATE); + + if(date + 1 > maxDate ){ + if(month + 1 > 11){ + calendar.add(Calendar.YEAR, 1); + calendar.set(Calendar.MONTH, 0); + calendar.set(Calendar.DATE, 1); + }else{ + calendar.set(year, month, date+1); + } + }else{ + calendar.set(year, month, date+1); + } + return DateUtil.getDateText(calendar.getTime(), format); + } + + //获取n天后的日期 + public static Date getNextNDay(Date startTime,Integer n){ + Calendar start = Calendar.getInstance(); + start.setTime(startTime); + start.add(Calendar.DATE, n); + return start.getTime(); + } + + //获取n天后的日期 00:00:00 + public static Date getNextNDayBegin(Date startTime,Integer n){ + Calendar start = Calendar.getInstance(); + start.setTime(startTime); + start.add(Calendar.DATE, n); + start.set(Calendar.HOUR_OF_DAY, 0); + start.set(Calendar.MINUTE, 0); + start.set(Calendar.SECOND, 0); + return start.getTime(); + } + + //获取n天后的日期 23:59:59 + public static Date getNextNDayEnd(Date startTime,Integer n){ + Calendar start = Calendar.getInstance(); + start.setTime(startTime); + start.add(Calendar.DATE, n); + start.set(Calendar.HOUR_OF_DAY, 23); + start.set(Calendar.MINUTE, 59); + start.set(Calendar.SECOND, 59); + return start.getTime(); + } + + //获取n天前的日期 + public static Date getPreNDay(Date startTime,Integer n){ + Calendar start = Calendar.getInstance(); + start.setTime(startTime); + start.add(Calendar.DATE, -n); + return start.getTime(); + } + + //获取n天前的日期 00:00:00 + public static Date getPreNDayBegin(Date startTime,Integer n){ + Calendar start = Calendar.getInstance(); + start.setTime(startTime); + start.add(Calendar.DATE, -n); + start.set(Calendar.HOUR_OF_DAY, 0); + start.set(Calendar.MINUTE, 0); + start.set(Calendar.SECOND, 0); + return start.getTime(); + } + + //获取n天前的日期 23:59:59 + public static Date getPreNDayEnd(Date startTime,Integer n){ + Calendar start = Calendar.getInstance(); + start.setTime(startTime); + start.add(Calendar.DATE, -n); + start.set(Calendar.HOUR_OF_DAY, 23); + start.set(Calendar.MINUTE, 59); + start.set(Calendar.SECOND, 59); + return start.getTime(); + } + + //获取前x天的数据, x < 10; + public static String getPreXDay(int x ,String format){ + Calendar calendar = Calendar.getInstance(); + int month = calendar.get(Calendar.MONTH); + int year = calendar.get(Calendar.YEAR); + int date = calendar.get(Calendar.DATE); + + if(date - x < 0 ){ + if(month - 1 < 0){ + calendar.add(Calendar.YEAR, -1); + calendar.set(Calendar.MONTH, 11); + calendar.set(Calendar.DATE, 31 - (x-date)); + }else{ + calendar.add(Calendar.MONTH, -1); + calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));//设置本月最大日期 + int maxDate = calendar.get(Calendar.DATE); + calendar.set(year, month - 1, maxDate - (x-date)); + } + }else{ + calendar.set(year, month, date - x); + } + return DateUtil.getDateText(calendar.getTime(), format); + } + + //获取当前年 + public static String getYear(){ + Calendar calendar = Calendar.getInstance(); + int year = calendar.get(Calendar.YEAR); + return year+""; + } + + //获取当前月 + public static String getMonth(){ + Calendar calendar = Calendar.getInstance(); + int month = calendar.get(Calendar.MONTH); + month = month + 1; + if(month > 12){ + return "12"; + } + return month+""; + } + + //获取 年-月的 第一天 和 最后一天 时间 + public static Map getMonthFirstEndDayTime(String year,String month){ + Map rst = new HashMap(); + Calendar calendar = Calendar.getInstance(); + int m = Integer.parseInt(month); + m = m - 1; + if(m < 0){ + m = 0; + } + calendar.set(Integer.parseInt(year), m, 1); + String firstDayTime = DateUtil.COMMON.getDateText(calendar.getTime()) +" 00:00:00"; + + calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));//设置本月最大日期 + String lastDayTime = DateUtil.COMMON.getDateText(calendar.getTime()) +" 23:59:59"; + + rst.put(CalendarUtil.MONTH_FIRST_DAY_TIME, firstDayTime); + rst.put(CalendarUtil.MONTH_LAST_DAY_TIME, lastDayTime); + + return rst; + } + + //获取前一个月 + public static Map getPreMonth(){ + Map rst = new HashMap(); + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MONTH, -1); + int year = calendar.get(Calendar.YEAR); + int month = calendar.get(Calendar.MONTH); + month = month + 1; + + rst.put("year", year+""); + if(month > 12){ + rst.put("month", "12"); + }else{ + rst.put("month", month+""); + } + return rst; + } + + //获取前一个月 + public static Map getPreMonth(Integer year,Integer month){ + Map rst = new HashMap(); + if(month == 1){ + rst.put("year", (year-1)+""); + rst.put("month", "12"); + }else{ + rst.put("year", year+""); + rst.put("month", (month-1)+""); + } + return rst; + } + + //获取开始月份和结束月份中间的所有月份,包括开始月份和结束月份 + public static List getBetweenMonths(String startMonth ,String endMonth){ + String[] startArr = startMonth.split("-"); + String[] endArr = endMonth.split("-"); + + Integer startY = Integer.parseInt(startArr[0]); + Integer startM = Integer.parseInt(startArr[1]); + + Integer endY = Integer.parseInt(endArr[0]); + Integer endM = Integer.parseInt(endArr[1]); + + Calendar startCalendar = Calendar.getInstance(); + startCalendar.set(startY, startM - 1, 1, 0, 0); + + Calendar endCalendar = Calendar.getInstance(); + endCalendar.set(endY, endM - 1, 1, 0, 0); + + List months = new ArrayList(); + while(startCalendar.getTimeInMillis() <= endCalendar.getTimeInMillis()){ + months.add(DateUtil.getDateText(startCalendar.getTime(),"yyyy-MM")); + startCalendar.add(Calendar.MONTH, 1); + } + return months; + } + + //获取日期之间的天List formt = "yyyy-MM-dd" + public static List getBetweenDateStr(String startTime,String endTime){ + List dateList = new ArrayList(); + try { + Long startM = DateUtil.COMMON.getTextDate(startTime).getTime(); + Long endM = DateUtil.COMMON.getTextDate(endTime).getTime(); + long result = (endM-startM) / (24 * 60 * 60*1000); + String[] startTimeStr = startTime.split("-"); + Calendar startCalendar = Calendar.getInstance(); + startCalendar.set(Integer.parseInt(startTimeStr[0]), Integer.parseInt(startTimeStr[1]) - 1, Integer.parseInt(startTimeStr[2])); + startCalendar.add(Calendar.DATE,-1); + for(int i = 0; i <= result ; i++){ + startCalendar.add(Calendar.DATE,1); + dateList.add(DateUtil.COMMON.getDateText(startCalendar.getTime())); + } + } catch (ParseException e) { + e.printStackTrace(); + } + return dateList; + } + + public static List getBetweenDateStr(String startTime,String endTime,String format){ + List dateList = new ArrayList(); + try { + Long startM = DateUtil.COMMON.getTextDate(startTime).getTime(); + Long endM = DateUtil.COMMON.getTextDate(endTime).getTime(); + long result = (endM-startM) / (24 * 60 * 60*1000); + String[] startTimeStr = startTime.split("-"); + Calendar startCalendar = Calendar.getInstance(); + startCalendar.set(Integer.parseInt(startTimeStr[0]), Integer.parseInt(startTimeStr[1]) - 1, Integer.parseInt(startTimeStr[2])); + startCalendar.add(Calendar.DATE,-1); + for(int i = 0; i <= result ; i++){ + startCalendar.add(Calendar.DATE,1); + dateList.add(DateUtil.getDateText(startCalendar.getTime(),format)); + } + } catch (ParseException e) { + e.printStackTrace(); + } + return dateList; + } + + //获取日期的前n个月的月份(闭区间) + public static List getPreNMonths(String curMonth ,Integer n){ + String[] curArr = curMonth.split("-"); + Integer curY = Integer.parseInt(curArr[0]); + Integer curM = Integer.parseInt(curArr[1]); + + Calendar curCalendar = Calendar.getInstance(); + curCalendar.set(curY, curM - 1, 1, 0, 0); + + Calendar tmpCalendar = Calendar.getInstance(); + tmpCalendar.set(curY, curM - 1 - n, 1, 0, 0); + + List months = new ArrayList(); + while(tmpCalendar.getTimeInMillis() <= curCalendar.getTimeInMillis()){ + months.add(DateUtil.getDateText(tmpCalendar.getTime(),"yyyy-MM")); + tmpCalendar.add(Calendar.MONTH, 1); + } + return months; + } + + //获取当前天 + public static String getToday(String format){ + Calendar calendar = Calendar.getInstance(); + return DateUtil.getDateText(calendar.getTime(), format); + } + + //获取当前月的第一天 + public static String getFirstDay(String format){ + Calendar calendar = Calendar.getInstance(); + int month = calendar.get(Calendar.MONTH); + int year = calendar.get(Calendar.YEAR); + calendar.set(year, month, 1); + return DateUtil.getDateText(calendar.getTime(), format); + } + + //获取当前月的最后一天 + public static String getLastDay(String format){ + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));//设置本月最大日期 + return DateUtil.getDateText(calendar.getTime(), format); + } + + //获取当前月的第一天 + public static Date getFirstDate(){ + Calendar calendar = Calendar.getInstance(); + int month = calendar.get(Calendar.MONTH); + int year = calendar.get(Calendar.YEAR); + calendar.set(year, month, 1); + return calendar.getTime(); + } + + //获取当前月的最后一天 + public static Date getLastDate(){ + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));//设置本月最大日期 + return calendar.getTime(); + } + + + //日期的天是否一样; + public static boolean isDayEqual(Date date1,Date date2){ + if(date1==null || date2 == null){ + return false; + } + String date1Str = DateUtil.COMPAT.getDateText(date1); + String date2Str = DateUtil.COMPAT.getDateText(date2); + return date1Str.equals(date2Str); + } + + /** + * 时间间距是否为xx; + * 如果在 space 之内返回true;否则返回false + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param space 毫秒 + * @return + */ + public static boolean isTimeSpace(Date startTime,Date endTime,long space){ + if (startTime == null || endTime == null) { + return false; + } + return endTime.getTime() - startTime.getTime() <= space; + } + + /** + * 时间间距是否在 startSpace 和 endSpace 之间 + * @param startTime + * @param endTime + * @param startSpace + * @param endSpace + * @return + */ + public static boolean isTimeBetween(Date startTime,Date endTime,long startSpace,long endSpace){ + return endTime.getTime() - startTime.getTime() <= endSpace && + endTime.getTime() - startTime.getTime() >= startSpace; + } + + public static boolean isTimeBetween(Date time,Date startTime,Date endTime){ + return time.getTime() >= startTime.getTime() && time.getTime() <= endTime.getTime(); + } + + //获取日期之间年的距离 + public static Integer getYearSpace(Date startTime,Date endTime){ + Calendar start = Calendar.getInstance(); + start.setTime(startTime); + Calendar end = Calendar.getInstance(); + end.setTime(endTime); + return end.get(Calendar.YEAR) - start.get(Calendar.YEAR); + } + + //获取日期之间天的距离 + public static Integer getDaySpace(Date startTime,Date endTime){ + return (int)(endTime.getTime() - startTime.getTime())/(24*60*60*1000); + } + + //获取当前日期 毫秒 + public static long getTimeInMillis(){ + Calendar now = Calendar.getInstance(); + return now.getTimeInMillis(); + } + + //获取当前日期 秒 + public static long getTimeInSeconds(){ + return getTimeInMillis()/1000L; + } + + public static void main(String[] args){ + /*String startTime = "2009-12-14"; + String endTime = "2010-1-14"; + List list = getBetweenDateStr(startTime,endTime); + for(String s : list){ + System.out.println(s); + }*/ + /*String nextday = getNextDay("yyyy-MM-dd"); + String xday = getPreXDay(6,"yyyy-MM-dd"); + System.out.println(nextday); + System.out.println(xday); + System.out.println(getFirstDay("yyyy-MM-dd")); + System.out.println(getLastDay("yyyy-MM-dd"));*/ + + /*try { + Date startTime = DateUtil.COMMON.getTextDate("2015-06-03 00:00:00"); + Date endTime = DateUtil.COMMON_FULL.getTextDate("2015-06-03 23:59:59"); + System.out.println(isTimeBetween(new Date(),startTime,endTime)); + + List month = getPreNMonths("2015-06",11); + for(String s : month){ + System.out.println(s); + } + + String str = DateUtil.COMMON_FULL.getDateText(getPreNDayEnd(new Date(),1)); + System.out.println(str); + + List days = getBetweenDateStr("2015-03-09","2015-06-15","MM/dd"); + for(String s : days){ + System.out.println(s); + } + + } catch (ParseException e) { + e.printStackTrace(); + }*/ + Calendar calendar = Calendar.getInstance(); + int year = calendar.get(Calendar.YEAR); + int month = calendar.get(Calendar.MONTH); + + Map oneMap = CalendarUtil.getMonthFirstEndDayTime(Integer.toString(year),Integer.toString(month-11));//当前月第一天的00:00:00 + Map oneEndMap = CalendarUtil.getMonthFirstEndDayTime(Integer.toString(year),Integer.toString(month));//当前月最后一天的23:59:59 + System.out.println(oneMap.get(CalendarUtil.MONTH_FIRST_DAY_TIME)); + System.out.println(oneEndMap.get(CalendarUtil.MONTH_LAST_DAY_TIME)); + } + +} + diff --git a/src/main/java/com.krt.dairy.common.util/CommonUtil.java b/src/main/java/com.krt.dairy.common.util/CommonUtil.java new file mode 100644 index 0000000..31a5b6f --- /dev/null +++ b/src/main/java/com.krt.dairy.common.util/CommonUtil.java @@ -0,0 +1,50 @@ +package com.krt.dairy.common.util; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.List; +import java.util.UUID; + +public class CommonUtil { + + public static String getUID(){ + return UUID.randomUUID().toString().replace("-", ""); + } + + public static String stringCap(String str){ + return str.substring(0,1).toLowerCase() + str.substring(1); + } + + public static byte[][] toArray(List list){ + byte[][] bytes = new byte[list.size()][]; + for(int i = 0; i < list.size() ;i++){ + bytes[i] = list.get(i); + } + return bytes; + } + + public static byte[] getFileBytes(File file) { + byte[] ret = null; + try { + if (file == null) { + return null; + } + FileInputStream in = new FileInputStream(file); + ByteArrayOutputStream out = new ByteArrayOutputStream(4096); + byte[] b = new byte[4096]; + int n; + while ((n = in.read(b)) != -1) { + out.write(b, 0, n); + } + in.close(); + out.close(); + ret = out.toByteArray(); + } catch (IOException e) { + e.printStackTrace(); + } + return ret; + } + +} diff --git a/src/main/java/com.krt.dairy.common.util/CookieUtil.java b/src/main/java/com.krt.dairy.common.util/CookieUtil.java new file mode 100644 index 0000000..65e4476 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.util/CookieUtil.java @@ -0,0 +1,46 @@ +package com.krt.dairy.common.util; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class CookieUtil { + + public static final String WEIXIN_OPENID = "_weixin_openid_"; + + public static Cookie addCookie(HttpServletResponse response,String cookieName,String value,Integer maxAge,String domain) { + return addCookie(response, cookieName, value, maxAge, domain, "/"); + } + + public static Cookie addCookie(HttpServletResponse response,String cookieName,String value,Integer maxAge,String domain,String path) { + Cookie cookie = new Cookie(cookieName,value); + cookie.setMaxAge(maxAge); + cookie.setDomain(domain); + cookie.setPath(path); + response.addCookie(cookie); + return cookie; + } + + // 获取 cookie + public static String getCookie(HttpServletRequest request, String cookieName) { + Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (Cookie cookie : cookies) { + if (cookieName.equalsIgnoreCase(cookie.getName())) { + return cookie.getValue(); + } + } + } + return null; + } + + // 删除 cookie + public static void delCookie(HttpServletResponse response, String cookieName) { + Cookie cookie = new Cookie(cookieName,null); + cookie.setMaxAge(0); + cookie.setPath("/"); + response.addCookie(cookie); + } + +} + diff --git a/src/main/java/com.krt.dairy.common.util/DateUtil.java b/src/main/java/com.krt.dairy.common.util/DateUtil.java new file mode 100644 index 0000000..635faf8 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.util/DateUtil.java @@ -0,0 +1,109 @@ +package com.krt.dairy.common.util; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +/** + * 日期工具类 + */ + +public class DateUtil { + + private final SimpleDateFormat format; + + public DateUtil(SimpleDateFormat format) { + this.format = format; + } + + public SimpleDateFormat getFormat() { + return format; + } + + // 紧凑型日期格式,也就是纯数字类型yyyyMMdd + public static final DateUtil COMPAT = new DateUtil(new SimpleDateFormat("yyyyMMdd")); + + // 紧凑型日期格式,也就是纯数字类型yyyyMMdd + public static final DateUtil COMPAT_FULL = new DateUtil(new SimpleDateFormat("yyyyMMddHHmmss")); + + // 常用日期格式,yyyy-MM-dd + public static final DateUtil COMMON = new DateUtil(new SimpleDateFormat("yyyy-MM-dd")); + public static final DateUtil COMMON_FULL = new DateUtil(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); + + // 使用斜线分隔的,西方多采用,yyyy/MM/dd + public static final DateUtil SLASH = new DateUtil(new SimpleDateFormat("yyyy/MM/dd")); + + // 中文日期格式常用,yyyy年MM月dd日 + public static final DateUtil CHINESE = new DateUtil(new SimpleDateFormat("yyyy年MM月dd日")); + public static final DateUtil CHINESE_FULL = new DateUtil(new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒")); + + /** + * 日期获取字符串 + */ + public String getDateText(Date date) { + return getFormat().format(date); + } + + /** + * 字符串获取日期 + * @throws ParseException + */ + public Date getTextDate(String text) throws ParseException { + return getFormat().parse(text); + } + + /** + * 日期获取字符串 + */ + public static String getDateText(Date date, String format) { + return new SimpleDateFormat(format).format(date); + } + + /** + * 字符串获取日期 + * @throws ParseException + */ + public static Date getTextDate(String dateText, String format) throws ParseException { + return new SimpleDateFormat(format).parse(dateText); + } + + /** + * 根据日期,返回其星期数,周一为1,周日为7 + * @param date + * @return + */ + public static int getWeekDay(Date date) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + int w = calendar.get(Calendar.DAY_OF_WEEK); + int ret; + if (w == Calendar.SUNDAY) + ret = 7; + else + ret = w - 1; + return ret; + } + + public static int getAge(Date birthday) { + Calendar calendar = Calendar.getInstance(); + if (calendar.before(birthday)) { + throw new IllegalArgumentException("出生时间大于当前时间!"); + } + int yearNow = calendar.get(Calendar.YEAR); + int monthNow = calendar.get(Calendar.MONTH) + 1;// 注意此处,如果不加1的话计算结果是错误的 + int dayOfMonthNow = calendar.get(Calendar.DAY_OF_MONTH); + calendar.setTime(birthday); + int yearBirth = calendar.get(Calendar.YEAR); + int monthBirth = calendar.get(Calendar.MONTH); + int dayOfMonthBirth = calendar.get(Calendar.DAY_OF_MONTH); + int age = yearNow - yearBirth; + if (monthNow < monthBirth ||(monthNow == monthBirth && dayOfMonthNow < dayOfMonthBirth)) { + age--; + } + return age; + + } + + +} diff --git a/src/main/java/com.krt.dairy.common.util/EncryptUtil.java b/src/main/java/com.krt.dairy.common.util/EncryptUtil.java new file mode 100644 index 0000000..56f6b42 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.util/EncryptUtil.java @@ -0,0 +1,108 @@ +package com.krt.dairy.common.util; + +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; + +/** + * 加解密工具类 + */ +public class EncryptUtil { + public static String encodedByMD5(String source) { + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] results = md.digest(source.getBytes()); + String result = bytesToHex(results); + return result.toUpperCase(); + } catch (NoSuchAlgorithmException e) { + throw new IllegalArgumentException(e); + } + } + + public static String bytesToHex(byte[] src) { + StringBuilder stringBuilder = new StringBuilder(); + if (src == null || src.length <= 0) + return null; + for (int i = 0; i < src.length; i++) { + int v = src[i] & 0xFF; + String hv = Integer.toHexString(v); + if (hv.length() < 2) { + stringBuilder.append(0); + } + stringBuilder.append(hv); + } + return stringBuilder.toString().toUpperCase(); + } + + public static String encryptSHA1(String content){ + try { + MessageDigest digest = MessageDigest + .getInstance("SHA-1"); + digest.update(content.getBytes()); + byte messageDigest[] = digest.digest(); + // Create Hex String + StringBuffer hexString = new StringBuffer(); + for (int i = 0; i < messageDigest.length; i++) { + String shaHex = Integer.toHexString(messageDigest[i] & 0xFF); + if (shaHex.length() < 2) { + hexString.append(0); + } + hexString.append(shaHex); + } + return hexString.toString(); + + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 使用AES的CBC模式加密 + * @param key 加密的秘钥 + * @param text 待加密的内容 + * @return 经过Base64编码的密文 + */ + public static String encryptByAESWithCBC(byte[] key,byte[] text){ + try { + Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); + SecretKeySpec keySpec = new SecretKeySpec(key, "AES"); + IvParameterSpec iv = new IvParameterSpec(key, 0, 16); + cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv); + byte[] encrypted = cipher.doFinal(text); + String base64Encrypted = new org.apache.commons.codec.binary.Base64().encodeToString(encrypted); + return base64Encrypted; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * + * @param key 经Base64编码的AES秘钥 + * @param text 经Base64编码的加密串 + * @return + */ + public static byte[] decryptByAESWithCBC(byte[] key,byte[] text){ + byte[] original=null; + try { + Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); + SecretKeySpec key_spec = new SecretKeySpec(key, "AES"); + IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(key, 0, 16)); + cipher.init(Cipher.DECRYPT_MODE, key_spec, iv); + original = cipher.doFinal(text); + } catch (Exception e) { + e.printStackTrace(); + } + return original; + } + + public static void main(String[] args){ + System.out.println(EncryptUtil.encodedByMD5("111111")); + } + +} diff --git a/src/main/java/com.krt.dairy.common.util/HttpUtil.java b/src/main/java/com.krt.dairy.common.util/HttpUtil.java new file mode 100644 index 0000000..141f5a6 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.util/HttpUtil.java @@ -0,0 +1,99 @@ +package com.krt.dairy.common.util; + +import org.apache.commons.lang.StringUtils; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * http工具类 + */ +public class HttpUtil extends org.springframework.web.util.WebUtils{ + + public static String getDomain(HttpServletRequest request){ + return request.getServerName(); + } + + public static String getHttpDomain(HttpServletRequest request){ + return request.getScheme() + "://" + request.getServerName(); + } + + public static String getContextHttpUri(HttpServletRequest request){ + return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); + } + + public static String getRealPath(HttpServletRequest request){ + return request.getSession().getServletContext().getRealPath("/"); + } + + public static String getRequestFullUri(HttpServletRequest request){ + String port = ""; + if(request.getServerPort() != 80){ + port = ":" + request.getServerPort(); + } + return request.getScheme() + "://" + request.getServerName() + port + request.getContextPath() + request.getServletPath(); + } + + public static String getRequestFullUriNoContextPath(HttpServletRequest request){ + String port = ""; + if(request.getServerPort() != 80){ + port = ":" + request.getServerPort(); + } + return request.getScheme() + "://" + request.getServerName() + port + request.getServletPath(); + } + + //获取ip地址; + public static String getIpAddr(HttpServletRequest request) { + String ip = request.getHeader("X-Forwarded-For"); + if (StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)) { + if(ip.indexOf("::ffff:")!=-1) ip = ip.replace("::ffff:", ""); + int index = ip.indexOf(","); + if (index != -1) { + return ip.substring(0, index); + } else { + return ip; + } + } + ip = request.getHeader("X-Real-IP"); + if (StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)) { + return ip; + } + return request.getRemoteAddr(); + } + + //判断当前请求是否为Ajax + public static boolean isAjaxRequest(HttpServletRequest request) { + String header = request.getHeader("X-Requested-With"); + return !StringUtils.isEmpty(header) && "XMLHttpRequest".equals(header); + } + + /** + * 重定向 + * @param httpServletRequest + * @param httpServletResponse + * @param url + */ + public static void redirectUrl(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String url){ + try { + httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + url); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * 重定向到http://的url + * @param httpServletRequest + * @param httpServletResponse + * @param url + */ + public static void redirectHttpUrl(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String url){ + try { + httpServletResponse.sendRedirect(url); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/com.krt.dairy.common.util/JsonUtil.java b/src/main/java/com.krt.dairy.common.util/JsonUtil.java new file mode 100644 index 0000000..fcbca11 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.util/JsonUtil.java @@ -0,0 +1,18 @@ +package com.krt.dairy.common.util; + + +import org.codehaus.jackson.map.ObjectMapper; + +import java.io.IOException; + +public class JsonUtil { + + private static ObjectMapper mapper; + static{ + mapper=new ObjectMapper(); + } + public static String toJson(Object obj) throws IOException { + String json = mapper.writeValueAsString(obj); + return json; + } +} diff --git a/src/main/java/com.krt.dairy.common.util/NumberUtil.java b/src/main/java/com.krt.dairy.common.util/NumberUtil.java new file mode 100644 index 0000000..748e4a1 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.util/NumberUtil.java @@ -0,0 +1,36 @@ +package com.krt.dairy.common.util; + +import java.util.Date; +import java.util.Random; + +public class NumberUtil { + + /** + * 生成编号 + * @param number 生成的编号位数 + * @return 返回生成的随机数 + */ + public static long randomNo(int number){ + double rate1 = Math.pow(10,number-1); + double rate2 = rate1*9; + long rate3 = (long)rate1*10; + Random random = new Random(); + double tmp= random.nextDouble()*rate2+rate1; + long no = Math.round(tmp)%rate3; + return no; + } + + private static int seq = 0;//序列 + private static final int LIMIT = 100000;//上限 + private static Date date = new Date(); + //根据时间生成唯一编码(考虑并发) + public static synchronized long timeUinqueNumber(){ + if (seq > LIMIT) seq = 0; + date.setTime(System.currentTimeMillis()); + String str = String.format("%1$tY%1$tm%1$td%1$tk%1$tM%1$tS%2$05d", date, seq++); + return Long.parseLong(str); + } + +} + + diff --git a/src/main/java/com.krt.dairy.common.util/PropertiesUtil.java b/src/main/java/com.krt.dairy.common.util/PropertiesUtil.java new file mode 100644 index 0000000..45c9bc2 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.util/PropertiesUtil.java @@ -0,0 +1,86 @@ +package com.krt.dairy.common.util; + +import java.io.*; +import java.net.URI; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +public class PropertiesUtil { + + private static Map propMap = new HashMap(); + + /*设置默认的properties文件,方便操作*/ + public static final String DEFAULT_PROPERTIES_FILE="application.properties"; + + public static Object getProperty(String file,String key){ + Properties prop = getProperties(file); + if(prop != null && prop.get(key) != null){ + return prop.get(key); + } + return null; + } + + public static Properties getProperties(String file){ + try { + if(propMap.get(file) == null){ + Properties prop = new Properties(); + prop.load(PropertiesUtil.class.getClassLoader().getResourceAsStream(file)); + propMap.put(file,prop); + return prop; + }else{ + return propMap.get(file); + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public static void updateProperties(Properties prop,String filePath){ + + FileInputStream fis = null; + BufferedInputStream bis = null; + try { + URI fileUri = PropertiesUtil.class.getClassLoader().getResource(filePath).toURI(); + File file = new File(fileUri); + + Properties tmpProp = new Properties(); + fis = new FileInputStream(file); + bis = new BufferedInputStream(fis); + tmpProp.load(bis); + + FileOutputStream fos = new FileOutputStream(file); + for(Object key : prop.keySet()){ + tmpProp.setProperty(String.valueOf(key),String.valueOf(prop.get(key))); + } + tmpProp.store(fos, null); + fis.close(); + fos.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 从默认配置文件中获取properties + * @return + */ + public static Properties getDefaultProperties(){ + return getProperties(DEFAULT_PROPERTIES_FILE); + } + + /** + * 从默认配置文件中获取配置项 + * @param key + * @return + */ + public static String getProperty(String key){ + Properties prop = getDefaultProperties(); + if(prop != null && prop.get(key) != null){ + return prop.getProperty(key); + } + return null; + } + +} diff --git a/src/main/java/com.krt.dairy.common.util/SecurityUtil.java b/src/main/java/com.krt.dairy.common.util/SecurityUtil.java new file mode 100644 index 0000000..b5d10d5 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.util/SecurityUtil.java @@ -0,0 +1,73 @@ +package com.krt.dairy.common.util; + +import java.util.Random; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class SecurityUtil { + + public static String htmlEncode(String source) { + if (source == null) { + return ""; + } + String html = ""; + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < source.length(); i++) { + char c = source.charAt(i); + switch (c) { + case '<': + buffer.append("<"); + break; + case '>': + buffer.append(">"); + break; + case '&': + buffer.append("&"); + break; + case '"': + buffer.append("""); + break; + case 10: + case 13: + break; + default: + buffer.append(c); + } + } + html = buffer.toString(); + return html; + } + + public static String filterHtml(String source) { + Pattern pattern = Pattern.compile("<([^>]*)>"); + Matcher matcher = pattern.matcher(source); + StringBuffer sb = new StringBuffer(); + boolean result1 = matcher.find(); + while (result1) { + matcher.appendReplacement(sb, ""); + result1 = matcher.find(); + } + matcher.appendTail(sb); + return sb.toString(); + } + + /** + * 获取一定长度的随机字符串 + * @param length 指定字符串长度 + * @return 一定长度的字符串 + */ + public static String getRandomString(int length) { + String base = "abcdefghijklmnopqrstuvwxyz0123456789"; + Random random = new Random(); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < length; i++) { + int number = random.nextInt(base.length()); + sb.append(base.charAt(number)); + } + return sb.toString(); + } + + public static void main(String[] args) { + System.out.println(filterHtml("百度")); +} +} diff --git a/src/main/java/com.krt.dairy.common.web.auth/SessionUser.java b/src/main/java/com.krt.dairy.common.web.auth/SessionUser.java new file mode 100644 index 0000000..eb9b2e3 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.web.auth/SessionUser.java @@ -0,0 +1,17 @@ +package com.krt.dairy.common.web.auth; + +import java.util.Set; + + +/** + * 权限用户 + */ +public interface SessionUser { + + String getUsername(); + + Long getUserId(); + + Set getPermissions(); + +} diff --git a/src/main/java/com.krt.dairy.common.web.auth/UserRole.java b/src/main/java/com.krt.dairy.common.web.auth/UserRole.java new file mode 100644 index 0000000..0734cf9 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.web.auth/UserRole.java @@ -0,0 +1,15 @@ +package com.krt.dairy.common.web.auth; + +import java.io.Serializable; + +/** + * 权限角色 + * @author Brain + */ +public class UserRole implements Serializable{ + + private static final long serialVersionUID = 406004317093554289L; + + + +} diff --git a/src/main/java/com.krt.dairy.common.web/DisableUrlSessionFilter.java b/src/main/java/com.krt.dairy.common.web/DisableUrlSessionFilter.java new file mode 100644 index 0000000..30bc32d --- /dev/null +++ b/src/main/java/com.krt.dairy.common.web/DisableUrlSessionFilter.java @@ -0,0 +1,53 @@ +package com.krt.dairy.common.web; + +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponseWrapper; +import javax.servlet.http.HttpSession; +import java.io.IOException; + +public class DisableUrlSessionFilter implements Filter { + + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + if (!(request instanceof HttpServletRequest)) { + chain.doFilter(request, response); + return; + } + HttpServletRequest httpRequest = (HttpServletRequest) request; + HttpServletResponse httpResponse = (HttpServletResponse) response; + + if (httpRequest.isRequestedSessionIdFromURL()) { + HttpSession session = httpRequest.getSession(); + if (session != null) + session.invalidate(); + } + + // wrap response to remove URL encoding + HttpServletResponseWrapper wrappedResponse = new HttpServletResponseWrapper(httpResponse) { + @Override + public String encodeRedirectUrl(String url) { + return url; + } + + public String encodeRedirectURL(String url) { + return url; + } + + public String encodeUrl(String url) { + return url; + } + + public String encodeURL(String url) { + return url; + } + }; + chain.doFilter(request, wrappedResponse); + } + + public void init(FilterConfig config) throws ServletException { + } + + public void destroy() { + } +} \ No newline at end of file diff --git a/src/main/java/com.krt.dairy.common.web/HttpHelper.java b/src/main/java/com.krt.dairy.common.web/HttpHelper.java new file mode 100644 index 0000000..40af3c4 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.web/HttpHelper.java @@ -0,0 +1,102 @@ +package com.krt.dairy.common.web; + +import org.apache.commons.lang.StringUtils; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * http工具类 + */ +public class HttpHelper extends org.springframework.web.util.WebUtils{ + + public static String getDomain(HttpServletRequest request){ + return request.getServerName(); + } + + public static String getHttpDomain(HttpServletRequest request){ + return request.getScheme() + "://" + request.getServerName(); + } + + public static String getContextHttpUri(HttpServletRequest request){ + return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); + } + + public static String getRealPath(HttpServletRequest request){ + return request.getSession().getServletContext().getRealPath("/"); + } + + public static String getRequestFullUri(HttpServletRequest request){ + String port = ""; + if(request.getServerPort() != 80){ + port = ":" + request.getServerPort(); + } + return request.getScheme() + "://" + request.getServerName() + port + request.getContextPath() + request.getServletPath(); + } + + public static String getRequestFullUriNoContextPath(HttpServletRequest request){ + String port = ""; + if(request.getServerPort() != 80){ + port = ":" + request.getServerPort(); + } + return request.getScheme() + "://" + request.getServerName() + port + request.getServletPath(); + } + + //获取ip地址; + public static String getIpAddr(HttpServletRequest request) { + String ip = request.getHeader("X-Forwarded-For"); + if (StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)) { + if(ip.indexOf("::ffff:")!=-1) ip = ip.replace("::ffff:", ""); + int index = ip.indexOf(","); + if (index != -1) { + return ip.substring(0, index); + } else { + return ip; + } + } + ip = request.getHeader("X-Real-IP"); + if (StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)) { + return ip; + } + return request.getRemoteAddr(); + } + + //判断当前请求是否为Ajax + public static boolean isAjaxRequest(HttpServletRequest request) { + String header = request.getHeader("X-Requested-With"); + return !StringUtils.isEmpty(header) && "XMLHttpRequest".equals(header); + } + + /** + * 重定向 + * @param httpServletRequest + * @param httpServletResponse + * @param url + */ + public static void redirectUrl(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String url){ + try { + httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + url); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * 重定向到http://的url + * @param httpServletRequest + * @param httpServletResponse + * @param url + */ + public static void redirectHttpUrl(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String url){ + try { + httpServletResponse.sendRedirect(url); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} + + + diff --git a/src/main/java/com.krt.dairy.common.web/JsonView.java b/src/main/java/com.krt.dairy.common.web/JsonView.java new file mode 100644 index 0000000..7664497 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.web/JsonView.java @@ -0,0 +1,82 @@ +package com.krt.dairy.common.web; + +import net.sf.json.JSONObject; + +public class JsonView { + + //错误代码 0-成功 + private Integer errcode = 0; + + // 消息 + private String message; + + // 数据 + private Object data; + + public static String render(Object data){ + JsonView tmp = new JsonView(0, "success",data); + return JSONObject.fromObject(tmp).toString(); + } + + public static String render(Integer errcode){ + JsonView tmp = new JsonView(errcode, ""); + return JSONObject.fromObject(tmp).toString(); + } + + public static String render(Integer errcode, String message){ + JsonView tmp = new JsonView(errcode, message); + return JSONObject.fromObject(tmp).toString(); + } + + public static String render(Integer errcode, String message, Object data){ + JsonView tmp = new JsonView(errcode, message, data); + return JSONObject.fromObject(tmp).toString(); + } + + public JsonView(Integer errcode, String message, Object data) { + this.errcode = errcode; + this.message = message; + this.data = data; + } + + public JsonView(Integer errcode, String message) { + this.errcode = errcode; + this.message = message; + } + + public JsonView(Integer errcode) { + this.errcode = errcode; + } + + public JsonView() { + } + + public Integer getErrcode() { + return errcode; + } + + public void setErrcode(Integer errcode) { + this.errcode = errcode; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + + public String toString(){ + return JSONObject.fromObject(this).toString(); + } + +} diff --git a/src/main/java/com.krt.dairy.common.web/SessionContext.java b/src/main/java/com.krt.dairy.common.web/SessionContext.java new file mode 100644 index 0000000..1b4f1bf --- /dev/null +++ b/src/main/java/com.krt.dairy.common.web/SessionContext.java @@ -0,0 +1,106 @@ +package com.krt.dairy.common.web; + +import com.krt.dairy.common.web.auth.SessionUser; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authc.AuthenticationException; +import org.apache.shiro.subject.Subject; + +import javax.servlet.http.HttpServletRequest; + +/** + * session工具类 + */ +public class SessionContext { + public static final String IDENTIFY_CODE_KEY = "_consts_identify_code_key_";// 其他人不得占用 + public static final String AUTH_USER_KEY = "_consts_auth_user_key_";// 其他人不得占用 + + public static Long getUserId(){ + if(null != getAuthUser()){ + return getAuthUser().getUserId(); + } + return null; + } + + public static String getUsername(){ + if(null != getAuthUser()){ + return getAuthUser().getUsername(); + } + return null; + } + + public static Long getWxUserId(HttpServletRequest request){ + if(null != getWxAuthUser(request)) + return getWxAuthUser(request).getUserId(); + return null; + } + + public static String getWxUsername(HttpServletRequest request){ + if(null != getWxAuthUser(request)) + return getWxAuthUser(request).getUsername(); + return null; + } + + public static boolean isWxLogin(HttpServletRequest request){ + return null != getWxAuthUser(request); + } + + // 如果是微信登录获取当前用户 + public static SessionUser getWxAuthUser(HttpServletRequest request){ + String sessionId = request.getSession().getId(); + Object obj = SessionContext.getAttribute(request, sessionId); + if(null != obj){ + return (SessionUser)obj; + } + return null; + } + + // 获取当前登录用户 + public static SessionUser getAuthUser() { + if(null != SecurityUtils.getSubject().getPrincipal()){ + return (SessionUser) SecurityUtils.getSubject().getPrincipal(); + } + return null; + } + + // 获取验证码 + public static String getIdentifyCode(HttpServletRequest request) { + if (request.getSession().getAttribute(IDENTIFY_CODE_KEY) != null) { + return getAttribute(request, IDENTIFY_CODE_KEY).toString(); + } else { + return null; + } + } + + // 获取属性 + public static Object getAttribute(HttpServletRequest request, String key) { + return request.getSession().getAttribute(key); + } + + // 设置属性 + public static void setAttribute(HttpServletRequest request, String key, Object value) { + request.getSession().setAttribute(key, value); + } + + // 删除属性 + public static void removeAttribute(HttpServletRequest request, String key) { + request.getSession().removeAttribute(key); + } + + public static boolean isLogin(){ + Subject currentUser = SecurityUtils.getSubject(); + if(null != currentUser && null != currentUser.getPrincipal()){ + return true; + } + return false; + } + + //shiro logout + public static void shiroLogout(){ + Subject currentUser = SecurityUtils.getSubject(); + try { + currentUser.logout(); + } catch (AuthenticationException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com.krt.dairy.common.web/SessionTimeObj.java b/src/main/java/com.krt.dairy.common.web/SessionTimeObj.java new file mode 100644 index 0000000..29b4c1a --- /dev/null +++ b/src/main/java/com.krt.dairy.common.web/SessionTimeObj.java @@ -0,0 +1,39 @@ +package com.krt.dairy.common.web; + + +/** + * Session中setAttribute的对象,加入了超时属性 + * 时间从创建对象开始; + * @author Brain + */ +public class SessionTimeObj { + + private Object value;//值对象 + private Long overtime;//超时时间,毫秒 + private long currentTime;//加入value时的当前时间 + + public SessionTimeObj(Object value,Long overtime){ + this.value = value; + this.overtime = overtime; + currentTime = System.currentTimeMillis(); + } + + public Object getValue() { + return value; + } + public void setValue(Object value) { + this.value = value; + } + public Long getOvertime() { + return overtime; + } + public void setOvertime(Long overtime) { + this.overtime = overtime; + } + + //超时返回true + public boolean isOvertime(){ + return System.currentTimeMillis() - currentTime > overtime; + } + +} diff --git a/src/main/java/com.krt.dairy.common.web/SpringBeanFactory.java b/src/main/java/com.krt.dairy.common.web/SpringBeanFactory.java new file mode 100644 index 0000000..3ebdfef --- /dev/null +++ b/src/main/java/com.krt.dairy.common.web/SpringBeanFactory.java @@ -0,0 +1,18 @@ +package com.krt.dairy.common.web; + +import org.springframework.mock.web.MockServletContext; +import org.springframework.web.context.support.XmlWebApplicationContext; + +public class SpringBeanFactory { + public static Object getBean(String[] paths, String name){ + XmlWebApplicationContext ctx = new XmlWebApplicationContext(); + ctx.setConfigLocations(paths); + ctx.setServletContext(new MockServletContext("")); + ctx.refresh(); + return ctx.getBean(name); + } + public static Object getBean(String name){ + String[] paths = { "applicationContext.xml" }; + return getBean(paths,name); + } +} diff --git a/src/main/java/com.krt.dairy.common.web/UTF8HttpMessageConverter.java b/src/main/java/com.krt.dairy.common.web/UTF8HttpMessageConverter.java new file mode 100644 index 0000000..35baeb0 --- /dev/null +++ b/src/main/java/com.krt.dairy.common.web/UTF8HttpMessageConverter.java @@ -0,0 +1,79 @@ +package com.krt.dairy.common.web; + +import org.springframework.http.HttpInputMessage; +import org.springframework.http.HttpOutputMessage; +import org.springframework.http.MediaType; +import org.springframework.http.converter.AbstractHttpMessageConverter; +import org.springframework.util.StreamUtils; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.List; + +/** + * 用于springmvc + * @ResponseBody 转码 + */ +public class UTF8HttpMessageConverter extends AbstractHttpMessageConverter { + + public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); + private final Charset defaultCharset; + private final List availableCharsets; + private boolean writeAcceptCharset; + + public UTF8HttpMessageConverter() { + this(DEFAULT_CHARSET); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public UTF8HttpMessageConverter(Charset defaultCharset) { + super(new MediaType[] { new MediaType("text", "plain", defaultCharset),MediaType.ALL }); + this.writeAcceptCharset = true; + this.defaultCharset = defaultCharset; + this.availableCharsets = new ArrayList(Charset.availableCharsets().values()); + } + + public void setWriteAcceptCharset(boolean writeAcceptCharset) { + this.writeAcceptCharset = writeAcceptCharset; + } + + public boolean supports(Class clazz) { + return String.class.equals(clazz); + } + + protected String readInternal(Class clazz,HttpInputMessage inputMessage) throws IOException { + Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType()); + return StreamUtils.copyToString(inputMessage.getBody(), charset); + } + + protected Long getContentLength(String s, MediaType contentType) { + Charset charset = getContentTypeCharset(contentType); + try { + return Long.valueOf(s.getBytes(charset.name()).length); + } catch (UnsupportedEncodingException ex) { + throw new IllegalStateException(ex); + } + } + + protected void writeInternal(String s, HttpOutputMessage outputMessage)throws IOException { + if (this.writeAcceptCharset) { + outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets()); + } + Charset charset = getContentTypeCharset(outputMessage.getHeaders().getContentType()); + StreamUtils.copy(s, charset, outputMessage.getBody()); + } + + protected List getAcceptedCharsets() { + return this.availableCharsets; + } + + private Charset getContentTypeCharset(MediaType contentType) { + if ((contentType != null) && (contentType.getCharSet() != null)) { + return contentType.getCharSet(); + } + return this.defaultCharset; + } + +} diff --git a/src/main/java/com/krt/dairy/common/orm/BaseEntity.java b/src/main/java/com/krt/dairy/common/orm/BaseEntity.java new file mode 100644 index 0000000..4703fd2 --- /dev/null +++ b/src/main/java/com/krt/dairy/common/orm/BaseEntity.java @@ -0,0 +1,65 @@ +package com.krt.dairy.common.orm; + +import java.util.Date; + +public class BaseEntity extends LongModel{ + private static final long serialVersionUID = 968132587307913395L; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 创建人(username) + */ + private String createUser; + + /** + * 更新时间 + */ + private Date updateTime; + + /** + * 最后一位更新人(username) + */ + private String updateUser; + + /** + * 逻辑删除 + */ + private Integer del = 0; + + public Date getCreateTime() { + return createTime; + } + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + public Integer getDel() { + return del; + } + public void setDel(Integer del) { + this.del = del; + } + public String getCreateUser() { + return createUser; + } + public void setCreateUser(String createUser) { + this.createUser = createUser; + } + public Date getUpdateTime() { + return updateTime; + } + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + public String getUpdateUser() { + return updateUser; + } + public void setUpdateUser(String updateUser) { + this.updateUser = updateUser; + } + +} + diff --git a/src/main/java/com/krt/dairy/common/orm/Identifier.java b/src/main/java/com/krt/dairy/common/orm/Identifier.java new file mode 100644 index 0000000..e8ed348 --- /dev/null +++ b/src/main/java/com/krt/dairy/common/orm/Identifier.java @@ -0,0 +1,12 @@ +package com.krt.dairy.common.orm; + +import java.io.Serializable; + +/** + * @param + */ +public interface Identifier { + + public KEY getId(); + +} diff --git a/src/main/java/com/krt/dairy/common/orm/LongModel.java b/src/main/java/com/krt/dairy/common/orm/LongModel.java new file mode 100644 index 0000000..505eaae --- /dev/null +++ b/src/main/java/com/krt/dairy/common/orm/LongModel.java @@ -0,0 +1,19 @@ +package com.krt.dairy.common.orm; + +import java.io.Serializable; + +public class LongModel implements Identifier ,Serializable{ + private static final long serialVersionUID = 7978917143723588623L; + + private Long id; + + public void setId(Long id) { + this.id = id; + } + + @Override + public Long getId() { + return id; + } + +} diff --git a/src/main/java/com/krt/dairy/common/orm/MyBatisJdbcHelper.java b/src/main/java/com/krt/dairy/common/orm/MyBatisJdbcHelper.java new file mode 100644 index 0000000..8efa094 --- /dev/null +++ b/src/main/java/com/krt/dairy/common/orm/MyBatisJdbcHelper.java @@ -0,0 +1,193 @@ +package com.krt.dairy.common.orm; + +import com.krt.dairy.common.util.BeanUtil; +import org.apache.commons.lang.StringUtils; + +import java.util.HashMap; +import java.util.Map; + +/** + * 为mybatis准备动态sql + */ +public class MyBatisJdbcHelper { + + public static String getByIdSql(Class entityClass,String... fieldNames){ + String sql = MyBatisJdbcHelper.querySql(entityClass,null,fieldNames); + sql += " WHERE ID = #{param2} "; + return sql; + } + + public static String querySql(Class entityClass, QueryFilter filter, String... fieldNames){ + StringBuilder sql = new StringBuilder("SELECT "); + String tableName = BeanUtil.getTableName(entityClass).toUpperCase(); + if(fieldNames != null && fieldNames.length > 0){ + String columnSql = ""; + for(String name : fieldNames){ + String column = BeanUtil.fieldToColumn(name); + columnSql += " " + column.toUpperCase() + ","; + } + sql.append(columnSql.substring(0, columnSql.length() - 1)); + }else{ + sql.append(" * "); + } + sql.append(" FROM " + tableName ); + + if(filter != null){ + if(!StringUtils.isEmpty(filter.getWhere())){ + sql.append(" WHERE " + filter.getWhere() ); + } + if(!StringUtils.isEmpty(filter.getSort())){ + sql.append(" ORDER BY " + filter.getSort() ); + } + } + + return sql.toString(); + } + + public static String queryByIdsSql(Class entityClass, E[] ids, String... fieldNames){ + StringBuilder where = new StringBuilder(); + for(E e : ids){ + where.append(e + ","); + } + String sql = querySql(entityClass, null, fieldNames); + return sql + " WHERE ID IN (" + where.toString().substring(0, where.length() - 1) +")"; + } + + public static String countSql(Class entityClass, QueryFilter filter){ + String tableName = BeanUtil.getTableName(entityClass).toUpperCase(); + StringBuilder sql = new StringBuilder("SELECT COUNT(1) FROM " + tableName); + if(filter != null){ + if(!StringUtils.isEmpty(filter.getWhere())){ + sql.append(" WHERE " + filter.getWhere() ); + } + } + return sql.toString(); + } + + public static String createSql(Class entityClass){ + Map map = BeanUtil.getAllFieldColumns(entityClass); + String tableName = BeanUtil.getTableName(entityClass).toUpperCase(); + StringBuilder sb = new StringBuilder("INSERT INTO " + tableName ); + Object[] filedNames = map.keySet().toArray(); + Object[] colNames = map.values().toArray(); + sb.append(" ( " + join(colNames).toUpperCase() + " )"); + sb.append(" VALUES "); + sb.append(" ( " + join2(filedNames) + " ) "); + return sb.toString(); + } + + public static Map createAllSqlMap(Class entityClass){ + Map map = BeanUtil.getAllFieldColumns(entityClass); + String tableName = BeanUtil.getTableName(entityClass).toUpperCase(); + StringBuilder sql1 = new StringBuilder("INSERT INTO " + tableName ); + Object[] filedNames = map.keySet().toArray(); + Object[] colNames = map.values().toArray(); + sql1.append(" ( " + join(colNames).toUpperCase() + " )"); + sql1.append(" VALUES "); + String sql2 = " ( " + join3(filedNames) + " ) "; + Map rstMap = new HashMap(); + rstMap.put("sql1", sql1.toString()); + rstMap.put("sql2", sql2); + return rstMap; + } + + public static String updateSql(Class entityClass,boolean byId, QueryFilter filter, String... fieldNames){ + Map map = BeanUtil.getAllFieldColumns(entityClass); + String tableName = BeanUtil.getTableName(entityClass).toUpperCase(); + StringBuilder sql = new StringBuilder("UPDATE " + tableName + " SET "); + if(fieldNames != null && fieldNames.length > 0){ + for(String name : fieldNames){ + String column = BeanUtil.fieldToColumn(name); + sql.append(" " + column.toUpperCase() + " = #{param2." + name + "},"); + } + }else{ + for (String s : map.keySet()) { + if (!"id".equals(s) && !"createUser".equals(s) && !"createTime".equals(s) && !"del".equals(s)) { + sql.append(" " + map.get(s).toString().toUpperCase() + " = #{param2." + s + "},"); + } + } + } + String updateSql = sql.toString().substring(0, sql.length() - 1); + if(byId){//根据ID更新对象 + updateSql += " WHERE ID = #{param2.id} "; + }else{//更新所有,或者根据条件更新对象 + if(filter != null){ + if(!StringUtils.isEmpty(filter.getWhere())){ + updateSql += " WHERE " + filter.getWhere(); + } + } + } + return updateSql; + } + + public static String deleteSql(Class entityClass,boolean byId, QueryFilter filter){ + String tableName = BeanUtil.getTableName(entityClass).toUpperCase(); + StringBuilder sql = new StringBuilder("DELETE FROM " + tableName); + if(byId){//根据ID更新对象 + sql.append(" WHERE ID = #{param2.id} "); + }else{//更新所有,或者根据条件更新对象 + if(filter != null){ + if(!StringUtils.isEmpty(filter.getWhere())){ + sql.append(" WHERE " + filter.getWhere()); + } + } + } + return sql.toString(); + } + + public static String deleteByIdSql(Class entityClass){ + String tableName = BeanUtil.getTableName(entityClass).toUpperCase(); + StringBuilder sql = new StringBuilder("DELETE FROM " + tableName); + sql.append(" WHERE ID = #{param2} "); + return sql.toString(); + } + + public static String deleteByIdSqls(Class entityClass){ + String tableName = BeanUtil.getTableName(entityClass).toUpperCase(); + StringBuilder sql = new StringBuilder("DELETE FROM " + tableName + " WHERE ID IN "); + return sql.toString(); + } + + public static String deleteByFilterSql(Class entityClass,QueryFilter filter){ + String tableName = BeanUtil.getTableName(entityClass).toUpperCase(); + StringBuilder sql = new StringBuilder("DELETE FROM " + tableName); + if(filter != null){ + if(!StringUtils.isEmpty(filter.getWhere())){ + sql.append(" WHERE " + filter.getWhere()); + } + } + return sql.toString(); + } + + + + + + private static String join(Object[] arr) { + StringBuilder sb = new StringBuilder(); + for (Object s : arr) { + sb.append(s + ","); + } + String str = sb.toString(); + return str.substring(0, str.length() - 1); + } + + public static String join2(Object[] arr) { + StringBuilder sb = new StringBuilder(); + for (Object s : arr) { + sb.append("#{param2." + s + "},"); + } + String str = sb.toString(); + return str.substring(0, str.length() - 1); + } + public static String join3(Object[] arr) { + StringBuilder sb = new StringBuilder(); + for (Object s : arr) { + sb.append("#{item." + s + "},"); + } + String str = sb.toString(); + return str.substring(0, str.length() - 1); + } + +} + diff --git a/src/main/java/com/krt/dairy/common/orm/QueryFilter.java b/src/main/java/com/krt/dairy/common/orm/QueryFilter.java new file mode 100644 index 0000000..14e5fc9 --- /dev/null +++ b/src/main/java/com/krt/dairy/common/orm/QueryFilter.java @@ -0,0 +1,24 @@ +package com.krt.dairy.common.orm; + + +/** + * 简单查询,目前只支持简单的 = 和 <> 查询 + * 只支持3个简单查询 + * @author bc_qi + */ +public class QueryFilter { + + Integer timeCount = 0;//计数器 + private StringBuilder where = new StringBuilder("");//最多3个条件 + private StringBuilder sort = new StringBuilder(""); + + public String getWhere() { + return where.toString(); + } + + public String getSort(){ + return sort.toString(); + } + +} + diff --git a/src/main/java/com/krt/dairy/common/web/error/ErrorController.java b/src/main/java/com/krt/dairy/common/web/error/ErrorController.java new file mode 100644 index 0000000..d3ea19c --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/error/ErrorController.java @@ -0,0 +1,36 @@ +package com.krt.dairy.common.web.error; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +@Controller +@RequestMapping("/error") +public class ErrorController { + + @RequestMapping("/101") + public ModelAndView error101(){ + return new ModelAndView("error/101"); + } + + @RequestMapping("/403") + public ModelAndView error403(){ + return new ModelAndView("error/403"); + } + + @RequestMapping("/404") + public ModelAndView error404(){ + return new ModelAndView("error/404"); + } + + @RequestMapping("/500") + public ModelAndView error500(){ + return new ModelAndView("error/500"); + } + + @RequestMapping("/405") + public ModelAndView error405(){ + return new ModelAndView("error/405"); + } + +} diff --git a/src/main/java/com/krt/dairy/common/web/shiro/ShiroFreeMarkerConfigurer.java b/src/main/java/com/krt/dairy/common/web/shiro/ShiroFreeMarkerConfigurer.java new file mode 100644 index 0000000..67d2b9c --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/shiro/ShiroFreeMarkerConfigurer.java @@ -0,0 +1,18 @@ +package com.krt.dairy.common.web.shiro; + +import com.krt.dairy.common.web.shiro.freemarker.ShiroTags; +import freemarker.template.TemplateException; +import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; + +import java.io.IOException; + +/** + * shiro freemarker 整合 + */ +public class ShiroFreeMarkerConfigurer extends FreeMarkerConfigurer { + @Override + public void afterPropertiesSet() throws IOException, TemplateException { + super.afterPropertiesSet(); + this.getConfiguration().setSharedVariable("shiro", new ShiroTags()); + } +} diff --git a/src/main/java/com/krt/dairy/common/web/shiro/freemarker/AuthenticatedTag.java b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/AuthenticatedTag.java new file mode 100644 index 0000000..3fb7015 --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/AuthenticatedTag.java @@ -0,0 +1,44 @@ +package com.krt.dairy.common.web.shiro.freemarker; + +import freemarker.core.Environment; +import freemarker.log.Logger; +import freemarker.template.TemplateDirectiveBody; +import freemarker.template.TemplateException; + +import java.io.IOException; +import java.util.Map; + + +/** + * JSP tag that renders the tag body only if the current user has executed a successful authentication attempt + * during their current session. + * + *

This is more restrictive than the {@link UserTag}, which only + * ensures the current user is known to the system, either via a current login or from Remember Me services, + * which only makes the assumption that the current user is who they say they are, and does not guarantee it like + * this tag does. + * + *

The logically opposite tag of this one is the {@link NotAuthenticatedTag} + * + *

Equivalent to {@link org.apache.shiro.web.tags.AuthenticatedTag}

+ * + * @since 0.2 + */ +public class AuthenticatedTag extends SecureTag { + private static final Logger log = Logger.getLogger("AuthenticatedTag"); + + @Override + public void render(Environment env, Map params, TemplateDirectiveBody body) throws IOException, TemplateException { + if (getSubject() != null && getSubject().isAuthenticated()) { + if (log.isDebugEnabled()) { + log.debug("Subject exists and is authenticated. Tag body will be evaluated."); + } + + renderBody(env, body); + } else { + if (log.isDebugEnabled()) { + log.debug("Subject does not exist or is not authenticated. Tag body will not be evaluated."); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/com/krt/dairy/common/web/shiro/freemarker/GuestTag.java b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/GuestTag.java new file mode 100644 index 0000000..c48a6f4 --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/GuestTag.java @@ -0,0 +1,42 @@ +package com.krt.dairy.common.web.shiro.freemarker; + +import freemarker.core.Environment; +import freemarker.log.Logger; +import freemarker.template.TemplateDirectiveBody; +import freemarker.template.TemplateException; + +import java.io.IOException; +import java.util.Map; + + +/** + * JSP tag that renders the tag body if the current user is not known to the system, either because they + * haven't logged in yet, or because they have no 'RememberMe' identity. + * + *

The logically opposite tag of this one is the {@link UserTag}. Please read that class's JavaDoc as it explains + * more about the differences between Authenticated/Unauthenticated and User/Guest semantic differences. + * + *

Equivalent to {@link org.apache.shiro.web.tags.GuestTag}

+ * + * @since 0.9 + */ +public class GuestTag extends SecureTag { + private static final Logger log = Logger.getLogger("AuthenticatedTag"); + + @Override + public void render(Environment env, Map params, TemplateDirectiveBody body) throws IOException, TemplateException { + if (getSubject() == null || getSubject().getPrincipal() == null) { + if (log.isDebugEnabled()) { + log.debug("Subject does not exist or does not have a known identity (aka 'principal'). " + + "Tag body will be evaluated."); + } + + renderBody(env, body); + } else { + if (log.isDebugEnabled()) { + log.debug("Subject exists or has a known identity (aka 'principal'). " + + "Tag body will not be evaluated."); + } + } + } +} diff --git a/src/main/java/com/krt/dairy/common/web/shiro/freemarker/HasAnyRolesTag.java b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/HasAnyRolesTag.java new file mode 100644 index 0000000..0001d59 --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/HasAnyRolesTag.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.krt.dairy.common.web.shiro.freemarker; + +import org.apache.shiro.subject.Subject; + + +/** + * Displays body content if the current user has any of the roles specified. + * + *

Equivalent to {@link org.apache.shiro.web.tags.HasAnyRolesTag}

+ * + * @since 0.2 + */ +public class HasAnyRolesTag extends RoleTag { + // Delimeter that separates role names in tag attribute + private static final String ROLE_NAMES_DELIMETER = ","; + + protected boolean showTagBody(String roleNames) { + boolean hasAnyRole = false; + Subject subject = getSubject(); + + if (subject != null) { + // Iterate through roles and check to see if the user has one of the roles + for (String role : roleNames.split(ROLE_NAMES_DELIMETER)) { + if (subject.hasRole(role.trim())) { + hasAnyRole = true; + break; + } + } + } + + return hasAnyRole; + } +} \ No newline at end of file diff --git a/src/main/java/com/krt/dairy/common/web/shiro/freemarker/HasPermissionTag.java b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/HasPermissionTag.java new file mode 100644 index 0000000..cc15a86 --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/HasPermissionTag.java @@ -0,0 +1,12 @@ +package com.krt.dairy.common.web.shiro.freemarker; + +/** + *

Equivalent to {@link org.apache.shiro.web.tags.HasPermissionTag}

+ * + * @since 0.1 + */ +public class HasPermissionTag extends PermissionTag { + protected boolean showTagBody(String p) { + return isPermitted(p); + } +} diff --git a/src/main/java/com/krt/dairy/common/web/shiro/freemarker/HasRoleTag.java b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/HasRoleTag.java new file mode 100644 index 0000000..908300e --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/HasRoleTag.java @@ -0,0 +1,10 @@ +package com.krt.dairy.common.web.shiro.freemarker; + +/** + *

Equivalent to {@link org.apache.shiro.web.tags.HasRoleTag}

+ */ +public class HasRoleTag extends RoleTag { + protected boolean showTagBody(String roleName) { + return getSubject() != null && getSubject().hasRole(roleName); + } +} diff --git a/src/main/java/com/krt/dairy/common/web/shiro/freemarker/LacksPermissionTag.java b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/LacksPermissionTag.java new file mode 100644 index 0000000..99786a7 --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/LacksPermissionTag.java @@ -0,0 +1,10 @@ +package com.krt.dairy.common.web.shiro.freemarker; + +/** + *

Equivalent to {@link org.apache.shiro.web.tags.LacksPermissionTag}

+ */ +public class LacksPermissionTag extends PermissionTag { + protected boolean showTagBody(String p) { + return !isPermitted(p); + } +} diff --git a/src/main/java/com/krt/dairy/common/web/shiro/freemarker/LacksRoleTag.java b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/LacksRoleTag.java new file mode 100644 index 0000000..23e6802 --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/LacksRoleTag.java @@ -0,0 +1,11 @@ +package com.krt.dairy.common.web.shiro.freemarker; + +/** + *

Equivalent to {@link org.apache.shiro.web.tags.LacksRoleTag}

+ */ +public class LacksRoleTag extends RoleTag { + protected boolean showTagBody(String roleName) { + boolean hasRole = getSubject() != null && getSubject().hasRole(roleName); + return !hasRole; + } +} diff --git a/src/main/java/com/krt/dairy/common/web/shiro/freemarker/NotAuthenticatedTag.java b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/NotAuthenticatedTag.java new file mode 100644 index 0000000..2874e0c --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/NotAuthenticatedTag.java @@ -0,0 +1,32 @@ +package com.krt.dairy.common.web.shiro.freemarker; + +import freemarker.core.Environment; +import freemarker.log.Logger; +import freemarker.template.TemplateDirectiveBody; +import freemarker.template.TemplateException; + +import java.io.IOException; +import java.util.Map; + + +/** + * Freemarker tag that renders the tag body only if the current user has not executed a successful authentication + * attempt during their current session. + * + *

The logically opposite tag of this one is the {@link org.apache.shiro.web.tags.AuthenticatedTag}. + * + *

Equivalent to {@link org.apache.shiro.web.tags.NotAuthenticatedTag}

+ */ +public class NotAuthenticatedTag extends SecureTag { + static final Logger log = Logger.getLogger("NotAuthenticatedTag"); + + @Override + public void render(Environment env, Map params, TemplateDirectiveBody body) throws IOException, TemplateException { + if (getSubject() == null || !getSubject().isAuthenticated()) { + log.debug("Subject does not exist or is not authenticated. Tag body will be evaluated."); + renderBody(env, body); + } else { + log.debug("Subject exists and is authenticated. Tag body will not be evaluated."); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/krt/dairy/common/web/shiro/freemarker/PermissionTag.java b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/PermissionTag.java new file mode 100644 index 0000000..7d0cf06 --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/PermissionTag.java @@ -0,0 +1,43 @@ +package com.krt.dairy.common.web.shiro.freemarker; + +import freemarker.core.Environment; +import freemarker.template.TemplateDirectiveBody; +import freemarker.template.TemplateException; +import freemarker.template.TemplateModelException; + +import java.io.IOException; +import java.util.Map; + +/** + *

Equivalent to {@link org.apache.shiro.web.tags.PermissionTag}

+ */ +public abstract class PermissionTag extends SecureTag { + String getName(Map params) { + return getParam(params, "name"); + } + + @Override + protected void verifyParameters(Map params) throws TemplateModelException { + String permission = getName(params); + + if (permission == null || permission.length() == 0) { + throw new TemplateModelException("The 'name' tag attribute must be set."); + } + } + + @Override + public void render(Environment env, Map params, TemplateDirectiveBody body) throws IOException, TemplateException { + String p = getName(params); + + boolean show = showTagBody(p); + if (show) { + renderBody(env, body); + } + } + + protected boolean isPermitted(String p) { + return getSubject() != null && getSubject().isPermitted(p); + } + + protected abstract boolean showTagBody(String p); +} diff --git a/src/main/java/com/krt/dairy/common/web/shiro/freemarker/PrincipalTag.java b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/PrincipalTag.java new file mode 100644 index 0000000..43fcbce --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/PrincipalTag.java @@ -0,0 +1,119 @@ +package com.krt.dairy.common.web.shiro.freemarker; + +import freemarker.core.Environment; +import freemarker.log.Logger; +import freemarker.template.TemplateDirectiveBody; +import freemarker.template.TemplateException; +import freemarker.template.TemplateModelException; + +import java.beans.BeanInfo; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.io.IOException; +import java.util.Map; + +/** + *

Tag used to print out the String value of a user's default principal, + * or a specific principal as specified by the tag's attributes.

+ * + *

If no attributes are specified, the tag prints out the toString() + * value of the user's default principal. If the type attribute + * is specified, the tag looks for a principal with the given type. If the + * property attribute is specified, the tag prints the string value of + * the specified property of the principal. If no principal is found or the user + * is not authenticated, the tag displays nothing unless a defaultValue + * is specified.

+ * + *

Equivalent to {@link org.apache.shiro.web.tags.PrincipalTag}

+ * + * @since 0.2 + */ +public class PrincipalTag extends SecureTag { + static final Logger log = Logger.getLogger("PrincipalTag"); + + /** + * The type of principal to be retrieved, or null if the default principal should be used. + */ + String getType(Map params) { + return getParam(params, "type"); + } + + /** + * The property name to retrieve of the principal, or null if the toString() value should be used. + */ + String getProperty(Map params) { + return getParam(params, "property"); + } + + @SuppressWarnings("unchecked") + @Override + public void render(Environment env, Map params, TemplateDirectiveBody body) throws IOException, TemplateException { + String result = null; + + if (getSubject() != null) { + // Get the principal to print out + Object principal; + + if (getType(params) == null) { + principal = getSubject().getPrincipal(); + } else { + principal = getPrincipalFromClassName(params); + } + + // Get the string value of the principal + if (principal != null) { + String property = getProperty(params); + + if (property == null) { + result = principal.toString(); + } else { + result = getPrincipalProperty(principal, property); + } + } + } + + // Print out the principal value if not null + if (result != null) { + try { + env.getOut().write(result); + } catch (IOException ex) { + throw new TemplateException("Error writing ["+result+"] to Freemarker.", ex, env); + } + } + } + + @SuppressWarnings("unchecked") + Object getPrincipalFromClassName(Map params) { + String type = getType(params); + + try { + Class cls = Class.forName(type); + + return getSubject().getPrincipals().oneByType(cls); + } catch (ClassNotFoundException ex) { + log.error("Unable to find class for name ["+type+"]", ex); + } + + return null; + } + + String getPrincipalProperty(Object principal, String property) throws TemplateModelException { + try { + BeanInfo beanInfo = Introspector.getBeanInfo(principal.getClass()); + + // Loop through the properties to get the string value of the specified property + for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) { + if (propertyDescriptor.getName().equals(property)) { + Object value = propertyDescriptor.getReadMethod().invoke(principal, (Object[]) null); + + return String.valueOf(value); + } + } + + // property not found, throw + throw new TemplateModelException("Property ["+property+"] not found in principal of type ["+principal.getClass().getName()+"]"); + } catch (Exception ex) { + throw new TemplateModelException("Error reading property ["+property+"] from principal of type ["+principal.getClass().getName()+"]", ex); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/krt/dairy/common/web/shiro/freemarker/RoleTag.java b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/RoleTag.java new file mode 100644 index 0000000..8194144 --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/RoleTag.java @@ -0,0 +1,27 @@ +package com.krt.dairy.common.web.shiro.freemarker; + +import freemarker.core.Environment; +import freemarker.template.TemplateDirectiveBody; +import freemarker.template.TemplateException; + +import java.io.IOException; +import java.util.Map; + +/** + *

Equivalent to {@link org.apache.shiro.web.tags.RoleTag}

+ */ +public abstract class RoleTag extends SecureTag { + String getName(Map params) { + return getParam(params, "name"); + } + + @Override + public void render(Environment env, Map params, TemplateDirectiveBody body) throws IOException, TemplateException { + boolean show = showTagBody(getName(params)); + if (show) { + renderBody(env, body); + } + } + + protected abstract boolean showTagBody(String roleName); +} \ No newline at end of file diff --git a/src/main/java/com/krt/dairy/common/web/shiro/freemarker/SecureTag.java b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/SecureTag.java new file mode 100644 index 0000000..ab41b55 --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/SecureTag.java @@ -0,0 +1,44 @@ +package com.krt.dairy.common.web.shiro.freemarker; + +import freemarker.core.Environment; +import freemarker.template.*; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.subject.Subject; + +import java.io.IOException; +import java.util.Map; + +/** + *

Equivalent to {@link org.apache.shiro.web.tags.SecureTag}

+ */ +public abstract class SecureTag implements TemplateDirectiveModel { + public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { + verifyParameters(params); + render(env, params, body); + } + + public abstract void render(Environment env, Map params, TemplateDirectiveBody body) throws IOException, TemplateException; + + protected String getParam(Map params, String name) { + Object value = params.get(name); + + if (value instanceof SimpleScalar) { + return ((SimpleScalar)value).getAsString(); + } + + return null; + } + + protected Subject getSubject() { + return SecurityUtils.getSubject(); + } + + protected void verifyParameters(Map params) throws TemplateModelException { + } + + protected void renderBody(Environment env, TemplateDirectiveBody body) throws IOException, TemplateException { + if (body != null) { + body.render(env.getOut()); + } + } +} diff --git a/src/main/java/com/krt/dairy/common/web/shiro/freemarker/ShiroTags.java b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/ShiroTags.java new file mode 100644 index 0000000..7830482 --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/ShiroTags.java @@ -0,0 +1,23 @@ +package com.krt.dairy.common.web.shiro.freemarker; + +import freemarker.template.SimpleHash; + +/** + * Shortcut for injecting the tags into Freemarker + * + *

Usage: cfg.setSharedVeriable("shiro", new ShiroTags());

+ */ +public class ShiroTags extends SimpleHash { + public ShiroTags() { + put("authenticated", new AuthenticatedTag()); + put("guest", new GuestTag()); + put("hasAnyRoles", new HasAnyRolesTag()); + put("hasPermission", new HasPermissionTag()); + put("hasRole", new HasRoleTag()); + put("lacksPermission", new LacksPermissionTag()); + put("lacksRole", new LacksRoleTag()); + put("notAuthenticated", new NotAuthenticatedTag()); + put("principal", new PrincipalTag()); + put("user", new UserTag()); + } +} \ No newline at end of file diff --git a/src/main/java/com/krt/dairy/common/web/shiro/freemarker/UserTag.java b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/UserTag.java new file mode 100644 index 0000000..5533a6a --- /dev/null +++ b/src/main/java/com/krt/dairy/common/web/shiro/freemarker/UserTag.java @@ -0,0 +1,37 @@ +package com.krt.dairy.common.web.shiro.freemarker; + +import freemarker.core.Environment; +import freemarker.log.Logger; +import freemarker.template.TemplateDirectiveBody; +import freemarker.template.TemplateException; + +import java.io.IOException; +import java.util.Map; + +/** + * Freemarker tag that renders the tag body if the current user known to the system, either from a successful login attempt + * (not necessarily during the current session) or from 'RememberMe' services. + * + *

Note: This is less restrictive than the AuthenticatedTag since it only assumes + * the user is who they say they are, either via a current session login or via Remember Me services, which + * makes no guarantee the user is who they say they are. The AuthenticatedTag however + * guarantees that the current user has logged in during their current session, proving they really are + * who they say they are. + * + *

The logically opposite tag of this one is the {@link org.apache.shiro.web.tags.GuestTag}. + * + *

Equivalent to {@link org.apache.shiro.web.tags.UserTag}

+ */ +public class UserTag extends SecureTag { + static final Logger log = Logger.getLogger("UserTag"); + + @Override + public void render(Environment env, Map params, TemplateDirectiveBody body) throws IOException, TemplateException { + if (getSubject() != null && getSubject().getPrincipal() != null) { + log.debug("Subject has known identity (aka 'principal'). Tag body will be evaluated."); + renderBody(env, body); + } else { + log.debug("Subject does not exist or have a known identity (aka 'principal'). Tag body will not be evaluated."); + } + } +} diff --git a/src/main/java/com/krt/dairy/core/auth/dao/AuthUserDao.java b/src/main/java/com/krt/dairy/core/auth/dao/AuthUserDao.java new file mode 100644 index 0000000..026655a --- /dev/null +++ b/src/main/java/com/krt/dairy/core/auth/dao/AuthUserDao.java @@ -0,0 +1,71 @@ +package com.krt.dairy.core.auth.dao; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.auth.domain.AuthUser; + +import java.util.List; + + +public interface AuthUserDao { + + /** + *根据id获取 + **/ + public AuthUser getById(Long id); + + /** + * 根据username获取 + */ + public AuthUser getByUsername(String username); + + /** + * 根据username 和 password获取 + * @param authUser + * @return + */ + public AuthUser getByUsernameAndPassword(AuthUser authUser); + + /** + *获取首页推荐5个讲师 + **/ + public List queryRecomd(); + + /** + *获取总数量 + **/ + public Integer getTotalItemsCount(AuthUser queryEntity); + + /** + *分页获取 + **/ + public List queryPage(AuthUser queryEntity, TailPage page); + + /** + *创建新记录 + **/ + public void createSelectivity(AuthUser entity); + + /** + *根据id更新 + **/ + public void update(AuthUser entity); + + /** + *根据id选择性更新自动 + **/ + public void updateSelectivity(AuthUser entity); + + /** + *物理删除 + **/ + public void delete(AuthUser entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(AuthUser entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/auth/dao/AuthUserMapper.xml b/src/main/java/com/krt/dairy/core/auth/dao/AuthUserMapper.xml new file mode 100644 index 0000000..da4120d --- /dev/null +++ b/src/main/java/com/krt/dairy/core/auth/dao/AuthUserMapper.xml @@ -0,0 +1,426 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + realname, username, password, gender, header, mobile, + status, birthday, education, college_code, college_name, cert_no, title, sign, + open_id, wechat_id, qq, login_time, ip, province, + city, district, weight, create_time, create_user, update_time, update_user, + del, id + + + + + + INSERT INTO t_auth_user + + + realname, + + + username, + + + password, + + + gender, + + + header, + + + mobile, + + + status, + + + birthday, + + + education, + + + college_code, + + + college_name, + + + cert_no, + + + title, + + + sign, + + + open_id, + + + wechat_id, + + + qq, + + + login_time, + + + ip, + + + province, + + + CITY, + + + district, + + + weight, + + + create_time, + + + create_user, + + + update_time, + + + update_user, + + + del, + + + VALUES + + + #{realname, jdbcType=VARCHAR}, + + + #{username, jdbcType=VARCHAR}, + + + #{password, jdbcType=VARCHAR}, + + + #{gender, jdbcType=INTEGER}, + + + #{header, jdbcType=VARCHAR}, + + + #{mobile, jdbcType=VARCHAR}, + + + #{status, jdbcType=INTEGER}, + + + #{birthday, jdbcType=DATE}, + + + #{education, jdbcType=VARCHAR}, + + + #{collegeCode, jdbcType=VARCHAR}, + + + #{collegeName, jdbcType=VARCHAR}, + + + #{certNo, jdbcType=VARCHAR}, + + + #{title, jdbcType=VARCHAR}, + + + #{sign, jdbcType=VARCHAR}, + + + #{openId, jdbcType=VARCHAR}, + + + #{wechatId, jdbcType=VARCHAR}, + + + #{qq, jdbcType=VARCHAR}, + + + #{loginTime, jdbcType=DATE}, + + + #{ip, jdbcType=VARCHAR}, + + + #{province, jdbcType=VARCHAR}, + + + #{city, jdbcType=VARCHAR}, + + + #{district, jdbcType=VARCHAR}, + + + #{weight, jdbcType=INTEGER}, + + + #{createTime, jdbcType=DATE}, + + + #{createUser, jdbcType=VARCHAR}, + + + #{updateTime, jdbcType=TIMESTAMP}, + + + #{updateUser, jdbcType=VARCHAR}, + + + #{del, jdbcType=TINYINT}, + + + + + + + + + + + + + + + + + + + + UPDATE t_auth_user + + + realname = #{realname, jdbcType=VARCHAR}, + + + username = #{username, jdbcType=VARCHAR}, + + + password = #{password, jdbcType=VARCHAR}, + + + gender = #{gender, jdbcType=INTEGER}, + + + header = #{header, jdbcType=VARCHAR}, + + + mobile = #{mobile, jdbcType=VARCHAR}, + + + status = #{status, jdbcType=INTEGER}, + + + birthday = #{birthday, jdbcType=DATE}, + + + education = #{education, jdbcType=VARCHAR}, + + + college_code = #{collegeCode, jdbcType=VARCHAR}, + + + college_name = #{collegeName, jdbcType=VARCHAR}, + + + cert_no = #{certNo, jdbcType=VARCHAR}, + + + title = #{title, jdbcType=VARCHAR}, + + + sign = #{sign, jdbcType=VARCHAR}, + + + open_id = #{openId, jdbcType=VARCHAR}, + + + wechat_id = #{wechatId, jdbcType=VARCHAR}, + + + qq = #{qq, jdbcType=VARCHAR}, + + + login_time = #{loginTime, jdbcType=DATE}, + + + ip = #{ip, jdbcType=VARCHAR}, + + + province = #{province, jdbcType=VARCHAR}, + + + city = #{city, jdbcType=VARCHAR}, + + + district = #{district, jdbcType=VARCHAR}, + + + weight = #{weight, jdbcType=INTEGER}, + + + update_time = #{updateTime, jdbcType=TIMESTAMP}, + + + update_user = #{updateUser, jdbcType=VARCHAR}, + + + del = #{del, jdbcType=TINYINT}, + + + WHERE id = #{id, jdbcType = INTEGER} + + + + INSERT INTO t_auth_user + ( realname, username, password, gender, header, mobile, + status, birthday, education, college_code, college_name, cert_no, title, sign, + open_id, wechat_id, qq, login_time, ip, province, + city, district, weight, create_time, create_user, update_time, update_user, + del, id ) + VALUES + ( #{realname, jdbcType=VARCHAR}, #{username, jdbcType=VARCHAR}, #{password, jdbcType=VARCHAR}, #{gender, jdbcType=INTEGER}, #{header, jdbcType=VARCHAR}, #{mobile, jdbcType=VARCHAR}, + #{status, jdbcType=INTEGER}, #{birthday, jdbcType=DATE}, #{education, jdbcType=VARCHAR}, #{collegeCode, jdbcType=VARCHAR}, #{collegeName, jdbcType=VARCHAR}, #{certNo, jdbcType=VARCHAR}, #{title, jdbcType=VARCHAR}, #{sign, jdbcType=VARCHAR}, + #{openId, jdbcType=VARCHAR}, #{wechatId, jdbcType=VARCHAR}, #{qq, jdbcType=VARCHAR}, #{loginTime, jdbcType=DATE}, #{ip, jdbcType=VARCHAR}, #{province, jdbcType=VARCHAR}, + #{city, jdbcType=VARCHAR}, #{district, jdbcType=VARCHAR} , #{weight, jdbcType=INTEGER}, #{createTime, jdbcType=DATE}, #{createUser, jdbcType=VARCHAR}, #{updateTime, jdbcType=TIMESTAMP}, #{updateUser, jdbcType=VARCHAR}, + #{del, jdbcType=TINYINT}, #{id, jdbcType=VARCHAR} ) + + + + UPDATE t_auth_user SET + realname = #{realname, jdbcType=VARCHAR}, + username = #{username, jdbcType=VARCHAR}, + password = #{password, jdbcType=VARCHAR}, + gender = #{gender, jdbcType=INTEGER}, + header = #{header, jdbcType=VARCHAR}, + mobile = #{mobile, jdbcType=VARCHAR}, + status = #{status, jdbcType=INTEGER}, + birthday = #{birthday, jdbcType=DATE}, + education = #{education, jdbcType=VARCHAR}, + college_code = #{collegeCode, jdbcType=VARCHAR}, + college_name = #{collegeName, jdbcType=VARCHAR}, + cert_no = #{certNo, jdbcType=VARCHAR}, + title = #{title, jdbcType=VARCHAR}, + sign = #{sign, jdbcType=VARCHAR}, + open_id = #{openId, jdbcType=VARCHAR}, + wechat_id = #{wechatId, jdbcType=VARCHAR}, + qq = #{qq, jdbcType=VARCHAR}, + login_time = #{loginTime, jdbcType=DATE}, + ip = #{ip, jdbcType=VARCHAR}, + province = #{province, jdbcType=VARCHAR}, + city = #{city, jdbcType=VARCHAR}, + district = #{district, jdbcType=VARCHAR}, + weight = #{weight, jdbcType=INTEGER}, + update_time = #{updateTime, jdbcType=TIMESTAMP}, + update_user = #{updateUser, jdbcType=VARCHAR} + WHERE id = #{id, jdbcType=INTEGER} + + + + DELETE + FROM t_auth_user + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_auth_user + SET del = 1 + WHERE id = #{id, jdbcType=INTEGER} + + + diff --git a/src/main/java/com/krt/dairy/core/auth/domain/AuthUser.java b/src/main/java/com/krt/dairy/core/auth/domain/AuthUser.java new file mode 100644 index 0000000..61e1374 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/auth/domain/AuthUser.java @@ -0,0 +1,311 @@ +package com.krt.dairy.core.auth.domain; + +import com.krt.dairy.common.orm.BaseEntity; +import com.krt.dairy.common.web.auth.SessionUser; + +import java.util.Date; +import java.util.Set; + +/** + * 系统用户 + */ +public class AuthUser extends BaseEntity implements SessionUser{ + + private static final long serialVersionUID = 94044276250229411L; + + /** + *登录用户名 + **/ + private String realname; + + /** + *真实姓名 + **/ + private String username; + + /** + *密码 + **/ + private String password; + + /** + *性别 + **/ + private Integer gender; + + /** + *头像 + **/ + private String header; + + /** + *手机号码 + **/ + private String mobile; + + /** + *状态:待审核(0),审核通过(1),默认(2),审核未通过(3),禁用(5) + **/ + private Integer status; + + /** + *生日 + **/ + private Date birthday; + + /** + *学历:大专、本科、硕士、博士、博士后 + **/ + private String education; + + /** + * 大学编号 + */ + private String collegeCode; + + /** + * 大学名称 + */ + private String collegeName; + + /** + *资格证书编号 + **/ + private String certNo; + + /** + *头衔 + **/ + private String title; + + /** + *签名 + **/ + private String sign; + + /** + *微信公众号openid + **/ + private String openId; + + /** + *微信号 + **/ + private String wechatId; + + /** + *qq号 + **/ + private String qq; + + /** + *最后一次登录时间 + **/ + private Date loginTime; + + /** + *最后一次登录IP + **/ + private String ip; + + /** + *所在省份 + **/ + private String province; + + /** + *所在城市 + **/ + private String city; + + /** + *所在地区 + **/ + private String district; + + /** + * 推荐权重 + */ + private Integer weight; + + /** + * 扩展字段:微信昵称 + */ + private String nickname; + + public String getRealname(){ + return realname; + } + public void setRealname(String realname){ + this.realname = realname; + } + + public String getUsername(){ + return username; + } + public void setUsername(String username){ + this.username = username; + } + + public String getPassword(){ + return password; + } + public void setPassword(String password){ + this.password = password; + } + + public Integer getGender(){ + return gender; + } + public void setGender(Integer gender){ + this.gender = gender; + } + + public String getHeader(){ + return header; + } + public void setHeader(String header){ + this.header = header; + } + + public String getMobile(){ + return mobile; + } + public void setMobile(String mobile){ + this.mobile = mobile; + } + + public Integer getStatus(){ + return status; + } + public void setStatus(Integer status){ + this.status = status; + } + + public Date getBirthday(){ + return birthday; + } + public void setBirthday(Date birthday){ + this.birthday = birthday; + } + + public String getEducation(){ + return education; + } + public void setEducation(String education){ + this.education = education; + } + public String getCollegeCode() { + return collegeCode; + } + public void setCollegeCode(String collegeCode) { + this.collegeCode = collegeCode; + } + public String getCollegeName() { + return collegeName; + } + public void setCollegeName(String collegeName) { + this.collegeName = collegeName; + } + public String getCertNo(){ + return certNo; + } + public void setCertNo(String certNo){ + this.certNo = certNo; + } + + public String getTitle(){ + return title; + } + public void setTitle(String title){ + this.title = title; + } + + public String getSign(){ + return sign; + } + public void setSign(String sign){ + this.sign = sign; + } + + public String getOpenId(){ + return openId; + } + public void setOpenId(String openId){ + this.openId = openId; + } + + public String getWechatId(){ + return wechatId; + } + public void setWechatId(String wechatId){ + this.wechatId = wechatId; + } + + public String getQq(){ + return qq; + } + public void setQq(String qq){ + this.qq = qq; + } + + public Date getLoginTime(){ + return loginTime; + } + public void setLoginTime(Date loginTime){ + this.loginTime = loginTime; + } + + public String getIp(){ + return ip; + } + public void setIp(String ip){ + this.ip = ip; + } + + public String getProvince(){ + return province; + } + public void setProvince(String province){ + this.province = province; + } + + public String getCity(){ + return city; + } + public void setCity(String city){ + this.city = city; + } + + public String getDistrict(){ + return district; + } + public void setDistrict(String district){ + this.district = district; + } + + public Integer getWeight() { + return weight; + } + public void setWeight(Integer weight) { + this.weight = weight; + } + + @Override + public Long getUserId() { + return this.getId(); + } + + @Override + public Set getPermissions(){ + return null; + } + public String getNickname() { + return nickname; + } + public void setNickname(String nickname) { + this.nickname = nickname; + } + +} + diff --git a/src/main/java/com/krt/dairy/core/auth/service/IAuthUserService.java b/src/main/java/com/krt/dairy/core/auth/service/IAuthUserService.java new file mode 100644 index 0000000..4cd48b1 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/auth/service/IAuthUserService.java @@ -0,0 +1,66 @@ +package com.krt.dairy.core.auth.service; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.auth.domain.AuthUser; + +import java.util.List; + + +public interface IAuthUserService { + + /** + *根据username获取 + **/ + public AuthUser getByUsername(String username); + + /** + *创建 + **/ + public void createSelectivity(AuthUser entity); + + + + /** + *根据id获取 + **/ + public AuthUser getById(Long id); + + /** + *根据username和password获取 + **/ + public AuthUser getByUsernameAndPassword(AuthUser authUser); + + /** + *获取首页推荐5个讲师 + **/ + public List queryRecomd(); + + /** + *分页获取 + **/ + public TailPage queryPage(AuthUser queryEntity, TailPage page); + + /** + *根据id更新 + **/ + public void update(AuthUser entity); + + /** + *根据id 进行可选性更新 + **/ + public void updateSelectivity(AuthUser entity); + + /** + *物理删除 + **/ + public void delete(AuthUser entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(AuthUser entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/auth/service/impl/AuthUserServiceImpl.java b/src/main/java/com/krt/dairy/core/auth/service/impl/AuthUserServiceImpl.java new file mode 100644 index 0000000..bb45499 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/auth/service/impl/AuthUserServiceImpl.java @@ -0,0 +1,90 @@ +package com.krt.dairy.core.auth.service.impl; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.common.storage.QiniuStorage; +import com.krt.dairy.core.auth.dao.AuthUserDao; +import com.krt.dairy.core.auth.domain.AuthUser; +import com.krt.dairy.core.auth.service.IAuthUserService; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + + +@Service +public class AuthUserServiceImpl implements IAuthUserService{ + + @Autowired + private AuthUserDao entityDao; + + public void createSelectivity(AuthUser entity){ + entityDao.createSelectivity(entity); + } + + /** + *根据username获取 + **/ + public AuthUser getByUsername(String username){ + return entityDao.getByUsername(username); + } + + + + public AuthUser getById(Long id){ + return entityDao.getById(id); + } + + /** + *根据username和password获取 + **/ + public AuthUser getByUsernameAndPassword(AuthUser authUser){ + return entityDao.getByUsernameAndPassword(authUser); + } + + /** + *获取首页推荐5个讲师 + **/ + public List queryRecomd(){ + List recomdList = entityDao.queryRecomd(); + if(CollectionUtils.isNotEmpty(recomdList)){ + for(AuthUser item : recomdList){ + if(StringUtils.isNotEmpty(item.getHeader())){ + item.setHeader(QiniuStorage.getUrl(item.getHeader())); + } + } + } + return recomdList; + } + + public TailPage queryPage(AuthUser queryEntity ,TailPage page){ + Integer itemsTotalCount = entityDao.getTotalItemsCount(queryEntity); + List items = entityDao.queryPage(queryEntity,page); + page.setItemsTotalCount(itemsTotalCount); + page.setItems(items); + return page; + } + + + + public void update(AuthUser entity){ + entityDao.update(entity); + } + + public void updateSelectivity(AuthUser entity){ + entityDao.updateSelectivity(entity); + } + + public void delete(AuthUser entity){ + entityDao.delete(entity); + } + + public void deleteLogic(AuthUser entity){ + entityDao.deleteLogic(entity); + } + + + +} + diff --git a/src/main/java/com/krt/dairy/core/consts/CourseEnum.java b/src/main/java/com/krt/dairy/core/consts/CourseEnum.java new file mode 100644 index 0000000..576f2d0 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/CourseEnum.java @@ -0,0 +1,25 @@ +package com.krt.dairy.core.consts; + +/** + * 课程使用的枚举 + */ +public enum CourseEnum { + + FREE(1), //免费 + FREE_NOT(0), //收费 + + ONSALE(1), //上架 + ONSALE_NOT(0), //下架 + + COLLECTION_CLASSIFY_COURSE(1);//课程收藏 + + + private Integer value; + private CourseEnum(Integer value) { + this.value = value; + } + + public Integer value(){ + return value; + } +} diff --git a/src/main/java/com/krt/dairy/core/consts/dao/ConstsClassifyDao.java b/src/main/java/com/krt/dairy/core/consts/dao/ConstsClassifyDao.java new file mode 100644 index 0000000..f704efa --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/dao/ConstsClassifyDao.java @@ -0,0 +1,77 @@ +package com.krt.dairy.core.consts.dao; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.consts.domain.ConstsClassify; +import com.krt.dairy.core.consts.domain.ConstsCollege; + +import java.util.List; + + +public interface ConstsClassifyDao { + + /** + *根据id获取 + **/ + public ConstsClassify getById(Long id); + + /** + * 根据code获取 + */ + public ConstsCollege getByCode(String code); + + /** + *获取所有 + **/ + public List queryAll(); + + /** + * 根据条件动态获取 + * @param queryEntity + * @return + */ + public List queryByCondition(ConstsClassify queryEntity); + + /** + *获取总数量 + **/ + public Integer getTotalItemsCount(ConstsClassify queryEntity); + + /** + *分页获取 + **/ + public List queryPage(ConstsClassify queryEntity, TailPage page); + + /** + *创建新记录 + **/ + public void create(ConstsClassify entity); + + /** + * 创建新记录 + */ + public void createSelectivity(ConstsClassify entity); + + /** + *根据id更新 + **/ + public void update(ConstsClassify entity); + + /** + *根据id选择性更新自动 + **/ + public void updateSelectivity(ConstsClassify entity); + + /** + *物理删除 + **/ + public void delete(ConstsClassify entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(ConstsClassify entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/consts/dao/ConstsClassifyMapper.xml b/src/main/java/com/krt/dairy/core/consts/dao/ConstsClassifyMapper.xml new file mode 100644 index 0000000..6c59291 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/dao/ConstsClassifyMapper.xml @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + name, code, parent_code, sort, create_time, create_user, update_time, + update_user, del, id + + + + + + + + + + + + + + + + INSERT INTO t_consts_classify + ( name, parent_code, sort, create_time, create_user, update_time, + update_user, del, id ) + VALUES + ( #{name, jdbcType=VARCHAR}, #{parentCode, jdbcType=VARCHAR}, #{sort, jdbcType=VARCHAR}, #{createTime, jdbcType=DATE}, #{createUser, jdbcType=VARCHAR}, #{updateTime, jdbcType=TIMESTAMP}, + #{updateUser, jdbcType=VARCHAR}, #{del, jdbcType=TINYINT}, #{id, jdbcType=VARCHAR} ) + + + + INSERT INTO t_consts_classify + + + name, + + + CODE, + + + parent_code, + + + sort, + + + create_time, + + + create_user, + + + update_time, + + + update_user, + + + del, + + + VALUES + + + #{name, jdbcType=VARCHAR}, + + + #{code, jdbcType=VARCHAR}, + + + #{parentCode, jdbcType=VARCHAR}, + + + #{sort, jdbcType=INTEGER}, + + + #{createTime, jdbcType=DATE}, + + + #{createUser, jdbcType=VARCHAR}, + + + #{updateTime, jdbcType=TIMESTAMP}, + + + #{updateUser, jdbcType=VARCHAR}, + + + #{del, jdbcType=TINYINT}, + + + + + + UPDATE t_consts_classify SET + name = #{name, jdbcType=VARCHAR}, + parent_code = #{parentCode, jdbcType=VARCHAR}, + sort = #{sort, jdbcType=VARCHAR}, + update_time = #{updateTime, jdbcType=TIMESTAMP}, + update_user = #{updateUser, jdbcType=VARCHAR} + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_consts_classify + + + name = #{name, jdbcType=VARCHAR}, + + + parent_code = #{parentCode, jdbcType=VARCHAR}, + + + sort = #{sort, jdbcType=VARCHAR}, + + + update_time = #{updateTime, jdbcType=TIMESTAMP}, + + + update_user = #{updateUser, jdbcType=VARCHAR}, + + + del = #{del, jdbcType=TINYINT}, + + + WHERE id = #{id, jdbcType = INTEGER} + + + + + DELETE FROM t_consts_classify + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_consts_classify + SET del = 1 + WHERE id = #{id, jdbcType=INTEGER} + + + diff --git a/src/main/java/com/krt/dairy/core/consts/dao/ConstsCollegeDao.java b/src/main/java/com/krt/dairy/core/consts/dao/ConstsCollegeDao.java new file mode 100644 index 0000000..b2d16e5 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/dao/ConstsCollegeDao.java @@ -0,0 +1,67 @@ +package com.krt.dairy.core.consts.dao; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.consts.domain.ConstsCollege; + +import java.util.List; + + +public interface ConstsCollegeDao { + + /** + *根据id获取 + **/ + public ConstsCollege getById(Long id); + + /** + * 根据code获取 + */ + public ConstsCollege getByCode(String code); + + /** + *获取所有 + **/ + public List queryAll(ConstsCollege queryEntity); + + /** + *获取总数量 + **/ + public Integer getTotalItemsCount(ConstsCollege queryEntity); + + /** + *分页获取 + **/ + public List queryPage(ConstsCollege queryEntity, TailPage page); + + /** + *创建新记录 + **/ + public void create(ConstsCollege entity); + + /** + * 创建网校 + */ + public void createSelectivity(ConstsCollege entity); + + /** + *根据id更新 + **/ + public void update(ConstsCollege entity); + + /** + *根据id选择性更新自动 + **/ + public void updateSelectivity(ConstsCollege entity); + + /** + *物理删除 + **/ + public void delete(ConstsCollege entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(ConstsCollege entity); + +} + diff --git a/src/main/java/com/krt/dairy/core/consts/dao/ConstsCollegeMapper.xml b/src/main/java/com/krt/dairy/core/consts/dao/ConstsCollegeMapper.xml new file mode 100644 index 0000000..3ef59fd --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/dao/ConstsCollegeMapper.xml @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + name, code, picture, create_time, create_user, update_time, + update_user, del, id + + + + + + + + + + + + + + INSERT INTO t_consts_college + ( name, code, picture, create_time, create_user, update_time, + update_user, del, id ) + VALUES + ( #{name, jdbcType=VARCHAR}, #{code, jdbcType=VARCHAR}, #{picture, jdbcType=VARCHAR}, #{createTime, jdbcType=DATE}, #{createUser, jdbcType=VARCHAR}, #{updateTime, jdbcType=TIMESTAMP}, + #{updateUser, jdbcType=VARCHAR}, #{del, jdbcType=TINYINT}, #{id, jdbcType=VARCHAR} ) + + + + INSERT INTO t_consts_college + + + name, + + + code, + + + picture, + + + create_time, + + + create_user, + + + update_time, + + + update_user, + + + del, + + + VALUES + + + #{name, jdbcType=VARCHAR}, + + + #{code, jdbcType=VARCHAR}, + + + #{picture, jdbcType=VARCHAR}, + + + #{createTime, jdbcType=DATE}, + + + #{createUser, jdbcType=VARCHAR}, + + + #{updateTime, jdbcType=TIMESTAMP}, + + + #{updateUser, jdbcType=VARCHAR}, + + + #{del, jdbcType=TINYINT}, + + + + + + UPDATE t_consts_college SET + name = #{name, jdbcType=VARCHAR}, + code = #{code, jdbcType=VARCHAR}, + picture = #{picture, jdbcType=VARCHAR}, + update_time = #{updateTime, jdbcType=TIMESTAMP}, + update_user = #{updateUser, jdbcType=VARCHAR} + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_consts_college + + + name = #{name, jdbcType=VARCHAR}, + + + code = #{code, jdbcType=VARCHAR}, + + + picture = #{picture, jdbcType=VARCHAR}, + + + update_time = #{updateTime, jdbcType=TIMESTAMP}, + + + update_user = #{updateUser, jdbcType=VARCHAR}, + + + del = #{del, jdbcType=TINYINT}, + + + WHERE id = #{id, jdbcType = INTEGER} + + + + + DELETE FROM t_consts_college + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_consts_college + SET del = 1 + WHERE id = #{id, jdbcType=INTEGER} + + + diff --git a/src/main/java/com/krt/dairy/core/consts/dao/ConstsSiteCarouselDao.java b/src/main/java/com/krt/dairy/core/consts/dao/ConstsSiteCarouselDao.java new file mode 100644 index 0000000..0032216 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/dao/ConstsSiteCarouselDao.java @@ -0,0 +1,69 @@ +package com.krt.dairy.core.consts.dao; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.consts.domain.ConstsSiteCarousel; + +import java.util.List; + + +public interface ConstsSiteCarouselDao { + + /** + *根据id获取 + **/ + public ConstsSiteCarousel getById(Long id); + + /** + * 获取轮播 + */ + public List queryCarousels(Integer count); + + /** + *获取所有 + **/ + public List queryAll(ConstsSiteCarousel queryEntity); + + /** + *获取总数量 + **/ + public Integer getTotalItemsCount(ConstsSiteCarousel queryEntity); + + /** + *分页获取 + **/ + public List queryPage(ConstsSiteCarousel queryEntity, TailPage page); + + /** + *创建新记录 + **/ + public void create(ConstsSiteCarousel entity); + + /** + * 创建新记录 + */ + public void createSelectivity(ConstsSiteCarousel entity); + + /** + *根据id更新 + **/ + public void update(ConstsSiteCarousel entity); + + /** + *根据id选择性更新自动 + **/ + public void updateSelectivity(ConstsSiteCarousel entity); + + /** + *物理删除 + **/ + public void delete(ConstsSiteCarousel entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(ConstsSiteCarousel entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/consts/dao/ConstsSiteCarouselMapper.xml b/src/main/java/com/krt/dairy/core/consts/dao/ConstsSiteCarouselMapper.xml new file mode 100644 index 0000000..7bfa77b --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/dao/ConstsSiteCarouselMapper.xml @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + name, picture, url, weight, enable, create_time, create_user, + update_time, update_user, del, id + + + + + + + + + + + + INSERT INTO t_consts_site_carousel + ( name, picture, url, weight, enable, create_time, create_user, + update_time, update_user, del, id ) + VALUES + ( #{name, jdbcType=VARCHAR}, #{picture, jdbcType=VARCHAR}, #{url, jdbcType=VARCHAR}, #{weight, jdbcType=INTEGER}, #{enable, jdbcType=TINYINT}, #{createTime, jdbcType=DATE}, #{createUser, jdbcType=VARCHAR}, + #{updateTime, jdbcType=TIMESTAMP}, #{updateUser, jdbcType=VARCHAR}, #{del, jdbcType=TINYINT}, #{id, jdbcType=INTEGER} ) + + + + UPDATE t_consts_site_carousel SET + name = #{name, jdbcType=VARCHAR}, + picture = #{picture, jdbcType=VARCHAR}, + url = #{url, jdbcType=VARCHAR}, + weight = #{weight, jdbcType=INTEGER}, + enable = #{enable, jdbcType=TINYINT}, + update_time = #{updateTime, jdbcType=TIMESTAMP}, + update_user = #{updateUser, jdbcType=VARCHAR} + WHERE id = #{id, jdbcType=INTEGER} + + + + INSERT INTO t_consts_site_carousel + + + name, + + + picture, + + + url, + + + weight, + + + enable, + + + create_time, + + + create_user, + + + update_time, + + + update_user, + + + del, + + + VALUES + + + #{name, jdbcType=VARCHAR}, + + + #{picture, jdbcType=VARCHAR}, + + + #{url, jdbcType=VARCHAR}, + + + #{weight, jdbcType=INTEGER}, + + + #{enable, jdbcType=INTEGER}, + + + #{createTime, jdbcType=DATE}, + + + #{createUser, jdbcType=VARCHAR}, + + + #{updateTime, jdbcType=TIMESTAMP}, + + + #{updateUser, jdbcType=VARCHAR}, + + + #{del, jdbcType=TINYINT}, + + + + + + UPDATE t_consts_site_carousel + + + name = #{name, jdbcType=VARCHAR}, + + + picture = #{picture, jdbcType=VARCHAR}, + + + url = #{url, jdbcType=VARCHAR}, + + + weight = #{weight, jdbcType=INTEGER}, + + + enable = #{enable, jdbcType=TINYINT}, + + + update_time = #{updateTime, jdbcType=TIMESTAMP}, + + + update_user = #{updateUser, jdbcType=VARCHAR}, + + + del = #{del, jdbcType=TINYINT}, + + + WHERE id = #{id, jdbcType = INTEGER} + + + + + DELETE FROM t_consts_site_carousel + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_consts_site_carousel + SET del = 1 + WHERE id = #{id, jdbcType=INTEGER} + + + diff --git a/src/main/java/com/krt/dairy/core/consts/domain/ConstsClassify.java b/src/main/java/com/krt/dairy/core/consts/domain/ConstsClassify.java new file mode 100644 index 0000000..34db656 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/domain/ConstsClassify.java @@ -0,0 +1,57 @@ +package com.krt.dairy.core.consts.domain; + +import com.krt.dairy.common.orm.BaseEntity; + +public class ConstsClassify extends BaseEntity{ + + private static final long serialVersionUID = -7695989855010913861L; + + /** + *名称 + **/ + private String name; + + /** + *编码 + **/ + private String code; + + /** + *父级别id + **/ + private String parentCode; + + /** + *排序 + **/ + private Long sort; + + public String getName(){ + return name; + } + public void setName(String name){ + this.name = name; + } + public String getCode() { + return code; + } + public void setCode(String code) { + this.code = code; + } + public String getParentCode() { + return parentCode; + } + public void setParentCode(String parentCode) { + this.parentCode = parentCode; + } + public Long getSort(){ + return sort; + } + public void setSort(Long sort){ + this.sort = sort; + } + + + +} + diff --git a/src/main/java/com/krt/dairy/core/consts/domain/ConstsCollege.java b/src/main/java/com/krt/dairy/core/consts/domain/ConstsCollege.java new file mode 100644 index 0000000..417810d --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/domain/ConstsCollege.java @@ -0,0 +1,48 @@ +package com.krt.dairy.core.consts.domain; + +import com.krt.dairy.common.orm.BaseEntity; + +public class ConstsCollege extends BaseEntity{ + + private static final long serialVersionUID = -7643904360103197835L; + + /** + *名称 + **/ + private String name; + + /** + *编码 + **/ + private String code; + + /** + *图片 + **/ + private String picture; + + public String getName(){ + return name; + } + public void setName(String name){ + this.name = name; + } + + public String getCode(){ + return code; + } + public void setCode(String code){ + this.code = code; + } + + public String getPicture(){ + return picture; + } + public void setPicture(String picture){ + this.picture = picture; + } + + + +} + diff --git a/src/main/java/com/krt/dairy/core/consts/domain/ConstsSiteCarousel.java b/src/main/java/com/krt/dairy/core/consts/domain/ConstsSiteCarousel.java new file mode 100644 index 0000000..c25d9c3 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/domain/ConstsSiteCarousel.java @@ -0,0 +1,71 @@ +package com.krt.dairy.core.consts.domain; + +import com.krt.dairy.common.orm.BaseEntity; + + +public class ConstsSiteCarousel extends BaseEntity{ + + private static final long serialVersionUID = -68528406716367757L; + + /** + *名称 + **/ + private String name; + + /** + *图片 + **/ + private String picture; + + /** + *链接 + **/ + private String url; + + /** + *权重 + **/ + private Integer weight; + + /** + * 是否可用 + */ + private Integer enable; + + + public String getName(){ + return name; + } + public void setName(String name){ + this.name = name; + } + + public String getPicture(){ + return picture; + } + public void setPicture(String picture){ + this.picture = picture; + } + + public String getUrl(){ + return url; + } + public void setUrl(String url){ + this.url = url; + } + + public Integer getWeight(){ + return weight; + } + public void setWeight(Integer weight){ + this.weight = weight; + } + public Integer getEnable() { + return enable; + } + public void setEnable(Integer enable) { + this.enable = enable; + } + +} + diff --git a/src/main/java/com/krt/dairy/core/consts/service/IConstsClassifyService.java b/src/main/java/com/krt/dairy/core/consts/service/IConstsClassifyService.java new file mode 100644 index 0000000..d388d06 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/service/IConstsClassifyService.java @@ -0,0 +1,64 @@ +package com.krt.dairy.core.consts.service; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.consts.domain.ConstsClassify; + +import java.util.List; + + +public interface IConstsClassifyService { + + /** + *根据id获取 + **/ + public ConstsClassify getById(Long id); + + /** + *获取所有 + **/ + public List queryAll(); + + /** + * 根据code获取 + */ + public ConstsClassify getByCode(String code); + + /** + *根据条件动态获取 + **/ + public List queryByCondition(ConstsClassify queryEntity); + + /** + *分页获取 + **/ + public TailPage queryPage(ConstsClassify queryEntity, TailPage page); + + /** + *创建 + **/ + public void create(ConstsClassify entity); + + /** + * 创建 + */ + public void createSelectivity(ConstsClassify entity); + + /** + *根据id 进行可选性更新 + **/ + public void updateSelectivity(ConstsClassify entity); + + /** + *物理删除 + **/ + public void delete(ConstsClassify entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(ConstsClassify entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/consts/service/IConstsCollegeService.java b/src/main/java/com/krt/dairy/core/consts/service/IConstsCollegeService.java new file mode 100644 index 0000000..0512a61 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/service/IConstsCollegeService.java @@ -0,0 +1,64 @@ +package com.krt.dairy.core.consts.service; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.consts.domain.ConstsCollege; + +import java.util.List; + + +public interface IConstsCollegeService { + + /** + *根据id获取 + **/ + public ConstsCollege getById(Long id); + + /** + * 根据code获取 + */ + public ConstsCollege getByCode(String code); + + /** + *获取所有 + **/ + public List queryAll(ConstsCollege queryEntity); + + /** + *分页获取 + **/ + public TailPage queryPage(ConstsCollege queryEntity, TailPage page); + + /** + *创建 + **/ + public void create(ConstsCollege entity); + + /** + * 创建网校 + */ + public void createSelectivity(ConstsCollege entity); + + /** + *根据id更新 + **/ + public void update(ConstsCollege entity); + + /** + *根据id 进行可选性更新 + **/ + public void updateSelectivity(ConstsCollege entity); + + /** + *物理删除 + **/ + public void delete(ConstsCollege entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(ConstsCollege entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/consts/service/IConstsSiteCarouselService.java b/src/main/java/com/krt/dairy/core/consts/service/IConstsSiteCarouselService.java new file mode 100644 index 0000000..27845b1 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/service/IConstsSiteCarouselService.java @@ -0,0 +1,59 @@ +package com.krt.dairy.core.consts.service; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.consts.domain.ConstsSiteCarousel; + +import java.util.List; + + +public interface IConstsSiteCarouselService { + + /** + *根据id获取 + **/ + public ConstsSiteCarousel getById(Long id); + + /** + *获取所有 + **/ + public List queryCarousels(Integer count); + + /** + *分页获取 + **/ + public TailPage queryPage(ConstsSiteCarousel queryEntity, TailPage page); + + /** + *创建 + **/ + public void create(ConstsSiteCarousel entity); + + /** + * 创建新记录 + */ + public void createSelectivity(ConstsSiteCarousel entity); + + /** + *根据id更新 + **/ + public void update(ConstsSiteCarousel entity); + + /** + *根据id 进行可选性更新 + **/ + public void updateSelectivity(ConstsSiteCarousel entity); + + /** + *物理删除 + **/ + public void delete(ConstsSiteCarousel entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(ConstsSiteCarousel entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/consts/service/impl/ConstsClassifyServiceImpl.java b/src/main/java/com/krt/dairy/core/consts/service/impl/ConstsClassifyServiceImpl.java new file mode 100644 index 0000000..e5c2664 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/service/impl/ConstsClassifyServiceImpl.java @@ -0,0 +1,81 @@ +package com.krt.dairy.core.consts.service.impl; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.consts.dao.ConstsClassifyDao; +import com.krt.dairy.core.consts.domain.ConstsClassify; +import com.krt.dairy.core.consts.service.IConstsClassifyService; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + + +@Service +public class ConstsClassifyServiceImpl implements IConstsClassifyService{ + + @Autowired + private ConstsClassifyDao entityDao; + + public ConstsClassify getById(Long id){ + return entityDao.getById(id); + } + + public List queryAll(){ + return entityDao.queryAll(); + } + + @Override + public List queryByCondition(ConstsClassify queryEntity){ + return entityDao.queryByCondition(queryEntity); + } + + @Override + public ConstsClassify getByCode(String code){ + if(StringUtils.isEmpty(code)) + return null; + ConstsClassify queryEntity = new ConstsClassify(); + queryEntity.setCode(code); + List list = entityDao.queryByCondition(queryEntity); + if(CollectionUtils.isNotEmpty(list)) + return list.get(0); + return null; + } + + public TailPage queryPage(ConstsClassify queryEntity ,TailPage page){ + Integer itemsTotalCount = entityDao.getTotalItemsCount(queryEntity); + List items = entityDao.queryPage(queryEntity,page); + page.setItemsTotalCount(itemsTotalCount); + page.setItems(items); + return page; + } + + @Override + public void create(ConstsClassify entity){ + entityDao.create(entity); + } + + @Override + public void createSelectivity(ConstsClassify entity){ + entityDao.createSelectivity(entity); + } + + @Override + public void updateSelectivity(ConstsClassify entity){ + entityDao.updateSelectivity(entity); + } + + @Override + public void delete(ConstsClassify entity){ + entityDao.delete(entity); + } + + @Override + public void deleteLogic(ConstsClassify entity){ + entityDao.deleteLogic(entity); + } + + +} + diff --git a/src/main/java/com/krt/dairy/core/consts/service/impl/ConstsCollegeServiceImpl.java b/src/main/java/com/krt/dairy/core/consts/service/impl/ConstsCollegeServiceImpl.java new file mode 100644 index 0000000..9ddfae9 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/service/impl/ConstsCollegeServiceImpl.java @@ -0,0 +1,76 @@ +package com.krt.dairy.core.consts.service.impl; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.consts.dao.ConstsCollegeDao; +import com.krt.dairy.core.consts.domain.ConstsCollege; +import com.krt.dairy.core.consts.service.IConstsCollegeService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + + +@Service +public class ConstsCollegeServiceImpl implements IConstsCollegeService{ + + @Autowired + private ConstsCollegeDao entityDao; + + /** + * 根据id获取 + */ + public ConstsCollege getById(Long id){ + return entityDao.getById(id); + } + + /** + * 根据code获取 + */ + public ConstsCollege getByCode(String code){ + return entityDao.getByCode(code); + } + + public List queryAll(ConstsCollege queryEntity){ + return entityDao.queryAll(queryEntity); + } + + public TailPage queryPage(ConstsCollege queryEntity ,TailPage page){ + Integer itemsTotalCount = entityDao.getTotalItemsCount(queryEntity); + List items = entityDao.queryPage(queryEntity,page); + page.setItemsTotalCount(itemsTotalCount); + page.setItems(items); + return page; + } + + public void create(ConstsCollege entity){ + entityDao.create(entity); + } + + /** + * 创建网校 + */ + public void createSelectivity(ConstsCollege entity){ + this.entityDao.createSelectivity(entity); + } + + public void update(ConstsCollege entity){ + entityDao.update(entity); + } + + public void updateSelectivity(ConstsCollege entity){ + entityDao.updateSelectivity(entity); + } + + public void delete(ConstsCollege entity){ + entityDao.delete(entity); + } + + public void deleteLogic(ConstsCollege entity){ + entityDao.deleteLogic(entity); + } + + + +} + diff --git a/src/main/java/com/krt/dairy/core/consts/service/impl/ConstsSiteCarouselServiceImpl.java b/src/main/java/com/krt/dairy/core/consts/service/impl/ConstsSiteCarouselServiceImpl.java new file mode 100644 index 0000000..3f5bd68 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/consts/service/impl/ConstsSiteCarouselServiceImpl.java @@ -0,0 +1,86 @@ +package com.krt.dairy.core.consts.service.impl; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.common.storage.QiniuStorage; +import com.krt.dairy.core.consts.dao.ConstsSiteCarouselDao; +import com.krt.dairy.core.consts.domain.ConstsSiteCarousel; +import com.krt.dairy.core.consts.service.IConstsSiteCarouselService; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + + +@Service +public class ConstsSiteCarouselServiceImpl implements IConstsSiteCarouselService{ + + @Autowired + private ConstsSiteCarouselDao entityDao; + + @Override + public ConstsSiteCarousel getById(Long id){ + return entityDao.getById(id); + } + + @Override + public List queryCarousels(Integer count){ + List resultList = entityDao.queryCarousels(count); + //处理为七牛图片链接 + for(ConstsSiteCarousel item : resultList){ + item.setPicture(QiniuStorage.getUrl(item.getPicture())); + } + return resultList; + } + + @Override + public TailPage queryPage(ConstsSiteCarousel queryEntity ,TailPage page){ + Integer itemsTotalCount = entityDao.getTotalItemsCount(queryEntity); + List items = entityDao.queryPage(queryEntity,page); + if(CollectionUtils.isNotEmpty(items)){ + for(ConstsSiteCarousel item : items){ + String pictureUrl = QiniuStorage.getUrl(item.getPicture());//处理图片 + item.setPicture(pictureUrl); + } + } + page.setItemsTotalCount(itemsTotalCount); + page.setItems(items); + return page; + } + + @Override + public void create(ConstsSiteCarousel entity){ + entityDao.create(entity); + } + + /** + * 创建新记录 + */ + public void createSelectivity(ConstsSiteCarousel entity){ + this.entityDao.createSelectivity(entity); + } + + @Override + public void update(ConstsSiteCarousel entity){ + entityDao.update(entity); + } + + @Override + public void updateSelectivity(ConstsSiteCarousel entity){ + entityDao.updateSelectivity(entity); + } + + @Override + public void delete(ConstsSiteCarousel entity){ + entityDao.delete(entity); + } + + @Override + public void deleteLogic(ConstsSiteCarousel entity){ + entityDao.deleteLogic(entity); + } + + + +} + diff --git a/src/main/java/com/krt/dairy/core/course/dao/CourseCommentDao.java b/src/main/java/com/krt/dairy/core/course/dao/CourseCommentDao.java new file mode 100644 index 0000000..b5c2354 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/dao/CourseCommentDao.java @@ -0,0 +1,75 @@ +package com.krt.dairy.core.course.dao; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.course.domain.CourseComment; + +import java.util.List; + + +public interface CourseCommentDao { + + /** + *根据id获取 + **/ + public CourseComment getById(Long id); + + /** + *获取所有 + **/ + public List queryAll(CourseComment queryEntity); + + /** + *获取总数量 + **/ + public Integer getTotalItemsCount(CourseComment queryEntity); + + /** + *分页获取 + **/ + public List queryPage(CourseComment queryEntity, TailPage page); + + + /** + *获取总数量 + **/ + public Integer getMyQAItemsCount(CourseComment queryEntity); + + /** + *分页获取 + **/ + public List queryMyQAItemsPage(CourseComment queryEntity, TailPage page); + + /** + *创建新记录 + **/ + public void create(CourseComment entity); + + /** + * 创建新记录 + */ + public void createSelectivity(CourseComment entity); + + /** + *根据id更新 + **/ + public void update(CourseComment entity); + + /** + *根据id选择性更新自动 + **/ + public void updateSelectivity(CourseComment entity); + + /** + *物理删除 + **/ + public void delete(CourseComment entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(CourseComment entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/course/dao/CourseCommentMapper.xml b/src/main/java/com/krt/dairy/core/course/dao/CourseCommentMapper.xml new file mode 100644 index 0000000..4fda32a --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/dao/CourseCommentMapper.xml @@ -0,0 +1,286 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + username, to_username, course_id, section_id, section_title, content, + ref_id, ref_content, type, create_time, create_user, update_time, + update_user, del, id + + + + + + + + + + + + + + + + + INSERT INTO t_course_comment + ( username, to_username, course_id, section_id, SECTION_TITLE, content, + ref_id, ref_content, type, create_time, create_user, update_time, + update_user, del, id ) + VALUES + ( #{username, jdbcType=VARCHAR}, #{toUsername, jdbcType=VARCHAR}, #{courseId, jdbcType=VARCHAR}, #{sectionId, jdbcType=VARCHAR}, #{sectionTitle, jdbcType=VARCHAR}, #{content, jdbcType=VARCHAR}, + #{refId, jdbcType=VARCHAR}, #{refContent, jdbcType=VARCHAR}, #{type, jdbcType=INTEGER}, #{createTime, jdbcType=DATE}, #{createUser, jdbcType=VARCHAR}, #{updateTime, jdbcType=TIMESTAMP}, + #{updateUser, jdbcType=VARCHAR}, #{del, jdbcType=TINYINT}, #{id, jdbcType=VARCHAR} ) + + + + INSERT INTO t_course_comment + + + username, + + + to_username, + + + course_id, + + + section_id, + + + SECTION_TITLE, + + + content, + + + ref_id, + + + ref_content, + + + type, + + + create_time, + + + create_user, + + + update_time, + + + update_user, + + + del, + + + VALUES + + + #{username, jdbcType=VARCHAR}, + + + #{toUsername, jdbcType=VARCHAR}, + + + #{courseId, jdbcType=INTEGER}, + + + #{sectionId, jdbcType=INTEGER}, + + + #{sectionTitle, jdbcType=VARCHAR}, + + + #{content, jdbcType=VARCHAR}, + + + #{refId, jdbcType=INTEGER}, + + + #{refContent, jdbcType=VARCHAR}, + + + #{type, jdbcType=INTEGER}, + + + #{createTime, jdbcType=DATE}, + + + #{createUser, jdbcType=VARCHAR}, + + + #{updateTime, jdbcType=TIMESTAMP}, + + + #{updateUser, jdbcType=VARCHAR}, + + + #{del, jdbcType=TINYINT}, + + + + + + UPDATE t_course_comment SET + username = #{username, jdbcType=VARCHAR}, + to_username = #{toUsername, jdbcType=VARCHAR}, + course_id = #{courseId, jdbcType=VARCHAR}, + section_id = #{sectionId, jdbcType=VARCHAR}, + SECTION_TITLE = #{sectionTitle, jdbcType=VARCHAR}, + content = #{content, jdbcType=VARCHAR}, + ref_id = #{refId, jdbcType=VARCHAR}, + ref_content = #{refContent, jdbcType=VARCHAR}, + type = #{type, jdbcType=INTEGER}, + update_time = #{updateTime, jdbcType=TIMESTAMP}, + update_user = #{updateUser, jdbcType=VARCHAR} + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_course_comment + + + username = #{username, jdbcType=VARCHAR}, + + + to_username = #{toUsername, jdbcType=VARCHAR}, + + + course_id = #{courseId, jdbcType=VARCHAR}, + + + section_id = #{sectionId, jdbcType=VARCHAR}, + + + section_title = #{sectionTitle, jdbcType=VARCHAR}, + + + content = #{content, jdbcType=VARCHAR}, + + + ref_id = #{refId, jdbcType=VARCHAR}, + + + ref_content = #{refContent, jdbcType=VARCHAR}, + + + type = #{type, jdbcType=INTEGER}, + + + update_time = #{updateTime, jdbcType=TIMESTAMP}, + + + update_user = #{updateUser, jdbcType=VARCHAR}, + + + del = #{del, jdbcType=TINYINT}, + + + WHERE id = #{id, jdbcType = INTEGER} + + + + + DELETE FROM t_course_comment + WHERE id = #{id, jdbcType=INTEGER} + OR ref_id = #{id, jdbcType=INTEGER} + + + + UPDATE t_course_comment + SET del = 1 + WHERE id = #{id, jdbcType=INTEGER} + OR ref_id = #{id, jdbcType=INTEGER} + + + diff --git a/src/main/java/com/krt/dairy/core/course/dao/CourseDao.java b/src/main/java/com/krt/dairy/core/course/dao/CourseDao.java new file mode 100644 index 0000000..f2860db --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/dao/CourseDao.java @@ -0,0 +1,62 @@ +package com.krt.dairy.core.course.dao; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.course.domain.Course; +import com.krt.dairy.core.course.domain.CourseQueryDto; + +import java.util.List; + + +public interface CourseDao { + + /** + *根据id获取 + **/ + public Course getById(Long id); + + /** + *根据条件获取所有, + *queryEntity:查询条件; + **/ + public List queryList(CourseQueryDto queryEntity); + + /** + *获取总数量 + **/ + public Integer getTotalItemsCount(Course queryEntity); + + /** + *分页获取 + **/ + public List queryPage(Course queryEntity, TailPage page); + + /** + *创建新记录 + **/ + public void create(Course entity); + public void createSelectivity(Course entity); + + /** + *根据id更新 + **/ + public void update(Course entity); + + /** + *根据id选择性更新自动 + **/ + public void updateSelectivity(Course entity); + + /** + *物理删除 + **/ + public void delete(Course entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(Course entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/course/dao/CourseMapper.xml b/src/main/java/com/krt/dairy/core/course/dao/CourseMapper.xml new file mode 100644 index 0000000..2527f63 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/dao/CourseMapper.xml @@ -0,0 +1,401 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + name, type, classify, classify_name, sub_classify, sub_classify_name, direction, username, + level, free, price, time, onsale, brief, picture, + recommend, weight, study_count, create_time, create_user, update_time, + update_user, del, id + + + + + + + + + + + + INSERT INTO t_course + + + name, + + + type, + + + classify, + + + classify_name, + + + sub_classify, + + + sub_classify_name, + + + direction, + + + username, + + + level, + + + free, + + + price, + + + time, + + + onsale, + + + brief, + + + picture, + + + recommend, + + + weight, + + + study_count, + + + create_time, + + + create_user, + + + update_time, + + + update_user, + + + del, + + + VALUES + + + #{name, jdbcType=VARCHAR}, + + + #{type, jdbcType=VARCHAR}, + + + #{classify, jdbcType=VARCHAR}, + + + #{classifyName, jdbcType=VARCHAR}, + + + #{subClassify, jdbcType=VARCHAR}, + + + #{subClassifyName, jdbcType=VARCHAR}, + + + #{direction, jdbcType=VARCHAR}, + + + #{username, jdbcType=INTEGER}, + + + #{level, jdbcType=INTEGER}, + + + #{free, jdbcType=INTEGER}, + + + #{price, jdbcType=DECIMAL}, + + + #{time, jdbcType=VARCHAR}, + + + #{onsale, jdbcType=INTEGER}, + + + #{brief, jdbcType=VARCHAR}, + + + #{picture, jdbcType=VARCHAR}, + + + #{recommend, jdbcType=INTEGER}, + + + #{weight, jdbcType=INTEGER}, + + + #{studyCount, jdbcType=INTEGER}, + + + #{createTime, jdbcType=DATE}, + + + #{createUser, jdbcType=VARCHAR}, + + + #{updateTime, jdbcType=TIMESTAMP}, + + + #{updateUser, jdbcType=VARCHAR}, + + + #{del, jdbcType=TINYINT}, + + + + + + UPDATE t_course + + + name = #{name, jdbcType=VARCHAR}, + + + type = #{type, jdbcType=VARCHAR}, + + + classify = #{classify, jdbcType=VARCHAR}, + + + classify_name = #{classifyName, jdbcType=VARCHAR}, + + + sub_classify = #{subClassify, jdbcType=VARCHAR}, + + + sub_classify_name = #{subClassifyName, jdbcType=VARCHAR}, + + + direction = #{direction, jdbcType=VARCHAR}, + + + username = #{username, jdbcType=VARCHAR}, + + + level = #{level, jdbcType=INTEGER}, + + + free = #{free, jdbcType=INTEGER}, + + + price = #{price, jdbcType=VARCHAR}, + + + time = #{time, jdbcType=VARCHAR}, + + + onsale = #{onsale, jdbcType=INTEGER}, + + + brief = #{brief, jdbcType=VARCHAR}, + + + picture = #{picture, jdbcType=VARCHAR}, + + + recommend = #{recommend, jdbcType=INTEGER}, + + + weight = #{weight, jdbcType=INTEGER}, + + + study_count = #{studyCount, jdbcType=INTEGER}, + + + update_time = #{updateTime, jdbcType=TIMESTAMP}, + + + update_user = #{updateUser, jdbcType=VARCHAR}, + + + del = #{del, jdbcType=TINYINT}, + + + WHERE id = #{id, jdbcType = INTEGER} + + + + INSERT INTO t_course + ( name, type, classify, classify_name, sub_classify, sub_classify_name, direction, username, + level, free, price, time, onsale, brief, picture, + recommend, weight, study_count, create_time, create_user, update_time, + update_user, del, id ) + VALUES + ( #{name, jdbcType=VARCHAR}, #{type, jdbcType=VARCHAR}, #{classify, jdbcType=VARCHAR}, #{classifyName, jdbcType=VARCHAR}, #{subClassify, jdbcType=VARCHAR}, #{subClassifyName, jdbcType=VARCHAR}, #{direction, jdbcType=VARCHAR}, #{username, jdbcType=VARCHAR}, + #{level, jdbcType=INTEGER}, #{free, jdbcType=INTEGER}, #{price, jdbcType=VARCHAR}, #{time, jdbcType=VARCHAR}, #{onsale, jdbcType=INTEGER}, #{brief, jdbcType=VARCHAR}, #{picture, jdbcType=VARCHAR}, + #{recommend, jdbcType=INTEGER}, #{weight, jdbcType=INTEGER}, #{studyCount, jdbcType=INTEGER}, #{createTime, jdbcType=DATE}, #{createUser, jdbcType=VARCHAR}, #{updateTime, jdbcType=TIMESTAMP}, + #{updateUser, jdbcType=VARCHAR}, #{del, jdbcType=TINYINT}, #{id, jdbcType=VARCHAR} ) + + + + UPDATE t_course SET + name = #{name, jdbcType=VARCHAR}, + type = #{type, jdbcType=VARCHAR}, + classify = #{classify, jdbcType=VARCHAR}, + classify_name = #{classifyName, jdbcType=VARCHAR}, + sub_classify = #{subClassify, jdbcType=VARCHAR}, + sub_classify_name = #{subClassifyName, jdbcType=VARCHAR}, + direction = #{direction, jdbcType=VARCHAR}, + USERNAME = #{username, jdbcType=VARCHAR}, + level = #{level, jdbcType=INTEGER}, + free = #{free, jdbcType=INTEGER}, + price = #{price, jdbcType=VARCHAR}, + time = #{time, jdbcType=VARCHAR}, + onsale = #{onsale, jdbcType=INTEGER}, + brief = #{brief, jdbcType=VARCHAR}, + picture = #{picture, jdbcType=VARCHAR}, + recommend = #{recommend, jdbcType=INTEGER}, + weight = #{weight, jdbcType=INTEGER}, + study_count = #{studyCount, jdbcType=INTEGER}, + update_time = #{updateTime, jdbcType=TIMESTAMP}, + update_user = #{updateUser, jdbcType=VARCHAR} + WHERE id = #{id, jdbcType=INTEGER} + + + + DELETE + FROM t_course + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_course + SET del = 1 + WHERE id = #{id, jdbcType=INTEGER} + + + diff --git a/src/main/java/com/krt/dairy/core/course/dao/CourseSectionDao.java b/src/main/java/com/krt/dairy/core/course/dao/CourseSectionDao.java new file mode 100644 index 0000000..83c121b --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/dao/CourseSectionDao.java @@ -0,0 +1,92 @@ +package com.krt.dairy.core.course.dao; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.course.domain.CourseSection; + +import java.util.List; + + +public interface CourseSectionDao { + + /** + *根据id获取 + **/ + public CourseSection getById(Long id); + + /** + *获取所有 + **/ + public List queryAll(CourseSection queryEntity); + + /** + * + */ + public Integer getMaxSort(Long courseId); + + /** + *获取总数量 + **/ + public Integer getTotalItemsCount(CourseSection queryEntity); + + /** + *分页获取 + **/ + public List queryPage(CourseSection queryEntity, TailPage page); + + /** + *创建新记录 + **/ + public void createSelectivity(CourseSection entity); + + /** + * 批量创建 + */ + public void createList(List entityList); + + /** + *根据id更新 + **/ + public void update(CourseSection entity); + + /** + *根据id选择性更新自动 + **/ + public void updateSelectivity(CourseSection entity); + + /** + *物理删除 + **/ + public void delete(CourseSection entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(CourseSection entity); + + /** + *物理删除课程对应的章节 + **/ + public void deleteByCourseId(CourseSection entity); + + /** + *逻辑删除课程对应的章节 + **/ + public void deleteLogicByCourseId(CourseSection entity); + + + /** + * 比当前sort大的,正序排序的第一个 + * @param curCourseSection + * @return + */ + public CourseSection getSortSectionMax(CourseSection curCourseSection); + + /** + * 比当前sort小的,倒序排序的第一个 + * @param curCourseSection + * @return + */ + public CourseSection getSortSectionMin(CourseSection curCourseSection); + +} + diff --git a/src/main/java/com/krt/dairy/core/course/dao/CourseSectionMapper.xml b/src/main/java/com/krt/dairy/core/course/dao/CourseSectionMapper.xml new file mode 100644 index 0000000..a184459 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/dao/CourseSectionMapper.xml @@ -0,0 +1,273 @@ + + + + + + + + + + + + + + + + + + + + + + + + course_id, parent_id, name, sort, time, onsale, video_url, + create_time, create_user, update_time, update_user, del, id + + + + + + + + + + + + + + INSERT INTO t_course_section + ( course_id, parent_id, name, sort, time, onsale, video_url, + CREATE_TIME, CREATE_USER, update_time, update_user, del, id ) + VALUES + ( #{courseId, jdbcType=VARCHAR}, #{parentId, jdbcType=VARCHAR}, #{name, jdbcType=VARCHAR}, #{sort, jdbcType=INTEGER}, #{time, jdbcType=VARCHAR}, #{onsale, jdbcType=INTEGER}, #{videoUrl, jdbcType=VARCHAR}, + #{createTime, jdbcType=DATE}, #{createUser, jdbcType=VARCHAR}, #{updateTime, jdbcType=TIMESTAMP}, #{updateUser, jdbcType=VARCHAR}, #{del, jdbcType=TINYINT}, #{id, jdbcType=VARCHAR} ) + + + + INSERT INTO t_course_section + + + course_id, + + + parent_id, + + + name, + + + sort, + + + time, + + + onsale, + + + video_url, + + + CREATE_TIME, + + + CREATE_USER, + + + update_time, + + + update_user, + + + del, + + + VALUES + + + #{courseId, jdbcType=INTEGER}, + + + #{parentId, jdbcType=INTEGER}, + + + #{name, jdbcType=VARCHAR}, + + + #{sort, jdbcType=INTEGER}, + + + #{time, jdbcType=VARCHAR}, + + + #{onsale, jdbcType=INTEGER}, + + + #{videoUrl, jdbcType=VARCHAR}, + + + #{createTime, jdbcType=DATE}, + + + #{createUser, jdbcType=VARCHAR}, + + + #{updateTime, jdbcType=TIMESTAMP}, + + + #{updateUser, jdbcType=VARCHAR}, + + + #{del, jdbcType=TINYINT}, + + + + + + INSERT INTO t_course_section + ( course_id, parent_id, name, sort, time, onsale, video_url, + CREATE_TIME, CREATE_USER, update_time, update_user, del ) + VALUES + + ( #{item.courseId, jdbcType=VARCHAR}, #{item.parentId, jdbcType=VARCHAR}, #{item.name, jdbcType=VARCHAR}, #{item.sort, jdbcType=INTEGER}, #{item.time, jdbcType=VARCHAR}, #{item.onsale, jdbcType=INTEGER}, #{item.videoUrl, jdbcType=VARCHAR}, + #{item.createTime, jdbcType=DATE}, #{item.createUser, jdbcType=VARCHAR}, #{item.updateTime, jdbcType=TIMESTAMP}, #{item.updateUser, jdbcType=VARCHAR}, #{item.del, jdbcType=TINYINT}) + + + + + UPDATE t_course_section SET + course_id = #{courseId, jdbcType=VARCHAR}, + parent_id = #{parentId, jdbcType=VARCHAR}, + name = #{name, jdbcType=VARCHAR}, + sort = #{sort, jdbcType=INTEGER}, + time = #{time, jdbcType=VARCHAR}, + onsale = #{onsale, jdbcType=INTEGER}, + video_url = #{videoUrl, jdbcType=VARCHAR}, + update_time = #{updateTime, jdbcType=TIMESTAMP}, + update_user = #{updateUser, jdbcType=VARCHAR} + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_course_section + + + course_id = #{courseId, jdbcType=VARCHAR}, + + + parent_id = #{parentId, jdbcType=VARCHAR}, + + + name = #{name, jdbcType=VARCHAR}, + + + sort = #{sort, jdbcType=INTEGER}, + + + time = #{time, jdbcType=VARCHAR}, + + + onsale = #{onsale, jdbcType=INTEGER}, + + + video_url = #{videoUrl, jdbcType=VARCHAR}, + + + update_time = #{updateTime, jdbcType=TIMESTAMP}, + + + update_user = #{updateUser, jdbcType=VARCHAR}, + + + del = #{del, jdbcType=TINYINT}, + + + WHERE id = #{id, jdbcType = INTEGER} + + + + + DELETE FROM t_course_section + WHERE id = #{id, jdbcType=INTEGER} + OR parent_id = #{id, jdbcType=INTEGER} + + + + UPDATE t_course_section + SET del = 1 + WHERE id = #{id, jdbcType=INTEGER} + OR parent_id = #{id, jdbcType=INTEGER} + + + + DELETE FROM t_course_section + WHERE course_id = #{courseId, jdbcType=INTEGER} + + + + UPDATE t_course_section + SET del = 1 + WHERE course_id = #{courseId, jdbcType=INTEGER} + + + + + + + + diff --git a/src/main/java/com/krt/dairy/core/course/domain/Course.java b/src/main/java/com/krt/dairy/core/course/domain/Course.java new file mode 100644 index 0000000..4826bc4 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/domain/Course.java @@ -0,0 +1,225 @@ +package com.krt.dairy.core.course.domain; + +import com.krt.dairy.common.orm.BaseEntity; + +import java.math.BigDecimal; + + +public class Course extends BaseEntity{ + + private static final long serialVersionUID = -935786327879089574L; + + /** + *课程名称 + **/ + private String name; + + /** + *课程类型 + **/ + private String type; + + /** + *课程分类 + **/ + private String classify; + + /** + * 课程分类名称 + */ + private String classifyName; + + /** + *课程二级分类 + **/ + private String subClassify; + + /** + * 课程二级分类名称 + */ + private String subClassifyName; + + /** + *课程方向 + **/ + private String direction; + + /** + *归属人 + **/ + private String username; + + /** + *课程级别:1-初级,2-中级,3-高级 + **/ + private Integer level; + + /** + *是否免费:0-否,1-是 + **/ + private Integer free; + + /** + *课程价格 + **/ + private BigDecimal price; + + /** + *时长 + **/ + private String time; + + /** + *未上架(0)、上架(1) + **/ + private Integer onsale; + + /** + *课程描述 + **/ + private String brief; + + /** + * 课程图片 + */ + private String picture; + + /** + *未推荐(0)、推荐(1) + **/ + private Integer recommend; + + /** + *权重 + **/ + private Integer weight; + + /** + *学习人数 + **/ + private Integer studyCount; + + public String getName(){ + return name; + } + public void setName(String name){ + this.name = name; + } + + public String getType(){ + return type; + } + public void setType(String type){ + this.type = type; + } + + public String getClassify(){ + return classify; + } + public void setClassify(String classify){ + this.classify = classify; + } + + public String getClassifyName() { + return classifyName; + } + public void setClassifyName(String classifyName) { + this.classifyName = classifyName; + } + public String getSubClassify(){ + return subClassify; + } + public void setSubClassify(String subClassify){ + this.subClassify = subClassify; + } + + public String getSubClassifyName() { + return subClassifyName; + } + public void setSubClassifyName(String subClassifyName) { + this.subClassifyName = subClassifyName; + } + public String getDirection(){ + return direction; + } + public void setDirection(String direction){ + this.direction = direction; + } + + public String getUsername() { + return username; + } + public void setUsername(String username) { + this.username = username; + } + public Integer getLevel(){ + return level; + } + public void setLevel(Integer level){ + this.level = level; + } + + public Integer getFree(){ + return free; + } + public void setFree(Integer free){ + this.free = free; + } + + public BigDecimal getPrice(){ + return price; + } + public void setPrice(BigDecimal price){ + this.price = price; + } + + public String getTime(){ + return time; + } + public void setTime(String time){ + this.time = time; + } + + public Integer getOnsale(){ + return onsale; + } + public void setOnsale(Integer onsale){ + this.onsale = onsale; + } + + public String getBrief(){ + return brief; + } + public void setBrief(String brief){ + this.brief = brief; + } + + public Integer getRecommend(){ + return recommend; + } + public void setRecommend(Integer recommend){ + this.recommend = recommend; + } + + public Integer getWeight(){ + return weight; + } + public void setWeight(Integer weight){ + this.weight = weight; + } + + public Integer getStudyCount(){ + return studyCount; + } + public void setStudyCount(Integer studyCount){ + this.studyCount = studyCount; + } + public String getPicture() { + return picture; + } + public void setPicture(String picture) { + this.picture = picture; + } + +} + diff --git a/src/main/java/com/krt/dairy/core/course/domain/CourseComment.java b/src/main/java/com/krt/dairy/core/course/domain/CourseComment.java new file mode 100644 index 0000000..985c487 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/domain/CourseComment.java @@ -0,0 +1,144 @@ +package com.krt.dairy.core.course.domain; + +import com.krt.dairy.common.orm.BaseEntity; + +/** + * 课程评论&QA + */ +public class CourseComment extends BaseEntity{ + + private static final long serialVersionUID = 789165716801545108L; + + /** + *用户username + **/ + private String username; + + /** + *评论对象username + **/ + private String toUsername; + + /** + *课程id + **/ + private Long courseId; + + /** + *章节id + **/ + private Long sectionId; + + /** + *章节标题 + **/ + private String sectionTitle; + + /** + *评论内容 + **/ + private String content; + + /** + *引用id + **/ + private Long refId; + + /** + *引用内容 + **/ + private String refContent; + + /** + *类型:0-评论;1-答疑QA + **/ + private Integer type; + + + /** + * 用户头像 + */ + private String header; + + /** + * 课程名称 + */ + private String courseName; + + public String getUsername(){ + return username; + } + public void setUsername(String username){ + this.username = username; + } + + public String getToUsername(){ + return toUsername; + } + public void setToUsername(String toUsername){ + this.toUsername = toUsername; + } + + public Long getCourseId(){ + return courseId; + } + public void setCourseId(Long courseId){ + this.courseId = courseId; + } + + public Long getSectionId(){ + return sectionId; + } + public void setSectionId(Long sectionId){ + this.sectionId = sectionId; + } + + public String getSectionTitle(){ + return sectionTitle; + } + public void setSectionTitle(String sectionTitle){ + this.sectionTitle = sectionTitle; + } + + public String getContent(){ + return content; + } + public void setContent(String content){ + this.content = content; + } + + public Long getRefId(){ + return refId; + } + public void setRefId(Long refId){ + this.refId = refId; + } + + public String getRefContent(){ + return refContent; + } + public void setRefContent(String refContent){ + this.refContent = refContent; + } + + public Integer getType(){ + return type; + } + public void setType(Integer type){ + this.type = type; + } + public String getHeader() { + return header; + } + public void setHeader(String header) { + this.header = header; + } + public String getCourseName() { + return courseName; + } + public void setCourseName(String courseName) { + this.courseName = courseName; + } + +} + diff --git a/src/main/java/com/krt/dairy/core/course/domain/CourseQueryDto.java b/src/main/java/com/krt/dairy/core/course/domain/CourseQueryDto.java new file mode 100644 index 0000000..a135f16 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/domain/CourseQueryDto.java @@ -0,0 +1,76 @@ +package com.krt.dairy.core.course.domain; + +import com.krt.dairy.common.util.BeanUtil; +import org.apache.commons.lang.StringUtils; + +/** + * 课程查询实体类 + */ +public class CourseQueryDto extends Course{ + + private static final long serialVersionUID = 6928526481007198051L; + + private String sortField; + + private String sortDirection = "DESC"; + + private Integer start=0;//limit开始 + + private Integer count;//数量 + + private Integer end;//limit结束 + + + public String getSortField() { + return sortField; + } + + /** + * 按照sortField升序 + * @param sortField:指java bean中的属性 + */ + public void ascSortField(String sortField) { + if(StringUtils.isNotEmpty(sortField)){ + this.sortField = BeanUtil.fieldToColumn(sortField); + this.sortDirection = " ASC "; + } + } + + /** + * 按照sortField降序 + * @param sortField :指java bean中的属性 + */ + public void descSortField(String sortField) { + if(StringUtils.isNotEmpty(sortField)){ + this.sortField = BeanUtil.fieldToColumn(sortField); + this.sortDirection = " DESC "; + } + } + + public String getSortDirection() { + return sortDirection; + } + + public Integer getStart() { + return start; + } + + public void setStart(Integer start) { + this.start = start; + } + + public void setCount(Integer count) { + this.count = count; + } + + public Integer getEnd() { + if(null != this.count){ + if(null == this.start){ + this.start = 0; + } + this.end = this.start + this.count; + } + return end; + } + +} diff --git a/src/main/java/com/krt/dairy/core/course/domain/CourseSection.java b/src/main/java/com/krt/dairy/core/course/domain/CourseSection.java new file mode 100644 index 0000000..4590aa8 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/domain/CourseSection.java @@ -0,0 +1,96 @@ +package com.krt.dairy.core.course.domain; + +import com.krt.dairy.common.orm.BaseEntity; + +/** + * 课程章节 + */ +public class CourseSection extends BaseEntity{ + + private static final long serialVersionUID = -7261405404725335316L; + + /** + *归属课程id + **/ + private Long courseId; + + /** + *父章节id,(只有2级) + **/ + private Long parentId; + + /** + *章节名称 + **/ + private String name; + + /** + *排序 + **/ + private Integer sort; + + /** + *时长 + **/ + private String time; + + /** + *未上架(0)、上架(1) + **/ + private Integer onsale; + + /** + * 视频url + */ + private String videoUrl; + + public Long getCourseId(){ + return courseId; + } + public void setCourseId(Long courseId){ + this.courseId = courseId; + } + + public Long getParentId(){ + return parentId; + } + public void setParentId(Long parentId){ + this.parentId = parentId; + } + + public String getName(){ + return name; + } + public void setName(String name){ + this.name = name; + } + + public Integer getSort(){ + return sort; + } + public void setSort(Integer sort){ + this.sort = sort; + } + + public String getTime(){ + return time; + } + public void setTime(String time){ + this.time = time; + } + + public Integer getOnsale(){ + return onsale; + } + public void setOnsale(Integer onsale){ + this.onsale = onsale; + } + public String getVideoUrl() { + return videoUrl; + } + public void setVideoUrl(String videoUrl) { + this.videoUrl = videoUrl; + } + +} + diff --git a/src/main/java/com/krt/dairy/core/course/service/ICourseCommentService.java b/src/main/java/com/krt/dairy/core/course/service/ICourseCommentService.java new file mode 100644 index 0000000..158a866 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/service/ICourseCommentService.java @@ -0,0 +1,64 @@ +package com.krt.dairy.core.course.service; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.course.domain.CourseComment; + +import java.util.List; + + +public interface ICourseCommentService { + + /** + *根据id获取 + **/ + public CourseComment getById(Long id); + + /** + *获取所有 + **/ + public List queryAll(CourseComment queryEntity); + + /** + *分页获取 + **/ + public TailPage queryPage(CourseComment queryEntity, TailPage page); + + /** + * 分页获取我的所有课程的qa + */ + public TailPage queryMyQAItemsPage(CourseComment queryEntity, TailPage page); + + /** + *创建 + **/ + public void create(CourseComment entity); + + /** + * 创建 + */ + public void createSelectivity(CourseComment entity); + + /** + *根据id更新 + **/ + public void update(CourseComment entity); + + /** + *根据id 进行可选性更新 + **/ + public void updateSelectivity(CourseComment entity); + + /** + *物理删除 + **/ + public void delete(CourseComment entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(CourseComment entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/course/service/ICourseSectionService.java b/src/main/java/com/krt/dairy/core/course/service/ICourseSectionService.java new file mode 100644 index 0000000..a99b762 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/service/ICourseSectionService.java @@ -0,0 +1,75 @@ +package com.krt.dairy.core.course.service; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.course.domain.CourseSection; + +import java.util.List; + + +public interface ICourseSectionService { + + /** + *根据id获取 + **/ + public CourseSection getById(Long id); + + /** + *获取所有 + **/ + public List queryAll(CourseSection queryEntity); + + /** + * 获取课程章最大的sort + */ + public Integer getMaxSort(Long courseId); + + /** + *分页获取 + **/ + public TailPage queryPage(CourseSection queryEntity, TailPage page); + + /** + *创建 + **/ + public void createSelectivity(CourseSection entity); + + /** + *批量创建 + **/ + public void createList(List entityList); + + /** + *根据id更新 + **/ + public void update(CourseSection entity); + + /** + *根据id 进行可选性更新 + **/ + public void updateSelectivity(CourseSection entity); + + /** + *物理删除 + **/ + public void delete(CourseSection entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(CourseSection entity); + + /** + * 比当前sort大的,正序排序的第一个 + * @param curCourseSection + * @return + */ + public CourseSection getSortSectionMax(CourseSection curCourseSection); + + /** + * 比当前sort小的,倒序排序的第一个 + * @param curCourseSection + * @return + */ + public CourseSection getSortSectionMin(CourseSection curCourseSection); +} + diff --git a/src/main/java/com/krt/dairy/core/course/service/ICourseService.java b/src/main/java/com/krt/dairy/core/course/service/ICourseService.java new file mode 100644 index 0000000..3bd32d1 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/service/ICourseService.java @@ -0,0 +1,50 @@ +package com.krt.dairy.core.course.service; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.course.domain.Course; +import com.krt.dairy.core.course.domain.CourseQueryDto; + +import java.util.List; + +/** + * 课程服务层 + */ +public interface ICourseService { + + /** + *根据id获取 + **/ + public Course getById(Long id); + + /** + *获取所有 + **/ + public List queryList(CourseQueryDto queryEntity); + + /** + *分页获取 + **/ + public TailPage queryPage(Course queryEntity, TailPage page); + + /** + *创建 + **/ + public void createSelectivity(Course entity); + + /** + *根据id 进行可选性更新 + **/ + public void updateSelectivity(Course entity); + + /** + *物理删除 + **/ + public void delete(Course entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(Course entity); + +} + diff --git a/src/main/java/com/krt/dairy/core/course/service/impl/CourseCommentServiceImpl.java b/src/main/java/com/krt/dairy/core/course/service/impl/CourseCommentServiceImpl.java new file mode 100644 index 0000000..ef46133 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/service/impl/CourseCommentServiceImpl.java @@ -0,0 +1,82 @@ +package com.krt.dairy.core.course.service.impl; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.course.dao.CourseCommentDao; +import com.krt.dairy.core.course.domain.CourseComment; +import com.krt.dairy.core.course.service.ICourseCommentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + + +@Service +public class CourseCommentServiceImpl implements ICourseCommentService{ + + @Autowired + private CourseCommentDao entityDao; + + @Override + public CourseComment getById(Long id){ + return entityDao.getById(id); + } + + @Override + public List queryAll(CourseComment queryEntity){ + return entityDao.queryAll(queryEntity); + } + + @Override + public TailPage queryPage(CourseComment queryEntity ,TailPage page){ + Integer itemsTotalCount = entityDao.getTotalItemsCount(queryEntity); + List items = entityDao.queryPage(queryEntity,page); + page.setItemsTotalCount(itemsTotalCount); + page.setItems(items); + return page; + } + + @Override + public TailPage queryMyQAItemsPage(CourseComment queryEntity ,TailPage page){ + Integer itemsTotalCount = entityDao.getMyQAItemsCount(queryEntity); + List items = entityDao.queryMyQAItemsPage(queryEntity,page); + page.setItemsTotalCount(itemsTotalCount); + page.setItems(items); + return page; + } + + @Override + public void create(CourseComment entity){ + entityDao.create(entity); + } + + /** + * 创建 + */ + public void createSelectivity(CourseComment entity){ + entityDao.createSelectivity(entity); + } + + @Override + public void update(CourseComment entity){ + entityDao.update(entity); + } + + @Override + public void updateSelectivity(CourseComment entity){ + entityDao.updateSelectivity(entity); + } + + @Override + public void delete(CourseComment entity){ + entityDao.delete(entity); + } + + @Override + public void deleteLogic(CourseComment entity){ + entityDao.deleteLogic(entity); + } + + + +} + diff --git a/src/main/java/com/krt/dairy/core/course/service/impl/CourseSectionServiceImpl.java b/src/main/java/com/krt/dairy/core/course/service/impl/CourseSectionServiceImpl.java new file mode 100644 index 0000000..2b990f8 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/service/impl/CourseSectionServiceImpl.java @@ -0,0 +1,88 @@ +package com.krt.dairy.core.course.service.impl; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.course.dao.CourseSectionDao; +import com.krt.dairy.core.course.domain.CourseSection; +import com.krt.dairy.core.course.service.ICourseSectionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + + +@Service +public class CourseSectionServiceImpl implements ICourseSectionService{ + + @Autowired + private CourseSectionDao entityDao; + + public CourseSection getById(Long id){ + return entityDao.getById(id); + } + + public List queryAll(CourseSection queryEntity){ + return entityDao.queryAll(queryEntity); + } + + /** + * 获取课程章最大的sort + */ + public Integer getMaxSort(Long courseId){ + return entityDao.getMaxSort(courseId); + } + + public TailPage queryPage(CourseSection queryEntity ,TailPage page){ + Integer itemsTotalCount = entityDao.getTotalItemsCount(queryEntity); + List items = entityDao.queryPage(queryEntity,page); + page.setItemsTotalCount(itemsTotalCount); + page.setItems(items); + return page; + } + + public void createSelectivity(CourseSection entity){ + entityDao.createSelectivity(entity); + } + + /** + *批量创建 + **/ + public void createList(List entityList){ + entityDao.createList(entityList); + } + + public void update(CourseSection entity){ + entityDao.update(entity); + } + + public void updateSelectivity(CourseSection entity){ + entityDao.updateSelectivity(entity); + } + + public void delete(CourseSection entity){ + entityDao.delete(entity); + } + + public void deleteLogic(CourseSection entity){ + entityDao.deleteLogic(entity); + } + + /** + * 比当前sort大的,正序排序的第一个 + * @param curCourseSection + * @return + */ + public CourseSection getSortSectionMax(CourseSection curCourseSection){ + return entityDao.getSortSectionMax(curCourseSection); + } + + /** + * 比当前sort小的,倒序排序的第一个 + * @param curCourseSection + * @return + */ + public CourseSection getSortSectionMin(CourseSection curCourseSection){ + return entityDao.getSortSectionMin(curCourseSection); + } + +} + diff --git a/src/main/java/com/krt/dairy/core/course/service/impl/CourseServiceImpl.java b/src/main/java/com/krt/dairy/core/course/service/impl/CourseServiceImpl.java new file mode 100644 index 0000000..c4eb642 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/course/service/impl/CourseServiceImpl.java @@ -0,0 +1,82 @@ +package com.krt.dairy.core.course.service.impl; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.common.storage.QiniuStorage; +import com.krt.dairy.core.consts.CourseEnum; +import com.krt.dairy.core.course.dao.CourseDao; +import com.krt.dairy.core.course.domain.Course; +import com.krt.dairy.core.course.domain.CourseQueryDto; +import com.krt.dairy.core.course.service.ICourseService; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class CourseServiceImpl implements ICourseService{ + + @Autowired + private CourseDao entityDao; + + private void prepareCoursePicture(Course course){ + if(null != course && StringUtils.isNotEmpty(course.getPicture())){ + course.setPicture(QiniuStorage.getUrl(course.getPicture())); + } + } + + @Override + public Course getById(Long id){ + Course course = entityDao.getById(id); + prepareCoursePicture(course); + return course; + } + + @Override + public List queryList(CourseQueryDto queryEntity){ + if(null == queryEntity.getOnsale()){//是否上架 + queryEntity.setOnsale(CourseEnum.ONSALE.value()); + } + return entityDao.queryList(queryEntity); + } + + @Override + public TailPage queryPage(Course queryEntity ,TailPage page){ + Integer itemsTotalCount = entityDao.getTotalItemsCount(queryEntity); + List items = entityDao.queryPage(queryEntity,page); + if(CollectionUtils.isNotEmpty(items)){ + for(Course item : items){ + prepareCoursePicture(item); + } + } + page.setItemsTotalCount(itemsTotalCount); + page.setItems(items); + return page; + } + + @Override + public void createSelectivity(Course entity){ + entityDao.createSelectivity(entity); + } + + @Override + public void updateSelectivity(Course entity){ + entityDao.updateSelectivity(entity); + } + + //物理删除 + @Override + public void delete(Course entity){ + entityDao.delete(entity); + } + + //逻辑删除 + @Override + public void deleteLogic(Course entity){ + entityDao.deleteLogic(entity); + } + +} + + diff --git a/src/main/java/com/krt/dairy/core/user/dao/UserCollectionsDao.java b/src/main/java/com/krt/dairy/core/user/dao/UserCollectionsDao.java new file mode 100644 index 0000000..f37d76e --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/dao/UserCollectionsDao.java @@ -0,0 +1,64 @@ +package com.krt.dairy.core.user.dao; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.user.domain.UserCollections; + +import java.util.List; + + +public interface UserCollectionsDao { + + /** + *根据id获取 + **/ + public UserCollections getById(Long id); + + /** + *获取所有 + **/ + public List queryAll(UserCollections queryEntity); + + /** + *获取总数量 + **/ + public Integer getTotalItemsCount(UserCollections queryEntity); + + /** + *分页获取 + **/ + public List queryPage(UserCollections queryEntity, TailPage page); + + /** + *创建新记录 + **/ + public void create(UserCollections entity); + + /** + *创建新记录 + **/ + public void createSelectivity(UserCollections entity); + + /** + *根据id更新 + **/ + public void update(UserCollections entity); + + /** + *根据id选择性更新自动 + **/ + public void updateSelectivity(UserCollections entity); + + /** + *物理删除 + **/ + public void delete(UserCollections entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(UserCollections entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/user/dao/UserCollectionsMapper.xml b/src/main/java/com/krt/dairy/core/user/dao/UserCollectionsMapper.xml new file mode 100644 index 0000000..5cf9bef --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/dao/UserCollectionsMapper.xml @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + user_id, classify,object_id, tips, create_time, create_user, update_time, + update_user, del, id + + + + + + + + + + + + INSERT INTO t_user_collections + ( user_id, classify, object_id, tips, create_time, create_user, update_time, + update_user, del, id ) + VALUES + ( #{userId, jdbcType=INTEGER}, #{classify, jdbcType=INTEGER},#{objectId, jdbcType=INTEGER},#{tips, jdbcType=VARCHAR}, #{createTime, jdbcType=DATE}, #{createUser, jdbcType=VARCHAR}, #{updateTime, jdbcType=TIMESTAMP}, + #{updateUser, jdbcType=VARCHAR}, #{del, jdbcType=TINYINT}, #{id, jdbcType=VARCHAR} ) + + + + INSERT INTO t_user_collections + + + user_id, + + + classify, + + + object_id, + + + tips, + + + create_time, + + + create_user, + + + update_time, + + + update_user, + + + del, + + + VALUES + + + #{userId, jdbcType=INTEGER}, + + + #{classify, jdbcType=INTEGER}, + + + #{objectId, jdbcType=INTEGER}, + + + #{tips, jdbcType=VARCHAR}, + + + #{createTime, jdbcType=DATE}, + + + #{createUser, jdbcType=VARCHAR}, + + + #{updateTime, jdbcType=TIMESTAMP}, + + + #{updateUser, jdbcType=VARCHAR}, + + + #{del, jdbcType=TINYINT}, + + + + + + UPDATE t_user_collections SET + user_id = #{userId, jdbcType=INTEGER}, + classify = #{classify, jdbcType=INTEGER}, + object_id = #{objectId, jdbcType=INTEGER}, + tips = #{tips, jdbcType=VARCHAR}, + update_time = #{updateTime, jdbcType=TIMESTAMP}, + update_user = #{updateUser, jdbcType=VARCHAR} + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_user_collections + + + user_id = #{userId, jdbcType=INTEGER}, + + + classify = #{classify, jdbcType=INTEGER}, + + + object_id = #{objectId, jdbcType=INTEGER}, + + + tips = #{tips, jdbcType=VARCHAR}, + + + update_time = #{updateTime, jdbcType=TIMESTAMP}, + + + update_user = #{updateUser, jdbcType=VARCHAR}, + + + del = #{del, jdbcType=TINYINT}, + + + WHERE id = #{id, jdbcType = INTEGER} + + + + + DELETE FROM t_user_collections + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_user_collections + SET del = 1 + WHERE id = #{id, jdbcType=INTEGER} + + + diff --git a/src/main/java/com/krt/dairy/core/user/dao/UserCourseSectionDao.java b/src/main/java/com/krt/dairy/core/user/dao/UserCourseSectionDao.java new file mode 100644 index 0000000..99eaaf8 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/dao/UserCourseSectionDao.java @@ -0,0 +1,65 @@ +package com.krt.dairy.core.user.dao; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.user.domain.UserCourseSection; +import com.krt.dairy.core.user.domain.UserCourseSectionDto; + +import java.util.List; + + +public interface UserCourseSectionDao { + + /** + *根据id获取 + **/ + public UserCourseSection getById(Long id); + + /** + *获取所有 + **/ + public List queryAll(UserCourseSection queryEntity); + + /** + * 获取最新的学习记录 + */ + public UserCourseSection queryLatest(UserCourseSection queryEntity); + + /** + *获取总数量 + **/ + public Integer getTotalItemsCount(UserCourseSection queryEntity); + + /** + *分页获取 + **/ + public List queryPage(UserCourseSection queryEntity, TailPage page); + + /** + *创建新记录 + **/ + public void createSelectivity(UserCourseSection entity); + + /** + *根据id更新 + **/ + public void update(UserCourseSection entity); + + /** + *根据id选择性更新自动 + **/ + public void updateSelectivity(UserCourseSection entity); + + /** + *物理删除 + **/ + public void delete(UserCourseSection entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(UserCourseSection entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/user/dao/UserCourseSectionMapper.xml b/src/main/java/com/krt/dairy/core/user/dao/UserCourseSectionMapper.xml new file mode 100644 index 0000000..965fd73 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/dao/UserCourseSectionMapper.xml @@ -0,0 +1,220 @@ + + + + + + + + + + + + + + + + + + + + + + user_id, course_id, section_id, status, rate, create_time, create_user, + update_time, update_user, del, id + + + + + + + + + + + + + + INSERT INTO t_user_course_section + ( user_id, course_id, section_id, status, rate, create_time, create_user, + update_time, update_user, del, id ) + VALUES + ( #{userId, jdbcType=INTEGER}, #{courseId, jdbcType=INTEGER}, #{sectionId, jdbcType=INTEGER}, #{status, jdbcType=INTEGER}, #{rate, jdbcType=INTEGER}, #{createTime, jdbcType=DATE}, #{createUser, jdbcType=VARCHAR}, + #{updateTime, jdbcType=TIMESTAMP}, #{updateUser, jdbcType=VARCHAR}, #{del, jdbcType=TINYINT}, #{id, jdbcType=VARCHAR} ) + + + + INSERT INTO t_user_course_section + + + user_id, + + + course_id, + + + section_id, + + + status, + + + rate, + + + create_time, + + + create_user, + + + update_time, + + + update_user, + + + del, + + + VALUES + + + #{userId, jdbcType=INTEGER}, + + + #{courseId, jdbcType=INTEGER}, + + + #{sectionId, jdbcType=INTEGER}, + + + #{status, jdbcType=INTEGER}, + + + #{rate, jdbcType=INTEGER}, + + + #{createTime, jdbcType=DATE}, + + + #{createUser, jdbcType=VARCHAR}, + + + #{updateTime, jdbcType=TIMESTAMP}, + + + #{updateUser, jdbcType=VARCHAR}, + + + #{del, jdbcType=TINYINT}, + + + + + + UPDATE t_user_course_section SET + user_id = #{userId, jdbcType=INTEGER}, + course_id = #{courseId, jdbcType=INTEGER}, + section_id = #{sectionId, jdbcType=INTEGER}, + status = #{status, jdbcType=INTEGER}, + rate = #{rate, jdbcType=INTEGER}, + update_time = #{updateTime, jdbcType=TIMESTAMP}, + update_user = #{updateUser, jdbcType=VARCHAR} + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_user_course_section + + + user_id = #{userId, jdbcType=INTEGER}, + + + course_id = #{courseId, jdbcType=INTEGER}, + + + section_id = #{sectionId, jdbcType=INTEGER}, + + + status = #{status, jdbcType=INTEGER}, + + + rate = #{rate, jdbcType=INTEGER}, + + + update_time = #{updateTime, jdbcType=TIMESTAMP}, + + + update_user = #{updateUser, jdbcType=VARCHAR}, + + + del = #{del, jdbcType=TINYINT}, + + + WHERE id = #{id, jdbcType = INTEGER} + + + + + DELETE + FROM t_user_course_section + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_user_course_section + SET del = 1 + WHERE id = #{id, jdbcType=INTEGER} + + + diff --git a/src/main/java/com/krt/dairy/core/user/dao/UserFollowsDao.java b/src/main/java/com/krt/dairy/core/user/dao/UserFollowsDao.java new file mode 100644 index 0000000..d6d5116 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/dao/UserFollowsDao.java @@ -0,0 +1,70 @@ +package com.krt.dairy.core.user.dao; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.user.domain.UserFollowStudyRecord; +import com.krt.dairy.core.user.domain.UserFollows; + +import java.util.List; + + +public interface UserFollowsDao { + + /** + *根据id获取 + **/ + public UserFollows getById(Long id); + + /** + *获取所有 + **/ + public List queryAll(UserFollows queryEntity); + + /** + *获取总数量 + **/ + public Integer getTotalItemsCount(UserFollows queryEntity); + + /** + *分页获取 + **/ + public List queryPage(UserFollows queryEntity, TailPage page); + + /** + *获取总数量 + **/ + public Integer getFollowStudyRecordCount(UserFollowStudyRecord queryEntity); + + /** + *分页获取 + **/ + public List queryFollowStudyRecord(UserFollowStudyRecord queryEntity, TailPage page); + + /** + *创建新记录 + **/ + public void createSelectivity(UserFollows entity); + + /** + *根据id更新 + **/ + public void update(UserFollows entity); + + /** + *根据id选择性更新自动 + **/ + public void updateSelectivity(UserFollows entity); + + /** + *物理删除 + **/ + public void delete(UserFollows entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(UserFollows entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/user/dao/UserFollowsMapper.xml b/src/main/java/com/krt/dairy/core/user/dao/UserFollowsMapper.xml new file mode 100644 index 0000000..55a9c61 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/dao/UserFollowsMapper.xml @@ -0,0 +1,187 @@ + + + + + + + + + + + + + + + + + + user_id, follow_id, create_time, create_user, update_time, update_user, + del, id + + + + + + + + + + + + + + + + INSERT INTO t_user_follows + ( user_id, follow_id, create_time, create_user, update_time, update_user, + del, id ) + VALUES + ( #{userId, jdbcType=VARCHAR}, #{followId, jdbcType=VARCHAR}, #{createTime, jdbcType=DATE}, #{createUser, jdbcType=VARCHAR}, #{updateTime, jdbcType=TIMESTAMP}, #{updateUser, jdbcType=VARCHAR}, + #{del, jdbcType=TINYINT}, #{id, jdbcType=VARCHAR} ) + + + + INSERT INTO t_user_follows + + + user_id, + + + follow_id, + + + create_time, + + + create_user, + + + update_time, + + + update_user, + + + del, + + + VALUES + + + #{userId, jdbcType=INTEGER}, + + + #{followId, jdbcType=INTEGER}, + + + #{createTime, jdbcType=DATE}, + + + #{createUser, jdbcType=VARCHAR}, + + + #{updateTime, jdbcType=TIMESTAMP}, + + + #{updateUser, jdbcType=VARCHAR}, + + + #{del, jdbcType=TINYINT}, + + + + + + UPDATE t_user_follows SET + user_id = #{userId, jdbcType=VARCHAR}, + follow_id = #{followId, jdbcType=VARCHAR}, + update_time = #{updateTime, jdbcType=TIMESTAMP}, + update_user = #{updateUser, jdbcType=VARCHAR} + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_user_follows + + + user_id = #{userId, jdbcType=VARCHAR}, + + + follow_id = #{followId, jdbcType=VARCHAR}, + + + update_time = #{updateTime, jdbcType=TIMESTAMP}, + + + update_user = #{updateUser, jdbcType=VARCHAR}, + + + del = #{del, jdbcType=TINYINT}, + + + WHERE id = #{id, jdbcType = INTEGER} + + + + + DELETE FROM t_user_follows + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_user_follows + SET del = 1 + WHERE id = #{id, jdbcType=INTEGER} + + + diff --git a/src/main/java/com/krt/dairy/core/user/dao/UserMessageDao.java b/src/main/java/com/krt/dairy/core/user/dao/UserMessageDao.java new file mode 100644 index 0000000..c8edeb5 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/dao/UserMessageDao.java @@ -0,0 +1,59 @@ +package com.krt.dairy.core.user.dao; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.user.domain.UserMessage; + +import java.util.List; + + +public interface UserMessageDao { + + /** + *根据id获取 + **/ + public UserMessage getById(Long id); + + /** + *获取所有 + **/ + public List queryAll(UserMessage queryEntity); + + /** + *获取总数量 + **/ + public Integer getTotalItemsCount(UserMessage queryEntity); + + /** + *分页获取 + **/ + public List queryPage(UserMessage queryEntity, TailPage page); + + /** + *创建新记录 + **/ + public void create(UserMessage entity); + + /** + *根据id更新 + **/ + public void update(UserMessage entity); + + /** + *根据id选择性更新自动 + **/ + public void updateSelectivity(UserMessage entity); + + /** + *物理删除 + **/ + public void delete(UserMessage entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(UserMessage entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/user/dao/UserMessageMapper.xml b/src/main/java/com/krt/dairy/core/user/dao/UserMessageMapper.xml new file mode 100644 index 0000000..43ebbf9 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/dao/UserMessageMapper.xml @@ -0,0 +1,211 @@ + + + + + + + + + + + + + + + + + + + + + + + + user_id, send_user_id, send_user_name, ref_id, ref_content, type, + status, create_time, create_user, update_time, update_user, del, + id + + + + + + + + + + + + INSERT INTO t_user_message + ( user_id, send_user_id, send_user_name, ref_id, ref_content, type, + status, create_time, create_user, update_time, update_user, del, + id ) + VALUES + ( #{userId, jdbcType=VARCHAR}, #{sendUserId, jdbcType=VARCHAR}, #{sendUserName, jdbcType=VARCHAR}, #{refId, jdbcType=VARCHAR}, #{refContent, jdbcType=VARCHAR}, #{type, jdbcType=INTEGER}, + #{status, jdbcType=INTEGER}, #{createTime, jdbcType=DATE}, #{createUser, jdbcType=VARCHAR}, #{updateTime, jdbcType=TIMESTAMP}, #{updateUser, jdbcType=VARCHAR}, #{del, jdbcType=TINYINT}, + #{id, jdbcType=VARCHAR} ) + + + + INSERT INTO t_user_message + + + user_id, + + + send_user_id, + + + send_user_name, + + + ref_id, + + + ref_content, + + + type, + + + status, + + + create_time, + + + create_user, + + + update_time, + + + update_user, + + + del, + + + VALUES + + + #{userId, jdbcType=INTEGER}, + + + #{sendUserId, jdbcType=INTEGER}, + + + #{sendUserName, jdbcType=VARCHAR}, + + + #{refId, jdbcType=VARCHAR}, + + + #{refContent, jdbcType=VARCHAR}, + + + #{type, jdbcType=INTEGER}, + + + #{status, jdbcType=INTEGER}, + + + #{createTime, jdbcType=DATE}, + + + #{createUser, jdbcType=VARCHAR}, + + + #{updateTime, jdbcType=TIMESTAMP}, + + + #{updateUser, jdbcType=VARCHAR}, + + + #{del, jdbcType=TINYINT}, + + + + + + UPDATE t_user_message SET + user_id = #{userId, jdbcType=VARCHAR}, + send_user_id = #{sendUserId, jdbcType=VARCHAR}, + send_user_name = #{sendUserName, jdbcType=VARCHAR}, + ref_id = #{refId, jdbcType=VARCHAR}, + ref_content = #{refContent, jdbcType=VARCHAR}, + type = #{type, jdbcType=INTEGER}, + status = #{status, jdbcType=INTEGER}, + update_time = #{updateTime, jdbcType=TIMESTAMP}, + update_user = #{updateUser, jdbcType=VARCHAR} + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_user_message + + + user_id = #{userId, jdbcType=VARCHAR}, + + + send_user_id = #{sendUserId, jdbcType=VARCHAR}, + + + send_user_name = #{sendUserName, jdbcType=VARCHAR}, + + + ref_id = #{refId, jdbcType=VARCHAR}, + + + ref_content = #{refContent, jdbcType=VARCHAR}, + + + type = #{type, jdbcType=INTEGER}, + + + status = #{status, jdbcType=INTEGER}, + + + update_time = #{updateTime, jdbcType=TIMESTAMP}, + + + update_user = #{updateUser, jdbcType=VARCHAR}, + + + del = #{del, jdbcType=TINYINT}, + + + WHERE id = #{id, jdbcType = INTEGER} + + + + + DELETE FROM t_user_message + WHERE id = #{id, jdbcType=INTEGER} + + + + UPDATE t_user_message + SET del = 1 + WHERE id = #{id, jdbcType=INTEGER} + + + diff --git a/src/main/java/com/krt/dairy/core/user/domain/UserCollections.java b/src/main/java/com/krt/dairy/core/user/domain/UserCollections.java new file mode 100644 index 0000000..4601d6d --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/domain/UserCollections.java @@ -0,0 +1,69 @@ +package com.krt.dairy.core.user.domain; + +import com.krt.dairy.common.orm.BaseEntity; + + +public class UserCollections extends BaseEntity{ + + private static final long serialVersionUID = -3909997252117758595L; + + /** + *用户id + **/ + private Long userId; + + /** + *用户收藏分类 + **/ + private Integer classify; + + /** + * 用户收藏id + */ + private Long objectId; + + /** + *用户收藏备注 + **/ + private String tips; + + /** + * 收藏名称 + */ + private String name; + + public Long getUserId(){ + return userId; + } + public void setUserId(Long userId){ + this.userId = userId; + } + + public Integer getClassify(){ + return classify; + } + public void setClassify(Integer classify){ + this.classify = classify; + } + + public String getTips(){ + return tips; + } + public void setTips(String tips){ + this.tips = tips; + } + public Long getObjectId() { + return objectId; + } + public void setObjectId(Long objectId) { + this.objectId = objectId; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + +} + diff --git a/src/main/java/com/krt/dairy/core/user/domain/UserCourseSection.java b/src/main/java/com/krt/dairy/core/user/domain/UserCourseSection.java new file mode 100644 index 0000000..d71de26 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/domain/UserCourseSection.java @@ -0,0 +1,70 @@ +package com.krt.dairy.core.user.domain; + +import com.krt.dairy.common.orm.BaseEntity; + + +public class UserCourseSection extends BaseEntity{ + + private static final long serialVersionUID = 5447461555053008202L; + + /** + *用户id + **/ + private Long userId; + + /** + *课程id + **/ + private Long courseId; + + /** + *章节id + **/ + private Long sectionId; + + /** + *状态:0-学习中;1-学习结束 + **/ + private Integer status; + + /** + * 进度 + */ + private Integer rate; + + public Long getUserId(){ + return userId; + } + public void setUserId(Long userId){ + this.userId = userId; + } + + public Long getCourseId(){ + return courseId; + } + public void setCourseId(Long courseId){ + this.courseId = courseId; + } + + public Long getSectionId(){ + return sectionId; + } + public void setSectionId(Long sectionId){ + this.sectionId = sectionId; + } + + public Integer getStatus(){ + return status; + } + public void setStatus(Integer status){ + this.status = status; + } + public Integer getRate() { + return rate; + } + public void setRate(Integer rate) { + this.rate = rate; + } + +} + diff --git a/src/main/java/com/krt/dairy/core/user/domain/UserCourseSectionDto.java b/src/main/java/com/krt/dairy/core/user/domain/UserCourseSectionDto.java new file mode 100644 index 0000000..c4c4384 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/domain/UserCourseSectionDto.java @@ -0,0 +1,62 @@ +package com.krt.dairy.core.user.domain; + +/** + * 用户学习课程dto + */ +public class UserCourseSectionDto extends UserCourseSection { + + private static final long serialVersionUID = 608405844566660424L; + + /** + * 用户名 + */ + private String username; + + /** + * 课程名 + */ + private String courseName; + + /** + * 章节名 + */ + private String sectionName; + + /** + * 用户头像 + */ + private String header; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getCourseName() { + return courseName; + } + + public void setCourseName(String courseName) { + this.courseName = courseName; + } + + public String getSectionName() { + return sectionName; + } + + public void setSectionName(String sectionName) { + this.sectionName = sectionName; + } + + public String getHeader() { + return header; + } + + public void setHeader(String header) { + this.header = header; + } + +} diff --git a/src/main/java/com/krt/dairy/core/user/domain/UserFollowStudyRecord.java b/src/main/java/com/krt/dairy/core/user/domain/UserFollowStudyRecord.java new file mode 100644 index 0000000..44d5f70 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/domain/UserFollowStudyRecord.java @@ -0,0 +1,127 @@ +package com.krt.dairy.core.user.domain; + +import java.util.Date; + +/** + * 关注的用户学习记录dto + */ +public class UserFollowStudyRecord { + + /** + * 课程id + */ + private Long courseId; + + /** + * 章节id + */ + private Long sectionId; + + /** + * 用户id + */ + private Long userId; + + /** + * 用户登录名 + */ + private String username; + + /** + * 用户头像 + */ + private String header; + + /** + * 关注用户id + */ + private Long followId; + + /** + * 课程名称 + */ + private String courseName; + + /** + * 章节名称 + */ + private String sectionName; + + /** + * 创建时间 + */ + private Date createTime; + + public Long getCourseId() { + return courseId; + } + + public void setCourseId(Long courseId) { + this.courseId = courseId; + } + + public Long getSectionId() { + return sectionId; + } + + public void setSectionId(Long sectionId) { + this.sectionId = sectionId; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getHeader() { + return header; + } + + public void setHeader(String header) { + this.header = header; + } + + public Long getFollowId() { + return followId; + } + + public void setFollowId(Long followId) { + this.followId = followId; + } + + public String getCourseName() { + return courseName; + } + + public void setCourseName(String courseName) { + this.courseName = courseName; + } + + public String getSectionName() { + return sectionName; + } + + public void setSectionName(String sectionName) { + this.sectionName = sectionName; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + +} diff --git a/src/main/java/com/krt/dairy/core/user/domain/UserFollows.java b/src/main/java/com/krt/dairy/core/user/domain/UserFollows.java new file mode 100644 index 0000000..a1e0785 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/domain/UserFollows.java @@ -0,0 +1,37 @@ +package com.krt.dairy.core.user.domain; + +import com.krt.dairy.common.orm.BaseEntity; + + +public class UserFollows extends BaseEntity{ + + private static final long serialVersionUID = -275116124638094439L; + + /** + *用户id + **/ + private Long userId; + + /** + *关注的用户id + **/ + private Long followId; + + public Long getUserId(){ + return userId; + } + public void setUserId(Long userId){ + this.userId = userId; + } + + public Long getFollowId(){ + return followId; + } + public void setFollowId(Long followId){ + this.followId = followId; + } + + + +} + diff --git a/src/main/java/com/krt/dairy/core/user/domain/UserMessage.java b/src/main/java/com/krt/dairy/core/user/domain/UserMessage.java new file mode 100644 index 0000000..0394b09 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/domain/UserMessage.java @@ -0,0 +1,97 @@ +package com.krt.dairy.core.user.domain; + +import com.krt.dairy.common.orm.BaseEntity; + + +public class UserMessage extends BaseEntity{ + + private static final long serialVersionUID = -5308032957532522065L; + + /** + *消息接收用户id + **/ + private Long userId; + + /** + *消息发起用户id + **/ + private Long sendUserId; + + /** + *消息发起用户名称 + **/ + private String sendUserName; + + /** + *引用id + **/ + private String refId; + + /** + *引用内容 + **/ + private String refContent; + + /** + *通知的类型,1-评论,2-关注,3-答疑 + **/ + private Integer type; + + /** + *未读(0)、已读(1) + **/ + private Integer status; + + public Long getUserId(){ + return userId; + } + public void setUserId(Long userId){ + this.userId = userId; + } + + public Long getSendUserId(){ + return sendUserId; + } + public void setSendUserId(Long sendUserId){ + this.sendUserId = sendUserId; + } + + public String getSendUserName(){ + return sendUserName; + } + public void setSendUserName(String sendUserName){ + this.sendUserName = sendUserName; + } + + public String getRefId(){ + return refId; + } + public void setRefId(String refId){ + this.refId = refId; + } + + public String getRefContent(){ + return refContent; + } + public void setRefContent(String refContent){ + this.refContent = refContent; + } + + public Integer getType(){ + return type; + } + public void setType(Integer type){ + this.type = type; + } + + public Integer getStatus(){ + return status; + } + public void setStatus(Integer status){ + this.status = status; + } + + + +} + diff --git a/src/main/java/com/krt/dairy/core/user/service/IUserCollectionsService.java b/src/main/java/com/krt/dairy/core/user/service/IUserCollectionsService.java new file mode 100644 index 0000000..c3548d7 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/service/IUserCollectionsService.java @@ -0,0 +1,54 @@ +package com.krt.dairy.core.user.service; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.user.domain.UserCollections; + +import java.util.List; + + +public interface IUserCollectionsService { + + /** + *根据id获取 + **/ + public UserCollections getById(Long id); + + /** + *获取所有 + **/ + public List queryAll(UserCollections queryEntity); + + /** + *分页获取 + **/ + public TailPage queryPage(UserCollections queryEntity, TailPage page); + + /** + *创建 + **/ + public void createSelectivity(UserCollections entity); + + /** + *根据id更新 + **/ + public void update(UserCollections entity); + + /** + *根据id 进行可选性更新 + **/ + public void updateSelectivity(UserCollections entity); + + /** + *物理删除 + **/ + public void delete(UserCollections entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(UserCollections entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/user/service/IUserCourseSectionService.java b/src/main/java/com/krt/dairy/core/user/service/IUserCourseSectionService.java new file mode 100644 index 0000000..99ea0e2 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/service/IUserCourseSectionService.java @@ -0,0 +1,60 @@ +package com.krt.dairy.core.user.service; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.user.domain.UserCourseSection; +import com.krt.dairy.core.user.domain.UserCourseSectionDto; + +import java.util.List; + + +public interface IUserCourseSectionService { + + /** + *根据id获取 + **/ + public UserCourseSection getById(Long id); + + /** + *获取所有 + **/ + public List queryAll(UserCourseSection queryEntity); + + /** + * 获取最新的 + */ + public UserCourseSection queryLatest(UserCourseSection queryEntity); + + /** + *分页获取 + **/ + public TailPage queryPage(UserCourseSection queryEntity, TailPage page); + + /** + *创建 + **/ + public void createSelectivity(UserCourseSection entity); + + /** + *根据id更新 + **/ + public void update(UserCourseSection entity); + + /** + *根据id 进行可选性更新 + **/ + public void updateSelectivity(UserCourseSection entity); + + /** + *物理删除 + **/ + public void delete(UserCourseSection entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(UserCourseSection entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/user/service/IUserFollowsService.java b/src/main/java/com/krt/dairy/core/user/service/IUserFollowsService.java new file mode 100644 index 0000000..4e76492 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/service/IUserFollowsService.java @@ -0,0 +1,60 @@ +package com.krt.dairy.core.user.service; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.user.domain.UserFollowStudyRecord; +import com.krt.dairy.core.user.domain.UserFollows; + +import java.util.List; + + +public interface IUserFollowsService { + + /** + *根据id获取 + **/ + public UserFollows getById(Long id); + + /** + *获取所有 + **/ + public List queryAll(UserFollows queryEntity); + + /** + *分页获取 + **/ + public TailPage queryPage(UserFollows queryEntity, TailPage page); + + /** + *分页获取 + **/ + public TailPage queryUserFollowStudyRecordPage(UserFollowStudyRecord queryEntity, TailPage page); + + /** + *创建 + **/ + public void createSelectivity(UserFollows entity); + + /** + *根据id更新 + **/ + public void update(UserFollows entity); + + /** + *根据id 进行可选性更新 + **/ + public void updateSelectivity(UserFollows entity); + + /** + *物理删除 + **/ + public void delete(UserFollows entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(UserFollows entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/user/service/IUserMessageService.java b/src/main/java/com/krt/dairy/core/user/service/IUserMessageService.java new file mode 100644 index 0000000..46ac258 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/service/IUserMessageService.java @@ -0,0 +1,54 @@ +package com.krt.dairy.core.user.service; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.user.domain.UserMessage; + +import java.util.List; + + +public interface IUserMessageService { + + /** + *根据id获取 + **/ + public UserMessage getById(Long id); + + /** + *获取所有 + **/ + public List queryAll(UserMessage queryEntity); + + /** + *分页获取 + **/ + public TailPage queryPage(UserMessage queryEntity, TailPage page); + + /** + *创建 + **/ + public void create(UserMessage entity); + + /** + *根据id更新 + **/ + public void update(UserMessage entity); + + /** + *根据id 进行可选性更新 + **/ + public void updateSelectivity(UserMessage entity); + + /** + *物理删除 + **/ + public void delete(UserMessage entity); + + /** + *逻辑删除 + **/ + public void deleteLogic(UserMessage entity); + + + +} + diff --git a/src/main/java/com/krt/dairy/core/user/service/impl/UserCollectionsServiceImpl.java b/src/main/java/com/krt/dairy/core/user/service/impl/UserCollectionsServiceImpl.java new file mode 100644 index 0000000..5e16945 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/service/impl/UserCollectionsServiceImpl.java @@ -0,0 +1,58 @@ +package com.krt.dairy.core.user.service.impl; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.user.dao.UserCollectionsDao; +import com.krt.dairy.core.user.domain.UserCollections; +import com.krt.dairy.core.user.service.IUserCollectionsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + + +@Service +public class UserCollectionsServiceImpl implements IUserCollectionsService{ + + @Autowired + private UserCollectionsDao entityDao; + + public UserCollections getById(Long id){ + return entityDao.getById(id); + } + + public List queryAll(UserCollections queryEntity){ + return entityDao.queryAll(queryEntity); + } + + public TailPage queryPage(UserCollections queryEntity ,TailPage page){ + Integer itemsTotalCount = entityDao.getTotalItemsCount(queryEntity); + List items = entityDao.queryPage(queryEntity,page); + page.setItemsTotalCount(itemsTotalCount); + page.setItems(items); + return page; + } + + public void createSelectivity(UserCollections entity){ + entityDao.createSelectivity(entity); + } + + public void update(UserCollections entity){ + entityDao.update(entity); + } + + public void updateSelectivity(UserCollections entity){ + entityDao.updateSelectivity(entity); + } + + public void delete(UserCollections entity){ + entityDao.delete(entity); + } + + public void deleteLogic(UserCollections entity){ + entityDao.deleteLogic(entity); + } + + + +} + diff --git a/src/main/java/com/krt/dairy/core/user/service/impl/UserCourseSectionServiceImpl.java b/src/main/java/com/krt/dairy/core/user/service/impl/UserCourseSectionServiceImpl.java new file mode 100644 index 0000000..501bd8b --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/service/impl/UserCourseSectionServiceImpl.java @@ -0,0 +1,63 @@ +package com.krt.dairy.core.user.service.impl; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.user.dao.UserCourseSectionDao; +import com.krt.dairy.core.user.domain.UserCourseSection; +import com.krt.dairy.core.user.domain.UserCourseSectionDto; +import com.krt.dairy.core.user.service.IUserCourseSectionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + + +@Service +public class UserCourseSectionServiceImpl implements IUserCourseSectionService{ + + @Autowired + private UserCourseSectionDao entityDao; + + public UserCourseSection getById(Long id){ + return entityDao.getById(id); + } + + public List queryAll(UserCourseSection queryEntity){ + return entityDao.queryAll(queryEntity); + } + + public UserCourseSection queryLatest(UserCourseSection queryEntity){ + return entityDao.queryLatest(queryEntity); + } + + public TailPage queryPage(UserCourseSection queryEntity , TailPage page){ + Integer itemsTotalCount = entityDao.getTotalItemsCount(queryEntity); + List items = entityDao.queryPage(queryEntity,page); + page.setItemsTotalCount(itemsTotalCount); + page.setItems(items); + return page; + } + + public void createSelectivity(UserCourseSection entity){ + entityDao.createSelectivity(entity); + } + + public void update(UserCourseSection entity){ + entityDao.update(entity); + } + + public void updateSelectivity(UserCourseSection entity){ + entityDao.updateSelectivity(entity); + } + + public void delete(UserCourseSection entity){ + entityDao.delete(entity); + } + + public void deleteLogic(UserCourseSection entity){ + entityDao.deleteLogic(entity); + } + + + +} + diff --git a/src/main/java/com/krt/dairy/core/user/service/impl/UserFollowsServiceImpl.java b/src/main/java/com/krt/dairy/core/user/service/impl/UserFollowsServiceImpl.java new file mode 100644 index 0000000..60dd8de --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/service/impl/UserFollowsServiceImpl.java @@ -0,0 +1,67 @@ +package com.krt.dairy.core.user.service.impl; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.user.dao.UserFollowsDao; +import com.krt.dairy.core.user.domain.UserFollowStudyRecord; +import com.krt.dairy.core.user.domain.UserFollows; +import com.krt.dairy.core.user.service.IUserFollowsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + + +@Service +public class UserFollowsServiceImpl implements IUserFollowsService{ + + @Autowired + private UserFollowsDao entityDao; + + public UserFollows getById(Long id){ + return entityDao.getById(id); + } + + public List queryAll(UserFollows queryEntity){ + return entityDao.queryAll(queryEntity); + } + + public TailPage queryPage(UserFollows queryEntity ,TailPage page){ + Integer itemsTotalCount = entityDao.getTotalItemsCount(queryEntity); + List items = entityDao.queryPage(queryEntity,page); + page.setItemsTotalCount(itemsTotalCount); + page.setItems(items); + return page; + } + + public TailPage queryUserFollowStudyRecordPage(UserFollowStudyRecord queryEntity ,TailPage page){ + Integer itemsTotalCount = entityDao.getFollowStudyRecordCount(queryEntity); + List items = entityDao.queryFollowStudyRecord(queryEntity,page); + page.setItemsTotalCount(itemsTotalCount); + page.setItems(items); + return page; + } + + public void createSelectivity(UserFollows entity){ + entityDao.createSelectivity(entity); + } + + public void update(UserFollows entity){ + entityDao.update(entity); + } + + public void updateSelectivity(UserFollows entity){ + entityDao.updateSelectivity(entity); + } + + public void delete(UserFollows entity){ + entityDao.delete(entity); + } + + public void deleteLogic(UserFollows entity){ + entityDao.deleteLogic(entity); + } + + + +} + diff --git a/src/main/java/com/krt/dairy/core/user/service/impl/UserMessageServiceImpl.java b/src/main/java/com/krt/dairy/core/user/service/impl/UserMessageServiceImpl.java new file mode 100644 index 0000000..3a630b7 --- /dev/null +++ b/src/main/java/com/krt/dairy/core/user/service/impl/UserMessageServiceImpl.java @@ -0,0 +1,58 @@ +package com.krt.dairy.core.user.service.impl; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.user.dao.UserMessageDao; +import com.krt.dairy.core.user.domain.UserMessage; +import com.krt.dairy.core.user.service.IUserMessageService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + + +@Service +public class UserMessageServiceImpl implements IUserMessageService{ + + @Autowired + private UserMessageDao entityDao; + + public UserMessage getById(Long id){ + return entityDao.getById(id); + } + + public List queryAll(UserMessage queryEntity){ + return entityDao.queryAll(queryEntity); + } + + public TailPage queryPage(UserMessage queryEntity ,TailPage page){ + Integer itemsTotalCount = entityDao.getTotalItemsCount(queryEntity); + List items = entityDao.queryPage(queryEntity,page); + page.setItemsTotalCount(itemsTotalCount); + page.setItems(items); + return page; + } + + public void create(UserMessage entity){ + entityDao.create(entity); + } + + public void update(UserMessage entity){ + entityDao.update(entity); + } + + public void updateSelectivity(UserMessage entity){ + entityDao.updateSelectivity(entity); + } + + public void delete(UserMessage entity){ + entityDao.delete(entity); + } + + public void deleteLogic(UserMessage entity){ + entityDao.deleteLogic(entity); + } + + + +} + diff --git a/src/main/java/com/krt/dairy/portal/business/ICourseBusiness.java b/src/main/java/com/krt/dairy/portal/business/ICourseBusiness.java new file mode 100644 index 0000000..989c3a2 --- /dev/null +++ b/src/main/java/com/krt/dairy/portal/business/ICourseBusiness.java @@ -0,0 +1,14 @@ +package com.krt.dairy.portal.business; + +import com.krt.dairy.portal.vo.CourseSectionVO; + +import java.util.List; + +public interface ICourseBusiness { + + /** + * 获取课程章节 + */ + List queryCourseSection(Long courseId); + +} diff --git a/src/main/java/com/krt/dairy/portal/business/IPortalBusiness.java b/src/main/java/com/krt/dairy/portal/business/IPortalBusiness.java new file mode 100644 index 0000000..97b4cda --- /dev/null +++ b/src/main/java/com/krt/dairy/portal/business/IPortalBusiness.java @@ -0,0 +1,24 @@ +package com.krt.dairy.portal.business; + +import com.krt.dairy.portal.vo.ConstsClassifyVO; + +import java.util.List; +import java.util.Map; + +public interface IPortalBusiness { + + /** + * 获取所有,包括一级分类&二级分类 + */ + List queryAllClassify(); + + /** + * 获取所有分类 + */ + Map queryAllClassifyMap(); + + /** + * 为分类设置课程推荐 + */ + void prepareRecomdCourses(List classifyVoList); +} diff --git a/src/main/java/com/krt/dairy/portal/business/impl/CourseBusinessImpl.java b/src/main/java/com/krt/dairy/portal/business/impl/CourseBusinessImpl.java new file mode 100644 index 0000000..51f87a8 --- /dev/null +++ b/src/main/java/com/krt/dairy/portal/business/impl/CourseBusinessImpl.java @@ -0,0 +1,51 @@ +package com.krt.dairy.portal.business.impl; + +import com.krt.dairy.core.consts.CourseEnum; +import com.krt.dairy.core.course.domain.CourseSection; +import com.krt.dairy.core.course.service.ICourseSectionService; +import com.krt.dairy.portal.business.ICourseBusiness; +import com.krt.dairy.portal.vo.CourseSectionVO; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.*; + + +/** + * 课程业务层 + */ +@Service +public class CourseBusinessImpl implements ICourseBusiness { + + @Autowired + private ICourseSectionService courseSectionService; + + /** + * 获取课程章节 + */ + public List queryCourseSection(Long courseId){ + List resultList = new ArrayList(); + CourseSection queryEntity = new CourseSection(); + queryEntity.setCourseId(courseId); + queryEntity.setOnsale(CourseEnum.ONSALE.value());//上架 + + Map tmpMap = new LinkedHashMap(); + Iterator it = courseSectionService.queryAll(queryEntity).iterator(); + while(it.hasNext()){ + CourseSection item = it.next(); + if(Long.valueOf(0).equals(item.getParentId())){//章 + CourseSectionVO vo = new CourseSectionVO(); + BeanUtils.copyProperties(item, vo); + tmpMap.put(vo.getId(), vo); + }else{ + tmpMap.get(item.getParentId()).getSections().add(item);//小节添加到大章中 + } + } + for(CourseSectionVO vo : tmpMap.values()){ + resultList.add(vo); + } + return resultList; + } + +} diff --git a/src/main/java/com/krt/dairy/portal/business/impl/PortalBusinessImpl.java b/src/main/java/com/krt/dairy/portal/business/impl/PortalBusinessImpl.java new file mode 100644 index 0000000..daff92f --- /dev/null +++ b/src/main/java/com/krt/dairy/portal/business/impl/PortalBusinessImpl.java @@ -0,0 +1,80 @@ +package com.krt.dairy.portal.business.impl; + +import com.krt.dairy.core.consts.domain.ConstsClassify; +import com.krt.dairy.core.consts.service.IConstsClassifyService; +import com.krt.dairy.core.course.domain.Course; +import com.krt.dairy.core.course.domain.CourseQueryDto; +import com.krt.dairy.core.course.service.ICourseService; +import com.krt.dairy.portal.business.IPortalBusiness; +import com.krt.dairy.portal.vo.ConstsClassifyVO; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.*; + +/** + * 首页业务层 + */ +@Service +public class PortalBusinessImpl implements IPortalBusiness { + + @Autowired + private IConstsClassifyService constsClassifyService; + + @Autowired + private ICourseService courseService; + + /** + * 获取所有,包括一级分类&二级分类 + */ + public List queryAllClassify(){ + List resultList = new ArrayList(); + for(ConstsClassifyVO vo : this.queryAllClassifyMap().values()){ + resultList.add(vo); + } + return resultList; + } + + /** + * 获取所有分类 + */ + public Map queryAllClassifyMap(){ + Map resultMap = new LinkedHashMap(); + Iterator it = constsClassifyService.queryAll().iterator(); + while(it.hasNext()){ + ConstsClassify c = it.next(); + if("0".equals(c.getParentCode())){//一级分类 + ConstsClassifyVO vo = new ConstsClassifyVO(); + BeanUtils.copyProperties(c, vo); + resultMap.put(vo.getCode(), vo); + }else{//二级分类 + if(null != resultMap.get(c.getParentCode())){ + resultMap.get(c.getParentCode()).getSubClassifyList().add(c);//添加到子分类中 + } + } + } + return resultMap; + } + + /** + * 为分类设置课程推荐 + */ + public void prepareRecomdCourses(List classifyVoList){ + if(CollectionUtils.isNotEmpty(classifyVoList)){ + for(ConstsClassifyVO item : classifyVoList){ + CourseQueryDto queryEntity = new CourseQueryDto(); + queryEntity.setCount(5); + queryEntity.descSortField("weight"); + queryEntity.setClassify(item.getCode());//分类code + + List tmpList = this.courseService.queryList(queryEntity); + if(CollectionUtils.isNotEmpty(tmpList)){ + item.setRecomdCourseList(tmpList); + } + } + } + } + +} diff --git a/src/main/java/com/krt/dairy/portal/controller/AuthController.java b/src/main/java/com/krt/dairy/portal/controller/AuthController.java new file mode 100644 index 0000000..0162a7c --- /dev/null +++ b/src/main/java/com/krt/dairy/portal/controller/AuthController.java @@ -0,0 +1,132 @@ +package com.krt.dairy.portal.controller; + +import com.krt.dairy.common.util.EncryptUtil; +import com.krt.dairy.common.web.JsonView; +import com.krt.dairy.common.web.SessionContext; +import com.krt.dairy.core.auth.domain.AuthUser; +import com.krt.dairy.core.auth.service.IAuthUserService; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authc.AuthenticationException; +import org.apache.shiro.authc.UsernamePasswordToken; +import org.apache.shiro.subject.Subject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; + + +/** + * 用户登录 & 注册 + */ +@Controller +@RequestMapping("/auth") +public class AuthController extends BaseController{ + + @Autowired + private IAuthUserService authUserService; + + /** + * 注册页面 + */ + @RequestMapping(value = "/register") + public ModelAndView register(){ + if(SessionContext.isLogin()){ + return new ModelAndView("redirect:/index.html"); + } + return new ModelAndView("auth/register"); + } + + /** + * 实现注册 + */ + @RequestMapping(value = "/doRegister") + @ResponseBody + public String doRegister(AuthUser authUser, String identiryCode, HttpServletRequest request) { + //验证码判断 + if(identiryCode!=null && !identiryCode.equalsIgnoreCase(SessionContext.getIdentifyCode(request))){ + return JsonView.render(2); + } + + AuthUser tmpUser = authUserService.getByUsername(authUser.getUsername()); + if(tmpUser != null){ + return JsonView.render(1); + }else{ + authUser.setPassword(EncryptUtil.encodedByMD5(authUser.getPassword())); + authUserService.createSelectivity(authUser); + return JsonView.render(0); + } + } + + /** + * 登录页面 + */ + @RequestMapping(value = "/login") + public ModelAndView login(){ + if(SessionContext.isLogin()){ + return new ModelAndView("redirect:/index.html"); + } + return new ModelAndView("auth/login"); + } + + /** + * ajax登录 + */ + @RequestMapping(value = "/ajaxlogin") + @ResponseBody + public String ajaxLogin(AuthUser user, String identiryCode, Integer rememberMe, + HttpServletRequest request){ + //验证码判断 + if(identiryCode!=null && + !identiryCode.equalsIgnoreCase(SessionContext.getIdentifyCode(request))){ + return JsonView.render(2, "验证码不正确!"); + } + Subject currentUser = SecurityUtils.getSubject(); + UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername() + ,EncryptUtil.encodedByMD5(user.getPassword())); + try { + if(rememberMe != null && rememberMe == 1){ + token.setRememberMe(true); + } + currentUser.login(token);//shiro:不抛出异常,登陆成功 + return new JsonView().toString(); + }catch(AuthenticationException e){ //登录失败 + return JsonView.render(1, "用户名或密码不正确"); + } + } + + @RequestMapping(value = "/doLogin") + public ModelAndView doLogin(AuthUser user, String identiryCode, HttpServletRequest request){ + + //如果已经登录过 + if(SessionContext.getAuthUser() != null){ + return new ModelAndView("redirect:/user/home.html"); + } + + //验证码判断 + if(identiryCode!=null && !identiryCode.equalsIgnoreCase(SessionContext.getIdentifyCode(request))){ + ModelAndView mv = new ModelAndView("auth/login"); + mv.addObject("errcode", 1); + return mv; + } + UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(),EncryptUtil.encodedByMD5(user.getPassword())); + try { + Subject currentUser = SecurityUtils.getSubject(); + currentUser.login(token);//shiro实现登录 + return new ModelAndView("redirect:/user/home.html"); + }catch(AuthenticationException e){ //登录失败 + ModelAndView mv = new ModelAndView("auth/login"); + mv.addObject("errcode", 2); + return mv; + } + } + + @RequestMapping(value = "/logout") + public ModelAndView logout(HttpServletRequest request) { + SessionContext.shiroLogout(); + return new ModelAndView("redirect:/index.html"); + } + +} diff --git a/src/main/java/com/krt/dairy/portal/controller/BaseController.java b/src/main/java/com/krt/dairy/portal/controller/BaseController.java new file mode 100644 index 0000000..1df07dc --- /dev/null +++ b/src/main/java/com/krt/dairy/portal/controller/BaseController.java @@ -0,0 +1,25 @@ +package com.krt.dairy.portal.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.ModelAttribute; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@Controller +public class BaseController { + @ModelAttribute + public void initPath(HttpServletRequest request, HttpServletResponse response, ModelMap model){ + String base = request.getContextPath(); + + String fullPath = request.getScheme()+"://"+request.getServerName() + +":" +request.getLocalPort() +base; + String backstage = request.getScheme()+"://"+request.getServerName() + +":" +request.getLocalPort()+"/h"; + model.addAttribute("pathUrl", fullPath); + model.addAttribute("backstage", backstage); + model.addAttribute("fullPath", fullPath); + + } +} diff --git a/src/main/java/com/krt/dairy/portal/controller/CollectionsController.java b/src/main/java/com/krt/dairy/portal/controller/CollectionsController.java new file mode 100644 index 0000000..d3f9c31 --- /dev/null +++ b/src/main/java/com/krt/dairy/portal/controller/CollectionsController.java @@ -0,0 +1,74 @@ +package com.krt.dairy.portal.controller; + +import com.krt.dairy.common.web.JsonView; +import com.krt.dairy.common.web.SessionContext; +import com.krt.dairy.core.consts.CourseEnum; +import com.krt.dairy.core.user.domain.UserCollections; +import com.krt.dairy.core.user.service.IUserCollectionsService; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.Date; +import java.util.List; + +/** + * 用户收藏 + */ +@Controller +@RequestMapping("/collections") +public class CollectionsController extends BaseController{ + + @Autowired + private IUserCollectionsService userCollectionsService; + + @RequestMapping(value = "/doCollection") + @ResponseBody + public String doCollection(Long courseId){ + //获取当前用户 + Long curUserId = SessionContext.getUserId(); + UserCollections userCollections = new UserCollections(); + + userCollections.setUserId(curUserId); + userCollections.setClassify(CourseEnum.COLLECTION_CLASSIFY_COURSE.value());//课程收藏 + userCollections.setObjectId(courseId); + List list = userCollectionsService.queryAll(userCollections); + + if(CollectionUtils.isNotEmpty(list)){ + userCollectionsService.delete(list.get(0)); + return new JsonView(0).toString(); + }else{ + userCollections.setCreateTime(new Date()); + userCollectionsService.createSelectivity(userCollections); + return new JsonView(1).toString();//已经收藏 + } + } + + /** + * 是否已经收藏 + * @param courseId + * @return + */ + @RequestMapping(value = "/isCollection") + @ResponseBody + public String isCollection(Long courseId){ + //获取当前用户 + Long curUserId = SessionContext.getUserId(); + UserCollections userCollections = new UserCollections(); + + userCollections.setUserId(curUserId); + userCollections.setClassify(CourseEnum.COLLECTION_CLASSIFY_COURSE.value());//课程收藏 + userCollections.setObjectId(courseId); + List list = userCollectionsService.queryAll(userCollections); + + if(CollectionUtils.isNotEmpty(list)){//已经收藏 + return new JsonView(1).toString(); + }else{ + return new JsonView(0).toString(); + } + } + +} + diff --git a/src/main/java/com/krt/dairy/portal/controller/CourseCommentController.java b/src/main/java/com/krt/dairy/portal/controller/CourseCommentController.java new file mode 100644 index 0000000..c563af3 --- /dev/null +++ b/src/main/java/com/krt/dairy/portal/controller/CourseCommentController.java @@ -0,0 +1,121 @@ +package com.krt.dairy.portal.controller; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.common.storage.QiniuStorage; +import com.krt.dairy.common.web.JsonView; +import com.krt.dairy.common.web.SessionContext; +import com.krt.dairy.core.course.domain.CourseComment; +import com.krt.dairy.core.course.domain.CourseSection; +import com.krt.dairy.core.course.service.ICourseCommentService; +import com.krt.dairy.core.course.service.ICourseSectionService; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import java.util.Date; + +/** + * 课程评论管理 + */ +@Controller +@RequestMapping("/courseComment") +public class CourseCommentController extends BaseController{ + + @Autowired + private ICourseCommentService courseCommentService; + + @Autowired + private ICourseSectionService courseSectionService; + + /** + * 加载评论&答疑 + * sectionId:章节id + * courseId :课程id + * type : 类型 + * @return + */ + @RequestMapping("/segment") + public ModelAndView segment(CourseComment queryEntity , TailPage page){ + if(null == queryEntity.getCourseId() || queryEntity.getType() == null) + return new ModelAndView("error/404"); + + ModelAndView mv = new ModelAndView("commentSegment"); + TailPage commentPage = this.courseCommentService.queryPage(queryEntity, page); + + //处理用户头像 + for(CourseComment item : commentPage.getItems()){ + if(StringUtils.isNotEmpty(item.getHeader())){ + item.setHeader(QiniuStorage.getUrl(item.getHeader())); + } + } + + mv.addObject("page", commentPage); + return mv; + } + + /** + * 发表评论 + * @param entity + * @return + */ + @RequestMapping(value = "/doComment") + @ResponseBody + public String doComment(HttpServletRequest request, CourseComment entity,String indeityCode){ + + //验证码判断 + if(null == indeityCode || + (indeityCode != null && !indeityCode.equalsIgnoreCase(SessionContext.getIdentifyCode(request)))){ + return new JsonView(2).toString();//验证码错误 + } + + //文字太长 + if(entity.getContent().trim().length() > 200 || entity.getContent().trim().length() == 0){ + return new JsonView(3).toString();//文字太长或者为空 + } + + if(null != entity.getRefId()){//来自于个人中心评论 + CourseComment refComment = this.courseCommentService.getById(entity.getRefId()); + if(null != refComment){ + CourseSection courseSection = courseSectionService.getById(refComment.getSectionId()); + if(null != courseSection){ + entity.setRefContent(refComment.getContent()); + entity.setRefId(entity.getRefId()); + entity.setCourseId(refComment.getCourseId()); + entity.setSectionId(refComment.getSectionId()); + entity.setSectionTitle(courseSection.getName()); + + entity.setToUsername(refComment.getUsername());//引用的评论的username + entity.setUsername(SessionContext.getUsername()); + entity.setCreateTime(new Date()); + entity.setCreateUser(SessionContext.getUsername()); + entity.setUpdateTime(new Date()); + entity.setUpdateUser(SessionContext.getUsername()); + + this.courseCommentService.createSelectivity(entity); + return new JsonView(0).toString(); + } + } + }else{ + CourseSection courseSection = courseSectionService.getById(entity.getSectionId()); + if(null != courseSection){ + entity.setSectionTitle(courseSection.getName()); + entity.setToUsername(entity.getCreateUser());//toUsername可以作为页面入参 + entity.setUsername(SessionContext.getUsername()); + entity.setCreateTime(new Date()); + entity.setCreateUser(SessionContext.getUsername()); + entity.setUpdateTime(new Date()); + entity.setUpdateUser(SessionContext.getUsername()); + + this.courseCommentService.createSelectivity(entity); + return new JsonView(0).toString(); + } + } + return new JsonView(1).toString(); + } + +} + diff --git a/src/main/java/com/krt/dairy/portal/controller/CourseController.java b/src/main/java/com/krt/dairy/portal/controller/CourseController.java new file mode 100644 index 0000000..5a8671a --- /dev/null +++ b/src/main/java/com/krt/dairy/portal/controller/CourseController.java @@ -0,0 +1,162 @@ +package com.krt.dairy.portal.controller; + +import com.krt.dairy.common.storage.QiniuStorage; +import com.krt.dairy.common.web.JsonView; +import com.krt.dairy.common.web.SessionContext; +import com.krt.dairy.core.auth.domain.AuthUser; +import com.krt.dairy.core.auth.service.IAuthUserService; +import com.krt.dairy.core.course.domain.Course; +import com.krt.dairy.core.course.domain.CourseQueryDto; +import com.krt.dairy.core.course.domain.CourseSection; +import com.krt.dairy.core.course.service.ICourseSectionService; +import com.krt.dairy.core.course.service.ICourseService; +import com.krt.dairy.core.user.domain.UserCourseSection; +import com.krt.dairy.core.user.service.IUserCourseSectionService; +import com.krt.dairy.portal.business.ICourseBusiness; +import com.krt.dairy.portal.vo.CourseSectionVO; +import net.sf.json.JSONObject; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; + +import java.util.Date; +import java.util.List; + +/** + * 课程详情信息 + */ +@Controller +@RequestMapping("/course") +public class CourseController extends BaseController { + + @Autowired + private ICourseBusiness courseBusiness; + + @Autowired + private ICourseService courseService; + + @Autowired + private IAuthUserService authUserService; + + @Autowired + private ICourseSectionService courseSectionService; + + @Autowired + private IUserCourseSectionService userCourseSectionService; + + + /** + * 课程章节页面 + * @return + */ + @RequestMapping("/learn/{courseId}") + public ModelAndView learn(@PathVariable Long courseId){ + if(null == courseId) + return new ModelAndView("error/404"); + + //获取课程 + Course course = courseService.getById(courseId); + if(null == course) + return new ModelAndView("error/404"); + + //获取课程章节 + ModelAndView mv = new ModelAndView("learn"); + List chaptSections = this.courseBusiness.queryCourseSection(courseId); + mv.addObject("course", course); + mv.addObject("chaptSections", chaptSections); + + //获取讲师 + AuthUser courseTeacher = this.authUserService.getByUsername(course.getUsername()); + if(null != courseTeacher && StringUtils.isNotEmpty(courseTeacher.getHeader())){ + courseTeacher.setHeader(QiniuStorage.getUrl(courseTeacher.getHeader())); + } + mv.addObject("courseTeacher", courseTeacher); + + //获取推荐课程 + CourseQueryDto queryEntity = new CourseQueryDto(); + queryEntity.descSortField("weight"); + queryEntity.setCount(5);//5门推荐课程 + queryEntity.setSubClassify(course.getSubClassify()); + List recomdCourseList = this.courseService.queryList(queryEntity); + mv.addObject("recomdCourseList", recomdCourseList); + + //当前学习的章节 + UserCourseSection userCourseSection = new UserCourseSection(); + userCourseSection.setCourseId(course.getId()); + userCourseSection.setUserId(SessionContext.getUserId()); + userCourseSection = this.userCourseSectionService.queryLatest(userCourseSection); + if(null != userCourseSection){ + CourseSection curCourseSection = this.courseSectionService.getById(userCourseSection.getSectionId()); + mv.addObject("curCourseSection", curCourseSection); + } + + return mv; + } + + + /** + * 视频学习页面 + * @return + */ + @RequestMapping("/video/{sectionId}") + public ModelAndView video(@PathVariable Long sectionId){ + if(null == sectionId) + return new ModelAndView("error/404"); + + CourseSection courseSection = courseSectionService.getById(sectionId); + if(null == courseSection) + return new ModelAndView("error/404"); + + //课程章节 + ModelAndView mv = new ModelAndView("video"); + List chaptSections = this.courseBusiness.queryCourseSection(courseSection.getCourseId()); + mv.addObject("courseSection", courseSection); + mv.addObject("chaptSections", chaptSections); + + //学习记录 + UserCourseSection userCourseSection = new UserCourseSection(); + userCourseSection.setUserId(SessionContext.getUserId()); + userCourseSection.setCourseId(courseSection.getCourseId()); + userCourseSection.setSectionId(courseSection.getId()); + UserCourseSection result = userCourseSectionService.queryLatest(userCourseSection); + + if(null == result){//如果没有,插入 + userCourseSection.setCreateTime(new Date()); + userCourseSection.setCreateUser(SessionContext.getUsername()); + userCourseSection.setUpdateTime(new Date()); + userCourseSection.setUpdateUser(SessionContext.getUsername()); + + userCourseSectionService.createSelectivity(userCourseSection); + }else{ + result.setUpdateTime(new Date()); + userCourseSectionService.update(result); + } + return mv; + } + + @RequestMapping(value = "/getCurLeanInfo") + @ResponseBody + public String getCurLeanInfo(){ + JsonView jv = new JsonView(); + //加载当前用户学习最新课程 + if(SessionContext.isLogin()){ + UserCourseSection userCourseSection = new UserCourseSection(); + userCourseSection.setUserId(SessionContext.getUserId()); + userCourseSection = this.userCourseSectionService.queryLatest(userCourseSection); + if(null != userCourseSection){ + JSONObject jsObj = new JSONObject(); + CourseSection curCourseSection = this.courseSectionService.getById(userCourseSection.getSectionId()); + jsObj.put("curCourseSection", curCourseSection); + Course curCourse = courseService.getById(userCourseSection.getCourseId()); + jsObj.put("curCourse", curCourse); + jv.setData(jsObj); + } + } + return jv.toString(); + } + +} diff --git a/src/main/java/com/krt/dairy/portal/controller/CourseListController.java b/src/main/java/com/krt/dairy/portal/controller/CourseListController.java new file mode 100644 index 0000000..f484ef9 --- /dev/null +++ b/src/main/java/com/krt/dairy/portal/controller/CourseListController.java @@ -0,0 +1,105 @@ +package com.krt.dairy.portal.controller; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.core.consts.CourseEnum; +import com.krt.dairy.core.consts.domain.ConstsClassify; +import com.krt.dairy.core.consts.service.IConstsClassifyService; +import com.krt.dairy.core.course.domain.Course; +import com.krt.dairy.core.course.service.ICourseService; +import com.krt.dairy.portal.business.IPortalBusiness; +import com.krt.dairy.portal.vo.ConstsClassifyVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * 课程分类页 + */ + +@Controller +@RequestMapping("/course") +public class CourseListController extends BaseController { + + @Autowired + private IConstsClassifyService constsClassifyService; + + @Autowired + private IPortalBusiness portalBusiness; + + @Autowired + private ICourseService courseService; + + /** + * 课程分类页 + * @param c 分类code + * @param sort 排序 + * @param page 分页 + */ + @RequestMapping("/list") + public ModelAndView list(String c, String sort, TailPage page){ + ModelAndView mv = new ModelAndView("list"); + String curCode = "-1";//当前方向code + String curSubCode = "-2";//当前分类code + + //加载所有课程分类 + Map classifyMap = portalBusiness.queryAllClassifyMap(); + //所有一级分类 + List classifysList = new ArrayList(); + for(ConstsClassifyVO vo : classifyMap.values()){ + classifysList.add(vo); + } + mv.addObject("classifys", classifysList); + + //当前分类 + ConstsClassify curClassify = constsClassifyService.getByCode(c); + + if(null == curClassify){//没有此分类,加载所有二级分类 + List subClassifys = new ArrayList(); + for(ConstsClassifyVO vo : classifyMap.values()){ + subClassifys.addAll(vo.getSubClassifyList()); + } + mv.addObject("subClassifys", subClassifys); + }else{ + if(!"0".endsWith(curClassify.getParentCode())){//当前是二级分类 + curSubCode = curClassify.getCode(); + curCode = curClassify.getParentCode(); + mv.addObject("subClassifys", classifyMap.get(curClassify.getParentCode()).getSubClassifyList());//此分类平级的二级分类 + }else{//当前是一级分类 + curCode = curClassify.getCode(); + mv.addObject("subClassifys", classifyMap.get(curClassify.getCode()).getSubClassifyList());//此分类下的二级分类 + } + } + mv.addObject("curCode", curCode); + mv.addObject("curSubCode", curSubCode); + + //分页排序数据 + //分页的分类参数 + Course queryEntity = new Course(); + if(!"-1".equals(curCode)){ + queryEntity.setClassify(curCode); + } + if(!"-2".equals(curSubCode)){ + queryEntity.setSubClassify(curSubCode); + } + + //排序参数 + if("pop".equals(sort)){//最热 + page.descSortField("studyCount"); + }else{ + sort = "last"; + page.descSortField("id"); + } + mv.addObject("sort", sort); + + //分页参数 + queryEntity.setOnsale(CourseEnum.ONSALE.value()); + page = this.courseService.queryPage(queryEntity, page); + mv.addObject("page", page); + return mv; + } +} diff --git a/src/main/java/com/krt/dairy/portal/controller/FollowerController.java b/src/main/java/com/krt/dairy/portal/controller/FollowerController.java new file mode 100644 index 0000000..69392af --- /dev/null +++ b/src/main/java/com/krt/dairy/portal/controller/FollowerController.java @@ -0,0 +1,70 @@ +package com.krt.dairy.portal.controller; + +import com.krt.dairy.common.web.JsonView; +import com.krt.dairy.common.web.SessionContext; +import com.krt.dairy.core.user.domain.UserFollows; +import com.krt.dairy.core.user.service.IUserFollowsService; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.Date; +import java.util.List; + +/** + * 用户关注 + */ +@Controller +@RequestMapping("follow") +public class FollowerController extends BaseController { + + @Autowired + private IUserFollowsService userFollowsService; + + @RequestMapping(value = "/doFollow") + @ResponseBody + public String doFollow(Long followId){ + //获取当前用户 + Long curUserId = SessionContext.getUserId(); + UserFollows userFollows = new UserFollows(); + + userFollows.setUserId(curUserId); + userFollows.setFollowId(followId); + List list = userFollowsService.queryAll(userFollows); + + if(CollectionUtils.isNotEmpty(list)){ + userFollowsService.delete(list.get(0)); + return new JsonView(0).toString(); + }else{ + userFollows.setCreateTime(new Date()); + userFollowsService.createSelectivity(userFollows); + return new JsonView(1).toString();//已经关注 + } + } + + /** + * 是否已经关注 + */ + @RequestMapping(value = "/isFollow") + @ResponseBody + public String isFollow(Long followId){ + //获取当前用户 + Long curUserId = SessionContext.getUserId(); + UserFollows userFollows = new UserFollows(); + + userFollows.setUserId(curUserId); + userFollows.setFollowId(followId); + List list = userFollowsService.queryAll(userFollows); + + if(CollectionUtils.isNotEmpty(list)){//已经关注 + return new JsonView(1).toString(); + }else{ + return new JsonView(0).toString(); + } + } + +} + + diff --git a/src/main/java/com/krt/dairy/portal/controller/PortalController.java b/src/main/java/com/krt/dairy/portal/controller/PortalController.java new file mode 100644 index 0000000..e3a81b2 --- /dev/null +++ b/src/main/java/com/krt/dairy/portal/controller/PortalController.java @@ -0,0 +1,87 @@ +package com.krt.dairy.portal.controller; + +import com.krt.dairy.core.auth.domain.AuthUser; +import com.krt.dairy.core.auth.service.IAuthUserService; +import com.krt.dairy.core.consts.CourseEnum; +import com.krt.dairy.core.consts.domain.ConstsSiteCarousel; +import com.krt.dairy.core.consts.service.IConstsSiteCarouselService; +import com.krt.dairy.core.course.domain.Course; +import com.krt.dairy.core.course.domain.CourseQueryDto; +import com.krt.dairy.core.course.service.ICourseService; +import com.krt.dairy.portal.business.IPortalBusiness; +import com.krt.dairy.portal.vo.ConstsClassifyVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import java.util.List; + +/** + * 网站主页 + */ +@Controller +@RequestMapping() +public class PortalController extends BaseController { + + @Autowired + private IPortalBusiness portalBusiness; + + @Autowired + private IConstsSiteCarouselService siteCarouselService; + + @Autowired + private ICourseService courseService; + + @Autowired + private IAuthUserService authUserService; + + + /** + * 首页 + */ + @RequestMapping("/index") + public ModelAndView index(){ + ModelAndView mv = new ModelAndView("index"); + + //加载轮播 + List carouselList = siteCarouselService.queryCarousels(5); + mv.addObject("carouselList", carouselList); + + //课程分类(一级分类) + List classifys = portalBusiness.queryAllClassify(); + + //课程推荐 + portalBusiness.prepareRecomdCourses(classifys); + mv.addObject("classifys", classifys); + + + //获取5门实战课推荐,根据权重(weight)进行排序 + CourseQueryDto queryEntity = new CourseQueryDto(); + queryEntity.setCount(5);//5门 + queryEntity.setFree(CourseEnum.FREE_NOT.value());//非免费的:实战课 + queryEntity.descSortField("weight");//按照weight降序排列 + List actionCourseList = this.courseService.queryList(queryEntity); + mv.addObject("actionCourseList", actionCourseList); + + //获取5门免费课推荐,根据权重(weight)进行排序 + queryEntity.setFree(CourseEnum.FREE.value());//非免费的:实战课 + List freeCourseList = this.courseService.queryList(queryEntity); + mv.addObject("freeCourseList", freeCourseList); + + //获取7门java课程,根据权重(学习数量studyCount)进行排序 + queryEntity.setCount(7); + queryEntity.setFree(null);//不分实战和免费类别 + queryEntity.setSubClassify("java");//java分类 + queryEntity.descSortField("studyCount");//按照studyCount降序排列 + List javaCourseList = this.courseService.queryList(queryEntity); + mv.addObject("javaCourseList", javaCourseList); + + //加载讲师 + List recomdTeacherList = authUserService.queryRecomd(); + mv.addObject("recomdTeacherList", recomdTeacherList); + + return mv; + } +} + diff --git a/src/main/java/com/krt/dairy/portal/controller/UserController.java b/src/main/java/com/krt/dairy/portal/controller/UserController.java new file mode 100644 index 0000000..2dde232 --- /dev/null +++ b/src/main/java/com/krt/dairy/portal/controller/UserController.java @@ -0,0 +1,196 @@ +package com.krt.dairy.portal.controller; + +import com.krt.dairy.common.page.TailPage; +import com.krt.dairy.common.storage.QiniuStorage; +import com.krt.dairy.common.util.EncryptUtil; +import com.krt.dairy.common.web.JsonView; +import com.krt.dairy.common.web.SessionContext; +import com.krt.dairy.core.auth.domain.AuthUser; +import com.krt.dairy.core.auth.service.IAuthUserService; +import com.krt.dairy.core.consts.domain.ConstsCollege; +import com.krt.dairy.core.consts.service.IConstsCollegeService; +import com.krt.dairy.core.course.domain.CourseComment; +import com.krt.dairy.core.course.service.ICourseCommentService; +import com.krt.dairy.core.user.domain.UserCollections; +import com.krt.dairy.core.user.domain.UserCourseSection; +import com.krt.dairy.core.user.domain.UserCourseSectionDto; +import com.krt.dairy.core.user.domain.UserFollowStudyRecord; +import com.krt.dairy.core.user.service.IUserCollectionsService; +import com.krt.dairy.core.user.service.IUserCourseSectionService; +import com.krt.dairy.core.user.service.IUserFollowsService; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.ModelAndView; + +import java.io.IOException; +import java.util.List; + +@Controller +@RequestMapping("/user") +public class UserController extends BaseController { + + @Autowired + private IUserFollowsService userFollowsService; + + @Autowired + private IAuthUserService authUserService; + + @Autowired + private IUserCourseSectionService userCourseSectionService; + + @Autowired + private IUserCollectionsService userCollectionsService; + + @Autowired + private ICourseCommentService courseCommentService; + + @Autowired + private IConstsCollegeService entityService; + + /** + * 首页 + */ + @RequestMapping("/home") + public ModelAndView index(TailPage page){ + ModelAndView mv = new ModelAndView("user/home"); + mv.addObject("curNav","home"); + + //加载关注用户的动态 + UserFollowStudyRecord queryEntity = new UserFollowStudyRecord(); + queryEntity.setUserId(SessionContext.getUserId()); + page = userFollowsService.queryUserFollowStudyRecordPage(queryEntity, page); + + //处理用户头像 + for(UserFollowStudyRecord item : page.getItems()){ + if(StringUtils.isNotEmpty(item.getHeader())){ + item.setHeader(QiniuStorage.getUrl(item.getHeader())); + } + } + mv.addObject("page", page); + + return mv; + } + + /** + * 我的课程 + */ + @RequestMapping("/course") + public ModelAndView course(TailPage page){ + ModelAndView mv = new ModelAndView("user/course"); + mv.addObject("curNav","course"); + + UserCourseSection queryEntity = new UserCourseSection(); + queryEntity.setUserId(SessionContext.getUserId()); + page = userCourseSectionService.queryPage(queryEntity, page); + mv.addObject("page", page); + + return mv; + } + + /** + * 我的收藏 + */ + @RequestMapping("/collect") + public ModelAndView collect(TailPage page){ + ModelAndView mv = new ModelAndView("user/collect"); + mv.addObject("curNav","collect"); + UserCollections queryEntity = new UserCollections(); + queryEntity.setUserId(SessionContext.getUserId()); + page = userCollectionsService.queryPage(queryEntity, page); + + mv.addObject("page", page); + return mv; + } + + /** + * 信息 + */ + @RequestMapping("/info") + public ModelAndView info(){ + ModelAndView mv = new ModelAndView("user/info"); + mv.addObject("curNav","info"); + List colleges = entityService.queryAll(null); + mv.addObject("colleges",colleges); + AuthUser authUser = authUserService.getById(SessionContext.getUserId()); + if(null != authUser && StringUtils.isNotEmpty(authUser.getHeader())){ + authUser.setHeader(QiniuStorage.getUrl(authUser.getHeader())); + } + mv.addObject("authUser",authUser); + return mv; + } + /** + * 保存信息 + */ + @RequestMapping("/saveInfo") + @ResponseBody + public String saveInfo(AuthUser authUser, @RequestParam MultipartFile pictureImg){ + try { + authUser.setId(SessionContext.getUserId()); + if (null != pictureImg && pictureImg.getBytes().length > 0) { + String key = QiniuStorage.uploadImage(pictureImg.getBytes()); + authUser.setHeader(key); + } + authUserService.updateSelectivity(authUser); + } catch (IOException e) { + e.printStackTrace(); + } + return new JsonView().toString(); + } + + /** + * 密码 + */ + @RequestMapping("/passwd") + public ModelAndView passwd(){ + ModelAndView mv = new ModelAndView("user/passwd"); + mv.addObject("curNav","passwd"); + return mv; + } + + /** + * 密码 + */ + @RequestMapping("/savePasswd") + @ResponseBody + public String savePasswd(String oldPassword, String password, String rePassword){ + AuthUser currentUser = authUserService.getById(SessionContext.getUserId()); + if(null == currentUser){ + return JsonView.render(1,"用户不存在!"); + } + oldPassword = EncryptUtil.encodedByMD5(oldPassword.trim()); + if(!oldPassword.equals(currentUser.getPassword())){ + return JsonView.render(1,"旧密码不正确!"); + } + if(StringUtils.isEmpty(password.trim())){ + return JsonView.render(1,"新密码不能为空!"); + } + if(!password.trim().equals(rePassword.trim())){ + return JsonView.render(1,"新密码与重复密码不一致!"); + } + currentUser.setPassword(EncryptUtil.encodedByMD5(password)); + authUserService.updateSelectivity(currentUser); + return new JsonView().toString(); + } + + /** + * 问答 + */ + @RequestMapping("/qa") + public ModelAndView qa(TailPage page){ + ModelAndView mv = new ModelAndView("user/qa"); + mv.addObject("curNav","qa"); + + CourseComment queryEntity = new CourseComment(); + queryEntity.setUsername(SessionContext.getUsername()); + page = courseCommentService.queryMyQAItemsPage(queryEntity, page); + mv.addObject("page", page); + + return mv; + } + +} diff --git a/src/main/java/com/krt/dairy/portal/vo/ConstsClassifyVO.java b/src/main/java/com/krt/dairy/portal/vo/ConstsClassifyVO.java new file mode 100644 index 0000000..8a0950c --- /dev/null +++ b/src/main/java/com/krt/dairy/portal/vo/ConstsClassifyVO.java @@ -0,0 +1,38 @@ +package com.krt.dairy.portal.vo; + +import com.krt.dairy.core.consts.domain.ConstsClassify; +import com.krt.dairy.core.course.domain.Course; + +import java.util.ArrayList; +import java.util.List; + +/** + * 页面展示 value object + */ +public class ConstsClassifyVO extends ConstsClassify { + + private static final long serialVersionUID = -6898939223836635781L; + + //子分类列表 + private List subClassifyList = new ArrayList(); + + //课程推荐列表 + private List recomdCourseList ; + + public List getSubClassifyList() { + return subClassifyList; + } + + public void setSubClassifyList(List subClassifyList) { + this.subClassifyList = subClassifyList; + } + + public List getRecomdCourseList() { + return recomdCourseList; + } + + public void setRecomdCourseList(List recomdCourseList) { + this.recomdCourseList = recomdCourseList; + } + +} diff --git a/src/main/java/com/krt/dairy/portal/vo/CourseSectionVO.java b/src/main/java/com/krt/dairy/portal/vo/CourseSectionVO.java new file mode 100644 index 0000000..97cdf7d --- /dev/null +++ b/src/main/java/com/krt/dairy/portal/vo/CourseSectionVO.java @@ -0,0 +1,26 @@ +package com.krt.dairy.portal.vo; + +import com.krt.dairy.core.course.domain.CourseSection; + +import java.util.ArrayList; +import java.util.List; + +/** + * 课程章节 + */ +public class CourseSectionVO extends CourseSection{ + private static final long serialVersionUID = 180753077428934254L; + + //小节 + private List sections = new ArrayList(); + + + public List getSections() { + return sections; + } + + public void setSections(List sections) { + this.sections = sections; + } + +} diff --git a/src/main/java/com/krt/dairy/web/IdentifyCodeController.java b/src/main/java/com/krt/dairy/web/IdentifyCodeController.java new file mode 100644 index 0000000..5118719 --- /dev/null +++ b/src/main/java/com/krt/dairy/web/IdentifyCodeController.java @@ -0,0 +1,50 @@ +package com.krt.dairy.web; + +import com.krt.dairy.common.web.SessionContext; +import org.apache.commons.lang.RandomStringUtils; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +import javax.imageio.ImageIO; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.IOException; + +/** + * 验证码生成器 + */ +@Controller +@RequestMapping("/tools/identiry") +public class IdentifyCodeController { + @RequestMapping("/code") + public void init(HttpServletRequest request, HttpServletResponse response){ + String random=RandomStringUtils.randomAlphanumeric(4); + SessionContext.setAttribute(request, SessionContext.IDENTIFY_CODE_KEY, random); + response.setContentType("image/jpeg"); + response.addHeader("pragma", "NO-cache"); + response.addHeader("Cache-Control","no-cache"); + response.addDateHeader("Expries",0); + int width=110, height=33; + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + Graphics g = image.getGraphics(); + //以下填充背景色 + g.setColor(new Color(225,225,225)); + Font DeFont=new Font("SansSerif", Font.PLAIN, 26); + g.setFont(DeFont); + g.fillRect(0, 0, width, height); + //设置字体色 + g.setColor(Color.BLACK); + g.drawString(random,20,25); + g.dispose(); + try { + ServletOutputStream outStream = response.getOutputStream(); + ImageIO.write(image, "JPG", outStream); + outStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/krt/dairy/web/auth/AuthFilter.java b/src/main/java/com/krt/dairy/web/auth/AuthFilter.java new file mode 100644 index 0000000..a363ef6 --- /dev/null +++ b/src/main/java/com/krt/dairy/web/auth/AuthFilter.java @@ -0,0 +1,63 @@ + +package com.krt.dairy.web.auth; + +import com.krt.dairy.common.util.JsonUtil; +import com.krt.dairy.common.web.HttpHelper; +import com.krt.dairy.common.web.JsonView; + +import org.apache.shiro.subject.Subject; +import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; + +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.PrintWriter; + +/** + * shiro 对用户是否登录的 filter + */ +public class AuthFilter extends FormAuthenticationFilter { + private static final Integer SHIRO_TIME_OUT = 1001; + + @Override + protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) { + return super.isAccessAllowed(request, response, mappedValue); + } + + @Override + protected boolean onAccessDenied(ServletRequest request,ServletResponse response) throws Exception { + HttpServletRequest httpservletrequest = (HttpServletRequest) request; + // 获取请求路径 + String login = httpservletrequest.getServletPath(); + // 判断请求路径是否为登录页 如果为登录页放行 + if (login.equals("/index.html")) { + return true; + } + // 获取当前登录用户 + Subject subject = getSubject(request, response); + // 判断是否授权 + if (subject.isAuthenticated()) { + return true; + } + + // 判断是否为ajax请求 + if (HttpHelper.isAjaxRequest(httpservletrequest)) { + JsonView jv = new JsonView(); + jv.setMessage("SHIRO登录超时"); + jv.setErrcode(SHIRO_TIME_OUT); + HttpServletResponse _response = (HttpServletResponse) response; + PrintWriter pw = _response.getWriter(); + _response.setContentType("application/json"); + pw.write(JsonUtil.toJson(jv)); + pw.flush(); + pw.close(); + } else { + saveRequestAndRedirectToLogin(request, response); + } + + // 如果没有授权则跳转到登录页面 + return false; + } + +} diff --git a/src/main/java/com/krt/dairy/web/auth/AuthRealm.java b/src/main/java/com/krt/dairy/web/auth/AuthRealm.java new file mode 100644 index 0000000..b9a71b8 --- /dev/null +++ b/src/main/java/com/krt/dairy/web/auth/AuthRealm.java @@ -0,0 +1,88 @@ +package com.krt.dairy.web.auth; + +import com.krt.dairy.common.storage.QiniuStorage; +import com.krt.dairy.common.storage.ThumbModel; +import com.krt.dairy.common.web.SessionContext; +import com.krt.dairy.common.web.auth.SessionUser; +import com.krt.dairy.core.auth.domain.AuthUser; +import com.krt.dairy.core.auth.service.IAuthUserService; +import org.apache.commons.lang.StringUtils; +import org.apache.shiro.authc.*; +import org.apache.shiro.authz.AuthorizationException; +import org.apache.shiro.authz.AuthorizationInfo; +import org.apache.shiro.authz.SimpleAuthorizationInfo; +import org.apache.shiro.realm.AuthorizingRealm; +import org.apache.shiro.subject.PrincipalCollection; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * shiro实现用户登陆; + * 各个模块表不一样,各自处理; + */ +public class AuthRealm extends AuthorizingRealm { + + @Autowired + private IAuthUserService authUserService; + + /** + * 实现用户登陆 + */ + @Override + protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authToken) throws AuthenticationException { + UsernamePasswordToken token = (UsernamePasswordToken) authToken; + String username = token.getUsername(); + String password = String.valueOf(token.getPassword()); + AuthUser authUser = null; + /** + * 业务代码-start + */ + try { + AuthUser tmpAuthUser = new AuthUser(); + tmpAuthUser.setUsername(username); + tmpAuthUser.setPassword(password); + + tmpAuthUser = authUserService.getByUsernameAndPassword(tmpAuthUser); + if(null != tmpAuthUser){ + authUser = new AuthUser(); + authUser.setId(tmpAuthUser.getId()); + authUser.setRealname(tmpAuthUser.getRealname()); + authUser.setUsername(tmpAuthUser.getUsername()); + authUser.setStatus(tmpAuthUser.getStatus()); + if(!StringUtils.isBlank(tmpAuthUser.getHeader())){ + authUser.setHeader(QiniuStorage.getUrl(tmpAuthUser.getHeader(),ThumbModel.THUMB_256));//设置头像 + } + }else{ + throw new AuthenticationException("## user password is not correct! "); + } + } catch (Exception e) { + throw new AuthenticationException("## user password is not correct! "); + } + //业务代码-end + // 设置用户权限信息 + /*try { + authUser.setPermissions(permissions); + } catch (Exception e) { + throw new AuthenticationException("## user permission setter exception! "); + }*/ + // 创建授权用户 + SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(authUser, password, getName()); + return info; + } + + @Override + protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { + if (principals == null) + throw new AuthorizationException("PrincipalCollection method argument cannot be null."); + // 获取当前登录用户 + SessionUser user = SessionContext.getAuthUser(); + if (user == null) { + return null; + } + // 设置权限 + SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); + // 获取用户权限并设置 以供shiro框架 + info.setStringPermissions(user.getPermissions()); + return info; + } + +} diff --git a/src/main/resources/app-servlet.xml b/src/main/resources/app-servlet.xml new file mode 100644 index 0000000..f060e27 --- /dev/null +++ b/src/main/resources/app-servlet.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + auto_detect + 1 + UTF-8 + UTF-8 + zh_CN + true,false + yyyy-MM-dd HH:mm:ss + yyyy-MM-dd + HH:mm:ss + 0.###### + true + /WEB-INF/ftl/spring.ftl as s + + + + + + + + + + + + + + + diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..a72aabe --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,6 @@ + +#qiniu +qiniu.accesskey=PNf6qqSQgkZHwRHGGE5AKEittarGwfwY0Z9-w9Gq +qiniu.secretkey=k7TNOkvKCy_bQZk_lEG1QFqPCkz1umfz_LaqKbbp +qiniu.bucket=image-dairy +qiniu.cdns=pgn9znrzc.bkt.clouddn.com \ No newline at end of file diff --git a/src/main/resources/applicationContext.xml b/src/main/resources/applicationContext.xml new file mode 100644 index 0000000..5d0c7c7 --- /dev/null +++ b/src/main/resources/applicationContext.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + classpath:/jdbc.properties + classpath:/application.properties + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/generatorConfig.xml b/src/main/resources/generatorConfig.xml new file mode 100644 index 0000000..dcfe8eb --- /dev/null +++ b/src/main/resources/generatorConfig.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
diff --git a/src/main/resources/jdbc.properties b/src/main/resources/jdbc.properties new file mode 100644 index 0000000..3814a6d --- /dev/null +++ b/src/main/resources/jdbc.properties @@ -0,0 +1,20 @@ + +datasource.type=mysql +datasource.autoCommitOnClose=false +datasource.driverClassName=com.mysql.jdbc.Driver + +datasource.url=jdbc:mysql://127.0.0.1:3306/image-dairy_db?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC +datasource.username=root +datasource.password=123456 + +c3p0.acquireIncrement=3 +c3p0.initialPoolSize=5 +c3p0.idleConnectionTestPeriod=900 + +c3p0.minPoolSize=10 +c3p0.maxPoolSize=25 + +c3p0.maxStatements=150 +c3p0.maxIdleTime=1800 + +c3p0.autoCommitOnClose=true diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties new file mode 100644 index 0000000..a593445 --- /dev/null +++ b/src/main/resources/log4j.properties @@ -0,0 +1,23 @@ +log4j.rootLogger = DEBUG, INFO, STDOUT + +log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender +log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout + +log4j.appender.DEBUG.layout.ConversionPattern=[%d{MM/dd HH:mm}] %m%n +log4j.appender.STDOUT.layout.ConversionPattern=[%d{MM/dd HH:mm}] %m%n + +log4j.logger.jdbc.sqlonly=DEBUG,STDOUT +log4j.logger.jdbc.sqltiming=OFF +log4j.logger.jdbc.audit=OFF +log4j.logger.jdbc.resultset=OFF +log4j.logger.jdbc.connection=OFF + +log4j.logger.org.apache.ibatis=OFF +log4j.logger.org.apache.ibatis.jdbc.ScriptRunner=DEBUG +log4j.logger.java.sql.Connection=OFF +log4j.logger.java.sql.Statement=OFF +log4j.logger.java.sql.PreparedStatement=OFF + +log4j.logger.com.google=ERROR +log4j.logger.net.rubyeye=ERROR + diff --git a/src/main/resources/mybatis-config.xml b/src/main/resources/mybatis-config.xml new file mode 100644 index 0000000..10461bb --- /dev/null +++ b/src/main/resources/mybatis-config.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/resources/shiro.xml b/src/main/resources/shiro.xml new file mode 100644 index 0000000..c6cf068 --- /dev/null +++ b/src/main/resources/shiro.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /error/** = anon + /res/** = anon + /tools/** = anon + /index.html* = anon + /auth/** = anon + /auth/logout.html = logout + + /course/list.html* = anon + /course/learn/*.html = anon + /course/video/*.html = authc + + /courseComment/segment.html* = anon + + /** = authc + + + + + + diff --git a/src/main/webapp/WEB-INF/pages/auth/login.html b/src/main/webapp/WEB-INF/pages/auth/login.html new file mode 100644 index 0000000..a23fabe --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/auth/login.html @@ -0,0 +1,59 @@ + + + + + + + + + 网校在线学习平台 + <#include "../common/res.html"> + + + + <#include "../common/header2.html"> +
+
+

登录

+
+ +
  • + +
  • +
  • + +
  • +
  • + + +
  • +
  • + + + 下次自动登录 +
  • + + <#if errcode ?? && errcode == 1> +
  • + + 请输入正确的验证码 +
  • + + <#if errcode ?? && errcode == 2> +
  • + + 用户名密码错 +
  • + + +
  • + +
    注册
    +
  • +
    +
    +
    + <#include "../common/footer.html"> + + + diff --git a/src/main/webapp/WEB-INF/pages/auth/register.html b/src/main/webapp/WEB-INF/pages/auth/register.html new file mode 100644 index 0000000..fe78fe4 --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/auth/register.html @@ -0,0 +1,97 @@ + + + + + + + + + 在线网校学习平台 + <#include "../common/res.html"> + + + + <#include "../common/header2.html"> +
    +
    +

    注册

    +
    +
  • + +
  • +
  • + +
  • +
  • + + +
  • + +
  • + +
  • +
  • + 已有账号,去登录 +
  • +
    +
    +
    + <#include "../common/footer.html"> + + + diff --git a/src/main/webapp/WEB-INF/pages/commentSegment.html b/src/main/webapp/WEB-INF/pages/commentSegment.html new file mode 100644 index 0000000..6eb361e --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/commentSegment.html @@ -0,0 +1,24 @@ + +<#if (page.items)??> +<#list page.items as item> +
    +
    +
    +
    ${item.username!} 评论道:
    + <#if item.refContent?? && item.refContent != ''> +
    + ${item.refContent!} +
    + +
    ${item.content!}
    + +
    +
    + +<#include "./common/tailPage.html"> + diff --git a/src/main/webapp/WEB-INF/pages/common/footer.html b/src/main/webapp/WEB-INF/pages/common/footer.html new file mode 100644 index 0000000..5a02ab2 --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/common/footer.html @@ -0,0 +1,16 @@ + + diff --git a/src/main/webapp/WEB-INF/pages/common/header.html b/src/main/webapp/WEB-INF/pages/common/header.html new file mode 100644 index 0000000..a2404ff --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/common/header.html @@ -0,0 +1,309 @@ +
    +
    + + + + + + <@shiro.user> + + + + +
    +
    + +<@shiro.guest> + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/pages/common/header2.html b/src/main/webapp/WEB-INF/pages/common/header2.html new file mode 100644 index 0000000..459903a --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/common/header2.html @@ -0,0 +1,17 @@ +
    +
    + + +
    +
    + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/pages/common/res.html b/src/main/webapp/WEB-INF/pages/common/res.html new file mode 100644 index 0000000..1df0a51 --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/common/res.html @@ -0,0 +1,38 @@ + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/pages/common/tailPage.html b/src/main/webapp/WEB-INF/pages/common/tailPage.html new file mode 100644 index 0000000..94c44a9 --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/common/tailPage.html @@ -0,0 +1,29 @@ +<#if (page.pageTotalCount)?? && page.pageTotalCount gt 1> +
    +
    +
    + + <#if !page.firstPage> + 首 页 + 上一页 + + + <#list page.showNums as n> + <#if page.showDot && n_index == 6> + ... + + <#if page.pageNum == n> + ${n} + <#else> + ${n} + + + + <#if !page.lastPage> + 下一页 + 尾 页 + +
    +
    +
    + diff --git a/src/main/webapp/WEB-INF/pages/common/tailPage2.html b/src/main/webapp/WEB-INF/pages/common/tailPage2.html new file mode 100644 index 0000000..55e0a74 --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/common/tailPage2.html @@ -0,0 +1,42 @@ +<#if (page.pageTotalCount)?? && page.pageTotalCount gt 1> +
    +
    +
    + + <#if !page.firstPage> + 首 页 + 上一页 + + <#list page.showNums as n> + <#if page.showDot && n_index == 6> + ... + + <#if page.pageNum == n> + ${n} + <#else> + ${n} + + + <#if !page.lastPage> + 下一页 + 尾 页 + +
    +
    +
    + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/pages/error/403.html b/src/main/webapp/WEB-INF/pages/error/403.html new file mode 100644 index 0000000..c5ed101 --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/error/403.html @@ -0,0 +1,22 @@ + + + + + + + + + 在线网校学习平台 + <#include "../common/res.html"> + + + + <#include "../common/header.html"> +
    +
    +

    403页面

    +
    +
    + <#include "../common/footer.html"> + + diff --git a/src/main/webapp/WEB-INF/pages/error/404.html b/src/main/webapp/WEB-INF/pages/error/404.html new file mode 100644 index 0000000..9620e2f --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/error/404.html @@ -0,0 +1,22 @@ + + + + + + + + + 在线网校学习平台 + <#include "../common/res.html"> + + + + <#include "../common/header.html"> +
    +
    +

    404页面

    +
    +
    + <#include "../common/footer.html"> + + diff --git a/src/main/webapp/WEB-INF/pages/error/500.html b/src/main/webapp/WEB-INF/pages/error/500.html new file mode 100644 index 0000000..2c8a582 --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/error/500.html @@ -0,0 +1,22 @@ + + + + + + + + + 在线网校学习平台 + <#include "../common/res.html"> + + + + <#include "../common/header.html"> +
    +
    +

    500页面

    +
    +
    + <#include "../common/footer.html"> + + diff --git a/src/main/webapp/WEB-INF/pages/index.html b/src/main/webapp/WEB-INF/pages/index.html new file mode 100644 index 0000000..caad944 --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/index.html @@ -0,0 +1,346 @@ + + + + + + + + + 在线网校学习平台 + + <#include "./common/res.html"> + + + + <#include "./common/header.html"> + +
    + +
    +
    + + +
    + <#if carouselList?? && carouselList?size gt 0> + <#list carouselList as item> + +
    +
    + + +
    +
    +
    + <#if carouselList?? && carouselList?size gt 0> + <#list carouselList as item> + <#if item_index == 0> + + <#else> + + + + +
    +
    + + + + +
    + <#if classifys??> + <#list classifys as item> + <#if item_index lt 6> + + + + +
    + + + <#if classifys??> + <#list classifys as item> + <#if item_index lt 6> +
    +
    + + <#if item.subClassifyList??> + <#list item.subClassifyList as subItem> + ${subItem.name!} + <#if subItem_index lt (item.subClassifyList?size - 1)> + / + + + +
    + +
    + +
    + <#if item.recomdCourseList?? && item.recomdCourseList?size gt 0 > + <#list item.recomdCourseList as item> +
  • ➤ ${item.name!}
  • + + +
    +
    +
    + + + + + +
    +
    + + + +
    +

    实战推荐

    +
    + <#if actionCourseList?? && actionCourseList?size gt 0> + <#list actionCourseList as item> + <#assign n = item_index + 1 /> + +
    style="margin-right: 0px;" > + <#if n %5 == 0> +
    + <#elseif n %4 == 0> + + + + +
    +

    免费好课

    +
    + <#if freeCourseList?? && freeCourseList?size gt 0> + <#list freeCourseList as item> + <#assign n = item_index + 1 /> + +
    style="margin-right: 0px;" > + <#if n %5 == 0> +
    + <#elseif n %4 == 0> + + + + +
    +

    Java开发工程师

    + <#if javaCourseList?? && javaCourseList?size gt 0> + <#assign javaC0 = javaCourseList[0] /> + +
    +
    +
    +

    ${javaC0.name!}

    +

    ${javaC0.brief!}

    +
    +
    了解详情 →
    +
    +
    +
    +
    +
    + + <#if javaCourseList?size gt 2> + <#assign javaC1 = javaCourseList[1] /> + <#assign javaC2 = javaCourseList[2] /> + + + +
    + + + +
    +

    名校讲师

    + <#if recomdTeacherList?? && recomdTeacherList?size gt 0> + <#list recomdTeacherList as item> +
    style="margin-right: 0px;" > +
    + <#if item.header?? && item.header != ''> + + <#else> + + + ${item.realname!} + ${item.collegeName!} · ${item.education!} + ${item.title!},${item.sign!} +
    +
    + + +
    + +
    + + <#include "./common/footer.html"> + + + + + diff --git a/src/main/webapp/WEB-INF/pages/learn.html b/src/main/webapp/WEB-INF/pages/learn.html new file mode 100644 index 0000000..dca12ae --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/learn.html @@ -0,0 +1,268 @@ + + + + + + + + + 在线网校学习平台 + <#include "./common/res.html"> + + + + <#include "./common/header.html"> +
    +
    + +
    +
    ${(course.name)!}
    + +
    + 继续学习 + +
    +
    上次学到
    +
    ${(curCourseSection.name)!}
    +
    + +
    +
    学习人数
    +
    ${(course.studyCount)!}
    +
    +
    +
    难度级别
    +
    + <#if course?? && course.level??> + <#if course.level == 1> + 初级 + <#elseif course.level == 2> + 中级 + <#else> + 高级 + + +
    +
    +
    +
    课程时长
    +
    ${(course.time)!}
    +
    + + +
    + +
    + ${(course.brief)!} +
    + + +
    + + + +
    + <#if chaptSections??> + <#list chaptSections as item> +
    + +

    +
    =
    ${item.name!}
    + +

    +
    + +
    + + + +
    + + + +
    +
    + +
    + +
    + <#if courseTeacher??> +
    + <#if courseTeacher.header?? && courseTeacher.header != ''> + + <#else> + + + ${(courseTeacher.realname)!""} + ${(courseTeacher.collegeName)!""} · ${(courseTeacher.education)!""} + ${(courseTeacher.title)!""},${(courseTeacher.sign)!""} + + + +
    + + +

    推荐课程

    + <#if recomdCourseList?? && recomdCourseList?size gt 0 > + <#list recomdCourseList as item> +
  • ${item.name!}
  • + + +
    + +
    + + <#include "./common/footer.html"> + + + + + + diff --git a/src/main/webapp/WEB-INF/pages/list.html b/src/main/webapp/WEB-INF/pages/list.html new file mode 100644 index 0000000..83b6fec --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/list.html @@ -0,0 +1,148 @@ + + + + + + + + + 在线网校学习平台 + <#include "./common/res.html"> + + + + <#include "./common/header.html"> + +
    + +
    + 方向: + +
    + +
    + 分类: + +
    + +
    +

    + 课程列表 + + class="color-oc" >最新 + + + class="color-oc" >最热 + +

    +
    + <#if (page.items)??> +
    + <#list page.items as item> + <#assign n = item_index + 1 /> + + + + <#include "./common/footer.html"> + + + + + + diff --git a/src/main/webapp/WEB-INF/pages/user/collect.html b/src/main/webapp/WEB-INF/pages/user/collect.html new file mode 100644 index 0000000..1d9600a --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/user/collect.html @@ -0,0 +1,58 @@ + + + + + + + + + 个人主页 + <#include "../common/res.html"> + + + + <#include "../common/header.html"> +
    +
    + <#include "./nav.html"> +
    + +
    +
    我的收藏
    +
    + +
    + <#if (page.items)??> + <#list page.items as item> +
    +
    + + ${item.name!} + +
    + 分类: + <#if item.classify??> + <#if item.classify == 1>课程 + + + 收藏时间: + <#if item.createTime??> + ${item.createTime?string('yyyy-MM-dd')} + + +
    +
    +
    + + + <#include "../common/tailPage2.html"> + +
    + +
    +
    + + <#include "../common/footer.html"> + + + diff --git a/src/main/webapp/WEB-INF/pages/user/course.html b/src/main/webapp/WEB-INF/pages/user/course.html new file mode 100644 index 0000000..1b736f3 --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/user/course.html @@ -0,0 +1,64 @@ + + + + + + + + + 个人主页 + <#include "../common/res.html"> + + + + <#include "../common/header.html"> +
    +
    + <#include "./nav.html"> +
    + +
    +
    最近学习
    +
    + +
    + <#if (page.items)??> + <#list page.items as item> +
    +
    + ${item.courseName!} +
    + 已学${item.rate!0}% + + + ${item.sectionName!} + + +
    + +
    +
    + + + <#include "../common/tailPage2.html"> + +
    + +
    + +
    + + <#include "../common/footer.html"> + + + + diff --git a/src/main/webapp/WEB-INF/pages/user/home.html b/src/main/webapp/WEB-INF/pages/user/home.html new file mode 100644 index 0000000..f9d98bb --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/user/home.html @@ -0,0 +1,62 @@ + + + + + + + + + 个人主页 + <#include "../common/res.html"> + + + + <#include "../common/header.html"> +
    +
    + <#include "./nav.html"> +
    + +
    +
    最新动态
    +
    + +
    + <#if (page.items)??> + <#list page.items as item> +
    +
    + <#if item.header?? && item.header != ''> + + <#else> + + +
    + +
    +
    ${item.username!}
    + + +
    +
    + + + <#include "../common/tailPage2.html"> +
    +
    +
    + <#include "../common/footer.html"> + + + diff --git a/src/main/webapp/WEB-INF/pages/user/info.html b/src/main/webapp/WEB-INF/pages/user/info.html new file mode 100644 index 0000000..b8d3941 --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/user/info.html @@ -0,0 +1,132 @@ + + + + + + + + + 个人主页 + <#include "../common/res.html"> + + + + <#include "../common/header.html"> +
    +
    + <#include "./nav.html"> +
    + + +
    +
    + 个人信息 +
    +
    + +
    +
    +
    + + <#if (authUser.header)?? && authUser.header != ''> + + <#else> + + +
    + 更换头像 + +
    +
    + +
  • + ${authUser.username!} +
  • +
  • + +
  • +
  • + +
  • +
  • + + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • + +
  • +
    保存
    +
  • + +
  • + +
  • +
    +
    +
    +
    + + <#include "../common/footer.html"> + + + + diff --git a/src/main/webapp/WEB-INF/pages/user/nav.html b/src/main/webapp/WEB-INF/pages/user/nav.html new file mode 100644 index 0000000..23d7cdf --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/user/nav.html @@ -0,0 +1,40 @@ + + +
    <@shiro.principal property="username"/>
    +
    + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/pages/user/passwd.html b/src/main/webapp/WEB-INF/pages/user/passwd.html new file mode 100644 index 0000000..b8eb7a6 --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/user/passwd.html @@ -0,0 +1,67 @@ + + + + + + + + + 个人主页 + <#include "../common/res.html"> + + + + <#include "../common/header.html"> +
    +
    + <#include "./nav.html"> +
    + + +
    +
    + 修改密码 +
    +
    + +
    +
  • +
  • +
  • +
  • +
    保存
    +
  • + +
  • + +
  • +
    +
    +
    + + <#include "../common/footer.html"> + + + + + + diff --git a/src/main/webapp/WEB-INF/pages/user/qa.html b/src/main/webapp/WEB-INF/pages/user/qa.html new file mode 100644 index 0000000..ca5cb50 --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/user/qa.html @@ -0,0 +1,145 @@ + + + + + + + + + 个人主页 + <#include "../common/res.html"> + + + + <#include "../common/header.html"> +
    +
    + <#include "./nav.html"> +
    + +
    +
    我的课程QA
    +
    + +
    + <#if (page.items)??> + <#list page.items as item> +
    +
    + +
    ${item.sectionTitle!}
    + +
    +
    + ${item.username!} 评论道: +
    + + <#if item.refContent?? && item.refContent != ''> +
    + ${item.refContent!} +
    + + +
    + ${item.content!} +
    +
    + +
    +
    + + + <#include "../common/tailPage2.html"> + +
    +
    +
    + <#include "../common/footer.html"> + + + + + + + + diff --git a/src/main/webapp/WEB-INF/pages/video.html b/src/main/webapp/WEB-INF/pages/video.html new file mode 100644 index 0000000..98279ee --- /dev/null +++ b/src/main/webapp/WEB-INF/pages/video.html @@ -0,0 +1,218 @@ + + + + + + + + + 在线网校学习平台 + <#include "./common/res.html"> + + + + <#include "./common/header.html"> +
    +
    +
    +
    ${(courseSection.name)!}
    + +
    + + + +
    + + +
    + + +
    +
    + + + <@shiro.user> +
    +
    + 发布评论: + 长度小于200 +
    +
    + + + + + +
    + + +
    +
    + +
    + +
    + + +
    +

    所有章节

    +
    +
    + <#if chaptSections??> + <#list chaptSections as item> +
    + +

    + ${item.name!} + +

    +
    + +
    + + +
    +
    + +
    + +
    + + <#include "./common/footer.html"> + + + + + + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..fd4a06b --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,106 @@ + + + + image-dairy + + + + contextClass + org.springframework.web.context.support.XmlWebApplicationContext + + + contextConfigLocation + classpath:applicationContext.xml + + + + + jsessionidFilter + com.krt.dairy.common.web.DisableUrlSessionFilter + + + jsessionidFilter + /* + + + + + encodingFilter + org.springframework.web.filter.CharacterEncodingFilter + + encoding + UTF-8 + + + forceEncoding + true + + + + encodingFilter + * + + + + app-servlet + org.springframework.web.servlet.DispatcherServlet + + contextConfigLocation + classpath:app-servlet.xml + + 1 + + + + app-servlet + *.html + + + + + shiroFilter + org.springframework.web.filter.DelegatingFilterProxy + + targetFilterLifecycle + true + + + + shiroFilter + /* + REQUEST + FORWARD + INCLUDE + ERROR + + + + + org.springframework.web.context.ContextLoaderListener + + + + 120 + + + + index.html + + + + 404 + /error/404.html + + + 500 + /error/500.html + + + 405 + /error/405.html + + + diff --git a/src/main/webapp/static/comment.html b/src/main/webapp/static/comment.html new file mode 100644 index 0000000..af371e4 --- /dev/null +++ b/src/main/webapp/static/comment.html @@ -0,0 +1,258 @@ + + + + + + + + + 在线网校学习平台 + + + + + + + + + + + + + + +
    +
    + + + + +
    +
    + + + + + + + + +
    +
    +
    +
    带您完成神秘的涟漪按钮效果-入门篇
    + +
    + 继续学习 + +
    +
    上次学到
    +
    1-1 感受神秘的涟漪效果之美感受神秘的涟漪效果之美
    +
    +
    +
    学习人数
    +
    1452
    +
    +
    +
    难度级别
    +
    中级
    +
    +
    +
    课程时长
    +
    1小时25分
    +
    + + +
    + +
    + 简介:安卓声音录制与播放功能实现,包括录制到文件、播放文件,可以实现类似于微信的语音消息发送与播放,还包括录制到字节流,从字节流播放,可以实现视频直播/实时对讲功能中的声音录制和播放。 Android大牛齐聚之地,这里总有人为你答疑解惑!慕课网Android讨论群 556384357 +
    + +
    + 章节 + 评论 +
    +
    + + +
    +
    +
    +
    +
    我是张三
    +
    这门课真实用!一个列表嵌套好多种布局的时候,用recyclerview控件优雅实现,效率果然提高不少,老板肯定又会夸我,啊哈哈!!!
    + +
    +
    + +
    +
    +
    +
    我是张三
    +
    这门课真实用!一个列表嵌套好多种布局的时候,用recyclerview控件优雅实现,效率果然提高不少,老板肯定又会夸我,啊哈哈!!!
    + +
    +
    +
    + +
    + + + + +
    + + + + + + diff --git a/src/main/webapp/static/index.html b/src/main/webapp/static/index.html new file mode 100644 index 0000000..03c61a5 --- /dev/null +++ b/src/main/webapp/static/index.html @@ -0,0 +1,618 @@ + + + + + + + + + 印象笔记 + + + + + + + + + + + + + + +
    +
    + + + + +
    +
    + + + + + + + +
    + +
    +
    +
    +
    +
    +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +
    + +
    +
    + +
    + + + + + + +
    +
    数据库
    +
    + + + +
    +
    UI设计
    +
    +
    + +
    + AAAAAAAAAA +
    + +
    + BBBBBBBBBBBB +
    + +
    + CCCCCCCCCCCC +
    + +
    + DDDDDDDDDDDDDD +
    + +
    + EEEEEEEEE +
    + +
    + FFFFFFFFFF +
    + +
    +
    + + + + + + + +
    +

    免费好课

    +
    + +
    +
    + 测试 +
    + +
    +

    Android自动化测试实战 工具 框架 脚本

    +

    找Android自动化测试工作必学的主流工具、框架和自动化脚本

    +
    +
    初级·178人在学
    +
    +
    +
    +
    + + +
    +
    + WebApp +
    +
    +

    AngularJS仿拉勾网WebApp 开发移动端单页应用

    +

    基于AngularJS,仿拉勾网开发一个招聘类的移动端单页应用

    +
    +
    初级·3444人在学
    +
    +
    +
    +
    + +
    +
    + Django +
    + +
    +

    强力django杀手级xadmin 打造上线标准的在线教育平台

    +

    全面掌握django框架,轻松应对python web开发工作

    +
    +
    初级·4888人在学
    +
    +
    +
    + +
    +
    + Python +
    + +
    +

    Python高级编程技巧实战

    +

    精选50个python训练任务,提升实战技能与高效编程技巧

    +
    +
    高级·81333人在学
    +
    +
    +
    + +
    +
    + PHP +
    + +
    +

    前端后台ThinkPHP开发整站

    +

    用PHP+MySQL+Ajax开完新闻资讯整站,实现“小全栈”的梦想

    +
    +
    中级·6133人在学
    +
    +
    +
    + +
    + +
    + + + +
    +

    Java开发工程师

    +
    +
    +
    +

    Java职业路径

    +

    带你研究Java技术框架,系统地学习java技术

    +
    +
    了解详情 →
    +
    +
    +
    +
    + +
    + + +
    + +
    +
    + 测试 +
    + +
    +

    Android自动化测试实战 工具 框架 脚本

    +

    找Android自动化测试工作必学的主流工具、框架和自动化脚本

    +
    +
    + 初级·178人在学 +
    +
    +
    +
    +
    + + +
    +
    + WebApp +
    +
    +

    AngularJS仿拉勾网WebApp 开发移动端单页应用

    +

    基于AngularJS,仿拉勾网开发一个招聘类的移动端单页应用

    +
    +
    + 初级·3444人在学 +
    +
    +
    +
    +
    + +
    +
    + Django +
    + +
    +

    强力django杀手级xadmin 打造上线标准的在线教育平台

    +

    全面掌握django框架,轻松应对python + web开发工作

    +
    +
    + 初级·4888人在学 +
    +
    +
    +
    + +
    +
    + Python +
    + +
    +

    Python高级编程技巧实战

    +

    精选50个python训练任务,提升实战技能与高效编程技巧

    +
    +
    + 高级·81333人在学 +
    +
    +
    +
    + +
    +
    +
    + + + +
    +

    名校讲师

    + +
    +
    + + 王阳明 + 中华大学 + 中华大学高级讲师,擅长写代码 +
    +
    +
    + + +
    +
    + + 王阳明 + 中华大学 + 中华大学高级讲师,擅长写代码 +
    +
    +
    + +
    +
    + + 王阳明 + 中华大学 + 中华大学高级讲师,擅长写代码 +
    +
    + +
    +
    + + 王阳明 + 中华大学 + 中华大学高级讲师,擅长写代码 +
    +
    + +
    +
    + + 王阳明 + 中华大学 + 中华大学高级讲师,擅长写代码 +
    +
    + +
    + +
    + + + + + + + + + + diff --git a/src/main/webapp/static/learn.html b/src/main/webapp/static/learn.html new file mode 100644 index 0000000..ac5f046 --- /dev/null +++ b/src/main/webapp/static/learn.html @@ -0,0 +1,337 @@ + + + + + + + + + 在线网校学习平台 + + + + + + + + + + + + + + +
    +
    + + + + +
    +
    + + + + + + + +
    + +
    +
    +
    带您完成神秘的涟漪按钮效果-入门篇
    + +
    + 继续学习 + +
    +
    上次学到
    +
    1-1 感受神秘的涟漪效果之美感受神秘的涟漪效果之美
    +
    +
    +
    学习人数
    +
    1452
    +
    +
    +
    难度级别
    +
    中级
    +
    +
    +
    课程时长
    +
    1小时25分
    +
    + + +
    + +
    + 简介:安卓声音录制与播放功能实现,包括录制到文件、播放文件,可以实现类似于微信的语音消息发送与播放,还包括录制到字节流,从字节流播放,可以实现视频直播/实时对讲功能中的声音录制和播放。 Android大牛齐聚之地,这里总有人为你答疑解惑!慕课网Android讨论群 556384357 +
    + +
    + 章节 + 评论 +
    +
    + + + +
    + + + + + + +
    + +
    + + + + + +
    + + + + + + + + + + diff --git a/src/main/webapp/static/list.html b/src/main/webapp/static/list.html new file mode 100644 index 0000000..bbf2f80 --- /dev/null +++ b/src/main/webapp/static/list.html @@ -0,0 +1,451 @@ + + + + + + + + + 在线网校学习平台 + + + + + + + + + + + + + + +
    +
    + + + + +
    +
    + + + + + + + + + +
    + +
    + 方向: + +
    + + + +
    + 分类: + +
    + + + +
    +

    + 课程列表 + + 最新 + + + 最热 + +

    +
    + + +
    +
    + 测试 +
    + +
    +

    Android自动化测试实战 工具 框架 脚本

    +

    找Android自动化测试工作必学的主流工具、框架和自动化脚本

    +
    +
    初级·178人在学
    +
    +
    +
    +
    + + +
    +
    + WebApp +
    +
    +

    AngularJS仿拉勾网WebApp 开发移动端单页应用

    +

    基于AngularJS,仿拉勾网开发一个招聘类的移动端单页应用

    +
    +
    初级·3444人在学
    +
    +
    +
    +
    + +
    +
    + Django +
    + +
    +

    强力django杀手级xadmin 打造上线标准的在线教育平台

    +

    全面掌握django框架,轻松应对python web开发工作

    +
    +
    初级·4888人在学
    +
    +
    +
    + +
    +
    + Python +
    + +
    +

    Python高级编程技巧实战

    +

    精选50个python训练任务,提升实战技能与高效编程技巧

    +
    +
    高级·81333人在学
    +
    +
    +
    + +
    +
    + PHP +
    + +
    +

    前端后台ThinkPHP开发整站

    +

    用PHP+MySQL+Ajax开完新闻资讯整站,实现“小全栈”的梦想

    +
    +
    中级·6133人在学
    +
    +
    +
    + +
    + + +
    + + +
    +
    + 测试 +
    + +
    +

    Android自动化测试实战 工具 框架 脚本

    +

    找Android自动化测试工作必学的主流工具、框架和自动化脚本

    +
    +
    初级·178人在学
    +
    +
    +
    +
    + + +
    +
    + WebApp +
    +
    +

    AngularJS仿拉勾网WebApp 开发移动端单页应用

    +

    基于AngularJS,仿拉勾网开发一个招聘类的移动端单页应用

    +
    +
    初级·3444人在学
    +
    +
    +
    +
    + +
    +
    + Django +
    + +
    +

    强力django杀手级xadmin 打造上线标准的在线教育平台

    +

    全面掌握django框架,轻松应对python web开发工作

    +
    +
    初级·4888人在学
    +
    +
    +
    + +
    +
    + Python +
    + +
    +

    Python高级编程技巧实战

    +

    精选50个python训练任务,提升实战技能与高效编程技巧

    +
    +
    高级·81333人在学
    +
    +
    +
    + +
    +
    + PHP +
    + +
    +

    前端后台ThinkPHP开发整站

    +

    用PHP+MySQL+Ajax开完新闻资讯整站,实现“小全栈”的梦想

    +
    +
    中级·6133人在学
    +
    +
    +
    + +
    + +
    + + + +
    +
    +
    + 首 页 + 上一页 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + ... + 下一页 + 尾 页 +
    +
    +
    + +
    + + + + + diff --git a/src/main/webapp/static/video.html b/src/main/webapp/static/video.html new file mode 100644 index 0000000..a781f66 --- /dev/null +++ b/src/main/webapp/static/video.html @@ -0,0 +1,360 @@ + + + + + + + + + 在线网校学习平台 + + + + + + + + + + + + + + +
    +
    + + + + +
    +
    + + + + + + + +
    +
    +
    +
    1-1 感受神秘的涟漪效果
    + +
    + +
    + +
    + 评论 +
    +
    + + +
    +
    +
    +
    +
    我是张三
    +
    这门课真实用!一个列表嵌套好多种布局的时候,用recyclerview控件优雅实现,效率果然提高不少,老板肯定又会夸我,啊哈哈!!!
    + +
    +
    + +
    +
    +
    +
    我是张三
    +
    这门课真实用!一个列表嵌套好多种布局的时候,用recyclerview控件优雅实现,效率果然提高不少,老板肯定又会夸我,啊哈哈!!!
    + +
    +
    +
    + + +
    +
    + 发布评论: + 长度小于200 +
    +
    + + + + + +
    + + +
    +
    + +
    + + +
    + + + + +
    + + + + + + + + + +