diff --git a/src/main/java/com/msdw/tms/api/StudentControllerApi.java b/src/main/java/com/msdw/tms/api/StudentControllerApi.java index e448eea..947ba24 100644 --- a/src/main/java/com/msdw/tms/api/StudentControllerApi.java +++ b/src/main/java/com/msdw/tms/api/StudentControllerApi.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 studentId); + + @ApiOperation(value = "编辑学生信息",notes = "编辑学生信息") + public R updateStudent(StudentVo studentVo); } diff --git a/src/main/java/com/msdw/tms/controller/StudentController.java b/src/main/java/com/msdw/tms/controller/StudentController.java index 04405bf..9fecd4d 100644 --- a/src/main/java/com/msdw/tms/controller/StudentController.java +++ b/src/main/java/com/msdw/tms/controller/StudentController.java @@ -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 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(); } + + } diff --git a/src/main/java/com/msdw/tms/dao/StudentDao.java b/src/main/java/com/msdw/tms/dao/StudentDao.java index f3c88e9..385986e 100644 --- a/src/main/java/com/msdw/tms/dao/StudentDao.java +++ b/src/main/java/com/msdw/tms/dao/StudentDao.java @@ -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 { + boolean saveStudent(StudentVo studentVo); + + IPage queryStudent(Page tpage,String searchContent,Integer schoolId); + + boolean deleteStudent(List studentId); } diff --git a/src/main/java/com/msdw/tms/dao/UserInfoDao.java b/src/main/java/com/msdw/tms/dao/UserInfoDao.java index 6ed791c..0fb9efe 100644 --- a/src/main/java/com/msdw/tms/dao/UserInfoDao.java +++ b/src/main/java/com/msdw/tms/dao/UserInfoDao.java @@ -15,4 +15,6 @@ public interface UserInfoDao extends BaseMapper { void userInfupdateUserInfoById(UserInfoEntity entity); String queryUserPassword(Integer userid); + + int saveUserInfo(UserInfoEntity userInfo); } diff --git a/src/main/java/com/msdw/tms/entity/vo/StudentVo.java b/src/main/java/com/msdw/tms/entity/vo/StudentVo.java index e5a7390..ae21864 100644 --- a/src/main/java/com/msdw/tms/entity/vo/StudentVo.java +++ b/src/main/java/com/msdw/tms/entity/vo/StudentVo.java @@ -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; + + } diff --git a/src/main/java/com/msdw/tms/service/StudentService.java b/src/main/java/com/msdw/tms/service/StudentService.java index 6b3dab0..0ff0daa 100644 --- a/src/main/java/com/msdw/tms/service/StudentService.java +++ b/src/main/java/com/msdw/tms/service/StudentService.java @@ -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{ + boolean saveStudent(StudentVo studentvo); + + PageUtils queryStudent(Integer schoolId,String searchContent, Integer page, Integer size); + + boolean deleteStudent(List studentId); } diff --git a/src/main/java/com/msdw/tms/service/UserInfoService.java b/src/main/java/com/msdw/tms/service/UserInfoService.java index 2bacae2..356be7a 100644 --- a/src/main/java/com/msdw/tms/service/UserInfoService.java +++ b/src/main/java/com/msdw/tms/service/UserInfoService.java @@ -16,4 +16,7 @@ public interface UserInfoService extends IService { void updateUserInfoById(UserInfoEntity entity); String queryPasword(Integer userId); + + int saveUserInfo(UserInfoEntity userInfo); + } diff --git a/src/main/java/com/msdw/tms/service/impl/StudentServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/StudentServiceImpl.java index ebf611f..3a70348 100644 --- a/src/main/java/com/msdw/tms/service/impl/StudentServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/StudentServiceImpl.java @@ -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 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 tPage = new Page<>(page,size); + IPage saveStudent = studentDao.queryStudent(tPage,searchContent,schoolId); + PageUtils pageUtils = new PageUtils(saveStudent); + return pageUtils; + } + + @Transactional + @Override + public boolean deleteStudent(List studentId) { + + boolean delete = studentDao.deleteStudent(studentId); + return delete; + } + } diff --git a/src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java index e0c60c3..cbb7310 100644 --- a/src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java @@ -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; + } } diff --git a/src/main/resources/mapper/tms/StudentDao.xml b/src/main/resources/mapper/tms/StudentDao.xml index baa1f80..d98a74e 100644 --- a/src/main/resources/mapper/tms/StudentDao.xml +++ b/src/main/resources/mapper/tms/StudentDao.xml @@ -2,4 +2,42 @@ + + + + INSERT INTO tms_student ( schoolId, userId, studentIdNumber, professionalId, gradeId, classId, roleId, isdel ) + VALUES + ( #{schoolId},#{userId},#{studentIdNumber},#{professionalId},#{gradeId},#{classId},#{roleId},#{isdel} + ) + + + + UPDATE tms_student + SET isdel = 1 + WHERE studentId IN ( + #{studentId} + ) + \ No newline at end of file diff --git a/src/main/resources/mapper/tms/UserInfoDao.xml b/src/main/resources/mapper/tms/UserInfoDao.xml index 7a7f05a..fba849b 100644 --- a/src/main/resources/mapper/tms/UserInfoDao.xml +++ b/src/main/resources/mapper/tms/UserInfoDao.xml @@ -59,4 +59,10 @@ + + + INSERT INTO hr_user_info ( uniqueIdentificationAccount, schoolId, account, roleId,isdel) + VALUES + ( #{uniqueIdentificationAccount}, #{schoolId}, #{account}, 4 ,#{isdel}) + \ No newline at end of file diff --git a/src/test/java/com/msdw/tms/service/StudentTest.java b/src/test/java/com/msdw/tms/service/StudentTest.java new file mode 100644 index 0000000..10d0446 --- /dev/null +++ b/src/test/java/com/msdw/tms/service/StudentTest.java @@ -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 studentId = {1,2}; +//// List studentId = new ArrayList<>(); +//// studentId.add(1); +//// studentId.add(2); +// +// boolean b = studentService.deleteStudent(studentId); +// System.out.println(b ? "删除成功" : "删除失败"); +// } +}