dev-discount
袁野 3 years ago
commit 82350b04fc
  1. 1
      hai-cweb/src/main/java/com/cweb/config/AuthConfig.java
  2. 64
      hai-cweb/src/main/java/com/cweb/controller/HighActivityController.java
  3. 1
      hai-service/src/main/java/com/hai/common/exception/ErrorCode.java
  4. 4
      hai-service/src/main/java/com/hai/common/utils/ResponseMsgUtil.java
  5. 16
      hai-service/src/main/java/com/hai/dao/HighActivityAwardUserMapperExt.java
  6. 7
      hai-service/src/main/java/com/hai/service/HighActivityAwardSerialNumService.java
  7. 23
      hai-service/src/main/java/com/hai/service/HighActivityAwardUserService.java
  8. 5
      hai-service/src/main/java/com/hai/service/impl/HighActivityAwardSerialNumServiceImpl.java
  9. 43
      hai-service/src/main/java/com/hai/service/impl/HighActivityAwardUserServiceImpl.java
  10. 49
      hai-service/src/main/java/com/hai/service/impl/HighActivityUserLotteryNumServiceImpl.java

@ -104,6 +104,7 @@ public class AuthConfig implements WebMvcConfigurer {
.excludePathPatterns("/highMerchantStore/getStoreListByMerchant")
.excludePathPatterns("/sms/sendSmsCode")
.excludePathPatterns("/sms/getSmsCode")
.excludePathPatterns("/activity/getWinLotteryList")
.excludePathPatterns("/user/login")
.excludePathPatterns("/user/getUnionId")
.excludePathPatterns("/order/orderToH5Pay")

@ -15,8 +15,10 @@ import com.hai.enum_type.ActivityInfoStatus;
import com.hai.model.HighUserModel;
import com.hai.model.ResponseData;
import com.hai.service.HighActivityAwardService;
import com.hai.service.HighActivityAwardUserService;
import com.hai.service.HighActivityInfoService;
import com.hai.service.HighActivityUserLotteryNumService;
import com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.MapUtils;
@ -24,6 +26,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DeadlockLoserDataAccessException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@ -51,13 +54,16 @@ public class HighActivityController {
@Resource
private HighActivityAwardService highActivityAwardService;
@Resource
private HighActivityAwardUserService highActivityAwardUserService;
@Resource
private HighActivityUserLotteryNumService highActivityUserLotteryNumService;
@RequestMapping(value="/userLottery",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "用户抽奖业务")
public ResponseData userLottery(@RequestBody JSONObject body, HttpServletRequest request) {
public ResponseData userLottery(@RequestBody JSONObject body, HttpServletRequest request) {
try {
// 用户
SessionObject sessionObject = userCenter.getSessionObject(request);
@ -67,15 +73,55 @@ public class HighActivityController {
log.error("HighActivityController --> lottery() error!", "参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 活动信息
HighActivityInfo activityInfo = highActivityInfoService.getDetailById(body.getLong("activityId"));
if (activityInfo == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到数据");
}
if (!activityInfo.getStatus().equals(ActivityInfoStatus.status2.getNumber())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "活动已结束");
}
Date currentDate = new Date();
if (currentDate.getTime() < activityInfo.getStartTime().getTime()) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "活动还未开始");
}
if (currentDate.getTime() > activityInfo.getEndTime().getTime()) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "活动已结束");
}
// 校验用户是否有抽奖次数
if (highActivityUserLotteryNumService.getLotteryNum(body.getLong("activityId"), userInfoModel.getHighUser().getId()) <= 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "抽奖次数已经用完了");
}
return ResponseMsgUtil.success(highActivityUserLotteryNumService.userLottery(body.getLong("activityId"),userInfoModel.getHighUser().getId()));
} catch (DeadlockLoserDataAccessException deadlockLoserDataAccessException) {
log.error("HighActivityController -> userLottery() error!", "服务器繁忙");
return ResponseMsgUtil.builderResponse(ErrorCode.SERVER_BUSY_ERROR.getCode(),ErrorCode.SERVER_BUSY_ERROR.getMsg(),null);
} catch (Exception e) {
log.error("HighActivityController -> userLottery() error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/getUserLotteryNum",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "获取用户抽奖次数")
public ResponseData getUserLotteryNum(@RequestParam(name = "activityId", required = true) Long activityId,
HttpServletRequest request) {
try {
// 用户
SessionObject sessionObject = userCenter.getSessionObject(request);
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
return ResponseMsgUtil.success(highActivityUserLotteryNumService.getLotteryNum(activityId,userInfoModel.getHighUser().getId()));
} catch (Exception e) {
log.error("HighActivityController -> getLotteryNum() error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/getActivityByCoupon",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据卡券查询活动信息")
@ -116,4 +162,20 @@ public class HighActivityController {
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/getWinLotteryList",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询中奖记录")
public ResponseData getWinLotteryList(@RequestParam(name = "activityId", required = true) Long activityId) {
try {
return ResponseMsgUtil.success(highActivityAwardUserService.getWinLotteryList(activityId));
} catch (Exception e) {
log.error("HighActivityController -> getWinLotteryList() error!",e);
return ResponseMsgUtil.exception(e);
}
}
}

@ -25,6 +25,7 @@ public enum ErrorCode {
WECHAT_DECRYPT_ERROR("3001","微信解密错误->%s"),
WECHAT_LOGIN_ERROR("3002","微信登录失败"),
WECHAT_LOGIN_TEACHER_ERROR("3003","当前微信用户不是老师,请联系管理员"),
SERVER_BUSY_ERROR("3004","服务器繁忙,请稍后重试"),
//////////////////业务异常/////////////
COMMON_ERROR("2000",""),

@ -60,9 +60,9 @@ public class ResponseMsgUtil {
if(e instanceof BizException){//业务异常处理
return builderResponse(((BizException)e).getErrorCode(), ((BizException)e).getErrorMsg(), null);
}else if(e instanceof BaseException){//系统异常处理
} else if(e instanceof BaseException){//系统异常处理
return builderResponse(((BaseException)e).getErrorCode(),"服务异常",null);
}else{//未知异常
} else{//未知异常
return builderResponse("999999", "未知异常", null);
}
}

@ -1,7 +1,21 @@
package com.hai.dao;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
/**
* mapper扩展类
*/
public interface HighActivityAwardUserMapperExt {
}
@Select(" select insert(b.phone, 4, 4, '****') phone,a.name awardName,a.create_time receiveTime from \n" +
" (select a.create_time, b.name,a.user_id " +
" from high_activity_award_user a,high_activity_award b " +
" where a.activity_award_id = b.id and a.activity_info_id = #{activityId} " +
" ORDER BY a.create_time desc LIMIT 50) a" +
" LEFT JOIN high_user b on b.id = a.user_id")
List<Map<String, Object>> selectWinLotteryList(@Param("activityId") Long activityId);
}

@ -17,6 +17,13 @@ public interface HighActivityAwardSerialNumService {
*/
void update(HighActivityAwardSerialNum serialNum);
/**
* 根据id查询详情
* @param id
* @return
*/
HighActivityAwardSerialNum getDetail(Long id);
/**
* 查询未中奖的编号
* @param activityId

@ -0,0 +1,23 @@
package com.hai.service;
import java.util.List;
import java.util.Map;
/**
* @author hurui
*/
public interface HighActivityAwardUserService {
/**
* 增加用户中奖记录
*/
void insertAwardUser(Long serialNumId,Long userId);
/**
* 此方法请勿随意调用与修改因为这个是专门对外开放的
* 根据活动查询中奖记录
* @param activityId
* @return
*/
List<Map<String, Object>> getWinLotteryList(Long activityId);
}

@ -20,6 +20,11 @@ public class HighActivityAwardSerialNumServiceImpl implements HighActivityAwardS
highActivityAwardSerialNumMapper.updateByPrimaryKey(serialNum);
}
@Override
public HighActivityAwardSerialNum getDetail(Long id) {
return highActivityAwardSerialNumMapper.selectByPrimaryKey(id);
}
@Override
public List<HighActivityAwardSerialNum> getNoGainListByActivity(Long activityId) {
HighActivityAwardSerialNumExample example = new HighActivityAwardSerialNumExample();

@ -0,0 +1,43 @@
package com.hai.service.impl;
import com.hai.dao.HighActivityAwardUserMapper;
import com.hai.entity.HighActivityAwardSerialNum;
import com.hai.entity.HighActivityAwardUser;
import com.hai.service.HighActivityAwardSerialNumService;
import com.hai.service.HighActivityAwardUserService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service("highActivityAwardUserService")
public class HighActivityAwardUserServiceImpl implements HighActivityAwardUserService {
@Resource
private HighActivityAwardUserMapper highActivityAwardUserMapper;
@Resource
private HighActivityAwardSerialNumService highActivityAwardSerialNumService;
@Override
public void insertAwardUser(Long serialNumId,Long userId) {
// 查询中奖号码
HighActivityAwardSerialNum detail = highActivityAwardSerialNumService.getDetail(serialNumId);
if (detail != null) {
HighActivityAwardUser awardUser = new HighActivityAwardUser();
awardUser.setCreateTime(new Date());
awardUser.setActivityAwardSerialNumId(serialNumId);
awardUser.setUserId(userId);
awardUser.setActivityInfoId(detail.getActivityInfoId());
awardUser.setActivityAwardId(detail.getActivityAwardId());
highActivityAwardUserMapper.insert(awardUser);
}
}
@Override
public List<Map<String, Object>> getWinLotteryList(Long activityId) {
return highActivityAwardUserMapper.selectWinLotteryList(activityId);
}
}

@ -1,5 +1,6 @@
package com.hai.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
@ -28,6 +29,9 @@ public class HighActivityUserLotteryNumServiceImpl implements HighActivityUserLo
@Resource
private HighActivityAwardActualPrizeService highActivityAwardActualPrizeService;
@Resource
private HighActivityAwardUserService highActivityAwardUserService;
@Resource
private HighActivityUserLotteryNumMapper highActivityUserLotteryNumMapper;
@ -35,27 +39,11 @@ public class HighActivityUserLotteryNumServiceImpl implements HighActivityUserLo
private HighDiscountUserRelService highDiscountUserRelService;
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW,isolation= Isolation.SERIALIZABLE)
@Transactional(rollbackFor = Exception.class,
propagation= Propagation.REQUIRES_NEW,
isolation= Isolation.SERIALIZABLE,
timeout = 30)
public Object userLottery(Long activityId, Long userId) {
// 活动信息
HighActivityInfo activityInfo = highActivityInfoService.getDetailById(activityId);
if (activityInfo == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到数据");
}
if (!activityInfo.getStatus().equals(ActivityInfoStatus.status2.getNumber())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "活动已结束");
}
Date currentDate = new Date();
if (currentDate.getTime() < activityInfo.getStartTime().getTime()) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "活动还未开始");
}
if (currentDate.getTime() > activityInfo.getEndTime().getTime()) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "活动已结束");
}
// 校验用户是否有抽奖次数
if (getLotteryNum(activityId, userId) <= 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "抽奖次数已经用完了");
}
// 查询活动未中奖的号码
List<HighActivityAwardSerialNum> serialNumList = highActivityAwardSerialNumService.getNoGainListByActivity(activityId);
if (serialNumList.size() == 0) {
@ -67,19 +55,27 @@ public class HighActivityUserLotteryNumServiceImpl implements HighActivityUserLo
// 抽中的号码
int index = (int) (Math.random() * serialNumList.size());
HighActivityAwardSerialNum serialNum = serialNumList.get(index);
serialNum.setStatus(2);
highActivityAwardSerialNumService.update(serialNum);
// 增加中奖记录
highActivityAwardUserService.insertAwardUser(serialNum.getId(),userId);
// 领取奖品
receivePrize(serialNum,userId);
return serialNum;
new Thread(() -> {
// 领取奖品
receivePrize(serialNum,userId);
}).start();
JSONObject jsonObject = new JSONObject();
jsonObject.put("activityAwardId", serialNum.getActivityAwardId());
jsonObject.put("serialNum", serialNum.getSerialNum());
return jsonObject;
}
/**
* 领取奖品
*/
private void receivePrize(HighActivityAwardSerialNum serialNum, Long userId) {
serialNum.setStatus(2);
highActivityAwardSerialNumService.update(serialNum);
// 查询中奖的奖品
List<HighActivityAwardActualPrize> prizeList = highActivityAwardActualPrizeService.getActualPrizeBySerialNumId(serialNum.getId());
for (HighActivityAwardActualPrize actualPrize : prizeList) {
@ -88,7 +84,6 @@ public class HighActivityUserLotteryNumServiceImpl implements HighActivityUserLo
if (actualPrize.getActualPrizeType() == 2) {
highDiscountUserRelService.receiveDiscount(userId,actualPrize.getActualPrizeId());
}
}
}

Loading…
Cancel
Save