wangliang 9 сар өмнө
parent
commit
b38025da99

+ 199 - 209
distributed-print/src/main/java/com/qmth/distributed/print/api/obe/TRBasicInfoController.java

@@ -1,6 +1,5 @@
 package com.qmth.distributed.print.api.obe;
 
-import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -12,8 +11,6 @@ import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.boot.api.exception.ApiException;
 import com.qmth.boot.core.rateLimit.annotation.RateLimit;
 import com.qmth.distributed.print.business.service.PrintCommonService;
-import com.qmth.distributed.print.business.util.PdfUtil;
-import com.qmth.distributed.print.util.WordToPdfUtil;
 import com.qmth.teachcloud.common.annotation.OperationLogDetail;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicCourse;
@@ -29,8 +26,6 @@ import com.qmth.teachcloud.common.service.CommonCacheService;
 import com.qmth.teachcloud.common.service.FileUploadService;
 import com.qmth.teachcloud.common.util.*;
 import com.qmth.teachcloud.mark.entity.MarkPaper;
-import com.qmth.teachcloud.mark.enums.LockType;
-import com.qmth.teachcloud.mark.lock.impl.CustomRedisLockProvider;
 import com.qmth.teachcloud.obe.been.dto.CourseWeightDetailDto;
 import com.qmth.teachcloud.obe.been.dto.CourseWeightDto;
 import com.qmth.teachcloud.obe.been.dto.TCUsualScoreDto;
@@ -47,7 +42,6 @@ import com.qmth.teachcloud.obe.service.*;
 import io.swagger.annotations.*;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.RegionUtil;
@@ -64,15 +58,11 @@ import javax.annotation.Resource;
 import javax.validation.Valid;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
 import java.math.BigDecimal;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.text.MessageFormat;
 import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
@@ -704,200 +694,200 @@ public class TRBasicInfoController {
         sheet.setColumnWidth(cellIndex, columnWidth > 10000 ? (int) Math.abs(columnWidth / 2) : columnWidth);
     }
 
-    @Resource
-    WordToPdfUtil wordToPdfUtil;
-
-    @Resource
-    CustomRedisLockProvider customRedisLockProvider;
-
-    @ApiOperation(value = "wordtopdf测试")
-    @RequestMapping(value = "/wordTopdf", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "转换成功", response = Object.class)})
-    @Aac(auth = false)
-    public Result wordTopdfTest() throws Exception {
-        if (customRedisLockProvider.tryLock(LockType.CREATE_PDF, "1")) {
-            try {
-                if (!customRedisLockProvider.isWriteLocked(LockType.CREATE_PDF, "1")) {
-                    customRedisLockProvider.waitLock(LockType.CREATE_PDF, "1");
-                }
-                customRedisLockProvider.watch(LockType.CREATE_PDF, "1");
-                customRedisLockProvider.watch(LockType.CREATE_PDF, "1");
-                wordToPdfUtil.wordToPdf("/Users/king/Downloads/测试学校_1_2021~2022第一学期_上学期《电力电子与电力传动》_课程目标达成度.docx", "/Users/king/Downloads/测试学校_1_2021~2022第一学期_上学期《电力电子与电力传动》_课程目标达成度.pdf", 0);
-                File file = new File("/Users/king/Downloads/测试学校_1_2021~2022第一学期_上学期《电力电子与电力传动》_课程目标达成度.pdf");
-//                PdfUtil.addWaterMarkFullScreen(file, new String[]{"启明泰和_课程目标达成度测试水印"});
-                PdfUtil.waterMark(file, "启明泰和_课程目标达成度测试水印", "123");
-            } finally {
-                customRedisLockProvider.unlock(LockType.CREATE_PDF, "1");
-                customRedisLockProvider.unwatch(LockType.CREATE_PDF, "1");
-                customRedisLockProvider.unwatch(LockType.CREATE_PDF, "1");
-            }
-        }
-        return ResultUtil.ok(true);
-    }
-
-    public static boolean threadBreak = false;
-    public static CopyOnWriteArrayList<Integer> threadKeyList = new CopyOnWriteArrayList<>();
-    public static String path = "/Users/king/Downloads/";
-    public static File fileDir = new File(path + "thread_test");
-    public static final String lockName = ":txt:file";
-    public static final String one = "[一]";
-    public static final String two = "[二]";
-    public static ConcurrentHashMap<Integer, Integer> keyMap = new ConcurrentHashMap<>();
-
-    @ApiOperation(value = "线程测试")
-    @RequestMapping(value = "/thread/test", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "测试成功", response = Object.class)})
-    @Aac(auth = false)
-    public Result threadTest() throws IOException, Exception {
-        threadBreak = false;
-        AtomicInteger threadReleaseToatlCount = new AtomicInteger(0);
-        threadKeyList.clear();
-        keyMap.clear();
-        int num = 100;
-        for (; ; ) {
-            int key = new Random().nextInt(num) + 1;
-            if (!keyMap.containsKey(key)) {
-                keyMap.put(key, key);
-                new Thread(() -> {
-                    //开始尝试获取锁
-                    if (customRedisLockProvider.tryLock(LockType.CREATE_PDF, key + "", 1L, TimeUnit.DAYS)) {
-                        log.info("########线程key:{}已获得锁########", key);
-                        try {
-                            StringJoiner stringJoinerSummary = this.readTxtFile(key + "");
-                            this.writeTxtFile(stringJoinerSummary, key + "", one + "->线程key:" + key + "已获得锁");
-                        } catch (IOException | InterruptedException e) {
-                            e.printStackTrace();
-                        }
-                        try {
-                            threadKeyList.add(key);
-                            long i = 0;
-                            do {
-                                i = i + new Random().nextInt(100) + 1;
-                                if ((Thread.currentThread().getId() & 1) == 0) {
-                                    Thread.sleep(new Random().nextInt(100) + 1);
-                                } else {
-                                    Thread.sleep(new Random().nextInt(50) + 1);
-                                }
-                            } while (i < 100000);
-                        } catch (InterruptedException e) {
-                            e.printStackTrace();
-                        } finally {
-                            customRedisLockProvider.unlock(LockType.CREATE_PDF, key + "");
-                            threadReleaseToatlCount.incrementAndGet();
-                            log.info("########线程key:{}已被释放,总计:{}########", key, threadReleaseToatlCount.get());
-                            try {
-                                StringJoiner stringJoinerSummary = this.readTxtFile(key + "");
-                                this.writeTxtFile(stringJoinerSummary, key + "", one + "->线程key:" + key + "已被释放");
-                            } catch (InterruptedException | IOException e) {
-                                e.printStackTrace();
-                            }
-                            if (threadReleaseToatlCount.get() == num) {
-                                threadBreak = true;
-                            }
-                        }
-                    }
-                }).start();
-            }
-            Thread.sleep(1000);
-            if (keyMap.size() == num) {
-                log.info("########线程生成完毕########");
-                break;
-            }
-        }
-        return ResultUtil.ok(true);
-    }
-
-    @ApiOperation(value = "线程抢夺测试")
-    @RequestMapping(value = "/thread/reave/test", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "测试成功", response = Object.class)})
-    @Aac(auth = false)
-    public Result threadReaveTest() throws IOException, Exception {
-        AtomicInteger threadReaveToatlCount = new AtomicInteger(0);
-        //开始尝试获取锁
-        for (; ; ) {
-            int index = new Random().nextInt(threadKeyList.size());
-            int key = threadKeyList.get(index);
-            if (customRedisLockProvider.tryLock(LockType.CREATE_PDF, key + "")) {
-                log.info("%%%%%%%%%线程key:{}抢到锁%%%%%%%%%", key);
-                StringJoiner stringJoinerSummary = this.readTxtFile(key + "");
-                this.writeTxtFile(stringJoinerSummary, key + "", two + "->线程key:" + key + "抢到锁");
-                threadReaveToatlCount.incrementAndGet();
-                threadKeyList.remove(key);
-                customRedisLockProvider.unlock(LockType.CREATE_PDF, key + "");
-            } else {
-                log.info("%%%%%%%%%线程key:{}正被锁定%%%%%%%%%", key);
-                StringJoiner stringJoinerSummary = this.readTxtFile(key + "");
-                this.writeTxtFile(stringJoinerSummary, key + "", two + "->线程key:" + key + "正被锁定");
-            }
-            Thread.sleep(1000);
-            if (threadKeyList.size() == 0 || threadBreak) {
-                log.info("%%%%%%%%%线程抢夺完毕%%%%%%%%%,总计:{}", threadReaveToatlCount.get());
-                break;
-            }
-        }
-        return ResultUtil.ok(true);
-    }
-
-    /**
-     * 获取txt文件读锁
-     *
-     * @param key
-     * @return
-     * @throws IOException
-     */
-    protected StringJoiner readTxtFile(String key) throws IOException {
-        if (!fileDir.exists()) {
-            fileDir.mkdirs();
-        }
-        File file = new File(fileDir.getPath() + File.separator + key + ".txt");
-        if (!file.exists()) {
-            file.createNewFile();
-        }
-        StringJoiner stringJoinerSummary = new StringJoiner("\n");
-        try {
-            customRedisLockProvider.watch(LockType.CREATE_PDF, key + lockName + ":read");
-            String text = IOUtils.toString(new FileInputStream(file), Charset.forName(SystemConstant.CHARSET_NAME));
-            if (Objects.nonNull(text) && !Objects.equals(text.trim(), "")) {
-                stringJoinerSummary.add(text);
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-        } finally {
-            customRedisLockProvider.unwatch(LockType.CREATE_PDF, key + lockName + ":read");
-        }
-        return stringJoinerSummary;
-    }
-
-    /**
-     * txt文件写锁
-     *
-     * @param stringJoinerSummary
-     * @param key
-     * @param message
-     * @throws InterruptedException
-     */
-    protected void writeTxtFile(StringJoiner stringJoinerSummary, String key, String message) throws InterruptedException, IOException {
-        if (!fileDir.exists()) {
-            fileDir.mkdirs();
-        }
-        File file = new File(fileDir.getPath() + File.separator + key + ".txt");
-        if (!file.exists()) {
-            file.createNewFile();
-        }
-        for (; ; ) {
-            if (!customRedisLockProvider.isWriteLocked(LockType.CREATE_PDF, key + lockName + ":wirte")) {
-                try {
-                    customRedisLockProvider.waitLock(LockType.CREATE_PDF, key + lockName + ":wirte");
-                    stringJoinerSummary.add(MessageFormat.format("{0}{1}", DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN), message));
-                    IOUtils.write(stringJoinerSummary.toString().getBytes(StandardCharsets.UTF_8), new FileOutputStream(file));
-                } catch (IOException e) {
-                    e.printStackTrace();
-                } finally {
-                    customRedisLockProvider.unlock(LockType.CREATE_PDF, key + lockName + ":wirte");
-                    break;
-                }
-            }
-            Thread.sleep(500);
-        }
-    }
+//    @Resource
+//    WordToPdfUtil wordToPdfUtil;
+//
+//    @Resource
+//    CustomRedisLockProvider customRedisLockProvider;
+//
+//    @ApiOperation(value = "wordtopdf测试")
+//    @RequestMapping(value = "/wordTopdf", method = RequestMethod.POST)
+//    @ApiResponses({@ApiResponse(code = 200, message = "转换成功", response = Object.class)})
+//    @Aac(auth = false)
+//    public Result wordTopdfTest() throws Exception {
+//        if (customRedisLockProvider.tryLock(LockType.CREATE_PDF, "1")) {
+//            try {
+//                if (!customRedisLockProvider.isWriteLocked(LockType.CREATE_PDF, "1")) {
+//                    customRedisLockProvider.waitLock(LockType.CREATE_PDF, "1");
+//                }
+//                customRedisLockProvider.watch(LockType.CREATE_PDF, "1");
+//                customRedisLockProvider.watch(LockType.CREATE_PDF, "1");
+//                wordToPdfUtil.wordToPdf("/Users/king/Downloads/测试学校_1_2021~2022第一学期_上学期《电力电子与电力传动》_课程目标达成度.docx", "/Users/king/Downloads/测试学校_1_2021~2022第一学期_上学期《电力电子与电力传动》_课程目标达成度.pdf", 0);
+//                File file = new File("/Users/king/Downloads/测试学校_1_2021~2022第一学期_上学期《电力电子与电力传动》_课程目标达成度.pdf");
+////                PdfUtil.addWaterMarkFullScreen(file, new String[]{"启明泰和_课程目标达成度测试水印"});
+//                PdfUtil.waterMark(file, "启明泰和_课程目标达成度测试水印", "123");
+//            } finally {
+//                customRedisLockProvider.unlock(LockType.CREATE_PDF, "1");
+//                customRedisLockProvider.unwatch(LockType.CREATE_PDF, "1");
+//                customRedisLockProvider.unwatch(LockType.CREATE_PDF, "1");
+//            }
+//        }
+//        return ResultUtil.ok(true);
+//    }
+//
+//    public static boolean threadBreak = false;
+//    public static CopyOnWriteArrayList<Integer> threadKeyList = new CopyOnWriteArrayList<>();
+//    public static String path = "/Users/king/Downloads/";
+//    public static File fileDir = new File(path + "thread_test");
+//    public static final String lockName = ":txt:file";
+//    public static final String one = "[一]";
+//    public static final String two = "[二]";
+//    public static ConcurrentHashMap<Integer, Integer> keyMap = new ConcurrentHashMap<>();
+//
+//    @ApiOperation(value = "线程测试")
+//    @RequestMapping(value = "/thread/test", method = RequestMethod.POST)
+//    @ApiResponses({@ApiResponse(code = 200, message = "测试成功", response = Object.class)})
+//    @Aac(auth = false)
+//    public Result threadTest() throws IOException, Exception {
+//        threadBreak = false;
+//        AtomicInteger threadReleaseToatlCount = new AtomicInteger(0);
+//        threadKeyList.clear();
+//        keyMap.clear();
+//        int num = 100;
+//        for (; ; ) {
+//            int key = new Random().nextInt(num) + 1;
+//            if (!keyMap.containsKey(key)) {
+//                keyMap.put(key, key);
+//                new Thread(() -> {
+//                    //开始尝试获取锁
+//                    if (customRedisLockProvider.tryLock(LockType.CREATE_PDF, key + "", 1L, TimeUnit.DAYS)) {
+//                        log.info("########线程key:{}已获得锁########", key);
+//                        try {
+//                            StringJoiner stringJoinerSummary = this.readTxtFile(key + "");
+//                            this.writeTxtFile(stringJoinerSummary, key + "", one + "->线程key:" + key + "已获得锁");
+//                        } catch (IOException | InterruptedException e) {
+//                            e.printStackTrace();
+//                        }
+//                        try {
+//                            threadKeyList.add(key);
+//                            long i = 0;
+//                            do {
+//                                i = i + new Random().nextInt(100) + 1;
+//                                if ((Thread.currentThread().getId() & 1) == 0) {
+//                                    Thread.sleep(new Random().nextInt(100) + 1);
+//                                } else {
+//                                    Thread.sleep(new Random().nextInt(50) + 1);
+//                                }
+//                            } while (i < 100000);
+//                        } catch (InterruptedException e) {
+//                            e.printStackTrace();
+//                        } finally {
+//                            customRedisLockProvider.unlock(LockType.CREATE_PDF, key + "");
+//                            threadReleaseToatlCount.incrementAndGet();
+//                            log.info("########线程key:{}已被释放,总计:{}########", key, threadReleaseToatlCount.get());
+//                            try {
+//                                StringJoiner stringJoinerSummary = this.readTxtFile(key + "");
+//                                this.writeTxtFile(stringJoinerSummary, key + "", one + "->线程key:" + key + "已被释放");
+//                            } catch (InterruptedException | IOException e) {
+//                                e.printStackTrace();
+//                            }
+//                            if (threadReleaseToatlCount.get() == num) {
+//                                threadBreak = true;
+//                            }
+//                        }
+//                    }
+//                }).start();
+//            }
+//            Thread.sleep(1000);
+//            if (keyMap.size() == num) {
+//                log.info("########线程生成完毕########");
+//                break;
+//            }
+//        }
+//        return ResultUtil.ok(true);
+//    }
+//
+//    @ApiOperation(value = "线程抢夺测试")
+//    @RequestMapping(value = "/thread/reave/test", method = RequestMethod.POST)
+//    @ApiResponses({@ApiResponse(code = 200, message = "测试成功", response = Object.class)})
+//    @Aac(auth = false)
+//    public Result threadReaveTest() throws IOException, Exception {
+//        AtomicInteger threadReaveToatlCount = new AtomicInteger(0);
+//        //开始尝试获取锁
+//        for (; ; ) {
+//            int index = new Random().nextInt(threadKeyList.size());
+//            int key = threadKeyList.get(index);
+//            if (customRedisLockProvider.tryLock(LockType.CREATE_PDF, key + "")) {
+//                log.info("%%%%%%%%%线程key:{}抢到锁%%%%%%%%%", key);
+//                StringJoiner stringJoinerSummary = this.readTxtFile(key + "");
+//                this.writeTxtFile(stringJoinerSummary, key + "", two + "->线程key:" + key + "抢到锁");
+//                threadReaveToatlCount.incrementAndGet();
+//                threadKeyList.remove(key);
+//                customRedisLockProvider.unlock(LockType.CREATE_PDF, key + "");
+//            } else {
+//                log.info("%%%%%%%%%线程key:{}正被锁定%%%%%%%%%", key);
+//                StringJoiner stringJoinerSummary = this.readTxtFile(key + "");
+//                this.writeTxtFile(stringJoinerSummary, key + "", two + "->线程key:" + key + "正被锁定");
+//            }
+//            Thread.sleep(1000);
+//            if (threadKeyList.size() == 0 || threadBreak) {
+//                log.info("%%%%%%%%%线程抢夺完毕%%%%%%%%%,总计:{}", threadReaveToatlCount.get());
+//                break;
+//            }
+//        }
+//        return ResultUtil.ok(true);
+//    }
+//
+//    /**
+//     * 获取txt文件读锁
+//     *
+//     * @param key
+//     * @return
+//     * @throws IOException
+//     */
+//    protected StringJoiner readTxtFile(String key) throws IOException {
+//        if (!fileDir.exists()) {
+//            fileDir.mkdirs();
+//        }
+//        File file = new File(fileDir.getPath() + File.separator + key + ".txt");
+//        if (!file.exists()) {
+//            file.createNewFile();
+//        }
+//        StringJoiner stringJoinerSummary = new StringJoiner("\n");
+//        try {
+//            customRedisLockProvider.watch(LockType.CREATE_PDF, key + lockName + ":read");
+//            String text = IOUtils.toString(new FileInputStream(file), Charset.forName(SystemConstant.CHARSET_NAME));
+//            if (Objects.nonNull(text) && !Objects.equals(text.trim(), "")) {
+//                stringJoinerSummary.add(text);
+//            }
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        } finally {
+//            customRedisLockProvider.unwatch(LockType.CREATE_PDF, key + lockName + ":read");
+//        }
+//        return stringJoinerSummary;
+//    }
+//
+//    /**
+//     * txt文件写锁
+//     *
+//     * @param stringJoinerSummary
+//     * @param key
+//     * @param message
+//     * @throws InterruptedException
+//     */
+//    protected void writeTxtFile(StringJoiner stringJoinerSummary, String key, String message) throws InterruptedException, IOException {
+//        if (!fileDir.exists()) {
+//            fileDir.mkdirs();
+//        }
+//        File file = new File(fileDir.getPath() + File.separator + key + ".txt");
+//        if (!file.exists()) {
+//            file.createNewFile();
+//        }
+//        for (; ; ) {
+//            if (!customRedisLockProvider.isWriteLocked(LockType.CREATE_PDF, key + lockName + ":wirte")) {
+//                try {
+//                    customRedisLockProvider.waitLock(LockType.CREATE_PDF, key + lockName + ":wirte");
+//                    stringJoinerSummary.add(MessageFormat.format("{0}{1}", DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN), message));
+//                    IOUtils.write(stringJoinerSummary.toString().getBytes(StandardCharsets.UTF_8), new FileOutputStream(file));
+//                } catch (IOException e) {
+//                    e.printStackTrace();
+//                } finally {
+//                    customRedisLockProvider.unlock(LockType.CREATE_PDF, key + lockName + ":wirte");
+//                    break;
+//                }
+//            }
+//            Thread.sleep(500);
+//        }
+//    }
 }

+ 101 - 101
distributed-print/src/main/java/com/qmth/distributed/print/util/WordToPdfUtil.java

@@ -1,101 +1,101 @@
-package com.qmth.distributed.print.util;
-
-import com.aspose.words.*;
-import com.qmth.boot.api.exception.ApiException;
-import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
-import com.qmth.teachcloud.common.enums.ImportTemplateEnum;
-import com.qmth.teachcloud.common.util.FileUtil;
-import com.qmth.teachcloud.common.util.ResultUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Component;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Objects;
-
-/**
- * @Description: aspose pdf util
- * @Param:
- * @return:
- * @Author: wangliang
- * @Date: 2021/4/7
- */
-@Component
-public class WordToPdfUtil {
-    private final static Logger log = LoggerFactory.getLogger(WordToPdfUtil.class);
-
-    /**
-     * 获取license
-     *
-     * @return
-     */
-    private boolean getLicense() {
-        boolean result = false;
-        try {
-            License aposeLic = new License();
-            InputStream inputStream = FileUtil.getStream(ImportTemplateEnum.WORD_TO_PDF_LICENSE.getTemplateName());
-            aposeLic.setLicense(inputStream);
-            result = true;
-        } catch (Exception e) {
-            log.error("请求出错", e);
-            if (e instanceof ApiException) {
-                ResultUtil.error((ApiException) e, e.getMessage());
-            } else {
-                ResultUtil.error(e.getMessage());
-            }
-        }
-        return result;
-    }
-
-    /**
-     * document转pdf
-     *
-     * @param documentPath
-     * @param pdfPath
-     * @return
-     * @throws IOException
-     */
-    public File wordToPdf(String documentPath, String pdfPath, int paperSize) throws IOException {
-        if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
-            throw ExceptionResultEnum.ERROR.exception("html转pdf失败,验证过期");
-        }
-        FileOutputStream os = null;
-        File file = null;
-        try {
-            long start = System.currentTimeMillis();
-            file = new File(pdfPath); //新建一个pdf文档
-            if (!file.getParentFile().exists()) {
-                file.getParentFile().mkdirs();
-                file.createNewFile();
-            }
-            os = new FileOutputStream(file);
-            Document doc = new Document(documentPath); //Address是将要被转化的word文档
-            DocumentBuilder builder = new DocumentBuilder(doc);
-            PageSetup pageSetup = builder.getPageSetup();
-            pageSetup.setPaperSize(paperSize);
-            pageSetup.setVerticalAlignment(PageVerticalAlignment.TOP);
-            if (paperSize == PaperSize.A3) {
-                pageSetup.setOrientation(Orientation.PORTRAIT);
-            }
-            doc.save(os, SaveFormat.PDF);//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
-            long end = System.currentTimeMillis();
-            log.info("共耗时:" + ((end - start) / 1000.0) + "秒"); //转化用时
-        } catch (Exception e) {
-            log.error("请求出错", e);
-            if (e instanceof ApiException) {
-                ResultUtil.error((ApiException) e, e.getMessage());
-            } else {
-                ResultUtil.error(e.getMessage());
-            }
-        } finally {
-            if (Objects.nonNull(os)) {
-                os.flush();
-                os.close();
-            }
-        }
-        return file;
-    }
-}
+//package com.qmth.distributed.print.util;
+//
+//import com.aspose.words.*;
+//import com.qmth.boot.api.exception.ApiException;
+//import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+//import com.qmth.teachcloud.common.enums.ImportTemplateEnum;
+//import com.qmth.teachcloud.common.util.FileUtil;
+//import com.qmth.teachcloud.common.util.ResultUtil;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//import org.springframework.stereotype.Component;
+//
+//import java.io.File;
+//import java.io.FileOutputStream;
+//import java.io.IOException;
+//import java.io.InputStream;
+//import java.util.Objects;
+//
+///**
+// * @Description: aspose pdf util
+// * @Param:
+// * @return:
+// * @Author: wangliang
+// * @Date: 2021/4/7
+// */
+//@Component
+//public class WordToPdfUtil {
+//    private final static Logger log = LoggerFactory.getLogger(WordToPdfUtil.class);
+//
+//    /**
+//     * 获取license
+//     *
+//     * @return
+//     */
+//    private boolean getLicense() {
+//        boolean result = false;
+//        try {
+//            License aposeLic = new License();
+//            InputStream inputStream = FileUtil.getStream(ImportTemplateEnum.WORD_TO_PDF_LICENSE.getTemplateName());
+//            aposeLic.setLicense(inputStream);
+//            result = true;
+//        } catch (Exception e) {
+//            log.error("请求出错", e);
+//            if (e instanceof ApiException) {
+//                ResultUtil.error((ApiException) e, e.getMessage());
+//            } else {
+//                ResultUtil.error(e.getMessage());
+//            }
+//        }
+//        return result;
+//    }
+//
+//    /**
+//     * document转pdf
+//     *
+//     * @param documentPath
+//     * @param pdfPath
+//     * @return
+//     * @throws IOException
+//     */
+//    public File wordToPdf(String documentPath, String pdfPath, int paperSize) throws IOException {
+//        if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
+//            throw ExceptionResultEnum.ERROR.exception("html转pdf失败,验证过期");
+//        }
+//        FileOutputStream os = null;
+//        File file = null;
+//        try {
+//            long start = System.currentTimeMillis();
+//            file = new File(pdfPath); //新建一个pdf文档
+//            if (!file.getParentFile().exists()) {
+//                file.getParentFile().mkdirs();
+//                file.createNewFile();
+//            }
+//            os = new FileOutputStream(file);
+//            Document doc = new Document(documentPath); //Address是将要被转化的word文档
+//            DocumentBuilder builder = new DocumentBuilder(doc);
+//            PageSetup pageSetup = builder.getPageSetup();
+//            pageSetup.setPaperSize(paperSize);
+//            pageSetup.setVerticalAlignment(PageVerticalAlignment.TOP);
+//            if (paperSize == PaperSize.A3) {
+//                pageSetup.setOrientation(Orientation.PORTRAIT);
+//            }
+//            doc.save(os, SaveFormat.PDF);//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
+//            long end = System.currentTimeMillis();
+//            log.info("共耗时:" + ((end - start) / 1000.0) + "秒"); //转化用时
+//        } catch (Exception e) {
+//            log.error("请求出错", e);
+//            if (e instanceof ApiException) {
+//                ResultUtil.error((ApiException) e, e.getMessage());
+//            } else {
+//                ResultUtil.error(e.getMessage());
+//            }
+//        } finally {
+//            if (Objects.nonNull(os)) {
+//                os.flush();
+//                os.close();
+//            }
+//        }
+//        return file;
+//    }
+//}

+ 30 - 30
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/lock/RedisLockProvider.java

@@ -1,30 +1,30 @@
-package com.qmth.teachcloud.mark.lock;
-
-import com.qmth.teachcloud.mark.enums.LockType;
-
-import java.util.concurrent.TimeUnit;
-
-public interface RedisLockProvider {
-
-    void waitLock(LockType type, String key);
-
-    void waitLock(LockType type, String key, Long time, TimeUnit timeUnit);
-
-    boolean tryLock(LockType type, String key);
-
-    boolean tryLock(LockType type, String key, Long time, TimeUnit timeUnit);
-
-    void unlock(LockType type, String key);
-
-    boolean isWriteLocked(LockType type, String key);
-
-    boolean isReadLocked(LockType type, String key);
-
-    void watch(LockType type, String key);
-
-    void watch(LockType type, String key, Long time, TimeUnit timeUnit);
-
-    void unwatch(LockType type, String key);
-
-    void clear();
-}
+//package com.qmth.teachcloud.mark.lock;
+//
+//import com.qmth.teachcloud.mark.enums.LockType;
+//
+//import java.util.concurrent.TimeUnit;
+//
+//public interface RedisLockProvider {
+//
+//    void waitLock(LockType type, String key);
+//
+//    void waitLock(LockType type, String key, Long time, TimeUnit timeUnit);
+//
+//    boolean tryLock(LockType type, String key);
+//
+//    boolean tryLock(LockType type, String key, Long time, TimeUnit timeUnit);
+//
+//    void unlock(LockType type, String key);
+//
+//    boolean isWriteLocked(LockType type, String key);
+//
+//    boolean isReadLocked(LockType type, String key);
+//
+//    void watch(LockType type, String key);
+//
+//    void watch(LockType type, String key, Long time, TimeUnit timeUnit);
+//
+//    void unwatch(LockType type, String key);
+//
+//    void clear();
+//}

+ 146 - 146
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/lock/impl/CustomRedisLockProvider.java

@@ -1,148 +1,148 @@
-package com.qmth.teachcloud.mark.lock.impl;
-
-import com.qmth.teachcloud.common.contant.SystemConstant;
-import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
-import com.qmth.teachcloud.common.util.RedisUtil;
-import com.qmth.teachcloud.mark.enums.LockType;
-import com.qmth.teachcloud.mark.lock.RedisLockProvider;
-import org.redisson.api.RReadWriteLock;
-import org.redisson.api.RedissonClient;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Component;
-import org.springframework.util.CollectionUtils;
-
-import javax.annotation.Resource;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-/**
- * 自己实现的内存锁控制
- *
- * @author luoshi
- */
-@Component("customRedisLockProvider")
-public class CustomRedisLockProvider implements RedisLockProvider {
-    private final static Logger log = LoggerFactory.getLogger(CustomRedisLockProvider.class);
-
-    @Resource
-    RedisUtil redisUtil;
-
-    @Resource
-    RedissonClient redissonClient;
-
-    @Override
-    public void waitLock(LockType type, String key) {
-        if (!this.isWriteLocked(type, key) && !this.isReadLocked(type, key)) {
-            getLock(type, key).writeLock().lock(SystemConstant.REDIS_LOCK_DEFAULT_TIME_OUT, TimeUnit.SECONDS);
-            log.info(">>>>>>>类型:{},key:{},写锁上锁成功,锁时长:{}", type.name(), key, SystemConstant.REDIS_LOCK_DEFAULT_TIME_OUT);
-        } else {
-            if (this.isReadLocked(type, key)) {
-                throw ExceptionResultEnum.ERROR.exception("获取写锁失败,请先释放读锁");
-            } else if (this.isWriteLocked(type, key)) {
-                throw ExceptionResultEnum.ERROR.exception("获取写锁失败,已获取到锁无需重复获取");
-            }
-        }
-    }
-
-    @Override
-    public void waitLock(LockType type, String key, Long time, TimeUnit timeUnit) {
-        if (!this.isWriteLocked(type, key) && !this.isReadLocked(type, key)) {
-            getLock(type, key).writeLock().lock(time, timeUnit);
-            log.info(">>>>>>>类型:{},key:{},写锁上锁成功,锁时长:{}", type.name(), key, time + "|" + timeUnit);
-        } else {
-            if (this.isReadLocked(type, key)) {
-                throw ExceptionResultEnum.ERROR.exception("获取写锁失败,请先释放读锁");
-            } else if (this.isWriteLocked(type, key)) {
-                throw ExceptionResultEnum.ERROR.exception("获取写锁失败,已获取到锁无需重复获取");
-            }
-        }
-    }
-
-    @Override
-    public boolean tryLock(LockType type, String key) {
-        try {
-            if (!this.isWriteLocked(type, key)) {
-                boolean lock = getLock(type, key).writeLock().tryLock(SystemConstant.REDIS_LOCK_GET_DEFAULT_TIME_OUT, SystemConstant.REDIS_LOCK_DEFAULT_TIME_OUT, TimeUnit.SECONDS);
-                log.info(">>>>>>>类型:{},key:{},写锁尝试上锁成功,锁时长:{}", type.name(), key, SystemConstant.REDIS_LOCK_GET_DEFAULT_TIME_OUT);
-                return lock;
-            }
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-        return false;
-    }
-
-    @Override
-    public boolean tryLock(LockType type, String key, Long time, TimeUnit timeUnit) {
-        try {
-            if (!this.isWriteLocked(type, key)) {
-                boolean lock = getLock(type, key).writeLock().tryLock(SystemConstant.REDIS_LOCK_GET_DEFAULT_TIME_OUT, time, timeUnit);
-                log.info(">>>>>>>类型:{},key:{},写锁尝试上锁成功,锁时长:{}", type.name(), key, time + "|" + timeUnit);
-                return lock;
-            }
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-        return false;
-    }
-
-    @Override
-    public boolean isWriteLocked(LockType type, String key) {
-        boolean lock = getLock(type, key).writeLock().isLocked();
-        log.info(">>>>>>>类型:{},key:{},写锁是否上锁:{}", type.name(), key, lock);
-        return lock;
-    }
-
-    @Override
-    public boolean isReadLocked(LockType type, String key) {
-        boolean lock = getLock(type, key).readLock().isLocked();
-        log.info(">>>>>>>类型:{},key:{},读锁是否上锁:{}", type.name(), key, lock);
-        return lock;
-    }
-
-    @Override
-    public void unlock(LockType type, String key) {
-        getLock(type, key).writeLock().unlock();
-        log.info(">>>>>>>类型:{},key:{},写锁释放锁成功", type.name(), key);
-    }
-
-    @Override
-    public void watch(LockType type, String key) {
-//        if (!this.isReadLocked(type, key)) {
-        getLock(type, key).readLock().lock(SystemConstant.REDIS_LOCK_DEFAULT_TIME_OUT, TimeUnit.SECONDS);
-        log.info(">>>>>>>类型:{},key:{},读锁上锁成功,锁时长:{}", type.name(), key, SystemConstant.REDIS_LOCK_GET_DEFAULT_TIME_OUT);
+//package com.qmth.teachcloud.mark.lock.impl;
+//
+//import com.qmth.teachcloud.common.contant.SystemConstant;
+//import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+//import com.qmth.teachcloud.common.util.RedisUtil;
+//import com.qmth.teachcloud.mark.enums.LockType;
+//import com.qmth.teachcloud.mark.lock.RedisLockProvider;
+//import org.redisson.api.RReadWriteLock;
+//import org.redisson.api.RedissonClient;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//import org.springframework.stereotype.Component;
+//import org.springframework.util.CollectionUtils;
+//
+//import javax.annotation.Resource;
+//import java.util.Set;
+//import java.util.concurrent.TimeUnit;
+//
+///**
+// * 自己实现的内存锁控制
+// *
+// * @author luoshi
+// */
+//@Component("customRedisLockProvider")
+//public class CustomRedisLockProvider implements RedisLockProvider {
+//    private final static Logger log = LoggerFactory.getLogger(CustomRedisLockProvider.class);
+//
+//    @Resource
+//    RedisUtil redisUtil;
+//
+//    @Resource
+//    RedissonClient redissonClient;
+//
+//    @Override
+//    public void waitLock(LockType type, String key) {
+//        if (!this.isWriteLocked(type, key) && !this.isReadLocked(type, key)) {
+//            getLock(type, key).writeLock().lock(SystemConstant.REDIS_LOCK_DEFAULT_TIME_OUT, TimeUnit.SECONDS);
+//            log.info(">>>>>>>类型:{},key:{},写锁上锁成功,锁时长:{}", type.name(), key, SystemConstant.REDIS_LOCK_DEFAULT_TIME_OUT);
+//        } else {
+//            if (this.isReadLocked(type, key)) {
+//                throw ExceptionResultEnum.ERROR.exception("获取写锁失败,请先释放读锁");
+//            } else if (this.isWriteLocked(type, key)) {
+//                throw ExceptionResultEnum.ERROR.exception("获取写锁失败,已获取到锁无需重复获取");
+//            }
 //        }
-    }
-
-    @Override
-    public void watch(LockType type, String key, Long time, TimeUnit timeUnit) {
-//        if (!this.isReadLocked(type, key)) {
-        getLock(type, key).readLock().lock(time, timeUnit);
-        log.info(">>>>>>>类型:{},key:{},读锁上锁成功,锁时长:{}", type.name(), key, time + "|" + timeUnit);
+//    }
+//
+//    @Override
+//    public void waitLock(LockType type, String key, Long time, TimeUnit timeUnit) {
+//        if (!this.isWriteLocked(type, key) && !this.isReadLocked(type, key)) {
+//            getLock(type, key).writeLock().lock(time, timeUnit);
+//            log.info(">>>>>>>类型:{},key:{},写锁上锁成功,锁时长:{}", type.name(), key, time + "|" + timeUnit);
+//        } else {
+//            if (this.isReadLocked(type, key)) {
+//                throw ExceptionResultEnum.ERROR.exception("获取写锁失败,请先释放读锁");
+//            } else if (this.isWriteLocked(type, key)) {
+//                throw ExceptionResultEnum.ERROR.exception("获取写锁失败,已获取到锁无需重复获取");
+//            }
 //        }
-    }
-
-    @Override
-    public void unwatch(LockType type, String key) {
-        getLock(type, key).readLock().unlock();
-        log.info(">>>>>>>类型:{},key:{},读锁释放锁成功", type.name(), key);
-    }
-
-    private RReadWriteLock getLock(LockType type, String key) {
-        return redissonClient.getReadWriteLock(type.name() + ":" + key);
-    }
-
-    @Override
-    public void clear() {
-        LockType[] lockTypes = LockType.values();
-        for (LockType lockType : lockTypes) {
-            Set<String> keySet = (Set<String>) redisUtil.getKeyPatterns(lockType.name() + ":*");
-            if (!CollectionUtils.isEmpty(keySet)) {
-                for (String s : keySet) {
-                    redisUtil.delete(s);
-                }
-            }
-        }
-    }
-}
+//    }
+//
+//    @Override
+//    public boolean tryLock(LockType type, String key) {
+//        try {
+//            if (!this.isWriteLocked(type, key)) {
+//                boolean lock = getLock(type, key).writeLock().tryLock(SystemConstant.REDIS_LOCK_GET_DEFAULT_TIME_OUT, SystemConstant.REDIS_LOCK_DEFAULT_TIME_OUT, TimeUnit.SECONDS);
+//                log.info(">>>>>>>类型:{},key:{},写锁尝试上锁成功,锁时长:{}", type.name(), key, SystemConstant.REDIS_LOCK_GET_DEFAULT_TIME_OUT);
+//                return lock;
+//            }
+//        } catch (InterruptedException e) {
+//            e.printStackTrace();
+//        }
+//        return false;
+//    }
+//
+//    @Override
+//    public boolean tryLock(LockType type, String key, Long time, TimeUnit timeUnit) {
+//        try {
+//            if (!this.isWriteLocked(type, key)) {
+//                boolean lock = getLock(type, key).writeLock().tryLock(SystemConstant.REDIS_LOCK_GET_DEFAULT_TIME_OUT, time, timeUnit);
+//                log.info(">>>>>>>类型:{},key:{},写锁尝试上锁成功,锁时长:{}", type.name(), key, time + "|" + timeUnit);
+//                return lock;
+//            }
+//        } catch (InterruptedException e) {
+//            e.printStackTrace();
+//        }
+//        return false;
+//    }
+//
+//    @Override
+//    public boolean isWriteLocked(LockType type, String key) {
+//        boolean lock = getLock(type, key).writeLock().isLocked();
+//        log.info(">>>>>>>类型:{},key:{},写锁是否上锁:{}", type.name(), key, lock);
+//        return lock;
+//    }
+//
+//    @Override
+//    public boolean isReadLocked(LockType type, String key) {
+//        boolean lock = getLock(type, key).readLock().isLocked();
+//        log.info(">>>>>>>类型:{},key:{},读锁是否上锁:{}", type.name(), key, lock);
+//        return lock;
+//    }
+//
+//    @Override
+//    public void unlock(LockType type, String key) {
+//        getLock(type, key).writeLock().unlock();
+//        log.info(">>>>>>>类型:{},key:{},写锁释放锁成功", type.name(), key);
+//    }
+//
+//    @Override
+//    public void watch(LockType type, String key) {
+////        if (!this.isReadLocked(type, key)) {
+//        getLock(type, key).readLock().lock(SystemConstant.REDIS_LOCK_DEFAULT_TIME_OUT, TimeUnit.SECONDS);
+//        log.info(">>>>>>>类型:{},key:{},读锁上锁成功,锁时长:{}", type.name(), key, SystemConstant.REDIS_LOCK_GET_DEFAULT_TIME_OUT);
+////        }
+//    }
+//
+//    @Override
+//    public void watch(LockType type, String key, Long time, TimeUnit timeUnit) {
+////        if (!this.isReadLocked(type, key)) {
+//        getLock(type, key).readLock().lock(time, timeUnit);
+//        log.info(">>>>>>>类型:{},key:{},读锁上锁成功,锁时长:{}", type.name(), key, time + "|" + timeUnit);
+////        }
+//    }
+//
+//    @Override
+//    public void unwatch(LockType type, String key) {
+//        getLock(type, key).readLock().unlock();
+//        log.info(">>>>>>>类型:{},key:{},读锁释放锁成功", type.name(), key);
+//    }
+//
+//    private RReadWriteLock getLock(LockType type, String key) {
+//        return redissonClient.getReadWriteLock(type.name() + ":" + key);
+//    }
+//
+//    @Override
+//    public void clear() {
+//        LockType[] lockTypes = LockType.values();
+//        for (LockType lockType : lockTypes) {
+//            Set<String> keySet = (Set<String>) redisUtil.getKeyPatterns(lockType.name() + ":*");
+//            if (!CollectionUtils.isEmpty(keySet)) {
+//                for (String s : keySet) {
+//                    redisUtil.delete(s);
+//                }
+//            }
+//        }
+//    }
+//}