学生管理(增删查)

hehai msdw_tms-v0.1
mzh820631607 4 years ago
parent 07639b6008
commit 05e9786c62
  1. 19
      src/main/java/com/msdw/tms/api/StudentControllerApi.java
  2. 70
      src/main/java/com/msdw/tms/controller/StudentController.java
  3. 11
      src/main/java/com/msdw/tms/dao/StudentDao.java
  4. 2
      src/main/java/com/msdw/tms/dao/UserInfoDao.java
  5. 15
      src/main/java/com/msdw/tms/entity/vo/StudentVo.java
  6. 10
      src/main/java/com/msdw/tms/service/StudentService.java
  7. 3
      src/main/java/com/msdw/tms/service/UserInfoService.java
  8. 37
      src/main/java/com/msdw/tms/service/impl/StudentServiceImpl.java
  9. 10
      src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java
  10. 38
      src/main/resources/mapper/tms/StudentDao.xml
  11. 6
      src/main/resources/mapper/tms/UserInfoDao.xml
  12. 66
      src/test/java/com/msdw/tms/service/StudentTest.java

@ -1,7 +1,26 @@
package com.msdw.tms.api;
import com.msdw.tms.common.utils.R;
import com.msdw.tms.entity.vo.StudentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@Api(value = "学生管理", tags = "学生管理")
public interface StudentControllerApi {
@ApiOperation(value = "新增学生",notes = "新增学生")
public R addStudent(@RequestBody StudentVo studentVo);
@ApiOperation(value = "学生列表信息",notes = "学生列表信息")
public R queryStudent(Integer schoolId, String seachContent, Integer page, Integer size);
@ApiOperation(value = "删除学生",notes = "删除学生")
public R daleteStudent(List<Integer> studentId);
@ApiOperation(value = "编辑学生信息",notes = "编辑学生信息")
public R updateStudent(StudentVo studentVo);
}

@ -1,14 +1,16 @@
package com.msdw.tms.controller;
import com.msdw.tms.api.StudentControllerApi;
import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.common.utils.R;
import com.msdw.tms.entity.StudentEntity;
import com.msdw.tms.entity.UserInfoEntity;
import com.msdw.tms.entity.vo.StudentVo;
import com.msdw.tms.service.StudentService;
import com.msdw.tms.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -21,12 +23,64 @@ public class StudentController implements StudentControllerApi{
@Autowired
private StudentService studentService;
@Autowired
private UserInfoService userInfoService;
/**
* 新增学生
* @param studentVo
* @return
*/
@Override
@PostMapping("/addStudent")
public R addStudent(@RequestBody StudentVo studentVo){
UserInfoEntity userInfoList = studentVo.getUserInfo();
int userId= userInfoService.saveUserInfo(userInfoList);
studentVo.setUserId(userInfoList.getUserId());
boolean saveStudent = studentService.saveStudent(studentVo);
return saveStudent ? R.ok() : R.error();
}
/**
* 学生列表
* @param schoolId
* @param seachContent
* @param page
* @param size
* @return
*/
@Override
@GetMapping("/queryStudent")
public R queryStudent(@RequestParam Integer schoolId,@RequestParam(required = false) String seachContent,@RequestParam Integer page,@RequestParam Integer size){
PageUtils query = studentService.queryStudent(schoolId,seachContent,page,size);
return R.ok().put("data",query);
}
/**
* 批量删除学生
* @param studentId
* @return
*/
@Override
@PostMapping("/daleteStudent")
public R daleteStudent(@RequestBody List<Integer> studentId){
boolean delete = studentService.deleteStudent(studentId);
return delete ? R.ok() : R.error();
}
/**
* 编辑学生
* @param studentVo
* @return
*/
@Override
@PostMapping("/updateStudent")
public R updateStudent(@RequestBody StudentVo studentVo) {
@PostMapping("addStudent")
public R addStudent(StudentVo studentVo){
UserInfoEntity userInfoList = studentVo.getUserInfoList();
userInfoList.setUniqueIdentificationAccount(String.valueOf(System.currentTimeMillis()));
// studentService.addStudent(studentVo,userInfoList);
return R.ok();
}
}

@ -1,9 +1,20 @@
package com.msdw.tms.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.msdw.tms.entity.StudentEntity;
import com.msdw.tms.entity.vo.StudentVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.poi.ss.formula.functions.T;
import java.util.List;
@Mapper
public interface StudentDao extends BaseMapper<StudentEntity> {
boolean saveStudent(StudentVo studentVo);
IPage<StudentVo> queryStudent(Page<T> tpage,String searchContent,Integer schoolId);
boolean deleteStudent(List<Integer> studentId);
}

@ -15,4 +15,6 @@ public interface UserInfoDao extends BaseMapper<UserInfoEntity> {
void userInfupdateUserInfoById(UserInfoEntity entity);
String queryUserPassword(Integer userid);
int saveUserInfo(UserInfoEntity userInfo);
}

@ -11,5 +11,18 @@ import java.util.List;
@Accessors(chain = true)
public class StudentVo extends StudentEntity {
private UserInfoEntity userInfoList;
private UserInfoEntity userInfo;
//学校名称
private String schoolName;
//用户姓名
private String userName;
//用户账号
private String account;
//登陆次数
private Integer logInNumber;
//最后登陆时间
private String lastLoginTime;
}

@ -1,8 +1,18 @@
package com.msdw.tms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.entity.StudentEntity;
import com.msdw.tms.entity.UserInfoEntity;
import com.msdw.tms.entity.vo.StudentVo;
import java.util.List;
public interface StudentService extends IService<StudentEntity>{
boolean saveStudent(StudentVo studentvo);
PageUtils queryStudent(Integer schoolId,String searchContent, Integer page, Integer size);
boolean deleteStudent(List<Integer> studentId);
}

@ -16,4 +16,7 @@ public interface UserInfoService extends IService<UserInfoEntity> {
void updateUserInfoById(UserInfoEntity entity);
String queryPasword(Integer userId);
int saveUserInfo(UserInfoEntity userInfo);
}

@ -1,12 +1,49 @@
package com.msdw.tms.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.msdw.tms.common.utils.Constant;
import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.dao.StudentDao;
import com.msdw.tms.entity.StudentEntity;
import com.msdw.tms.entity.vo.StudentVo;
import com.msdw.tms.service.StudentService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service("studentService")
public class StudentServiceImpl extends ServiceImpl<StudentDao,StudentEntity> implements StudentService {
@Autowired
private StudentDao studentDao;
@Transactional
@Override
public boolean saveStudent(StudentVo studentvo) {
studentvo.setIsdel(Constant.IsDel.NOT_DEL.getType());
boolean save = studentDao.saveStudent(studentvo);
return save;
}
@Override
public PageUtils queryStudent(Integer schoolId,String searchContent, Integer page, Integer size) {
Page<T> tPage = new Page<>(page,size);
IPage<StudentVo> saveStudent = studentDao.queryStudent(tPage,searchContent,schoolId);
PageUtils pageUtils = new PageUtils(saveStudent);
return pageUtils;
}
@Transactional
@Override
public boolean deleteStudent(List<Integer> studentId) {
boolean delete = studentDao.deleteStudent(studentId);
return delete;
}
}

@ -3,6 +3,7 @@ package com.msdw.tms.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.msdw.tms.common.utils.Constant;
import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.common.utils.Query;
import com.msdw.tms.common.utils.R;
@ -14,6 +15,7 @@ import com.msdw.tms.entity.response.ResultCode;
import com.msdw.tms.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.Map;
@ -58,4 +60,12 @@ public R add(UserInfoEntity userInfoEntity) {
String s = userInfoDao.queryUserPassword(userId);
return s;
}
@Transactional
@Override
public int saveUserInfo(UserInfoEntity userInfo) {
userInfo.setUniqueIdentificationAccount(String.valueOf(System.currentTimeMillis())).setIsdel(Constant.IsDel.NOT_DEL.getType());
int userId = userInfoDao.saveUserInfo(userInfo);
return userId;
}
}

@ -2,4 +2,42 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.msdw.tms.dao.StudentDao">
<select id="queryStudent" resultType="com.msdw.tms.entity.vo.StudentVo">
SELECT
l.schoolId,
l.schoolName,
u.userId,
u.userName,
account,
logInNumber,
lastLoginTime,
s.roleId,
s.studentIdNumber
FROM
hr_user_info u,
tms_student s,
school l
WHERE
u.schoolId = #{schoolId}
AND u.schoolId = s.schoolId
AND u.schoolId = l.schoolId
<if test="searchContent!=null">AND (u.userName LIKE CONCAT('%',#{searchContent},'%') OR s.studentIdNumber LIKE CONCAT('%',#{searchContent},'%'))</if>
ORDER BY
lastLoginTime DESC
</select>
<insert id="saveStudent" useGeneratedKeys="true" keyProperty="studentId">
INSERT INTO tms_student ( schoolId, userId, studentIdNumber, professionalId, gradeId, classId, roleId, isdel )
VALUES
( #{schoolId},#{userId},#{studentIdNumber},#{professionalId},#{gradeId},#{classId},#{roleId},#{isdel}
)
</insert>
<update id="deleteStudent" parameterType="com.msdw.tms.entity.StudentEntity">
UPDATE tms_student
SET isdel = 1
WHERE studentId IN (
<foreach collection="list" separator="," item="studentId">#{studentId}</foreach>
)
</update>
</mapper>

@ -59,4 +59,10 @@
<select id="queryUserPassword" resultType="string">
SELECT `password` FROM hr_user_info WHERE userId = #{userId}
</select>
<insert id="saveUserInfo" useGeneratedKeys="true" keyProperty="userId" keyColumn="userId">
INSERT INTO hr_user_info ( uniqueIdentificationAccount, schoolId, account, roleId,isdel)
VALUES
( #{uniqueIdentificationAccount}, #{schoolId}, #{account}, 4 ,#{isdel})
</insert>
</mapper>

@ -0,0 +1,66 @@
package com.msdw.tms.service;
import cn.hutool.system.UserInfo;
import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.common.utils.R;
import com.msdw.tms.controller.StudentController;
import com.msdw.tms.entity.UserInfoEntity;
import com.msdw.tms.entity.vo.StudentVo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList;
import java.util.List;
@SpringBootTest
public class StudentTest {
@Autowired
private StudentService studentService;
@Autowired
private UserInfoService userInfoService;
/**
* 添加学生
*/
@Test
public void addStudent(){
StudentVo studentVo = new StudentVo();
Integer a = 1;
UserInfoEntity userInfoEntity = new UserInfoEntity();
userInfoEntity.setAccount("123456").setUserName("michonne").setSchoolId(a);
studentVo.setSchoolId(a).setUserId(257).setStudentIdNumber("888888").setRoleId(4).setProfessionalId(1).setGradeId(1).setClassId(1);
studentVo.setUserInfo(userInfoEntity);
boolean aa= studentService.saveStudent(studentVo);
// boolean bb = userInfoService.saveUserInfo(userInfoEntity);
System.out.println(aa ? "添加成功" : "添加失败");
}
/**
* 学生列表
*/
@Test
public void queryStudent(){
Integer schoolId = 1;
String searchContent = "michonne";
Integer page = 1;
Integer size = 20;
PageUtils pageUtils = studentService.queryStudent(schoolId,searchContent,page,size);
System.out.println(pageUtils);
}
/**
* 删除学生
*/
// @Test
// public void deleteStudent(){
// List<Integer> studentId = {1,2};
//// List<Integer> studentId = new ArrayList<>();
//// studentId.add(1);
//// studentId.add(2);
//
// boolean b = studentService.deleteStudent(studentId);
// System.out.println(b ? "删除成功" : "删除失败");
// }
}
Loading…
Cancel
Save