修改错误日志权限

This commit is contained in:
wuchunlei
2024-09-14 16:14:48 +08:00
parent 717323019d
commit a895687731
16 changed files with 886 additions and 27 deletions

View File

@@ -56,6 +56,14 @@
</properties>
<dependencies>
<!--汉字转拼音-->
<dependency>
<groupId>com.github.promeg</groupId>
<artifactId>tinypinyin</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@@ -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<String,Object> params) {
LambdaQueryWrapper<UserCertificate> 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> userCertificate = userCertificateService.list(wrapper);
return R.ok().put("userCertificate",userCertificate);
}
//生成证书
@RequestMapping("/generateCertificateClass")
public R generateCertificateClass(@RequestBody Map<String,Object> 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<ClassExamUser>()
.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<Map<String,Object>> list = classEntityService.classCourseInfoClassId(classEntity.getId());
for (Map<String,Object> 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<UserCertificate> userCertificateList = userCertificateService.list(new LambdaQueryWrapper<UserCertificate>()
.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 "";
}
}
}

View File

@@ -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<UserCertificate> wrapper = new LambdaQueryWrapper();
wrapper.eq(UserCertificate::getUserId, ShiroUtils.getUId());
return R.ok().put("certificateList",userCertificateService.list(wrapper));
}
//生成证书(管理员)
@RequestMapping("/generateCertificateAdmin")
public R generateCertificateAdmin(@RequestBody Map<String,Object> 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<String,Object> params) {
MPJLambdaWrapper<UserCertificate> 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<UserCertificate> 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<String,Object> 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<String,Object> params) {
userCertificateService.removeById(params.get("id").toString());
return R.ok();
}
}

View File

@@ -184,6 +184,15 @@ public class UserController {
}
}
/**
* 修改用户
*/
@RequestMapping("/updateUser")
public R updateUser(@RequestBody MyUserEntity userEntity){
userService.updateById(userEntity);
return R.ok();
}
/**
* 验证码注册或登录
*/

View File

@@ -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<UserCertificate> {
}

View File

@@ -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;//分数

View File

@@ -21,6 +21,10 @@ public class CourseEntity {
private String title;
private String etitle;
private String titleAbbr;
private Integer sort;
private String image;

View File

@@ -28,6 +28,10 @@ public class MyUserEntity implements Serializable {
* 姓名
*/
private String name;
/**
* 证件照
*/
private String photo;
/**
* 年龄
*/

View File

@@ -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;
}

View File

@@ -91,4 +91,6 @@ public interface ClassEntityService extends IService<ClassEntity> {
List userScoreList(Map<String,Object> params);
List<Map<String,Object>> classCourseInfoClassId(int classId);
}

View File

@@ -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<ClassExamUser> {
}

View File

@@ -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<UserCertificate> {
String generateCertificate(String type,String no,String iconUrl,String name,String des,String edes,String endy,String endm,String endd);
}

View File

@@ -318,7 +318,7 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
}else {
//结班限制
int classExamUsers = classExamUserDao.selectCount(new LambdaQueryWrapper<ClassExamUser>()
.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<ClassEntityDao, ClassEnt
wrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassEntity::getModelId);
wrapper.leftJoin(ClassCourse.class,ClassCourse::getModelId,ClassModel::getId);
wrapper.eq(ClassCourse::getCourseId,params.get("courseId"));
wrapper.ne(ClassEntity::getState,"2");
wrapper.eq(ClassEntity::getState,"0");
List<ClassEntity> classes = this.baseMapper.selectList(wrapper);
if (classes.size() > 0){
for (ClassEntity classEntity:classes){
@@ -1097,7 +1097,7 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
if (classModel.getIsExam()==1){
List<Map<String,Object>> classExamUsers = classExamUserDao.selectMaps(new MPJLambdaWrapper<ClassExamUser>()
.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<ClassEntityDao, ClassEnt
return resultList;
}
@Override
public List<Map<String,Object>> classCourseInfoClassId(int classId) {
List<Map<String,Object>> res = new ArrayList<>();
ClassEntity classEntity = this.baseMapper.selectById(classId);
MPJLambdaWrapper<CourseEntity> 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<CourseEntity> courseEntityList = courseDao.selectList(wrapper);
for (CourseEntity course:courseEntityList){
Map<String,Object> candk = new HashMap<>();
MPJLambdaWrapper<CourseCatalogueChapterEntity> w = new MPJLambdaWrapper<>();
w.leftJoin(CourseCatalogueChapterVideoEntity.class,CourseCatalogueChapterVideoEntity::getChapterId,CourseCatalogueChapterEntity::getId);
w.eq(CourseCatalogueChapterEntity::getCourseId,course.getId());
w.selectSum(CourseCatalogueChapterVideoEntity::getDuration);
Map<String,Object> 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) {

View File

@@ -147,22 +147,32 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> 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<ClassCourse> 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<ClassCourse> courseList = classCourseDao.selectList(courseWrapper);
List<ClassCourse> 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<ClassCourse> 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<Map<String,Object>> resultList = new ArrayList<>();
List<String> answerList = new ArrayList<>();
List<Map<String,Object>> sList = new ArrayList<>();
List<Map<String,Object>> 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<ClassExamDao, ClassExam> 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<ClassExamDao, ClassExam> 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<ClassExamDao, ClassExam> i
ClassExamUser classExamUser = classExamUserDao.selectOne(new LambdaQueryWrapper<ClassExamUser>()
.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<ClassExamDao, ClassExam> i
@Override
public Object getExamPaperList(Map<String, Object> params) {
List<ClassExamUser> classExamUserList = classExamUserDao.selectList(new LambdaQueryWrapper<ClassExamUser>()
.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<ClassExamDao, ClassExam> i
@Override
public R getExamPaperInfo(Map<String, Object> 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) {

View File

@@ -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<ClassExamUserDao, ClassExamUser> implements ClassExamUserService {
}

View File

@@ -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<UserCertificateDao, UserCertificate> 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;
}
}
}