修改错误日志权限

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

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