Bladeren bron

3.4.5 update-20250515 pdf内嵌字体、数据同步bug修复

xiaofei 1 maand geleden
bovenliggende
commit
1c9cd3b74b

+ 15 - 5
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicExamStudentServiceImpl.java

@@ -37,6 +37,8 @@ import com.qmth.teachcloud.mark.service.MarkStudentService;
 import com.qmth.teachcloud.mark.service.MarkTaskService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -58,7 +60,7 @@ import java.util.stream.Collectors;
  */
 @Service
 public class BasicExamStudentServiceImpl extends ServiceImpl<BasicExamStudentMapper, BasicExamStudent> implements BasicExamStudentService {
-
+    private static final Logger log = LoggerFactory.getLogger(BasicExamStudentServiceImpl.class);
     @Resource
     private BasicRoleDataPermissionService basicRoleDataPermissionService;
     @Resource
@@ -621,10 +623,9 @@ public class BasicExamStudentServiceImpl extends ServiceImpl<BasicExamStudentMap
 
         List<BasicExamStudent> basicExamStudents = new ArrayList<>();
 
-        StringJoiner errorMsg = new StringJoiner("<br>");
-        AtomicInteger i = new AtomicInteger(0);
+        log.info("考生同步:校验考生数据开始");
+        StringJoiner errorMsg = new StringJoiner("\n");
         for (TSyncDataStudent tSyncDataStudent : examStudentDataVoList) {
-            StringJoiner stringJoiner = new StringJoiner(";<br>");
             try {
                 if (StringUtils.isBlank(tSyncDataStudent.getCourseCode())) {
                     throw ExceptionResultEnum.ERROR.exception("课程代码必填");
@@ -779,16 +780,25 @@ public class BasicExamStudentServiceImpl extends ServiceImpl<BasicExamStudentMap
                 parserRequiredField(basicExamStudent, basicExamRule);
                 basicExamStudents.add(basicExamStudent);
             } catch (Exception e) {
-                stringJoiner.add(e.getMessage());
+                errorMsg.add(e.getMessage());
             }
         }
 
+        log.info("考生同步:校验考生数据结束");
+        log.info("考生同步:更新(插入)考生数据开始");
         this.saveOrUpdateBatch(basicExamStudents);
+        log.info("考生同步:更新(插入)考生数据结束");
+        log.info("考生同步:更新启用状态开始");
         // 更新删除考生启用状态为false
         this.baseMapper.updateEnableFalse(examId);
+        log.info("考生同步:更新启用状态结束");
+        log.info("考生同步:扫描考生数据开始");
         this.updateMarkData(examId, basicExamStudentList, null);
+        log.info("考生同步:扫描考生数据结束");
+        log.info("考生同步:创建课程管理数据开始");
         // 自动创建课程管理数据
         teachCourseService.batchCreateTeachCourse(schoolId, examId, basicExamStudentList);
+        log.info("考生同步:创建课程管理数据结束");
         Map<String, Object> map = new HashMap<>();
         map.put("count", basicExamStudents.size());
         map.put("errMsg", errorMsg.toString());

+ 10 - 10
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/PdfUtil.java

@@ -472,7 +472,7 @@ public class PdfUtil {
             }
             reader = new PdfReader(new FileInputStream(inputFile));
             stamper = new PdfStamper(reader, new FileOutputStream(outputPath));
-            BaseFont base = BaseFont.createFont(AsianFontMapper.ChineseSimplifiedFont, AsianFontMapper.ChineseSimplifiedEncoding_H, BaseFont.NOT_EMBEDDED);
+//            BaseFont base = BaseFont.createFont(AsianFontMapper.ChineseSimplifiedFont, AsianFontMapper.ChineseSimplifiedEncoding_H, BaseFont.NOT_EMBEDDED);
             PdfGState gs = new PdfGState();
             //这里是透明度设置
             gs.setFillOpacity(opacity);
@@ -506,7 +506,7 @@ public class PdfUtil {
                 under.saveState();
                 under.setGState(gs);
                 under.beginText();
-                under.setFontAndSize(base, fontsize); //这里是水印字体大小
+                under.setFontAndSize(PdfFillUtils.bfChinese, fontsize); //这里是水印字体大小
                 for (int j = 0; j < waterMarkName.length; j++) {
                     under.showTextAligned(Element.ALIGN_LEFT, waterMarkName[j], 20, pageRect.getHeight() - 20 - (j * textH), rotation);
                 }
@@ -577,7 +577,7 @@ public class PdfUtil {
             }
             reader = new PdfReader(new FileInputStream(inputFile));
             stamper = new PdfStamper(reader, new FileOutputStream(outputPath));
-            BaseFont base = BaseFont.createFont(AsianFontMapper.ChineseSimplifiedFont, AsianFontMapper.ChineseSimplifiedEncoding_H, BaseFont.NOT_EMBEDDED);
+//            BaseFont base = BaseFont.createFont(AsianFontMapper.ChineseSimplifiedFont, AsianFontMapper.ChineseSimplifiedEncoding_H, BaseFont.NOT_EMBEDDED);
             PdfGState gs = new PdfGState();
             //这里是透明度设置
             gs.setFillOpacity(opacity);
@@ -591,7 +591,7 @@ public class PdfUtil {
             under.saveState();
             under.setGState(gs);
             under.beginText();
-            under.setFontAndSize(base, fontsize); //这里是水印字体大小
+            under.setFontAndSize(PdfFillUtils.bfChinese, fontsize); //这里是水印字体大小
 
             image.setAbsolutePosition(pageRect.getWidth() * 0.75f, pageRect.getHeight() - 40);
             image.scaleAbsolute(150, 30);
@@ -658,7 +658,7 @@ public class PdfUtil {
             }
             reader = new PdfReader(new FileInputStream(inputFile));
             stamper = new PdfStamper(reader, new FileOutputStream(inputFile));
-            BaseFont base = BaseFont.createFont(AsianFontMapper.ChineseSimplifiedFont, AsianFontMapper.ChineseSimplifiedEncoding_H, BaseFont.NOT_EMBEDDED);
+//            BaseFont base = BaseFont.createFont(AsianFontMapper.ChineseSimplifiedFont, AsianFontMapper.ChineseSimplifiedEncoding_H, BaseFont.NOT_EMBEDDED);
             PdfGState gs = new PdfGState();
             //这里是透明度设置
             gs.setFillOpacity(opacity);
@@ -688,7 +688,7 @@ public class PdfUtil {
                 under.saveState();
                 under.setGState(gs);
                 under.beginText();
-                under.setFontAndSize(base, fontsize); //这里是水印字体大小
+                under.setFontAndSize(PdfFillUtils.bfChinese, fontsize); //这里是水印字体大小
                 for (int j = 0; j < waterMarkName.length; j++) {
                     under.showTextAligned(Element.ALIGN_LEFT, waterMarkName[j], 20, pageRect.getHeight() - 20 - (j * textH), rotation);
                 }
@@ -733,7 +733,7 @@ public class PdfUtil {
         PdfGState gs = new PdfGState();
 
         // 设置字体
-        BaseFont font = BaseFont.createFont(AsianFontMapper.ChineseSimplifiedFont, AsianFontMapper.ChineseSimplifiedEncoding_H, BaseFont.NOT_EMBEDDED);
+//        BaseFont font = BaseFont.createFont(AsianFontMapper.ChineseSimplifiedFont, AsianFontMapper.ChineseSimplifiedEncoding_H, BaseFont.NOT_EMBEDDED);
 
         // 设置透明度
         gs.setFillOpacity(0.2f);
@@ -747,7 +747,7 @@ public class PdfUtil {
             // 水印颜色
             content.setColorFill(BaseColor.BLUE);
             // 水印字体样式和大小
-            content.setFontAndSize(font, 20);
+            content.setFontAndSize(PdfFillUtils.bfChinese, 20);
 
             // 获取页面尺寸
             Rectangle pageSize = reader.getPageSize(i);
@@ -795,7 +795,7 @@ public class PdfUtil {
             stamper.setEncryption(null, ownerPassword, PdfWriter.DO_NOT_ENCRYPT_METADATA, true);
             stamper.setViewerPreferences(PdfWriter.HideToolbar | PdfWriter.HideMenubar);
 
-            BaseFont font = BaseFont.createFont(AsianFontMapper.ChineseSimplifiedFont, AsianFontMapper.ChineseSimplifiedEncoding_H, BaseFont.NOT_EMBEDDED);
+//            BaseFont font = BaseFont.createFont(AsianFontMapper.ChineseSimplifiedFont, AsianFontMapper.ChineseSimplifiedEncoding_H, BaseFont.NOT_EMBEDDED);
 
             Rectangle pageRect = null;
             PdfGState gs = new PdfGState();
@@ -823,7 +823,7 @@ public class PdfUtil {
                 under.saveState();
                 under.setGState(gs);
                 under.beginText();
-                under.setFontAndSize(font, 15);
+                under.setFontAndSize(PdfFillUtils.bfChinese, 15);
                 // 水印文字成45度角倾斜
                 for (int height = interval + textH; height < pageRect.getHeight();
                      height = height + textH * 8) {

+ 3 - 2
distributed-print/src/test/java/com/qmth/distributed/print/PDFWaterMarkTest.java

@@ -5,6 +5,7 @@ import com.itextpdf.text.DocumentException;
 import com.itextpdf.text.Element;
 import com.itextpdf.text.Rectangle;
 import com.itextpdf.text.pdf.*;
+import com.qmth.distributed.print.business.util.PdfFillUtils;
 
 import javax.swing.*;
 import java.awt.*;
@@ -54,7 +55,7 @@ public class PDFWaterMarkTest {
         try {
             reader = new PdfReader(inputFile);
             stamper = new PdfStamper(reader, new FileOutputStream(outputFile));
-            BaseFont base = BaseFont.createFont(AsianFontMapper.ChineseSimplifiedFont, AsianFontMapper.ChineseSimplifiedEncoding_H, BaseFont.NOT_EMBEDDED);
+//            BaseFont base = BaseFont.createFont(AsianFontMapper.ChineseSimplifiedFont, AsianFontMapper.ChineseSimplifiedEncoding_H, BaseFont.NOT_EMBEDDED);
             Rectangle pageRect = null;
             PdfGState gs = new PdfGState();
             //这里是透明度设置
@@ -87,7 +88,7 @@ public class PDFWaterMarkTest {
                 under.setGState(gs);
                 under.beginText();
                 //under.setColorFill(BaseColor.PINK);  //添加文字颜色  不能动态改变 放弃使用
-                under.setFontAndSize(base, fontsize); //这里是水印字体大小
+                under.setFontAndSize(PdfFillUtils.bfChinese, fontsize); //这里是水印字体大小
                 for (int j = 0; j < waterMarkName.length;j++) {
                     under.showTextAligned(Element.ALIGN_LEFT, waterMarkName[j], 10, pageRect.getHeight() - 30 - (j * textH), rotation);
                 }

+ 13 - 0
teachcloud-data/src/main/java/com/qmth/teachcloud/data/service/DataService.java

@@ -2,9 +2,22 @@ package com.qmth.teachcloud.data.service;
 
 
 import com.qmth.distributed.print.business.bean.params.SysAdminSetParam;
+import com.qmth.teachcloud.data.dto.SyncDataResult;
 import com.qmth.teachcloud.data.entity.TSyncData;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.transaction.annotation.Transactional;
 
 public interface DataService {
     boolean testConnect(SysAdminSetParam sysAdminSetParam);
     void syncData(Long schoolId, Long examId, TSyncData syncData);
+
+    SyncDataResult syncOrg(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType);
+
+    SyncDataResult syncUser(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType);
+
+    SyncDataResult syncCourse(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType);
+
+    SyncDataResult syncStudent(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType);
+
+    SyncDataResult syncExamTask(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType);
 }

+ 1 - 0
teachcloud-data/src/main/java/com/qmth/teachcloud/data/service/TSyncDataStudentService.java

@@ -13,4 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface TSyncDataStudentService extends IService<TSyncDataStudent> {
 
+    void deleteByExamId(Long examId);
 }

+ 35 - 12
teachcloud-data/src/main/java/com/qmth/teachcloud/data/service/impl/DataServiceImpl.java

@@ -3,11 +3,9 @@ package com.qmth.teachcloud.data.service.impl;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.qmth.distributed.print.business.bean.params.SysAdminSetParam;
-import com.qmth.distributed.print.business.enums.RequiredFieldsEnum;
 import com.qmth.distributed.print.business.service.BasicExamStudentService;
 import com.qmth.distributed.print.business.service.BasicMessageService;
 import com.qmth.distributed.print.business.service.ExamTaskService;
-import com.qmth.teachcloud.common.bean.examRule.CodeNameEnableDisabledValue;
 import com.qmth.teachcloud.common.bean.sync.*;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicSchool;
@@ -33,6 +31,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.util.HashMap;
@@ -149,7 +148,9 @@ public class DataServiceImpl implements DataService {
         }
     }
 
-    private SyncDataResult syncOrg(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
+    @Transactional
+    @Override
+    public SyncDataResult syncOrg(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
         long startTime = System.currentTimeMillis();
         List<OrgDataVo> dataVoList = dataUtil.listOrg(jdbcTemplate, DataType.A, datasourceType);
         log.info("查询到待同步机构数量:" + dataVoList.size());
@@ -168,7 +169,9 @@ public class DataServiceImpl implements DataService {
         return new SyncDataResult(i.get(), errorMsg.toString());
     }
 
-    private SyncDataResult syncUser(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
+    @Transactional
+    @Override
+    public SyncDataResult syncUser(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
         long startTime = System.currentTimeMillis();
         List<UserDataVo> dataVoList = dataUtil.listUser(jdbcTemplate, DataType.B, datasourceType);
         log.info("查询到待同步用户数量:" + dataVoList.size());
@@ -187,7 +190,9 @@ public class DataServiceImpl implements DataService {
         return new SyncDataResult(i.get(), errorMsg.toString());
     }
 
-    private SyncDataResult syncCourse(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
+    @Transactional
+    @Override
+    public SyncDataResult syncCourse(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
         long startTime = System.currentTimeMillis();
         List<CourseDataVo> dataVoList = dataUtil.listCourse(jdbcTemplate, DataType.C, datasourceType);
         log.info("查询到待同步课程数量:" + dataVoList.size());
@@ -206,14 +211,18 @@ public class DataServiceImpl implements DataService {
         return new SyncDataResult(i.get(), errorMsg.toString());
     }
 
-    private SyncDataResult syncStudent(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
+    @Transactional
+    @Override
+    public SyncDataResult syncStudent(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
         long startTime = System.currentTimeMillis();
+        log.info("考生同步:查询待同步考生开始");
         List<TSyncDataStudent> dataVoList = dataUtil.listExamStudent(jdbcTemplate, DataType.D, datasourceType);
-        log.info("查询到待同步考生数量:" + dataVoList.size());
+        log.info("考生同步:查询待同步考生结束。数量:{}", dataVoList.size());
         Map<String, Object> map = new HashMap<>();
-        int successCount = 0;
+        int successCount;
         String errMsg = null;
         try {
+            log.info("考生同步:处理考试时间开始");
             for (TSyncDataStudent tSyncDataStudent : dataVoList) {
                 tSyncDataStudent.setId(SystemConstant.getDbUuid());
                 tSyncDataStudent.setSchoolId(schoolId);
@@ -229,21 +238,35 @@ public class DataServiceImpl implements DataService {
                     }
                 }
             }
-            tSyncDataStudentService.remove(new UpdateWrapper<TSyncDataStudent>().lambda().eq(TSyncDataStudent::getSchoolId, schoolId).eq(TSyncDataStudent::getExamId, examId));
-            tSyncDataStudentService.saveBatch(dataVoList);
+            log.info("考生同步:处理考试时间结束");
+            log.info("考生同步:删除临时表数据开始");
+            tSyncDataStudentService.deleteByExamId(examId);
+            log.info("考生同步:删除临时表数据结束");
+            log.info("考生同步:插入临时表数据开始");
+            tSyncDataStudentService.saveOrUpdateBatch(dataVoList);
+            log.info("考生同步:插入临时表数据开始");
+            log.info("考生同步:处理考生考入开始");
             map = basicExamStudentService.saveBasicExamStudentFormSync(schoolId, examId, dataVoList);
+            log.info("考生同步:处理考生考入结束");
         } catch (Exception e) {
             errMsg = e.getMessage();
+            log.info("考生同步:过程中报错:{}",errMsg);
+            e.printStackTrace();
         } finally {
+            log.info("考生同步:保存日志数据开始");
             successCount = map.containsKey("count") ? Integer.parseInt(map.get("count").toString()) : 0;
-            errMsg = errMsg == null && map.containsKey("errMsg") ? map.get("errMsg").toString() : null;
+            errMsg = errMsg == null && map.containsKey("errMsg") ? map.get("errMsg").toString() : errMsg;
             long endTime = System.currentTimeMillis();
             tSyncDataLogService.saveLog(schoolId, examId, DataType.D.name(), startTime, endTime, dataVoList.size(), successCount, errMsg);
+            tSyncDataStudentService.deleteByExamId(examId);
+            log.info("考生同步:保存日志数据结束");
         }
         return new SyncDataResult(successCount, errMsg);
     }
 
-    private SyncDataResult syncExamTask(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
+    @Transactional
+    @Override
+    public SyncDataResult syncExamTask(JdbcTemplate jdbcTemplate, Long schoolId, Long examId, String datasourceType) {
         long startTime = System.currentTimeMillis();
         List<ExamTaskDataVo> dataVoList = dataUtil.listExamTask(jdbcTemplate, DataType.E, datasourceType);
         log.info("查询到待同步命题任务数量:" + dataVoList.size());

+ 7 - 0
teachcloud-data/src/main/java/com/qmth/teachcloud/data/service/impl/TSyncDataStudentServiceImpl.java

@@ -1,5 +1,6 @@
 package com.qmth.teachcloud.data.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.qmth.teachcloud.common.bean.sync.TSyncDataStudent;
 import com.qmth.teachcloud.data.mapper.TSyncDataStudentMapper;
 import com.qmth.teachcloud.data.service.TSyncDataStudentService;
@@ -17,4 +18,10 @@ import org.springframework.stereotype.Service;
 @Service
 public class TSyncDataStudentServiceImpl extends ServiceImpl<TSyncDataStudentMapper, TSyncDataStudent> implements TSyncDataStudentService {
 
+    @Override
+    public void deleteByExamId(Long examId) {
+        UpdateWrapper<TSyncDataStudent> updateWrapper = new UpdateWrapper<>();
+        updateWrapper.lambda().eq(TSyncDataStudent::getExamId, examId);
+        this.remove(updateWrapper);
+    }
 }