From c8a44c97d023ddaafdaf22310edc340ac59bbf9b Mon Sep 17 00:00:00 2001 From: pd <2776455882@qq.com> Date: Mon, 27 Jul 2020 21:03:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=80=83=E6=A0=B8=E3=80=81?= =?UTF-8?q?=E8=A1=A5=E8=80=83=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MakeuplistController.java | 10 +- .../liuwanr/helper/ExcelImportHelper.java | 93 ++++++++++++------- .../yipin/liuwanr/mapper/AssesmentMapper.java | 5 + .../liuwanr/mapper/MakeuplistMapper.java | 6 +- .../liuwanr/service/AssesmentService.java | 22 ++++- .../liuwanr/service/MakeuplistService.java | 36 ++++--- .../yipin/liuwanr/vo/MakeupStudentsVo.java | 11 +-- 7 files changed, 116 insertions(+), 67 deletions(-) diff --git a/src/main/java/com/yipin/liuwanr/controller/MakeuplistController.java b/src/main/java/com/yipin/liuwanr/controller/MakeuplistController.java index 41f6b7d..9cd039f 100644 --- a/src/main/java/com/yipin/liuwanr/controller/MakeuplistController.java +++ b/src/main/java/com/yipin/liuwanr/controller/MakeuplistController.java @@ -33,7 +33,6 @@ public class MakeuplistController { Response resp = new Response(); MultipartFile file=vo.getFile(); Integer staffId=vo.getStaffId(); - Integer uploadType=vo.getUploadType(); Integer schoolId=vo.getSchoolId(); long uploadTime=vo.getUploadTime(); @@ -43,14 +42,11 @@ public class MakeuplistController { }else if(StringUtils.isEmpty(uploadTime)){ resp.setStatus(300); resp.setMessage("文件上传时间为空"); - }else if(StringUtils.isEmpty(uploadType)){ - resp.setStatus(300); - resp.setMessage("文件上传选项为空"); }else if(StringUtils.isEmpty(schoolId)){ resp.setStatus(300); resp.setMessage("学校为空"); }else{ - HashMap ret = makeuplistService.addMakeuplist(file,schoolId,staffId,uploadType,uploadTime); + HashMap ret = makeuplistService.addMakeuplist(file,schoolId,staffId,uploadTime); int status = (int) ret.get("retcode"); if (200 == status) { resp.setStatus(status); @@ -69,7 +65,7 @@ public class MakeuplistController { * @return */ @GetMapping("/queryGetByClassName") - Response queryGetByClassName(@RequestParam Integer staffId,@RequestParam long uploadTime, + Response queryGetByClassName(@RequestParam Integer staffId,@RequestParam Long uploadTime, @RequestParam Integer uploadType,@RequestParam Integer schoolId) { Response resp = new Response(); if(StringUtils.isEmpty(staffId)) { @@ -123,7 +119,7 @@ public class MakeuplistController { } @GetMapping("/getStudent") - Response getStudent(@RequestParam Integer staffId,@RequestParam long uploadTime,@RequestParam Integer uploadType, + Response getStudent(@RequestParam Integer staffId,@RequestParam Long uploadTime,@RequestParam Integer uploadType, @RequestParam Integer schoolId){ Response resp = new Response(); if(StringUtils.isEmpty(staffId)) { diff --git a/src/main/java/com/yipin/liuwanr/helper/ExcelImportHelper.java b/src/main/java/com/yipin/liuwanr/helper/ExcelImportHelper.java index e732d78..c3bdea6 100644 --- a/src/main/java/com/yipin/liuwanr/helper/ExcelImportHelper.java +++ b/src/main/java/com/yipin/liuwanr/helper/ExcelImportHelper.java @@ -2,8 +2,10 @@ package com.yipin.liuwanr.helper; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import com.yipin.liuwanr.vo.MakeupStudentsVo; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; @@ -11,6 +13,7 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; import com.yipin.liuwanr.entity.Makeuplist; @@ -24,9 +27,11 @@ public class ExcelImportHelper { * @param file * @return */ - public static List readExcel(MultipartFile file,Integer uploadType) { + public static HashMap readExcel(MultipartFile file) { + HashMap resp=new HashMap(); List list = new ArrayList(); List names=new ArrayList(); + Integer uploadType=null; try { String fileName = file.getOriginalFilename(); Workbook workbook = null; @@ -37,50 +42,66 @@ public class ExcelImportHelper { } Makeuplist makeuplist = null; // 循环工作表Sheet - for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) { - Sheet hssfSheet = workbook.getSheetAt(numSheet); - if (hssfSheet == null) { - continue; - } - // 循环行Row - for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) { - Row row = hssfSheet.getRow(rowNum); - - if (row != null) { - makeuplist = new Makeuplist(); - row.getCell(0).setCellType(CellType.STRING); - Cell className = row.getCell(0); - row.getCell(1).setCellType(CellType.STRING); - Cell studentNumber = row.getCell(1); - row.getCell(2).setCellType(CellType.STRING); - Cell studentName = row.getCell(2); - if(uploadType.equals(0)){ - String name=className.getStringCellValue(); - names.add(name); + + Sheet hssfSheet = workbook.getSheetAt(0); + if (hssfSheet != null) { + Row row1 = hssfSheet.getRow(0); + if(row1!=null){ + row1.getCell(0).setCellType(CellType.STRING); + Cell readClassName = row1.getCell(0); + String readName=readClassName.getStringCellValue(); + if(!StringUtils.isEmpty(readName)){ + if(readName.equals("实验班级名称")){ + uploadType=0; + }else if(readName.equals("行政班级名称")){ + uploadType=1; + }else{ + throw new RuntimeException("数据模板被修改"); + } } - makeuplist.setClassName(className.getStringCellValue()); - makeuplist.setStudentNumber(studentNumber.getStringCellValue()); - makeuplist.setStudentName(studentName.getStringCellValue()); - list.add(makeuplist); - } - } - if(uploadType.equals(0)){ - if(!names.isEmpty()&&names.size()>0){ - for (int i=0;i0){ + for (int i=0;i releaseAssesment(Integer courseId); + + + //考核名称去重 + @Select("select count(*) from assessment where assesmentName=#{assesmentName}") + Integer getByAssesmentName(String assesmentName); } diff --git a/src/main/java/com/yipin/liuwanr/mapper/MakeuplistMapper.java b/src/main/java/com/yipin/liuwanr/mapper/MakeuplistMapper.java index 28814b8..7d39557 100644 --- a/src/main/java/com/yipin/liuwanr/mapper/MakeuplistMapper.java +++ b/src/main/java/com/yipin/liuwanr/mapper/MakeuplistMapper.java @@ -25,8 +25,8 @@ public interface MakeuplistMapper { "where m.studentId=s.studentId and s.classId=c.classId and c.gradeId=g.gradeId and s.professionalId=p.professionalId and m.experimentalClassId=ecn .experimentalClassId and m.staffId=#{staffId} and m.uploadTime=#{uploadTime} and m.schoolId=#{schoolId}") List queryExperimentalClassMakeuplist(@Param("staffId")Integer staffId, @Param("uploadTime")String uploadTime,@Param("schoolId") Integer schoolId); - @Select("select experimentalClassId,studentId,classId from makeuplist where staffId=#{staffId} and uploadTime=#{uploadTime} and schoolId=#{schoolId}") - List getstudent(@Param("staffId")Integer staffId, @Param("uploadTime")String uploadTime,@Param("schoolId") Integer schoolId); + @Select("select experimentalClassId,studentId,classId from makeuplist where staffId=#{staffId} and uploadTime=#{uploadTime} and schoolId=#{schoolId} and uploadType=#{uploadType}") + List getstudent(@Param("staffId")Integer staffId, @Param("uploadTime")String uploadTime,@Param("schoolId") Integer schoolId,@Param("uploadType")Integer uploadType); @Select("select classId,studentId from makeuplist where staffId=#{staffId} and uploadTime=#{uploadTime}") List getClass(@Param("staffId")Integer staffId, @Param("uploadTime")String uploadTime); @@ -38,7 +38,7 @@ public interface MakeuplistMapper { //实验班级信息 @Select("SELECT exn.experimentalClassId,studentNumber,s.studentId from student s left join experimental_class_student ecs on s.studentId=ecs.studentId left join experimental_class_ning exn on ecs.experimentalClassId=exn.experimentalClassId " + - " where exn.experimentalClassName='111' and exn.schoolId=1 and s.studentNumber='123'") + " where exn.experimentalClassName=#{experimentalClassName} and exn.schoolId=#{schoolId} and s.studentNumber=#{studentNumber}") Student queryExperimentalClassStudent(@Param("experimentalClassName") String experimentalClassName,@Param("schoolId")Integer schoolId,@Param("studentNumber")String studentNumber); //行政班级信息 diff --git a/src/main/java/com/yipin/liuwanr/service/AssesmentService.java b/src/main/java/com/yipin/liuwanr/service/AssesmentService.java index fee4af8..c793ec2 100644 --- a/src/main/java/com/yipin/liuwanr/service/AssesmentService.java +++ b/src/main/java/com/yipin/liuwanr/service/AssesmentService.java @@ -90,6 +90,14 @@ public class AssesmentService { mapper.insertAssesment(assesment); //得到考核id Integer assesmentId = assesment.getId(); + + String name=assesment.getAssesmentName(); + Integer number=mapper.getByAssesmentName(name); + if(number!=null&&number>0){ + name+=(number+1); + assesment.setAssesmentName(name); + } + //往记录表中添加选中的学生信息,哪名学生要参与某一课程的什么考核,该考核下的 哪一项目 mapper.insertRecore(studentIds, assesment.getExperimentId(), assesment.getCourseId(), assesmentId); @@ -135,14 +143,14 @@ public class AssesmentService { */ public HashMap queryGetById(Integer id) { HashMap resp = new HashMap(); - List obj = new ArrayList(); + HashMap obj=new HashMap<>(); try { //考核信息 Assesment assesment = mapper.queryGetById(id); //之前选中的学生 List students = mapper.queryStudent(id); - obj.add(assesment); - obj.add(students); + obj.put("assesment",assesment); + obj.put("students",students); resp.put("retvalue", obj); resp.put("retcode", 200); @@ -206,6 +214,14 @@ public class AssesmentService { //判分点数量 Integer pointNumber = mapper.queryPointNumber(assesment.getExperimentId()); assesment.setAssessmentNumber(pointNumber); + + String name=assesment.getAssesmentName(); + Integer number=mapper.getByAssesmentName(name); + if(number!=null&&number>0){ + name+=(number+1); + assesment.setAssesmentName(name); + } + mapper.updateAssesment(assesment); resp.put("retcode", 200); diff --git a/src/main/java/com/yipin/liuwanr/service/MakeuplistService.java b/src/main/java/com/yipin/liuwanr/service/MakeuplistService.java index 71db7ea..476712f 100644 --- a/src/main/java/com/yipin/liuwanr/service/MakeuplistService.java +++ b/src/main/java/com/yipin/liuwanr/service/MakeuplistService.java @@ -61,7 +61,7 @@ public class MakeuplistService { HashMap resp = new HashMap(); String time= AssesmentHelper.longPointDate(uploadTime); try{ - resp.put("retvalue",makeuplistMapper.getstudent(staffId,time,schoolId)); + resp.put("retvalue",makeuplistMapper.getstudent(staffId,time,schoolId,uploadType)); resp.put("retcode", 200); }catch (RuntimeException e){ logger.error(e.getMessage()); @@ -72,8 +72,6 @@ public class MakeuplistService { return resp; } - - public HashMap getByMakeuplist(Integer staffId,long uploadTime,Integer uploadType,Integer schoolId){ HashMap resp = new HashMap(); String time= AssesmentHelper.longPointDate(uploadTime); @@ -103,20 +101,34 @@ public class MakeuplistService { * @return */ @Transactional - public HashMap addMakeuplist( MultipartFile file,Integer schoolId,Integer staffId,Integer uploadType,long uploadTime) { + public HashMap addMakeuplist( MultipartFile file,Integer schoolId,Integer staffId,long uploadTime) { HashMap resp = new HashMap(); - MakeupStudentsVo vo; + MakeupStudentsVo vo=new MakeupStudentsVo(); String time= AssesmentHelper.longPointDate(uploadTime); try { //补考学生信息 - List makeuplists= ExcelImportHelper.readExcel(file,uploadType); - if(!makeuplists.isEmpty()&&makeuplists.size()>0){ - if(uploadType.equals(0)){ - addMakeuplist(makeuplists,schoolId,staffId,uploadType,time); - }else if(uploadType.equals(1)){ - addMakeuplist(makeuplists,schoolId,staffId,uploadType,time); + HashMap obj= ExcelImportHelper.readExcel(file); + if(obj!=null){ + Integer uploadType=(Integer) obj.get("uploadType"); + List makeuplists=(List)obj.get("makeuplists"); + if(!makeuplists.isEmpty()&&makeuplists.size()>0){ + if(uploadType!=null){ + if(uploadType.equals(0)){ + addMakeuplist(makeuplists,schoolId,staffId,uploadType,time); + }else if(uploadType.equals(1)){ + addMakeuplist(makeuplists,schoolId,staffId,uploadType,time); + } + resp.put("retcode", 200); + vo.setUploadType(uploadType); + resp.put("retvalue", vo); + }else{ + resp.put("retcode", 300); + resp.put("retvalue", "文件模板错误"); + } + }else{ + resp.put("retcode", 300); + resp.put("retvalue", "导入文件失败"); } - resp.put("retcode", 200); }else{ resp.put("retcode", 300); resp.put("retvalue", "导入文件失败"); diff --git a/src/main/java/com/yipin/liuwanr/vo/MakeupStudentsVo.java b/src/main/java/com/yipin/liuwanr/vo/MakeupStudentsVo.java index 3236518..ca8f078 100644 --- a/src/main/java/com/yipin/liuwanr/vo/MakeupStudentsVo.java +++ b/src/main/java/com/yipin/liuwanr/vo/MakeupStudentsVo.java @@ -4,6 +4,8 @@ import com.yipin.liuwanr.entity.Makeuplist; import com.yipin.liuwanr.entity.Student; import org.springframework.web.multipart.MultipartFile; +import java.util.List; + /** * 补考名单信息 */ @@ -12,15 +14,12 @@ public class MakeupStudentsVo extends Makeuplist { private MultipartFile file;//上传文件 private Integer staffId;//教师id private Integer schoolId;//学校id - private long uploadTime;//上传时间 + private Long uploadTime;//上传时间 private Integer uploadType;//上传方式 - private String time;//yyyy-MM-dd HH:mm - public MakeupStudentsVo() { } - public String getTime() { return time; } @@ -53,11 +52,11 @@ public class MakeupStudentsVo extends Makeuplist { this.staffId = staffId; } - public long getUploadTime() { + public Long getUploadTime() { return uploadTime; } - public void setUploadTime(long uploadTime) { + public void setUploadTime(Long uploadTime) { this.uploadTime = uploadTime; }