diff --git a/src/main/java/com/peanut/modules/common/controller/ClassController.java b/src/main/java/com/peanut/modules/common/controller/ClassController.java index 6d371066..c386a779 100644 --- a/src/main/java/com/peanut/modules/common/controller/ClassController.java +++ b/src/main/java/com/peanut/modules/common/controller/ClassController.java @@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.imageio.ImageIO; +import java.math.BigDecimal; import java.net.URL; import java.util.HashSet; import java.util.List; @@ -400,113 +401,107 @@ public class ClassController { return R.ok().put("userCertificate",userCertificate); } - //生成证书 - @RequestMapping("/generateCertificateClass") + //结班后发放证书 + @RequestMapping("/generateCertificateByClassEnd") @Transactional - public R generateCertificateClass(@RequestBody Map params) { - //抢锁 - Boolean lock = redisTemplate.opsForValue().setIfAbsent("lock", "123"); - if(lock) { - try { - //证书类型A a证 B b证 ZK自考 - String type = params.get("type").toString(); - MyUserEntity user = ShiroUtils.getUser(); - String photoUrl = user.getPhoto();//证书人照片 - String realName = user.getName();//真是姓名 + public R generateCertificateByClassEnd(@RequestBody Map params){ + ClassEntity classEntity = classEntityService.getById(params.get("classId").toString()); + //给合格学员发放证书 + List> userScoreList = classEntityService.userScoreList(params); + for (Map userScoreMap : userScoreList) { + if (new BigDecimal(userScoreMap.get("userScore").toString()).compareTo(new BigDecimal(60))>=0){ UserCertificate userCertificate = new UserCertificate(); + userCertificate.setTitle(classEntity.getTitle()); + String type = "B"; + if (new BigDecimal(userScoreMap.get("userScore").toString()).compareTo(new BigDecimal(70))>=0){ + type = "A"; + } userCertificate.setType(type); - userCertificate.setUserId(ShiroUtils.getUId()); - if ("ZK".equals(type)){ - CourseEntity courseEntity = courseService.getById(params.get("relationId").toString()); - String courseTitle = courseEntity.getTitle(); - if (courseTitle.contains("【")){ - courseTitle = courseEntity.getTitle().substring(0,courseEntity.getTitle().indexOf("【")); - } - userCertificate.setTitle(courseTitle); - ClassExamUser classExamUser = classExamUserService.getOne(new LambdaQueryWrapper() - .eq(ClassExamUser::getUserId,ShiroUtils.getUId()) - .eq(ClassExamUser::getRelationId,params.get("relationId").toString())); - String endYear = DateUtil.year(classExamUser.getEndTime())+""; - String endMonth = DateUtil.month(classExamUser.getEndTime())+1+""; - String endDay = DateUtil.dayOfMonth(classExamUser.getEndTime())+""; - String[] description= {endYear,endMonth,endDay,courseTitle}; - String[] edes = {courseEntity.getEtitle()}; - String certificateNo = getNextCertificateNo(type,courseEntity.getTitleAbbr());//证书编号 - String url = userCertificateService.generateCertificate(type,certificateNo,photoUrl,realName, description, edes, endYear,endMonth,endDay); + MyUserEntity user = (MyUserEntity)userScoreMap.get("user"); + userCertificate.setUserId(user.getId()); + userCertificate.setClassId(classEntity.getId()); + //查询小班下得课程信息 + List> classCourseInfoLlist = classEntityService.classCourseInfoClassId(classEntity.getId(),0); + for (Map classCourseInfo:classCourseInfoLlist){ + String certificateNo = classEntityService.getNextCertificateNo(type,classCourseInfo.get("titleAbbr").toString()); userCertificate.setCertificateNo(certificateNo); - userCertificate.setCertificateUrl(url); - userCertificate.setCourseId(courseEntity.getId()); - userCertificateService.save(userCertificate); - }else { - ClassEntity classEntity = classEntityService.getById(params.get("relationId").toString()); - String startYear = DateUtil.year(classEntity.getStartTime())+""; - String startMonth = DateUtil.month(classEntity.getStartTime())+1+""; - String startDay = DateUtil.dayOfMonth(classEntity.getStartTime())+""; - String endYear = DateUtil.year(classEntity.getEndTime())+""; - String endMonth = DateUtil.month(classEntity.getEndTime())+1+""; - String endDay = DateUtil.dayOfMonth(classEntity.getEndTime())+""; - List> list = classEntityService.classCourseInfoClassId(classEntity.getId()); - for (Map map:list){ - userCertificate.setCourseId((Integer) map.get("courseId")); - double keshiTotal = (double)map.get("keshi"); + userCertificate.setCourseId((Integer) classCourseInfo.get("courseId")); + if (StringUtils.isNotEmpty(user.getPhoto())&&StringUtils.isNotEmpty(user.getName())){ + String startYear = DateUtil.year(classEntity.getStartTime())+""; + String startMonth = DateUtil.month(classEntity.getStartTime())+1+""; + String startDay = DateUtil.dayOfMonth(classEntity.getStartTime())+""; + String endYear = DateUtil.year(classEntity.getEndTime())+""; + String endMonth = DateUtil.month(classEntity.getEndTime())+1+""; + String endDay = DateUtil.dayOfMonth(classEntity.getEndTime())+""; + double keshiTotal = (double)classCourseInfo.get("keshi"); String keshi = (keshiTotal+"").replace(".0",""); - String courseTitle = map.get("courseTitle").toString(); + String courseTitle = classCourseInfo.get("courseTitle").toString(); if (courseTitle.contains("【")){ courseTitle = courseTitle.substring(0,courseTitle.indexOf("【")); } String[] des = {startYear,startMonth,startDay,endYear,endMonth,endDay, classEntity.getTitle(),courseTitle,keshi}; - String[] edes = {map.get("courseETitle").toString(),keshi}; - String certificateNo = getNextCertificateNo(type,map.get("titleAbbr").toString()); - String url = userCertificateService.generateCertificate(type,certificateNo,photoUrl,realName,des, edes, endYear,endMonth,endDay); + String[] edes = {classCourseInfo.get("courseETitle").toString(),keshi}; + String url = userCertificateService.generateCertificate(type,certificateNo,user.getPhoto(),user.getName(), + des, edes, endYear,endMonth,endDay); userCertificate.setCertificateUrl(url); - userCertificate.setCertificateNo(certificateNo); - userCertificate.setTitle(classEntity.getTitle()); - userCertificate.setClassId(classEntity.getId()); - userCertificateService.save(userCertificate); } + userCertificateService.save(userCertificate); } - }finally { - //解锁 - redisTemplate.delete("lock"); } - }else { - generateCertificateClass(params); } return R.ok(); } - //获取下一个编号 - public String getNextCertificateNo(String type,String courseNamePinyin){ - List userCertificateList = userCertificateService.list(new LambdaQueryWrapper() - .orderByDesc(UserCertificate::getId)); - String res = ""; - if (userCertificateList.size() > 0){ - UserCertificate u0 = userCertificateList.get(0); - String certificateNo = u0.getCertificateNo(); - int no = 0; - if (certificateNo.contains("ZK")){ - no = Integer.parseInt(certificateNo.substring(5,11))+1; - }else { - no = Integer.parseInt(certificateNo.substring(3,9))+1; - } - if ("A".equals(type)){ - res = "NO."+String.format("%06d", no); - }else if ("B".equals(type)){ - res = "NO."+String.format("%06d", no); - }else if ("ZK".equals(type)){ - res = "NO.ZK"+String.format("%06d", no); - } + //生成证书图片 + @RequestMapping("/generateCertificateClass") + public R generateCertificateClass(@RequestBody Map params) { + MyUserEntity user = ShiroUtils.getUser(); + String photoUrl = user.getPhoto();//证书人照片 + String realName = user.getName();//真实姓名 + UserCertificate userCertificate = userCertificateService.getById(params.get("id").toString()); + String type = userCertificate.getType();//证书类型A a证 B b证 ZK自考 + if ("ZK".equals(type)){ + CourseEntity courseEntity = courseService.getById(userCertificate.getCourseId()); + String courseTitle = userCertificate.getTitle(); + ClassExamUser classExamUser = classExamUserService.getOne(new LambdaQueryWrapper() + .eq(ClassExamUser::getUserId,ShiroUtils.getUId()) + .eq(ClassExamUser::getRelationId,userCertificate.getCourseId())); + String endYear = DateUtil.year(classExamUser.getEndTime())+""; + String endMonth = DateUtil.month(classExamUser.getEndTime())+1+""; + String endDay = DateUtil.dayOfMonth(classExamUser.getEndTime())+""; + String[] description= {endYear,endMonth,endDay,courseTitle}; + String[] edes = {courseEntity.getEtitle()}; + String certificateNo = userCertificate.getCertificateNo();//证书编号 + String url = userCertificateService.generateCertificate(type,certificateNo,photoUrl,realName, description, edes, endYear,endMonth,endDay); + userCertificate.setCertificateUrl(url); + userCertificateService.updateById(userCertificate); }else { - if ("A".equals(type)){ - res = "NO.000001"; - }else if ("B".equals(type)){ - res = "NO.000001"; - }else if ("ZK".equals(type)){ - res = "NO.ZK000001"; + ClassEntity classEntity = classEntityService.getById(userCertificate.getClassId()); + String startYear = DateUtil.year(classEntity.getStartTime())+""; + String startMonth = DateUtil.month(classEntity.getStartTime())+1+""; + String startDay = DateUtil.dayOfMonth(classEntity.getStartTime())+""; + String endYear = DateUtil.year(classEntity.getEndTime())+""; + String endMonth = DateUtil.month(classEntity.getEndTime())+1+""; + String endDay = DateUtil.dayOfMonth(classEntity.getEndTime())+""; + List> list = classEntityService.classCourseInfoClassId(classEntity.getId(),userCertificate.getCourseId()); + for (Map map:list){ + double keshiTotal = (double)map.get("keshi"); + String keshi = (keshiTotal+"").replace(".0",""); + String courseTitle = map.get("courseTitle").toString(); + if (courseTitle.contains("【")){ + courseTitle = courseTitle.substring(0,courseTitle.indexOf("【")); + } + String[] des = {startYear,startMonth,startDay,endYear,endMonth,endDay, + classEntity.getTitle(),courseTitle,keshi}; + String[] edes = {map.get("courseETitle").toString(),keshi}; + String certificateNo = userCertificate.getCertificateNo(); + String url = userCertificateService.generateCertificate(type,certificateNo,photoUrl,realName,des, edes, endYear,endMonth,endDay); + userCertificate.setCertificateUrl(url); + userCertificateService.updateById(userCertificate); } } - return res+courseNamePinyin; + return R.ok(); } diff --git a/src/main/java/com/peanut/modules/common/controller/ClassExamController.java b/src/main/java/com/peanut/modules/common/controller/ClassExamController.java index c24eab4f..7928efd6 100644 --- a/src/main/java/com/peanut/modules/common/controller/ClassExamController.java +++ b/src/main/java/com/peanut/modules/common/controller/ClassExamController.java @@ -1,16 +1,14 @@ package com.peanut.modules.common.controller; +import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.peanut.common.excel.ExcelUtil; import com.peanut.common.utils.DateUtils; import com.peanut.common.utils.R; -import com.peanut.modules.common.entity.ClassExamOption; -import com.peanut.modules.common.entity.ClassExamSubject; -import com.peanut.modules.common.entity.ClassExamUser; -import com.peanut.modules.common.entity.ClassModel; -import com.peanut.modules.common.service.ClassExamOptionService; -import com.peanut.modules.common.service.ClassExamService; -import com.peanut.modules.common.service.ClassExamSubjectService; +import com.peanut.common.utils.ShiroUtils; +import com.peanut.modules.common.entity.*; +import com.peanut.modules.common.service.*; +import com.peanut.modules.master.service.CourseService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -35,6 +33,12 @@ public class ClassExamController { private ClassExamSubjectService classExamSubjectService; @Autowired private ClassExamOptionService classExamOptionService; + @Autowired + private CourseService courseService; + @Autowired + private ClassEntityService classEntityService; + @Autowired + private UserCertificateService userCertificateService; //导入考试题 @RequestMapping("/importSubject") @@ -191,8 +195,34 @@ public class ClassExamController { //提交试卷 @RequestMapping("/submitExamPaper") public R submitExamPaper(@RequestBody Map params){ - Object examPaper = classExamService.submitExamPaper(params); - return R.ok().put("examPaper",examPaper); + ClassExamUser classExamUser = classExamService.submitExamPaper(params); + //自考的人成绩达标,发放证书 + if ("2".equals(classExamUser.getType())&&classExamUser.getScore()>=80){ + UserCertificate userCertificate = new UserCertificate(); + userCertificate.setType("ZK"); + userCertificate.setUserId(ShiroUtils.getUId()); + CourseEntity courseEntity = courseService.getById(classExamUser.getRelationId()); + String courseTitle = courseEntity.getTitle(); + if (courseTitle.contains("【")){ + courseTitle = courseEntity.getTitle().substring(0,courseEntity.getTitle().indexOf("【")); + } + userCertificate.setTitle(courseTitle); + String certificateNo = classEntityService.getNextCertificateNo("ZK",courseEntity.getTitleAbbr());//证书编号 + userCertificate.setCertificateNo(certificateNo); + if (StringUtils.isNotEmpty(ShiroUtils.getUser().getPhoto())&&StringUtils.isNotEmpty(ShiroUtils.getUser().getName())){ + String endYear = DateUtil.year(classExamUser.getEndTime())+""; + String endMonth = DateUtil.month(classExamUser.getEndTime())+1+""; + String endDay = DateUtil.dayOfMonth(classExamUser.getEndTime())+""; + String[] description= {endYear,endMonth,endDay,courseTitle}; + String[] edes = {courseEntity.getEtitle()}; + String url = userCertificateService.generateCertificate("ZK",certificateNo,ShiroUtils.getUser().getPhoto(), + ShiroUtils.getUser().getName(), description, edes, endYear,endMonth,endDay); + userCertificate.setCertificateUrl(url); + } + userCertificate.setCourseId(courseEntity.getId()); + userCertificateService.save(userCertificate); + } + return R.ok().put("examPaper",classExamUser); } //试卷列表 diff --git a/src/main/java/com/peanut/modules/common/entity/ClassExamUser.java b/src/main/java/com/peanut/modules/common/entity/ClassExamUser.java index 879b8b59..7252d017 100644 --- a/src/main/java/com/peanut/modules/common/entity/ClassExamUser.java +++ b/src/main/java/com/peanut/modules/common/entity/ClassExamUser.java @@ -14,11 +14,11 @@ public class ClassExamUser { @TableId private Integer id; - private String type; + private String type;//考试类型 1小班 2自考 - private Integer relationId;//考试类型 1小班 2自考 + private Integer relationId;//班级id或课程id - private Integer userId;//班级id或课程id + private Integer userId; private Integer score;//分数 diff --git a/src/main/java/com/peanut/modules/common/service/ClassEntityService.java b/src/main/java/com/peanut/modules/common/service/ClassEntityService.java index a70b7688..83c272ed 100644 --- a/src/main/java/com/peanut/modules/common/service/ClassEntityService.java +++ b/src/main/java/com/peanut/modules/common/service/ClassEntityService.java @@ -27,6 +27,8 @@ public interface ClassEntityService extends IService { R updateClassState(Map params); + String getNextCertificateNo(String type,String courseNamePinyin); + boolean editClass(Map params); R setUserRole(Map params); @@ -95,6 +97,6 @@ public interface ClassEntityService extends IService { List userScoreList(Map params); - List> classCourseInfoClassId(int classId); + List> classCourseInfoClassId(int classId,int courseId); } diff --git a/src/main/java/com/peanut/modules/common/service/ClassExamService.java b/src/main/java/com/peanut/modules/common/service/ClassExamService.java index 5d420934..add4242b 100644 --- a/src/main/java/com/peanut/modules/common/service/ClassExamService.java +++ b/src/main/java/com/peanut/modules/common/service/ClassExamService.java @@ -36,7 +36,7 @@ public interface ClassExamService extends IService { void submitOption(Map params); - Object submitExamPaper(Map params); + ClassExamUser submitExamPaper(Map params); Object getExamPaperList(Map params); diff --git a/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java b/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java index 26d93f8a..ee581335 100644 --- a/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java +++ b/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java @@ -18,6 +18,7 @@ import org.apache.commons.lang.StringUtils; import org.springframework.amqp.core.MessagePostProcessor; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; @@ -54,6 +55,8 @@ public class ClassEntityServiceImpl extends ServiceImpl params) { @@ -334,6 +337,51 @@ public class ClassEntityServiceImpl extends ServiceImpl userCertificateList = userCertificateDao.selectList(new LambdaQueryWrapper() + .orderByDesc(UserCertificate::getId)); + String res = ""; + if (userCertificateList.size() > 0){ + UserCertificate u0 = userCertificateList.get(0); + String certificateNo = u0.getCertificateNo(); + int no = 0; + if (certificateNo.contains("ZK")){ + no = Integer.parseInt(certificateNo.substring(5,11))+1; + }else { + no = Integer.parseInt(certificateNo.substring(3,9))+1; + } + if ("A".equals(type)){ + res = "NO."+String.format("%06d", no); + }else if ("B".equals(type)){ + res = "NO."+String.format("%06d", no); + }else if ("ZK".equals(type)){ + res = "NO.ZK"+String.format("%06d", no); + } + }else { + if ("A".equals(type)){ + res = "NO.000001"; + }else if ("B".equals(type)){ + res = "NO.000001"; + }else if ("ZK".equals(type)){ + res = "NO.ZK000001"; + } + } + return res+courseNamePinyin; + }finally { + //解锁 + redisTemplate.delete("certificateNoLock"); + } + }else { + return getNextCertificateNo(type,courseNamePinyin); + } + } + @Override public boolean editClass(Map params) { ClassEntity c = new ClassEntity(); @@ -1302,7 +1350,7 @@ public class ClassEntityServiceImpl extends ServiceImpl> classCourseInfoClassId(int classId) { + public List> classCourseInfoClassId(int classId,int courseId) { List> res = new ArrayList<>(); ClassEntity classEntity = this.baseMapper.selectById(classId); MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); @@ -1310,6 +1358,9 @@ public class ClassEntityServiceImpl extends ServiceImpl courseEntityList = courseDao.selectList(wrapper); for (CourseEntity course:courseEntityList){ Map candk = new HashMap<>(); diff --git a/src/main/java/com/peanut/modules/common/service/impl/ClassExamServiceImpl.java b/src/main/java/com/peanut/modules/common/service/impl/ClassExamServiceImpl.java index bd5a8890..f934f4f4 100644 --- a/src/main/java/com/peanut/modules/common/service/impl/ClassExamServiceImpl.java +++ b/src/main/java/com/peanut/modules/common/service/impl/ClassExamServiceImpl.java @@ -278,7 +278,7 @@ public class ClassExamServiceImpl extends ServiceImpl i } @Override - public Object submitExamPaper(Map params) { + public ClassExamUser submitExamPaper(Map params) { ClassExamUser classExamUser = classExamUserDao.selectById(params.get("id").toString()); List subjectList = JSONUtil.parseArray(classExamUser.getSubject()); List answerList = JSONUtil.parseArray(classExamUser.getAnswer());