pageInfo = new PageInfo(list);
+ Map map = new HashMap(2);
+ map.put("portfolios", pageInfo.getList());
+ Map pagination = Utils.getPagination(pageInfo);
+ map.put("pagination", pagination);
+ return GlobalResultGenerator.genSuccessResult(map);
+ }
}
diff --git a/src/main/java/com/rymcu/forest/web/api/common/WebSocketController.java b/src/main/java/com/rymcu/forest/web/api/common/WebSocketController.java
index 62f5e26..7a3a4b1 100644
--- a/src/main/java/com/rymcu/forest/web/api/common/WebSocketController.java
+++ b/src/main/java/com/rymcu/forest/web/api/common/WebSocketController.java
@@ -1,7 +1,6 @@
package com.rymcu.forest.web.api.common;
import com.alibaba.fastjson.JSONObject;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
@@ -9,7 +8,7 @@ import org.springframework.messaging.simp.annotation.SendToUser;
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.stereotype.Controller;
-import java.util.HashMap;
+import javax.annotation.Resource;
/**
* @author ronger
@@ -17,42 +16,18 @@ import java.util.HashMap;
@Controller
public class WebSocketController {
- @Autowired
+ @Resource
private SimpMessagingTemplate template;
@MessageMapping("/sendMessage")
- @SendTo("/public/greetings")
- public void sendMessage(JSONObject message, StompHeaderAccessor headerAccessor){
- this.template.convertAndSend("/public/greetings",message);
+ @SendTo("/topic/greening")
+ public void sendMessage(JSONObject message, StompHeaderAccessor headerAccessor) {
+ this.template.convertAndSend("/topic/greening", message);
}
@MessageMapping("/message")
@SendToUser("/message")
- public void message(JSONObject message){
- String type = message.get("type").toString();
- HashMap res = (HashMap) message.get("data");
- HashMap mine = (HashMap) res.get("mine");
- HashMap to = (HashMap) res.get("to");
- System.out.println(to.get("type"));
- boolean flag = to.get("type").equals("friend")?true:false;
- String id = to.get("id").toString();
- HashMap map = new HashMap();
- map.put("id",mine.get("id"));
- map.put("avatar",mine.get("avatar"));
- map.put("formid",mine.get("id"));
- map.put("username",mine.get("username"));
- map.put("type",to.get("type"));
- map.put("content",mine.get("content"));
- map.put("mine",false);
- map.put("cid",0);
- map.put("timestamp","");
- JSONObject json = new JSONObject();
- json.put("type",type);
- json.put("data",map);
- if(flag){
- this.template.convertAndSendToUser(id,"/message",json);
- }else{
- this.template.convertAndSendToUser(id,"/message",json);
- }
+ public void message(JSONObject message, StompHeaderAccessor headerAccessor) {
+ this.template.convertAndSendToUser(message.getString("to"), "/message", message);
}
}
diff --git a/src/main/java/com/rymcu/forest/web/api/user/UserController.java b/src/main/java/com/rymcu/forest/web/api/user/UserController.java
index f7e154e..9976387 100644
--- a/src/main/java/com/rymcu/forest/web/api/user/UserController.java
+++ b/src/main/java/com/rymcu/forest/web/api/user/UserController.java
@@ -37,16 +37,16 @@ public class UserController {
@Resource
private FollowService followService;
- @GetMapping("/{nickname}")
+ @GetMapping("/{account}")
@VisitLogger
- public GlobalResult detail(@PathVariable String nickname){
- UserDTO userDTO = userService.findUserDTOByNickname(nickname);
+ public GlobalResult detail(@PathVariable String account){
+ UserDTO userDTO = userService.findUserDTOByAccount(account);
return GlobalResultGenerator.genSuccessResult(userDTO);
}
- @GetMapping("/{nickname}/articles")
- public GlobalResult userArticles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String nickname){
- UserDTO userDTO = userService.findUserDTOByNickname(nickname);
+ @GetMapping("/{account}/articles")
+ public GlobalResult userArticles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){
+ UserDTO userDTO = userService.findUserDTOByAccount(account);
if (userDTO == null){
return GlobalResultGenerator.genErrorResult("用户不存在!");
}
@@ -57,9 +57,9 @@ public class UserController {
return GlobalResultGenerator.genSuccessResult(map);
}
- @GetMapping("/{nickname}/portfolios")
- public GlobalResult userPortfolios(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String nickname){
- UserDTO userDTO = userService.findUserDTOByNickname(nickname);
+ @GetMapping("/{account}/portfolios")
+ public GlobalResult userPortfolios(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){
+ UserDTO userDTO = userService.findUserDTOByAccount(account);
if (userDTO == null){
return GlobalResultGenerator.genErrorResult("用户不存在!");
}
@@ -73,9 +73,9 @@ public class UserController {
return GlobalResultGenerator.genSuccessResult(map);
}
- @GetMapping("/{nickname}/followers")
- public GlobalResult userFollowers(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String nickname){
- UserDTO userDTO = userService.findUserDTOByNickname(nickname);
+ @GetMapping("/{account}/followers")
+ public GlobalResult userFollowers(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){
+ UserDTO userDTO = userService.findUserDTOByAccount(account);
if (userDTO == null){
return GlobalResultGenerator.genErrorResult("用户不存在!");
}
@@ -89,9 +89,9 @@ public class UserController {
return GlobalResultGenerator.genSuccessResult(map);
}
- @GetMapping("/{nickname}/followings")
- public GlobalResult userFollowings(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String nickname){
- UserDTO userDTO = userService.findUserDTOByNickname(nickname);
+ @GetMapping("/{account}/followings")
+ public GlobalResult userFollowings(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){
+ UserDTO userDTO = userService.findUserDTOByAccount(account);
if (userDTO == null){
return GlobalResultGenerator.genErrorResult("用户不存在!");
}
@@ -105,9 +105,9 @@ public class UserController {
return GlobalResultGenerator.genSuccessResult(map);
}
- @GetMapping("/{nickname}/user-extend")
- public GlobalResult userExtend(@PathVariable String nickname) {
- UserExtend userExtend = userService.selectUserExtendByNickname(nickname);
+ @GetMapping("/{account}/user-extend")
+ public GlobalResult userExtend(@PathVariable String account) {
+ UserExtend userExtend = userService.selectUserExtendByAccount(account);
return GlobalResultGenerator.genSuccessResult(userExtend);
}
diff --git a/src/main/java/com/rymcu/forest/wx/mp/controller/WxMenuController.java b/src/main/java/com/rymcu/forest/wx/mp/controller/WxMenuController.java
index 09668aa..1a0e8ad 100644
--- a/src/main/java/com/rymcu/forest/wx/mp/controller/WxMenuController.java
+++ b/src/main/java/com/rymcu/forest/wx/mp/controller/WxMenuController.java
@@ -1,5 +1,6 @@
package com.rymcu.forest.wx.mp.controller;
+import com.rymcu.forest.wx.mp.service.WxMenuService;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.bean.menu.WxMenuButton;
@@ -7,8 +8,11 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
import me.chanjar.weixin.mp.bean.menu.WxMpMenu;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
+import javax.annotation.Resource;
+import java.io.IOException;
import java.net.MalformedURLException;
import static me.chanjar.weixin.common.api.WxConsts.MenuButtonType;
@@ -21,7 +25,8 @@ import static me.chanjar.weixin.common.api.WxConsts.MenuButtonType;
@RequestMapping("/wx/menu/{appId}")
public class WxMenuController {
private final WxMpService wxService;
-
+ @Resource
+ private WxMenuService wxMenuService;
/**
*
* 自定义菜单创建接口
@@ -38,52 +43,9 @@ public class WxMenuController {
}
@GetMapping("/create")
- public String menuCreateSample(@PathVariable String appId) throws WxErrorException, MalformedURLException {
- WxMenu menu = new WxMenu();
- WxMenuButton button1 = new WxMenuButton();
- button1.setType(MenuButtonType.VIEW);
- button1.setName("官方网站");
- button1.setUrl("https://rymcu.com");
-
-// WxMenuButton button2 = new WxMenuButton();
-// button2.setType(WxConsts.BUTTON_MINIPROGRAM);
-// button2.setName("小程序");
-// button2.setAppId("wx286b93c14bbf93aa");
-// button2.setPagePath("pages/lunar/index.html");
-// button2.setUrl("http://mp.weixin.qq.com");
-
- WxMenuButton button3 = new WxMenuButton();
- button3.setName("学习教程");
-
- menu.getButtons().add(button1);
-// menu.getButtons().add(button2);
- menu.getButtons().add(button3);
-
- WxMenuButton button31 = new WxMenuButton();
- button31.setType(MenuButtonType.VIEW);
- button31.setName("51单片机入门教程");
- button31.setUrl("https://mp.weixin.qq.com/mp/homepage?__biz=MzA3NjMzMzM1Mw==&hid=1&sn=672df75323f9976d990f6be14355070b");
-
-// WxMenuButton button34 = new WxMenuButton();
-// button34.setType(MenuButtonType.VIEW);
-// button34.setName("获取用户信息");
-//
-// ServletRequestAttributes servletRequestAttributes =
-// (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
-// if (servletRequestAttributes != null) {
-// HttpServletRequest request = servletRequestAttributes.getRequest();
-// URL requestURL = new URL(request.getRequestURL().toString());
-// String url = this.wxService.switchoverTo(appId).oauth2buildAuthorizationUrl(
-// String.format("%s://%s/wx/redirect/%s/greet", requestURL.getProtocol(), requestURL.getHost(), appId),
-// WxConsts.OAuth2Scope.SNSAPI_USERINFO, null);
-// button34.setUrl(url);
-// }
-
- button3.getSubButtons().add(button31);
-// button3.getSubButtons().add(button34);
-
+ public String menuCreateSample(@PathVariable String appId) throws WxErrorException, IOException {
this.wxService.switchover(appId);
- return this.wxService.getMenuService().menuCreate(menu);
+ return this.wxService.getMenuService().menuCreate(wxMenuService.getMenus());
}
/**
diff --git a/src/main/java/com/rymcu/forest/wx/mp/controller/WxRedirectController.java b/src/main/java/com/rymcu/forest/wx/mp/controller/WxRedirectController.java
index 0395f65..2e0364c 100644
--- a/src/main/java/com/rymcu/forest/wx/mp/controller/WxRedirectController.java
+++ b/src/main/java/com/rymcu/forest/wx/mp/controller/WxRedirectController.java
@@ -1,10 +1,10 @@
package com.rymcu.forest.wx.mp.controller;
import lombok.AllArgsConstructor;
+import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
+import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
-import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
@@ -27,8 +27,8 @@ public class WxRedirectController {
}
try {
- WxMpOAuth2AccessToken accessToken = wxService.getOAuth2Service().getAccessToken(code);
- WxMpUser user = wxService.getOAuth2Service().getUserInfo(accessToken, null);
+ WxOAuth2AccessToken accessToken = wxService.getOAuth2Service().getAccessToken(code);
+ WxOAuth2UserInfo user = wxService.getOAuth2Service().getUserInfo(accessToken, null);
map.put("user", user);
} catch (WxErrorException e) {
e.printStackTrace();
diff --git a/src/main/java/com/rymcu/forest/wx/mp/controller/WxoAuthController.java b/src/main/java/com/rymcu/forest/wx/mp/controller/WxoAuthController.java
index d302914..8638bf5 100644
--- a/src/main/java/com/rymcu/forest/wx/mp/controller/WxoAuthController.java
+++ b/src/main/java/com/rymcu/forest/wx/mp/controller/WxoAuthController.java
@@ -4,10 +4,10 @@ import com.rymcu.forest.service.WxUserService;
import com.rymcu.forest.util.ContextHolderUtils;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
+import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.URIUtil;
import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
@@ -44,7 +44,7 @@ public class WxoAuthController {
baseUrl = new StringBuilder(domain).append(contextPath);
}
StringBuilder accessTokenUrl = baseUrl.append("/wx/oauth/" + appId + "/getAccessToken?redirectUrl=").append(URIUtil.encodeURIComponent(redirectUrl));
- String oauth2Url = wxMpService.getOAuth2Service().buildAuthorizationUrl(accessTokenUrl.toString(), WxConsts.OAuth2Scope.SNSAPI_BASE, null);
+ String oauth2Url = wxMpService.getOAuth2Service().buildAuthorizationUrl(accessTokenUrl.toString(), WxConsts.OAuth2Scope.SNSAPI_USERINFO, null);
return "redirect:" + oauth2Url;
}
@@ -52,14 +52,14 @@ public class WxoAuthController {
@GetMapping("getAccessToken")
public String getAccessToken(@PathVariable String appId, @RequestParam(name = "code") String code, @RequestParam(name = "redirectUrl") String redirectUrl) throws Exception {
wxMpService.switchoverTo(appId);
- WxMpOAuth2AccessToken oAuth2AccessToken = wxMpService.getOAuth2Service().getAccessToken(code);
+ WxOAuth2AccessToken oAuth2AccessToken = wxMpService.getOAuth2Service().getAccessToken(code);
boolean valid = wxMpService.getOAuth2Service().validateAccessToken(oAuth2AccessToken);
if (!valid) {
throw new Exception("无权限");
}
- WxMpUser wxMpUser =wxMpService.getUserService().userInfo(oAuth2AccessToken.getOpenId());
- wxUserService.saveUser(wxMpUser,appId);
+ WxMpUser wxMpUser = wxMpService.getUserService().userInfo(oAuth2AccessToken.getOpenId());
+ wxUserService.saveUser(wxMpUser, appId);
ContextHolderUtils.getSession2().setAttribute("wxUser", wxMpUser);
return "redirect:" + redirectUrl;
}
diff --git a/src/main/java/com/rymcu/forest/wx/mp/service/WxMenuService.java b/src/main/java/com/rymcu/forest/wx/mp/service/WxMenuService.java
new file mode 100644
index 0000000..b67745d
--- /dev/null
+++ b/src/main/java/com/rymcu/forest/wx/mp/service/WxMenuService.java
@@ -0,0 +1,17 @@
+package com.rymcu.forest.wx.mp.service;
+
+import me.chanjar.weixin.common.bean.menu.WxMenu;
+
+import java.io.IOException;
+
+/**
+ * @author ronger
+ */
+public interface WxMenuService {
+ /**
+ * 获取公众号菜单配置
+ * @return
+ * @throws IOException
+ */
+ WxMenu getMenus() throws IOException;
+}
diff --git a/src/main/java/com/rymcu/forest/wx/mp/service/impl/WxMenuServiceImpl.java b/src/main/java/com/rymcu/forest/wx/mp/service/impl/WxMenuServiceImpl.java
new file mode 100644
index 0000000..f70493c
--- /dev/null
+++ b/src/main/java/com/rymcu/forest/wx/mp/service/impl/WxMenuServiceImpl.java
@@ -0,0 +1,46 @@
+package com.rymcu.forest.wx.mp.service.impl;
+
+import com.rymcu.forest.wx.mp.service.WxMenuService;
+import me.chanjar.weixin.common.bean.menu.WxMenu;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.io.Resource;
+import org.springframework.stereotype.Service;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Scanner;
+
+/**
+ * @author ronger
+ */
+@Service
+public class WxMenuServiceImpl implements WxMenuService {
+ @Value("classpath:wxMpMenus.json")
+ private Resource menuResource;
+
+ @Override
+ public WxMenu getMenus() throws IOException {
+ File file = menuResource.getFile();
+ String menuJson = this.jsonRead(file);
+ WxMenu wxMenu = WxMenu.fromJson(menuJson);
+ return wxMenu;
+ }
+
+ private String jsonRead(File file) {
+ Scanner scanner = null;
+ StringBuilder buffer = new StringBuilder();
+ try {
+ scanner = new Scanner(file, "utf-8");
+ while (scanner.hasNextLine()) {
+ buffer.append(scanner.nextLine());
+ }
+ } catch (Exception e) {
+
+ } finally {
+ if (scanner != null) {
+ scanner.close();
+ }
+ }
+ return buffer.toString();
+ }
+}
diff --git a/src/main/java/mapper/ArticleMapper.xml b/src/main/java/mapper/ArticleMapper.xml
index 240f694..6b8fd88 100644
--- a/src/main/java/mapper/ArticleMapper.xml
+++ b/src/main/java/mapper/ArticleMapper.xml
@@ -97,6 +97,9 @@
delete from forest_portfolio_article where id_article = #{id}
+
+ delete from forest_article_content where id_article = #{idArticle}
+
\ No newline at end of file
diff --git a/src/main/java/mapper/NotificationMapper.xml b/src/main/java/mapper/NotificationMapper.xml
index 81fa9b0..144d4ca 100644
--- a/src/main/java/mapper/NotificationMapper.xml
+++ b/src/main/java/mapper/NotificationMapper.xml
@@ -10,6 +10,15 @@
+
+
+
+
+
+
+
+
+
insert into forest_notification (id_user, data_type, data_id, data_summary, created_time) values (#{idUser}, #{dataType}, #{dataId}, #{dataSummary}, sysdate())
@@ -19,8 +28,8 @@
-