From 78fffad1fffb77ada79a329fc52dcce98661e870 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期一, 24 五月 2021 06:30:37 +0800
Subject: [PATCH] 优化代码

---
 service-user/src/main/java/com/java110/user/api/QuestionAnswerApi.java |   62 +++++++++++++++++++++++++------
 1 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/service-user/src/main/java/com/java110/user/api/QuestionAnswerApi.java b/service-user/src/main/java/com/java110/user/api/QuestionAnswerApi.java
old mode 100644
new mode 100755
index a11aa62..606bcde
--- a/service-user/src/main/java/com/java110/user/api/QuestionAnswerApi.java
+++ b/service-user/src/main/java/com/java110/user/api/QuestionAnswerApi.java
@@ -1,5 +1,6 @@
 package com.java110.user.api;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.java110.dto.questionAnswer.QuestionAnswerDto;
 import com.java110.dto.questionAnswerTitle.QuestionAnswerTitleDto;
@@ -21,9 +22,15 @@
 import com.java110.user.bmo.questionAnswerTitleValue.IUpdateQuestionAnswerTitleValueBMO;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.BeanConvertUtil;
+import com.java110.utils.util.StringUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
 
 @RestController
@@ -103,7 +110,6 @@
         Assert.hasKeyAndValue(reqJson, "qaName", "璇锋眰鎶ユ枃涓湭鍖呭惈qaName");
         Assert.hasKeyAndValue(reqJson, "startTime", "璇锋眰鎶ユ枃涓湭鍖呭惈startTime");
         Assert.hasKeyAndValue(reqJson, "endTime", "璇锋眰鎶ユ枃涓湭鍖呭惈endTime");
-        Assert.hasKeyAndValue(reqJson, "objType", "璇锋眰鎶ユ枃涓湭鍖呭惈objType");
         Assert.hasKeyAndValue(reqJson, "qaId", "qaId涓嶈兘涓虹┖");
 
 
@@ -140,7 +146,8 @@
      */
     @RequestMapping(value = "/queryQuestionAnswer", method = RequestMethod.GET)
     public ResponseEntity<String> queryQuestionAnswer(
-            @RequestHeader(value = "store-id") String storeId,
+            @RequestHeader(value = "store-id", required = false) String storeId,
+            @RequestHeader(value = "user-id", required = false) String userId,
             @RequestParam(value = "communityId", required = false) String communityId,
             @RequestParam(value = "objType", required = false) String objType,
             @RequestParam(value = "page") int page,
@@ -148,8 +155,13 @@
         QuestionAnswerDto questionAnswerDto = new QuestionAnswerDto();
         questionAnswerDto.setPage(page);
         questionAnswerDto.setRow(row);
-        questionAnswerDto.setObjType(objType);
-        questionAnswerDto.setObjId(QuestionAnswerDto.QA_TYPE_COMMUNITY.endsWith(objType) ? communityId : storeId);
+        questionAnswerDto.setUserId(userId);
+        if (!StringUtil.isEmpty(objType)) {
+            questionAnswerDto.setObjType(objType);
+            questionAnswerDto.setObjId(QuestionAnswerDto.QA_TYPE_COMMUNITY.equals(objType) ? communityId : storeId);
+        } else {
+            questionAnswerDto.setObjIds(new String[]{storeId, communityId});
+        }
         return getQuestionAnswerBMOImpl.get(questionAnswerDto);
     }
 
@@ -167,12 +179,22 @@
         Assert.hasKeyAndValue(reqJson, "qaId", "璇锋眰鎶ユ枃涓湭鍖呭惈qaId");
         Assert.hasKeyAndValue(reqJson, "qaTitle", "璇锋眰鎶ユ枃涓湭鍖呭惈qaTitle");
         Assert.hasKeyAndValue(reqJson, "titleType", "璇锋眰鎶ユ枃涓湭鍖呭惈titleType");
+        Assert.hasKeyAndValue(reqJson, "objId", "璇锋眰鎶ユ枃涓湭鍖呭惈objId");
         Assert.hasKeyAndValue(reqJson, "objType", "璇锋眰鎶ユ枃涓湭鍖呭惈objType");
         Assert.hasKeyAndValue(reqJson, "seq", "璇锋眰鎶ユ枃涓湭鍖呭惈seq");
 
+        JSONArray titleValues = null;
+        if (!QuestionAnswerTitleDto.TITLE_TYPE_QUESTIONS.equals(reqJson.getString("titleType"))) {
+            titleValues = reqJson.getJSONArray("titleValues");
+
+            if (titleValues.size() < 1) {
+                throw new IllegalArgumentException("鏈寘鍚�夐」");
+            }
+        }
+
 
         QuestionAnswerTitlePo questionAnswerTitlePo = BeanConvertUtil.covertBean(reqJson, QuestionAnswerTitlePo.class);
-        return saveQuestionAnswerTitleBMOImpl.save(questionAnswerTitlePo);
+        return saveQuestionAnswerTitleBMOImpl.save(questionAnswerTitlePo, titleValues);
     }
 
     /**
@@ -186,16 +208,23 @@
     @RequestMapping(value = "/updateQuestionAnswerTitle", method = RequestMethod.POST)
     public ResponseEntity<String> updateQuestionAnswerTitle(@RequestBody JSONObject reqJson) {
 
-        Assert.hasKeyAndValue(reqJson, "qaId", "璇锋眰鎶ユ枃涓湭鍖呭惈qaId");
+//        Assert.hasKeyAndValue(reqJson, "qaId", "璇锋眰鎶ユ枃涓湭鍖呭惈qaId");
         Assert.hasKeyAndValue(reqJson, "qaTitle", "璇锋眰鎶ユ枃涓湭鍖呭惈qaTitle");
         Assert.hasKeyAndValue(reqJson, "titleType", "璇锋眰鎶ユ枃涓湭鍖呭惈titleType");
         Assert.hasKeyAndValue(reqJson, "objType", "璇锋眰鎶ユ枃涓湭鍖呭惈objType");
         Assert.hasKeyAndValue(reqJson, "seq", "璇锋眰鎶ユ枃涓湭鍖呭惈seq");
         Assert.hasKeyAndValue(reqJson, "titleId", "titleId涓嶈兘涓虹┖");
+        JSONArray titleValues = null;
+        if (!QuestionAnswerTitleDto.TITLE_TYPE_QUESTIONS.equals(reqJson.getString("titleType"))) {
+            titleValues = reqJson.getJSONArray("titleValues");
 
+            if (titleValues.size() < 1) {
+                throw new IllegalArgumentException("鏈寘鍚�夐」");
+            }
+        }
 
         QuestionAnswerTitlePo questionAnswerTitlePo = BeanConvertUtil.covertBean(reqJson, QuestionAnswerTitlePo.class);
-        return updateQuestionAnswerTitleBMOImpl.update(questionAnswerTitlePo);
+        return updateQuestionAnswerTitleBMOImpl.update(questionAnswerTitlePo, titleValues);
     }
 
     /**
@@ -226,16 +255,25 @@
      * @path /app/questionAnswer/queryQuestionAnswerTitle
      */
     @RequestMapping(value = "/queryQuestionAnswerTitle", method = RequestMethod.GET)
-    public ResponseEntity<String> queryQuestionAnswerTitle(@RequestHeader(value = "store-id") String storeId,
+    public ResponseEntity<String> queryQuestionAnswerTitle(@RequestHeader(value = "store-id", required = false) String storeId,
+                                                          // @RequestHeader(value = "user-id", required = false) String userId,
                                                            @RequestParam(value = "communityId", required = false) String communityId,
                                                            @RequestParam(value = "objType") String objType,
+                                                           @RequestParam(value = "qaId") String qaId,
                                                            @RequestParam(value = "page") int page,
                                                            @RequestParam(value = "row") int row) {
         QuestionAnswerTitleDto questionAnswerTitleDto = new QuestionAnswerTitleDto();
         questionAnswerTitleDto.setPage(page);
         questionAnswerTitleDto.setRow(row);
-        questionAnswerTitleDto.setObjType(objType);
-        questionAnswerTitleDto.setObjId(QuestionAnswerDto.QA_TYPE_COMMUNITY.endsWith(objType) ? communityId : storeId);
+        questionAnswerTitleDto.setQaId(qaId);
+        //questionAnswerTitleDto.setUserId(userId);
+        if (!StringUtil.isEmpty(objType)) {
+            questionAnswerTitleDto.setObjType(objType);
+            questionAnswerTitleDto.setObjId(QuestionAnswerDto.QA_TYPE_COMMUNITY.equals(objType) ? communityId : storeId);
+        } else {
+            questionAnswerTitleDto.setObjIds(new String[]{storeId, communityId});
+        }
+
         return getQuestionAnswerTitleBMOImpl.get(questionAnswerTitleDto);
     }
 
@@ -319,7 +357,7 @@
         questionAnswerTitleValueDto.setPage(page);
         questionAnswerTitleValueDto.setRow(row);
         questionAnswerTitleValueDto.setObjType(objType);
-        questionAnswerTitleValueDto.setObjId(QuestionAnswerDto.QA_TYPE_COMMUNITY.endsWith(objType) ? communityId : storeId);
+        questionAnswerTitleValueDto.setObjId(QuestionAnswerDto.QA_TYPE_COMMUNITY.equals(objType) ? communityId : storeId);
         return getQuestionAnswerTitleValueBMOImpl.get(questionAnswerTitleValueDto);
     }
 }

--
Gitblit v1.8.0