|
@@ -1,5 +1,27 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
@@ -23,6 +45,7 @@ import com.ym.mec.im.ImFeignService;
|
|
|
import com.ym.mec.thirdparty.eseal.ESealPlugin;
|
|
|
import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
+import com.ym.mec.util.date.DateUtil;
|
|
|
import com.ym.mec.util.http.HttpUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -223,81 +246,58 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public StudentRegistration addStudent(StudentRegistration studentRegistration) throws Exception {
|
|
|
- String key = "_student_registration";
|
|
|
- long threadId = Thread.currentThread().getId();
|
|
|
- if (!redisCache.getLocked(key, threadId, 10)) {
|
|
|
- throw new BizException("系统繁忙,请稍后再试");
|
|
|
+ Integer userId = studentRegistration.getUserId();
|
|
|
+
|
|
|
+ Student student = studentDao.getLocked(userId);
|
|
|
+ if (student == null) {
|
|
|
+ throw new BizException("查询学生信息失败");
|
|
|
}
|
|
|
- try {
|
|
|
- Date date = new Date();
|
|
|
- Integer userId = 0;
|
|
|
- SysUser sysUser = studentRegistrationDao.getSysUserByPhone(studentRegistration.getParentsPhone());
|
|
|
- if (sysUser == null) {
|
|
|
- sysUser = new SysUser();
|
|
|
- sysUser.setPhone(studentRegistration.getParentsPhone());
|
|
|
- sysUser.setCreateTime(date);
|
|
|
- sysUser.setUpdateTime(date);
|
|
|
- sysUser.setLockFlag(0);
|
|
|
- sysUser.setDelFlag(com.ym.mec.auth.api.enums.YesOrNoEnum.NO);
|
|
|
- sysUser.setUserType("STUDENT");
|
|
|
- sysUser.setGender(studentRegistration.getGender());
|
|
|
- sysUser.setOrganId(studentRegistration.getOrganId());
|
|
|
- sysUser.setRealName(studentRegistration.getParentsName());
|
|
|
- sysUser.setUsername(studentRegistration.getName());
|
|
|
- sysUser.setIdCardNo(studentRegistration.getIdCardNo());
|
|
|
- sysUser.setBirthdate(studentRegistration.getBirthdate());
|
|
|
- teacherDao.addSysUser(sysUser);
|
|
|
- userId = sysUser.getId();
|
|
|
- // 添加用户现金账户
|
|
|
- sysUserCashAccountDao.insert(new SysUserCashAccount(userId, "CNY"));
|
|
|
- // 注册到融云
|
|
|
- if (StringUtils.isEmpty(sysUser.getAvatar())) {
|
|
|
- sysUser.setAvatar(sysConfigDao.findConfigValue(SysConfigService.USER_DEFAULT_HEAD_URL));
|
|
|
- }
|
|
|
- ImResult register = imFeignService.register(new ImUserModel(userId.toString(), sysUser.getUsername(), sysUser.getAvatar()));
|
|
|
- sysUser.setImToken(register.getToken());
|
|
|
- } else {
|
|
|
- if (StringUtils.isNotEmpty(sysUser.getUsername())) {
|
|
|
- if (!sysUser.getUsername().equals(studentRegistration.getName())) {
|
|
|
- throw new BizException("操作失败:账户已被注册");
|
|
|
- }
|
|
|
- }
|
|
|
- if (!sysUser.getUserType().contains("STUDENT")) {
|
|
|
- sysUser.setUserType(sysUser.getUserType() + ",STUDENT");
|
|
|
- }
|
|
|
- sysUser.setPhone(studentRegistration.getParentsPhone());
|
|
|
- sysUser.setOrganId(studentRegistration.getOrganId());
|
|
|
- sysUser.setRealName(studentRegistration.getParentsName());
|
|
|
|
|
|
- sysUser.setUsername(studentRegistration.getName());
|
|
|
- sysUser.setGender(studentRegistration.getGender());
|
|
|
- sysUser.setBirthdate(studentRegistration.getBirthdate());
|
|
|
- sysUser.setCreateTime(date);
|
|
|
- sysUser.setUpdateTime(date);
|
|
|
- teacherDao.updateUser(sysUser);
|
|
|
- }
|
|
|
+ StudentRegistration hasReg = getByPhoneAndMusicGroupId(studentRegistration.getMusicGroupId(), studentRegistration.getParentsPhone());
|
|
|
+ if (hasReg != null) {
|
|
|
+ throw new BizException("该乐团您已报名");
|
|
|
+ }
|
|
|
|
|
|
- studentRegistration.setActualSubjectId(studentRegistration.getSubjectId());
|
|
|
- studentRegistration.setCreateTime(date);
|
|
|
- studentRegistration.setUpdateTime(date);
|
|
|
- studentRegistration.setUserId(sysUser.getId());
|
|
|
- studentRegistrationDao.insert(studentRegistration);
|
|
|
- studentRegistrationDao.updateCurrentClass(studentRegistration);
|
|
|
- // 增加报名学生数
|
|
|
- musicGroupSubjectPlanService.addApplyStudentNum(studentRegistration.getMusicGroupId(), studentRegistration.getSubjectId(), 1);
|
|
|
- // 报名成功后,发送短信
|
|
|
- // String studentApplyUrl = sysConfigDao.findConfigValue(SysConfigService.STUDENT_APPLY_URL) + studentRegistration.getMusicGroupId();
|
|
|
- String serverPhone = sysConfigDao.findConfigValue(SysConfigService.SERVER_PHONE);
|
|
|
- Subject subject = subjectDao.get(studentRegistration.getActualSubjectId());
|
|
|
- // MusicGroup musicGroup = musicGroupDao.get(studentRegistration.getMusicGroupId());
|
|
|
-
|
|
|
- Map<Integer, String> map = new HashMap<>(1);
|
|
|
- map.put(studentRegistration.getUserId(), studentRegistration.getParentsPhone());
|
|
|
- sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS, MessageTypeEnum.SMS_APPLY_MESSAGE, map, null, 0, "", "",
|
|
|
- studentRegistration.getParentsName(), subject.getName(), serverPhone);
|
|
|
- } finally {
|
|
|
- redisCache.releaseLocked(key, threadId);
|
|
|
+ Date date = new Date();
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserByMobile(studentRegistration.getParentsPhone());
|
|
|
+ if (sysUser == null) {
|
|
|
+ throw new BizException("用户信息查询失败");
|
|
|
}
|
|
|
+
|
|
|
+ if (!sysUser.getUserType().contains("STUDENT")) {
|
|
|
+ sysUser.setUserType(sysUser.getUserType() + ",STUDENT");
|
|
|
+ }
|
|
|
+ sysUser.setPhone(studentRegistration.getParentsPhone());
|
|
|
+ sysUser.setOrganId(studentRegistration.getOrganId());
|
|
|
+ sysUser.setRealName(studentRegistration.getParentsName());
|
|
|
+
|
|
|
+ sysUser.setUsername(studentRegistration.getName());
|
|
|
+ sysUser.setGender(studentRegistration.getGender());
|
|
|
+ sysUser.setBirthdate(studentRegistration.getBirthdate());
|
|
|
+ sysUser.setCreateTime(date);
|
|
|
+ sysUser.setUpdateTime(date);
|
|
|
+ teacherDao.updateUser(sysUser);
|
|
|
+
|
|
|
+ studentRegistration.setActualSubjectId(studentRegistration.getSubjectId());
|
|
|
+ studentRegistration.setCreateTime(date);
|
|
|
+ studentRegistration.setUpdateTime(date);
|
|
|
+ studentRegistration.setUserId(sysUser.getId());
|
|
|
+ studentRegistration.setMusicGroupStatus(StudentMusicGroupStatusEnum.APPLY);
|
|
|
+ studentRegistrationDao.insert(studentRegistration);
|
|
|
+
|
|
|
+ // 增加报名学生数
|
|
|
+ musicGroupSubjectPlanService.addApplyStudentNum(studentRegistration.getMusicGroupId(), studentRegistration.getSubjectId(), 1);
|
|
|
+ // 报名成功后,发送短信
|
|
|
+ // String studentApplyUrl = sysConfigDao.findConfigValue(SysConfigService.STUDENT_APPLY_URL) + studentRegistration.getMusicGroupId();
|
|
|
+ String serverPhone = sysConfigDao.findConfigValue(SysConfigService.SERVER_PHONE);
|
|
|
+ Subject subject = subjectDao.get(studentRegistration.getActualSubjectId());
|
|
|
+ // MusicGroup musicGroup = musicGroupDao.get(studentRegistration.getMusicGroupId());
|
|
|
+
|
|
|
+ Map<Integer, String> map = new HashMap<>(1);
|
|
|
+ map.put(studentRegistration.getUserId(), studentRegistration.getParentsPhone());
|
|
|
+ sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS, MessageTypeEnum.SMS_APPLY_MESSAGE, map, null, 0, "", "",
|
|
|
+ studentRegistration.getParentsName(), subject.getName(), serverPhone);
|
|
|
+
|
|
|
return studentRegistration;
|
|
|
}
|
|
|
|