|
@@ -1,12 +1,16 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
-import com.ym.mec.biz.dal.dao.ActivityUserMapperDao;
|
|
|
-import com.ym.mec.biz.dal.dao.VipGroupActivityDao;
|
|
|
+import com.ym.mec.auth.api.entity.SysUser;
|
|
|
+import com.ym.mec.biz.dal.dao.*;
|
|
|
import com.ym.mec.biz.dal.dto.ActivityQueryDto;
|
|
|
import com.ym.mec.biz.dal.dto.ActivityStudentAdjustDto;
|
|
|
import com.ym.mec.biz.dal.dto.ActivityStudentDto;
|
|
|
+import com.ym.mec.biz.dal.dto.ActivityUserMapperAddDto;
|
|
|
import com.ym.mec.biz.dal.entity.ActivityUserMapper;
|
|
|
+import com.ym.mec.biz.dal.entity.Student;
|
|
|
+import com.ym.mec.biz.dal.entity.SysUserCashAccountLog;
|
|
|
import com.ym.mec.biz.dal.entity.VipGroupActivity;
|
|
|
+import com.ym.mec.biz.dal.enums.ReturnFeeEnum;
|
|
|
import com.ym.mec.biz.dal.page.ActivityStudentQueryInfo;
|
|
|
import com.ym.mec.biz.service.ActivityUserMapperService;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
@@ -25,6 +29,9 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.ym.mec.biz.dal.enums.GroupType.ACTIVITY;
|
|
|
+import static com.ym.mec.biz.dal.enums.GroupType.SUBJECT_CHANGE;
|
|
|
+
|
|
|
@Service
|
|
|
public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, ActivityUserMapper> implements ActivityUserMapperService {
|
|
|
|
|
@@ -32,6 +39,12 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
|
|
|
private ActivityUserMapperDao activityUserMapperDao;
|
|
|
@Autowired
|
|
|
private VipGroupActivityDao vipGroupActivityDao;
|
|
|
+ @Autowired
|
|
|
+ private StudentDao studentDao;
|
|
|
+ @Autowired
|
|
|
+ private TeacherDao teacherDao;
|
|
|
+ @Autowired
|
|
|
+ private SysUserCashAccountLogDao sysUserCashAccountLogDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Integer, ActivityUserMapper> getDAO() {
|
|
@@ -90,11 +103,13 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void add(List<ActivityStudentAdjustDto> activityStudentAdjustDtos) {
|
|
|
- if(activityStudentAdjustDtos == null || activityStudentAdjustDtos.size() == 0){
|
|
|
+ public void add(ActivityUserMapperAddDto activityUserMapperAddDto) {
|
|
|
+ List<ActivityStudentAdjustDto> activityStudentAdjustDtos = activityUserMapperAddDto.getActivityStudentAdjustDtos();
|
|
|
+ if(activityStudentAdjustDtos == null || activityStudentAdjustDtos.size() == 0){
|
|
|
throw new BizException("请选择学员");
|
|
|
}
|
|
|
- Integer activityId = activityStudentAdjustDtos.get(0).getActivityId();
|
|
|
+ Integer activityId = activityUserMapperAddDto.getActivityId();
|
|
|
+ String memo = activityUserMapperAddDto.getMemo();
|
|
|
VipGroupActivity activity = vipGroupActivityDao.get(activityId);
|
|
|
if(activity == null){
|
|
|
throw new BizException("活动信息不存在");
|
|
@@ -103,7 +118,8 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
|
|
|
throw new BizException("操作失败:只有课程活动支持此操作");
|
|
|
}
|
|
|
List<Integer> studentIds = activityStudentAdjustDtos.stream().map(e -> e.getUserId()).collect(Collectors.toList());
|
|
|
-
|
|
|
+ List<Student> studentTeacher = studentDao.findByStudentIds(studentIds);
|
|
|
+ Map<Integer, List<Student>> collect = studentTeacher.stream().collect(Collectors.groupingBy(Student::getUserId));
|
|
|
String courseType = activity.getCourseType();
|
|
|
Integer giveCourseNum = activity.getGiveCourseNum();
|
|
|
String giveCourseType = activity.getGiveCourseType();
|
|
@@ -118,32 +134,68 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
|
|
|
if(activityUserMapperNum <= 0){
|
|
|
throw new BizException("操作失败:加课次数不可为空");
|
|
|
}
|
|
|
+ List<Student> students = collect.get(adjustDto.getUserId());
|
|
|
+ Integer teacherId = null;
|
|
|
+ if(students != null && students.size() > 0){
|
|
|
+ teacherId = students.get(0).getTeacherId();
|
|
|
+ }
|
|
|
for (int i = 0; i < activityUserMapperNum; i++) {
|
|
|
ActivityUserMapper activityUserMapper = new ActivityUserMapper();
|
|
|
activityUserMapper.setActivityId(activityId);
|
|
|
activityUserMapper.setUserId(adjustDto.getUserId());
|
|
|
activityUserMapper.setActualPrice(BigDecimal.ZERO);
|
|
|
activityUserMapper.setReturnFee(false);
|
|
|
-// activityUserMapper.setTeacherId();
|
|
|
- if("VIP".equals(courseType)){
|
|
|
- activityUserMapper.setVipFlag(1);
|
|
|
- }else {
|
|
|
- activityUserMapper.setPracticeFlag(1);
|
|
|
+ activityUserMapper.setTeacherId(teacherId);
|
|
|
+ activityUserMapper.setAddMemo(memo);
|
|
|
+ if(adjustDto.getCourseNum() > i){
|
|
|
+ if("VIP".equals(courseType)){
|
|
|
+ activityUserMapper.setVipFlag(1);
|
|
|
+ }else {
|
|
|
+ activityUserMapper.setPracticeFlag(1);
|
|
|
+ }
|
|
|
}
|
|
|
- if(giveCourseNum != null && giveCourseNum > 0){
|
|
|
+
|
|
|
+ if(adjustDto.getGiveCourseNum() > i && giveCourseNum != null && giveCourseNum > 0){
|
|
|
if("VIP".equals(giveCourseType)){
|
|
|
activityUserMapper.setGiveVipFlag(1);
|
|
|
}else {
|
|
|
activityUserMapper.setGivePracticeFlag(1);
|
|
|
}
|
|
|
}
|
|
|
+ activityUserMappers.add(activityUserMapper);
|
|
|
}
|
|
|
}
|
|
|
+ activityUserMapperDao.batchInsert(activityUserMappers);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void cut(Integer activityUserMapperId, String memo) {
|
|
|
-
|
|
|
+ public void cut(Integer activityUserMapperId, String memo, BigDecimal amount) {
|
|
|
+ ActivityUserMapper activityUserMapper = activityUserMapperDao.get(activityUserMapperId);
|
|
|
+ if(activityUserMapper.getVipFlag() == 2 ||
|
|
|
+ activityUserMapper.getGiveVipFlag() == 2 ||
|
|
|
+ activityUserMapper.getPracticeGroupId() == 2 ||
|
|
|
+ activityUserMapper.getGivePracticeFlag() == 2 || activityUserMapper.getReturnFee()){
|
|
|
+ throw new BizException("操作失败:活动已消耗");
|
|
|
+ }
|
|
|
+ activityUserMapper.setCutMemo(memo);
|
|
|
+ activityUserMapper.setReturnFee(true);
|
|
|
+ activityUserMapperDao.update(activityUserMapper);
|
|
|
+ if(amount == null || amount.compareTo(BigDecimal.ZERO) <= 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(amount.compareTo(activityUserMapper.getActualPrice()) > 0){
|
|
|
+ throw new BizException("操作失败:退费金额不得超过购买金额{}",activityUserMapper.getActualPrice());
|
|
|
+ }
|
|
|
+ SysUser user = teacherDao.getUser(activityUserMapper.getUserId());
|
|
|
+ SysUserCashAccountLog sysUserCashAccountLog = new SysUserCashAccountLog();
|
|
|
+ sysUserCashAccountLog.setUserId(activityUserMapper.getUserId());
|
|
|
+ sysUserCashAccountLog.setGroupType(ACTIVITY);
|
|
|
+ sysUserCashAccountLog.setOrganId(user.getOrganId());
|
|
|
+ sysUserCashAccountLog.setGroupId(activityUserMapperId.toString());
|
|
|
+ sysUserCashAccountLog.setAmount(amount);
|
|
|
+ sysUserCashAccountLog.setReturnFeeType(ReturnFeeEnum.CANCEL_ACTIVITY_COURSE);
|
|
|
+ sysUserCashAccountLog.setComment("取消活动排课");
|
|
|
+ sysUserCashAccountLogDao.insert(sysUserCashAccountLog);
|
|
|
}
|
|
|
}
|