论文信息管理控制器 - Spring Boot 项目代码示例
该代码文件是一个 Spring Boot 项目中的控制器类,用于处理论文信息相关的请求。该类中包含了添加、修改、删除、查询论文信息的方法,以及上传论文、批复论文、评分等操作的方法。其中,上传论文、批复论文、评分等操作涉及到邮件通知功能,使用了 MailUtils 工具类发送邮件。该类中还使用了@Autowired注解自动装配了其他服务类和 Mapper 接口。
package com.gtms.gtms.controller;
import com.gtms.gtms.entity.*;
import com.gtms.gtms.mapper.*;
import com.gtms.gtms.service.*;
import com.gtms.gtms.util.MailUtils;
import com.gtms.gtms.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.MailException;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author: 84644
* @Date: 2021/11/9 12:05
* @Description:
**/
@RequestMapping("/thesis")
@Controller
public class ThesisInfoController {
private static final Logger LOG = LoggerFactory.getLogger(ThesisInfoController.class);
@Autowired
private ThesisInfoService thesisInfoService;
@Autowired
private TeacherInfoService teacherInfoService;
@Autowired
private StudentInfoService studentInfoService;
@Autowired
private StudentTeacherRelationService studentTeacherRelationService;
@Autowired
private TeacherInfoMapper teacherInfoMapper;
@Autowired
private StudentInfoMapper studentInfoMapper;
@Autowired
private ReplyMapper replyMapper;
@Autowired
private ScoreMapper scoreMapper;
@Autowired
private UploadWordMapper uploadWordMapper;
@Autowired
private MailUtils mailUtils;
@Value("${mail.from.account}")
private String mailFromAccount;
private final String MAIL_TITLE = '论文选题教师处理结果';
@RequestMapping("/getThesisInfo")
@ResponseBody
public Object getThesisInfo(int page, int rows) {
LOG.info("==================开始查询论文信息==================");
try {
Map<String, Object> res = thesisInfoService.getThesisInfo(page, rows);
LOG.info("==================查询论文信息结束,数据:{}==================", res);
return res;
} catch (Exception e) {
LOG.error("==================查询论文信息异常,e={}==================", e);
}
return ResultUtil.dataGridEmptyResult();
}
@RequestMapping("/getThesisInfoByTeacherNo")
@ResponseBody
public Object getThesisInfoByTeacherNo(int page, int rows, HttpServletRequest request) {
User user = (User) request.getSession().getAttribute("user");
try {
TeacherInfo teacherInfo = teacherInfoService.getInfo(user.getId());
LOG.info("==================开始根据教师用户id查询教师发布论文信息,教师用户id:{}==================", user.getId());
Map<String, Object> res = thesisInfoService.getThesisInfoByTeacherNo(page, rows, teacherInfo.getTeacherNo());
LOG.info("==================根据教师用户id查询教师发布论文信息完成,数据:{}==================", res);
return res;
} catch (Exception e) {
LOG.error("==================根据教师用户id查询教师发布论文信息异常,e={}==================", e);
return ResultUtil.dataGridEmptyResult();
}
}
@RequestMapping("/addThesis")
@ResponseBody
public Object addThesis(String thesisTitle, String noticeInfo, HttpServletRequest request) {
User user = (User) request.getSession().getAttribute("user");
LOG.info("==================开始添加论文信息==================");
ThesisInfo thesisInfo = new ThesisInfo();
thesisInfo.setThesisTitle(thesisTitle);
thesisInfo.setNoticeInfo(noticeInfo);
try {
TeacherInfo teacherInfo = teacherInfoService.getInfo(user.getId());
thesisInfo.setTeacherName(teacherInfo.getTeacherName());
thesisInfo.setTeacherNo(teacherInfo.getTeacherNo());
thesisInfoService.insert(thesisInfo);
LOG.info("==================添加论文信息完成==================");
return ResultUtil.success("添加论文信息成功");
} catch (Exception e) {
LOG.error("添加论文信息异常,e={}", e);
return ResultUtil.error("添加论文信息异常");
}
}
@RequestMapping("/uploadWord")
@ResponseBody
public Object uploadWord(UploadWordVO uploadWordVO, HttpServletRequest request) {
User user = (User) request.getSession().getAttribute("user");
LOG.info("==================开始添加论文信息==================");
try {
UploadWord uploadWord = new UploadWord();
BeanUtils.copyProperties(uploadWordVO,uploadWord);
StudentInfo studentInfo = studentInfoService.getInfo(user.getId());
List<StudentTeacherRelation> studentTeacherRelations = studentTeacherRelationService.getInfoByStudentNo(user.getUserAccount());
TeacherInfo teacherInfo = new TeacherInfo();
if(!studentTeacherRelations.isEmpty()){
List<StudentTeacherRelation> teacherRelations =studentTeacherRelations.stream()
.filter(Objects::nonNull).filter(a -> a.getOpinionFlag().intValue() == 1).collect(Collectors.toList());
if(teacherRelations.isEmpty()){
return ResultUtil.error("选题审核中");
}else{
String teacherNo = teacherRelations.get(0).getTeacherNo();
Map<String,Object> map = new HashMap<>();
map.put("teacher_no",teacherNo);
List<TeacherInfo> teacherInfos = teacherInfoMapper.selectByMap(map);
teacherInfo = teacherInfos.get(0);
}
}else{
return ResultUtil.error("请先选题");
}
//绑定学生与老师的关系
uploadWord.setStudentId(studentInfo.getId());
uploadWord.setTeacherId(teacherInfo.getId());
thesisInfoService.uploadWord(uploadWord);
LOG.info("==================添加论文信息完成==================");
//通知老师
mailUtils.sendEmail(mailFromAccount,teacherInfo.getTeacherEmail(),"学生上传论文",studentInfo.getStudentName() + "重新上传论文,请批复");
return ResultUtil.success("添加论文信息成功");
} catch (Exception e) {
LOG.error("添加论文信息异常,e={}", e);
return ResultUtil.error("添加论文信息异常");
}
}
@RequestMapping("/reply")
@ResponseBody
public Object reply(Reply reply, HttpServletRequest request) {
User user = (User) request.getSession().getAttribute("user");
LOG.info("==================开始添加批复论文信息==================");
try {
UploadWord uploadWord = new UploadWord();
uploadWord.setId(reply.getWordId());
UploadWord uploadWord1 = uploadWordMapper.selectById(uploadWord);
StudentInfo studentInfo = new StudentInfo();
studentInfo.setId(uploadWord1.getStudentId());
StudentInfo studentInfo1 = studentInfoMapper.selectById(studentInfo);
replyMapper.insert(reply);
LOG.info("==================添加论文批复信息完成==================");
//通知学生
mailUtils.sendEmail(mailFromAccount,studentInfo1.getStudentEmail(),"导师批复论文","导师已批复论文,请查看");
//修改批复状态
uploadWord1.setStatus("已批复");
uploadWordMapper.updateById(uploadWord1);
return ResultUtil.success("添加论文批复信息成功");
} catch (Exception e) {
LOG.error("添加论文信息异常,e={}", e);
return ResultUtil.error("添加论文批复信息异常");
}
}
@RequestMapping("/onscore")
@ResponseBody
public Object onscore(ScoreVO scoreVO, HttpServletRequest request) {
LOG.info("==================开始添加评分信息==================");
try {
Score score = new Score();
BeanUtils.copyProperties(scoreVO,score);
scoreMapper.insert(score);
LOG.info("==================添加评分信息完成==================");
LOG.info("==================修改论文的状态信息==================");
UploadWord uploadWord = new UploadWord();
uploadWord.setId(scoreVO.getSuwId());
UploadWord uploadWord1 = uploadWordMapper.selectById(uploadWord);
uploadWord1.setBy("已评分");
uploadWordMapper.updateById(uploadWord1);
LOG.info("==================修改论文的状态信息完成==================");
//通知学生
StudentInfo studentInfo = studentInfoMapper.selectById(score.getStudentId());
mailUtils.sendEmail(mailFromAccount,studentInfo.getStudentEmail(),"导师评分","导师已评分,请查看");
return ResultUtil.success("添加评分信息成功");
} catch (Exception e) {
LOG.error("添加评分信息异常,e={}", e);
return ResultUtil.error("添加评分信息异常");
}
}
@RequestMapping("/modifyThesis")
@ResponseBody
public Object modifyThesis(ThesisInfo thesisInfo) {
LOG.info("==================开始修改论文信息==================");
try {
thesisInfoService.updateById(thesisInfo);
LOG.info("==================修改论文信息完成==================");
return ResultUtil.success("修改论文信息成功");
} catch (Exception e) {
LOG.error("修改论文信息异常,e={}", e);
return ResultUtil.error("修改论文信息异常");
}
}
@RequestMapping("/getThesisInfoById")
@ResponseBody
public Object getThesisInfoById(Integer id) {
LOG.info("==================开始根据id查询论文信息==================");
try {
ThesisInfo thesisInfo = thesisInfoService.selectById(id);
LOG.info("==================根据id查询论文信息完成,论文信息:{}==================", thesisInfo);
return ResultUtil.success(thesisInfo);
} catch (Exception e) {
LOG.error("修改论文信息异常,e={}", e);
return ResultUtil.error("修改论文信息异常");
}
}
@RequestMapping("/deleteThesisInfoByIds")
@ResponseBody
@Transactional
public Object deleteThesisInfoByIds(Integer[] ids) {
LOG.info("==================开始根据id删除论文信息==================");
try {
// 删除论文信息
thesisInfoService.deleteBatchIds(Arrays.asList(ids));
// 删除学生选题信息
studentTeacherRelationService.deleteByThesisId(ids);
// 发送邮件通知学生
List<StudentTeacherRelation> thesisList = studentTeacherRelationService.getInfoByThesisNos(ids);
for (int i = 0;i<thesisList.size();i++){
try {
mailUtils.sendEmail(mailFromAccount,thesisList.get(i).getStudentEmail(),MAIL_TITLE,
"你所选的论文选题已经被教师删除,请及时处理");
} catch (MailException e) {
LOG.error("==================发送邮件失败,e={},收件邮箱:{}==================", e, thesisList.get(i).getStudentEmail());
}
}
LOG.info("==================根据id删除论文信息完成==================");
return ResultUtil.success("删除成功");
} catch (Exception e) {
LOG.error("修改论文信息异常,e={}", e);
return ResultUtil.error("修改论文信息异常");
}
}
}
原文地址: https://www.cveoy.top/t/topic/j5Pv 著作权归作者所有。请勿转载和采集!