Kaynağa Gözat

Merge branch 'master' of http://git.dayaedu.com/yonge/edu-saas

zouxuan 5 yıl önce
ebeveyn
işleme
5e30a452ac

+ 1 - 1
edu-user/edu-user-server/src/main/java/com/keao/edu/user/config/ResourceServerConfig.java

@@ -25,7 +25,7 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
 	@Override
 	public void configure(HttpSecurity http) throws Exception {
 		http.authorizeRequests()
-				.antMatchers("/v2/api-docs")
+				.antMatchers("/v2/api-docs", "/su/**")
 				.permitAll()
 				// 任何人不登录都可以获取的资源
 				// .antMatchers("/ipController/**").hasIpAddress("127.0.0.1") //特定ip可以不登录获取资源

+ 33 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/controller/ShortUrlController.java

@@ -0,0 +1,33 @@
+package com.keao.edu.user.controller;
+
+import com.keao.edu.common.controller.BaseController;
+import com.keao.edu.user.entity.ShortUrl;
+import com.keao.edu.user.service.ShortUrlService;
+import io.swagger.annotations.Api;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @Author Joburgess
+ * @Date 2020.06.22
+ */
+@Controller
+@RequestMapping("/")
+@Api(tags = "短链接服务")
+public class ShortUrlController extends BaseController {
+
+    @Autowired
+    private ShortUrlService shortUrlService;
+
+    @GetMapping(value = "/su/{id}")
+    public void redirectUrl(@PathVariable("id") Long id, HttpServletResponse response) throws IOException {
+        ShortUrl shortUrl = shortUrlService.get(id);
+        response.sendRedirect(shortUrl.getUrl());
+    }
+
+}

+ 3 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/entity/ShortUrl.java

@@ -15,6 +15,9 @@ public class ShortUrl {
 
 	private java.util.Date createTime;
 
+	public ShortUrl() {
+	}
+
 	public ShortUrl(String url) {
 		this.url = url;
 	}

+ 6 - 6
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/ShortUrlServiceImpl.java

@@ -30,12 +30,12 @@ public class ShortUrlServiceImpl extends BaseServiceImpl<Long, ShortUrl> impleme
 		}
 		ShortUrl shortUrl=new ShortUrl(sourceUrl);
 		shortUrlDao.insert(shortUrl);
-		StringBuffer returnUrl=new StringBuffer("http://");
-		return null;
-	}
 
-	public static void main(String[] args) {
-		String url="http://192.168.3.151/test/test";
-		System.out.println(url.substring(url.indexOf("//")));
+		String temp=sourceUrl.substring(sourceUrl.indexOf("//")+2);
+		StringBuffer returnUrl=new StringBuffer(sourceUrl.substring(0, sourceUrl.indexOf("//") + temp.indexOf("/") + 2));
+		returnUrl.append("/su/");
+		returnUrl.append(shortUrl.getId());
+
+		return returnUrl.toString();
 	}
 }