goods20 преди 5 месеца
родител
ревизия
6457164583

+ 12 - 0
ruoyi-common/src/main/java/com/ruoyi/common/enums/LotteryTypeEnum.java

@@ -11,6 +11,7 @@ public enum LotteryTypeEnum {
 
     private Integer code;
     private String desc;
+
     LotteryTypeEnum(Integer code, String desc) {
         this.code = code;
         this.desc = desc;
@@ -23,4 +24,15 @@ public enum LotteryTypeEnum {
     public String getDesc() {
         return desc;
     }
+
+    public static LotteryTypeEnum match(int code) {
+        LotteryTypeEnum result = null;
+        for (LotteryTypeEnum s : values()) {
+            if (s.getCode() == code) {
+                result = s;
+                break;
+            }
+        }
+        return result;
+    }
 }

+ 1 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -112,6 +112,7 @@ public class SecurityConfig {
                             // 静态资源,可匿名访问
                             .requestMatchers(HttpMethod.GET, "/", "/*.html", "/**.html", "/**.css", "/**.js", "/profile/**").permitAll()
                             .requestMatchers("/swagger-ui.html", "/v3/api-docs/**", "/swagger-ui/**", "/druid/**").permitAll()
+                            .requestMatchers("/wx/**").anonymous()
                             // 除上面外的所有请求全部需要鉴权认证
                             .anyRequest().authenticated();
                 })

+ 50 - 44
ruoyi-framework/src/main/java/com/ruoyi/framework/recovery/domain/WxLottery.java

@@ -17,110 +17,116 @@ public class WxLottery extends BaseEntity
 {
     private static final long serialVersionUID = 1L;
 
-    /** 抽奖id */
+    /**
+     * 抽奖id
+     */
     private Long id;
 
-    /** 抽奖内容 */
+    /**
+     * 抽奖内容
+     */
     @Excel(name = "抽奖内容")
     private String lotteryDesc;
 
-    /** 奖品数量 */
+    /**
+     * 奖品数量
+     */
     @Excel(name = "奖品数量")
     private Long lotteryNum;
 
-    /** 抽奖图片 */
+    /**
+     * 抽奖图片
+     */
     @Excel(name = "抽奖图片")
     private String lotteryImage;
 
-    /** 开奖时间 */
+    /**
+     * 开奖时间
+     */
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @Excel(name = "开奖时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
     private Date lotteryTime;
 
-    /** 创建时间 */
+    /**
+     * 创建时间
+     */
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
     private Date createDate;
 
-    /** 更新时间 */
+    /**
+     * 更新时间
+     */
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
     private Date updateDate;
 
-    public void setId(Long id) 
-    {
+    public void setId(Long id) {
         this.id = id;
     }
 
-    public Long getId() 
-    {
+    public Long getId() {
         return id;
     }
-    public void setLotteryDesc(String lotteryDesc) 
-    {
+
+    public void setLotteryDesc(String lotteryDesc) {
         this.lotteryDesc = lotteryDesc;
     }
 
-    public String getLotteryDesc() 
-    {
+    public String getLotteryDesc() {
         return lotteryDesc;
     }
-    public void setLotteryNum(Long lotteryNum) 
-    {
+
+    public void setLotteryNum(Long lotteryNum) {
         this.lotteryNum = lotteryNum;
     }
 
-    public Long getLotteryNum() 
-    {
+    public Long getLotteryNum() {
         return lotteryNum;
     }
-    public void setLotteryImage(String lotteryImage) 
-    {
+
+    public void setLotteryImage(String lotteryImage) {
         this.lotteryImage = lotteryImage;
     }
 
-    public String getLotteryImage() 
-    {
+    public String getLotteryImage() {
         return lotteryImage;
     }
-    public void setLotteryTime(Date lotteryTime) 
-    {
+
+    public void setLotteryTime(Date lotteryTime) {
         this.lotteryTime = lotteryTime;
     }
 
-    public Date getLotteryTime() 
-    {
+    public Date getLotteryTime() {
         return lotteryTime;
     }
-    public void setCreateDate(Date createDate) 
-    {
+
+    public void setCreateDate(Date createDate) {
         this.createDate = createDate;
     }
 
-    public Date getCreateDate() 
-    {
+    public Date getCreateDate() {
         return createDate;
     }
-    public void setUpdateDate(Date updateDate) 
-    {
+
+    public void setUpdateDate(Date updateDate) {
         this.updateDate = updateDate;
     }
 
-    public Date getUpdateDate() 
-    {
+    public Date getUpdateDate() {
         return updateDate;
     }
 
     @Override
     public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("id", getId())
-            .append("lotteryDesc", getLotteryDesc())
-            .append("lotteryNum", getLotteryNum())
-            .append("lotteryImage", getLotteryImage())
-            .append("lotteryTime", getLotteryTime())
-            .append("createDate", getCreateDate())
-            .append("updateDate", getUpdateDate())
-            .toString();
+        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+                .append("id", getId())
+                .append("lotteryDesc", getLotteryDesc())
+                .append("lotteryNum", getLotteryNum())
+                .append("lotteryImage", getLotteryImage())
+                .append("lotteryTime", getLotteryTime())
+                .append("createDate", getCreateDate())
+                .append("updateDate", getUpdateDate())
+                .toString();
     }
 }

+ 6 - 6
ruoyi-framework/src/main/java/com/ruoyi/framework/recovery/domain/WxUserLottery.java

@@ -26,7 +26,7 @@ public class WxUserLottery extends BaseEntity
 
     /** 抽奖编号 */
     @Excel(name = "抽奖编号")
-    private String lotteryNum;
+    private String lotteryCode;
 
     /** 用户编号 */
     @Excel(name = "用户编号")
@@ -68,14 +68,14 @@ public class WxUserLottery extends BaseEntity
     {
         return lotteryId;
     }
-    public void setLotteryNum(String lotteryNum) 
+    public void setLotteryCode(String lotteryCode)
     {
-        this.lotteryNum = lotteryNum;
+        this.lotteryCode = lotteryCode;
     }
 
-    public String getLotteryNum() 
+    public String getLotteryCode()
     {
-        return lotteryNum;
+        return lotteryCode;
     }
     public void setOpenId(String openId)
     {
@@ -127,7 +127,7 @@ public class WxUserLottery extends BaseEntity
         return "WxUserLottery{" +
                 "id=" + id +
                 ", lotteryId=" + lotteryId +
-                ", lotteryNum='" + lotteryNum + '\'' +
+                ", lotteryNum='" + lotteryCode + '\'' +
                 ", userId=" + openId +
                 ", mark='" + mark + '\'' +
                 ", lotteryType='" + lotteryType + '\'' +

+ 11 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/recovery/mapper/WxLotteryMapper.java

@@ -1,7 +1,9 @@
 package com.ruoyi.framework.recovery.mapper;
 
+import java.util.Date;
 import java.util.List;
 import com.ruoyi.framework.recovery.domain.WxLottery;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 微信抽奖Mapper接口
@@ -58,4 +60,13 @@ public interface WxLotteryMapper
      * @return 结果
      */
     public int deleteWxLotteryByIds(Long[] ids);
+
+    /**
+     * 查询抽奖截止时间之前的内容
+     *
+     * @param date 截止时间之前
+     * @param type 类型
+     * @return 结果集
+     */
+    List<WxLottery> selectWxLotteryListByTime(@Param("date") Date date, @Param("type") String type);
 }

+ 17 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/recovery/mapper/WxUserLotteryMapper.java

@@ -2,6 +2,7 @@ package com.ruoyi.framework.recovery.mapper;
 
 import java.util.List;
 import com.ruoyi.framework.recovery.domain.WxUserLottery;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 微信中奖记录Mapper接口
@@ -58,4 +59,20 @@ public interface WxUserLotteryMapper
      * @return 结果
      */
     public int deleteWxUserLotteryByIds(Long[] ids);
+
+    /**
+     * 根据微信openid查询奖品内容
+     *
+     * @param openId 入参
+     * @return 结果集
+     */
+    List<WxUserLottery> selectWxUserLotteryListByOpenId(String openId);
+
+    /**
+     * 根据奖品id查询所有获奖记录
+     *
+     * @param id 奖品id
+     * @return 获奖记录
+     */
+    List<Long> selectLotteryCodesByLotteryId(@Param("id") Long id);
 }

+ 12 - 0
ruoyi-system/src/main/resources/mapper/system/WxLotteryMapper.xml

@@ -78,4 +78,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
+
+    <select id="selectWxLotteryListByTime" resultMap="WxLotteryResult">
+        <include refid="selectWxLotteryVo"/>
+        <where>
+            <if test="type != null and type != '' and type == 'now'">
+                lottery_time >= #{date,jdbcType=TIMESTAMP}
+            </if>
+            <if test="type != null and type != '' and type == 'history'">
+                lottery_time &lt;= #{date,jdbcType=TIMESTAMP}
+            </if>
+        </where>
+    </select>
 </mapper>

+ 8 - 0
ruoyi-system/src/main/resources/mapper/system/WxUserLotteryMapper.xml

@@ -83,4 +83,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
+
+    <select id="selectWxUserLotteryListByOpenId" resultType="com.ruoyi.framework.recovery.domain.WxUserLottery">
+
+    </select>
+
+    <select id="selectLotteryCodesByLotteryId" resultType="java.lang.Long">
+        select lottery_num from wx_user_lottery where lottery_id = #{id} and mark = 1
+    </select>
 </mapper>

+ 23 - 3
ruoyi-wx/src/main/java/com/ruoyi/wx/web/controller/WxLotteryUserController.java

@@ -1,13 +1,17 @@
 package com.ruoyi.wx.web.controller;
 
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.framework.recovery.domain.WxLottery;
 import com.ruoyi.wx.web.domain.dto.LotteryDto;
+import com.ruoyi.wx.web.domain.vo.AwardVo;
 import com.ruoyi.wx.web.domain.vo.LotteryVo;
 import com.ruoyi.wx.web.service.IWxLotteryUserService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
+
 /**
  *
  * 微信抽奖中心
@@ -20,15 +24,31 @@ public class WxLotteryUserController {
     @Autowired
     private IWxLotteryUserService wxLotteryUserService;
 
+    /**
+     * 获取全量抽奖详情
+     *
+     * @param type 查询历史或者当前内容,now:查询当前抽奖,history:查询历史抽奖
+     * @return 结果集
+     */
+    @GetMapping("/info/list")
+    public AjaxResult getLotteryUserList(String type) {
+        try {
+            List<AwardVo> lotteryVo = wxLotteryUserService.getList(type);
+            return AjaxResult.success(lotteryVo);
+        } catch (SecurityException e) {
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+
     /**
      *
      * 获取当前人的抽奖内容
      * @return
      */
-    @GetMapping("/info/list")
-    public AjaxResult getIndex() {
+    @GetMapping("/info/list/{lotteryId}")
+    public AjaxResult getIndex(@PathVariable("lotteryId") Long lotteryId) {
         try {
-            LotteryVo lotteryVo = wxLotteryUserService.getList();
+            List<LotteryVo> lotteryVo = wxLotteryUserService.getListById(lotteryId);
             return AjaxResult.success(lotteryVo);
         } catch (SecurityException e) {
             return AjaxResult.error(e.getMessage());

+ 118 - 0
ruoyi-wx/src/main/java/com/ruoyi/wx/web/domain/vo/AwardVo.java

@@ -0,0 +1,118 @@
+package com.ruoyi.wx.web.domain.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 获奖vo
+ */
+public class AwardVo {
+    /**
+     * 抽奖内容
+     */
+    private String lotteryDesc;
+
+    /**
+     * 奖品数量
+     */
+    private Long lotteryNum;
+
+    /**
+     * 抽奖图片
+     */
+    private String lotteryImage;
+
+    /**
+     * 获奖编号
+     */
+    private List<String> lotteryCodes;
+
+    /**
+     * 开奖时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date lotteryTime;
+
+    /**
+     * 创建时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createDate;
+
+    /**
+     * 更新时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date updateDate;
+
+    public void setLotteryDesc(String lotteryDesc) {
+        this.lotteryDesc = lotteryDesc;
+    }
+
+    public String getLotteryDesc() {
+        return lotteryDesc;
+    }
+
+    public void setLotteryNum(Long lotteryNum) {
+        this.lotteryNum = lotteryNum;
+    }
+
+    public Long getLotteryNum() {
+        return lotteryNum;
+    }
+
+    public void setLotteryImage(String lotteryImage) {
+        this.lotteryImage = lotteryImage;
+    }
+
+    public String getLotteryImage() {
+        return lotteryImage;
+    }
+
+    public void setLotteryTime(Date lotteryTime) {
+        this.lotteryTime = lotteryTime;
+    }
+
+    public Date getLotteryTime() {
+        return lotteryTime;
+    }
+
+    public void setCreateDate(Date createDate) {
+        this.createDate = createDate;
+    }
+
+    public Date getCreateDate() {
+        return createDate;
+    }
+
+    public void setUpdateDate(Date updateDate) {
+        this.updateDate = updateDate;
+    }
+
+    public Date getUpdateDate() {
+        return updateDate;
+    }
+
+    public List<String> getLotteryCodes() {
+        return lotteryCodes;
+    }
+
+    public void setLotteryCodes(List<String> lotteryCodes) {
+        this.lotteryCodes = lotteryCodes;
+    }
+
+    @Override
+    public String toString() {
+        return "AwardVo{" +
+                "lotteryDesc='" + lotteryDesc + '\'' +
+                ", lotteryNum=" + lotteryNum +
+                ", lotteryImage='" + lotteryImage + '\'' +
+                ", lotteryCodes=" + lotteryCodes +
+                ", lotteryTime=" + lotteryTime +
+                ", createDate=" + createDate +
+                ", updateDate=" + updateDate +
+                '}';
+    }
+}

+ 30 - 3
ruoyi-wx/src/main/java/com/ruoyi/wx/web/domain/vo/LotteryVo.java

@@ -3,16 +3,33 @@ package com.ruoyi.wx.web.domain.vo;
 import java.util.List;
 
 public class LotteryVo {
+    /**
+     * 奖品id
+     */
+    private Long lotteryId;
     /**
      * 抽奖码
      */
     private List<String> lotteryCodes;
 
     /**
-     * 抽奖
+     * 抽奖类型
      */
     private String lotteryType;
 
+    /**
+     * 抽奖类型名称
+     */
+    private String lotteryTypeName;
+
+    public Long getLotteryId() {
+        return lotteryId;
+    }
+
+    public void setLotteryId(Long lotteryId) {
+        this.lotteryId = lotteryId;
+    }
+
     public List<String> getLotteryCodes() {
         return lotteryCodes;
     }
@@ -29,11 +46,21 @@ public class LotteryVo {
         lotteryType = lotteryNum;
     }
 
+    public String getLotteryTypeName() {
+        return lotteryTypeName;
+    }
+
+    public void setLotteryTypeName(String lotteryTypeName) {
+        this.lotteryTypeName = lotteryTypeName;
+    }
+
     @Override
     public String toString() {
         return "LotteryVo{" +
-                "LotteryCode='" + lotteryCodes + '\'' +
-                ", LotteryNum='" + lotteryType + '\'' +
+                "lotteryId=" + lotteryId +
+                ", lotteryCodes=" + lotteryCodes +
+                ", lotteryType='" + lotteryType + '\'' +
+                ", lotteryTypeName='" + lotteryTypeName + '\'' +
                 '}';
     }
 }

+ 12 - 1
ruoyi-wx/src/main/java/com/ruoyi/wx/web/service/IWxLotteryUserService.java

@@ -1,15 +1,19 @@
 package com.ruoyi.wx.web.service;
 
+import com.ruoyi.framework.recovery.domain.WxLottery;
 import com.ruoyi.wx.web.domain.dto.LotteryDto;
+import com.ruoyi.wx.web.domain.vo.AwardVo;
 import com.ruoyi.wx.web.domain.vo.LotteryVo;
 
+import java.util.List;
+
 public interface IWxLotteryUserService {
     /**
      * 获取当前人抽奖码
      *
      * @return 返回结果集
      */
-    LotteryVo getList();
+    List<LotteryVo> getListById(Long lotteryId);
 
     /**
      * 当前人员进行抽奖
@@ -18,4 +22,11 @@ public interface IWxLotteryUserService {
      * @return 结果集
      */
     LotteryVo addLottery(LotteryDto lotteryDto);
+
+    /**
+     * 获取全量抽奖内容
+     *
+     * @return 结果集
+     */
+    List<AwardVo> getList(String type);
 }

+ 68 - 13
ruoyi-wx/src/main/java/com/ruoyi/wx/web/service/impl/WxLotteryUserServiceImpl.java

@@ -1,43 +1,67 @@
 package com.ruoyi.wx.web.service.impl;
 
 import cn.hutool.core.collection.CollectionUtil;
+import com.ruoyi.common.enums.LotteryTypeEnum;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.framework.recovery.domain.WxLottery;
 import com.ruoyi.framework.recovery.domain.WxUserLottery;
+import com.ruoyi.framework.recovery.mapper.WxLotteryMapper;
 import com.ruoyi.framework.recovery.mapper.WxUserLotteryMapper;
 import com.ruoyi.wx.web.domain.dto.LotteryDto;
+import com.ruoyi.wx.web.domain.vo.AwardVo;
 import com.ruoyi.wx.web.domain.vo.LotteryVo;
 import com.ruoyi.wx.web.service.IWxLotteryUserService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 @Service
+@Slf4j
 public class WxLotteryUserServiceImpl implements IWxLotteryUserService {
+    @Autowired
+    private WxLotteryMapper wxLotteryMapper;
+
     @Autowired
     private WxUserLotteryMapper wxUserLotteryMapper;
 
     @Override
-    public LotteryVo getList() {
+    public List<LotteryVo> getListById(Long lotteryId) {
+        log.info("查询用户抽奖码入参:{}", lotteryId);
+        if (lotteryId == null) {
+            throw new ServiceException("入参不能为空");
+        }
         WxUserLottery lottery = new WxUserLottery();
         String wxOpenid = SecurityUtils.getLoginWxUser().getWxUser().getWxOpenid();
         lottery.setOpenId(wxOpenid);
+        lottery.setLotteryId(lotteryId);
         List<WxUserLottery> userLotteries = wxUserLotteryMapper.selectWxUserLotteryList(lottery);
         if (CollectionUtil.isEmpty(userLotteries)) {
-            return new LotteryVo();
-        }
-        List<String> lotteryIds = new ArrayList<>();
-        for (WxUserLottery userLottery : userLotteries) {
-            lotteryIds.add(userLottery.getLotteryNum());
+            return new ArrayList<>();
         }
-        // TODO 修改返回参数为List<LotteryVo>
-        LotteryVo result = new LotteryVo();
-        result.setLotteryCodes(lotteryIds);
-        result.setLotteryType("1");
-        return result;
+        // 根据抽奖类型分类
+        List<LotteryVo> resultList = new ArrayList<>();
+        Map<String, List<WxUserLottery>> typeMap = userLotteries.stream().collect(Collectors.groupingBy(WxUserLottery::getLotteryType));
+        typeMap.forEach((key, value) -> {
+            LotteryVo result = new LotteryVo();
+            result.setLotteryType(key);
+            result.setLotteryTypeName(LotteryTypeEnum.match(Integer.parseInt(key)).getDesc());
+            result.setLotteryId(lotteryId);
+            List<String> lotteryIds = new ArrayList<>();
+            for (WxUserLottery userLottery : value) {
+                lotteryIds.add(userLottery.getLotteryCode());
+            }
+            result.setLotteryCodes(lotteryIds);
+            resultList.add(result);
+        });
+        return resultList;
     }
 
     @Override
@@ -50,18 +74,49 @@ public class WxLotteryUserServiceImpl implements IWxLotteryUserService {
         if (total > 10) {
             throw new ServiceException("超出抽奖数量阈值");
         }
+        List<String> lotteryCodes = new ArrayList<>();
         // 构建抽奖记录
         for (int i = 0 ; i < lotteryDto.getNum() ; i++) {
             WxUserLottery info = new WxUserLottery();
             info.setOpenId(wxOpenid);
             String lotteryCode = String.valueOf(System.currentTimeMillis()).substring(7);
             lotteryCode = lotteryCode + i;
-            info.setLotteryNum(lotteryCode);
+            lotteryCodes.add(lotteryCode);
+            info.setLotteryCode(lotteryCode);
             info.setLotteryType(lotteryDto.getType());
             info.setCreateDate(new Date());
+            info.setLotteryId(lotteryDto.getLotteryId());
             wxUserLotteryMapper.insertWxUserLottery(info);
         }
+        LotteryVo lotteryVo = new LotteryVo();
+        lotteryVo.setLotteryCodes(lotteryCodes);
+        lotteryVo.setLotteryId(lotteryVo.getLotteryId());
+        lotteryVo.setLotteryType(lotteryDto.getType());
+        lotteryVo.setLotteryTypeName(LotteryTypeEnum.match(Integer.parseInt(lotteryDto.getType())).getDesc());
+        return lotteryVo;
+    }
 
-        return null;
+    @Override
+    public List<AwardVo> getList(String type) {
+        List<AwardVo> awardVos = new ArrayList<>();
+        List<WxLottery> wxLotteries = wxLotteryMapper.selectWxLotteryListByTime(new Date(), type);
+        // 查询历史获奖记录时会查到以及获奖内容
+        if ("now".equals(type)) {
+            for (WxLottery lottery : wxLotteries) {
+                AwardVo awardVo = new AwardVo();
+                BeanUtils.copyProperties(lottery, awardVo);
+                awardVos.add(awardVo);
+            }
+        } else {
+            for (WxLottery lottery : wxLotteries) {
+                AwardVo awardVo = new AwardVo();
+                List<Long> lotteryCodes = wxUserLotteryMapper.selectLotteryCodesByLotteryId(lottery.getId());
+                List<String> lotteryCodeList = lotteryCodes.stream().map(String::valueOf).toList();
+                BeanUtils.copyProperties(lottery, awardVo);
+                awardVo.setLotteryCodes(lotteryCodeList);
+                awardVos.add(awardVo);
+            }
+        }
+        return awardVos;
     }
 }