瀏覽代碼

新增学生信息管理后端实现

mcbaiyun 5 月之前
父節點
當前提交
ea848134eb

+ 61 - 0
src/main/java/com/smart/reader/controller/StudentInfoController.java

@@ -0,0 +1,61 @@
+package com.smart.reader.controller;
+
+import com.smart.reader.common.Page;
+import com.smart.reader.exception.CustomException;
+import com.smart.reader.model.bo.StudentInfoAddBo;
+import com.smart.reader.model.bo.StudentInfoUpdateBo;
+import com.smart.reader.model.vo.StudentInfoVo;
+import com.smart.reader.service.StudentInfoService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@RestController
+@RequestMapping("/api/v1/system/studentInfo")
+@Validated
+@Api(tags = "学生信息管理")
+public class StudentInfoController {
+
+    @Resource
+    private StudentInfoService studentInfoService;
+
+    @GetMapping("/list")
+    @ApiOperation("分页查询学生信息")
+    public Page<StudentInfoVo> queryInfo(int pageNum, int pageSize) throws CustomException {
+        return studentInfoService.queryInfo(pageNum, pageSize);
+    }
+
+    @PostMapping("/add")
+    @ApiOperation("新增学生信息")
+    public Boolean add(@RequestBody StudentInfoAddBo studentInfo) throws CustomException {
+        return studentInfoService.add(studentInfo);
+    }
+
+    @DeleteMapping("/delete/{id}")
+    @ApiOperation("删除学生信息")
+    public Boolean delete(@PathVariable Long id) throws CustomException {
+        return studentInfoService.delete(id);
+    }
+
+    @PutMapping("/edit")
+    @ApiOperation("修改学生信息")
+    public Boolean edit(@RequestBody StudentInfoUpdateBo studentInfo) throws CustomException {
+        return studentInfoService.edit(studentInfo);
+    }
+
+    @GetMapping("/{id}")
+    @ApiOperation("查询学生详情")
+    public StudentInfoVo detail(@PathVariable Long id) throws CustomException {
+        return studentInfoService.detail(id);
+    }
+
+    @DeleteMapping("/batchDelete")
+    @ApiOperation("批量删除学生信息")
+    public Boolean batchDelete(@RequestBody List<Long> ids) throws CustomException {
+        return studentInfoService.batchDelete(ids);
+    }
+}

+ 14 - 0
src/main/java/com/smart/reader/dao/StudentInfoMapper.java

@@ -0,0 +1,14 @@
+package com.smart.reader.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.smart.reader.model.po.StudentInfo;
+import com.smart.reader.model.vo.StudentInfoVo;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+@Mapper
+public interface StudentInfoMapper extends BaseMapper<StudentInfo> {
+    List<StudentInfoVo> queryInfo();
+    StudentInfoVo detail(@Param("id") Long id);
+}

+ 13 - 0
src/main/java/com/smart/reader/model/bo/StudentInfoAddBo.java

@@ -0,0 +1,13 @@
+package com.smart.reader.model.bo;
+
+import com.smart.reader.model.po.BaseEntity;
+import com.smart.reader.model.po.StudentInfo;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(value = "学生信息新增参数")
+public class StudentInfoAddBo extends StudentInfo {
+
+}

+ 13 - 0
src/main/java/com/smart/reader/model/bo/StudentInfoUpdateBo.java

@@ -0,0 +1,13 @@
+package com.smart.reader.model.bo;
+
+import com.smart.reader.model.po.BaseEntity;
+import com.smart.reader.model.po.StudentInfo;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(value = "学生信息更新参数")
+public class StudentInfoUpdateBo extends StudentInfo {
+
+}

+ 42 - 0
src/main/java/com/smart/reader/model/po/StudentInfo.java

@@ -0,0 +1,42 @@
+
+package com.smart.reader.model.po;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+@ApiModel(value = "学生信息表")
+@TableName("student_info")
+@Data
+public class StudentInfo extends BaseEntity{
+    /** 学号;学号 */
+    @ApiModelProperty(name = "学号", notes = "学号")
+    @TableField("student_no")
+    private String studentNo;
+
+    /** 姓名;姓名 */
+    @ApiModelProperty(name = "姓名", notes = "姓名")
+    @TableField("full_name")
+    private String fullName;
+
+    /** 性别;性别 */
+    @ApiModelProperty(name = "性别", notes = "性别")
+    @TableField("sex")
+    private Integer sex;
+
+    /** 班级ID;班级ID */
+    @ApiModelProperty(name = "班级ID", notes = "班级ID")
+    @TableField("class_info_id")
+    private Long classInfoId;
+
+    /** 面容ID;面容ID */
+    @ApiModelProperty(name = "面容ID", notes = "面容ID")
+    @TableField("face_id")
+    private String faceId;
+
+    /** 手机号;手机号 */
+    @ApiModelProperty(name = "手机号", notes = "手机号")
+    @TableField("phone_number")
+    private String phoneNumber;
+}

+ 15 - 0
src/main/java/com/smart/reader/model/vo/StudentInfoVo.java

@@ -0,0 +1,15 @@
+package com.smart.reader.model.vo;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.smart.reader.model.po.BaseEntity;
+import com.smart.reader.model.po.StudentInfo;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(value = "学生信息表")
+@TableName("student_info")
+public class StudentInfoVo extends StudentInfo {
+
+}

+ 19 - 0
src/main/java/com/smart/reader/service/StudentInfoService.java

@@ -0,0 +1,19 @@
+package com.smart.reader.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.smart.reader.common.Page;
+import com.smart.reader.exception.CustomException;
+import com.smart.reader.model.bo.StudentInfoAddBo;
+import com.smart.reader.model.bo.StudentInfoUpdateBo;
+import com.smart.reader.model.po.StudentInfo;
+import com.smart.reader.model.vo.StudentInfoVo;
+import java.util.List;
+
+public interface StudentInfoService extends IService<StudentInfo> {
+    Page<StudentInfoVo> queryInfo(int pageNum, int pageSize) throws CustomException;
+    Boolean add(StudentInfoAddBo studentInfo) throws CustomException;
+    Boolean delete(Long id) throws CustomException;
+    Boolean edit(StudentInfoUpdateBo studentInfo) throws CustomException;
+    StudentInfoVo detail(Long id) throws CustomException;
+    Boolean batchDelete(List<Long> ids) throws CustomException;
+}

+ 88 - 0
src/main/java/com/smart/reader/service/impl/StudentInfoServiceImpl.java

@@ -0,0 +1,88 @@
+package com.smart.reader.service.impl;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.github.pagehelper.PageHelper;
+import com.smart.reader.common.Page;
+import com.smart.reader.dao.StudentInfoMapper;
+import com.smart.reader.exception.CustomException;
+import com.smart.reader.model.bo.StudentInfoAddBo;
+import com.smart.reader.model.bo.StudentInfoUpdateBo;
+import com.smart.reader.model.po.StudentInfo;
+import com.smart.reader.model.vo.StudentInfoVo;
+import com.smart.reader.service.StudentInfoService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+@Service
+public class StudentInfoServiceImpl extends ServiceImpl<StudentInfoMapper, StudentInfo> implements StudentInfoService {
+
+    @Override
+    public Page<StudentInfoVo> queryInfo(int pageNum, int pageSize) throws CustomException {
+        try {
+            PageHelper.startPage(pageNum, pageSize);
+            List<StudentInfoVo> tableInfoVos = this.baseMapper.queryInfo();
+            return new Page<>(pageNum, pageSize, tableInfoVos);
+        } catch (Exception e) {
+            throw new CustomException("学生信息查询失败");
+        }
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Boolean add(StudentInfoAddBo studentInfo) throws CustomException {
+        StudentInfo info = BeanUtil.copyProperties(studentInfo, StudentInfo.class);
+        boolean save = this.save(info);
+        if (!save) {
+            throw new CustomException("学生数据添加失败");
+        }
+        return true;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Boolean delete(Long id) throws CustomException {
+        boolean remove = this.removeById(id);
+        if (!remove) {
+            throw new CustomException("学生数据删除失败");
+        }
+        return true;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Boolean edit(StudentInfoUpdateBo studentInfo) throws CustomException {
+        StudentInfo info = this.getById(studentInfo.getId());
+        if (ObjectUtil.isEmpty(info)) {
+            throw new CustomException("学生数据不存在");
+        }
+        BeanUtil.copyProperties(studentInfo, info);
+        boolean update = this.updateById(info);
+        if (!update) {
+            throw new CustomException("学生数据修改失败");
+        }
+        return true;
+    }
+
+    @Override
+    public StudentInfoVo detail(Long id) throws CustomException {
+        StudentInfoVo vo = this.baseMapper.detail(id);
+        if (ObjectUtil.isEmpty(vo)) {
+            throw new CustomException("学生详情获取失败");
+        }
+        return vo;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Boolean batchDelete(List<Long> ids) throws CustomException {
+        boolean result = this.removeByIds(ids);
+        if (!result) {
+            throw new CustomException("学生批量删除失败");
+        }
+        return true;
+    }
+}

+ 12 - 0
src/main/resources/mapper/StudentInfoMapper.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.smart.reader.dao.StudentInfoMapper">
+
+  <select id="queryInfo" resultType="com.smart.reader.model.vo.StudentInfoVo">
+    SELECT si.* from `student_info` si
+  </select>
+
+  <select id="detail" resultType="com.smart.reader.model.vo.StudentInfoVo">
+    select si.* from `student_info` si where si.id=#{id}
+  </select>
+</mapper>