Browse Source

判断是否有权限做任务

master
zhizhi wu 3 years ago
parent
commit
d523f50be3
  1. 34
      src/main/java/com/ccsens/braintraining/api/RaffleController.java
  2. 6
      src/main/java/com/ccsens/braintraining/aspect/MustLoginAspect.java
  3. 21
      src/main/java/com/ccsens/braintraining/bean/dto/RaffleDto.java
  4. 20
      src/main/java/com/ccsens/braintraining/bean/dto/TallDto.java
  5. 36
      src/main/java/com/ccsens/braintraining/bean/vo/RaffleVo.java
  6. 21
      src/main/java/com/ccsens/braintraining/bean/vo/TallVo.java
  7. 24
      src/main/java/com/ccsens/braintraining/persist/dao/RaffleDao.java
  8. 26
      src/main/java/com/ccsens/braintraining/service/IRaffleService.java
  9. 139
      src/main/java/com/ccsens/braintraining/service/RaffleService.java
  10. 8
      src/main/java/com/ccsens/braintraining/util/BrainTrainingCodeError.java
  11. 29
      src/main/java/com/ccsens/braintraining/util/BrainTrainingConstant.java
  12. 2
      src/main/resources/application-dev.yml
  13. 3
      src/main/resources/application-prod.yml
  14. 3
      src/main/resources/application-test.yml
  15. 4
      src/main/resources/application.yml
  16. 79
      src/main/resources/mapper_dao/RaffleDao.xml

34
src/main/java/com/ccsens/braintraining/api/RaffleController.java

@ -47,13 +47,13 @@ public class RaffleController {
@Login
@ApiOperation(value = "中奖信息")
@RequestMapping(value = "/prizeRecord", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<RaffleVo.PrizeRecord> prizeRecord(@ApiParam @Validated @RequestBody QueryDto<RaffleDto.RecordList> params) {
public JsonResponse<PageInfo<RaffleVo.PrizeRecord>> prizeRecord(@ApiParam @Validated @RequestBody QueryDto<RaffleDto.RecordList> params) {
log.info("中奖信息查询:{}", params);
PageInfo<RaffleVo.PrizeRecord> records = raffleService.prizeRecord(params.getParam(), params.getUserId());
log.info("中奖信息结束:{}");
return JsonResponse.newInstance().ok(records);
}
// @MustLogin
@MustLogin
@ApiOperation(value = "抽奖")
@RequestMapping(value = "/draw", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<RaffleVo.Prize> draw(@ApiParam @Validated @RequestBody QueryDto<RaffleDto.ActiveId> params) {
@ -62,4 +62,34 @@ public class RaffleController {
log.info("{}抽奖:{}结束:{}", params.getUserId(), params.getParam().getActiveId(), prize);
return JsonResponse.newInstance().ok(prize);
}
@MustLogin
@ApiOperation(value = "查询用户的中奖纪录")
@RequestMapping(value = "/selfPrize", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<PageInfo<RaffleVo.PrizeTime>> selfPrize(@ApiParam @Validated @RequestBody QueryDto<RaffleDto.SelfPrize> params) {
log.info("查询用户的中奖纪录:{}", params);
PageInfo<RaffleVo.PrizeTime> prizes = raffleService.queryUserPrize(params.getParam(), params.getUserId());
log.info("查询用户的中奖纪录结束:{}", prizes);
return JsonResponse.newInstance().ok(prizes);
}
@MustLogin
@ApiOperation(value = "检查任务的完成情况")
@RequestMapping(value = "/checkTask", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<RaffleVo.CheckTask> checkTask(@ApiParam @Validated @RequestBody QueryDto<RaffleDto.DoTask> params) {
log.info("检查任务的完成情况:{}", params);
RaffleVo.CheckTask prizes = raffleService.checkTask(params.getParam(), params.getUserId(), params.getToken(), params.getDeviceId());
log.info("检查任务的完成情况结束:{}", prizes);
return JsonResponse.newInstance().ok(prizes);
}
@MustLogin
@ApiOperation(value = "完成任务")
@RequestMapping(value = "/doTask", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<RaffleVo.DoTask> doTask(@ApiParam @Validated @RequestBody QueryDto<RaffleDto.DoTask> params) {
log.info("完成任务:{}", params);
RaffleVo.DoTask prizes = raffleService.doTask(params.getParam(), params.getUserId());
log.info("完成任务结束:{}", prizes);
return JsonResponse.newInstance().ok(prizes);
}
}

6
src/main/java/com/ccsens/braintraining/aspect/MustLoginAspect.java

@ -67,7 +67,8 @@ public class MustLoginAspect {
RequestContextHolder.getRequestAttributes()).getRequest();
// 获取token
final String authHeader = request.getHeader(WebConstant.HEADER_KEY_TOKEN);
log.info("token:{}", authHeader);
final String deviceId = request.getHeader(BrainTrainingConstant.User.DEVICE_ID);
log.info("token:{}, deviceId:{}", authHeader, deviceId);
if ( mustLoginAnnotation != null && StrUtil.isEmpty(authHeader)) {
throw new BaseException(CodeEnum.NOT_LOGIN);
}
@ -94,7 +95,8 @@ public class MustLoginAspect {
dto.setAvatarUrl(bean.getAvatarUrl());
dto.setPhone(bean.getPhone());
dto.setAuthType(bean.getAuthType());
dto.setToken(WebConstant.HEADER_KEY_TOKEN_PREFIX + authHeader);
dto.setToken(authHeader);
dto.setDeviceId(deviceId);
// 判断该userId是否已经存储
saveUser(bean);
}

21
src/main/java/com/ccsens/braintraining/bean/dto/RaffleDto.java

@ -28,6 +28,14 @@ public class RaffleDto {
@NotNull(message="请输入抽奖活动信息")
@ApiModelProperty("抽奖ID")
private Long activeId;
}
@Data
@ApiModel("中奖纪录列表-请求")
public static class RecordList {
@NotNull(message="请输入抽奖活动信息")
@ApiModelProperty("抽奖ID")
private Long activeId;
@Min(1)
@ApiModelProperty("页码")
private int pageNum = 1;
@ -38,11 +46,8 @@ public class RaffleDto {
}
@Data
@ApiModel("中奖纪录列表-请求")
public static class RecordList {
@NotNull(message="请输入抽奖活动信息")
@ApiModelProperty("抽奖ID")
private Long activeId;
@ApiModel("用户中奖纪录列表-请求")
public static class SelfPrize {
@Min(1)
@ApiModelProperty("页码")
private int pageNum = 1;
@ -51,4 +56,10 @@ public class RaffleDto {
@ApiModelProperty("每页多少条")
private int pageSize = 20;
}
@Data
@ApiModel("用户做任务-请求")
public static class DoTask {
@ApiModelProperty("任务ID")
private Long taskId;
}
}

20
src/main/java/com/ccsens/braintraining/bean/dto/TallDto.java

@ -0,0 +1,20 @@
package com.ccsens.braintraining.bean.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @description:
* @author: whj
* @time: 2022/3/17 15:49
*/
public class TallDto {
@Data
@ApiModel("根据公众号id判断用户是否关注该公众号-请求")
public static class Tencent{
@ApiModelProperty("公众号ID")
private String appId;
}
}

36
src/main/java/com/ccsens/braintraining/bean/vo/RaffleVo.java

@ -1,10 +1,12 @@
package com.ccsens.braintraining.bean.vo;
import cn.hutool.core.util.StrUtil;
import com.ccsens.braintraining.bean.po.RaffleActive;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
@ -35,6 +37,8 @@ public class RaffleVo {
private Long startTime;
@ApiModelProperty("结束时间")
private Long endTime;
@ApiModelProperty("用户剩余抽奖次数")
private Integer prizeTimes;
}
@Data
@ApiModel("抽奖活动-奖品-响应")
@ -59,8 +63,12 @@ public class RaffleVo {
private Byte type;
@ApiModelProperty("完成状态 0:未完成 1:已完成 2:以前完成")
private Byte finishStatus;
@ApiModelProperty("参数")
private String param;
}
@Data
@ApiModel("中奖纪录")
public static class PrizeRecord {
@ -96,5 +104,33 @@ public class RaffleVo {
private Integer remain;
}
@Data
@ApiModel("抽奖活动-奖品-响应")
public static class PrizeTime {
@ApiModelProperty("奖品ID")
private Long prizeId;
@ApiModelProperty("奖品名称")
private String name;
@ApiModelProperty("奖品图标")
private String icon;
@ApiModelProperty("中奖时间")
private Date time;
}
@Data
@ApiModel("用户做任务-响应")
public static class DoTask {
@ApiModelProperty("增加的次数")
private Integer addTimes;
@ApiModelProperty("总抽奖次数")
private Long totalTimes;
}
@Data
@ApiModel("检查任务的完成情况-返回")
public static class CheckTask {
@ApiModelProperty("完成状态 -1:活动已结束 0:未完成 1:已完成 2:以前完成")
private Byte finishStatus;
}
}

21
src/main/java/com/ccsens/braintraining/bean/vo/TallVo.java

@ -0,0 +1,21 @@
package com.ccsens.braintraining.bean.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @description:
* @author: whj
* @time: 2022/3/17 18:54
*/
public class TallVo {
@Data
@ApiModel("用户是否关注公众号")
public static class UserOfficial{
@ApiModelProperty("用户id")
private Long userId;
@ApiModelProperty("是否关注公众号 0未关注 1已关注")
private byte status;
}
}

24
src/main/java/com/ccsens/braintraining/persist/dao/RaffleDao.java

@ -1,5 +1,7 @@
package com.ccsens.braintraining.persist.dao;
import com.ccsens.braintraining.bean.po.RaffleActive;
import com.ccsens.braintraining.bean.po.RaffleTask;
import com.ccsens.braintraining.bean.vo.RaffleVo;
import org.apache.ibatis.annotations.Param;
@ -45,4 +47,26 @@ public interface RaffleDao {
* @param prizeId 奖品ID
*/
void decreasePrize(@Param("prizeId") Long prizeId);
/**
* 查询用户的中奖纪录
* @param userId 用户ID
* @return 中奖纪录
*/
List<RaffleVo.PrizeTime> queryUserPrize(@Param("userId") Long userId);
/**
* 查询任务关联的正在进行的活动
* @param taskId 任务ID
* @return 活动
*/
RaffleTask getRunningTask(@Param("taskId") Long taskId);
/**
* 查询关注公众号的次数
* @param taskId
* @param userId
* @return
*/
Integer countSubscribe(@Param("taskId") Long taskId, @Param("userId")Long userId);
}

26
src/main/java/com/ccsens/braintraining/service/IRaffleService.java

@ -32,4 +32,30 @@ public interface IRaffleService {
* @return 奖品
*/
RaffleVo.Prize draw(RaffleDto.ActiveId param, Long userId);
/**
* 查询用户的中奖纪录
* @param param 分页
* @param userId 用户ID
* @return 中奖纪录
*/
PageInfo<RaffleVo.PrizeTime> queryUserPrize(RaffleDto.SelfPrize param, Long userId);
/**
* 用户执行任务增加抽奖次数
* @param param 任务
* @param userId 用户
* @return 成功与否
*/
RaffleVo.DoTask doTask(RaffleDto.DoTask param, Long userId);
/**
* 检查用户关于任务的完成情况
* @param param 任务
* @param userId 用户
* @param token token
* @param deviceId 设备ID
* @return 完成情况
*/
RaffleVo.CheckTask checkTask(RaffleDto.DoTask param, Long userId, String token, String deviceId);
}

139
src/main/java/com/ccsens/braintraining/service/RaffleService.java

@ -1,27 +1,37 @@
package com.ccsens.braintraining.service;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.ccsens.braintraining.bean.dto.RaffleDto;
import com.ccsens.braintraining.bean.po.RaffleActive;
import com.ccsens.braintraining.bean.po.RaffleRecord;
import com.ccsens.braintraining.bean.dto.TallDto;
import com.ccsens.braintraining.bean.po.*;
import com.ccsens.braintraining.bean.vo.RaffleVo;
import com.ccsens.braintraining.bean.vo.TallVo;
import com.ccsens.braintraining.persist.dao.RaffleDao;
import com.ccsens.braintraining.persist.mapper.RaffleActiveMapper;
import com.ccsens.braintraining.persist.mapper.RaffleRecordMapper;
import com.ccsens.braintraining.persist.mapper.RaffleTaskParamMapper;
import com.ccsens.braintraining.persist.mapper.RaffleTimesMapper;
import com.ccsens.braintraining.util.BrainTrainingCodeError;
import com.ccsens.braintraining.util.BrainTrainingConstant;
import com.ccsens.util.bean.dto.QueryDto;
import com.ccsens.util.exception.BaseException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.Random;
import java.util.*;
/**
* @description:
@ -33,6 +43,8 @@ import java.util.Random;
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class RaffleService implements IRaffleService {
@Value("${url.subscriptWx}")
private String subscriptWxUrl;
@Resource
private Snowflake snowflake;
@Resource
@ -41,10 +53,22 @@ public class RaffleService implements IRaffleService {
private RaffleActiveMapper raffleActiveMapper;
@Resource
private RaffleRecordMapper raffleRecordMapper;
@Resource
private RaffleTimesMapper raffleTimesMapper;
@Resource
private RaffleTaskParamMapper raffleTaskParamMapper;
@Override
public RaffleVo.Active active(RaffleDto.Equipment param, Long userId) {
return raffleDao.queryActiveNow(param.getEquipmentId(), userId);
RaffleVo.Active active = raffleDao.queryActiveNow(param.getEquipmentId(), userId);
if (active != null) {
Integer remainTimes = raffleDao.countTimes(active.getActive().getActiveId(), userId);
active.getActive().setPrizeTimes(remainTimes);
}
return active;
}
@Override
@ -103,9 +127,112 @@ public class RaffleService implements IRaffleService {
record.setPrizeId(prize.getPrizeId());
record.setUserId(userId);
raffleRecordMapper.insertSelective(record);
// 设置最小
// 设置奖品剩余数-1
raffleDao.decreasePrize(prize.getPrizeId());
return prize;
}
}
@Override
public PageInfo<RaffleVo.PrizeTime> queryUserPrize(RaffleDto.SelfPrize param, Long userId) {
PageHelper.startPage(param.getPageNum(), param.getPageSize());
List<RaffleVo.PrizeTime> records = raffleDao.queryUserPrize(userId);
return new PageInfo(records);
}
@Override
public RaffleVo.DoTask doTask(RaffleDto.DoTask param, Long userId) {
// 判断
return null;
}
@Override
public RaffleVo.CheckTask checkTask(RaffleDto.DoTask param, Long userId, String token, String deviceId) {
RaffleVo.CheckTask checkTask = new RaffleVo.CheckTask();
// 判断活动是否是当前的活动
RaffleTask task = raffleDao.getRunningTask(param.getTaskId());
log.info("活动:{}", task);
if (task == null) {
checkTask.setFinishStatus(BrainTrainingConstant.Raffle.TASK_FINISH_END);
return checkTask;
}
// 判断是否已经有记录
List<RaffleTimes> raffleTimes = null;
RaffleTimesExample timesExample = new RaffleTimesExample();
timesExample.createCriteria().andTaskIdEqualTo(param.getTaskId())
.andUserIdEqualTo(userId).andFinishTypeGreaterThan(BrainTrainingConstant.Raffle.TASK_FINISH_NO);
switch (task.getPeriod()) {
case BrainTrainingConstant.Raffle.TASK_PERIOD_ALL:
raffleTimes = raffleTimesMapper.selectByExample(timesExample);
break;
case BrainTrainingConstant.Raffle.TASK_PERIOD_EVERY_DAY:
timesExample.createCriteria().andCreatedAtGreaterThanOrEqualTo(DateUtil.beginOfDay(new Date()));
raffleTimes = raffleTimesMapper.selectByExample(timesExample);
break;
default:
throw new BaseException(BrainTrainingCodeError.SETTING_ERROR);
}
// 执行的次数大于任务最大的执行次数,则不能再做
if (raffleTimes.size() >= task.getRunTimes()) {
checkTask.setFinishStatus(raffleTimes.get(0).getFinishType());
return checkTask;
}
// 判断是否以前做过了
if (task.getType() == BrainTrainingConstant.Raffle.TASK_TYPE_SUBSCRIBE) {
// 关注公众号
// 查询记录中有没有关注的是同一个公众号的
Integer recordTimes = raffleDao.countSubscribe(param.getTaskId(), userId);
if (recordTimes != null && recordTimes > 0) {
checkTask.setFinishStatus(BrainTrainingConstant.Raffle.TASK_FINISH_BEFORE);
return checkTask;
}
// 查询该用户是否已经关注了
// 查询公众号appId
RaffleTaskParamExample paramExample = new RaffleTaskParamExample();
paramExample.createCriteria().andTaskIdEqualTo(param.getTaskId()).andKeyWordEqualTo(BrainTrainingConstant.Raffle.TASK_PARAM_APP_ID);
paramExample.setOrderByClause("id desc limit 1");
List<RaffleTaskParam> params = raffleTaskParamMapper.selectByExample(paramExample);
if (CollectionUtil.isEmpty(params)) {
throw new BaseException(BrainTrainingCodeError.SETTING_ERROR);
}
String appId = params.get(0).getKeyValue();
byte status = pageSubscript(token, deviceId, appId);
} else if (task.getType() == BrainTrainingConstant.Raffle.TASK_TYPE_PERFECT) {
// TODO 查询详情表
}
checkTask.setFinishStatus(BrainTrainingConstant.Raffle.TASK_FINISH_NO);
return checkTask;
}
private byte pageSubscript(String token, String deviceId, String appId) {
TallDto.Tencent tencent = new TallDto.Tencent();
tencent.setAppId(appId);
QueryDto<TallDto.Tencent> dto = new QueryDto<>();
dto.setParam(tencent);
log.info("调用判断接口, dto:{}, token:{}", dto, token);
Map<String, String> tokenMap = new HashMap<>();
tokenMap.put(BrainTrainingConstant.User.AUTHORIZATION, token);
tokenMap.put(BrainTrainingConstant.User.DEVICE_ID, deviceId);
HttpResponse execute = HttpUtil.createPost(subscriptWxUrl).addHeaders(tokenMap).body(JSONObject.toJSONString(dto)).execute();
log.info("http:{}", HttpUtil.createPost(subscriptWxUrl).addHeaders(tokenMap).body(JSONObject.toJSONString(dto)));
log.info("调用判断用户是否关注公众号接口的结果:{}", execute);
if (execute == null || StrUtil.isEmpty(execute.body()) || execute.body().contains("<html") ) {
throw new BaseException(BrainTrainingCodeError.SYS_ERROR);
}
JSONObject json = JSONObject.parseObject(execute.body());
log.info("json:{}", json);
if (json.getIntValue(BrainTrainingConstant.CODE) != BrainTrainingCodeError.SUCCESS.getCode()) {
throw new BaseException(json.getIntValue(BrainTrainingConstant.CODE),json.getString(BrainTrainingConstant.MSG));
}
TallVo.UserOfficial official = JSONObject.parseObject(json.getString("data"), TallVo.UserOfficial.class);
return official.getStatus();
}
}

8
src/main/java/com/ccsens/braintraining/util/BrainTrainingCodeError.java

@ -9,8 +9,10 @@ import com.ccsens.util.CodeError;
*/
public class BrainTrainingCodeError extends CodeError {
public static final Code RAFFLE_ACTIVE_NOT_OPEN = new Code(501,"抽奖活动暂未开放,请开发后再参与活动。",true);
public static final Code RAFFLE_ACTIVE_NOT_TIMES = new Code(502,"您的抽奖机会已经用完了。",true);
public static final Code RAFFLE_ACTIVE_PRIZE_NO = new Code(503,"亟待运营人员补充奖品,请您稍后再试。",true);
public static final Code SETTING_ERROR = new Code(501,"配置错误,请联系运营成员修改。",true);
public static final Code RAFFLE_ACTIVE_NOT_OPEN = new Code(502,"抽奖活动暂未开放,请开发后再参与活动。",true);
public static final Code RAFFLE_ACTIVE_NOT_TIMES = new Code(503,"您的抽奖机会已经用完了。",true);
public static final Code RAFFLE_ACTIVE_PRIZE_NO = new Code(504,"亟待运营人员补充奖品,请您稍后再试。",true);
}

29
src/main/java/com/ccsens/braintraining/util/BrainTrainingConstant.java

@ -9,8 +9,37 @@ import com.ccsens.util.WebConstant;
*/
public class BrainTrainingConstant extends WebConstant {
public final static String CODE = "code";
public final static String MSG = "msg";
public static class User{
public final static String USER_IDS_KEY = "brain_training_user_ids";
public final static String AUTHORIZATION = "Authorization";
public final static String DEVICE_ID = "deviceId";
}
public static class Raffle{
/**完成状态 -1:活动已结束*/
public final static byte TASK_FINISH_END = -1;
/**完成状态 0:未完成*/
public final static byte TASK_FINISH_NO = 0;
/**完成状态 1:已完成*/
public final static byte TASK_FINISH_YES = 1;
/**完成状态 2:以前完成*/
public final static byte TASK_FINISH_BEFORE = 2;
/**执行周期,0:整个活动期间共N次*/
public final static byte TASK_PERIOD_ALL = 0;
/**执行周期,1:每天N次*/
public final static byte TASK_PERIOD_EVERY_DAY = 1;
/**执行类型 0:关注公众号*/
public final static byte TASK_TYPE_SUBSCRIBE = 0;
/**执行类型 1:完善信息*/
public final static byte TASK_TYPE_PERFECT = 0;
/**任务参数:appId*/
public final static String TASK_PARAM_APP_ID = "appId";
}
}

2
src/main/resources/application-dev.yml

@ -50,4 +50,4 @@ file:
imgDomain: http://127.0.0.1:7280/v1.0/uploads/
url:
token: http://101.201.226.163/gateway/ptostall/users/token
refreshToken: http://101.201.226.163/gateway/ptostall/users/refreshToken
subscriptWx: http://101.201.226.163/gateway/ptostall/wx/officialId

3
src/main/resources/application-prod.yml

@ -15,4 +15,5 @@ file:
domain: https://www.tall.wiki/braintraining/v1.0/
imgDomain: https://www.tall.wiki/braintraining/v1.0/uploads/
url:
token: http://101.201.226.163/gateway/ptostall/users/token
token: http://101.201.226.163/gateway/ptostall/users/token
subscriptWx: http://101.201.226.163/gateway/ptostall/wx/officialId

3
src/main/resources/application-test.yml

@ -15,4 +15,5 @@ file:
domain: http://test.tall.wiki/braintraining/v1.0/
imgDomain: http://test.tall.wiki/braintraining/v1.0/uploads/
url:
token: http://101.201.226.163/gateway/ptostall/users/token
token: http://101.201.226.163/gateway/ptostall/users/token
subscriptWx: http://101.201.226.163/gateway/ptostall/wx/officialId

4
src/main/resources/application.yml

@ -1,4 +1,4 @@
spring:
profiles:
active: test
include: common, util-test
active: dev
include: common, util-dev

79
src/main/resources/mapper_dao/RaffleDao.xml

@ -23,6 +23,7 @@
<result property="icon" column="taskIcon"/>
<result property="type" column="type"/>
<result property="finishStatus" column="finishStatus"/>
<result property="param" column="param"/>
</collection>
</resultMap>
<update id="decreasePrize">
@ -47,7 +48,8 @@
t.NAME AS taskName,
t.icon AS taskIcon,
t.type,
IF( t2.id IS NULL, 0, t2.finish_type + 1 ) AS finishStatus
IF( t2.id IS NULL, 0, t2.finish_type ) AS finishStatus,
param.param
FROM
(select * from t_raffle_active WHERE equipment_id = #{equipmentId} AND start_time &lt;= UNIX_TIMESTAMP(now()) * 1000 AND end_time &gt;= UNIX_TIMESTAMP(now()) * 1000 AND rec_status = 0 order by id desc limit 1) a
LEFT JOIN t_raffle_prize p ON a.id = p.active_id
@ -61,6 +63,24 @@
<otherwise>AND t2.id is null</otherwise>
</choose>
AND t2.rec_status = 0
LEFT JOIN (SELECT
t.id,
concat( '{', word, '}' ) AS param
FROM
(
SELECT
t.id,
GROUP_CONCAT(
concat( '"', key_word, '":"', key_value, '"' )) AS word
FROM
t_raffle_task_param p,
t_raffle_task t
WHERE
p.task_id = t.id
AND t.active_id = 1
AND t.rec_status = 0
AND p.rec_status = 0
GROUP BY t.id ) t) param on t.id = param.id
</select>
<select id="queryPrizeRecord" resultType="com.ccsens.braintraining.bean.vo.RaffleVo$PrizeRecord">
@ -97,6 +117,7 @@
t1.id = t2.task_id
AND t1.active_id = #{activeId}
AND t2.user_id = #{userId}
AND t2.finish_type = 0
AND t1.rec_status = 0
AND t2.rec_status = 0
) t,
@ -132,4 +153,60 @@
ORDER BY
id
</select>
<select id="queryUserPrize" resultType="com.ccsens.braintraining.bean.vo.RaffleVo$PrizeTime">
SELECT
p.id AS prizeId,
p.NAME,
p.icon,
r.created_at AS time
FROM
t_raffle_record r,
t_raffle_prize p
WHERE
r.prize_id = p.id
AND r.user_id = #{userId}
AND p.type > 0
AND r.rec_status = 0
AND p.rec_status = 0
order by r.id desc
</select>
<select id="getRunningTask" resultType="com.ccsens.braintraining.bean.po.RaffleTask">
SELECT
t.*
FROM
t_raffle_active a,
t_raffle_task t
WHERE
a.id = t.active_id
AND t.id = #{taskId}
AND a.start_time &lt;= UNIX_TIMESTAMP( now()) * 1000 AND a.end_time &gt;= UNIX_TIMESTAMP(now()) * 1000
AND a.rec_status = 0
AND t.rec_status = 0
</select>
<select id="countSubscribe" resultType="java.lang.Integer">
SELECT
count(*)
FROM
t_raffle_task t1,
t_raffle_task_param p1,
t_raffle_task t2,
t_raffle_task_param p2,
t_raffle_times t
WHERE
t1.id = p1.task_id
AND p1.key_word = 'appId'
AND t2.id = p2.id
AND p2.key_word = 'appId'
AND p1.key_value = p2.key_value
AND t.task_id = t2.id
AND t1.id = #{taskId}
AND t.user_id = #{userId}
AND t.finish_type > 0
AND t1.rec_status = 0
AND p1.rec_status = 0
AND t2.rec_status = 0
AND p2.rec_status = 0
AND t.rec_status = 0
</select>
</mapper>
Loading…
Cancel
Save