证书修改
This commit is contained in:
@@ -19,6 +19,7 @@ import org.apache.commons.lang.ArrayUtils;
|
|||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@@ -401,115 +402,111 @@ public class ClassController {
|
|||||||
|
|
||||||
//生成证书
|
//生成证书
|
||||||
@RequestMapping("/generateCertificateClass")
|
@RequestMapping("/generateCertificateClass")
|
||||||
|
@Transactional
|
||||||
public R generateCertificateClass(@RequestBody Map<String,Object> params) {
|
public R generateCertificateClass(@RequestBody Map<String,Object> params) {
|
||||||
try {
|
//抢锁
|
||||||
//证书类型A a证 B b证 ZK自考
|
Boolean lock = redisTemplate.opsForValue().setIfAbsent("lock", "123");
|
||||||
String type = params.get("type").toString();
|
if(lock) {
|
||||||
MyUserEntity user = ShiroUtils.getUser();
|
try {
|
||||||
String photoUrl = user.getPhoto();//证书人照片
|
//证书类型A a证 B b证 ZK自考
|
||||||
String realName = user.getName();//真是姓名
|
String type = params.get("type").toString();
|
||||||
UserCertificate userCertificate = new UserCertificate();
|
MyUserEntity user = ShiroUtils.getUser();
|
||||||
userCertificate.setType(type);
|
String photoUrl = user.getPhoto();//证书人照片
|
||||||
userCertificate.setUserId(ShiroUtils.getUId());
|
String realName = user.getName();//真是姓名
|
||||||
if ("ZK".equals(type)){
|
UserCertificate userCertificate = new UserCertificate();
|
||||||
CourseEntity courseEntity = courseService.getById(params.get("relationId").toString());
|
userCertificate.setType(type);
|
||||||
String courseTitle = courseEntity.getTitle();
|
userCertificate.setUserId(ShiroUtils.getUId());
|
||||||
if (courseTitle.contains("【")){
|
if ("ZK".equals(type)){
|
||||||
courseTitle = courseEntity.getTitle().substring(0,courseEntity.getTitle().indexOf("【"));
|
CourseEntity courseEntity = courseService.getById(params.get("relationId").toString());
|
||||||
|
String courseTitle = courseEntity.getTitle();
|
||||||
|
if (courseTitle.contains("【")){
|
||||||
|
courseTitle = courseEntity.getTitle().substring(0,courseEntity.getTitle().indexOf("【"));
|
||||||
|
}
|
||||||
|
userCertificate.setTitle(courseTitle);
|
||||||
|
ClassExamUser classExamUser = classExamUserService.getOne(new LambdaQueryWrapper<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,courseTitle};
|
||||||
|
String[] edes = {courseEntity.getEtitle()};
|
||||||
|
String certificateNo = getNextCertificateNo(type,courseEntity.getTitleAbbr());//证书编号
|
||||||
|
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"));
|
||||||
|
double keshiTotal = (double)map.get("keshi");
|
||||||
|
String keshi = (keshiTotal+"").replace(".0","");
|
||||||
|
String courseTitle = map.get("courseTitle").toString();
|
||||||
|
if (courseTitle.contains("【")){
|
||||||
|
courseTitle = courseTitle.substring(0,courseTitle.indexOf("【"));
|
||||||
|
}
|
||||||
|
String[] des = {startYear,startMonth,startDay,endYear,endMonth,endDay,
|
||||||
|
classEntity.getTitle(),courseTitle,keshi};
|
||||||
|
String[] edes = {map.get("courseETitle").toString(),keshi};
|
||||||
|
String certificateNo = getNextCertificateNo(type,map.get("titleAbbr").toString());
|
||||||
|
String url = userCertificateService.generateCertificate(type,certificateNo,photoUrl,realName,des, edes, endYear,endMonth,endDay);
|
||||||
|
userCertificate.setCertificateUrl(url);
|
||||||
|
userCertificate.setCertificateNo(certificateNo);
|
||||||
|
userCertificate.setTitle(classEntity.getTitle());
|
||||||
|
userCertificate.setClassId(classEntity.getId());
|
||||||
|
userCertificateService.save(userCertificate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
userCertificate.setTitle(courseTitle);
|
}finally {
|
||||||
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,courseTitle};
|
|
||||||
String[] edes = {courseEntity.getEtitle()};
|
|
||||||
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);
|
|
||||||
//解锁
|
//解锁
|
||||||
redisTemplate.delete("lock");
|
redisTemplate.delete("lock");
|
||||||
}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 courseTitle = map.get("courseTitle").toString();
|
|
||||||
if (courseTitle.contains("【")){
|
|
||||||
courseTitle = courseTitle.substring(0,courseTitle.indexOf("【"));
|
|
||||||
}
|
|
||||||
String[] des = {startYear,startMonth,startDay,endYear,endMonth,endDay,
|
|
||||||
classEntity.getTitle(),courseTitle,keshi};
|
|
||||||
String[] edes = {map.get("courseETitle").toString(),keshi};
|
|
||||||
String url = userCertificateService.generateCertificate(type,certificateNo,photoUrl,realName,des, edes, endYear,endMonth,endDay);
|
|
||||||
userCertificate.setTitle(classEntity.getTitle());
|
|
||||||
userCertificate.setCertificateUrl(url);
|
|
||||||
userCertificate.setClassId(classEntity.getId());
|
|
||||||
userCertificateService.save(userCertificate);
|
|
||||||
//解锁
|
|
||||||
redisTemplate.delete("lock");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return R.ok();
|
}else {
|
||||||
}finally {
|
generateCertificateClass(params);
|
||||||
//解锁
|
|
||||||
redisTemplate.delete("lock");
|
|
||||||
}
|
}
|
||||||
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取下一个编号
|
//获取下一个编号
|
||||||
public String getNextCertificateNo(String type,String courseNamePinyin){
|
public String getNextCertificateNo(String type,String courseNamePinyin){
|
||||||
//抢锁
|
List<UserCertificate> userCertificateList = userCertificateService.list(new LambdaQueryWrapper<UserCertificate>()
|
||||||
Boolean lock = redisTemplate.opsForValue().setIfAbsent("lock", "123");
|
.orderByDesc(UserCertificate::getId));
|
||||||
if(lock) {
|
String res = "";
|
||||||
List<UserCertificate> userCertificateList = userCertificateService.list(new LambdaQueryWrapper<UserCertificate>()
|
if (userCertificateList.size() > 0){
|
||||||
.orderByDesc(UserCertificate::getCreateTime));
|
UserCertificate u0 = userCertificateList.get(0);
|
||||||
String res = "";
|
String certificateNo = u0.getCertificateNo();
|
||||||
if (userCertificateList.size() > 0){
|
int no = 0;
|
||||||
UserCertificate u0 = userCertificateList.get(0);
|
if (certificateNo.contains("ZK")){
|
||||||
String certificateNo = u0.getCertificateNo();
|
no = Integer.parseInt(certificateNo.substring(5,11))+1;
|
||||||
int no = 0;
|
|
||||||
if (certificateNo.contains("ZK")){
|
|
||||||
no = Integer.parseInt(certificateNo.substring(5,11))+1;
|
|
||||||
}else {
|
|
||||||
no = Integer.parseInt(certificateNo.substring(3,9))+1;
|
|
||||||
}
|
|
||||||
if ("A".equals(type)){
|
|
||||||
res = "NO."+String.format("%06d", no);
|
|
||||||
}else if ("B".equals(type)){
|
|
||||||
res = "NO."+String.format("%06d", no);
|
|
||||||
}else if ("ZK".equals(type)){
|
|
||||||
res = "NO.ZK"+String.format("%06d", no);
|
|
||||||
}
|
|
||||||
}else {
|
}else {
|
||||||
if ("A".equals(type)){
|
no = Integer.parseInt(certificateNo.substring(3,9))+1;
|
||||||
res = "NO.000001";
|
}
|
||||||
}else if ("B".equals(type)){
|
if ("A".equals(type)){
|
||||||
res = "NO.000001";
|
res = "NO."+String.format("%06d", no);
|
||||||
}else if ("ZK".equals(type)){
|
}else if ("B".equals(type)){
|
||||||
res = "NO.ZK000001";
|
res = "NO."+String.format("%06d", no);
|
||||||
}
|
}else if ("ZK".equals(type)){
|
||||||
|
res = "NO.ZK"+String.format("%06d", no);
|
||||||
}
|
}
|
||||||
return res+courseNamePinyin;
|
|
||||||
}else {
|
}else {
|
||||||
return getNextCertificateNo(type,courseNamePinyin);
|
if ("A".equals(type)){
|
||||||
|
res = "NO.000001";
|
||||||
|
}else if ("B".equals(type)){
|
||||||
|
res = "NO.000001";
|
||||||
|
}else if ("ZK".equals(type)){
|
||||||
|
res = "NO.ZK000001";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return res+courseNamePinyin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user