Browse Source

feat(lottery):新增获取当前等级奖品接口

wangyc 7 years ago
parent
commit
cbf7362d2d

+ 30 - 1
src/main/java/com/uas/platform/b2c/common/lottery/controller/LotteryController.java

@@ -1,7 +1,9 @@
 package com.uas.platform.b2c.common.lottery.controller;
 
 import com.uas.platform.b2c.common.lottery.service.ActivityItemService;
+import com.uas.platform.b2c.common.lottery.service.PrizeService;
 import com.uas.platform.b2c.common.lottery.service.UserInfoService;
+import com.uas.platform.b2c.common.lottery.service.WinningHistoryService;
 import com.uas.platform.b2c.trade.support.ResultMap;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -22,10 +24,16 @@ public class LotteryController {
 
     private final ActivityItemService activityItemService;
 
+    private final PrizeService prizeService;
+
+    private final WinningHistoryService winningHistoryService;
+
     @Autowired
-    public LotteryController(UserInfoService userInfoService, ActivityItemService activityItemService) {
+    public LotteryController(UserInfoService userInfoService, ActivityItemService activityItemService, PrizeService prizeService, WinningHistoryService winningHistoryService) {
         this.userInfoService = userInfoService;
         this.activityItemService = activityItemService;
+        this.prizeService = prizeService;
+        this.winningHistoryService = winningHistoryService;
     }
 
     /**
@@ -48,4 +56,25 @@ public class LotteryController {
         return activityItemService.getActivityItems(activityCode);
     }
 
+    /**
+     * 获取当前等级奖品
+     * @param activityCode 活动编号
+     * @param itemCode 等级编号
+     * @return
+     */
+    @RequestMapping(value = "/user/prizes", method = RequestMethod.GET, produces = "application/json")
+    public ResultMap getPrizesByUser(String activityCode, String itemCode) {
+        return prizeService.getPrizesByUser(activityCode, itemCode);
+    }
+
+    /**
+     * 获取获奖记录
+     * @param activityCode 活动编号
+     * @param size 条数
+     * @return
+     */
+    @RequestMapping(value = "/user/winninghistories", method = RequestMethod.GET, produces = "application/json")
+    public ResultMap getWinningHistories(String activityCode, Integer size) {
+        return winningHistoryService.getWinningHistories(activityCode, size);
+    }
 }

+ 19 - 0
src/main/java/com/uas/platform/b2c/common/lottery/service/PrizeService.java

@@ -0,0 +1,19 @@
+package com.uas.platform.b2c.common.lottery.service;
+
+import com.uas.platform.b2c.trade.support.ResultMap;
+
+/**
+ * Created by wangyc on 2018/9/12.
+ *
+ * @version 2018/9/12 17:34 wangyc
+ */
+public interface PrizeService {
+
+    /**
+     * 获取当前等级奖品
+     * @param activityCode 活动编号
+     * @param itemCode 等级编号
+     * @return
+     */
+    ResultMap getPrizesByUser(String activityCode, String itemCode);
+}

+ 3 - 3
src/main/java/com/uas/platform/b2c/common/lottery/service/impl/ActivityItemServiceImpl.java

@@ -22,8 +22,8 @@ import org.springframework.util.StringUtils;
 @Service
 public class ActivityItemServiceImpl implements ActivityItemService {
 
-    // 获取单个用户信息路径
-    private static final String GET_USER_URL = "/activityItem/user";
+    // 获取单个用户等级信息路径
+    private static final String GET_ITEMS_USER_URL = "/activityItem/user";
 
     private final SysConf sysConf;
 
@@ -44,7 +44,7 @@ public class ActivityItemServiceImpl implements ActivityItemService {
         params.put("activityCode", activityCode);
 
         try {
-            Response response = HttpUtil.sendGetRequest(sysConf.getLottery() + GET_USER_URL, params);
+            Response response = HttpUtil.sendGetRequest(sysConf.getLottery() + GET_ITEMS_USER_URL, params);
             return JSON.parseObject(response.getResponseText(), ResultMap.class);
         } catch (Exception e) {
             return new ResultMap(CodeType.ERROR_STATE, "获取等级信息错误,请重试");

+ 54 - 0
src/main/java/com/uas/platform/b2c/common/lottery/service/impl/PrizeServiceImpl.java

@@ -0,0 +1,54 @@
+package com.uas.platform.b2c.common.lottery.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.uas.platform.b2c.common.lottery.service.PrizeService;
+import com.uas.platform.b2c.core.config.SysConf;
+import com.uas.platform.b2c.core.support.SystemSession;
+import com.uas.platform.b2c.trade.support.CodeType;
+import com.uas.platform.b2c.trade.support.ResultMap;
+import com.uas.platform.core.util.HttpUtil;
+import com.uas.platform.core.util.HttpUtil.Response;
+import java.util.HashMap;
+import java.util.Map;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+/**
+ * Created by wangyc on 2018/9/12.
+ *
+ * @version 2018/9/12 17:36 wangyc
+ */
+@Service
+public class PrizeServiceImpl implements PrizeService {
+
+    private final SysConf sysConf;
+
+    // 获取当前等级奖品路径
+    private static final String GET_PRIZES_USER_URL = "/prizes/user";
+
+    @Autowired
+    public PrizeServiceImpl(SysConf sysConf) {
+        this.sysConf = sysConf;
+    }
+
+    @Override
+    public ResultMap getPrizesByUser(String activityCode, String itemCode) {
+        if (StringUtils.isEmpty(activityCode)) {
+            return new ResultMap(CodeType.PARAMETER_ERROR, "活动信息不完全,请确认活动信息");
+        }
+
+        Map<String, Object> params = new HashMap<>();
+        params.put("useruu", SystemSession.getUser().getUserUU());
+        params.put("enuu", SystemSession.getUser().getEnterprise() == null ? 0 : SystemSession.getUser().getEnterprise().getUu());
+        params.put("activityCode", activityCode);
+        params.put("itemCode", itemCode == null ? "" : itemCode);
+
+        try {
+            Response response = HttpUtil.sendGetRequest(sysConf.getLottery() + GET_PRIZES_USER_URL, params);
+            return JSON.parseObject(response.getResponseText(), ResultMap.class);
+        } catch (Exception e) {
+            return new ResultMap(CodeType.ERROR_STATE, "获取奖品信息错误,请重试");
+        }
+    }
+}