Explorar el Código

1.学生端添加激活码列表接口和激活码兑换接口

yuanliang hace 1 año
padre
commit
d00bd68173

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/TenantActivationCodeService.java

@@ -44,4 +44,6 @@ public interface TenantActivationCodeService extends IService<TenantActivationCo
      Boolean update(TenantActivationCodeWrapper.TenantActivationCode tenantActivationCode);
 
     void sendActivationCode(Long tenantId, Long tenantAlbumPurchaseId, List<String> activationCodeList, List<Long> studentIdList);
+
+    void active(String activationCode, Long studentId);
 }

+ 55 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantActivationCodeServiceImpl.java

@@ -8,17 +8,22 @@ import com.yonge.cooleshow.biz.dal.dao.StudentDao;
 import com.yonge.cooleshow.biz.dal.entity.Student;
 import com.yonge.cooleshow.biz.dal.entity.SysUser;
 import com.yonge.cooleshow.biz.dal.entity.TenantActivationCode;
+import com.yonge.cooleshow.biz.dal.entity.TenantAlbumPurchase;
 import com.yonge.cooleshow.biz.dal.mapper.SysUserMapper;
 import com.yonge.cooleshow.biz.dal.mapper.TenantActivationCodeMapper;
+import com.yonge.cooleshow.biz.dal.mapper.TenantAlbumPurchaseMapper;
 import com.yonge.cooleshow.biz.dal.service.TenantActivationCodeService;
 import com.yonge.cooleshow.biz.dal.wrapper.TenantActivationCodeWrapper;
 import com.yonge.toolset.base.exception.BizException;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
+import org.redisson.api.RLock;
+import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -37,6 +42,9 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
     @Autowired
     private SysUserMapper sysUserMapper;
 
+    @Autowired
+    private TenantAlbumPurchaseMapper tenantAlbumPurchaseMapper;
+
     /**
      * 查询详情
      *
@@ -135,4 +143,51 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
             }
         }
     }
+
+    @Override
+    public void active(String activationCode, Long studentId) {
+        Student student = studentDao.selectById(studentId);
+        if (student == null) {
+            throw new BizException("学生不存在");
+        }
+        Long tenantId = -1L;
+        if (student.getTenantId() != null) {
+            tenantId = student.getTenantId();
+        }
+
+        TenantActivationCode code = this.lambdaQuery().eq(TenantActivationCode::getTenantId, tenantId)
+                .eq(TenantActivationCode::getActivationCode, activationCode)
+                .last("limit 1").one();
+        if (code == null) {
+            throw new BizException("激活码不存在");
+        }
+        if (Boolean.TRUE.equals(code.getActivationStatus())) {
+            throw new BizException("激活码已经被使用");
+        }
+
+        // 通过状态和ID同时判断更新是否存在竞争
+        boolean update = this.lambdaUpdate()
+                .set(TenantActivationCode::getActivationStatus, true)
+                .set(TenantActivationCode::getActivationUserId, student.getUserId())
+                .set(TenantActivationCode::getActivationTime, new Date())
+                .eq(TenantActivationCode::getId, code.getId())
+                .eq(TenantActivationCode::getActivationStatus, false)
+                .update();
+        if (!update) {
+            throw new BizException("激活码已经被使用");
+        }
+
+        // todo 更新会员信息,如果更新异常,回滚激活码
+
+        // 更新购买记录中激活码使用统计数量值
+        Integer activeCodeNumber = this.lambdaQuery()
+                .eq(TenantActivationCode::getTenantId, tenantId)
+                .eq(TenantActivationCode::getTenantAlbumPurchaseId, code.getTenantAlbumPurchaseId())
+                .eq(TenantActivationCode::getActivationStatus, true).count();
+
+        TenantAlbumPurchase tenantAlbumPurchase = new TenantAlbumPurchase();
+        tenantAlbumPurchase.setId(code.getTenantAlbumPurchaseId());
+        tenantAlbumPurchase.setActiveQuantity(activeCodeNumber);
+        tenantAlbumPurchaseMapper.updateById(tenantAlbumPurchase);
+    }
 }

+ 3 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/TenantActivationCodeWrapper.java

@@ -46,6 +46,9 @@ public class TenantActivationCodeWrapper {
         @ApiModelProperty("激活状态")
         private Boolean activationStatus;
 
+        @ApiModelProperty("激活手机号码")
+        private String activationPhone;
+
         @ApiModelProperty("激活开始")
         private Date activationStartTime;
 

+ 4 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantActivationCodeMapper.xml

@@ -40,6 +40,9 @@
             <if test="param.activationStatus != null">
                 AND t.activation_status_ = #{param.activationStatus}
             </if>
+            <if test="param.activationPhone != null">
+                AND t.activation_phone_ = #{param.activationPhone}
+            </if>
             <if test="param.activationStartTime != null">
                 AND t.activation_time_ >= #{param.activationStartTime}
             </if>
@@ -47,5 +50,6 @@
                 AND #{param.activationEndTime} >= t.activation_time_
             </if>
         </where>
+        order by t.activation_status_ asc, t.id_ desc
     </select>
 </mapper>

+ 73 - 0
cooleshow-user/user-student/src/main/java/com/yonge/cooleshow/student/controller/TenantActivationCodeController.java

@@ -0,0 +1,73 @@
+package com.yonge.cooleshow.student.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.microsvc.toolkit.common.response.paging.PageInfo;
+import com.microsvc.toolkit.common.response.paging.QueryInfo;
+import com.microsvc.toolkit.common.webportal.exception.BizException;
+import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
+import com.yonge.cooleshow.auth.api.entity.SysUser;
+import com.yonge.cooleshow.biz.dal.entity.Student;
+import com.yonge.cooleshow.biz.dal.service.StudentService;
+import com.yonge.cooleshow.biz.dal.service.TenantActivationCodeService;
+import com.yonge.cooleshow.biz.dal.wrapper.TenantActivationCodeWrapper;
+import com.yonge.cooleshow.common.controller.BaseController;
+import com.yonge.cooleshow.common.entity.HttpResponseResult;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+
+@Slf4j
+@Validated
+@RestController
+@RequestMapping("/tenantActivationCode")
+@Api(tags = "机构激活码")
+public class TenantActivationCodeController extends BaseController {
+
+    @Autowired
+    private TenantActivationCodeService tenantActivationCodeService;
+
+    @Autowired
+    private SysUserFeignService sysUserFeignService;
+
+    @Autowired
+    private StudentService studentService;
+
+    @ApiOperation(value = "查询分页", notes = "机构激活码- 传入 TenantActivationCodeVo.TenantActivationCodeQuery")
+    @PostMapping("/page")
+    public HttpResponseResult<PageInfo<TenantActivationCodeWrapper.TenantActivationCode>> page(
+            @RequestBody TenantActivationCodeWrapper.TenantActivationCodeQuery query) {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if (sysUser == null || null == sysUser.getId()) {
+            throw new BizException("请登录");
+        }
+        Student student = studentService.getById(sysUser.getId());
+        if (student == null) {
+            throw new BizException("学生不存在");
+        }
+        query.setActivationPhone(sysUser.getPhone());
+        query.setTenantId(student.getTenantId());
+        // 查询数据
+        IPage<TenantActivationCodeWrapper.TenantActivationCode> pages =
+                tenantActivationCodeService.selectPage(QueryInfo.getPage(query), query);
+        return succeed(QueryInfo.pageInfo(pages, pages.getRecords()));
+    }
+
+    @ApiOperation(value = "激活激活码")
+    @PostMapping("/active")
+    public HttpResponseResult<Boolean> active(@RequestParam("activationCode") String activationCode) {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if (sysUser == null || null == sysUser.getId()) {
+            throw new BizException("请登录");
+        }
+        tenantActivationCodeService.active(activationCode, sysUser.getId());
+        return succeed();
+    }
+}