Browse Source

Merge remote-tracking branch 'origin/release-201827-wangcz' into release-201827-wangcz

yujia 7 years ago
parent
commit
292abcd6c1

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

@@ -1,11 +1,15 @@
 package com.uas.platform.b2c.common.lottery.controller;
 
+import com.alibaba.fastjson.JSONObject;
 import com.uas.platform.b2c.common.lottery.service.ActivityItemService;
+import com.uas.platform.b2c.common.lottery.service.LotteryService;
 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.common.search.util.PageParams;
 import com.uas.platform.b2c.trade.support.ResultMap;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
@@ -28,12 +32,15 @@ public class LotteryController {
 
     private final WinningHistoryService winningHistoryService;
 
+    private final LotteryService lotteryService;
+
     @Autowired
-    public LotteryController(UserInfoService userInfoService, ActivityItemService activityItemService, PrizeService prizeService, WinningHistoryService winningHistoryService) {
+    public LotteryController(UserInfoService userInfoService, ActivityItemService activityItemService, PrizeService prizeService, WinningHistoryService winningHistoryService, LotteryService lotteryService) {
         this.userInfoService = userInfoService;
         this.activityItemService = activityItemService;
         this.prizeService = prizeService;
         this.winningHistoryService = winningHistoryService;
+        this.lotteryService = lotteryService;
     }
 
     /**
@@ -77,4 +84,26 @@ public class LotteryController {
     public ResultMap getWinningHistories(String activityCode, Integer size) {
         return winningHistoryService.getWinningHistories(activityCode, size);
     }
+
+    /**
+     * 分页获取个人中奖记录
+     * @param activityCode 活动编码
+     * @param pageParams 分页参数
+     * @return
+     */
+    @RequestMapping(value = "/user/winninghistories/one", method = RequestMethod.GET, produces = "application/json")
+    public JSONObject getWinningHistoriesByUser(String activityCode, PageParams pageParams) {
+        return winningHistoryService.getWinningHistoriesByUser(activityCode, pageParams);
+    }
+
+    /**
+     * 用户抽奖
+     * @param activityCode 活动编号
+     * @param itemCode 等级编号
+     * @return
+     */
+    @RequestMapping(value = "/user/draw", method = RequestMethod.GET, produces = "application/json")
+    public ResultMap drawLottery(String activityCode, String itemCode) {
+        return lotteryService.drawLottery(activityCode, itemCode);
+    }
 }

+ 19 - 0
src/main/java/com/uas/platform/b2c/common/lottery/service/LotteryService.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/13.
+ *
+ * @version 2018/9/13 17:14 wangyc
+ */
+public interface LotteryService {
+
+    /**
+     * 用户抽奖
+     * @param activityCode 活动编号
+     * @param itemCode 等级编号
+     * @return
+     */
+    ResultMap drawLottery(String activityCode, String itemCode);
+}

+ 11 - 0
src/main/java/com/uas/platform/b2c/common/lottery/service/WinningHistoryService.java

@@ -1,6 +1,9 @@
 package com.uas.platform.b2c.common.lottery.service;
 
+import com.alibaba.fastjson.JSONObject;
+import com.uas.platform.b2c.common.search.util.PageParams;
 import com.uas.platform.b2c.trade.support.ResultMap;
+import org.springframework.data.domain.Page;
 
 /**
  * Created by wangyc on 2018/9/12.
@@ -16,4 +19,12 @@ public interface WinningHistoryService {
      * @return
      */
     ResultMap getWinningHistories(String activityCode, Integer size);
+
+    /**
+     * 分页获取个人中奖记录
+     * @param activityCode 活动编码
+     * @param pageParams 分页参数
+     * @return
+     */
+    JSONObject getWinningHistoriesByUser(String activityCode, PageParams pageParams);
 }

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

@@ -0,0 +1,55 @@
+package com.uas.platform.b2c.common.lottery.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.uas.platform.b2c.common.lottery.service.LotteryService;
+import com.uas.platform.b2c.core.config.SysConf;
+import com.uas.platform.b2c.core.support.SystemSession;
+import com.uas.platform.b2c.trade.support.ResultMap;
+import com.uas.platform.core.util.HttpUtil;
+import com.uas.platform.core.util.HttpUtil.Response;
+import com.uas.ps.core.page.exception.IllegalOperatorException;
+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/13.
+ *
+ * @version 2018/9/13 17:15 wangyc
+ */
+@Service
+public class LotteryServiceImpl implements LotteryService {
+
+    private final SysConf sysConf;
+
+    private static final String DRAW_PERSONAL_URL = "/lottery/draw";
+
+    @Autowired
+    public LotteryServiceImpl(SysConf sysConf) {
+        this.sysConf = sysConf;
+    }
+
+    @Override
+    public ResultMap drawLottery(String activityCode, String itemCode) {
+        if (StringUtils.isEmpty(activityCode)) {
+            throw new IllegalOperatorException("活动信息不完全,请确认活动信息");
+        }
+
+        Map<String, Object> params = new HashMap<>();
+        params.put("activityCode", activityCode);
+        params.put("itemCode", itemCode);
+        params.put("useruu", SystemSession.getUser().getUserUU());
+        params.put("enuu", SystemSession.getUser().getEnterprise() == null ? 0 : SystemSession.getUser().getEnterprise().getUu());
+
+        try {
+            Response response = HttpUtil
+                .sendGetRequest(sysConf.getLottery() + DRAW_PERSONAL_URL, params);
+            return JSON.parseObject(response.getResponseText(), ResultMap.class);
+        } catch (Exception e) {
+            throw new IllegalOperatorException("获取中奖信息错误,请重试");
+        }
+    }
+}

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

@@ -42,7 +42,7 @@ public class PrizeServiceImpl implements PrizeService {
         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);
+        params.put("itemCode", StringUtils.isEmpty(itemCode) ? "" : itemCode);
 
         try {
             Response response = HttpUtil.sendGetRequest(sysConf.getLottery() + GET_PRIZES_USER_URL, params);

+ 29 - 1
src/main/java/com/uas/platform/b2c/common/lottery/service/impl/WinningHistoryServiceImpl.java

@@ -1,15 +1,20 @@
 package com.uas.platform.b2c.common.lottery.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.uas.platform.b2c.common.lottery.service.WinningHistoryService;
+import com.uas.platform.b2c.common.search.util.PageParams;
 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 com.uas.ps.core.page.exception.IllegalOperatorException;
 import java.util.HashMap;
 import java.util.Map;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
@@ -23,9 +28,12 @@ public class WinningHistoryServiceImpl implements WinningHistoryService {
 
     private final SysConf sysConf;
 
-    // 获取当前等级奖品路径
+    // 获取最近中奖记录路径
     private static final String GET_WINNING_HOSTORIES_TOP_URL = "/winninghistorys/top";
 
+    // 获取个人中奖记录路径
+    private static final String GET_WINNING_HOSTORIES_PERSONAL_URL = "/winninghistorys/user";
+
     @Autowired
     public WinningHistoryServiceImpl(SysConf sysConf) {
         this.sysConf = sysConf;
@@ -48,4 +56,24 @@ public class WinningHistoryServiceImpl implements WinningHistoryService {
             return new ResultMap(CodeType.ERROR_STATE, "获取中奖信息错误,请重试");
         }
     }
+
+    @Override
+    public JSONObject getWinningHistoriesByUser(String activityCode, PageParams pageParams) {
+        if (StringUtils.isEmpty(activityCode)) {
+            throw new IllegalOperatorException("活动信息不完全,请确认活动信息");
+        }
+
+        Map<String, Object> params = new HashMap<>();
+        params.put("activityCode", activityCode);
+        params.put("useruu", SystemSession.getUser().getUserUU());
+        params.put("enuu", SystemSession.getUser().getEnterprise() == null ? 0 : SystemSession.getUser().getEnterprise().getUu());
+        params.put("pageParams", pageParams);
+
+        try {
+            Response response = HttpUtil.sendGetRequest(sysConf.getLottery() + GET_WINNING_HOSTORIES_PERSONAL_URL, params);
+            return JSON.parseObject(response.getResponseText(), JSONObject.class);
+        } catch (Exception e) {
+            throw new IllegalOperatorException("获取中奖信息错误,请重试");
+        }
+    }
 }