xielq 4 роки тому
батько
коміт
b3b0590f6e
36 змінених файлів з 1488 додано та 0 видалено
  1. 76 0
      build.gradle
  2. 9 0
      demo-test-web/build.gradle
  3. 16 0
      demo-test-web/src/main/java/com/uas/cloud/mall/service/Application.java
  4. 50 0
      demo-test-web/src/main/java/com/uas/cloud/mall/service/controller/IndexController.java
  5. 11 0
      demo-test-web/src/main/java/com/uas/cloud/mall/service/facade/ContentFacade.java
  6. 40 0
      demo-test-web/src/main/java/com/uas/cloud/mall/service/facade/impl/ContentFacadeImpl.java
  7. 191 0
      demo-test-web/src/main/java/com/uas/cloud/mall/service/model/Content.java
  8. 68 0
      demo-test-web/src/main/java/com/uas/cloud/mall/service/model/Module.java
  9. 20 0
      demo-test-web/src/main/java/com/uas/cloud/mall/service/service/ContentService.java
  10. 11 0
      demo-test-web/src/main/resources/application.yml
  11. 12 0
      demo-test-web/src/main/resources/static/index.html
  12. 22 0
      demo-test-web/src/main/resources/templates/home.html
  13. 10 0
      demo-test-web/src/main/resources/templates/shop.html
  14. 16 0
      demo-test-web/src/main/webapp/index.jsp
  15. BIN
      gradle/wrapper/gradle-wrapper.jar
  16. 6 0
      gradle/wrapper/gradle-wrapper.properties
  17. 164 0
      gradlew
  18. 90 0
      gradlew.bat
  19. 3 0
      settings.gradle
  20. 14 0
      src/main/java/com/uas/cloud/mall/service/Application.java
  21. 68 0
      src/main/java/com/uas/cloud/mall/service/controller/ContentController.java
  22. 16 0
      src/main/java/com/uas/cloud/mall/service/facade/ContentFacade.java
  23. 64 0
      src/main/java/com/uas/cloud/mall/service/facade/impl/ContentFacadeImpl.java
  24. 202 0
      src/main/java/com/uas/cloud/mall/service/model/Content.java
  25. 17 0
      src/main/java/com/uas/cloud/mall/service/model/ContentRepository.java
  26. 68 0
      src/main/java/com/uas/cloud/mall/service/model/Module.java
  27. 30 0
      src/main/java/com/uas/cloud/mall/service/service/ContentService.java
  28. 48 0
      src/main/java/com/uas/cloud/mall/service/service/impl/ContentServiceImpl.java
  29. 54 0
      src/main/java/com/uas/cloud/mall/service/util/CommonUtils.java
  30. 13 0
      src/main/resources/application-dev.yml
  31. 0 0
      src/main/resources/application-prod.yml
  32. 0 0
      src/main/resources/application-test.yml
  33. 5 0
      src/main/resources/application.yml
  34. 13 0
      src/main/webapp/resources/profile/module-info.json
  35. 11 0
      src/test/java/com/uas/cloud/mall/service/parent/ApplicationTest.java
  36. 50 0
      src/test/java/com/uas/cloud/mall/service/service/ContentServiceTest.java

+ 76 - 0
build.gradle

@@ -0,0 +1,76 @@
+buildscript {
+    ext {
+        springBootVersion = '1.4.4.RELEASE'
+    }
+    repositories {
+        mavenLocal()
+        mavenCentral()
+    }
+    dependencies {
+        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
+    }
+}
+
+group 'com.uas.cloud.mall.service'
+version '1.0-SNAPSHOT'
+
+apply plugin: 'idea'
+apply plugin: 'java'
+apply plugin: 'spring-boot'
+
+sourceCompatibility = 1.8
+targetCompatibility = 1.8
+
+repositories {
+    mavenLocal()
+    mavenCentral()
+}
+
+dependencyManagement {
+    imports {
+        mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Camden.SR5'
+    }
+}
+
+dependencies {
+    compile('org.springframework.cloud:spring-cloud-starter-eureka')
+    compile('org.springframework.boot:spring-boot-starter-data-mongodb')
+    testCompile('org.springframework.boot:spring-boot-starter-test')
+}
+
+subprojects {
+    apply plugin: 'idea'
+    apply plugin: 'java'
+    apply plugin: 'spring-boot'
+
+    sourceCompatibility = 1.8
+    targetCompatibility = 1.8
+
+    repositories {
+        mavenLocal()
+        jcenter()
+        mavenCentral()
+    }
+
+    dependencyManagement {
+        imports {
+            mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Camden.SR5'
+        }
+    }
+
+    idea {
+        module {
+            downloadSources = true
+            downloadJavadoc = false
+            inheritOutputDirs = false
+            outputDir = file("$buildDir/classes/main/")
+        }
+    }
+}
+
+idea {
+    project {
+        jdkName = '1.8'
+        languageLevel = '1.8'
+    }
+}

+ 9 - 0
demo-test-web/build.gradle

@@ -0,0 +1,9 @@
+
+dependencies {
+    compile('org.springframework.cloud:spring-cloud-starter-feign')
+    compile('org.springframework.cloud:spring-cloud-starter-eureka')
+    compile('org.springframework.boot:spring-boot-starter-web')
+    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
+    compile("org.springframework.boot:spring-boot-devtools")
+    testCompile('org.springframework.boot:spring-boot-starter-test')
+}

+ 16 - 0
demo-test-web/src/main/java/com/uas/cloud/mall/service/Application.java

@@ -0,0 +1,16 @@
+package com.uas.cloud.mall.service;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.netflix.feign.EnableFeignClients;
+
+@EnableDiscoveryClient
+@EnableFeignClients
+@SpringBootApplication
+public class Application {
+
+	public static void main(String[] args) {
+		SpringApplication.run(Application.class, args);
+	}
+}

+ 50 - 0
demo-test-web/src/main/java/com/uas/cloud/mall/service/controller/IndexController.java

@@ -0,0 +1,50 @@
+package com.uas.cloud.mall.service.controller;
+
+import com.uas.cloud.mall.service.facade.ContentFacade;
+import com.uas.cloud.mall.service.model.Content;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+import java.util.Map;
+
+@Controller
+public class IndexController {
+
+	private final ContentFacade contentFacade;
+
+
+	@Autowired
+	public IndexController(ContentFacade contentFacade) {
+		this.contentFacade = contentFacade;
+	}
+
+	@RequestMapping(value = "/shop", method = RequestMethod.GET)
+	public String shop(Model model) {
+		model.addAttribute("name", "Arvin");
+		return "shop";
+	}
+
+	@ResponseBody
+	@RequestMapping(value = "/contents/123", method = RequestMethod.GET)
+	public Map<String, List<Content>> findContentByModuleName(HttpServletRequest request) {
+		return contentFacade.getModuleContentMap(request.getRequestURI());
+	}
+
+	@RequestMapping(value = "/contents", method = RequestMethod.GET)
+	public String home(Model model, HttpServletRequest request) {
+		Map<String, List<Content>> modules = contentFacade.getModuleContentMap(request.getRequestURI());
+		model.addAllAttributes(modules);
+		model.addAttribute("name", "Arvin");
+		for (String key : model.asMap().keySet()) {
+			System.out.println(model.asMap().get(key));
+		}
+		return "home";
+	}
+
+}

+ 11 - 0
demo-test-web/src/main/java/com/uas/cloud/mall/service/facade/ContentFacade.java

@@ -0,0 +1,11 @@
+package com.uas.cloud.mall.service.facade;
+
+import com.uas.cloud.mall.service.model.Content;
+
+import java.util.List;
+import java.util.Map;
+
+public interface ContentFacade {
+
+	Map<String, List<Content>> getModuleContentMap(String path);
+}

+ 40 - 0
demo-test-web/src/main/java/com/uas/cloud/mall/service/facade/impl/ContentFacadeImpl.java

@@ -0,0 +1,40 @@
+package com.uas.cloud.mall.service.facade.impl;
+
+import com.uas.cloud.mall.service.facade.ContentFacade;
+import com.uas.cloud.mall.service.model.Content;
+import com.uas.cloud.mall.service.model.Module;
+import com.uas.cloud.mall.service.service.ContentService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class ContentFacadeImpl implements ContentFacade {
+
+	private final ContentService contentService;
+
+	@Autowired
+	public ContentFacadeImpl(ContentService contentService) {
+		this.contentService = contentService;
+	}
+
+	@Override
+	public Map<String, List<Content>> getModuleContentMap(String path) {
+		List<Module> modules = contentService.findModulesByPath(path);
+		if (CollectionUtils.isEmpty(modules)) {
+			return Collections.emptyMap();
+		}
+		Map<String, List<Content>> map = new HashMap<>();
+		for (Module module : modules) {
+			if (module != null) {
+				map.put(module.getName(), module.getContents());
+			}
+		}
+		return map;
+	}
+}

+ 191 - 0
demo-test-web/src/main/java/com/uas/cloud/mall/service/model/Content.java

@@ -0,0 +1,191 @@
+package com.uas.cloud.mall.service.model;
+
+import java.util.Date;
+
+/**
+ * 内容实体类
+ */
+public class Content {
+
+	private String id;
+
+	/**
+	 * 模块名称
+	 */
+	private String moduleName;
+
+	/**
+	 * 标签
+	 */
+	private String flag;
+
+	/**
+	 * 排序
+	 */
+	private int order;
+
+	/**
+	 * 标题
+	 */
+	private String caption;
+
+	/**
+	 * 子标题
+	 */
+	private String subCaption;
+
+	/**
+	 * 描述
+	 */
+	private String description;
+
+	/**
+	 * 文本内容
+	 */
+	private String textContent;
+
+	/**
+	 * 缩略图
+	 */
+	private String thumbnail;
+
+	/**
+	 * 大图
+	 */
+	private String image;
+
+	/**
+	 * 链接
+	 */
+	private String url;
+
+	/**
+	 * 备注
+	 */
+	private String remark;
+
+	/**
+	 * 创建时间
+	 */
+	private Date createTime;
+
+	/**
+	 * 更新时间
+	 */
+	private Date updateTime;
+
+	public Content() {
+	}
+
+	public String getId() {
+		return id;
+	}
+
+	public void setId(String id) {
+		this.id = id;
+	}
+
+	public String getModuleName() {
+		return moduleName;
+	}
+
+	public void setModuleName(String moduleName) {
+		this.moduleName = moduleName;
+	}
+
+	public int getOrder() {
+		return order;
+	}
+
+	public void setOrder(int order) {
+		this.order = order;
+	}
+
+	public String getCaption() {
+		return caption;
+	}
+
+	public void setCaption(String caption) {
+		this.caption = caption;
+	}
+
+	public String getSubCaption() {
+		return subCaption;
+	}
+
+	public void setSubCaption(String subCaption) {
+		this.subCaption = subCaption;
+	}
+
+	public String getDescription() {
+		return description;
+	}
+
+	public void setDescription(String description) {
+		this.description = description;
+	}
+
+	public String getTextContent() {
+		return textContent;
+	}
+
+	public void setTextContent(String textContent) {
+		this.textContent = textContent;
+	}
+
+	public String getThumbnail() {
+		return thumbnail;
+	}
+
+	public void setThumbnail(String thumbnail) {
+		this.thumbnail = thumbnail;
+	}
+
+	public String getImage() {
+		return image;
+	}
+
+	public void setImage(String image) {
+		this.image = image;
+	}
+
+	public String getUrl() {
+		return url;
+	}
+
+	public void setUrl(String url) {
+		this.url = url;
+	}
+
+	public String getRemark() {
+		return remark;
+	}
+
+	public void setRemark(String remark) {
+		this.remark = remark;
+	}
+
+	public String getFlag() {
+		return flag;
+	}
+
+	public void setFlag(String flag) {
+		this.flag = flag;
+	}
+
+	public Date getCreateTime() {
+		return createTime;
+	}
+
+	public void setCreateTime(Date createTime) {
+		this.createTime = createTime;
+	}
+
+	public Date getUpdateTime() {
+		return updateTime;
+	}
+
+	public void setUpdateTime(Date updateTime) {
+		this.updateTime = updateTime;
+	}
+}

+ 68 - 0
demo-test-web/src/main/java/com/uas/cloud/mall/service/model/Module.java

@@ -0,0 +1,68 @@
+package com.uas.cloud.mall.service.model;
+
+import java.util.List;
+
+/**
+ * 模块信息
+ *
+ * history:
+ * Created by huxz on 2017-2-25 14:56:02
+ */
+public class Module {
+
+	/**
+	 * 模块名称
+	 */
+	private String name;
+
+	/**
+	 * 路径
+	 */
+	private String path;
+
+	/**
+	 * 标签
+	 */
+	private String tag;
+
+	/**
+	 * 内容列表信息
+	 */
+	private List<Content> contents;
+
+	public Module() {
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getPath() {
+		return path;
+	}
+
+	public void setPath(String path) {
+		this.path = path;
+	}
+
+	public String getTag() {
+		return tag;
+	}
+
+	public void setTag(String tag) {
+		this.tag = tag;
+	}
+
+	public List<Content> getContents() {
+		return contents;
+	}
+
+	public void setContents(List<Content> contents) {
+		this.contents = contents;
+	}
+
+}

+ 20 - 0
demo-test-web/src/main/java/com/uas/cloud/mall/service/service/ContentService.java

@@ -0,0 +1,20 @@
+package com.uas.cloud.mall.service.service;
+
+import com.uas.cloud.mall.service.model.Content;
+import com.uas.cloud.mall.service.model.Module;
+import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.List;
+
+@FeignClient("mall-cms-service")
+public interface ContentService {
+
+	@RequestMapping(value = "/mall-cms-service/contents", method = RequestMethod.GET)
+	List<Content> findByModuleName(@RequestParam("moduleName") String moduleName);
+
+	@RequestMapping(value = "/mall-cms-service/modules", method = RequestMethod.GET)
+	List<Module> findModulesByPath(@RequestParam("path") String path);
+}

+ 11 - 0
demo-test-web/src/main/resources/application.yml

@@ -0,0 +1,11 @@
+spring:
+  application:
+    name: demo-test-web
+
+server:
+  port: 8099
+
+eureka:
+  client:
+    service-url:
+      defaultZone: http://localhost:1111/eureka/

+ 12 - 0
demo-test-web/src/main/resources/static/index.html

@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+	<meta charset="UTF-8">
+	<title>Index Page</title>
+</head>
+<body>
+	<div>
+		<h2>Index</h2>
+	</div>
+</body>
+</html>

+ 22 - 0
demo-test-web/src/main/resources/templates/home.html

@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:th="http://www.thymeleaf.org">
+<head>
+	<title>Getting Started: Serving Web Content</title>
+	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+</head>
+<body>
+	<p th:text="'Hello, ' + ${name} + '!'" />
+	<div>
+		<div th:text="${slideView}">
+
+		</div>
+		<div name="slideView" th:each="content : ${slideView}">
+			<p th:text="${content.caption}">112</p>
+			<img src="https://www.baidu.com/img/bd_logo1.png" th:src="@{${content.image}}" th:alt="${content.caption}" style="width: 100px; height: 120px;"/>
+		</div>
+		<!--<div th:each="content : ${slideView}">
+			<img src="https://www.google.com.hk/url?sa=i&rct=j&q=&esrc=s&source=imgres&cd=&cad=rja&uact=8&ved=0ahUKEwiZo_jygavSAhWJsI8KHY6iAtcQjRwIBw&url=%68%74%74%70%73%3a%2f%2f%62%6c%6f%67%2e%63%6f%64%69%6e%67%2e%6e%65%74%2f%62%6c%6f%67%2f%53%70%72%69%6e%67%2d%42%6f%6f%74&psig=AFQjCNGkuazbz40GWFXDwtqBXmVpGd1seA&ust=1488104096811223" th:src="${content.image}" th:alt="${content.caption}">
+		</div>-->
+	</div>
+</body>
+</html>

+ 10 - 0
demo-test-web/src/main/resources/templates/shop.html

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:th="http://www.thymeleaf.org">
+<head>
+	<title>Getting Started: Serving Web Content</title>
+	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+</head>
+<body>
+	<p th:text="'Hello, ' + ${name} + '!'" />
+</body>
+</html>

+ 16 - 0
demo-test-web/src/main/webapp/index.jsp

@@ -0,0 +1,16 @@
+<%--
+  Created by IntelliJ IDEA.
+  User: Arvin
+  Date: 2017/2/25
+  Time: 12:34
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+  <head>
+    <title>$Title$</title>
+  </head>
+  <body>
+  $END$
+  </body>
+</html>

BIN
gradle/wrapper/gradle-wrapper.jar


+ 6 - 0
gradle/wrapper/gradle-wrapper.properties

@@ -0,0 +1,6 @@
+#Fri Feb 24 17:04:48 CST 2017
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip

+ 164 - 0
gradlew

@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+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
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+    echo "$*"
+}
+
+die ( ) {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+  NONSTOP* )
+    nonstop=true
+    ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+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
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+    JAVACMD=`cygpath --unix "$JAVACMD"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=$((i+1))
+    done
+    case $i in
+        (0) set -- ;;
+        (1) set -- "$args0" ;;
+        (2) set -- "$args0" "$args1" ;;
+        (3) set -- "$args0" "$args1" "$args2" ;;
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+    JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

+ 90 - 0
gradlew.bat

@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem  Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega

+ 3 - 0
settings.gradle

@@ -0,0 +1,3 @@
+rootProject.name = 'mall-cms-service'
+include 'demo-test-web'
+

+ 14 - 0
src/main/java/com/uas/cloud/mall/service/Application.java

@@ -0,0 +1,14 @@
+package com.uas.cloud.mall.service;
+
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+
+@EnableDiscoveryClient
+@SpringBootApplication
+public class Application {
+
+	public static void main(String[] args) {
+		new SpringApplicationBuilder(Application.class).web(true).run(args);
+	}
+}

+ 68 - 0
src/main/java/com/uas/cloud/mall/service/controller/ContentController.java

@@ -0,0 +1,68 @@
+package com.uas.cloud.mall.service.controller;
+
+import com.uas.cloud.mall.service.facade.ContentFacade;
+import com.uas.cloud.mall.service.model.Content;
+import com.uas.cloud.mall.service.model.Module;
+import com.uas.cloud.mall.service.service.ContentService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+
+@RestController
+@RequestMapping("/mall-cms-service/")
+public class ContentController {
+
+	private final ContentService contentService;
+
+	private final ContentFacade contentFacade;
+
+	@Autowired
+	public ContentController(ContentService contentService, ContentFacade contentFacade) {
+		this.contentService = contentService;
+		this.contentFacade = contentFacade;
+	}
+
+	/**
+	 * 新增或修改内容信息
+	 *
+	 * @param content	待持久化的内容
+	 */
+	@RequestMapping(value = "/contents", method = RequestMethod.POST)
+	public Content saveContent(@RequestBody Content content) {
+		return contentService.saveContent(content);
+	}
+
+	/**
+	 * 根据内容ID删除内容信息
+	 *
+	 * @param id	内容主键ID
+	 */
+	@RequestMapping(value = "/contents/{id}", method = RequestMethod.DELETE)
+	public Content deleteContent(@PathVariable("id") String id) {
+		return contentService.deleteContent(id);
+	}
+
+	/**
+	 * 根据模块名称获取内容列表
+	 *
+	 * @param moduleName	模板名称
+	 */
+	@RequestMapping(value = "/contents", method = RequestMethod.GET)
+	public List<Content> findByModuleName(String moduleName) {
+		return contentService.findByModuleName(moduleName);
+	}
+
+	/**
+	 * 获取当前URI中所有模块信息
+	 *
+	 * @param path	当前URI路径
+	 */
+	@RequestMapping(value = "/modules", method = RequestMethod.GET)
+	public List<Module> findModulesByPath(@RequestParam("path") String path, HttpServletRequest request) {
+		String realPath = request.getSession().getServletContext().getRealPath("/");
+		return contentFacade.findModulesByPath(path, realPath);
+	}
+
+}

+ 16 - 0
src/main/java/com/uas/cloud/mall/service/facade/ContentFacade.java

@@ -0,0 +1,16 @@
+package com.uas.cloud.mall.service.facade;
+
+import com.uas.cloud.mall.service.model.Module;
+
+import java.util.List;
+
+public interface ContentFacade {
+
+	/**
+	 * 读取配置文件中的数据,获取当前URI中所有模块信息的内容信息
+	 *
+	 * @param path		当前URI路径
+	 * @param realPath	静态资源的实际路径
+	 */
+	List<Module> findModulesByPath(String path, String realPath);
+}

+ 64 - 0
src/main/java/com/uas/cloud/mall/service/facade/impl/ContentFacadeImpl.java

@@ -0,0 +1,64 @@
+package com.uas.cloud.mall.service.facade.impl;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.uas.cloud.mall.service.facade.ContentFacade;
+import com.uas.cloud.mall.service.model.Content;
+import com.uas.cloud.mall.service.model.Module;
+import com.uas.cloud.mall.service.service.ContentService;
+import com.uas.cloud.mall.service.util.CommonUtils;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+
+@Service
+public class ContentFacadeImpl implements ContentFacade {
+
+	private final ContentService contentService;
+
+	private static final String PROFILE_LOCATION = "resources/profile/module-info.json";
+
+	@Autowired
+	public ContentFacadeImpl(ContentService contentService) {
+		this.contentService = contentService;
+	}
+
+	@Override
+	public List<Module> findModulesByPath(String path, String realPath) {
+		if (StringUtils.isEmpty(realPath) || StringUtils.isEmpty(path)) {
+			return Collections.emptyList();
+		}
+		JSONObject profile = CommonUtils.obtainProfile(realPath, PROFILE_LOCATION);
+		if (profile == null) {
+			return Collections.emptyList();
+		}
+		try {
+			String modulesJson = profile.getString(path);
+			if (StringUtils.isEmpty(modulesJson)) {
+				return Collections.emptyList();
+			}
+			ObjectMapper mapper = new ObjectMapper();
+			List<Module> modules = mapper.readValue(modulesJson, new TypeReference<List<Module>>() {});
+			if (CollectionUtils.isEmpty(modules)) {
+				return Collections.emptyList();
+			}
+			for (Module module : modules) {
+				List<Content> contents = contentService.findByModuleName(module.getName());
+				if (!CollectionUtils.isEmpty(contents)) {
+					module.setContents(contents);
+				}
+			}
+			return modules;
+		} catch (JSONException | IOException e) {
+			e.printStackTrace();
+			return Collections.emptyList();
+		}
+	}
+}

+ 202 - 0
src/main/java/com/uas/cloud/mall/service/model/Content.java

@@ -0,0 +1,202 @@
+package com.uas.cloud.mall.service.model;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+import org.springframework.data.mongodb.core.mapping.Field;
+
+import java.util.Date;
+
+/**
+ * 内容实体类
+ */
+@Document
+public class Content {
+
+	@Id
+	private String id;
+
+	/**
+	 * 模块名称
+	 */
+	@Field("module_name")
+	private String moduleName;
+
+	/**
+	 * 标签
+	 */
+	private String flag;
+
+	/**
+	 * 排序
+	 */
+	private int order;
+
+	/**
+	 * 标题
+	 */
+	private String caption;
+
+	/**
+	 * 子标题
+	 */
+	@Field("sub_caption")
+	private String subCaption;
+
+	/**
+	 * 描述
+	 */
+	private String description;
+
+	/**
+	 * 文本内容
+	 */
+	@Field("text_content")
+	private String textContent;
+
+	/**
+	 * 缩略图
+	 */
+	private String thumbnail;
+
+	/**
+	 * 大图
+	 */
+	private String image;
+
+	/**
+	 * 链接
+	 */
+	private String url;
+
+	/**
+	 * 备注
+	 */
+	private String remark;
+
+	/**
+	 * 创建时间
+	 */
+	@Field("create_time")
+	private Date createTime;
+
+	/**
+	 * 更新时间
+	 */
+	@Field("update_time")
+	private Date updateTime;
+
+	public Content() {
+	}
+
+	public String getId() {
+		return id;
+	}
+
+	public void setId(String id) {
+		this.id = id;
+	}
+
+	public String getModuleName() {
+		return moduleName;
+	}
+
+	public void setModuleName(String moduleName) {
+		this.moduleName = moduleName;
+	}
+
+	public int getOrder() {
+		return order;
+	}
+
+	public void setOrder(int order) {
+		this.order = order;
+	}
+
+	public String getCaption() {
+		return caption;
+	}
+
+	public void setCaption(String caption) {
+		this.caption = caption;
+	}
+
+	public String getSubCaption() {
+		return subCaption;
+	}
+
+	public void setSubCaption(String subCaption) {
+		this.subCaption = subCaption;
+	}
+
+	public String getDescription() {
+		return description;
+	}
+
+	public void setDescription(String description) {
+		this.description = description;
+	}
+
+	public String getTextContent() {
+		return textContent;
+	}
+
+	public void setTextContent(String textContent) {
+		this.textContent = textContent;
+	}
+
+	public String getThumbnail() {
+		return thumbnail;
+	}
+
+	public void setThumbnail(String thumbnail) {
+		this.thumbnail = thumbnail;
+	}
+
+	public String getImage() {
+		return image;
+	}
+
+	public void setImage(String image) {
+		this.image = image;
+	}
+
+	public String getUrl() {
+		return url;
+	}
+
+	public void setUrl(String url) {
+		this.url = url;
+	}
+
+	public String getRemark() {
+		return remark;
+	}
+
+	public void setRemark(String remark) {
+		this.remark = remark;
+	}
+
+	public String getFlag() {
+		return flag;
+	}
+
+	public void setFlag(String flag) {
+		this.flag = flag;
+	}
+
+	public Date getCreateTime() {
+		return createTime;
+	}
+
+	public void setCreateTime(Date createTime) {
+		this.createTime = createTime;
+	}
+
+	public Date getUpdateTime() {
+		return updateTime;
+	}
+
+	public void setUpdateTime(Date updateTime) {
+		this.updateTime = updateTime;
+	}
+}

+ 17 - 0
src/main/java/com/uas/cloud/mall/service/model/ContentRepository.java

@@ -0,0 +1,17 @@
+package com.uas.cloud.mall.service.model;
+
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface ContentRepository extends MongoRepository<Content, String> {
+
+	/**
+	 * 根据模块名称查询内容信息列表
+	 *
+	 * @param moduleName	模板名称
+	 */
+	List<Content> findByModuleName(String moduleName);
+}

+ 68 - 0
src/main/java/com/uas/cloud/mall/service/model/Module.java

@@ -0,0 +1,68 @@
+package com.uas.cloud.mall.service.model;
+
+import java.util.List;
+
+/**
+ * 模块信息
+ *
+ * history:
+ * Created by huxz on 2017-2-25 14:56:02
+ */
+public class Module {
+
+	/**
+	 * 模块名称
+	 */
+	private String name;
+
+	/**
+	 * 路径
+	 */
+	private String path;
+
+	/**
+	 * 标签
+	 */
+	private String tag;
+
+	/**
+	 * 内容列表信息
+	 */
+	private List<Content> contents;
+
+	public Module() {
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getPath() {
+		return path;
+	}
+
+	public void setPath(String path) {
+		this.path = path;
+	}
+
+	public String getTag() {
+		return tag;
+	}
+
+	public void setTag(String tag) {
+		this.tag = tag;
+	}
+
+	public List<Content> getContents() {
+		return contents;
+	}
+
+	public void setContents(List<Content> contents) {
+		this.contents = contents;
+	}
+
+}

+ 30 - 0
src/main/java/com/uas/cloud/mall/service/service/ContentService.java

@@ -0,0 +1,30 @@
+package com.uas.cloud.mall.service.service;
+
+import com.uas.cloud.mall.service.model.Content;
+
+import java.util.List;
+
+public interface ContentService {
+
+	/**
+	 * 新增或修改内容信息
+	 *
+	 * @param content	待持久化的内容
+	 */
+	Content saveContent(Content content);
+
+	/**
+	 * 根据内容主键ID删除内容
+	 *
+	 * @param id    内容主键ID
+	 */
+	Content deleteContent(String id);
+
+	/**
+	 * 根据模块名称获取内容列表信息
+	 *
+	 * @param moduleName	模板名称
+	 */
+	List<Content> findByModuleName(String moduleName);
+
+}

+ 48 - 0
src/main/java/com/uas/cloud/mall/service/service/impl/ContentServiceImpl.java

@@ -0,0 +1,48 @@
+package com.uas.cloud.mall.service.service.impl;
+
+import com.uas.cloud.mall.service.model.Content;
+import com.uas.cloud.mall.service.model.ContentRepository;
+import com.uas.cloud.mall.service.service.ContentService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import java.util.Collections;
+import java.util.List;
+
+@Service
+public class ContentServiceImpl implements ContentService {
+
+	private final ContentRepository contentDao;
+
+	@Autowired
+	public ContentServiceImpl(ContentRepository contentDao) {
+		this.contentDao = contentDao;
+	}
+
+	@Override
+	public Content saveContent(Content content) {
+		if (content == null) {
+			return null;
+		}
+		return contentDao.save(content);
+	}
+
+	@Override
+	public Content deleteContent(String id) {
+		if (StringUtils.isEmpty(id)) {
+			return null;
+		}
+		Content content = contentDao.findOne(id);
+		contentDao.delete(id);
+		return content;
+	}
+
+	@Override
+	public List<Content> findByModuleName(String moduleName) {
+		if (StringUtils.isEmpty(moduleName)) {
+			return Collections.emptyList();
+		}
+		return contentDao.findByModuleName(moduleName);
+	}
+}

+ 54 - 0
src/main/java/com/uas/cloud/mall/service/util/CommonUtils.java

@@ -0,0 +1,54 @@
+package com.uas.cloud.mall.service.util;
+
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+
+import java.io.*;
+import java.util.UUID;
+
+/**
+ * 通用工具类
+ *
+ * history:
+ * Created by huxz on 2017-2-25 11:54:42
+ */
+public class CommonUtils {
+
+	/**
+	 * 生成UUID
+	 */
+	public static String GenerateUUid() {
+		String uuid = UUID.randomUUID().toString();
+		return uuid.replace("-", "");
+	}
+
+	/**
+	 * 获取配置信息
+	 *
+	 * @param realPath	静态资源的实际位置
+	 * @param filePath	配置文件的位置
+	 */
+	public static JSONObject obtainProfile(String realPath, String filePath) {
+		BufferedReader reader = null;
+		try {
+			reader = new BufferedReader(new FileReader(new File(realPath, filePath)));
+			StringBuilder builder = new StringBuilder();
+			String line;
+			while ((line = reader.readLine()) != null) {
+				builder.append(line);
+			}
+			return new JSONObject(builder.toString());
+		} catch (IOException | JSONException e) {
+			e.printStackTrace();
+		} finally {
+			if (reader != null) {
+				try {
+					reader.close();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		}
+		return null;
+	}
+}

+ 13 - 0
src/main/resources/application-dev.yml

@@ -0,0 +1,13 @@
+server:
+  port: 3160
+
+eureka:
+  client:
+    service-url:
+      defaultZone: http://localhost:1111/eureka/
+
+spring:
+  data:
+    # Spring Data Mongo
+    mongodb:
+      uri: mongodb://localhost:27017/cms

+ 0 - 0
src/main/resources/application-prod.yml


+ 0 - 0
src/main/resources/application-test.yml


+ 5 - 0
src/main/resources/application.yml

@@ -0,0 +1,5 @@
+spring:
+  application:
+    name: mall-cms-service
+  profiles:
+    active: dev

+ 13 - 0
src/main/webapp/resources/profile/module-info.json

@@ -0,0 +1,13 @@
+{
+  "/contents" : [
+	{
+	  "name" : "slideView",
+	  "path" : "/contents",
+	  "tag" : "image"
+	} , {
+	  "name" : "slideView",
+	  "path" : "/contents",
+	  "tag" : "image"
+	}
+  ]
+}

+ 11 - 0
src/test/java/com/uas/cloud/mall/service/parent/ApplicationTest.java

@@ -0,0 +1,11 @@
+package com.uas.cloud.mall.service.parent;
+
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest
+public class ApplicationTest {
+
+}

+ 50 - 0
src/test/java/com/uas/cloud/mall/service/service/ContentServiceTest.java

@@ -0,0 +1,50 @@
+package com.uas.cloud.mall.service.service;
+
+import com.uas.cloud.mall.service.model.Content;
+import com.uas.cloud.mall.service.parent.ApplicationTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+
+public class ContentServiceTest extends ApplicationTest {
+
+	@Autowired
+	private ContentService contentService;
+
+	@Test
+	public void saveContent() throws Exception {
+		Date date = new Date();
+		Content content = new Content();
+		content.setId("d549675ffe974420a710a7e59e889c16");
+		content.setCaption("Title");
+		content.setSubCaption("subTitle");
+		content.setDescription("This is an description for testing content!");
+		content.setCreateTime(date);
+		content.setUpdateTime(date);
+		content.setModuleName("slide-view");
+		content.setFlag("image");
+		content.setImage("icon3.jpg");
+		content.setOrder(2);
+		content.setRemark("Just for testing");
+		content = contentService.saveContent(content);
+		System.out.println(Objects.toString(content));
+	}
+
+	@Test
+	public void deleteContent() throws Exception {
+		Content content = contentService.deleteContent("59175b5bbb084e658ca15ded2082b95f");
+		System.out.println(Objects.toString(content));
+	}
+
+	@Test
+	public void findByModuleName() throws Exception {
+		List<Content> contents = contentService.findByModuleName("slide-view");
+		for (Content content : contents) {
+			System.out.println(String.format("{id: %s, caption: %s}", content.getId(), content.getCaption()));
+		}
+	}
+
+}