增加抽奖相关接口

This commit is contained in:
wulin 2020-08-24 09:20:20 +08:00
parent 18794604ab
commit 2608277896
20 changed files with 244 additions and 198 deletions

View File

@ -378,6 +378,7 @@ public class DingTalkUtil {
luckRecord.setStaffId(staffEntity.getId());
luckRecord.setLuckId(luckId);
luckRecord.setName(staffEntity.getName());
luckRecord.setMobile(staffEntity.getMobile());
luckRecordService.insertLuckRecord(luckRecord);
}

View File

@ -65,6 +65,8 @@ public class ShiroConfig {
filterMap.put("/dtlg/login", "anon");
filterMap.put("/dtlg/luck", "anon");
filterMap.put("/dtlg/look", "anon");
filterMap.put("/luck/getLuckById", "anon");
filterMap.put("/luck/updateLuck", "anon");
filterMap.put("/**", "oauth2");
shiroFilter.setFilterChainDefinitionMap(filterMap);

View File

@ -1,18 +1,21 @@
package com.lz.modules.luck.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lz.common.utils.PageUtils;
import com.lz.common.utils.R;
import com.lz.common.utils.StringUtil;
import com.lz.modules.luck.entity.Luck;
import com.lz.modules.luck.entity.*;
import com.lz.modules.luck.service.LuckGoodsService;
import com.lz.modules.luck.service.LuckRecordService;
import com.lz.modules.luck.service.LuckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@ -23,6 +26,12 @@ public class LuckController {
@Autowired
private LuckService luckService;
@Autowired
private LuckGoodsService luckGoodsService;
@Autowired
private LuckRecordService luckRecordService;
@RequestMapping("/list")
public R list(@RequestBody String body) {
@ -37,8 +46,111 @@ public class LuckController {
return R.ok().put("luck",luck);
}
@GetMapping("/getLuckById")
public R getLuckById(@RequestParam Long luckId) {
return getLuck(luckId);
}
@RequestMapping("/update")
private R getLuck(Long luckId){
Luck luck = luckService.selectLuckById(luckId);
if(luck != null){
LuckDetailInfoReq luckDetailInfoReq = new LuckDetailInfoReq();
if(luck.getFinish().intValue() == 0){//活动未结束
luckDetailInfoReq.setId(luckId);
luckDetailInfoReq.setName(luck.getName());
List<LuckGoods> luckGoods = luckGoodsService.getByLuckId(luckId);
if(luckGoods.size() > 0){
List<LuckGoodsReq> luckGoodsReqs = new ArrayList<>();
for (LuckGoods luckGood:luckGoods
) {
LuckGoodsReq luckGoodsReq = new LuckGoodsReq();
luckGoodsReq.setCounts(luckGood.getCounts());
luckGoodsReq.setId(luckGood.getId());
luckGoodsReq.setName(luckGood.getName());
luckGoodsReq.setWeight(luckGood.getWeight());
luckGoodsReqs.add(luckGoodsReq);
}
luckDetailInfoReq.setLuckGoodsReqs(luckGoodsReqs);
List<LuckRecord> luckRecords = luckRecordService.selectLuckRecordByLuckId(String.valueOf(luckId));
if(luckRecords.size() > 0){
List<LuckRecordReq> luckRecordReqList = new ArrayList<>();
for (LuckRecord luckRecord:luckRecords
) {
LuckRecordReq luckRecordReq = new LuckRecordReq();
luckRecordReq.setName(luckRecord.getName());
luckRecordReq.setId(luckRecord.getId());
luckRecordReq.setGoodsId(luckRecord.getGoodsId());
luckRecordReq.setGoodsName(luckRecord.getGoodsName());
luckRecordReq.setIsLuck(luckRecord.getIsLuck());
luckRecordReq.setWeight(luckRecord.getWeight());
luckRecordReq.setMobile(luckRecord.getMobile());
luckRecordReqList.add(luckRecordReq);
}
luckDetailInfoReq.setLuckRecordReqs(luckRecordReqList);
return R.ok().put("luck",luckDetailInfoReq);
}
return R.error("活动暂无人员报名");
}
return R.error("活动无相关奖品信息");
}else{
//获取获奖人员信息
luckDetailInfoReq.setIsFinish(1);
luckDetailInfoReq.setId(luckId);
luckDetailInfoReq.setName(luck.getName());
List<LuckRecord> luckRecords = luckRecordService.selectGoodLuckRecordByLuckId(String.valueOf(luckId));
if(luckRecords.size() > 0) {
List<LuckRecordReq> luckRecordReqList = new ArrayList<>();
for (LuckRecord luckRecord : luckRecords
) {
LuckRecordReq luckRecordReq = new LuckRecordReq();
luckRecordReq.setName(luckRecord.getName());
luckRecordReq.setId(luckRecord.getId());
luckRecordReq.setGoodsId(luckRecord.getGoodsId());
luckRecordReq.setGoodsName(luckRecord.getGoodsName());
luckRecordReq.setIsLuck(luckRecord.getIsLuck());
luckRecordReq.setWeight(luckRecord.getWeight());
luckRecordReq.setMobile(luckRecord.getMobile());
luckRecordReqList.add(luckRecordReq);
}
luckDetailInfoReq.setLuckRecordReqs(luckRecordReqList);
return R.ok().put("luck", luckDetailInfoReq);
}
}
}
return R.error("无相关活动");
}
@PostMapping("/updateLuck")
public R updateLuck(@RequestBody String body) {
JSONArray jsonArray = JSONObject.parseArray(body);
Long luckId = 0L;
for(int i = 0; i < jsonArray.size(); i++){
JSONObject json = jsonArray.getJSONObject(i);
LuckRecordReq luckRecordReq = json.toJavaObject(LuckRecordReq.class);
luckId = luckRecordReq.getLuckId();
luckRecordService.updateLuckRecordByReqWithId(luckRecordReq);
}
int count = luckRecordService.selectCountGoodLuckRecordByLuckId(luckId);
int count1 = luckGoodsService.selectNumGoodLuckRecordByLuckId(luckId);
if(count < count1){
//获取未中奖人列表
return getLuck(luckId);
}else{
//设置中将结束
luckService.setLuckFinishById(luckId);
Luck luck = luckService.selectLuckById(luckId);
LuckDetailInfoReq luckDetailInfoReq = new LuckDetailInfoReq();
luckDetailInfoReq.setIsFinish(1);
luckDetailInfoReq.setName(luck.getName());
luckDetailInfoReq.setId(luck.getId());
return R.ok().put("luck", luckDetailInfoReq);
}
}
@RequestMapping("/update")
public R update(@RequestBody Luck luck) {
luckService.updateLuckById(luck);
return R.ok();

View File

@ -11,6 +11,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lz.modules.luck.entity.LuckGoods;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface LuckGoodsMapper extends BaseMapper<LuckGoods> {
@ -30,4 +33,7 @@ public interface LuckGoodsMapper extends BaseMapper<LuckGoods> {
int deleteLuckGoodsById(@Param("id")Long id);
List<LuckGoods> getByLuckId(@Param("luckId") Long luckId);
int selectNumGoodLuckRecordByLuckId(@Param("luckId") Long luckId);
}

View File

@ -30,4 +30,5 @@ public interface LuckMapper extends BaseMapper<Luck> {
int deleteLuckById(@Param("id")Long id);
void setLuckFinishById(Long luckId);
}

View File

@ -9,6 +9,7 @@ package com.lz.modules.luck.dao;
*/
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lz.modules.luck.entity.LuckRecord;
import com.lz.modules.luck.entity.LuckRecordReq;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -36,4 +37,10 @@ public interface LuckRecordMapper extends BaseMapper<LuckRecord> {
LuckRecord selectLuckRecordByLuckIdAndStaffId(@Param("luckId") Long luckId, @Param("id") Long id);
List<LuckRecord> selectLuckRecordByLuckId(@Param("luckId") String luckId);
void updateLuckRecordByReqWithId(LuckRecordReq luckRecordReq);
List<LuckRecord> selectGoodLuckRecordByLuckId(String luckId);
int selectCountGoodLuckRecordByLuckId(@Param("luckId") Long luckId);
}

View File

@ -0,0 +1,13 @@
package com.lz.modules.luck.entity;
import lombok.Data;
import java.util.List;
@Data
public class LuckDetailInfoReq {
private String name;//活动名称
private Long Id;//活动名称
private int isFinish;//活动是否结束
private List<LuckGoodsReq> luckGoodsReqs;//奖品列表
private List<LuckRecordReq> luckRecordReqs;//参与抽奖人员列表
}

View File

@ -28,7 +28,7 @@ public class LuckGoods implements java.io.Serializable {
private Long luckId;
//奖品名称
private String name;
//权重
//权重权重抽奖顺序
private Integer weight;
//备注
private String remark;
@ -125,14 +125,14 @@ public class LuckGoods implements java.io.Serializable {
}
/**
* 权重
* 权重 权重抽奖顺序
* @return
*/
public Integer getWeight() {
return weight;
}
/**
* 权重
* 权重 权重抽奖顺序
* @param weight
*/
public void setWeight(Integer weight) {

View File

@ -13,26 +13,13 @@ import java.util.Date;
@Data
public class LuckGoodsReq implements java.io.Serializable {
private int page = 1;
private int rows = 10;
private String sort;
private String order;
//
private Long id;
//
private Integer isDelete;
//
private Date gmtCreate;
//
private Date gmtModified;
//活动ID
private Long luckId;
//奖品名称
private String name;
//权重
private Integer weight;
//备注
private String remark;
//数量
private Integer counts;
/**
@ -50,65 +37,7 @@ public class LuckGoodsReq implements java.io.Serializable {
this.id = id;
}
/**
*
* @return
*/
public Integer getIsDelete() {
return isDelete;
}
/**
*
* @param isDelete
*/
public void setIsDelete(Integer isDelete) {
this.isDelete = isDelete;
}
/**
*
* @return
*/
public Date getGmtCreate() {
return gmtCreate;
}
/**
*
* @param gmtCreate
*/
public void setGmtCreate(Date gmtCreate) {
this.gmtCreate = gmtCreate;
}
/**
*
* @return
*/
public Date getGmtModified() {
return gmtModified;
}
/**
*
* @param gmtModified
*/
public void setGmtModified(Date gmtModified) {
this.gmtModified = gmtModified;
}
/**
* 活动ID
* @return
*/
public Long getLuckId() {
return luckId;
}
/**
* 活动ID
* @param luckId
*/
public void setLuckId(Long luckId) {
this.luckId = luckId;
}
/**
* 奖品名称
@ -140,20 +69,7 @@ public class LuckGoodsReq implements java.io.Serializable {
this.weight = weight;
}
/**
* 备注
* @return
*/
public String getRemark() {
return remark;
}
/**
* 备注
* @param remark
*/
public void setRemark(String remark) {
this.remark = remark;
}
/**
* 数量
@ -174,13 +90,8 @@ public class LuckGoodsReq implements java.io.Serializable {
public String toString() {
return "LuckGoods{" +
",id=" + id +
",isDelete=" + isDelete +
",gmtCreate=" + gmtCreate +
",gmtModified=" + gmtModified +
",luckId=" + luckId +
",name=" + name +
",weight=" + weight +
",remark=" + remark +
",counts=" + counts +
"}";
}

View File

@ -28,7 +28,9 @@ public class LuckRecord implements java.io.Serializable {
private Long staffId;
//姓名
private String name;
//是否中将 0为中将 1中将
//手机号
private String mobile;
//是否中将 0为中将 是否中将 0为中将 1 特等奖或者一等奖以此类推
private Integer isLuck;
//权重或者排序
private Integer weight;

View File

@ -13,22 +13,11 @@ import java.util.Date;
@Data
public class LuckRecordReq implements java.io.Serializable {
private int page = 1;
private int rows = 10;
private String sort;
private String order;
//
private Long id;
//是否删除 0未删除 1删除
private Integer isDelete;
//
private Date gmtCreate;
//
private Date gmtModified;
//员工staff_id
private Long staffId;
//姓名
private String name;
private String mobile;
//是否中将 0为中将 1中将
private Integer isLuck;
//权重或者排序
@ -39,8 +28,6 @@ public class LuckRecordReq implements java.io.Serializable {
private String goodsName;
//奖品ID目前不设置ID了
private Long goodsId;
//备注
private String remark;
/**
*
* @return
@ -56,66 +43,6 @@ public class LuckRecordReq implements java.io.Serializable {
this.id = id;
}
/**
* 是否删除 0未删除 1删除
* @return
*/
public Integer getIsDelete() {
return isDelete;
}
/**
* 是否删除 0未删除 1删除
* @param isDelete
*/
public void setIsDelete(Integer isDelete) {
this.isDelete = isDelete;
}
/**
*
* @return
*/
public Date getGmtCreate() {
return gmtCreate;
}
/**
*
* @param gmtCreate
*/
public void setGmtCreate(Date gmtCreate) {
this.gmtCreate = gmtCreate;
}
/**
*
* @return
*/
public Date getGmtModified() {
return gmtModified;
}
/**
*
* @param gmtModified
*/
public void setGmtModified(Date gmtModified) {
this.gmtModified = gmtModified;
}
/**
* 员工staff_id
* @return
*/
public Long getStaffId() {
return staffId;
}
/**
* 员工staff_id
* @param staffId
*/
public void setStaffId(Long staffId) {
this.staffId = staffId;
}
/**
* 姓名
* @return
@ -206,36 +133,18 @@ public class LuckRecordReq implements java.io.Serializable {
this.goodsId = goodsId;
}
/**
* 备注
* @return
*/
public String getRemark() {
return remark;
}
/**
* 备注
* @param remark
*/
public void setRemark(String remark) {
this.remark = remark;
}
@Override
public String toString() {
return "LuckRecord{" +
",id=" + id +
",isDelete=" + isDelete +
",gmtCreate=" + gmtCreate +
",gmtModified=" + gmtModified +
",staffId=" + staffId +
",name=" + name +
",isLuck=" + isLuck +
",weight=" + weight +
",luckId=" + luckId +
",goodsName=" + goodsName +
",goodsId=" + goodsId +
",remark=" + remark +
"}";
}
}

View File

@ -3,6 +3,8 @@ package com.lz.modules.luck.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.lz.modules.luck.entity.LuckGoods;
import java.util.List;
/**
* <p>
* 奖品表 服务类
@ -30,4 +32,8 @@ public interface LuckGoodsService extends IService<LuckGoods> {
int deleteLuckGoodsById(Long id);
List<LuckGoods> getByLuckId(Long luckId);
//获取奖品总数
int selectNumGoodLuckRecordByLuckId(Long luckId);
}

View File

@ -2,6 +2,7 @@ package com.lz.modules.luck.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.lz.modules.luck.entity.LuckRecord;
import com.lz.modules.luck.entity.LuckRecordReq;
import java.util.List;
@ -35,4 +36,10 @@ public interface LuckRecordService extends IService<LuckRecord> {
LuckRecord selectLuckRecordByLuckIdAndStaffId(Long luckId, Long id);
List<LuckRecord> selectLuckRecordByLuckId(String luckId);
void updateLuckRecordByReqWithId(LuckRecordReq luckRecordReq);
List<LuckRecord> selectGoodLuckRecordByLuckId(String valueOf);
//获取中奖人数
int selectCountGoodLuckRecordByLuckId(Long luckId);
}

View File

@ -30,4 +30,5 @@ public interface LuckService extends IService<Luck> {
int deleteLuckById(Long id);
void setLuckFinishById(Long luckId);
}

View File

@ -7,6 +7,8 @@ import com.lz.modules.luck.service.LuckGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 奖品表 服务类
@ -58,6 +60,14 @@ public class LuckGoodsServiceImpl extends ServiceImpl<LuckGoodsMapper, LuckGoods
return luckGoodsMapper.deleteLuckGoodsById(id);
}
@Override
public List<LuckGoods> getByLuckId(Long luckId){
return luckGoodsMapper.getByLuckId(luckId);
}
@Override
public int selectNumGoodLuckRecordByLuckId(Long luckId){
return luckGoodsMapper.selectNumGoodLuckRecordByLuckId(luckId);
}
}

View File

@ -3,6 +3,7 @@ package com.lz.modules.luck.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lz.modules.luck.dao.LuckRecordMapper;
import com.lz.modules.luck.entity.LuckRecord;
import com.lz.modules.luck.entity.LuckRecordReq;
import com.lz.modules.luck.service.LuckRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -70,4 +71,20 @@ public class LuckRecordServiceImpl extends ServiceImpl<LuckRecordMapper, LuckRec
return luckRecordMapper.selectLuckRecordByLuckId(luckId);
}
@Override
public void updateLuckRecordByReqWithId(LuckRecordReq luckRecordReq){
luckRecordMapper.updateLuckRecordByReqWithId(luckRecordReq);
}
@Override
public List<LuckRecord> selectGoodLuckRecordByLuckId(String luckId){
return luckRecordMapper.selectGoodLuckRecordByLuckId(luckId);
}
@Override
public int selectCountGoodLuckRecordByLuckId(Long luckId){
return luckRecordMapper.selectCountGoodLuckRecordByLuckId(luckId);
}
}

View File

@ -58,6 +58,11 @@ public class LuckServiceImpl extends ServiceImpl<LuckMapper, Luck> implements Lu
return luckMapper.deleteLuckById(id);
}
@Override
public void setLuckFinishById(Long luckId){
luckMapper.setLuckFinishById(luckId);
}
}

View File

@ -89,5 +89,12 @@
update luck_goods set is_delete = 1 where id=#{id} limit 1
</update>
<select id="getByLuckId" resultType="LuckGoods" >
select * from luck_goods where luck_id=#{luckId} and is_delete = 0 order by weight desc
</select>
<select id="selectNumGoodLuckRecordByLuckId" parameterType="java.lang.Long" resultType="integer">
select sum(counts) from luck_goods where luck_id=#{luckId} and is_delete = 0
</select>
</mapper>

View File

@ -91,7 +91,11 @@
<update id="deleteLuckById" parameterType="java.lang.Long">
update luck set is_delete = 1 where id=#{id} limit 1
update luck set is_delete = 1, gmt_modified=now() where id=#{id} limit 1
</update>
<update id="setLuckFinishById" parameterType="java.lang.Long">
update luck set finish = 1, gmt_modified=now() where id=#{luckId} limit 1
</update>
</mapper>

View File

@ -10,6 +10,7 @@
<result column="gmt_modified" property="gmtModified"/>
<result column="staff_id" property="staffId"/>
<result column="name" property="name"/>
<result column="mobile" property="mobile"/>
<result column="is_luck" property="isLuck"/>
<result column="weight" property="weight"/>
<result column="luck_id" property="luckId"/>
@ -21,7 +22,7 @@
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, staff_id AS staffId, name AS name, is_luck AS isLuck, weight AS weight, luck_id AS luckId, goods_name AS goodsName, goods_id AS goodsId, remark AS remark
id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, staff_id AS staffId, name AS name, mobile AS mobile, is_luck AS isLuck, weight AS weight, luck_id AS luckId, goods_name AS goodsName, goods_id AS goodsId, remark AS remark
</sql>
@ -36,6 +37,7 @@
insert into luck_record(
<if test="staffId != null">staff_id, </if>
<if test="name != null">name, </if>
<if test="moblie != null">name, </if>
<if test="isLuck != null">is_luck, </if>
<if test="weight != null">weight, </if>
<if test="luckId != null">luck_id, </if>
@ -48,6 +50,7 @@
)values(
<if test="staffId != null">#{ staffId}, </if>
<if test="name != null">#{ name}, </if>
<if test="mobile != null">#{ mobile}, </if>
<if test="isLuck != null">#{ isLuck}, </if>
<if test="weight != null">#{ weight}, </if>
<if test="luckId != null">#{ luckId}, </if>
@ -69,6 +72,7 @@
<if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
<if test="staffId != null">staff_id = #{staffId},</if>
<if test="name != null">name = #{name},</if>
<if test="mobile != null">mobile = #{mobile},</if>
<if test="isLuck != null">is_luck = #{isLuck},</if>
<if test="weight != null">weight = #{weight},</if>
<if test="luckId != null">luck_id = #{luckId},</if>
@ -89,6 +93,7 @@
gmt_create = #{gmtCreate},
staff_id = #{staffId},
name = #{name},
mobile = #{mobile},
is_luck = #{isLuck},
weight = #{weight},
luck_id = #{luckId},
@ -109,7 +114,27 @@
</select>
<select id="selectLuckRecordByLuckId" resultType="LuckRecord" >
select * from luck_record where luck_id=#{luckId}and is_delete = 0
select * from luck_record where luck_id=#{luckId}and is_delete = 0 order by is_luck desc
</select>
<update id="updateLuckRecordByReqWithId" parameterType="LuckRecordReq" >
update
luck_record
set
is_luck = #{isLuck},
luck_id = #{luckId},
goods_name = #{goodsName},
goods_id = #{goodsId}
,gmt_modified = now()
where id = #{id}
</update>
<select id="selectGoodLuckRecordByLuckId" resultType="LuckRecord" >
select * from luck_record where luck_id=#{luckId}and is_delete = 0 and is_luck=1 order by goods_id asc
</select>
<select id="selectCountGoodLuckRecordByLuckId" parameterType="java.lang.Long" resultType="integer">
select count(1) from luck_record where luck_id=#{luckId} and is_delete = 0 and is_luck=1
</select>
</mapper>