|
|
|
@ -1,13 +1,24 @@ |
|
|
|
package com.hxhq.business.service.impl; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.hxhq.business.domain.Study; |
|
|
|
import com.hxhq.business.domain.StudySubject; |
|
|
|
import com.hxhq.business.form.study.StudySubjectUserSaveForm; |
|
|
|
import com.hxhq.business.service.IStudyService; |
|
|
|
import com.hxhq.business.service.IStudySubjectService; |
|
|
|
import com.hxhq.common.core.exception.ServiceException; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import com.hxhq.business.mapper.StudySubjectUserMapper; |
|
|
|
import com.hxhq.business.domain.StudySubjectUser; |
|
|
|
import com.hxhq.business.service.IStudySubjectUserService; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
/** |
|
|
|
* 试验-学科-成员Service业务层处理 |
|
|
|
@ -18,17 +29,62 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
@Service |
|
|
|
public class StudySubjectUserServiceImpl extends ServiceImpl<StudySubjectUserMapper, StudySubjectUser> implements IStudySubjectUserService |
|
|
|
{ |
|
|
|
/** |
|
|
|
* 查询试验-学科-成员列表 |
|
|
|
* |
|
|
|
* @param studySubjectUser 试验-学科-成员 |
|
|
|
* @return 试验-学科-成员 |
|
|
|
*/ |
|
|
|
@Autowired |
|
|
|
private IStudySubjectService studySubjectService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<StudySubjectUser> queryList(StudySubjectUser studySubjectUser) |
|
|
|
{ |
|
|
|
QueryWrapper<StudySubjectUser> queryWrapper = Wrappers.query(); |
|
|
|
return this.list(queryWrapper); |
|
|
|
public List<StudySubjectUser> getListByStudySubjectId(Long studySubjectId) { |
|
|
|
QueryWrapper<StudySubjectUser> queryWrapper = new QueryWrapper<>(); |
|
|
|
queryWrapper.eq("study_subject_id",studySubjectId); |
|
|
|
return list(queryWrapper); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void saveInfo(StudySubjectUserSaveForm form) { |
|
|
|
StudySubject studySubject = studySubjectService.getById(form.getStudySubjectId()); |
|
|
|
if(studySubject==null){ |
|
|
|
throw new ServiceException("试验学科不存在"); |
|
|
|
} |
|
|
|
//传入的成员信息 |
|
|
|
List<StudySubjectUser> itemList = form.getSubjectUserList(); |
|
|
|
//已经设置的学科信息 |
|
|
|
List<StudySubjectUser> oldList = getListByStudySubjectId(form.getStudySubjectId()); |
|
|
|
List<StudySubjectUser> deleteList = new ArrayList<>(); |
|
|
|
List<StudySubjectUser> addList = new ArrayList<>(); |
|
|
|
List<StudySubjectUser> modifyList = new ArrayList<>(); |
|
|
|
|
|
|
|
for(StudySubjectUser item : itemList){ |
|
|
|
List<StudySubjectUser> existsList = oldList.stream().filter(o->o.getUserId().equals(item.getUserId())).collect(Collectors.toList()); |
|
|
|
if(existsList.size()==0){ |
|
|
|
item.setStudySubjectId(form.getStudySubjectId()); |
|
|
|
addList.add(item); |
|
|
|
}else{ |
|
|
|
item.setId(existsList.get(0).getId()); |
|
|
|
modifyList.add(item); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for(StudySubjectUser old : oldList){ |
|
|
|
if(itemList.stream().filter(o->o.getUserId().equals(old.getUserId())).collect(Collectors.toList()).size()==0){ |
|
|
|
deleteList.add(old); |
|
|
|
} |
|
|
|
} |
|
|
|
if(addList.size()>0){ |
|
|
|
saveBatch(addList); |
|
|
|
} |
|
|
|
if(modifyList.size()>0){ |
|
|
|
updateBatchById(modifyList); |
|
|
|
} |
|
|
|
if(deleteList.size()>0){ |
|
|
|
removeBatchByIds(deleteList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void deleteByStudySubjectId(Long studySubjectId) { |
|
|
|
QueryWrapper<StudySubjectUser> queryWrapper = new QueryWrapper<>(); |
|
|
|
queryWrapper.eq("study_subject_id",studySubjectId); |
|
|
|
remove(queryWrapper); |
|
|
|
} |
|
|
|
} |