12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package com.example.service.impl;
- import com.example.context.BaseContext;
- import com.example.dto.TeacherDTO;
- import com.example.entity.Patent;
- import com.example.entity.Teacher;
- import com.example.mapper.TeacherMapper;
- import com.example.service.TeacherService;
- import com.example.vo.TeacherVO;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.List;
- @Service
- public class TeacherServiceImpl implements TeacherService {
- @Autowired
- private TeacherMapper teacherMapper;
- /**
- * 新增老师基本信息
- *
- * @param teacherDTO
- */
- @Override
- public void saveTeacher(TeacherDTO teacherDTO) {
- Teacher teacher = new Teacher();
- BeanUtils.copyProperties(teacherDTO, teacher);
- teacher.setId(BaseContext.getCurrentId());
- teacherMapper.saveTeacher(teacher);
- //向研究领域插入n条数据
- // List<ResearchFiled> researchFiled = teacher.getResearchFiled();
- //向专利插入n条数据
- /* List<Patent> patents = teacher.getPatent();
- if (patents != null && !patents.isEmpty()) {
- patents.forEach(patents1 -> patents1.setTeacherId(teacher.getId()));
- teacherMapper.savePatent(patents);
- }*/
- }
- @Override
- public void updateTeacher(TeacherDTO teacherDTO, Long id) {
- Teacher teacher = new Teacher();
- BeanUtils.copyProperties(teacherDTO, teacher);
- teacher.setId(id);
- teacherMapper.updateTeacher(teacher);
- //向专利插入n条数据
- /* teacherMapper.deletePatents(teacher.getId());
- List<Patent> patents = teacher.getPatent();
- if (patents != null && !patents.isEmpty()) {
- patents.forEach(patents1 -> patents1.setTeacherId(teacher.getId()));
- teacherMapper.savePatent(patents);
- }*/
- }
- /**
- * 根据id查询老师详细信息
- *
- * @param id
- */
- @Override
- public TeacherVO getById(Long id) {
- //查询专利
- //List<Patent> patents = teacherMapper.getPatent(id);
- //查询老师信息
- Teacher teacher = teacherMapper.getTeacher(id);
- TeacherVO teacherVO = new TeacherVO();
- BeanUtils.copyProperties(teacher, teacherVO);
- //teacherVO.setPatent(patents);
- return teacherVO;
- }
- /**
- * 根据id删除老师信息
- *
- * @param id
- */
- @Override
- public void deleteById(Long id) {
- teacherMapper.deleteById(id);
- }
- }
|