Bläddra i källkod

老师信息查询,老师信息删除

Signed-off-by: guoWenHao <2532478980@qq.com>
guoWenHao 9 månader sedan
förälder
incheckning
5adb7138b9

+ 44 - 0
teacher-pojo/src/main/java/com/example/vo/TeacherVO.java

@@ -0,0 +1,44 @@
+package com.example.vo;
+
+import com.example.entity.Patent;
+import com.example.entity.ResearchFiled;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class TeacherVO implements Serializable {
+
+    private Long id;
+
+    private String name;
+
+    private String profile;
+
+    private String image;
+
+    private String gradauteCourse;
+
+    private String undergradauteCourse;
+
+    private List<ResearchFiled> researchFiled;
+
+    private List<Patent> patent;
+
+    private String email;
+
+    private String phoneNumber;
+
+    private Integer awardsNum;
+
+    private Integer workNum;
+
+    private Integer thesisNum;
+}

+ 17 - 0
teacher-serve/src/main/java/com/example/controller/teacher/TeacherController.java

@@ -1,8 +1,10 @@
 package com.example.controller.teacher;
 
 import com.example.dto.TeacherDTO;
+import com.example.entity.Teacher;
 import com.example.result.Result;
 import com.example.service.TeacherService;
+import com.example.vo.TeacherVO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -40,4 +42,19 @@ public class TeacherController {
         teacherService.updateTeacher(teacherDTO,id);
         return Result.success();
     }
+    @GetMapping("/{id}")
+    @ApiOperation(value = "根据id删除老师信息")
+    public Result<TeacherVO> getById(@PathVariable Long id){
+        log.info("查询老师详情:{}",id);
+        TeacherVO TeacherVO=teacherService.getById(id);
+        return Result.success(TeacherVO);
+    }
+
+    @DeleteMapping("/{id}")
+    @ApiOperation(value = "根据id删除老师信息")
+    public Result deleteById(@PathVariable Long id){
+        log.info("根据id删除老师信息:{}",id);
+        teacherService.deleteById(id);
+        return Result.success();
+    }
 }

+ 4 - 2
teacher-serve/src/main/java/com/example/interceptor/JwtTokenAdminInterceptor.java

@@ -35,9 +35,11 @@ public class JwtTokenAdminInterceptor implements HandlerInterceptor {
      */
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
         //判断当前拦截到的是Controller的方法还是其他资源
-        //同时放行公开部分
+        //同时放行get请求
         String uri = request.getRequestURI();
-        if (!(handler instanceof HandlerMethod)) {
+
+        String method = request.getMethod();
+        if (!(handler instanceof HandlerMethod) || "GET".equalsIgnoreCase(method)) {
             //当前拦截到的不是动态方法,直接放行
             return true;
         }

+ 4 - 3
teacher-serve/src/main/java/com/example/mapper/AwardsMapper.java

@@ -3,6 +3,7 @@ package com.example.mapper;
 import com.example.entity.Awards;
 import org.apache.ibatis.annotations.Insert;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Update;
 
 @Mapper
@@ -18,8 +19,8 @@ public interface AwardsMapper {
     /**
      * 修改教师获奖数量
      * @param id
-     * @param awardsNum
+     * @param
      */
-    @Update("update teacherteam_system.teacher set awards_num = #{awardsNum} where id = #{id}")
-    void addAwardsNum(Long id, Integer awardsNum);
+    @Update("update teacherteam_system.teacher set awards_num = awards_num+1 where id = #{id}")
+    void addAwardsNum(@Param("id") Long id);
 }

+ 26 - 0
teacher-serve/src/main/java/com/example/mapper/TeacherMapper.java

@@ -6,6 +6,7 @@ import com.example.entity.Teacher;
 import org.apache.ibatis.annotations.Delete;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 
 import java.util.List;
 
@@ -46,4 +47,29 @@ public interface TeacherMapper {
      * @param id
      */
     void deletePatents(Long id);
+    /**
+     * 根据id查询老师研究领域
+     * @param id
+     */
+    @Select("select * from teacherteam_system.research_filed where teacher_id=#{id}")
+    List<ResearchFiled> getResearch(Long id);
+    /**
+     * 根据id查询老师专利
+     * @param id
+     */
+    @Select("select * from teacherteam_system.patent where teacher_id = #{id}")
+    List<Patent> getPatent(Long id);
+    /**
+     * 根据id查询老师基本信息
+     * @param id
+     */
+    @Select("select * from teacherteam_system.teacher where id = #{id}")
+    Teacher getTeacher(Long id);
+
+    /**
+     * 根据id删除老师信息
+     * @param id
+     */
+    @Delete("delete from teacherteam_system.teacher where id=#{id}")
+    void deleteById(Long id);
 }

+ 6 - 0
teacher-serve/src/main/java/com/example/service/TeacherService.java

@@ -1,6 +1,8 @@
 package com.example.service;
 
 import com.example.dto.TeacherDTO;
+import com.example.entity.Teacher;
+import com.example.vo.TeacherVO;
 
 public interface TeacherService {
     /**
@@ -10,4 +12,8 @@ public interface TeacherService {
     void saveTeacher(TeacherDTO teacherDTO);
 
     void updateTeacher(TeacherDTO teacherDTO,Long id);
+
+    TeacherVO getById(Long id);
+
+    void deleteById(Long id);
 }

+ 1 - 2
teacher-serve/src/main/java/com/example/service/impl/AwardsServiceImpl.java

@@ -30,9 +30,8 @@ public class AwardsServiceImpl implements AwardsService {
         BeanUtils.copyProperties(awardsDTO, awards);
         Long id=BaseContext.getCurrentId();
         awards.setTeacherId(id);
-        awardsNum=awardsNum+1;
         awardsMapper.uploadAwards(awards);
-        awardsMapper.addAwardsNum(id,awardsNum);
+        awardsMapper.addAwardsNum(id);
 
     }
 }

+ 32 - 1
teacher-serve/src/main/java/com/example/service/impl/TeacherServiceImpl.java

@@ -7,6 +7,7 @@ import com.example.entity.ResearchFiled;
 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;
@@ -48,7 +49,7 @@ public class TeacherServiceImpl implements TeacherService {
     }
 
     @Override
-    public void updateTeacher(TeacherDTO teacherDTO,Long id) {
+    public void updateTeacher(TeacherDTO teacherDTO, Long id) {
         Teacher teacher = new Teacher();
         BeanUtils.copyProperties(teacherDTO, teacher);
         teacher.setId(id);
@@ -74,4 +75,34 @@ public class TeacherServiceImpl implements TeacherService {
             teacherMapper.savePatent(patents);
         }
     }
+
+    /**
+     * 根据id查询老师详细信息
+     *
+     * @param id
+     */
+    @Override
+    public TeacherVO getById(Long id) {
+        //查询研究领域
+        List<ResearchFiled> researchFileds = teacherMapper.getResearch(id);
+        //查询专利
+        List<Patent> patents = teacherMapper.getPatent(id);
+        //查询老师信息
+        Teacher teacher = teacherMapper.getTeacher(id);
+        TeacherVO teacherVO = new TeacherVO();
+        BeanUtils.copyProperties(teacher, teacherVO);
+        teacherVO.setResearchFiled(researchFileds);
+        teacherVO.setPatent(patents);
+        return teacherVO;
+    }
+
+    /**
+     * 根据id删除老师信息
+     * @param id
+     */
+    @Override
+    public void deleteById(Long id) {
+        teacherMapper.deleteById(id);
+    }
+
 }