package com.ruoyi.system.service.impl; import java.util.List; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.ClassUtils; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.system.domain.StudentInfoOld; import com.ruoyi.system.mapper.StudentInfoOldMapper; import lombok.SneakyThrows; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.system.mapper.StudentInfoMapper; import com.ruoyi.system.domain.StudentInfo; import com.ruoyi.system.service.IStudentInfoService; /** * 学生档案信息Service业务层处理 * * @author ruoyi * @date 2023-07-21 */ @Service public class StudentInfoServiceImpl implements IStudentInfoService { @Autowired private StudentInfoMapper studentInfoMapper; @Autowired private StudentInfoOldMapper studentInfoOldMapper; /** * 查询学生档案信息 * * @param id 学生档案信息主键 * @return 学生档案信息 */ @Override public StudentInfo selectStudentInfoById(Long id) { return studentInfoMapper.selectStudentInfoById(id); } /** * 查询学生档案信息列表 * * @param studentInfo 学生档案信息 * @return 学生档案信息 */ @Override public List selectStudentInfoList(StudentInfo studentInfo) { return studentInfoMapper.selectStudentInfoList(studentInfo); } /** * 新增学生档案信息 * * @param studentInfo 学生档案信息 * @return 结果 */ @Override public AjaxResult insertStudentInfo(StudentInfo studentInfo) { //查询数据库是否存在信息 StudentInfo student = new StudentInfo(); student.setStudentId(studentInfo.getStudentId()); List studentInfos = studentInfoMapper.selectStudentInfoList(student); if(studentInfos!=null && studentInfos.size()>0){ return AjaxResult.error("参数错误"); } studentInfo.setCreateTime(DateUtils.getNowDate()); int rows = studentInfoMapper.insertStudentInfo(studentInfo); return rows > 0 ? AjaxResult.success() : AjaxResult.error(); } /** * 修改学生档案信息 * * @param studentInfo 学生档案信息 * @return 结果 */ @SneakyThrows @Override public int updateStudentInfo(StudentInfo studentInfo) { //查询修改前数据 StudentInfo student = studentInfoMapper.selectStudentInfoByStudentId(studentInfo.getStudentId()); StudentInfoOld studentInfoOld = new StudentInfoOld(); ClassUtils.copyProperties(student, studentInfoOld); studentInfoOld.setCreateTime(DateUtils.getNowDate()); studentInfoOld.setUpdateTime(studentInfo.getCreateTime()); studentInfoOldMapper.insertStudentInfoOld(studentInfoOld); studentInfo.setUpdateTime(DateUtils.getNowDate()); return studentInfoMapper.updateStudentInfo(studentInfo); } /** * 批量删除学生档案信息 * * @param ids 需要删除的学生档案信息主键 * @return 结果 */ @Override public int deleteStudentInfoByIds(Long[] ids) { return studentInfoMapper.deleteStudentInfoByIds(ids); } /** * 删除学生档案信息信息 * * @param id 学生档案信息主键 * @return 结果 */ @Override public int deleteStudentInfoById(Long id) { return studentInfoMapper.deleteStudentInfoById(id); } }