From 62a447d89331aee1feae7724c7616aa1bb2cfe79 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 16 十月 2024 14:28:37 +0800
Subject: [PATCH] 将CMQ替换为rabbitmq
---
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/HomeNavbarControllerV2.java | 549 ++++++++++++++++++++++++++++++------------------------
1 files changed, 306 insertions(+), 243 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/HomeNavbarControllerV2.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/HomeNavbarControllerV2.java
index 35b72f7..36520c7 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/HomeNavbarControllerV2.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/HomeNavbarControllerV2.java
@@ -1,243 +1,306 @@
-package com.yeshi.fanli.controller.client.v2;
-
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.annotation.Resource;
-
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.yeshi.utils.JsonUtil;
-
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
-import com.yeshi.fanli.entity.accept.AcceptData;
-import com.yeshi.fanli.entity.bus.homemodule.HomeNavbar;
-import com.yeshi.fanli.entity.bus.homemodule.HomeNavbar.NavbarTypeEnum;
-import com.yeshi.fanli.entity.bus.homemodule.HomeNavbarUser;
-import com.yeshi.fanli.exception.homemodule.HomeNavbarUserException;
-import com.yeshi.fanli.service.inter.homemodule.HomeNavbarService;
-import com.yeshi.fanli.service.inter.homemodule.HomeNavbarUserService;
-import com.yeshi.fanli.util.StringUtil;
-
-import net.sf.json.JSONObject;
-
-@Controller
-@RequestMapping("api/v2/navbar")
-public class HomeNavbarControllerV2 {
-
- @Resource
- private HomeNavbarService homeNavbarService;
-
- @Resource
- private HomeNavbarUserService homeNavbarUserService;
-
- /**
- * 鑾峰彇瀵艰埅鏍忓唴瀹�
- *
- * @param acceptData
- * @param out
- */
- @RequestMapping(value = "getHomeItems", method = RequestMethod.POST)
- public void getHomeItems(AcceptData acceptData, Long uid, PrintWriter out) {
- List<HomeNavbar> listNavbar = homeNavbarUserService.listEffectiveNavbar(uid, acceptData.getDevice());
- if (listNavbar == null) {
- listNavbar = new ArrayList<HomeNavbar>();
- }
- JSONObject data = new JSONObject();
- data.put("count", listNavbar.size());
- data.put("listNavbar", JsonUtil.getApiCommonGson().toJson(listNavbar));
- out.print(JsonUtil.loadTrueResult(data));
- }
-
- /**
- * 鑾峰彇瀵艰埅鏍忕紪杈戝唴瀹�
- *
- * @param acceptData
- * @param out
- */
- @RequestMapping(value = "getUserItems", method = RequestMethod.POST)
- public void getUserItems(AcceptData acceptData, Long uid, PrintWriter out) {
- try {
- List<HomeNavbar> listExist = new ArrayList<HomeNavbar>();
- List<HomeNavbar> listItems = new ArrayList<HomeNavbar>();
-
- // 绯荤粺榛樿瀵艰埅鏍�
- List<HomeNavbar> listNavbar = homeNavbarService.listQueryEffectiveNavbar();
- if (listNavbar != null && listNavbar.size() > 0) {
- listItems.addAll(listNavbar);
- }
-
- int nonCount = 0;
- // 鏌ヨ鐢ㄦ埛鑷畾涔夊鑸�
- List<HomeNavbarUser> listUser = homeNavbarUserService.listUserNavbar(uid, acceptData.getDevice());
-
- if (listUser == null || listUser.size() == 0) {
- for (int i = 0; i < listItems.size(); i++) {
- HomeNavbar homeNavbar = listItems.get(i);
- // 娲诲姩鍓旈櫎
- if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
- listItems.remove(homeNavbar);
- i--;
- continue;
- }
-
- if (homeNavbar.getIsDefault()) {
- listExist.add(homeNavbar);
-
- if (homeNavbar.getIsFixed()) {
- nonCount++;
- }
-
- listItems.remove(homeNavbar);
- i--;
- }
- }
-
- } else {
- // 鑾峰彇鍥哄畾涓嶅彲缂栬緫
- for (int i = 0; i < listItems.size(); i++) {
- HomeNavbar homeNavbar = listItems.get(i);
-
- // 娲诲姩鍓旈櫎
- if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
- listItems.remove(homeNavbar);
- i--;
- continue;
- }
-
- if (homeNavbar.getIsFixed()) {
- listExist.add(homeNavbar);
- nonCount++;
-
- listItems.remove(homeNavbar);
- i--;
- }
- }
-
- // 鐢ㄦ埛缂栬緫鐨勬暟鎹�
- for (HomeNavbarUser homeNavbarUser : listUser) {
- HomeNavbar homeNavbar = homeNavbarUser.getHomeNavbar();
- if (homeNavbar == null) {
- continue;
- }
-
- // 娲诲姩鍓旈櫎
- if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
- continue;
- }
-
- long homeId = homeNavbar.getId();
- for (int i = 0; i < listItems.size(); i++) {
- HomeNavbar navbar = listItems.get(i);
- long id = navbar.getId();
- if (homeId == id) {
- // 鍔犲叆鐢ㄦ埛宸查��
- listExist.add(navbar);
- // 绉婚櫎鐢ㄦ埛宸查��
- listItems.remove(navbar);
- i--;
- break;
- }
- }
- }
- }
-
- JSONObject data = new JSONObject();
- data.put("min", 6);
- data.put("max", 16);
- data.put("nonCount", nonCount);
- data.put("listExist", JsonUtil.getApiCommonGson().toJson(listExist));
- data.put("listItems", JsonUtil.getApiCommonGson().toJson(listItems));
- out.print(JsonUtil.loadTrueResult(data));
- } catch (HomeNavbarUserException e) {
- out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
- }
- }
-
- /**
- * 璁剧疆鑷畾涔�
- *
- * @param acceptData
- * @param uid
- * @param list
- * @param out
- */
- @RequestMapping(value = "saveUserItems", method = RequestMethod.POST)
- public void saveUserItems(AcceptData acceptData, Long uid, String barIds, PrintWriter out) {
- try {
- if (StringUtil.isNullOrEmpty(barIds)) {
- out.print(JsonUtil.loadFalseResult("Id鍙傛暟涓嶈兘涓虹┖"));
- return;
- }
-
- Gson gson = new Gson();
- List<Long> list = gson.fromJson(barIds, new TypeToken<ArrayList<Long>>() {
- }.getType());
- if (list == null || list.size() == 0) {
- out.print(JsonUtil.loadFalseResult("鏈娴嬪埌鏁版嵁"));
- return;
- }
-
- homeNavbarUserService.addNavbarUser(uid, acceptData.getDevice(), list);
- out.print(JsonUtil.loadTrueResult("淇濆瓨鎴愬姛"));
- } catch (HomeNavbarUserException e) {
- out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
- }
- }
-
- /**
- * 杩樺師榛樿
- *
- * @param acceptData
- * @param uid
- * @param out
- */
- @RequestMapping(value = "restoreDefault", method = RequestMethod.POST)
- public void restoreDefault(AcceptData acceptData, Long uid, PrintWriter out) {
- try {
- int nonCount = 0;
- List<HomeNavbar> listExist = new ArrayList<HomeNavbar>();
- List<HomeNavbar> listItems = new ArrayList<HomeNavbar>();
-
- List<HomeNavbar> listNavbar = homeNavbarUserService.restoreSystemDefault(uid, acceptData.getDevice());
- if (listNavbar != null && listNavbar.size() > 0) {
- listItems.addAll(listNavbar);
- }
-
- for (int i = 0; i < listItems.size(); i++) {
- HomeNavbar homeNavbar = listItems.get(i);
- // 娲诲姩鍓旈櫎
- if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
- listItems.remove(homeNavbar);
- i--;
- continue;
- }
-
- // 绛涢�夊嚭榛樿椤�
- if (!homeNavbar.getIsDefault()) {
- break;
- } else {
- if (homeNavbar.getIsFixed()) {
- nonCount++;
- }
- listExist.add(homeNavbar);
-
- listItems.remove(homeNavbar);
- i--;
- }
- }
-
- JSONObject data = new JSONObject();
- data.put("nonCount", nonCount);
- data.put("listExist", JsonUtil.getApiCommonGson().toJson(listExist));
- data.put("listItems", JsonUtil.getApiCommonGson().toJson(listItems));
- out.print(JsonUtil.loadTrueResult(data));
- } catch (HomeNavbarUserException e) {
- out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
- }
- }
-
-}
+package com.yeshi.fanli.controller.client.v2;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import com.yeshi.fanli.entity.SystemEnum;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.yeshi.utils.JsonUtil;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.yeshi.fanli.entity.accept.AcceptData;
+import com.yeshi.fanli.entity.bus.homemodule.HomeNavbar;
+import com.yeshi.fanli.entity.bus.homemodule.HomeNavbar.NavbarTypeEnum;
+import com.yeshi.fanli.entity.bus.homemodule.HomeNavbarUser;
+import com.yeshi.fanli.exception.homemodule.HomeNavbarUserException;
+import com.yeshi.fanli.service.inter.homemodule.DeviceSexService;
+import com.yeshi.fanli.service.inter.homemodule.HomeNavbarService;
+import com.yeshi.fanli.service.inter.homemodule.HomeNavbarUserService;
+import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.VersionUtil;
+
+import net.sf.json.JSONObject;
+
+@Controller
+@RequestMapping("api/v2/navbar")
+public class HomeNavbarControllerV2 {
+
+ @Resource
+ private HomeNavbarService homeNavbarService;
+
+ @Resource
+ private HomeNavbarUserService homeNavbarUserService;
+
+ @Resource
+ private DeviceSexService deviceSexService;
+
+
+ /**
+ * 鏀瑰彉鎬у埆
+ *
+ * @param acceptData
+ * @param sex
+ * @param out
+ */
+ @RequestMapping(value = "changeSex", method = RequestMethod.POST)
+ public void changeSex(AcceptData acceptData, Integer sex, PrintWriter out) {
+ try {
+ // 鑾峰彇璁惧瀹氫箟鎬у埆
+ deviceSexService.save(acceptData.getDevice(), sex);
+ JSONObject data = new JSONObject();
+ data.put("sex", sex);
+ out.print(JsonUtil.loadTrueResult(data));
+ } catch (Exception e) {
+ out.print(JsonUtil.loadFalseResult("鍒囨崲澶辫触"));
+ }
+ }
+
+
+ /**
+ * 鑾峰彇瀵艰埅鏍忓唴瀹�
+ *
+ * @param acceptData
+ * @param uid
+ * @param out
+ */
+ @RequestMapping(value = "getHomeItems", method = RequestMethod.POST)
+ public void getHomeItems(AcceptData acceptData, Long uid, PrintWriter out) {
+ // 鑾峰彇璁惧瀹氫箟鎬у埆
+ int deviceSex = deviceSexService.getDeviceSex(acceptData.getDevice(), acceptData.getSystem());
+ List<HomeNavbar> listNavbar = homeNavbarUserService.listEffectiveNavbar(uid, acceptData.getDevice(), deviceSex, acceptData.getSystem());
+
+ List<HomeNavbar> list = new ArrayList<HomeNavbar>();
+ if (listNavbar != null) {
+ list.addAll(listNavbar);
+ }
+
+ //闈炴澘鏍楀揩鐪佸垹闄ょ綉椤电被瀵艰埅
+ for (int i = 0; i < list.size(); i++) {
+ if (list.get(i).getType() == NavbarTypeEnum.web && acceptData.getSystem() != SystemEnum.blks) {
+ list.remove(i--);
+ }
+ }
+
+ if (!VersionUtil.greaterThan_1_6_0(acceptData.getPlatform(), acceptData.getVersion())) {
+ for (int i = 0; i < list.size(); i++) {
+ NavbarTypeEnum type = list.get(i).getType();
+ if (type == NavbarTypeEnum.commonTemplate) {
+ list.remove(i);
+ i--;
+ }
+ }
+ }
+
+ JSONObject data = new JSONObject();
+ data.put("sex", deviceSex);
+ data.put("count", list.size());
+ data.put("listNavbar", JsonUtil.getApiCommonGson().toJson(list));
+ out.print(JsonUtil.loadTrueResult(data));
+ }
+
+ /**
+ * 鑾峰彇瀵艰埅鏍忕紪杈戝唴瀹�
+ *
+ * @param acceptData
+ * @param out
+ */
+ @RequestMapping(value = "getUserItems", method = RequestMethod.POST)
+ public void getUserItems(AcceptData acceptData, Long uid, PrintWriter out) {
+ try {
+ List<HomeNavbar> listExist = new ArrayList<HomeNavbar>();
+ List<HomeNavbar> listItems = new ArrayList<HomeNavbar>();
+
+ // 绯荤粺榛樿瀵艰埅鏍�
+ List<HomeNavbar> listNavbar = homeNavbarService.listQueryEffectiveNavbar(acceptData.getSystem());
+ if (listNavbar != null && listNavbar.size() > 0) {
+ listItems.addAll(listNavbar);
+ }
+
+ int nonCount = 0;
+ // 鏌ヨ鐢ㄦ埛鑷畾涔夊鑸�
+ List<HomeNavbarUser> listUser = homeNavbarUserService.listUserNavbar(uid, acceptData.getDevice(),acceptData.getSystem());
+
+ if (listUser == null || listUser.size() == 0) {
+ for (int i = 0; i < listItems.size(); i++) {
+ HomeNavbar homeNavbar = listItems.get(i);
+ // 娲诲姩鍓旈櫎
+ if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
+ listItems.remove(homeNavbar);
+ i--;
+ continue;
+ }
+
+ if (homeNavbar.getIsDefault()) {
+ if (homeNavbar.getIsFixed()) {
+ nonCount++;
+ }
+
+ listExist.add(homeNavbar);
+ listItems.remove(homeNavbar);
+ i--;
+ continue;
+ }
+ }
+
+ } else {
+ // 鑾峰彇鍥哄畾涓嶅彲缂栬緫
+ for (int i = 0; i < listItems.size(); i++) {
+ HomeNavbar homeNavbar = listItems.get(i);
+
+ // 娲诲姩鍓旈櫎
+ if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
+ listItems.remove(homeNavbar);
+ i--;
+ continue;
+ }
+
+ if (homeNavbar.getIsFixed()) {
+ listExist.add(homeNavbar);
+ nonCount++;
+
+ listItems.remove(homeNavbar);
+ i--;
+ }
+ }
+
+ // 鐢ㄦ埛缂栬緫鐨勬暟鎹�
+ for (HomeNavbarUser homeNavbarUser : listUser) {
+ HomeNavbar homeNavbar = homeNavbarUser.getHomeNavbar();
+ if (homeNavbar == null) {
+ continue;
+ }
+
+ // 娲诲姩鍓旈櫎
+ if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
+ continue;
+ }
+
+ long homeId = homeNavbar.getId();
+ for (int i = 0; i < listItems.size(); i++) {
+ HomeNavbar navbar = listItems.get(i);
+ long id = navbar.getId();
+ if (homeId == id) {
+ // 鍔犲叆鐢ㄦ埛宸查��
+ listExist.add(navbar);
+ // 绉婚櫎鐢ㄦ埛宸查��
+ listItems.remove(navbar);
+ i--;
+ break;
+ }
+ }
+ }
+ }
+
+ JSONObject data = new JSONObject();
+ data.put("min", 6);
+ data.put("max", 16);
+ data.put("nonCount", nonCount);
+ data.put("listExist", JsonUtil.getApiCommonGson().toJson(listExist));
+ data.put("listItems", JsonUtil.getApiCommonGson().toJson(listItems));
+ out.print(JsonUtil.loadTrueResult(data));
+ } catch (HomeNavbarUserException e) {
+ out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
+ }
+ }
+
+ /**
+ * 璁剧疆鑷畾涔�
+ *
+ * @param acceptData
+ * @param uid
+ * @param list
+ * @param out
+ */
+ @RequestMapping(value = "saveUserItems", method = RequestMethod.POST)
+ public void saveUserItems(AcceptData acceptData, Long uid, String barIds, PrintWriter out) {
+ try {
+ if (StringUtil.isNullOrEmpty(barIds)) {
+ out.print(JsonUtil.loadFalseResult("Id鍙傛暟涓嶈兘涓虹┖"));
+ return;
+ }
+
+ Gson gson = new Gson();
+ List<Long> list = gson.fromJson(barIds, new TypeToken<ArrayList<Long>>() {
+ }.getType());
+ if (list == null || list.size() == 0) {
+ out.print(JsonUtil.loadFalseResult("鏈娴嬪埌鏁版嵁"));
+ return;
+ }
+
+ homeNavbarUserService.addNavbarUser(uid, acceptData.getDevice(), list);
+ out.print(JsonUtil.loadTrueResult("淇濆瓨鎴愬姛"));
+
+ // 璁剧疆涓洪�氱敤
+ deviceSexService.save(acceptData.getDevice(), 0);
+
+ } catch (HomeNavbarUserException e) {
+ out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
+ }
+ }
+
+ /**
+ * 杩樺師榛樿
+ *
+ * @param acceptData
+ * @param uid
+ * @param out
+ */
+ @RequestMapping(value = "restoreDefault", method = RequestMethod.POST)
+ public void restoreDefault(AcceptData acceptData, Long uid, PrintWriter out) {
+ try {
+ int nonCount = 0;
+ List<HomeNavbar> listExist = new ArrayList<HomeNavbar>();
+ List<HomeNavbar> listItems = new ArrayList<HomeNavbar>();
+
+
+ List<HomeNavbar> listNavbar = homeNavbarUserService.restoreSystemDefault(uid, acceptData.getDevice(), acceptData.getSystem());
+ if (listNavbar != null && listNavbar.size() > 0) {
+ listItems.addAll(listNavbar);
+ }
+
+ for (int i = 0; i < listItems.size(); i++) {
+ HomeNavbar homeNavbar = listItems.get(i);
+ // 娲诲姩鍓旈櫎
+ if (!NavbarTypeEnum.category.equals(homeNavbar.getType())) {
+ listItems.remove(homeNavbar);
+ i--;
+ continue;
+ }
+
+ // 绛涢�夊嚭榛樿椤�
+ if (!homeNavbar.getIsDefault()) {
+ break;
+ } else {
+ // 鍥哄畾涓暟
+ if (homeNavbar.getIsFixed()) {
+ nonCount++;
+ }
+ // 榛樿椤�
+ listExist.add(homeNavbar);
+ listItems.remove(homeNavbar);
+ i--;
+ continue;
+ }
+ }
+
+ JSONObject data = new JSONObject();
+ data.put("nonCount", nonCount);
+ data.put("listExist", JsonUtil.getApiCommonGson().toJson(listExist));
+ data.put("listItems", JsonUtil.getApiCommonGson().toJson(listItems));
+ out.print(JsonUtil.loadTrueResult(data));
+
+ // 璁剧疆涓洪�氱敤
+ deviceSexService.save(acceptData.getDevice(), 0);
+
+ } catch (HomeNavbarUserException e) {
+ out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
+ }
+ }
+
+}
--
Gitblit v1.8.0