Browse Source

问卷接口

YeLuo 5 years ago
parent
commit
848574d75f

+ 48 - 0
src/main/java/com/yingying/tourist/business/BusinessConstant.java

@@ -0,0 +1,48 @@
1
+package com.yingying.tourist.business;
2
+
3
+import java.util.HashMap;
4
+import java.util.Map;
5
+
6
+public class BusinessConstant {
7
+
8
+    public enum Identity{
9
+        A("A","自然的崇拜者"), B("B","洒脱的冒险家"), C("C","文化的朝圣者"),D("D","心灵的按摩师");
10
+
11
+        Identity(String key,String value){
12
+            this.key = key;
13
+            this.value = value;
14
+        }
15
+        public String key;
16
+        public String value;
17
+
18
+        public static String getValue(String key) {
19
+            if (key==null) return null;
20
+            for (Identity d : Identity.values()){
21
+                if (key.equals(d.key)) {
22
+                    return d.value;
23
+                }
24
+            }
25
+            return key;
26
+        }
27
+    }
28
+
29
+    public static Map<Integer, String> describeMap = new HashMap<>(16);
30
+    static {
31
+        describeMap.put(1,"在山西挖煤挖到300000斤");
32
+        describeMap.put(2,"做环卫工打扫400个公厕坑位");
33
+        describeMap.put(3,"去动物园完成200次小脑斧近身喂食");
34
+        describeMap.put(4,"埋伏在巷子口专业碰瓷150次");
35
+        describeMap.put(5,"出演神剧龙套装死1800次");
36
+        describeMap.put(6,"在鬼屋扮鬼被人毒打900次");
37
+        describeMap.put(7,"在路边卖掉12000张煎饼果子");
38
+        describeMap.put(8,"帮狗粮工厂试吃1111罐狗粮");
39
+        describeMap.put(9,"在澡堂搭毛巾帮人搓澡1700次");
40
+        describeMap.put(10,"骑三轮车拉完800个胖太太客人");
41
+        describeMap.put(11,"沿街收破烂走过600条街");
42
+        describeMap.put(12,"劝退300位斯巴达广场舞大妈");
43
+        describeMap.put(13,"猫在后厨边哭边刷30000个盘子");
44
+        describeMap.put(14,"去民政局门口卖唱500首分手快乐");
45
+        describeMap.put(15,"去黑帮老大家催收到200万欠款");
46
+        describeMap.put(16,"下乡给4000头公猪做绝育手术");
47
+    }
48
+}

+ 2 - 0
src/main/java/com/yingying/tourist/vo/QuestionVo.java

@@ -7,4 +7,6 @@ public class QuestionVo {
7 7
     private String resultDestination;
8 8
     private String resultOutter;
9 9
     private String resultInner;
10
+    private String resultIdentity;
11
+    private String resultDescribe;
10 12
 }

+ 11 - 4
src/main/java/com/yingying/tourist/web/QuestionController.java

@@ -1,14 +1,16 @@
1 1
 package com.yingying.tourist.web;
2 2
 
3 3
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
4
+import com.yingying.tourist.business.BusinessConstant;
5
+import com.yingying.tourist.common.Util;
4 6
 import com.yingying.tourist.domain.Question;
7
+import com.yingying.tourist.exception.ErrorCode;
5 8
 import com.yingying.tourist.result.MessageResult;
6 9
 import com.yingying.tourist.service.QuestionService;
7 10
 import com.yingying.tourist.vo.QuestionVo;
8 11
 import org.springframework.beans.BeanUtils;
9 12
 import org.springframework.beans.factory.annotation.Autowired;
10 13
 import org.springframework.web.bind.annotation.GetMapping;
11
-import org.springframework.web.bind.annotation.RequestParam;
12 14
 import org.springframework.web.bind.annotation.RestController;
13 15
 
14 16
 @RestController
@@ -18,13 +20,18 @@ public class QuestionController {
18 20
     private QuestionService questionService;
19 21
 
20 22
     @GetMapping("question/pick")
21
-    public MessageResult<QuestionVo> question(String pickOne, String pickTwo, String pickThird,String pickFourth){
23
+    public MessageResult<QuestionVo> question(String pickOne, String pickTwo, String pickThird, String pickFourth){
24
+        if (Util.isNull(pickOne) || Util.isNull(pickTwo) || Util.isNull(pickThird) || Util.isNull(pickFourth)) {
25
+            return new MessageResult<QuestionVo>().failure(ErrorCode.PARAMETERS_ERROR);
26
+        }
27
+        QuestionVo questionVo = new QuestionVo();
22 28
         String pick = pickOne + pickTwo + pickThird;
23 29
         EntityWrapper<Question> wrapper = new EntityWrapper<>();
24
-        wrapper.eq("questionPath", pick);
30
+        wrapper.eq("question_path", pick);
25 31
         Question question = questionService.selectOne(wrapper);
26
-        QuestionVo questionVo = new QuestionVo();
27 32
         BeanUtils.copyProperties(question, questionVo);
33
+        questionVo.setResultDescribe(BusinessConstant.describeMap.get(Util.getRandomInt(1,16)));
34
+        questionVo.setResultIdentity(BusinessConstant.Identity.getValue(pickFourth));
28 35
         return new MessageResult<QuestionVo>().ok(questionVo);
29 36
     }
30 37
 }