|  | @@ -1,6 +1,7 @@
 | 
	
		
			
				|  |  |  package com.ym.mec.biz.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.math.BigDecimal;
 | 
	
		
			
				|  |  | +import java.util.ArrayList;
 | 
	
		
			
				|  |  |  import java.util.Date;
 | 
	
		
			
				|  |  |  import java.util.HashMap;
 | 
	
		
			
				|  |  |  import java.util.List;
 | 
	
	
		
			
				|  | @@ -14,30 +15,38 @@ import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.CourseScheduleTeacherSalaryDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.TeacherDefaultVipGroupSalaryDao;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dao.VipGroupActivityDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.VipGroupDao;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dto.VipGroupSalarySettlementDto;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.CourseSchedule.CourseScheduleType;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.CourseScheduleTeacherSalary;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.TeacherDefaultVipGroupSalary;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.VipGroup;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.entity.VipGroupActivity;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.enums.SalarySettlementTypeEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.TeachModeEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.TeacherDefaultVipGroupSalaryService;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.dal.BaseDAO;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.service.impl.BaseServiceImpl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @Service
 | 
	
		
			
				|  |  | -public class TeacherDefaultVipGroupSalaryServiceImpl extends BaseServiceImpl<Long, TeacherDefaultVipGroupSalary>  implements TeacherDefaultVipGroupSalaryService {
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | +public class TeacherDefaultVipGroupSalaryServiceImpl extends BaseServiceImpl<Long, TeacherDefaultVipGroupSalary> implements TeacherDefaultVipGroupSalaryService {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	@Autowired
 | 
	
		
			
				|  |  |  	private TeacherDefaultVipGroupSalaryDao teacherDefaultVipGroupSalaryDao;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Autowired
 | 
	
		
			
				|  |  |  	private CourseScheduleTeacherSalaryDao courseScheduleTeacherSalaryDao;
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	@Autowired
 | 
	
		
			
				|  |  |  	private VipGroupDao vipGroupDao;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	@Autowired
 | 
	
		
			
				|  |  | +	private VipGroupActivityDao vipGroupActivityDao;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	@Override
 | 
	
		
			
				|  |  |  	public BaseDAO<Long, TeacherDefaultVipGroupSalary> getDAO() {
 | 
	
		
			
				|  |  |  		return teacherDefaultVipGroupSalaryDao;
 | 
	
	
		
			
				|  | @@ -46,7 +55,7 @@ public class TeacherDefaultVipGroupSalaryServiceImpl extends BaseServiceImpl<Lon
 | 
	
		
			
				|  |  |  	@Override
 | 
	
		
			
				|  |  |  	public TeacherDefaultVipGroupSalary findByTeacherAndCategory(Integer userId, Long categoryId) {
 | 
	
		
			
				|  |  |  		TeacherDefaultVipGroupSalary byTeacherAndCategory = teacherDefaultVipGroupSalaryDao.findByTeacherAndCategory(userId, categoryId);
 | 
	
		
			
				|  |  | -		if(Objects.isNull(byTeacherAndCategory)){
 | 
	
		
			
				|  |  | +		if (Objects.isNull(byTeacherAndCategory)) {
 | 
	
		
			
				|  |  |  			byTeacherAndCategory.setOfflineClassesSalary(new BigDecimal(0));
 | 
	
		
			
				|  |  |  			byTeacherAndCategory.setOnlineClassesSalary(new BigDecimal(0));
 | 
	
		
			
				|  |  |  		}
 | 
	
	
		
			
				|  | @@ -75,14 +84,21 @@ public class TeacherDefaultVipGroupSalaryServiceImpl extends BaseServiceImpl<Lon
 | 
	
		
			
				|  |  |  				// 修改了哪些课酬
 | 
	
		
			
				|  |  |  				TeacherDefaultVipGroupSalary oldMS = map.get(ms.getVipGroupCategoryId());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -				if (oldMS.getOfflineClassesSalary().doubleValue() != ms.getOfflineClassesSalary().doubleValue()
 | 
	
		
			
				|  |  | -						|| oldMS.getOnlineClassesSalary().doubleValue() != ms.getOnlineClassesSalary().doubleValue()) {
 | 
	
		
			
				|  |  | +				if (oldMS == null || oldMS.getOfflineClassesSalary() == null
 | 
	
		
			
				|  |  | +						|| oldMS.getOfflineClassesSalary().doubleValue() != ms.getOfflineClassesSalary().doubleValue()
 | 
	
		
			
				|  |  | +						|| oldMS.getOnlineClassesSalary() == null || oldMS.getOnlineClassesSalary().doubleValue() != ms.getOnlineClassesSalary().doubleValue()) {
 | 
	
		
			
				|  |  |  					salaryMap.put(ms.getVipGroupCategoryId(), ms);
 | 
	
		
			
				|  |  |  				}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  			if (salaryMap.size() > 0) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +				// 根据教师编号删除
 | 
	
		
			
				|  |  | +				teacherDefaultVipGroupSalaryDao.delByTeacherId(salary.getUserId());
 | 
	
		
			
				|  |  | +				// 新增
 | 
	
		
			
				|  |  | +				teacherDefaultVipGroupSalaryDao.batchAdd(teacherDefaultVipGroupSalaries);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  				String typeList = CourseScheduleType.VIP.getCode();
 | 
	
		
			
				|  |  |  				// 查询所有需要修改的课酬
 | 
	
		
			
				|  |  |  				List<CourseScheduleTeacherSalary> updateTeacherSalaryList = courseScheduleTeacherSalaryDao.queryUserNoSettlementListByTypeAndStartClassDate(
 | 
	
	
		
			
				|  | @@ -91,33 +107,58 @@ public class TeacherDefaultVipGroupSalaryServiceImpl extends BaseServiceImpl<Lon
 | 
	
		
			
				|  |  |  				if (updateTeacherSalaryList != null && updateTeacherSalaryList.size() > 0) {
 | 
	
		
			
				|  |  |  					Set<String> musicGroupIdList = updateTeacherSalaryList.stream().map(ts -> ts.getMusicGroupId()).collect(Collectors.toSet());
 | 
	
		
			
				|  |  |  					// 查询包含的VIP信息
 | 
	
		
			
				|  |  | -					Map<Long, VipGroup> vipGroupMap = vipGroupDao.queryByIds(StringUtils.join(musicGroupIdList, ",")).stream()
 | 
	
		
			
				|  |  | -							.collect(Collectors.toMap(VipGroup::getId, mg -> mg));
 | 
	
		
			
				|  |  | +					List<VipGroup> vipGroupList = vipGroupDao.queryByIds(StringUtils.join(musicGroupIdList, ","));
 | 
	
		
			
				|  |  | +					if (vipGroupList == null || vipGroupList.size() == 0) {
 | 
	
		
			
				|  |  | +						return;
 | 
	
		
			
				|  |  | +					}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +					Map<Long, VipGroup> vipGroupMap = vipGroupList.stream().collect(Collectors.toMap(VipGroup::getId, mg -> mg));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +					// 查询活动
 | 
	
		
			
				|  |  | +					Map<Integer, VipGroupActivity> vipGroupActivityMap = vipGroupActivityDao
 | 
	
		
			
				|  |  | +							.queryByIds(StringUtils.join(vipGroupList.stream().map(vg -> vg.getVipGroupActivityId()).collect(Collectors.toList()), ","))
 | 
	
		
			
				|  |  | +							.stream().collect(Collectors.toMap(VipGroupActivity::getId, va -> va));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  					// 批量修改课程课酬
 | 
	
		
			
				|  |  | +					List<CourseScheduleTeacherSalary> list = new ArrayList<CourseScheduleTeacherSalary>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  					for (CourseScheduleTeacherSalary ts : updateTeacherSalaryList) {
 | 
	
		
			
				|  |  |  						VipGroup vipGroup = vipGroupMap.get(ts.getMusicGroupId());
 | 
	
		
			
				|  |  |  						// 课酬结算标准
 | 
	
		
			
				|  |  |  						if (vipGroup != null) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +							VipGroupActivity vipGroupActivity = vipGroupActivityMap.get(vipGroup.getVipGroupActivityId());
 | 
	
		
			
				|  |  | +							if (vipGroupActivity == null) {
 | 
	
		
			
				|  |  | +								continue;
 | 
	
		
			
				|  |  | +							}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +							VipGroupSalarySettlementDto vipGroupSalarySettlementDto = JSON.parseObject(vipGroupActivity.getSalarySettlementJson(),
 | 
	
		
			
				|  |  | +									VipGroupSalarySettlementDto.class);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +							if (vipGroupSalarySettlementDto == null) {
 | 
	
		
			
				|  |  | +								continue;
 | 
	
		
			
				|  |  | +							}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  							TeacherDefaultVipGroupSalary tdms = salaryMap.get(vipGroup.getVipGroupCategoryId());
 | 
	
		
			
				|  |  |  							if (tdms != null) {
 | 
	
		
			
				|  |  | -								if (ts.getCourseSchedule().getTeachMode() == TeachModeEnum.ONLINE) {// 线上课
 | 
	
		
			
				|  |  | +								if (vipGroupSalarySettlementDto.getOnlineSalarySettlement().getSalarySettlementType() == SalarySettlementTypeEnum.FIXED_SALARY
 | 
	
		
			
				|  |  | +										&& (ts.getCourseSchedule().getTeachMode() == TeachModeEnum.ONLINE)) {// 线上课
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  									ts.setExpectSalary(tdms.getOnlineClassesSalary());
 | 
	
		
			
				|  |  | -								} else if (ts.getCourseSchedule().getTeachMode() == TeachModeEnum.OFFLINE) {// 线下课
 | 
	
		
			
				|  |  | +									list.add(ts);
 | 
	
		
			
				|  |  | +								} else if (vipGroupSalarySettlementDto.getOnlineSalarySettlement().getSalarySettlementType() == SalarySettlementTypeEnum.FIXED_SALARY
 | 
	
		
			
				|  |  | +										&& ts.getCourseSchedule().getTeachMode() == TeachModeEnum.OFFLINE) {// 线下课
 | 
	
		
			
				|  |  |  									ts.setExpectSalary(tdms.getOfflineClassesSalary());
 | 
	
		
			
				|  |  | +									list.add(ts);
 | 
	
		
			
				|  |  |  								}
 | 
	
		
			
				|  |  |  							}
 | 
	
		
			
				|  |  |  						}
 | 
	
		
			
				|  |  |  					}
 | 
	
		
			
				|  |  | +					if (list.size() > 0) {
 | 
	
		
			
				|  |  | +						courseScheduleTeacherSalaryDao.batchUpdateTeacherExpectSalarys(list);
 | 
	
		
			
				|  |  | +					}
 | 
	
		
			
				|  |  |  				}
 | 
	
		
			
				|  |  | -				courseScheduleTeacherSalaryDao.batchUpdateTeacherExpectSalarys(updateTeacherSalaryList);
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -			// 根据教师编号删除
 | 
	
		
			
				|  |  | -			teacherDefaultVipGroupSalaryDao.delByTeacherId(salary.getUserId());
 | 
	
		
			
				|  |  | -			// 新增
 | 
	
		
			
				|  |  | -			teacherDefaultVipGroupSalaryDao.batchAdd(teacherDefaultVipGroupSalaries);
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  }
 |