From 717323019d0084132708433ddd745f83e2fb36f0 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Thu, 12 Sep 2024 10:01:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=9B=B8=E9=99=A4=E6=97=B6=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E5=B0=8F=E6=95=B0=E4=B8=AA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/service/impl/ClassEntityServiceImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 536df265..d890088e 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 @@ -1120,7 +1120,7 @@ public class ClassEntityServiceImpl extends ServiceImpl Date: Sat, 14 Sep 2024 16:14:48 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 8 + .../common/controller/ClassController.java | 132 +++++ .../controller/UserCertificateController.java | 117 +++++ .../common/controller/UserController.java | 9 + .../common/dao/UserCertificateDao.java | 9 + .../modules/common/entity/ClassExamUser.java | 6 +- .../modules/common/entity/CourseEntity.java | 4 + .../modules/common/entity/MyUserEntity.java | 4 + .../common/entity/UserCertificate.java | 38 ++ .../common/service/ClassEntityService.java | 2 + .../common/service/ClassExamUserService.java | 7 + .../service/UserCertificateService.java | 11 + .../service/impl/ClassEntityServiceImpl.java | 35 +- .../service/impl/ClassExamServiceImpl.java | 65 ++- .../impl/ClassExamUserServiceImpl.java | 13 + .../impl/UserCertificateServiceImpl.java | 453 ++++++++++++++++++ 16 files changed, 886 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/peanut/modules/common/controller/UserCertificateController.java create mode 100644 src/main/java/com/peanut/modules/common/dao/UserCertificateDao.java create mode 100644 src/main/java/com/peanut/modules/common/entity/UserCertificate.java create mode 100644 src/main/java/com/peanut/modules/common/service/ClassExamUserService.java create mode 100644 src/main/java/com/peanut/modules/common/service/UserCertificateService.java create mode 100644 src/main/java/com/peanut/modules/common/service/impl/ClassExamUserServiceImpl.java create mode 100644 src/main/java/com/peanut/modules/common/service/impl/UserCertificateServiceImpl.java diff --git a/pom.xml b/pom.xml index f37603ca..064243a8 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,14 @@ + + + com.github.promeg + tinypinyin + 2.0.3 + + + org.springframework.boot spring-boot-starter-test 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 be9f3ea2..cfd27589 100644 --- a/src/main/java/com/peanut/modules/common/controller/ClassController.java +++ b/src/main/java/com/peanut/modules/common/controller/ClassController.java @@ -1,16 +1,30 @@ package com.peanut.modules.common.controller; +import cn.hutool.core.date.DateUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.promeg.pinyinhelper.Pinyin; +import com.peanut.common.utils.DateUtils; import com.peanut.common.utils.R; +import com.peanut.common.utils.ShiroUtils; +import com.peanut.modules.common.dao.ClassExamUserDao; import com.peanut.modules.common.entity.*; import com.peanut.modules.common.service.ClassEntityService; +import com.peanut.modules.common.service.ClassExamUserService; +import com.peanut.modules.common.service.MyUserService; +import com.peanut.modules.common.service.UserCertificateService; +import com.peanut.modules.medical.service.CourseService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.imageio.ImageIO; +import java.net.URL; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -22,6 +36,14 @@ public class ClassController { @Autowired private ClassEntityService classEntityService; + @Autowired + private UserCertificateService userCertificateService; + @Autowired + private CourseService courseService; + @Autowired + private ClassExamUserService classExamUserService; + @Autowired + private StringRedisTemplate redisTemplate; //班级模型列表 @RequestMapping("/getClassModelList") @@ -355,4 +377,114 @@ public class ClassController { return R.ok().put("result",classEntityService.userScoreList(params)); } + //获取小班证书 + @RequestMapping("/getUserCertificateByClassId") + public R getUserCertificateByClassId(@RequestBody Map params) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + if (StringUtils.isNotBlank(params.get("classId").toString())){ + wrapper.eq(UserCertificate::getClassId,params.get("classId")); + } + wrapper.eq(UserCertificate::getUserId,params.get("userId")); + List userCertificate = userCertificateService.list(wrapper); + return R.ok().put("userCertificate",userCertificate); + } + + //生成证书 + @RequestMapping("/generateCertificateClass") + public R generateCertificateClass(@RequestBody Map params) { + try { + //证书类型A a证 B b证 ZK自考 + String type = params.get("type").toString(); + MyUserEntity user = ShiroUtils.getUser(); + String photoUrl = user.getPhoto();//证书人照片 + String realName = user.getName();//真是姓名 + UserCertificate userCertificate = new UserCertificate(); + userCertificate.setType(type); + userCertificate.setUserId(ShiroUtils.getUId()); + if ("ZK".equals(type)){ + CourseEntity courseEntity = courseService.getById(params.get("relationId").toString()); + userCertificate.setTitle(courseEntity.getTitle()); + String certificateNo = getNextCertificateNo(type,courseEntity.getTitleAbbr());//证书编号 + 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+"日自考通过太湖学堂"+courseEntity.getTitle()+"课程考试,确认合格。"; + String edes = "has past the online-examination study of "+courseEntity.getEtitle()+" Courses in Tai Hu Education online."; + String url = userCertificateService.generateCertificate(type,certificateNo,photoUrl,realName, description, edes, endYear,endMonth,endDay); + 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")); + String certificateNo = getNextCertificateNo(type,map.get("titleAbbr").toString()); + userCertificate.setCertificateNo(certificateNo); + double keshiTotal = (double)map.get("keshi"); + String keshi = (keshiTotal+"").replace(".0",""); + String description = "自"+startYear+"年"+startMonth+"月"+startDay+"日至"+endYear+"年"+endMonth+"月"+endDay+"日" + + "在太湖学堂"+classEntity.getTitle()+"学习,修完"+map.get("courseTitle")+"课程,共计"+keshi+"学时,确认合格。"; + String edes = "Has satisfactorily completed an online courseTCM on "+map.get("courseETitle")+" with "+keshi+" course hours intotal, and has been recongnized eligibility without assessment."; + String url = userCertificateService.generateCertificate(type,certificateNo,photoUrl,realName, description, edes, endYear,endMonth,endDay); + userCertificate.setTitle(classEntity.getTitle()); + userCertificate.setCertificateUrl(url); + userCertificate.setClassId(classEntity.getId()); + userCertificateService.save(userCertificate); + } + } + return R.ok(); + }finally { + //解锁 + redisTemplate.delete("lock"); + } + + } + + //获取下一个编号 + public String getNextCertificateNo(String type,String courseNamePinyin){ + //抢锁 + Boolean lock = redisTemplate.opsForValue().setIfAbsent("lock", "123"); + if(lock) { + List userCertificateList = userCertificateService.list(new LambdaQueryWrapper() + .orderByDesc(UserCertificate::getCreateTime)); + String res = ""; + if (userCertificateList.size() > 0){ + UserCertificate u0 = userCertificateList.get(0); + String certificateNo = u0.getCertificateNo(); + int no = Integer.parseInt(certificateNo.substring(certificateNo.indexOf("1")+1,certificateNo.indexOf("1")+7))+1; + if ("A".equals(type)){ + res = "NO.A1"+String.format("%06d", no); + }else if ("B".equals(type)){ + res = "NO.B1"+String.format("%06d", no); + }else if ("ZK".equals(type)){ + res = "NO.ZK1"+String.format("%06d", no); + } + }else { + if ("A".equals(type)){ + res = "NO.A1000001"; + }else if ("B".equals(type)){ + res = "NO.B1000001"; + }else if ("ZK".equals(type)){ + res = "NO.ZK1000001"; + } + } + return res+courseNamePinyin; + }else { + return ""; + } + } + + + } diff --git a/src/main/java/com/peanut/modules/common/controller/UserCertificateController.java b/src/main/java/com/peanut/modules/common/controller/UserCertificateController.java new file mode 100644 index 00000000..d9346e28 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/controller/UserCertificateController.java @@ -0,0 +1,117 @@ +package com.peanut.modules.common.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.yulichang.wrapper.MPJLambdaWrapper; +import com.peanut.common.utils.R; +import com.peanut.common.utils.ShiroUtils; +import com.peanut.modules.common.entity.MyUserEntity; +import com.peanut.modules.common.entity.UserCertificate; +import com.peanut.modules.common.service.UserCertificateService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import javax.imageio.ImageIO; +import java.net.URL; +import java.util.List; +import java.util.Map; + +/** + * 用户证书 + */ +@Slf4j +@RestController("commonUserCertificate") +@RequestMapping("common/userCertificate") +public class UserCertificateController { + + @Autowired + private UserCertificateService userCertificateService; + + //获取证书列表 + @RequestMapping("/getUserCertificateList") + public R getUserCertificateList() { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); + wrapper.eq(UserCertificate::getUserId, ShiroUtils.getUId()); + return R.ok().put("certificateList",userCertificateService.list(wrapper)); + } + + //生成证书(管理员) + @RequestMapping("/generateCertificateAdmin") + public R generateCertificateAdmin(@RequestBody Map params) { + if (StringUtils.isBlank(params.get("type").toString())||StringUtils.isBlank(params.get("certificateNo").toString())|| + StringUtils.isBlank(params.get("iconUrl").toString())||StringUtils.isBlank(params.get("realName").toString())|| + StringUtils.isBlank(params.get("description").toString())||StringUtils.isBlank(params.get("edes").toString())|| + StringUtils.isBlank(params.get("endYear").toString())|| StringUtils.isBlank(params.get("endMonth").toString())|| + StringUtils.isBlank(params.get("endDay").toString())){ + return R.error("数据不能为空"); + } + try { + ImageIO.read(new URL(params.get("iconUrl").toString())); + }catch (Exception e) { + return R.error("照片链接错误"); + } + String type = params.get("type").toString(); + String certificateNo = params.get("certificateNo").toString(); + String iconUrl = params.get("iconUrl").toString(); + String realName = params.get("realName").toString(); + String description = params.get("description").toString(); + String edes = params.get("edes").toString(); + String endYear = params.get("endYear").toString(); + String endMonth = params.get("endMonth").toString(); + String endDay = params.get("endDay").toString(); + String url = userCertificateService.generateCertificate(type,certificateNo,iconUrl,realName, description, edes, endYear,endMonth,endDay); + return R.ok().put("url",url); + } + + //证书列表 + @RequestMapping("/getCertificateList") + public R getCertificateList(@RequestBody Map params) { + MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); + wrapper.leftJoin(MyUserEntity.class,MyUserEntity::getId,UserCertificate::getUserId); + wrapper.selectAll(UserCertificate.class); + wrapper.select(MyUserEntity::getName,MyUserEntity::getNickname,MyUserEntity::getTel,MyUserEntity::getEmail); + if (StringUtils.isNotBlank(params.get("userWords").toString())){ + wrapper.and(t->t.like(MyUserEntity::getName,params.get("userWords")).or().like(MyUserEntity::getNickname,params.get("userWords")) + .or().like(MyUserEntity::getEmail,params.get("userWords")).or().like(MyUserEntity::getTel,params.get("userWords"))); + } + if (StringUtils.isNotBlank(params.get("title").toString())){ + wrapper.like(UserCertificate::getTitle,params.get("title")); + } + if (StringUtils.isNotBlank(params.get("certificateNo").toString())){ + wrapper.like(UserCertificate::getCertificateNo,params.get("certificateNo")); + } + Page page = userCertificateService.page(new Page<>( + Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),wrapper); + return R.ok().put("certificate",page); + } + + @RequestMapping("/getCertificateById") + public R getCertificateById(@RequestBody Map params) { + UserCertificate userCertificate = userCertificateService.getById(params.get("id").toString()); + return R.ok().put("userCertificate",userCertificate); + } + + @RequestMapping("/addCertificate") + public R addCertificate(@RequestBody UserCertificate userCertificate) { + userCertificateService.save(userCertificate); + return R.ok(); + } + + @RequestMapping("/updateCertificate") + public R updateCertificate(@RequestBody UserCertificate userCertificate) { + userCertificateService.updateById(userCertificate); + return R.ok(); + } + + @RequestMapping("/delCertificate") + public R delCertificate(@RequestBody Map params) { + userCertificateService.removeById(params.get("id").toString()); + return R.ok(); + } + + + +} diff --git a/src/main/java/com/peanut/modules/common/controller/UserController.java b/src/main/java/com/peanut/modules/common/controller/UserController.java index 1c2e6938..922968da 100644 --- a/src/main/java/com/peanut/modules/common/controller/UserController.java +++ b/src/main/java/com/peanut/modules/common/controller/UserController.java @@ -184,6 +184,15 @@ public class UserController { } } + /** + * 修改用户 + */ + @RequestMapping("/updateUser") + public R updateUser(@RequestBody MyUserEntity userEntity){ + userService.updateById(userEntity); + return R.ok(); + } + /** * 验证码注册或登录 */ diff --git a/src/main/java/com/peanut/modules/common/dao/UserCertificateDao.java b/src/main/java/com/peanut/modules/common/dao/UserCertificateDao.java new file mode 100644 index 00000000..27b9234d --- /dev/null +++ b/src/main/java/com/peanut/modules/common/dao/UserCertificateDao.java @@ -0,0 +1,9 @@ +package com.peanut.modules.common.dao; + +import com.github.yulichang.base.MPJBaseMapper; +import com.peanut.modules.common.entity.UserCertificate; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface UserCertificateDao extends MPJBaseMapper { +} 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 1c27f9f5..879b8b59 100644 --- a/src/main/java/com/peanut/modules/common/entity/ClassExamUser.java +++ b/src/main/java/com/peanut/modules/common/entity/ClassExamUser.java @@ -14,9 +14,11 @@ public class ClassExamUser { @TableId private Integer id; - private Integer classId; + private String type; - private Integer userId; + private Integer relationId;//考试类型 1小班 2自考 + + private Integer userId;//班级id或课程id private Integer score;//分数 diff --git a/src/main/java/com/peanut/modules/common/entity/CourseEntity.java b/src/main/java/com/peanut/modules/common/entity/CourseEntity.java index 14f42bc7..99cb314e 100644 --- a/src/main/java/com/peanut/modules/common/entity/CourseEntity.java +++ b/src/main/java/com/peanut/modules/common/entity/CourseEntity.java @@ -21,6 +21,10 @@ public class CourseEntity { private String title; + private String etitle; + + private String titleAbbr; + private Integer sort; private String image; diff --git a/src/main/java/com/peanut/modules/common/entity/MyUserEntity.java b/src/main/java/com/peanut/modules/common/entity/MyUserEntity.java index 7c02da6c..4789bf12 100644 --- a/src/main/java/com/peanut/modules/common/entity/MyUserEntity.java +++ b/src/main/java/com/peanut/modules/common/entity/MyUserEntity.java @@ -28,6 +28,10 @@ public class MyUserEntity implements Serializable { * 姓名 */ private String name; + /** + * 证件照 + */ + private String photo; /** * 年龄 */ diff --git a/src/main/java/com/peanut/modules/common/entity/UserCertificate.java b/src/main/java/com/peanut/modules/common/entity/UserCertificate.java new file mode 100644 index 00000000..c202eab2 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/entity/UserCertificate.java @@ -0,0 +1,38 @@ +package com.peanut.modules.common.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import java.util.Date; + +@Data +@TableName("user_certificate") +public class UserCertificate { + + @TableId + private Integer id; + + private String title; + + //证书类型A a证 B b证 ZK自考 + private String type; + + private String certificateNo; + + private String certificateUrl; + + private Integer userId; + + //课程id + private Integer courseId; + + //如果从小班拿的证,有小班id + private Integer classId; + + private Date createTime; + + @TableLogic + private Integer delFlag; + +} 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 44f41baf..5a974e27 100644 --- a/src/main/java/com/peanut/modules/common/service/ClassEntityService.java +++ b/src/main/java/com/peanut/modules/common/service/ClassEntityService.java @@ -91,4 +91,6 @@ public interface ClassEntityService extends IService { List userScoreList(Map params); + List> classCourseInfoClassId(int classId); + } diff --git a/src/main/java/com/peanut/modules/common/service/ClassExamUserService.java b/src/main/java/com/peanut/modules/common/service/ClassExamUserService.java new file mode 100644 index 00000000..dc338fe4 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/service/ClassExamUserService.java @@ -0,0 +1,7 @@ +package com.peanut.modules.common.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.peanut.modules.common.entity.ClassExamUser; + +public interface ClassExamUserService extends IService { +} diff --git a/src/main/java/com/peanut/modules/common/service/UserCertificateService.java b/src/main/java/com/peanut/modules/common/service/UserCertificateService.java new file mode 100644 index 00000000..2819dfff --- /dev/null +++ b/src/main/java/com/peanut/modules/common/service/UserCertificateService.java @@ -0,0 +1,11 @@ +package com.peanut.modules.common.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.peanut.modules.common.entity.UserCertificate; + +public interface UserCertificateService extends IService { + + + String generateCertificate(String type,String no,String iconUrl,String name,String des,String edes,String endy,String endm,String endd); + +} 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 d890088e..c4cb631e 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 @@ -318,7 +318,7 @@ public class ClassEntityServiceImpl extends ServiceImpl() - .eq(ClassExamUser::getClassId,classEntity.getId()) + .eq(ClassExamUser::getRelationId,classEntity.getId()) .eq(ClassExamUser::getScoreSuccess,0)); if (classExamUsers>0){ return R.error("有学员正在考试,请稍后再试"); @@ -634,7 +634,7 @@ public class ClassEntityServiceImpl extends ServiceImpl classes = this.baseMapper.selectList(wrapper); if (classes.size() > 0){ for (ClassEntity classEntity:classes){ @@ -1097,7 +1097,7 @@ public class ClassEntityServiceImpl extends ServiceImpl> classExamUsers = classExamUserDao.selectMaps(new MPJLambdaWrapper() .eq(ClassExamUser::getUserId,params.get("userId").toString()) - .eq(ClassExamUser::getClassId,classEntity.getId()) + .eq(ClassExamUser::getRelationId,classEntity.getId()) .eq(ClassExamUser::getScoreSuccess,1) .selectAs(ClassExamUser::getId,"id") .selectAs(ClassExamUser::getScore,"score") @@ -1214,6 +1214,35 @@ public class ClassEntityServiceImpl extends ServiceImpl> classCourseInfoClassId(int classId) { + List> res = new ArrayList<>(); + ClassEntity classEntity = this.baseMapper.selectById(classId); + MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); + wrapper.selectAll(CourseEntity.class); + wrapper.leftJoin(ClassCourse.class,ClassCourse::getCourseId,CourseEntity::getId); + wrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassCourse::getModelId); + wrapper.eq(ClassModel::getId,classEntity.getModelId()); + List courseEntityList = courseDao.selectList(wrapper); + for (CourseEntity course:courseEntityList){ + Map candk = new HashMap<>(); + MPJLambdaWrapper w = new MPJLambdaWrapper<>(); + w.leftJoin(CourseCatalogueChapterVideoEntity.class,CourseCatalogueChapterVideoEntity::getChapterId,CourseCatalogueChapterEntity::getId); + w.eq(CourseCatalogueChapterEntity::getCourseId,course.getId()); + w.selectSum(CourseCatalogueChapterVideoEntity::getDuration); + Map map = courseCatalogueChapterDao.selectJoinMap(w); + double duration = Double.parseDouble(map.get("duration").toString()); + double minute = duration/60; + double keshi = Math.ceil(minute/45); + candk.put("courseId",course.getId()); + candk.put("courseTitle",course.getTitle()); + candk.put("courseETitle",course.getEtitle()); + candk.put("titleAbbr",course.getTitleAbbr()); + candk.put("keshi",keshi); + res.add(candk); + } + return res; + } private MessagePostProcessor messagePostProcessor(long date) { 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 87d60f9d..bd5a8890 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 @@ -147,22 +147,32 @@ public class ClassExamServiceImpl extends ServiceImpl i if (list.size() > 0){ return R.error("存在正在考试,请结束再试"); } - ClassEntity classEntity = classEntityDao.selectById(params.get("classId").toString()); - ClassModel classModel = classModelDao.selectById(classEntity.getModelId()); - int examTime = classModel.getExamTime(); - MPJLambdaWrapper courseWrapper = new MPJLambdaWrapper<>(); - courseWrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassCourse::getModelId); - courseWrapper.leftJoin(ClassEntity.class,ClassEntity::getModelId,ClassModel::getId); - courseWrapper.eq(ClassEntity::getId,classEntity.getId()); - courseWrapper.selectAll(ClassCourse.class); - List courseList = classCourseDao.selectList(courseWrapper); + List courseList = new ArrayList<>(); + int examTime = 45;//考试持续时间 + int stotal = 60;//单选题总数 + int mtotal = 40;//多选题总数 + if ("1".equals(params.get("type").toString())){ + ClassEntity classEntity = classEntityDao.selectById(params.get("relationId").toString()); + ClassModel classModel = classModelDao.selectById(classEntity.getModelId()); + examTime = classModel.getExamTime();//考试持续时间 + MPJLambdaWrapper courseWrapper = new MPJLambdaWrapper<>(); + courseWrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassCourse::getModelId); + courseWrapper.leftJoin(ClassEntity.class,ClassEntity::getModelId,ClassModel::getId); + courseWrapper.eq(ClassEntity::getId,classEntity.getId()); + courseWrapper.selectAll(ClassCourse.class); + courseList = classCourseDao.selectList(courseWrapper); + stotal = Integer.parseInt(classModel.getExamProportion().split(":")[0]);//单选题总数 + mtotal = Integer.parseInt(classModel.getExamProportion().split(":")[1]);//多选题总数 + }else { + ClassCourse classCourse = new ClassCourse(); + classCourse.setCourseId((Integer) params.get("relationId")); + courseList.add(classCourse); + } List> resultList = new ArrayList<>(); List answerList = new ArrayList<>(); List> sList = new ArrayList<>(); List> mList = new ArrayList<>(); if (courseList.size() > 0) { - int stotal = Integer.parseInt(classModel.getExamProportion().split(":")[0]);//单选题总数 - int mtotal = Integer.parseInt(classModel.getExamProportion().split(":")[1]);//多选题总数 int snum = (int)Math.floor(stotal/courseList.size()); int mnum = (int)Math.floor(mtotal/courseList.size()); for (ClassCourse classCourse:courseList){ @@ -219,7 +229,8 @@ public class ClassExamServiceImpl extends ServiceImpl i } } ClassExamUser classExamUser = new ClassExamUser(); - classExamUser.setClassId(classEntity.getId()); + classExamUser.setType(params.get("type").toString()); + classExamUser.setRelationId(Integer.parseInt(params.get("relationId").toString())); classExamUser.setSubject(JSONUtil.toJsonStr(resultList)); classExamUser.setAnswer(JSONUtil.toJsonStr(answerList)); classExamUser.setUserId(ShiroUtils.getUId()); @@ -234,7 +245,7 @@ public class ClassExamServiceImpl extends ServiceImpl i messagePostProcessor(examTime*60*1000+3000)//3秒延迟 ); return R.ok().put("examPaper",resultList).put("id",classExamUser.getId()) - .put("startTime",classExamUser.getStartTime()).put("planEndTime",DateUtils.addDateMinutes(startTime,examTime)); + .put("startTime",classExamUser.getStartTime()).put("planEndTime",DateUtils.addDateMinutes(startTime,examTime).getTime()); } @@ -243,10 +254,15 @@ public class ClassExamServiceImpl extends ServiceImpl i ClassExamUser classExamUser = classExamUserDao.selectOne(new LambdaQueryWrapper() .eq(ClassExamUser::getUserId,ShiroUtils.getUId()).eq(ClassExamUser::getScoreSuccess,0)); if (classExamUser!=null){ - ClassEntity classEntity = classEntityDao.selectById(classExamUser.getClassId()); - ClassModel classModel = classModelDao.selectById(classEntity.getModelId()); - return R.ok().put("classExamUser",classExamUser) - .put("planEndTime",DateUtils.addDateMinutes(classExamUser.getStartTime(),classModel.getExamTime())); + if ("1".equals(classExamUser.getType())){ + ClassEntity classEntity = classEntityDao.selectById(classExamUser.getRelationId()); + ClassModel classModel = classModelDao.selectById(classEntity.getModelId()); + return R.ok().put("classExamUser",classExamUser) + .put("planEndTime",DateUtils.addDateMinutes(classExamUser.getStartTime(),classModel.getExamTime()).getTime()); + }else { + return R.ok().put("classExamUser",classExamUser) + .put("planEndTime",DateUtils.addDateMinutes(classExamUser.getStartTime(),45).getTime()); + } }else { return R.ok().put("classExamUser",null).put("planEndTime",null); } @@ -313,7 +329,7 @@ public class ClassExamServiceImpl extends ServiceImpl i @Override public Object getExamPaperList(Map params) { List classExamUserList = classExamUserDao.selectList(new LambdaQueryWrapper() - .eq(ClassExamUser::getClassId,params.get("classId")) + .eq(ClassExamUser::getRelationId,params.get("classId")) .eq(ClassExamUser::getUserId,params.get("userId")) .orderByDesc(ClassExamUser::getScore)); return classExamUserList; @@ -322,10 +338,15 @@ public class ClassExamServiceImpl extends ServiceImpl i @Override public R getExamPaperInfo(Map params) { ClassExamUser classExamUser = classExamUserDao.selectById(params.get("id").toString()); - ClassEntity classEntity = classEntityDao.selectById(classExamUser.getClassId()); - ClassModel classModel = classModelDao.selectById(classEntity.getModelId()); - return R.ok().put("examPaper",classExamUser) - .put("planEndTime",DateUtils.addDateMinutes(classExamUser.getStartTime(),classModel.getExamTime())); + if ("1".equals(classExamUser.getType())){ + ClassEntity classEntity = classEntityDao.selectById(classExamUser.getRelationId()); + ClassModel classModel = classModelDao.selectById(classEntity.getModelId()); + return R.ok().put("examPaper",classExamUser) + .put("planEndTime",DateUtils.addDateMinutes(classExamUser.getStartTime(),classModel.getExamTime()).getTime()); + }else { + return R.ok().put("examPaper",classExamUser) + .put("planEndTime",DateUtils.addDateMinutes(classExamUser.getStartTime(),45).getTime()); + } } private MessagePostProcessor messagePostProcessor(long date) { diff --git a/src/main/java/com/peanut/modules/common/service/impl/ClassExamUserServiceImpl.java b/src/main/java/com/peanut/modules/common/service/impl/ClassExamUserServiceImpl.java new file mode 100644 index 00000000..a18aa917 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/service/impl/ClassExamUserServiceImpl.java @@ -0,0 +1,13 @@ +package com.peanut.modules.common.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.peanut.modules.common.dao.ClassExamUserDao; +import com.peanut.modules.common.entity.ClassExamUser; +import com.peanut.modules.common.service.ClassExamUserService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@Service("commonClassExamUserService") +public class ClassExamUserServiceImpl extends ServiceImpl implements ClassExamUserService { +} diff --git a/src/main/java/com/peanut/modules/common/service/impl/UserCertificateServiceImpl.java b/src/main/java/com/peanut/modules/common/service/impl/UserCertificateServiceImpl.java new file mode 100644 index 00000000..68e0a665 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/service/impl/UserCertificateServiceImpl.java @@ -0,0 +1,453 @@ +package com.peanut.modules.common.service.impl; + +import com.aliyun.oss.OSS; +import com.aliyun.oss.OSSClientBuilder; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.github.promeg.pinyinhelper.Pinyin; +import com.peanut.common.utils.ConstantPropertiesUtils; +import com.peanut.modules.common.dao.UserCertificateDao; +import com.peanut.modules.common.entity.UserCertificate; +import com.peanut.modules.common.service.UserCertificateService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.springframework.stereotype.Service; +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.UUID; + +@Slf4j +@Service("commonUserCertificateService") +public class UserCertificateServiceImpl extends ServiceImpl implements UserCertificateService { + + + public static void main(String[] args) { + + System.out.println(" "); + } + + + @Override + public String generateCertificate(String type,String certificateNo,String iconUrl,String realName,String des,String edes, + String endYear,String endMonth,String endDay) { + String url = ""; + if ("A".equals(type)){ + url = generateACertificate(certificateNo, iconUrl, realName, des, endYear, endMonth, endDay); + }else if ("B".equals(type)) { + url = generateBCertificate(certificateNo, iconUrl, realName, des, endYear, endMonth, endDay); + }else if ("ZK".equals(type)){ + url = generateZKCertificate(certificateNo, iconUrl, realName, des, endYear, endMonth, endDay); + } + String eurl = generateECertificate(certificateNo,realName, edes); + return url+","+eurl; + } + + + + + public String generateZKCertificate(String no,String iconUrl,String name,String des,String endy,String endm,String endd) { + try { + Image src = ImageIO.read(new URL("https://ehh-private-01.oss-cn-beijing.aliyuncs.com/certificate/ZK.png")); + // 获取图片的高和宽 + int wideth = src.getWidth(null); + int height = src.getHeight(null); + // 新增一个图片缓冲 + BufferedImage image = new BufferedImage(wideth, height, BufferedImage.TYPE_INT_RGB); + Graphics2D g = image.createGraphics(); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.drawImage(src, 0, 0, wideth, height, null); + + // 设置字体颜色 + g.setColor(new Color(0,75,63)); + g.setFont(new Font("Arial", Font.BOLD, 30)); + FontMetrics metrics = g.getFontMetrics(); + int nox = (wideth - metrics.stringWidth(no))/2; + int noy = 415; + g.drawString(no, nox, noy); + + if (StringUtils.isNotBlank(iconUrl)){ + Image images = ImageIO.read(new URL(iconUrl)); + g.drawImage(images,(wideth-images.getWidth(null))/2,435,245,280,null); + } + + g.setColor(new Color(0,75,63)); + g.setFont(new Font("宋体", Font.BOLD, 40)); + FontMetrics metricss = g.getFontMetrics(); + int namex = (wideth - metricss.stringWidth(name))/2; + int namey = 765; + g.drawString(name, namex, namey); + + g.setColor(Color.BLACK); + g.setFont(new Font("黑体", Font.BOLD, 30)); + FontMetrics dess = g.getFontMetrics(); + int alreadyWriteLine = 0; //已经写了多少行 + int nowWidth = 0; //目前一行的长度 + boolean space = true; //第一行空两格 + for (int i = 0; i < des.length(); i++) { + int oneWordWidth = dess.charWidth(des.charAt(i)); //获取单个字符的长度 + if (nowWidth+oneWordWidth>650){ + alreadyWriteLine++; + int writeY = 850 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距 + g.drawString(des.charAt(i) + "", 180, writeY); + nowWidth = 0; + space = false; + nowWidth += oneWordWidth; + }else { + int writeY = 850 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距 + if (nowWidth==0&&space){//换行画 + g.drawString(des.charAt(i)+"", 180+oneWordWidth, writeY); + nowWidth += oneWordWidth*2; + }else {//一字一字画 + g.drawString(des.charAt(i)+"", 180+nowWidth, writeY); + nowWidth += oneWordWidth; + } + } + } + g.setColor(new Color(0,75,63)); + g.setFont(new Font("黑体", Font.BOLD, 28)); + g.drawString(endy,595,1123); + g.drawString(endm,703,1123); + g.drawString(endd,770,1123); + // 释放资源 + g.dispose(); + File tempFile = File.createTempFile("tempfile_"+UUID.randomUUID().toString(), ".jpg"); + ImageIO.write(image, "jpg", tempFile); + String res = uploadFile(tempFile); + tempFile.delete(); + return res; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public String generateBCertificate(String no,String iconUrl,String name,String des,String endy,String endm,String endd) { + try { + Image src = ImageIO.read(new URL("https://ehh-private-01.oss-cn-beijing.aliyuncs.com/certificate/B.png")); + // 获取图片的高和宽 + int wideth = src.getWidth(null); + int height = src.getHeight(null); + // 新增一个图片缓冲 + BufferedImage image = new BufferedImage(wideth, height, BufferedImage.TYPE_INT_RGB); + Graphics2D g = image.createGraphics(); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.drawImage(src, 0, 0, wideth, height, null); + + // 设置字体颜色 + g.setColor(new Color(160,113,0)); + g.setFont(new Font("Arial", Font.BOLD, 48)); + FontMetrics metrics = g.getFontMetrics(); + int nox = (wideth - metrics.stringWidth(no))/2; + int noy = 380; + g.drawString(no, nox, noy); + + if (StringUtils.isNotBlank(iconUrl)){ + Image images = ImageIO.read(new URL(iconUrl)); + g.drawImage(images,(wideth-images.getWidth(null))/2,400,245,280,null); + } + + g.setColor(Color.BLACK); + g.setFont(new Font("宋体", Font.BOLD, 40)); + FontMetrics metricss = g.getFontMetrics(); + int namex = (wideth - metricss.stringWidth(name))/2; + int namey = 730; + g.drawString(name, namex, namey); + + g.setFont(new Font("黑体", Font.BOLD, 30)); + FontMetrics dess = g.getFontMetrics(); + int alreadyWriteLine = 0; //已经写了多少行 + int nowWidth = 0; //目前一行的长度 + boolean space = true; //第一行空两格 + for (int i = 0; i < des.length(); i++) { + int oneWordWidth = dess.charWidth(des.charAt(i)); //获取单个字符的长度 + if (nowWidth+oneWordWidth>650){ + alreadyWriteLine++; + int writeY = 850 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距 + g.drawString(des.charAt(i) + "", 180, writeY); + nowWidth = 0; + space = false; + nowWidth += oneWordWidth; + }else { + int writeY = 850 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距 + if (nowWidth==0&&space){//换行画 + g.drawString(des.charAt(i)+"", 180+oneWordWidth, writeY); + nowWidth += oneWordWidth*2; + }else {//一字一字画 + g.drawString(des.charAt(i)+"", 180+nowWidth, writeY); + nowWidth += oneWordWidth; + } + } + } + g.setFont(new Font("黑体", Font.BOLD, 28)); + g.drawString(endy,600,1158); + g.drawString(endm,695,1158); + g.drawString(endd,748,1158); + // 释放资源 + g.dispose(); + File tempFile = File.createTempFile("tempfile_"+UUID.randomUUID().toString(), ".jpg"); + ImageIO.write(image, "jpg", tempFile); + String res = uploadFile(tempFile); + tempFile.delete(); + return res; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public String generateACertificate(String no,String iconUrl,String name,String des,String endy,String endm,String endd) { + try { + Image src = ImageIO.read(new URL("https://ehh-private-01.oss-cn-beijing.aliyuncs.com/certificate/A.png")); + // 获取图片的高和宽 + int wideth = src.getWidth(null); + int height = src.getHeight(null); + // 新增一个图片缓冲 + BufferedImage image = new BufferedImage(wideth, height, BufferedImage.TYPE_INT_RGB); + Graphics2D g = image.createGraphics(); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.drawImage(src, 0, 0, wideth, height, null); + + // 设置字体颜色 + g.setColor(new Color(160,113,0)); + g.setFont(new Font("Arial", Font.BOLD, 48)); + FontMetrics metrics = g.getFontMetrics(); + int nox = (wideth - metrics.stringWidth(no))/2; + int noy = 355; + g.drawString(no, nox, noy); + + if (StringUtils.isNotBlank(iconUrl)){ + Image images = ImageIO.read(new URL(iconUrl)); + g.drawImage(images,(wideth-images.getWidth(null))/2,480,245,280,null); + } + + g.setColor(Color.BLACK); + g.setFont(new Font("宋体", Font.BOLD, 50)); + FontMetrics metricss = g.getFontMetrics(); + int namex = (wideth - metricss.stringWidth(name))/2; + int namey = 815; + g.drawString(name, namex, namey); + + g.setFont(new Font("黑体", Font.BOLD, 30)); + FontMetrics dess = g.getFontMetrics(); + int alreadyWriteLine = 0; //已经写了多少行 + int nowWidth = 0; //目前一行的长度 + boolean space = true; //第一行空两格 + for (int i = 0; i < des.length(); i++) { + int oneWordWidth = dess.charWidth(des.charAt(i)); //获取单个字符的长度 + if (nowWidth+oneWordWidth>650){ + alreadyWriteLine++; + int writeY = 865 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距 + g.drawString(des.charAt(i) + "", 180, writeY); + nowWidth = 0; + space = false; + nowWidth += oneWordWidth; + }else { + int writeY = 865 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距 + if (nowWidth==0&&space){//换行画 + g.drawString(des.charAt(i)+"", 180+oneWordWidth, writeY); + nowWidth += oneWordWidth*2; + }else {//一字一字画 + g.drawString(des.charAt(i)+"", 180+nowWidth, writeY); + nowWidth += oneWordWidth; + } + } + } + + g.setFont(new Font("黑体", Font.BOLD, 28)); + g.drawString(endy,605,1185); + g.drawString(endm,715,1185); + g.drawString(endd,780,1185); + + // 释放资源 + g.dispose(); + File tempFile = File.createTempFile("tempfile_"+UUID.randomUUID().toString(), ".jpg"); + ImageIO.write(image, "jpg", tempFile); + String res = uploadFile(tempFile); + tempFile.delete(); + return res; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + public String generateECertificate(String no,String name,String des) { + try { + Image src = ImageIO.read(new URL("https://ehh-private-01.oss-cn-beijing.aliyuncs.com/certificate/E.png")); + String filename = "eee"; + // 获取图片的高和宽 + int wideth = src.getWidth(null); + int height = src.getHeight(null); + // 新增一个图片缓冲 + BufferedImage image = new BufferedImage(wideth, height, BufferedImage.TYPE_INT_RGB); + Graphics2D g = image.createGraphics(); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.drawImage(src, 0, 0, wideth, height, null); + + // 设置字体颜色 + g.setColor(new Color(160,113,0)); + g.setFont(new Font("Arial", Font.BOLD, 48)); + FontMetrics metrics = g.getFontMetrics(); + int nox = (wideth - metrics.stringWidth(no))/2; + int noy = 500; + g.drawString(no, nox, noy); + + g.setColor(Color.BLACK); + g.setFont(new Font("Arial", Font.PLAIN, 58)); + FontMetrics metricss = g.getFontMetrics(); + //转换成拼音 + name = nameToPinyin(name); + int namex = (wideth - metricss.stringWidth(name))/2; + int namey = 660; + g.drawString(name, namex, namey); + + g.setFont(new Font("Arial", Font.PLAIN, 30)); + FontMetrics dess = g.getFontMetrics(); + int alreadyWriteLine = 0; //已经写了多少行 + int nowWidth = 0; //目前一行的长度 + boolean space = true; //第一行空两格 + for (int i = 0; i < des.length(); i++) { + int oneWordWidth = dess.charWidth(des.charAt(i)); //获取单个字符的长度 + if (nowWidth+oneWordWidth>700){//换行画 + alreadyWriteLine++; + int writeY = 780 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距 + g.drawString(des.charAt(i) + "", 155, writeY); + nowWidth = 0; + space = false; + nowWidth += oneWordWidth; + }else {//一字一字画 + int writeY = 780 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距 + if (nowWidth==0&&space){//首行空一格 + g.drawString(des.charAt(i)+"", 155+oneWordWidth, writeY); + nowWidth += oneWordWidth*2; + }else { + g.drawString(des.charAt(i)+"", 155+nowWidth, writeY); + nowWidth += oneWordWidth; + } + } + } + // 释放资源 + g.dispose(); + File tempFile = File.createTempFile("tempfile_"+UUID.randomUUID().toString(), ".jpg"); + ImageIO.write(image, "jpg", tempFile); + String res = uploadFile(tempFile); + tempFile.delete(); + return res; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + public String nameToPinyin(String realName){ + String pinyin = Pinyin.toPinyin(realName, " ").toLowerCase(); + String[] sss = pinyin.split(" "); + String nick = ""; + String name = ""; + for (int i = 0; i < sss.length; i++) { + String ss = sss[i]; + ss = ss.replace(ss.charAt(0),Character.toUpperCase(ss.charAt(0))); + if (i==0){ + nick = ss; + }else { + name = name+" "+ss; + } + } + return name+" "+nick; + } + + + + public void generateTestCertificate(String no,String name,String time,String des,String trans,String trans2, + String trans3,String endy,String endm,String endd) { + try { + Image src = ImageIO.read(new File("F:\\certificate\\template\\a.png")); + String filename = "aaa"; + // 获取图片的高和宽 + int wideth = src.getWidth(null); + int height = src.getHeight(null); + // 新增一个图片缓冲 + BufferedImage image = new BufferedImage(wideth, height, BufferedImage.TYPE_INT_RGB); + Graphics2D g = image.createGraphics(); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.drawImage(src, 0, 0, wideth, height, null); + + // 设置字体颜色 + g.setColor(new Color(160,113,0)); + g.setFont(new Font("Arial", Font.BOLD, 48)); + FontMetrics metrics = g.getFontMetrics(); + int nox = (wideth - metrics.stringWidth(no))/2; +// int noy = 1037 - metrics.getHeight();//1305 + int noy = 355; + g.drawString(no, nox, noy); + + g.setColor(Color.BLACK); + g.setFont(new Font("宋体", Font.BOLD, 50)); + FontMetrics metricss = g.getFontMetrics(); + int namex = (wideth - metricss.stringWidth(name))/2; + int namey = 815; + g.drawString(name, namex, namey); + + g.setFont(new Font("宋体", Font.BOLD, 115)); + FontMetrics times = g.getFontMetrics(); + int timex = (wideth - times.stringWidth(time))/2; + int timey = 2370 - times.getHeight();//2270 + g.drawString(time, timex, timey); + + FontMetrics dess = g.getFontMetrics(); + int desx = (wideth - dess.stringWidth(des))/2; + int desy = 2635 - dess.getHeight();//2535 + g.drawString(des, desx, desy); + + g.setFont(new Font("Arial", Font.BOLD, 75)); + FontMetrics transs = g.getFontMetrics(); + int transx = (wideth - transs.stringWidth(trans))/2; + int transy = 2735 - transs.getHeight();//2685 + g.drawString(trans, transx, transy); + + FontMetrics trans2s = g.getFontMetrics(); + int trans2x = (wideth - trans2s.stringWidth(trans2))/2; + g.drawString(trans2, trans2x, transy+120); + + FontMetrics trans3s = g.getFontMetrics(); + int trans3x = (wideth - trans3s.stringWidth(trans3))/2; + g.drawString(trans3, trans3x, transy+240); + + g.setFont(new Font("宋体", Font.BOLD, 80)); + g.drawString(endy,1800,3440); + g.drawString(endm,2090,3440); + g.drawString(endd,2250,3440); + + // 释放资源 + g.dispose(); + File outputfile = new File("F:\\certificate\\template\\"+ filename +".jpg"); + ImageIO.write(image, "jpg", outputfile); + + System.out.println(no +","+ name +","+ filename); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static String uploadFile(File file){ + // 工具类获取值 + String endpoint = ConstantPropertiesUtils.END_POIND; + String accessKeyId = ConstantPropertiesUtils.ACCESS_KEY_ID; + String accessKeySecret = ConstantPropertiesUtils.ACCESS_KEY_SECRET; + String bucketName = ConstantPropertiesUtils.BUCKET_NAME; + try { + // 创建OSS实例。 + OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); + String fileName = UUID.randomUUID().toString()+".jpg"; + //把上传之后文件路径返回 需要把上传到阿里云oss路径手动拼接出来 + // https://edu-guli-1010.oss-cn-beijing.aliyuncs.com/01.jpg + String url = "https://"+bucketName+"."+endpoint+"/certificate/"+fileName; + //调用oss方法实现上传 + ossClient.putObject(bucketName,"certificate/"+fileName, file); + // 关闭OSSClient。 + ossClient.shutdown(); + return url; + }catch(Exception e) { + e.printStackTrace(); + return null; + } + } + +}