|
|
@ -6,11 +6,17 @@ import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
|
import com.hxhq.business.domain.Study; |
|
|
|
|
|
import com.hxhq.business.form.study.StudySubjectSaveForm; |
|
|
|
|
|
import com.hxhq.business.service.IStudyService; |
|
|
|
|
|
import com.hxhq.common.core.exception.ServiceException; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import com.hxhq.business.mapper.StudySubjectMapper; |
|
|
import com.hxhq.business.mapper.StudySubjectMapper; |
|
|
import com.hxhq.business.domain.StudySubject; |
|
|
import com.hxhq.business.domain.StudySubject; |
|
|
import com.hxhq.business.service.IStudySubjectService; |
|
|
import com.hxhq.business.service.IStudySubjectService; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 试验-学科Service业务层处理 |
|
|
* 试验-学科Service业务层处理 |
|
|
@ -21,18 +27,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
@Service |
|
|
@Service |
|
|
public class StudySubjectServiceImpl extends ServiceImpl<StudySubjectMapper, StudySubject> implements IStudySubjectService |
|
|
public class StudySubjectServiceImpl extends ServiceImpl<StudySubjectMapper, StudySubject> implements IStudySubjectService |
|
|
{ |
|
|
{ |
|
|
/** |
|
|
|
|
|
* 查询试验-学科列表 |
|
|
|
|
|
* |
|
|
|
|
|
* @param studySubject 试验-学科 |
|
|
|
|
|
* @return 试验-学科 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public List<StudySubject> queryList(StudySubject studySubject) |
|
|
|
|
|
{ |
|
|
|
|
|
QueryWrapper<StudySubject> queryWrapper = Wrappers.query(); |
|
|
|
|
|
return this.list(queryWrapper); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private IStudyService studyService; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 获取试验下的学科设置信息(含未设置的学科) |
|
|
* 获取试验下的学科设置信息(含未设置的学科) |
|
|
@ -69,9 +65,51 @@ public class StudySubjectServiceImpl extends ServiceImpl |
|
|
* @param studyId |
|
|
* @param studyId |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
private List<StudySubject> getListByStudyId(Long studyId){ |
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public List<StudySubject> getListByStudyId(Long studyId){ |
|
|
QueryWrapper<StudySubject> queryWrapper = new QueryWrapper<>(); |
|
|
QueryWrapper<StudySubject> queryWrapper = new QueryWrapper<>(); |
|
|
queryWrapper.eq("study_id",studyId); |
|
|
queryWrapper.eq("study_id",studyId); |
|
|
return list(queryWrapper); |
|
|
return list(queryWrapper); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
public void saveInfo(StudySubjectSaveForm form) { |
|
|
|
|
|
Study study = studyService.getById(form.getStudyId()); |
|
|
|
|
|
if(study==null){ |
|
|
|
|
|
throw new ServiceException("试验不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
//传入的学科信息 |
|
|
|
|
|
List<StudySubject> itemList = form.getSubjectList(); |
|
|
|
|
|
|
|
|
|
|
|
//已经设置的学科信息 |
|
|
|
|
|
List<StudySubject> oldList = getListByStudyId(form.getStudyId()); |
|
|
|
|
|
List<StudySubject> deleteList = new ArrayList<>(); |
|
|
|
|
|
List<StudySubject> addList = new ArrayList<>(); |
|
|
|
|
|
List<StudySubject> modifyList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
for(StudySubject item : itemList){ |
|
|
|
|
|
if(oldList.stream().filter(o->o.getDeptId().equals(item.getDeptId())).collect(Collectors.toList()).size()==0){ |
|
|
|
|
|
item.setStudyId(form.getStudyId()); |
|
|
|
|
|
addList.add(item); |
|
|
|
|
|
}else{ |
|
|
|
|
|
modifyList.add(item); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for(StudySubject old : oldList){ |
|
|
|
|
|
if(itemList.stream().filter(o->o.getDeptId().equals(old.getDeptId())).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); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |