From 0d2ba8feb248c3ac673c0fc718d3826ab544ee2c Mon Sep 17 00:00:00 2001 From: "jiakun.lin" Date: Tue, 16 Mar 2021 14:20:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E6=B7=BB=E5=8A=A0=E5=BF=85?= =?UTF-8?q?=E9=A1=BB=E8=A6=81=E5=B8=A6=E5=AD=A6=E5=8F=B7=EF=BC=8C=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E5=AD=A6=E5=8F=B7=E5=94=AF=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../msdw/tms/api/UserInfoControllerApi.java | 2 +- .../tms/controller/UserInfoController.java | 23 +++++++++++++++---- .../java/com/msdw/tms/dao/StudentDao.java | 4 +++- .../com/msdw/tms/service/StudentService.java | 3 ++- .../tms/service/impl/StudentServiceImpl.java | 18 ++++++++------- src/main/resources/mapper/tms/StudentDao.xml | 8 +++++-- 6 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/msdw/tms/api/UserInfoControllerApi.java b/src/main/java/com/msdw/tms/api/UserInfoControllerApi.java index 51edcf5..037f505 100644 --- a/src/main/java/com/msdw/tms/api/UserInfoControllerApi.java +++ b/src/main/java/com/msdw/tms/api/UserInfoControllerApi.java @@ -24,7 +24,7 @@ public interface UserInfoControllerApi { R getUserId(String token); @ApiOperation(value = "注册",notes = "注册") - R save(UserInfoEntity entity); + R save(UserInfoEntity entity,@ApiParam(value = "学号",required = true)String workNumber); @ApiOperation(value = "个人中心信息展示",notes = "个人中心信息展示") R userInfo(Integer id); diff --git a/src/main/java/com/msdw/tms/controller/UserInfoController.java b/src/main/java/com/msdw/tms/controller/UserInfoController.java index 5f9586a..f5bac50 100644 --- a/src/main/java/com/msdw/tms/controller/UserInfoController.java +++ b/src/main/java/com/msdw/tms/controller/UserInfoController.java @@ -8,6 +8,7 @@ import com.msdw.tms.entity.UserEntity; import com.msdw.tms.entity.UserInfoEntity; import com.msdw.tms.entity.UserPersonalFileEntity; import com.msdw.tms.entity.vo.CheckVo; +import com.msdw.tms.entity.vo.StudentVo; import com.msdw.tms.entity.vo.UserEntityVo; import com.msdw.tms.entity.vo.UserProsonalEntityVo; import com.msdw.tms.service.StudentService; @@ -58,27 +59,41 @@ public class UserInfoController implements UserInfoControllerApi { @Override @Transactional @PostMapping("/add") - public R save(@RequestBody UserInfoEntity userInfoEntity){ + public R save(@RequestBody UserInfoEntity userInfoEntity,@RequestParam String workNumber){ String token ="UT_"+ UUID.randomUUID().toString().replace("-", ""); userInfoEntity.setToken(token); userInfoEntity.setSchoolId(2105); Integer schoolId = userInfoEntity.getSchoolId(); Integer integer = userInfoService.queryStudentAccount(userInfoEntity.getAccount(),schoolId); Integer integer1 = userInfoService.queryStudentPhone(userInfoEntity.getPhone()); + + //新增学生 + StudentVo studentVo = new StudentVo(); + studentVo.setUserId(userInfoEntity.getUserId()); + studentVo.setRoleId(Integer.valueOf(userInfoEntity.getRoleId())); + studentVo.setSchoolId(schoolId); + studentVo.setIsdel(0); + studentVo.setWorkNumber(workNumber); + studentVo.setPlatformId(1); + //为1 学号有重复 + int num = studentService.queryStudentByWorkNumber(studentVo); + if (integer==1){ return R.error(400,"账号已存在"); } if (integer1==1){ - return R.error(400,"改手机号已被绑定"); + return R.error(400,"该手机号已被绑定"); + } + if (num == 1){ + return R.error(400,"该学号重复!"); } int userId = userInfoService.add(userInfoEntity); if (userId==0){ return R.error(400,"添加用户信息失败"); } // userInfoEntity.setUserId(userId); - studentService.addStudentInfo(userInfoEntity); - return R.ok(); + return studentService.addStudentInfo(studentVo); } /** diff --git a/src/main/java/com/msdw/tms/dao/StudentDao.java b/src/main/java/com/msdw/tms/dao/StudentDao.java index b426e78..1dff280 100644 --- a/src/main/java/com/msdw/tms/dao/StudentDao.java +++ b/src/main/java/com/msdw/tms/dao/StudentDao.java @@ -28,7 +28,7 @@ public interface StudentDao extends BaseMapper { void updateWorkNumber(String workNumber,Integer studentId); - boolean addStudentInfo(UserInfoEntity userInfoEntity); + boolean addStudentInfo(StudentVo studentVo); List querySchoolName(String schoolAppellationName); @@ -37,4 +37,6 @@ public interface StudentDao extends BaseMapper { int querySchoolAppellationName(String schoolAppellationName); List queryAccount(String account,Integer schoolId); + + int queryStudentByWorkNumber(StudentVo studentVo); } diff --git a/src/main/java/com/msdw/tms/service/StudentService.java b/src/main/java/com/msdw/tms/service/StudentService.java index 05d99e9..efc4e0e 100644 --- a/src/main/java/com/msdw/tms/service/StudentService.java +++ b/src/main/java/com/msdw/tms/service/StudentService.java @@ -30,7 +30,7 @@ public interface StudentService extends IService{ void updateWorkNumber(Integer studentId); - R addStudentInfo(UserInfoEntity userInfoEntity); + R addStudentInfo(StudentVo studentVo); void downloadFiles(HttpServletResponse response) throws IOException; @@ -40,4 +40,5 @@ public interface StudentService extends IService{ R queryAccount(String account,Integer schoolId); + int queryStudentByWorkNumber(StudentVo studentVo); } 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 cca9696..e3a099d 100644 --- a/src/main/java/com/msdw/tms/service/impl/StudentServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/StudentServiceImpl.java @@ -122,18 +122,15 @@ public class StudentServiceImpl extends ServiceImpl im } @Override - public R addStudentInfo(UserInfoEntity userInfoEntity) { + public R addStudentInfo(StudentVo studentVo) { R r = new R(); - boolean result = studentDao.addStudentInfo(userInfoEntity); + boolean result = studentDao.addStudentInfo(studentVo); if (result==false){ - r.put("code",300); - r.put("errmessage","注册失败!"); - return r; + throw new RuntimeException();//添加失败,抛出运行时异常让外层事务回滚 }else{ - r.put("code",200); - r.put("errmessage","注册成功!"); - return r; + return R.ok("注册成功!"); } + } @Override @@ -310,4 +307,9 @@ public class StudentServiceImpl extends ServiceImpl im } + @Override + public int queryStudentByWorkNumber(StudentVo studentVo) { + return studentDao.queryStudentByWorkNumber(studentVo); + } + } diff --git a/src/main/resources/mapper/tms/StudentDao.xml b/src/main/resources/mapper/tms/StudentDao.xml index e421705..6a11653 100644 --- a/src/main/resources/mapper/tms/StudentDao.xml +++ b/src/main/resources/mapper/tms/StudentDao.xml @@ -94,9 +94,9 @@ WHERE ) - INSERT INTO student(schoolId,userId,roleId,isdel,platformId) + INSERT INTO student(schoolId,userId,roleId,isdel,platformId,workNumber) VALUES - ( #{schoolId},#{userId},4,0,1 + ( #{schoolId},#{userId},#{roleId},#{isdel},#{platformId},#{workNumber} ) @@ -146,4 +146,8 @@ WHERE update student set workNumber = #{workNumber} where studentId = #{studentId} + + \ No newline at end of file