|
|
@@ -4,8 +4,10 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
import com.zhongzheng.common.utils.ServletUtils;
|
|
|
+import com.zhongzheng.modules.alioss.service.OssService;
|
|
|
import com.zhongzheng.modules.base.bo.CertificateTpAddBo;
|
|
|
import com.zhongzheng.modules.base.bo.CertificateTpEditBo;
|
|
|
import com.zhongzheng.modules.base.bo.CertificateTpQueryBo;
|
|
|
@@ -22,6 +24,10 @@ import com.zhongzheng.modules.goods.service.IGoodsService;
|
|
|
import com.zhongzheng.modules.goods.vo.GoodsVo;
|
|
|
import com.zhongzheng.modules.grade.bo.ClassGradeUserQueryBo;
|
|
|
import com.zhongzheng.modules.grade.service.IClassGradeUserService;
|
|
|
+import com.zhongzheng.modules.user.bo.UserCertificateAddBo;
|
|
|
+import com.zhongzheng.modules.user.service.IUserCertificateService;
|
|
|
+import com.zhongzheng.modules.user.service.IUserService;
|
|
|
+import com.zhongzheng.modules.user.vo.UserVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
@@ -34,10 +40,8 @@ import javax.validation.Valid;
|
|
|
import javax.validation.Validation;
|
|
|
import java.awt.*;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
-import java.io.File;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.Collections;
|
|
|
+import java.io.*;
|
|
|
+import java.util.*;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -54,6 +58,12 @@ public class CertificateTpServiceImpl extends ServiceImpl<CertificateTpMapper, C
|
|
|
private IGoodsService iGoodsService;
|
|
|
@Autowired
|
|
|
private IClassGradeUserService iClassGradeUserService;
|
|
|
+ @Autowired
|
|
|
+ private IUserCertificateService iUserCertificateService;
|
|
|
+ @Autowired
|
|
|
+ private IUserService iUserService;
|
|
|
+ @Autowired
|
|
|
+ private OssService ossService;
|
|
|
|
|
|
@Override
|
|
|
public CertificateTpVo queryById(Long tpId){
|
|
|
@@ -117,8 +127,12 @@ public class CertificateTpServiceImpl extends ServiceImpl<CertificateTpMapper, C
|
|
|
*/
|
|
|
@Override
|
|
|
public String makeCertificatePhoto(ClassGradeUserQueryBo bo) {
|
|
|
+ if(Validator.isEmpty(bo.getUserId())||Validator.isEmpty(bo.getGradeId())||Validator.isEmpty(bo.getGoodsId())){
|
|
|
+ throw new CustomException("数据错误");
|
|
|
+ }
|
|
|
GoodsVo goodsVo = iGoodsService.selectDetail(bo.getGoodsId());
|
|
|
List<CourseChapterVo> chapterList = iClassGradeUserService.findChapterList(bo);
|
|
|
+ UserVo userVo = iUserService.queryById(bo.getUserId());
|
|
|
if(Validator.isNotEmpty(goodsVo.getCertificateIds())){
|
|
|
String[] s = goodsVo.getCertificateIds().split(",");
|
|
|
List<Long> tpIds = new ArrayList<>();
|
|
|
@@ -127,71 +141,135 @@ public class CertificateTpServiceImpl extends ServiceImpl<CertificateTpMapper, C
|
|
|
}
|
|
|
CertificateTpQueryBo queryBo = new CertificateTpQueryBo();
|
|
|
queryBo.setTpIds(tpIds);
|
|
|
- List<CertificateTpVo> list = queryList(queryBo);
|
|
|
+ queryBo.setStatus(new ArrayList<Integer>(Arrays.asList(1)));
|
|
|
+ List<CertificateTpVo> list = selectList(queryBo);
|
|
|
+ String nowDate = DateUtils.getDate();
|
|
|
for(CertificateTpVo tpVo : list){
|
|
|
if("certificate01".equals(tpVo.getKeyValue())){
|
|
|
CertificatePhotoVo vo = new CertificatePhotoVo();
|
|
|
- vo.setCode("XYZC21011234");
|
|
|
- vo.setRealname("李盛仁");
|
|
|
- vo.setIdCard("445224199901040003");
|
|
|
+ String code = "XYZC"+nowDate.substring(2, 4)+"01"+getCertificateCode();
|
|
|
+ vo.setCode(code);
|
|
|
+ vo.setRealname(userVo.getRealname());
|
|
|
+ vo.setIdCard(userVo.getIdCard());
|
|
|
String date = DateUtils.timestampToDate(goodsVo.getCreateTime());
|
|
|
vo.setYear(date.substring(0, 4));
|
|
|
vo.setType("专业");
|
|
|
vo.setMajor("网络班");
|
|
|
vo.setClassHours(goodsVo.getClassHours()+"");
|
|
|
- vo.setDateY(DateUtils.getDate().substring(0, 4));
|
|
|
- vo.setDateM(DateUtils.getDate().substring(5, 2));
|
|
|
- vo.setDateD(DateUtils.getDate().substring(7, 2));
|
|
|
+ vo.setDateY(nowDate.substring(0, 4));
|
|
|
+ vo.setDateM(nowDate.substring(5, 7));
|
|
|
+ vo.setDateD(nowDate.substring(8, 10));
|
|
|
List<String> chapterListTxt = changeChapterList(chapterList);
|
|
|
+ vo.setChapterList(chapterListTxt);
|
|
|
+ String ossPath = drawPic(vo);
|
|
|
|
|
|
+ UserCertificateAddBo addBo = new UserCertificateAddBo();
|
|
|
+ addBo.setUserId(bo.getUserId());
|
|
|
+ addBo.setGoodsId(bo.getGoodsId());
|
|
|
+ addBo.setGradeId(bo.getGradeId());
|
|
|
+ addBo.setCertificateTpId(tpVo.getTpId());
|
|
|
+ addBo.setCertificateCode(code);
|
|
|
+ addBo.setCertificatePath(ossPath);
|
|
|
+ addBo.setClassHours(goodsVo.getClassHours());
|
|
|
+ addBo.setEducationTypeId(goodsVo.getEducationTypeId());
|
|
|
+ addBo.setProjectId(goodsVo.getProjectId());
|
|
|
+ addBo.setBusinessId(goodsVo.getBusinessId());
|
|
|
+ iUserCertificateService.insertByAddBo(addBo);
|
|
|
+
|
|
|
+ }
|
|
|
+ else if("certificate02".equals(tpVo.getKeyValue())){
|
|
|
+ CertificatePhotoVo vo = new CertificatePhotoVo();
|
|
|
+ String code = "XYZC"+nowDate.substring(2, 4)+"03"+getCertificateCode();
|
|
|
+ vo.setCode(code);
|
|
|
+ vo.setRealname(userVo.getRealname());
|
|
|
+ vo.setIdCard(userVo.getIdCard());
|
|
|
+ String date = DateUtils.timestampToDate(goodsVo.getCreateTime());
|
|
|
+ vo.setYear(date.substring(0, 4));
|
|
|
+ vo.setType("选修");
|
|
|
+ vo.setMajor("网络班");
|
|
|
+ vo.setClassHours(goodsVo.getClassHours()+"");
|
|
|
+ vo.setDateY(nowDate.substring(0, 4));
|
|
|
+ vo.setDateM(nowDate.substring(5, 7));
|
|
|
+ vo.setDateD(nowDate.substring(8, 10));
|
|
|
+ List<String> chapterListTxt = changeChapterList(chapterList);
|
|
|
vo.setChapterList(chapterListTxt);
|
|
|
drawPic(vo);
|
|
|
|
|
|
}
|
|
|
- }
|
|
|
+ else if("certificate03".equals(tpVo.getKeyValue())){
|
|
|
+ CertificatePhotoVo vo = new CertificatePhotoVo();
|
|
|
+ String code = "XYZC"+nowDate.substring(2, 4)+"03"+getCertificateCode();
|
|
|
+ vo.setCode(code);
|
|
|
+ vo.setRealname(userVo.getRealname());
|
|
|
+ vo.setIdCard(userVo.getIdCard());
|
|
|
+ String date = DateUtils.timestampToDate(goodsVo.getCreateTime());
|
|
|
+ vo.setYear(date.substring(0, 4));
|
|
|
+ vo.setType("选修");
|
|
|
+ vo.setMajor("网络班");
|
|
|
+ String sex = "男";
|
|
|
+ if(Validator.isNotEmpty(userVo.getSex())&&userVo.getSex()==2){
|
|
|
+ sex = "女";
|
|
|
+ }
|
|
|
+ vo.setSex(sex);
|
|
|
+ vo.setClassHours(goodsVo.getClassHours()+"");
|
|
|
+ vo.setDateY(nowDate.substring(0, 4));
|
|
|
+ vo.setDateM(nowDate.substring(5, 7));
|
|
|
+ vo.setDateD(nowDate.substring(8, 10));
|
|
|
+ vo.setMajor("一级建造师继续教育培训");
|
|
|
+ vo.setRemark1("其中必修");
|
|
|
+ vo.setRemark2("课 60 学时,测试成绩合格。");
|
|
|
+ List<String> chapterListTxt = changeChapterList(chapterList);
|
|
|
+ vo.setChapterList(chapterListTxt);
|
|
|
+ drawPicOneBuild(vo);
|
|
|
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
- private String getCertificateCode(List<CourseChapterVo> chapterList){
|
|
|
- return null;
|
|
|
+ private String getCertificateCode(){
|
|
|
+ Long id = iUserCertificateService.selectMaxId();
|
|
|
+ String nowId = Long.toString(id);
|
|
|
+ String result = "";
|
|
|
+ result = String.format("%0" + 4 + "d", Integer.parseInt(nowId) + 1);
|
|
|
+ return result;
|
|
|
}
|
|
|
+
|
|
|
private List<String> changeChapterList(List<CourseChapterVo> chapterList){
|
|
|
List<String> chapterListTxt = new ArrayList<>();
|
|
|
for(int i =0; i<chapterList.size(); i++){
|
|
|
String numTag = "";
|
|
|
if(i==0){
|
|
|
- numTag = "①.";
|
|
|
+ numTag = "①. ";
|
|
|
}
|
|
|
else if(i==1){
|
|
|
- numTag = "②.";
|
|
|
+ numTag = "②. ";
|
|
|
}
|
|
|
else if(i==2){
|
|
|
- numTag = "③.";
|
|
|
+ numTag = "③. ";
|
|
|
}
|
|
|
else if(i==3){
|
|
|
- numTag = "④.";
|
|
|
+ numTag = "④. ";
|
|
|
}
|
|
|
else if(i==4){
|
|
|
- numTag = "⑤.";
|
|
|
+ numTag = "⑤. ";
|
|
|
}
|
|
|
else if(i==5){
|
|
|
- numTag = "⑥.";
|
|
|
+ numTag = "⑥. ";
|
|
|
}
|
|
|
else if(i==6){
|
|
|
- numTag = "⑦.";
|
|
|
+ numTag = "⑦. ";
|
|
|
}
|
|
|
else if(i==7){
|
|
|
- numTag = "⑧.";
|
|
|
+ numTag = "⑧. ";
|
|
|
}
|
|
|
chapterListTxt.add(numTag+chapterList.get(i).getName());
|
|
|
}
|
|
|
return chapterListTxt;
|
|
|
}
|
|
|
|
|
|
- private String drawPic(CertificatePhotoVo entity){
|
|
|
+ private String drawPic(CertificatePhotoVo entity){
|
|
|
Font font = new Font("微软雅黑", Font.PLAIN, 45);// 添加字体的属性设置
|
|
|
-
|
|
|
String projectUrl = "D:\\test\\";
|
|
|
String imgName = projectUrl + "out01.jpg";
|
|
|
try {
|
|
|
@@ -203,7 +281,7 @@ public class CertificateTpServiceImpl extends ServiceImpl<CertificateTpMapper, C
|
|
|
|
|
|
// 设置文本样式
|
|
|
g.setFont(font);
|
|
|
- g.setColor(Color.BLACK);
|
|
|
+ g.setColor(Color.DARK_GRAY);
|
|
|
|
|
|
g.drawString(entity.getCode(), 445, 290);
|
|
|
g.drawString(entity.getRealname(), 488, 562);
|
|
|
@@ -212,9 +290,6 @@ public class CertificateTpServiceImpl extends ServiceImpl<CertificateTpMapper, C
|
|
|
g.drawString(entity.getType(), 780, 679);
|
|
|
g.drawString(entity.getMajor(), 1175, 679);
|
|
|
g.drawString(entity.getClassHours(), 953, 788);
|
|
|
- g.drawString(entity.getDateY(), 2280, 1599);
|
|
|
- g.drawString(entity.getDateM(), 2505, 1599);
|
|
|
- g.drawString(entity.getDateD(), 2712, 1599);
|
|
|
int x = 493;
|
|
|
int y = 999;
|
|
|
int i=0;
|
|
|
@@ -231,6 +306,60 @@ public class CertificateTpServiceImpl extends ServiceImpl<CertificateTpMapper, C
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ g.setColor(Color.BLACK);
|
|
|
+ g.drawString(entity.getDateY(), 2280, 1599);
|
|
|
+ g.drawString(entity.getDateM(), 2505, 1599);
|
|
|
+ g.drawString(entity.getDateD(), 2712, 1599);
|
|
|
+ // 完成模板修改
|
|
|
+ g.dispose();
|
|
|
+ // 获取新文件的地址
|
|
|
+ File outputfile = new File(imgName);
|
|
|
+ // 生成新的合成过的用户二维码并写入新图片
|
|
|
+ // ImageIO.write(imageLocal, "jpg", outputfile);
|
|
|
+ //上传OSS
|
|
|
+ InputStream is = bufferedImageToInputStream(imageLocal);
|
|
|
+ return ossService.uploadInputStream(is,7);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String drawPicOneBuild(CertificatePhotoVo entity){
|
|
|
+ Font font = new Font("宋体", Font.PLAIN, 20);// 添加字体的属性设置 微软雅黑
|
|
|
+
|
|
|
+ String projectUrl = "D:\\test\\";
|
|
|
+ String imgName = projectUrl + "out02.jpg";
|
|
|
+ try {
|
|
|
+ // 加载本地图片
|
|
|
+ String imageLocalUrl = projectUrl + "003.jpg";
|
|
|
+ BufferedImage imageLocal = ImageIO.read(new File(imageLocalUrl));
|
|
|
+ // 以本地图片为模板
|
|
|
+ Graphics2D g = imageLocal.createGraphics();
|
|
|
+
|
|
|
+ // 设置文本样式
|
|
|
+ g.setFont(font);
|
|
|
+ g.setColor(Color.BLACK);
|
|
|
+
|
|
|
+ g.drawString(entity.getCode(), 273, 635);
|
|
|
+ g.drawString(entity.getRealname(), 828, 265);
|
|
|
+ g.drawString(entity.getSex(), 1015, 265);
|
|
|
+ g.drawString(entity.getIdCard(), 833, 315);
|
|
|
+ g.drawString(entity.getDateY(), 780, 365);
|
|
|
+ g.drawString(entity.getDateM(), 905, 365);
|
|
|
+ g.drawString(entity.getMajor(), 736, 408);
|
|
|
+ g.drawString(entity.getRemark1(), 1035, 408);
|
|
|
+ g.drawString(entity.getRemark2(), 730, 460);
|
|
|
+
|
|
|
+ g.drawString(entity.getDateY(), 707, 677);
|
|
|
+ g.drawString(entity.getDateM(), 783, 677);
|
|
|
+ g.drawString(entity.getDateD(), 835, 677);
|
|
|
+
|
|
|
+ g.drawString(entity.getDateY(), 945, 677);
|
|
|
+ g.drawString(entity.getDateM(), 1019, 677);
|
|
|
+ g.drawString(entity.getDateD(), 1071, 677);
|
|
|
+
|
|
|
// 完成模板修改
|
|
|
g.dispose();
|
|
|
// 获取新文件的地址
|
|
|
@@ -246,6 +375,18 @@ public class CertificateTpServiceImpl extends ServiceImpl<CertificateTpMapper, C
|
|
|
return imgName;
|
|
|
}
|
|
|
|
|
|
+ public InputStream bufferedImageToInputStream(BufferedImage image){
|
|
|
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
|
|
|
+ try {
|
|
|
+ ImageIO.write(image, "png", os);
|
|
|
+ InputStream input = new ByteArrayInputStream(os.toByteArray());
|
|
|
+ return input;
|
|
|
+ } catch (IOException e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<CertificateTpVo> selectList(CertificateTpQueryBo bo) {
|
|
|
return this.baseMapper.selectList(bo);
|