瀏覽代碼

三周年抽奖活动后台抽奖页面功能
1.抽奖页面活动功能,如抽奖,显示中奖人员
2.抽奖页面加载数据问题

yanliming 23 小時之前
父節點
當前提交
c45ec78afc

+ 3 - 0
common/src/main/java/com/jpsoft/lotteryActivity/modules/base/dao/WinningInfoDAO.java

@@ -1,6 +1,8 @@
 package com.jpsoft.lotteryActivity.modules.base.dao;
 
 import java.util.List;
+
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 import com.jpsoft.lotteryActivity.modules.base.entity.WinningInfo;
 import java.util.Map;
@@ -14,6 +16,7 @@ public interface WinningInfoDAO {
 	WinningInfo get(String id);
 	int delete(String id);
 	List<WinningInfo> list();
+	List<WinningInfo> findByActivityIdAndAwardId(@Param("activityId") String activityId,@Param("awardId") String awardId);
 	List<String> findPersonPhone();
 	List<WinningInfo> search(Map<String, Object> searchParams, List<Sort> sortList);
 }

+ 1 - 0
common/src/main/java/com/jpsoft/lotteryActivity/modules/base/service/LotteryPersonnelInfoService.java

@@ -13,5 +13,6 @@ public interface LotteryPersonnelInfoService {
 	int update(LotteryPersonnelInfo model);
 	int delete(String id);
 	List<LotteryPersonnelInfo> list();
+	List<LotteryPersonnelInfo> findByActivityId(String activityId);
 	Page<LotteryPersonnelInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, boolean count, List<Sort> sortList);
 }

+ 1 - 0
common/src/main/java/com/jpsoft/lotteryActivity/modules/base/service/WinningInfoService.java

@@ -14,5 +14,6 @@ public interface WinningInfoService {
 	int delete(String id);
 	List<WinningInfo> startLottery(String activityId,String awardId);
 	List<WinningInfo> list();
+	List<WinningInfo> findByActivityIdAndAwardId(String activityId,String awardId);
 	Page<WinningInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, boolean count, List<Sort> sortList);
 }

+ 6 - 0
common/src/main/java/com/jpsoft/lotteryActivity/modules/base/service/impl/LotteryPersonnelInfoServiceImpl.java

@@ -58,6 +58,12 @@ public class LotteryPersonnelInfoServiceImpl implements LotteryPersonnelInfoServ
 		// TODO Auto-generated method stub
 		return lotteryPersonnelInfoDAO.list();
 	}
+
+
+	@Override
+	public List<LotteryPersonnelInfo> findByActivityId(String activityId){
+		return lotteryPersonnelInfoDAO.findByActivityId(activityId);
+	}
 		
 	@Override
 	public Page<LotteryPersonnelInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {

+ 16 - 1
common/src/main/java/com/jpsoft/lotteryActivity/modules/base/service/impl/WinningInfoServiceImpl.java

@@ -74,10 +74,20 @@ public class WinningInfoServiceImpl implements WinningInfoService {
             lotteryPersonnelInfoList.removeIf(lotteryPersonnelInfo -> lotteryPersonnelInfo.getPhone().equals(phone));
         }
 
-
         //中奖人员名单
         List<WinningInfo> winningInfoList = lotteryFunction(activityId, awardId, lotteryPersonnelInfoList, awardNumber);
 
+
+        //保存中奖人员到数据库
+        for (WinningInfo winningInfo:winningInfoList) {
+            winningInfo.setId(UUID.randomUUID().toString());
+            winningInfo.setDelFlag(false);
+            winningInfo.setCreateTime(new Date());
+            winningInfo.setAwardId(awardId);
+            winningInfo.setActivityId(activityId);
+            winningInfoDAO.insert(winningInfo);
+        }
+
         return winningInfoList;
     }
 
@@ -137,6 +147,11 @@ public class WinningInfoServiceImpl implements WinningInfoService {
         return winningInfoDAO.list();
     }
 
+    @Override
+    public List<WinningInfo> findByActivityIdAndAwardId(String activityId,String awardId){
+        return winningInfoDAO.findByActivityIdAndAwardId(activityId,awardId);
+    }
+
     @Override
     public Page<WinningInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize, boolean count, List<Sort> sortList) {
         Page<WinningInfo> page = PageHelper.startPage(pageNumber, pageSize, count).doSelectPage(() -> {

+ 7 - 0
common/src/main/resources/mapper/base/WinningInfo.xml

@@ -80,6 +80,13 @@ id_,lottery_personnel_id,award_id,activity_id,create_by,create_time,update_by,up
 	<select id="list" resultMap="WinningInfoMap">
 		select * from base_winning_info
 	</select>
+	<select id="findByActivityIdAndAwardId" resultMap="WinningInfoMap">
+		select * from base_winning_info
+		where
+		del_flag=false
+		and activity_id = #{activityId}
+		and award_id = #{awardId}
+	</select>
 	<select id="findPersonPhone" resultType="java.lang.String">
 		SELECT b.phone_ as 'phone' FROM base_winning_info a
 		INNER JOIN base_lottery_personnel_info b on a.lottery_personnel_id=b.id_

+ 205 - 11
server/src/main/java/com/jpsoft/lotteryActivity/modules/business/controller/StartLotteryController.java

@@ -3,19 +3,25 @@ package com.jpsoft.lotteryActivity.modules.business.controller;
 
 import com.jpsoft.lotteryActivity.modules.base.entity.ActivityInfo;
 import com.jpsoft.lotteryActivity.modules.base.entity.AwardInfo;
+import com.jpsoft.lotteryActivity.modules.base.entity.LotteryPersonnelInfo;
+import com.jpsoft.lotteryActivity.modules.base.entity.WinningInfo;
 import com.jpsoft.lotteryActivity.modules.base.service.ActivityInfoService;
 import com.jpsoft.lotteryActivity.modules.base.service.AwardInfoService;
+import com.jpsoft.lotteryActivity.modules.base.service.LotteryPersonnelInfoService;
+import com.jpsoft.lotteryActivity.modules.base.service.WinningInfoService;
 import com.jpsoft.lotteryActivity.modules.common.dto.MessageResult;
+import com.jpsoft.lotteryActivity.utils.StringUtils;
 import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @RestController
 @RequestMapping("/business/startLottery")
@@ -28,9 +34,15 @@ public class StartLotteryController {
     @Autowired
     private AwardInfoService awardInfoService;
 
-    @ApiOperation(value="列表")
-    @RequestMapping(value = "list",method = RequestMethod.POST)
-    public MessageResult<List<ActivityInfo>> list(){
+    @Autowired
+    private WinningInfoService winningInfoService;
+
+    @Autowired
+    private LotteryPersonnelInfoService lotteryPersonnelInfoService;
+
+    @ApiOperation(value = "列表")
+    @RequestMapping(value = "list", method = RequestMethod.POST)
+    public MessageResult<List<ActivityInfo>> list() {
         MessageResult<List<ActivityInfo>> msgResult = new MessageResult<>();
 
         List<ActivityInfo> activityInfoList = activityInfoService.list();
@@ -42,11 +54,10 @@ public class StartLotteryController {
     }
 
 
-
-    @ApiOperation(value="列表")
-    @RequestMapping(value = "findByActivityId",method = RequestMethod.POST)
-    public MessageResult<List<AwardInfo>> findByActivityId(String activityId, HttpServletRequest request){
-        String subject = (String)request.getAttribute("subject");
+    @ApiOperation(value = "列表")
+    @RequestMapping(value = "findByActivityId", method = RequestMethod.POST)
+    public MessageResult<List<AwardInfo>> findByActivityId(String activityId, HttpServletRequest request) {
+        String subject = (String) request.getAttribute("subject");
 
         //当前用户ID
         System.out.println(subject);
@@ -60,4 +71,187 @@ public class StartLotteryController {
 
         return msgResult;
     }
+
+
+    @ApiOperation(value = "获取获奖人员列表")
+    @RequestMapping(value = "findWinningByActivityId", method = RequestMethod.POST)
+    public MessageResult<List<Map>> findWinningByActivityId(String activityId, HttpServletRequest request) {
+        String subject = (String) request.getAttribute("subject");
+
+        //当前用户ID
+        System.out.println(subject);
+
+        MessageResult<List<Map>> msgResult = new MessageResult<>();
+
+        List<AwardInfo> awardInfoList = awardInfoService.findByActivityId(activityId);
+
+        List<Map> mapList = new ArrayList<>();
+
+
+        for (AwardInfo awardInfo : awardInfoList) {
+            Map map = new HashMap();
+            List<WinningInfo> winningInfoList = winningInfoService.findByActivityIdAndAwardId(activityId, awardInfo.getId());
+
+            for (WinningInfo winningInfo : winningInfoList) {
+                LotteryPersonnelInfo lotteryPersonnelInfo = lotteryPersonnelInfoService.get(winningInfo.getLotteryPersonnelId());
+                if (lotteryPersonnelInfo != null) {
+                    String phone = "";
+                    if (StringUtils.isNoneEmpty(lotteryPersonnelInfo.getPhone())) {
+                        phone = desensitizePhone(lotteryPersonnelInfo.getPhone());
+                    }
+                    winningInfo.setLotteryPersonnelPhone(phone);
+                    winningInfo.setLotteryPersonnelImage(lotteryPersonnelInfo.getImage());
+                }
+            }
+
+            map.put("name", awardInfo.getName());
+            map.put("num", winningInfoList.size());
+            map.put("winningInfoList", winningInfoList);
+
+            mapList.add(map);
+        }
+
+        msgResult.setResult(true);
+        msgResult.setData(mapList);
+
+        return msgResult;
+    }
+
+
+    @ApiOperation(value = "参与抽奖人员列表")
+    @RequestMapping(value = "lotteryPersonnelList", method = RequestMethod.POST)
+    public MessageResult<List<LotteryPersonnelInfo>> lotteryPersonnelList(String activityId, HttpServletRequest request) {
+        String subject = (String) request.getAttribute("subject");
+
+        //当前用户ID
+        System.out.println(subject);
+
+        MessageResult<List<LotteryPersonnelInfo>> msgResult = new MessageResult<>();
+
+        List<LotteryPersonnelInfo> lotteryPersonnelInfoList = lotteryPersonnelInfoService.findByActivityId(activityId);
+
+        for (LotteryPersonnelInfo lotteryPersonnelInfo : lotteryPersonnelInfoList) {
+
+            String phone = "";
+            if (StringUtils.isNoneEmpty(lotteryPersonnelInfo.getPhone())) {
+                phone = desensitizePhone(lotteryPersonnelInfo.getPhone());
+            }
+            lotteryPersonnelInfo.setPhone(phone);
+        }
+
+        msgResult.setResult(true);
+        msgResult.setData(lotteryPersonnelInfoList);
+
+        return msgResult;
+    }
+
+
+    @ApiOperation(value="获取信息")
+    @GetMapping("edit/{id}")
+    public MessageResult<AwardInfo> edit(@PathVariable("id") String id){
+        MessageResult<AwardInfo> msgResult = new MessageResult<>();
+
+        try {
+            AwardInfo awardInfo = awardInfoService.get(id);
+
+            if (awardInfo != null) {
+                ActivityInfo activityInfo = activityInfoService.get(awardInfo.getActivityId());
+                if(activityInfo!=null){
+                    awardInfo.setActivityName(activityInfo.getName());
+                }
+                msgResult.setResult(true);
+                msgResult.setData(awardInfo);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库不存在该记录!");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+
+
+    @ApiOperation(value = "开始抽奖")
+    @PostMapping("startLotteryAward")
+    public MessageResult<List<Map>> startLotteryAward(String activityId,String awardId) {
+        MessageResult<List<Map>> msgResult = new MessageResult<>();
+
+        try {
+
+            List<WinningInfo> winningInfoList = winningInfoService.startLottery(activityId,awardId);
+
+            List<Map> mapList = new ArrayList<>();
+
+            for (WinningInfo winningInfo : winningInfoList) {
+                Map map = new HashMap();
+
+                String activityName = "";
+                String phone = "";
+                String lotteryPersonnelNickName = "";
+                String lotteryPersonnelImage = "";
+                String awardName = "";
+                String awardPrizeName = "";
+
+                ActivityInfo activityInfo = activityInfoService.get(winningInfo.getActivityId());
+                if (activityInfo != null) {
+                    activityName = activityInfo.getName();
+                }
+
+                map.put("activityName", activityName);
+
+                LotteryPersonnelInfo lotteryPersonnelInfo = lotteryPersonnelInfoService.get(winningInfo.getLotteryPersonnelId());
+
+                if (lotteryPersonnelInfo != null) {
+                    phone = desensitizePhone(lotteryPersonnelInfo.getPhone());
+                    lotteryPersonnelNickName = lotteryPersonnelInfo.getNickName();
+                    lotteryPersonnelImage = lotteryPersonnelInfo.getImage();
+                }
+
+                map.put("lotteryPersonnelPhone", phone);
+                map.put("lotteryPersonnelNickName", lotteryPersonnelNickName);
+                map.put("lotteryPersonnelImage", lotteryPersonnelImage);
+
+                AwardInfo awardInfo = awardInfoService.get(winningInfo.getAwardId());
+
+                if (awardInfo != null) {
+                    awardName = awardInfo.getName();
+                    awardPrizeName = awardInfo.getPrizeName();
+                }
+
+                map.put("awardName", awardName);
+                map.put("awardPrizeName", awardPrizeName);
+                map.put("lotteryPersonnelId", winningInfo.getLotteryPersonnelId());
+
+                mapList.add(map);
+            }
+
+            msgResult.setResult(true);
+            msgResult.setData(mapList);
+
+        } catch (Exception ex) {
+            logger.error(ex.getMessage(), ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+
+    private String desensitizePhone(String phone) {
+        if (phone == null || phone.length() != 11) {
+            return phone; // 非11位手机号不处理
+        }
+        // 使用正则表达式替换中间4位
+        return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
+    }
+
 }