|
@@ -1,28 +1,50 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
|
|
-import com.ym.mec.biz.dal.dao.ActivityUserMapperDao;
|
|
|
|
|
|
|
+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.ActivityQueryDto;
|
|
|
|
|
+import com.ym.mec.biz.dal.dto.ActivityStudentAdjustDto;
|
|
|
import com.ym.mec.biz.dal.dto.ActivityStudentDto;
|
|
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.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.dal.page.ActivityStudentQueryInfo;
|
|
|
import com.ym.mec.biz.service.ActivityUserMapperService;
|
|
import com.ym.mec.biz.service.ActivityUserMapperService;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
|
|
+import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
import com.ym.mec.common.page.PageInfo;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
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
|
|
@Service
|
|
|
public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, ActivityUserMapper> implements ActivityUserMapperService {
|
|
public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, ActivityUserMapper> implements ActivityUserMapperService {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ActivityUserMapperDao activityUserMapperDao;
|
|
private ActivityUserMapperDao activityUserMapperDao;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private VipGroupActivityDao vipGroupActivityDao;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private StudentDao studentDao;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TeacherDao teacherDao;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysUserCashAccountLogDao sysUserCashAccountLogDao;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public BaseDAO<Integer, ActivityUserMapper> getDAO() {
|
|
public BaseDAO<Integer, ActivityUserMapper> getDAO() {
|
|
@@ -78,4 +100,102 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
|
|
|
pageInfo.setRows(dataList);
|
|
pageInfo.setRows(dataList);
|
|
|
return pageInfo;
|
|
return pageInfo;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void add(ActivityUserMapperAddDto activityUserMapperAddDto) {
|
|
|
|
|
+ List<ActivityStudentAdjustDto> activityStudentAdjustDtos = activityUserMapperAddDto.getActivityStudentAdjustDtos();
|
|
|
|
|
+ if(activityStudentAdjustDtos == null || activityStudentAdjustDtos.size() == 0){
|
|
|
|
|
+ throw new BizException("请选择学员");
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer activityId = activityUserMapperAddDto.getActivityId();
|
|
|
|
|
+ String memo = activityUserMapperAddDto.getMemo();
|
|
|
|
|
+ VipGroupActivity activity = vipGroupActivityDao.get(activityId);
|
|
|
|
|
+ if(activity == null){
|
|
|
|
|
+ throw new BizException("活动信息不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if(activity.getActivityType() != 1){
|
|
|
|
|
+ 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();
|
|
|
|
|
+ List<ActivityUserMapper> activityUserMappers = new ArrayList<>();
|
|
|
|
|
+ for (ActivityStudentAdjustDto adjustDto : activityStudentAdjustDtos) {
|
|
|
|
|
+ int activityUserMapperNum = adjustDto.getCourseNum();
|
|
|
|
|
+ if(giveCourseNum != null && giveCourseNum > 0){
|
|
|
|
|
+ if(adjustDto.getGiveCourseNum() > activityUserMapperNum){
|
|
|
|
|
+ activityUserMapperNum = adjustDto.getGiveCourseNum();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ 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(teacherId);
|
|
|
|
|
+ activityUserMapper.setAddMemo(memo);
|
|
|
|
|
+ if(adjustDto.getCourseNum() > i){
|
|
|
|
|
+ if("VIP".equals(courseType)){
|
|
|
|
|
+ activityUserMapper.setVipFlag(1);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ activityUserMapper.setPracticeFlag(1);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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, 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);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|