|
@@ -1,15 +1,27 @@
|
|
|
package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
+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.wrapper.TenantActivationCodeWrapper;
|
|
|
+import com.yonge.cooleshow.biz.dal.mapper.SysUserMapper;
|
|
|
import com.yonge.cooleshow.biz.dal.mapper.TenantActivationCodeMapper;
|
|
|
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.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 机构激活码
|
|
@@ -19,48 +31,108 @@ import com.yonge.cooleshow.biz.dal.service.TenantActivationCodeService;
|
|
|
@Service
|
|
|
public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivationCodeMapper, TenantActivationCode> implements TenantActivationCodeService {
|
|
|
|
|
|
- /**
|
|
|
+ @Autowired
|
|
|
+ private StudentDao studentDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysUserMapper sysUserMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
* 查询详情
|
|
|
+ *
|
|
|
* @param id 详情ID
|
|
|
* @return TenantActivationCode
|
|
|
*/
|
|
|
- @Override
|
|
|
+ @Override
|
|
|
public TenantActivationCode detail(Long id) {
|
|
|
-
|
|
|
+
|
|
|
return baseMapper.selectById(id);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 分页查询
|
|
|
- * @param page IPage<TenantActivationCode>
|
|
|
+ *
|
|
|
+ * @param page IPage<TenantActivationCode>
|
|
|
* @param query TenantActivationCodeWrapper.TenantActivationCodeQuery
|
|
|
* @return IPage<TenantActivationCode>
|
|
|
*/
|
|
|
@Override
|
|
|
- public IPage<TenantActivationCode> selectPage(IPage<TenantActivationCode> page, TenantActivationCodeWrapper.TenantActivationCodeQuery query) {
|
|
|
-
|
|
|
+ public IPage<TenantActivationCodeWrapper.TenantActivationCode> selectPage(IPage<TenantActivationCodeWrapper.TenantActivationCode> page,
|
|
|
+ TenantActivationCodeWrapper.TenantActivationCodeQuery query) {
|
|
|
+
|
|
|
return page.setRecords(baseMapper.selectPage(page, query));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 添加
|
|
|
+ *
|
|
|
* @param tenantActivationCode TenantActivationCodeWrapper.TenantActivationCode
|
|
|
* @return Boolean
|
|
|
*/
|
|
|
@Override
|
|
|
- public Boolean add(TenantActivationCodeWrapper.TenantActivationCode tenantActivationCode) {
|
|
|
-
|
|
|
+ public Boolean add(TenantActivationCodeWrapper.TenantActivationCode tenantActivationCode) {
|
|
|
+
|
|
|
return this.save(JSON.parseObject(tenantActivationCode.jsonString(), TenantActivationCode.class));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新
|
|
|
+ *
|
|
|
* @param tenantActivationCode TenantActivationCodeWrapper.TenantActivationCode
|
|
|
* @return Boolean
|
|
|
*/
|
|
|
@Override
|
|
|
- public Boolean update(TenantActivationCodeWrapper.TenantActivationCode tenantActivationCode){
|
|
|
+ public Boolean update(TenantActivationCodeWrapper.TenantActivationCode tenantActivationCode) {
|
|
|
+
|
|
|
+ return this.updateById(JSON.parseObject(tenantActivationCode.jsonString(), TenantActivationCode.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void sendActivationCode(Long tenantId, Long tenantAlbumPurchaseId, List<String> activationCodeList,
|
|
|
+ List<Long> studentIdList) {
|
|
|
+ QueryWrapper<TenantActivationCode> queryWrapper = new QueryWrapper<>();
|
|
|
+ if (CollectionUtils.isEmpty(activationCodeList)) {
|
|
|
+ // 入参为空走批量发放方式
|
|
|
+ queryWrapper.lambda().eq(TenantActivationCode::getTenantId, tenantId)
|
|
|
+ .eq(TenantActivationCode::getTenantAlbumPurchaseId, tenantAlbumPurchaseId)
|
|
|
+ .eq(TenantActivationCode::getActivationStatus, false);
|
|
|
+ } else {
|
|
|
+ queryWrapper.lambda().eq(TenantActivationCode::getTenantId, tenantId)
|
|
|
+ .eq(TenantActivationCode::getTenantAlbumPurchaseId, tenantAlbumPurchaseId)
|
|
|
+ .in(TenantActivationCode::getActivationCode, activationCodeList)
|
|
|
+ .eq(TenantActivationCode::getActivationStatus, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<TenantActivationCode> tenantActivationCodes = baseMapper.selectList(queryWrapper);
|
|
|
+ if (tenantActivationCodes.isEmpty()) {
|
|
|
+ throw new BizException("无可发放的激活码");
|
|
|
+ }
|
|
|
+
|
|
|
+ QueryWrapper<Student> studentQueryWrapper = new QueryWrapper<>();
|
|
|
+ studentQueryWrapper.lambda().eq(Student::getTenantId, tenantId)
|
|
|
+ .in(Student::getUserId, studentIdList);
|
|
|
+ List<Student> students = studentDao.selectList(studentQueryWrapper);
|
|
|
+ if (tenantActivationCodes.size() < students.size()) {
|
|
|
+ throw new BizException("学生的数量不能大于可用的激活码数量");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> studentIds = students.stream().map(Student::getUserId).collect(Collectors.toList());
|
|
|
+ Map<Long, String> idPhoneMap = sysUserMapper.selectBatchIds(studentIds).stream()
|
|
|
+ .collect(Collectors.toMap(SysUser::getId, SysUser::getPhone));
|
|
|
|
|
|
- return this.updateById(JSON.parseObject(tenantActivationCode.jsonString(), TenantActivationCode.class));
|
|
|
+ for (Long studentId : studentIds) {
|
|
|
+ for (TenantActivationCode tenantActivationCode : tenantActivationCodes) {
|
|
|
+ boolean update = this.lambdaUpdate()
|
|
|
+ .set(TenantActivationCode::getSendStatus, "SEND")
|
|
|
+ .set(TenantActivationCode::getActivationPhone, idPhoneMap.get(studentId))
|
|
|
+ .eq(TenantActivationCode::getActivationStatus, false)
|
|
|
+ .eq(TenantActivationCode::getId, tenantActivationCode.getId())
|
|
|
+ .update();
|
|
|
+ if (!update) {
|
|
|
+ throw new BizException("激活码已被激活:" + tenantActivationCode.getActivationCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|