diff --git a/pom.xml b/pom.xml index b9db35f..cfc7e35 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,11 @@ poi-ooxml-schemas 4.0.1 + + redis.clients + jedis + 2.9.3 + org.springframework.boot diff --git a/src/main/java/com/msdw/tms/api/EvaluationRecordControllerApi.java b/src/main/java/com/msdw/tms/api/EvaluationRecordControllerApi.java index 2ec18f6..5556157 100644 --- a/src/main/java/com/msdw/tms/api/EvaluationRecordControllerApi.java +++ b/src/main/java/com/msdw/tms/api/EvaluationRecordControllerApi.java @@ -40,7 +40,7 @@ public interface EvaluationRecordControllerApi { * 开始测评,返回第一题的数据 */ @ApiOperation(value = "开始测评", notes = "开始测评") - R startEvaluation(Integer userId,Integer type); + R startEvaluation(Integer userId); /** * 上一题 diff --git a/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java b/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java index 3086fcd..2d67884 100644 --- a/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java +++ b/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java @@ -4,6 +4,7 @@ import com.msdw.tms.common.utils.R; import com.msdw.tms.entity.request.QuestionsAddRequest; import com.msdw.tms.entity.request.QuestionsQueryRequest; import com.msdw.tms.entity.request.QuestionsUpdateRequest; +import com.msdw.tms.entity.vo.RulesVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -51,6 +52,8 @@ public interface QuestionsControllerApi { /** * 是否禁用试题 */ +// @ApiOperation(value = "是否禁用试题", notes = "是否禁用试题") +// R isNable(RulesVo rulesVo); @ApiOperation(value = "是否禁用试题", notes = "是否禁用试题") R isNable(@ApiParam(name = "id", value = "试题主键", required = true) List idList); // 2020.09.18 diff --git a/src/main/java/com/msdw/tms/api/StudentControllerApi.java b/src/main/java/com/msdw/tms/api/StudentControllerApi.java index dec5a8c..faac6bd 100644 --- a/src/main/java/com/msdw/tms/api/StudentControllerApi.java +++ b/src/main/java/com/msdw/tms/api/StudentControllerApi.java @@ -6,7 +6,10 @@ 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 org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.List; @Api(value = "学生管理", tags = "学生管理") @@ -25,8 +28,14 @@ public interface StudentControllerApi { public R updateStudent(StudentVo studentVo); @ApiOperation(value = "重置密码",notes = "重置密码") - public R reSetPassword(Integer userId); + public R reSetPassword(List userId); @ApiOperation(value = "禁用账号",notes = "禁用账号") - public R disableAccount(Integer userId); + public R disableAccount(StudentVo studentIds); + + @ApiOperation(value = "下载导入模板", notes = "下载导入模板") + public R downloadFiles(HttpServletResponse response) throws IOException; + + @ApiOperation(value = "批量导入学生信息",notes = "批量导入学生信息") + public R uploadFile(MultipartFile file) throws IOException; } diff --git a/src/main/java/com/msdw/tms/common/utils/ConstantUtils.java b/src/main/java/com/msdw/tms/common/utils/ConstantUtils.java new file mode 100644 index 0000000..5fd6312 --- /dev/null +++ b/src/main/java/com/msdw/tms/common/utils/ConstantUtils.java @@ -0,0 +1,22 @@ +package com.msdw.tms.common.utils; + +/** + * 此类用于公用常量设置 + */ +public class ConstantUtils { + //绑定电子科大的schoolId + public static final Integer Keda_schoolId = 2105; + + //绑定角色ID + public static final Integer STUDENT_ROLE = 4; + public static final String STR_STUDENT_ROLE = "4"; + + //平台id + public static final Integer PLATFORMID= 1; + + //excel模板信息表id + public static final int XLSX_TEMPLATE_ID = 2; + + //用户初始密码 + public static final String INITIAL_PASSWORD = "huoran123"; +} diff --git a/src/main/java/com/msdw/tms/common/utils/ExcelImportHelper.java b/src/main/java/com/msdw/tms/common/utils/ExcelImportHelper.java new file mode 100644 index 0000000..e17d364 --- /dev/null +++ b/src/main/java/com/msdw/tms/common/utils/ExcelImportHelper.java @@ -0,0 +1,109 @@ +package com.msdw.tms.common.utils; + +import com.msdw.tms.entity.vo.StudentVo; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class ExcelImportHelper { + + /** + * 读取学生管理 + * @param file + * @return + */ + public static List readStudent(MultipartFile file) { + List list = new ArrayList(); + + Workbook workbook=getWorkbook(file); + StudentVo student = null; + // 循环工作表Sheet + for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) { + Sheet hssfSheet = workbook.getSheetAt(numSheet); + if (hssfSheet == null) { + continue; + } + // 循环行Row//开始行2 + for (int rowNum = 2; rowNum <= hssfSheet.getLastRowNum(); rowNum++) { + Row row = hssfSheet.getRow(rowNum); + + Cell phone; + Cell email; + if (row != null) { + student = new StudentVo(); + row.getCell(0).setCellType(CellType.STRING); + Cell studentName = row.getCell(0); + row.getCell(1).setCellType(CellType.STRING); + Cell schoolAppellationName = row.getCell(1); + row.getCell(2).setCellType(CellType.STRING); + Cell account = row.getCell(2); + row.getCell(3).setCellType(CellType.STRING); + Cell studentNumber = row.getCell(3); + if (row.getCell(4)!=null){ + row.getCell(4).setCellType(CellType.STRING); + phone = row.getCell(4); + }else { + phone = row.createCell(4); + } + if (row.getCell(5)!=null){ + row.getCell(5).setCellType(CellType.STRING); + email = row.getCell(5); + }else { + email = row.createCell(5); + } +// row.getCell(4).setCellType(CellType.STRING); +// Cell phone = row.getCell(4); +// row.getCell(5).setCellType(CellType.STRING); +// Cell email = row.getCell(5); + + + // 学生姓名 + student.setUserName(studentName.getStringCellValue()); + // 角色id + student.setRoleId(ConstantUtils.STUDENT_ROLE); + // 学生学号 + student.setWorkNumber(studentNumber.getStringCellValue()); + //所属院校 + student.setSchoolAppellationName(schoolAppellationName.getStringCellValue()); + //用户账号 + student.setAccount(account.getStringCellValue()); + //电话 + student.setPhone(phone.getStringCellValue()); + //邮箱 + student.setEmail(email.getStringCellValue()); + //学校id + student.setSchoolId(ConstantUtils.Keda_schoolId); + list.add(student); + } + } + + } + + return list; + } + + private static Workbook getWorkbook(MultipartFile file) { + String fileName = file.getOriginalFilename(); + Workbook workbook = null; + + if (fileName.endsWith("xlsx")) { + try { + workbook = new XSSFWorkbook(file.getInputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + }else if (fileName.endsWith("xls")) { + try { + workbook = new HSSFWorkbook(file.getInputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + } + return workbook; + } +} diff --git a/src/main/java/com/msdw/tms/controller/EvaluationRecordController.java b/src/main/java/com/msdw/tms/controller/EvaluationRecordController.java index a2cdf17..32dc244 100644 --- a/src/main/java/com/msdw/tms/controller/EvaluationRecordController.java +++ b/src/main/java/com/msdw/tms/controller/EvaluationRecordController.java @@ -57,9 +57,10 @@ public class EvaluationRecordController implements EvaluationRecordControllerApi @Override @GetMapping("/start") - public R startEvaluation(@RequestParam(value = "userId") Integer userId,Integer type) { +// public R startEvaluation(@RequestParam(value = "userId") Integer userId,Integer type) { + public R startEvaluation(@RequestParam(value = "userId") Integer userId) { TMSEvaluationRecordVO evaluationRecordVO = evaluationRecordService.startEvaluation(userId); - evaluationRecordVO.setTypes(type); +// evaluationRecordVO.setTypes(type); return R.ok().put("data", evaluationRecordVO); } diff --git a/src/main/java/com/msdw/tms/controller/QuestionsController.java b/src/main/java/com/msdw/tms/controller/QuestionsController.java index 6c05485..b4402e2 100644 --- a/src/main/java/com/msdw/tms/controller/QuestionsController.java +++ b/src/main/java/com/msdw/tms/controller/QuestionsController.java @@ -1,14 +1,20 @@ package com.msdw.tms.controller; import com.msdw.tms.api.QuestionsControllerApi; +import com.msdw.tms.common.exception.ExceptionCast; +import com.msdw.tms.common.utils.Constant; import com.msdw.tms.common.utils.FilesResult; import com.msdw.tms.common.utils.PageUtils; import com.msdw.tms.common.utils.R; +import com.msdw.tms.entity.EvaluationRulesEntity; +import com.msdw.tms.entity.QuestionsEntity; import com.msdw.tms.entity.request.QuestionsAddRequest; import com.msdw.tms.entity.request.QuestionsQueryRequest; import com.msdw.tms.entity.request.QuestionsUpdateRequest; +import com.msdw.tms.entity.response.CommonCode; import com.msdw.tms.entity.vo.EvaluationVO; import com.msdw.tms.entity.vo.QuestionsDetailVO; +import com.msdw.tms.entity.vo.RulesVo; import com.msdw.tms.service.QuestionsService; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; @@ -86,13 +92,12 @@ public class QuestionsController implements QuestionsControllerApi { return update ? R.ok() : R.error(); } + /** * 是否禁用试题 */ -// @Override + @Override @PutMapping("/isenable") -// 2020.09.18 -// @RequiresPermissions("qms:questions:isenable") // public R isNable(@RequestBody Integer id) { public R isNable(@RequestBody List idList) { Integer id = idList.get(0); @@ -101,6 +106,56 @@ public class QuestionsController implements QuestionsControllerApi { return b ? R.ok() : R.error(); } +// /** +// * 是否禁用试题 +// */ +// @Override +// @PutMapping("/isenable") +//// 2020.09.18 +//// @RequiresPermissions("qms:questions:isenable") +//// public R isNable(@RequestBody Integer id) { +// public R isNable(@RequestBody RulesVo rules) { +//// public R isNable(@RequestBody List idList) { +//// Integer id = idList.get(0); +// QuestionsEntity questionsEntity = new QuestionsEntity(); +// Integer id = rules.getQuestionId(); +// questionsEntity.setId(id); +// QuestionsEntity byId = questionsService.getById(id); +// int rulesNumber = rules.getQuestionsNumber(); +// if (byId.getIsEnable().equals(Constant.IsEnable.ENABLE.getType())) { +// Integer types = rules.getTypes(); +//// String questionsTypes= types==1 ? "single_num" : (types==2 ? "multiple_num":"judgment_num");//根据题型获取数据库字段名 +// EvaluationRulesEntity rule = questionsService.queryNumberOfTatolQuestions(); +// int num = 0; +// if (types==1){ +// num += rule.getSingleNum(); +// }else if (types==2){ +// num += rule.getMultipleNum(); +// }else if (types==3){ +// num += rule.getJudgmentNum(); +// } +// if (num userIds){ + Integer userId = userIds.get(0); + try { + Integer initial = userInfoService.initialPassword(userId); + if (initial==0){ + return R.error(400,"密码不变,更新成功"); + } + }catch (RuntimeException e){ + e.printStackTrace(); + return R.error(); + } + return R.ok(); } /** * 禁用账号 - * @param studentId + * @param studentIds * @return */ @Override @PutMapping("/disableAccount") - public R disableAccount(@RequestBody Integer studentId) { - boolean disable = studentService.disableAccount(studentId); - return disable ? R.ok() : R.error(); + public R disableAccount(@RequestBody StudentVo studentIds) { + + Integer state = studentIds.getDisableAccount(); + if (state==0){ + studentIds.setDisableAccount(1); + }else if(state==1){ + studentIds.setDisableAccount(0); + } + userInfoService.disableAccount(studentIds); + return R.ok(); } + public R downLoadStudent(){ + return R.ok(); + } + + /** + * excel模板文件下载 + */ + @Override + @GetMapping("/download") + public R downloadFiles(HttpServletResponse response) throws IOException { + studentService.downloadFiles(response); + return R.ok(); + } + + /** + * 批量导入学生信息 + * @param file + * @return + */ + @Override + @PostMapping("/uploadFile") + public R uploadFile(MultipartFile file) throws IOException{ + Integer schoolId = ConstantUtils.Keda_schoolId; + HashMap upload = studentService.upload(file,schoolId); + return R.ok().put("data",upload); + } + + @PostMapping("/export_failure") + public void exportFailureRecord(HttpServletResponse response, String token) throws Exception{ + + studentService.exportFailureRecord(response,token); + } } diff --git a/src/main/java/com/msdw/tms/controller/UserInfoController.java b/src/main/java/com/msdw/tms/controller/UserInfoController.java index 5b25442..552db3d 100644 --- a/src/main/java/com/msdw/tms/controller/UserInfoController.java +++ b/src/main/java/com/msdw/tms/controller/UserInfoController.java @@ -7,6 +7,7 @@ import com.msdw.tms.common.utils.R; import com.msdw.tms.entity.UserEntity; import com.msdw.tms.entity.UserInfoEntity; import com.msdw.tms.entity.vo.UserEntityVo; +import com.msdw.tms.service.StudentService; import com.msdw.tms.service.UserInfoService; import com.msdw.tms.service.UserService; import org.springframework.beans.factory.annotation.Autowired; @@ -14,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import java.util.Arrays; +import java.util.List; import java.util.Map; @RestController @@ -22,6 +24,9 @@ public class UserInfoController implements UserInfoControllerApi { @Autowired private UserInfoService userInfoService; + @Autowired + private StudentService studentService; + /** * 列表 */ @@ -46,9 +51,26 @@ public class UserInfoController implements UserInfoControllerApi { /** * 注册 */ + @Override + @Transactional @PostMapping("/add") public R save(@RequestBody UserInfoEntity userInfoEntity){ - userInfoService.add(userInfoEntity); + userInfoEntity.setSchoolId(2105); + Integer schoolId = userInfoEntity.getSchoolId(); + Integer integer = userInfoService.queryStudentAccount(userInfoEntity.getAccount(),schoolId); + Integer integer1 = userInfoService.queryStudentPhone(userInfoEntity.getPhone(),schoolId); + if (integer==1){ + return R.error(400,"账号已存在"); + } + if (integer1==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(); } @@ -56,6 +78,7 @@ public class UserInfoController implements UserInfoControllerApi { /** * 修改 */ + @Override @PutMapping("/update") public R update(@RequestBody UserInfoEntity userEntity){ userInfoService.updateById(userEntity); diff --git a/src/main/java/com/msdw/tms/dao/QuestionsDao.java b/src/main/java/com/msdw/tms/dao/QuestionsDao.java index 0a64cba..a5399e1 100644 --- a/src/main/java/com/msdw/tms/dao/QuestionsDao.java +++ b/src/main/java/com/msdw/tms/dao/QuestionsDao.java @@ -1,7 +1,9 @@ package com.msdw.tms.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.msdw.tms.entity.EvaluationRulesEntity; import com.msdw.tms.entity.QuestionsEntity; +import com.msdw.tms.entity.vo.QuestionsDetailVO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -23,4 +25,9 @@ public interface QuestionsDao extends BaseMapper { Integer countTotalMultiplenum(); Integer countTotalJudgmentnum(); + + EvaluationRulesEntity queryNumberOfQuestions(); + + EvaluationRulesEntity queryNumberOfTatolQuestions(); + } diff --git a/src/main/java/com/msdw/tms/dao/StudentDao.java b/src/main/java/com/msdw/tms/dao/StudentDao.java index c036ef3..320d1aa 100644 --- a/src/main/java/com/msdw/tms/dao/StudentDao.java +++ b/src/main/java/com/msdw/tms/dao/StudentDao.java @@ -4,6 +4,7 @@ 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.UserInfoEntity; import com.msdw.tms.entity.vo.StudentVo; import org.apache.ibatis.annotations.Mapper; import org.apache.poi.ss.formula.functions.T; @@ -13,17 +14,23 @@ import java.util.List; @Mapper public interface StudentDao extends BaseMapper { - List queryStudentIdNumber(String studentIdNumber); + List queryStudentIdNumber(String workNumber,Integer schoolId); boolean saveStudent(StudentVo studentVo); IPage queryStudent(Page tpage,String searchContent,Integer schoolId); - boolean deleteStudent(List studentId); + Integer deleteStudent(List studentId); - boolean updateStudent(StudentVo studentVo); + Integer updateStudent(StudentVo studentVo); - boolean initialPassword(Integer userId,String password); + void updateWorkNumber(String workNumber); - boolean disableAccount(Integer studentId); + boolean addStudentInfo(UserInfoEntity userInfoEntity); + + List querySchoolName(String schoolAppellationName); + + int bacthAddStudents(List students); + + int querySchoolAppellationName(String schoolAppellationName); } diff --git a/src/main/java/com/msdw/tms/dao/UserInfoDao.java b/src/main/java/com/msdw/tms/dao/UserInfoDao.java index 0fb9efe..c5e8b6f 100644 --- a/src/main/java/com/msdw/tms/dao/UserInfoDao.java +++ b/src/main/java/com/msdw/tms/dao/UserInfoDao.java @@ -2,19 +2,37 @@ package com.msdw.tms.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.msdw.tms.common.utils.R; +import com.msdw.tms.entity.StudentEntity; import com.msdw.tms.entity.UserEntity; import com.msdw.tms.entity.UserInfoEntity; +import com.msdw.tms.entity.vo.StudentVo; import com.msdw.tms.entity.vo.UserEntityVo; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; @Mapper public interface UserInfoDao extends BaseMapper { - Boolean add(UserInfoEntity userEntity); + int add(UserInfoEntity userEntity); void userInfupdateUserInfoById(UserInfoEntity entity); String queryUserPassword(Integer userid); int saveUserInfo(UserInfoEntity userInfo); + + Integer initialPassword(Integer userId, String password); + + Integer disableAccount(StudentVo studentIds); + + List queryStudentAccount(String account,Integer schoolId); + + List queryStudentPhone(String phone,Integer schoolId); + + int bacthAddStudents(List students); + + int batchSaveUserInfo(StudentVo studentVo); + } diff --git a/src/main/java/com/msdw/tms/entity/StudentEntity.java b/src/main/java/com/msdw/tms/entity/StudentEntity.java index 453ba5b..c536303 100644 --- a/src/main/java/com/msdw/tms/entity/StudentEntity.java +++ b/src/main/java/com/msdw/tms/entity/StudentEntity.java @@ -7,7 +7,7 @@ import lombok.Data; import lombok.experimental.Accessors; @Data -@TableName("tms_student") +@TableName("student") @Accessors(chain = true) public class StudentEntity { @@ -19,17 +19,25 @@ public class StudentEntity { //绑定用户Id private Integer userId; //学号 - private String studentIdNumber; + private String workNumber; //绑定专业Id private Integer professionalId; + //绑定专业名称 + private String professionalName; //绑定年级Id private Integer gradeId; + //绑定年级名称 + private String gradeName; //绑定班级Id、 private Integer classId; + //绑定班级名称 + private String className; //绑定角色Id private Integer roleId; + //登录次数 + private Integer loginNumber; //是否删除(0未删除,1已删除) private Integer isdel; - //是否禁用账号(0禁用,1不禁用,默认0) - private Integer disableAccount; + //绑定平台id(默认手写1) + private Integer platformId; } diff --git a/src/main/java/com/msdw/tms/entity/UserInfoEntity.java b/src/main/java/com/msdw/tms/entity/UserInfoEntity.java index b69bda4..646ddb8 100644 --- a/src/main/java/com/msdw/tms/entity/UserInfoEntity.java +++ b/src/main/java/com/msdw/tms/entity/UserInfoEntity.java @@ -54,5 +54,8 @@ public class UserInfoEntity { private Integer isdel; //角色id private String roleId; - + //是否禁用(0未禁用1已禁用默认0) + private Integer disableAccount; + //所属院校id + private Integer schoolAppellationId; } diff --git a/src/main/java/com/msdw/tms/entity/vo/RulesVo.java b/src/main/java/com/msdw/tms/entity/vo/RulesVo.java new file mode 100644 index 0000000..8fb7d77 --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/vo/RulesVo.java @@ -0,0 +1,18 @@ +package com.msdw.tms.entity.vo; + +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +public class RulesVo { + //题型(1单选2多选3判断) + private Integer types; + //试题数量 + private Integer questionsNumber; + //测评对应该试题数量 +// private int rulesNumber; + //试题id + private Integer questionId; + +} 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 5d4fe9d..5983c85 100644 --- a/src/main/java/com/msdw/tms/entity/vo/StudentVo.java +++ b/src/main/java/com/msdw/tms/entity/vo/StudentVo.java @@ -14,21 +14,26 @@ import java.util.List; @Accessors(chain = true) public class StudentVo extends StudentEntity { - private UserInfoEntity userInfo; - //学校名称 private String schoolName; //用户姓名 private String userName; //用户账号 private String account; - //登陆次数 - private Integer logInNumber; + //密码 + private String password; //最后登陆时间 private String lastLoginTime; //电话 private String phone; //邮箱 private String email; - + //禁用状态 + private Integer disableAccount; + //所属院校 + private String schoolAppellation; + //唯一性标识账号 + private String uniqueIdentificationAccount; + //绑定所属院校名称 + private String schoolAppellationName; } diff --git a/src/main/java/com/msdw/tms/service/QuestionsService.java b/src/main/java/com/msdw/tms/service/QuestionsService.java index d8bf9b3..54698a4 100644 --- a/src/main/java/com/msdw/tms/service/QuestionsService.java +++ b/src/main/java/com/msdw/tms/service/QuestionsService.java @@ -3,12 +3,16 @@ package com.msdw.tms.service; import com.baomidou.mybatisplus.extension.service.IService; import com.msdw.tms.common.utils.FilesResult; import com.msdw.tms.common.utils.PageUtils; +import com.msdw.tms.common.utils.R; +import com.msdw.tms.entity.EvaluationRulesEntity; import com.msdw.tms.entity.QuestionsEntity; import com.msdw.tms.entity.request.QuestionsAddRequest; import com.msdw.tms.entity.request.QuestionsQueryRequest; import com.msdw.tms.entity.request.QuestionsUpdateRequest; import com.msdw.tms.entity.vo.EvaluationVO; import com.msdw.tms.entity.vo.QuestionsDetailVO; +import com.msdw.tms.entity.vo.RulesVo; +import org.apache.tomcat.util.digester.Rules; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; @@ -35,8 +39,6 @@ public interface QuestionsService extends IService { boolean isEnable(Integer id); - boolean deleteByIds(List asList); - Map importQuestion(MultipartFile file) throws IOException; FilesResult uploadFiles(MultipartFile file) throws IOException; @@ -50,5 +52,15 @@ public interface QuestionsService extends IService { String getEvaluationRemainingTime(Integer userId); void exportFailureRecord(HttpServletResponse response, String token) throws Exception; + + + + +// EvaluationRulesEntity queryNumberOfQuestions(); +// boolean isEnable(RulesVo rules,QuestionsEntity questionsEntity); +boolean deleteByIds(List asList); +//测评设置是否禁用试题 +// EvaluationRulesEntity queryNumberOfTatolQuestions(); + } diff --git a/src/main/java/com/msdw/tms/service/StudentService.java b/src/main/java/com/msdw/tms/service/StudentService.java index 1e03410..d26d8f4 100644 --- a/src/main/java/com/msdw/tms/service/StudentService.java +++ b/src/main/java/com/msdw/tms/service/StudentService.java @@ -2,15 +2,20 @@ package com.msdw.tms.service; import com.baomidou.mybatisplus.extension.service.IService; 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 org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.HashMap; import java.util.List; public interface StudentService extends IService{ - Integer queryStudentIdNumber(String studentIdNumber); + Integer queryStudentIdNumber(String workNumber,Integer schoolId); boolean saveStudent(StudentVo studentvo); @@ -20,7 +25,13 @@ public interface StudentService extends IService{ boolean updateStudent(StudentVo studentVo); - boolean initialPassword(Integer userId); + void updateWorkNumber(Integer studentId); - boolean disableAccount(Integer studentId); + R addStudentInfo(UserInfoEntity userInfoEntity); + + void downloadFiles(HttpServletResponse response) throws IOException; + + HashMap upload(MultipartFile file, Integer schoolId) throws IOException; + + void exportFailureRecord(HttpServletResponse response,String token); } diff --git a/src/main/java/com/msdw/tms/service/UserInfoService.java b/src/main/java/com/msdw/tms/service/UserInfoService.java index 356be7a..1fda227 100644 --- a/src/main/java/com/msdw/tms/service/UserInfoService.java +++ b/src/main/java/com/msdw/tms/service/UserInfoService.java @@ -4,14 +4,16 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.msdw.tms.common.utils.PageUtils; import com.msdw.tms.common.utils.R; import com.msdw.tms.entity.UserInfoEntity; +import com.msdw.tms.entity.vo.StudentVo; +import java.util.List; import java.util.Map; public interface UserInfoService extends IService { PageUtils queryPage(Map params); - R add(UserInfoEntity userInfoEntity); + int add(UserInfoEntity userInfoEntity); void updateUserInfoById(UserInfoEntity entity); @@ -19,4 +21,12 @@ public interface UserInfoService extends IService { int saveUserInfo(UserInfoEntity userInfo); + Integer initialPassword(Integer userId); + + void disableAccount(StudentVo studentIds); + + Integer queryStudentAccount(String account,Integer schoolId); + + Integer queryStudentPhone(String phone,Integer schoolId); + } diff --git a/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java index 9cbceff..f121590 100644 --- a/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java @@ -7,13 +7,11 @@ 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.exception.ExceptionCast; -import com.msdw.tms.common.utils.Constant; -import com.msdw.tms.common.utils.FilesResult; -import com.msdw.tms.common.utils.PageUtils; -import com.msdw.tms.common.utils.Query; +import com.msdw.tms.common.utils.*; import com.msdw.tms.common.utils.poi.ExcelExportUtil; import com.msdw.tms.common.utils.poi.ExcelImportUtil; import com.msdw.tms.dao.QuestionsDao; +import com.msdw.tms.entity.EvaluationRulesEntity; import com.msdw.tms.entity.QuestionsEntity; import com.msdw.tms.entity.XlsxTemplateEntity; import com.msdw.tms.entity.request.QuestionsAddRequest; @@ -28,6 +26,7 @@ import com.msdw.tms.service.QuestionsService; import com.msdw.tms.service.XlsxTemplateService; import org.apache.commons.lang.StringUtils; import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.ValueOperations; @@ -54,11 +53,11 @@ public class QuestionsServiceImpl extends ServiceImpl asList) { @@ -631,4 +637,18 @@ public class QuestionsServiceImpl extends ServiceImpl im @Autowired private StudentDao studentDao; - /** - * 初始密码 - */ - private static final String INITIAL_PASSWORD = "huoran123"; + @Resource + XlsxTemplateService xlsxTemplateService; + + @Resource + AliyunOssService ossService; + + @Autowired + private UserInfoDao userInfoDao; @Override - public Integer queryStudentIdNumber(String studentIdNumber) { - List result = studentDao.queryStudentIdNumber(studentIdNumber); + public Integer queryStudentIdNumber(String workNumber,Integer schoolId) { + List result = studentDao.queryStudentIdNumber(workNumber,schoolId); if (result.size()==1){ return 1; + }else{ + return 0; } - return 0; } @Transactional @@ -56,30 +74,192 @@ public class StudentServiceImpl extends ServiceImpl im @Override public boolean deleteStudent(List studentId) { - boolean delete = studentDao.deleteStudent(studentId); - return delete; + try { + Integer delete = studentDao.deleteStudent(studentId); + return true; + }catch (RuntimeException e){ + e.printStackTrace(); + return false; + } } @Transactional @Override public boolean updateStudent(StudentVo studentVo) { - boolean update = studentDao.updateStudent(studentVo); - return update; + try { + Integer update = studentDao.updateStudent(studentVo); + return true; + }catch (RuntimeException e){ + e.printStackTrace(); + return false; + } } - @Transactional @Override - public boolean initialPassword(Integer userId) { + public void updateWorkNumber(Integer studentId) { + studentDao.updateWorkNumber("00");//将学号重置为00 + } + + @Override + public R addStudentInfo(UserInfoEntity userInfoEntity) { + R r = new R(); + boolean result = studentDao.addStudentInfo(userInfoEntity); + if (result==false){ + r.put("code",300); + r.put("errmessage","注册失败!"); + return r; + }else{ + r.put("code",200); + r.put("errmessage","注册成功!"); + return r; + } + } - boolean initial = studentDao.initialPassword(userId,INITIAL_PASSWORD); - return initial; + @Override + public void downloadFiles(HttpServletResponse response) throws IOException { + XlsxTemplateEntity xlsxTemplate = xlsxTemplateService.getById(ConstantUtils.XLSX_TEMPLATE_ID); + ossService.downloadFiles(response, xlsxTemplate.getFileName()); } @Transactional @Override - public boolean disableAccount(Integer studentId) { - boolean disable = studentDao.disableAccount(studentId); - return disable; + public HashMap upload(MultipartFile file, Integer schoolId) throws IOException{ + List students = ExcelImportHelper.readStudent(file); + + // 参数合法性校验,只能上传.xlsx后缀的文件 + if (StringUtils.isBlank(file.getOriginalFilename()) + || !file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")).equals(Constant.EXCEL_SUFFIX)) { + ExceptionCast.cast(CommonCode.EXCEL_FILE_INVALID); + } + + HashMap map = new HashMap<>(); + try { + for (int i = 0;i result1 = studentDao.queryStudentIdNumber(workNumber,schoolId); + String email = student.getEmail(); + if (phone!=null&&phone!=""){ + List result2 = userInfoDao.queryStudentPhone(phone, schoolId); + if (result2.size()==1){ + log.error("该号码已被使用"); + map.put("被占用电话号码序列:"+System.currentTimeMillis(),"电话号码:"+phone); + students.remove(i); + i--; + continue; + } + studentVo.setPhone(phone); + } + if (email!=null&&email!=""){ + studentVo.setEmail(email); + } + List result3 = studentDao.querySchoolName(schoolAppellationName); + // 唯一标示性账号 + studentVo.setUniqueIdentificationAccount(String.valueOf(System.currentTimeMillis())). + setPassword(ConstantUtils.INITIAL_PASSWORD) + .setSchoolId(ConstantUtils.Keda_schoolId).setRoleId(ConstantUtils.STUDENT_ROLE) + ; + studentVo.setAccount(student.getAccount()).setSchoolAppellationName(schoolAppellationName).setUserName(student.getUserName()).setIsdel(Constant.IsDel.NOT_DEL.getType()); + + if (result1.size()==1){ + log.error("该学号已存在"); + map.put("学号已存在序列:"+System.currentTimeMillis(),"学号:"+workNumber); + students.remove(i); + i--; + continue; + }else if(result3.size()!=1){ + log.error("不存在该院校"); + map.put("错误的学校名称序列:"+System.currentTimeMillis(),"学校名称:"+schoolAppellationName); + students.remove(i); + i--; + continue; + } + if (!students.isEmpty()&&students.size()>0){ + userInfoDao.batchSaveUserInfo(studentVo); + student.setUserId(studentVo.getUserId()).setIsdel(Constant.IsDel.NOT_DEL.getType()).setPlatformId(ConstantUtils.PLATFORMID); + boolean b = studentDao.saveStudent(student); + if (!b){ + throw new RuntimeException(); + } + } + } + }catch (RuntimeException e){ + log.error(e.getMessage()); + throw new RuntimeException(); + } + + return map; + } + + @Override + public void exportFailureRecord(HttpServletResponse response,String token) { + + } +// public HashMap readStudent(Integer schoolId, MultipartFile file) { +// HashMap resp = new HashMap(); +// try { +// // 读取excel文件中的学生信息 +// List students = ExcelImportHelper.readStudent(file); +// List users = new ArrayList(); +// // 循环员工信息,将员工信息与用户信息进行对比 +// for (int i = 0; i < students.size(); i++) { +// Student student = students.get(i); +// // 学校id +// student.setSchoolId(schoolId); +// +// Student stu=studentMapper.getStudent(student); +// +// if(stu!=null) { +// // 专业id +// student.setProfessionalId(stu.getProfessionalId()); +// // 年级 +// student.setGradeId(stu.getGradeId()); +// //班级 +// student.setClassId(stu.getClassId()); +// +// UserM user = new UserM(); +// // 用户名称 +// user.setName(student.getStudentName()); +// // 用户密码 +// user.setPassword("huoran123"); +// // 用户角色 +// user.setAccountRole(student.getRoleId()); +// // 工号 +// user.setWorkNumber(student.getWorkNumber()); +// // 手机号 +// user.setPhone(student.getPhone()); +// // 邮箱 +// user.setEmail(student.getEmail()); +// // 唯一标识性账号 +// user.setUniqueIdentificationAccount(student.getUniqueIdentificationAccount()); +// // 学校id +// user.setSchoolId(schoolId); +// +// users.add(user); +// +// }else { +// students.remove(i); +// i--; +// } +// } +// if (!students.isEmpty() && students.size() > 0) { +// // 批量添加学生 +// studentMapper.bacthAddStudent(students); +// // 批量添加用户 +// userMapper.addUserM(users); +// } +// resp.put("retcode", 200); +// } catch (RuntimeException e) { +// logger.error(e.getMessage()); +// resp.put("retcode", 500); +// resp.put("retvalue", "Inquiry Failed"); +// return resp; +// } +// return resp; +// } } 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 cbb7310..a10b937 100644 --- a/src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java @@ -3,21 +3,21 @@ 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; +import com.msdw.tms.common.utils.*; import com.msdw.tms.dao.UserInfoDao; +import com.msdw.tms.entity.StudentEntity; import com.msdw.tms.entity.UserInfoEntity; import com.msdw.tms.entity.response.CommonCode; import com.msdw.tms.entity.response.ResponseResult; import com.msdw.tms.entity.response.ResultCode; +import com.msdw.tms.entity.vo.StudentVo; 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.List; import java.util.Map; @Service("userInfoService") @@ -25,6 +25,7 @@ public class UserInfoServiceImpl extends ServiceImpl params) { @@ -35,21 +36,30 @@ public class UserInfoServiceImpl extends ServiceImpl result = userInfoDao.queryStudentAccount(account,schoolId); + if (result.size()==1){ + return 1; + }else{ + return 0; + } + } + + @Override + public Integer queryStudentPhone(String phone,Integer schoolId) { + List result = userInfoDao.queryStudentPhone(phone,schoolId); + if (result.size()==1){ + return 1; + }else{ + return 0; + } + } + } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index bcfc268..5537c11 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -17,7 +17,7 @@ spring: # port: 6379 # password: huoran redis: - host: 47.102.214.131 + host: 192.168.31.125 port: 6379 password: mybatis-plus: diff --git a/src/main/resources/excel-template/学生导入模板.xlsx b/src/main/resources/excel-template/学生导入模板.xlsx new file mode 100644 index 0000000..a7be4bc Binary files /dev/null and b/src/main/resources/excel-template/学生导入模板.xlsx differ diff --git a/src/main/resources/mapper/tms/QuestionsDao.xml b/src/main/resources/mapper/tms/QuestionsDao.xml index 6e26302..ffdfec9 100644 --- a/src/main/resources/mapper/tms/QuestionsDao.xml +++ b/src/main/resources/mapper/tms/QuestionsDao.xml @@ -53,6 +53,12 @@ + + \ No newline at end of file diff --git a/src/main/resources/mapper/tms/StudentDao.xml b/src/main/resources/mapper/tms/StudentDao.xml index 3b05e44..5b67ea0 100644 --- a/src/main/resources/mapper/tms/StudentDao.xml +++ b/src/main/resources/mapper/tms/StudentDao.xml @@ -2,92 +2,111 @@ - + + + - INSERT INTO tms_student ( schoolId, userId, studentIdNumber, professionalId, gradeId, classId, roleId, isdel ) + INSERT INTO student ( schoolId, userId, workNumber, roleId, isdel,platformId ) VALUES - ( #{schoolId},#{userId},#{studentIdNumber},#{professionalId},#{gradeId},#{classId},#{roleId},#{isdel} + ( #{schoolId},#{userId},#{workNumber},#{roleId},#{isdel},#{platformId} + ) + + + INSERT INTO student(schoolId,userId,roleId,isdel,platformId) + VALUES + ( #{schoolId},#{userId},4,0,1 ) + + INSERT INTO student( schoolId, userId, workNumber, roleId, isdel,platformId ) + VALUES + + ( #{studentVo.schoolId},#{studentVo.userId},#{studentVo.workNumber},4,0,1) + + - UPDATE tms_student - SET isdel = 1 + UPDATE student s,hr_user_info u + SET s.isdel = 1,u.isdel = 1 WHERE studentId IN ( #{studentId} ) + AND + s.userId = u.userId - UPDATE - tms_student s,hr_user_info u - - s.schoolId = #{schoolId}, - s.studentIdNumber = #{studentIdNumber}, - s.professionalId = #{professionalId}, - s.gradeId = #{gradeId}, - s.classId = #{classId}, - u.userName = #{userName}, - u.schoolId = #{schoolId}, - u.account = #{account}, - u.phone = #{phone}, - u.phone = NULL, - u.email = #{email} - u.email = NULL - - WHERE + UPDATE + student s,hr_user_info u + + s.schoolId = #{schoolId}, + s.workNumber = #{workNumber}, + s.professionalId = #{professionalId}, + s.professionalName = #{professionalName}, + s.gradeId = #{gradeId}, + s.gradeName = #{gradeName}, + s.classId = #{classId}, + s.className = #{className}, + u.userName = #{userName}, + u.schoolId = #{schoolId}, + u.account = #{account}, + u.phone = #{phone}, + u.phone = NULL, + u.email = #{email} + u.email = NULL + u.schoolAppellationId = #{schoolAppellationId}> + + WHERE u.userId = s.userId - AND - u.userId = #{userId} - AND + AND s.studentId = #{studentId} - - UPDATE - hr_user_info - SET - password = #{password} - WHERE - userId = #{userId} + + update student set workNumber = #{workNumber} - - UPDATE - tms_student - SET - disableAccount = 1 - WHERE - studentId = #{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 60ccddf..79c66ca 100644 --- a/src/main/resources/mapper/tms/UserInfoDao.xml +++ b/src/main/resources/mapper/tms/UserInfoDao.xml @@ -3,13 +3,13 @@ - + insert into hr_user_info( userName, uniqueIdentificationAccount, provinceId, - cityId, schoolId, phone,account,password,roleId) + cityId, schoolId, phone,account,password,roleId,schoolAppellationId) values( #{userName}, #{uniqueIdentificationAccount}, #{provinceId}, - #{cityId}, #{schoolId},#{phone}, #{account},#{password},#{roleId}) + #{cityId}, #{schoolId},#{phone}, #{account},#{password},#{roleId},#{schoolAppellationId}) @@ -59,10 +59,69 @@ + + - INSERT INTO hr_user_info ( userName,email,phone,uniqueIdentificationAccount, schoolId, account, roleId,isdel) + INSERT INTO hr_user_info ( userName,email,phone,uniqueIdentificationAccount, schoolId, account,password, roleId,isdel,schoolAppellationId) VALUES - ( #{userName},#{email},#{phone},#{uniqueIdentificationAccount}, #{schoolId}, #{account}, 4 ,#{isdel}) + ( #{userName},#{email},#{phone},#{uniqueIdentificationAccount}, #{schoolId}, #{account}, #{password}, 4 ,0,#{schoolAppellationId}) + + + insert into hr_user_info( + userName, uniqueIdentificationAccount, schoolId, phone,account,password,roleId, schoolAppellationId) + values + + (#{studentVo.userName}, #{studentVo.uniqueIdentificationAccount},#{studentVo.schoolId}, + #{studentVo.phone}, #{studentVo.account},#{studentVo.password},#{studentVo.roleId}, + (SELECT schoolId FROM school WHERE schoolName = #{studentVo.schoolAppellationName})) + + + insert into hr_user_info( + userName, uniqueIdentificationAccount, schoolId, phone,account,password,roleId, schoolAppellationId) + values + (#{userName}, #{uniqueIdentificationAccount},#{schoolId}, + #{phone}, #{account},#{password},#{roleId}, + (SELECT schoolId FROM school WHERE schoolName = #{schoolAppellationName})) + + + + UPDATE + hr_user_info + SET + password = #{password} + WHERE + userId = #{userId} + + + + UPDATE + student stu, + hr_user_info u + SET + u.disableAccount = #{disableAccount} + WHERE + stu.studentId = #{studentId} + AND + stu.userId = u.userId + \ No newline at end of file diff --git a/src/test/java/com/msdw/tms/JedisTest.java b/src/test/java/com/msdw/tms/JedisTest.java new file mode 100644 index 0000000..8339c90 --- /dev/null +++ b/src/test/java/com/msdw/tms/JedisTest.java @@ -0,0 +1,25 @@ +package com.msdw.tms; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import redis.clients.jedis.Jedis; + +@SpringBootTest +public class JedisTest { + @Test + public void test() { + Jedis jedis = null; + try { + jedis = new Jedis("127.0.0.1", 6379); + //120.78.198.231 + System.out.println(jedis.ping()); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (jedis != null) { + jedis.close(); + } + } + } + +} diff --git a/src/test/java/com/msdw/tms/service/QuestionsServiceTest.java b/src/test/java/com/msdw/tms/service/QuestionsServiceTest.java index e8aa298..58631db 100644 --- a/src/test/java/com/msdw/tms/service/QuestionsServiceTest.java +++ b/src/test/java/com/msdw/tms/service/QuestionsServiceTest.java @@ -67,12 +67,12 @@ class QuestionsServiceTest { System.out.println(questionsService.updateQuestionById(questions)); } - @Test - @Transactional - void isnable() { - Integer id = 1; - System.out.println(questionsService.isEnable(id)); - } +// @Test +// @Transactional +// void isnable() { +// Integer id = 1; +// System.out.println(questionsService.isEnable(id)); +// } @Test @Transactional diff --git a/src/test/java/com/msdw/tms/service/StudentTest.java b/src/test/java/com/msdw/tms/service/StudentTest.java index 3fbe752..60d248d 100644 --- a/src/test/java/com/msdw/tms/service/StudentTest.java +++ b/src/test/java/com/msdw/tms/service/StudentTest.java @@ -30,10 +30,9 @@ public class StudentTest { Integer a = 1; UserInfoEntity userInfoEntity = new UserInfoEntity(); userInfoEntity.setAccount("123456").setUserName("michonne").setSchoolId(a); - studentVo.setSchoolId(a).setStudentIdNumber("888888").setRoleId(4).setProfessionalId(1).setGradeId(1).setClassId(1); - studentVo.setUserInfo(userInfoEntity); + studentVo.setSchoolId(a).setWorkNumber("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 ? "添加成功" : "添加失败"); }