Sfoglia il codice sorgente

等级评定下载

licailing 4 anni fa
parent
commit
f41997c9ba

+ 2 - 0
src/main/java/com/izouma/wenlvju/domain/Rate.java

@@ -162,6 +162,8 @@ public class Rate extends BaseEntity {
     @ApiModelProperty(value = "变更地址")
     private String changeAddress;
 
+    private String pdfUrl;
+
     public String getDetailAddress() {
         String str = "江苏省南京市" + this.district;
 

+ 2 - 2
src/main/java/com/izouma/wenlvju/repo/TrainingInstitutionRepo.java

@@ -15,10 +15,10 @@ public interface TrainingInstitutionRepo extends JpaRepository<TrainingInstituti
     @Transactional
     void softDelete(Long id);
 
-    @Query(nativeQuery = true, value = "select phone from training_institution where submit = false and phone REGEXP '^[1][356789][0-9]{9}$'")
+    @Query(nativeQuery = true, value = "select DISTINCT phone from training_institution where submit = false and phone REGEXP '^[1][356789][0-9]{9}$'")
     List<String> findAllBySubmitFalseAndPhoneIsNotNull();
 
-    @Query(nativeQuery = true, value = "select phone from training_institution where submit = false and phone REGEXP '^[1][356789][0-9]{9}$' limit 2000,2000")
+    @Query(nativeQuery = true, value = "select DISTINCT phone from training_institution where submit = false and phone REGEXP '^[1][356789][0-9]{9}$' limit 2000,2000")
     List<String> findAllBySubmitFalseAndPhoneIsNotNullLimit();
 
     List<TrainingInstitution> findAllByPhoneIsNull();

+ 85 - 9
src/main/java/com/izouma/wenlvju/service/RateService.java

@@ -234,6 +234,12 @@ public class RateService {
 //        }
     }
 
+    /**
+     * 生成word模版
+     *
+     * @param rate
+     * @return
+     */
     public String export(Rate rate) {
         Map<String, Object> dataMap = new HashMap<>();
         try {
@@ -266,7 +272,6 @@ public class RateService {
 
             //单位概况
             dataMap.put("introduction", rate.getIntroduction());
-
             //等级
             dataMap.put("grade", rate.getGrade().getDesc());
 
@@ -297,6 +302,10 @@ public class RateService {
         this.addList(imageUrllist, rate.getFinance());
         this.addList(imageUrllist, rate.getProperty());
 
+        if (CollUtil.isEmpty(imageUrllist)) {
+            return;
+        }
+
         String filename = "img" + UUID.randomUUID() + ".pdf";
         File file = null;
 
@@ -316,12 +325,13 @@ public class RateService {
                 png1.setAlignment(Image.MIDDLE);
                 png1.scalePercent(percent + 3);// 表示是原来图像的比例;
                 doc.add(png1);
+
+
             }
 //            b = os.toByteArray();
 
             file = new File(filename);
-//            System.out.println(filename);
-//            System.out.println(file.getName());
+
             InputStream is = new FileInputStream(file);
             files.add(is);
 
@@ -464,11 +474,17 @@ public class RateService {
         return url.substring(index + 1);
     }
 
-    public void exportPdf(Long id, HttpServletResponse response) throws IOException {
+    /**
+     * 合并并下载pdf
+     *
+     * @param id
+     * @param response
+     * @throws IOException
+     */
+    public void exportPdf1(Long id, HttpServletResponse response) throws IOException {
         Rate rate = rateRepo.findById(id).orElseThrow(new BusinessException("无记录"));
         List<InputStream> files = this.upLoad1(rate);
 
-
         // pdf合并工具类
         PDFMergerUtility mergePdf = new PDFMergerUtility();
         mergePdf.addSources(files);
@@ -479,10 +495,6 @@ public class RateService {
 
         mergePdf.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
 
-        // 设置合并生成pdf文件名称
-//        String targetPath = "/Users/qiufangchao/Desktop/result.pdf";
-//        mergePdf.setDestinationFileName(targetPath);
-
         for (InputStream is : files) {
             is.close();
         }
@@ -497,6 +509,70 @@ public class RateService {
         outputStream.close();
     }
 
+    /**
+     * 下载pdf
+     *
+     * @param id
+     * @param response
+     * @throws IOException
+     */
+    public byte[] exportPdf(Long id, HttpServletResponse response) throws IOException {
+        Rate rate = rateRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+
+        // 设置response的Header
+        response.setContentType("application/pdf");
+        response.addHeader("Content-Disposition", "attachment;filename=" + "result.pdf");
+
+        String pdfUrl = rate.getPdfUrl();
+        File file = new File(pdfUrl);
+
+        // 以流的形式下载文件。
+        InputStream fis = new BufferedInputStream(new FileInputStream(file));
+        byte[] buffer = new byte[fis.available()];
+
+        fis.read(buffer);
+        fis.close();
+        return buffer;
+
+//        OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
+//        toClient.write(buffer);
+//        toClient.flush();
+//        toClient.close();
+
+    }
+
+    /**
+     * 合并pdf
+     *
+     * @param rate
+     * @throws IOException
+     */
+    public void mergePdf(Rate rate) throws IOException {
+        List<InputStream> files = this.upLoad1(rate);
+
+        String targetPath = "/Users/qiufangchao/Desktop/rate/material" + rate.getId() + ".pdf";
+        // pdf合并工具类
+        PDFMergerUtility mergePdf = new PDFMergerUtility();
+
+        mergePdf.addSources(files);
+        // 设置合并生成pdf文件名称
+        mergePdf.setDestinationFileName(targetPath);
+        try {
+            mergePdf.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
+            for (InputStream is : files) {
+                is.close();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 选专家发消息
+     *
+     * @param rate
+     * @return
+     */
     public Map<String, String> reviewTimesMessage(Rate rate) {
         List<Long> ids = new ArrayList<>(rate.getExpertMemberUserId());
         ids.add(rate.getExpertUserId());

+ 3 - 2
src/main/java/com/izouma/wenlvju/web/RateController.java

@@ -137,12 +137,13 @@ public class RateController extends BaseController {
     }
 
     @GetMapping(value = "/exportPdf/{id}", produces = "application/pdf;charset=utf-8")
-    public void exportPdf(@PathVariable Long id, HttpServletResponse response) {
+    public byte[] exportPdf(@PathVariable Long id, HttpServletResponse response) {
         try {
-            rateService.exportPdf(id, response);
+            return rateService.exportPdf(id, response);
         } catch (IOException e) {
             e.printStackTrace();
         }
+        return null;
     }
 
     @OperLog(value = "等级评定", type = "修改", desc = "对等级评定申请进行操作")

+ 1 - 1
src/main/resources/application.yaml

@@ -14,7 +14,7 @@ spring:
     profiles:
         active: dev
     datasource:
-        url: jdbc:mysql://mysql.izouma.com/exam_test?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8
+        url: jdbc:mysql://mysql.izouma.com/exam?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8
         username: microball
         password: 2wsx@WSX#EDC
         hikari:

File diff suppressed because it is too large
+ 0 - 0
src/main/resources/templates/RateTemplate.ftl


+ 1 - 0
src/main/vue/package.json

@@ -31,6 +31,7 @@
     "vue-avatar-cropper": "^1.0.5",
     "vue-axios": "^2.1.5",
     "vue-chartjs": "^3.5.0",
+    "vue-clipboard2": "^0.3.3",
     "vue-grid-layout": "^2.3.7",
     "vue-i18n": "^8.18.2",
     "vue-router": "^3.3.4",

+ 2 - 0
src/main/vue/src/main.js

@@ -18,6 +18,7 @@ import DistrictSelect from '@/components/DistrictSelect';
 import Formatters from '@/mixins/formatters';
 import 'normalize.css/normalize.css';
 import 'element-ui/lib/theme-chalk/index.css';
+import VueClipboard from 'vue-clipboard2';
 // 修改 el-dialog 默认点击遮照为不关闭
 ElementUI.Dialog.props.closeOnClickModal.default = false;
 
@@ -46,6 +47,7 @@ Vue.config.productionTip = false;
 Vue.use(ElementUI, { size: 'small' });
 Vue.use(http);
 Vue.use(dataExport);
+Vue.use(VueClipboard);
 Vue.component('sortable-header', SortableHeader);
 Vue.component('multi-upload', MultiUpload);
 Vue.component('single-upload', SingleUpload);

+ 5 - 1
src/main/vue/src/views/TrainingInstitutionEdit.vue

@@ -7,7 +7,7 @@
             label-width="178px"
             label-position="right"
             size="small"
-            style="max-width: 500px;"
+            style="max-width: 700px;"
         >
             <el-form-item prop="name" label="企业名称">
                 <el-input v-model="formData.name"></el-input>
@@ -89,6 +89,10 @@
             </el-form-item>
             <el-form-item prop="examPoint" label="是否是艺术水平考级考点">
                 <!-- <el-input v-model="formData.examPoint"></el-input> -->
+                <el-radio-group v-model="formData.examPoint">
+                    <el-radio :label="true">是</el-radio>
+                    <el-radio :label="false">否</el-radio>
+                </el-radio-group>
             </el-form-item>
             <el-form-item prop="gradingOrganization" label="艺术水平考级机构名称">
                 <el-input v-model="formData.gradingOrganization"></el-input>

+ 4 - 1
src/main/vue/src/views/TrainingInstitutionList.vue

@@ -133,7 +133,10 @@ export default {
     },
     methods: {
         beforeGetData() {
-            return { search: this.search };
+            return {
+                search: this.search,
+                sort: 'firstWrite,desc'
+            };
         },
         toggleMultipleMode(multipleMode) {
             this.multipleMode = multipleMode;

+ 49 - 6
src/main/vue/src/views/rate/RateOrganizerList.vue

@@ -49,7 +49,7 @@
                     <span v-else><el-tag type="info">暂无</el-tag></span>
                 </template>
             </el-table-column>
-            <el-table-column label="操作" align="center" fixed="right" min-width="150">
+            <el-table-column label="操作" align="center" fixed="right" min-width="160">
                 <template slot-scope="{ row }">
                     <el-button @click="editRow(row)" type="primary" size="mini" plain>
                         <span v-if="row.status == 'FIRST_REVIEW_DENY' || !row.submit">编辑资料</span>
@@ -65,7 +65,7 @@
                         >撤回
                     </el-button>
                     <el-button
-                        @click="word(row)"
+                        @click="aletrLog(row)"
                         type="primary"
                         :loading="downloading"
                         size="mini"
@@ -98,6 +98,22 @@
             >
             </el-pagination>
         </div>
+        <el-dialog title="提示信息" width="500px" :visible.sync="dialogVisible" center>
+            <div>
+                <span class="content"
+                    >下载文件需要合并所有上传的信息,并转成pdf,可能会比较大。如遇无法下载,可试以下方法:</span
+                ><br />
+                <span class="content">1.点击复制链接按钮,复制下载地址用任何其他方式下载;</span><br />
+                <span class="content">2.刷新页面,查看网络是否流畅;</span><br />
+                <span class="content">3.更换最新的谷歌(chrome)浏览器,再点击下载文件;</span><br />
+                <span class="content">4.如还是长时间没有反应,可联系技术支持微信:PrettyFairyLi;</span><br />
+                <span class="content">链接地址:{{ rate.pdfUrl }}</span>
+            </div>
+            <div style="float: right; padding: 10px;">
+                <el-button size="mini" @click="copy">复制链接</el-button>
+                <el-button @click="word()" type="primary" size="mini">继续下载</el-button>
+            </div>
+        </el-dialog>
     </div>
 </template>
 <script>
@@ -114,7 +130,9 @@ export default {
             search: '',
             url: '/rate/all',
             downloading: false,
-            canApply: false
+            canApply: false,
+            dialogVisible: false,
+            rate: {}
         };
     },
     created() {
@@ -214,10 +232,15 @@ export default {
                     }
                 });
         },
-        word(row) {
+        aletrLog(row) {
+            this.rate = row;
+            this.dialogVisible = true;
+        },
+        word() {
             this.downloading = true;
+            console.log(this.rate);
             this.$axios
-                .get('/rate/exportPdf/' + row.id, { responseType: 'blob' })
+                .get('/rate/exportPdf/' + this.rate.id, { responseType: 'blob' })
                 .then(res => {
                     console.log(res);
                     this.downloading = false;
@@ -233,6 +256,8 @@ export default {
                     console.log(e);
                     this.downloading = false;
                     this.$message.error(e.error);
+                    this.rate = {};
+                    this.dialogVisible = false;
                 });
             // this.$axios
             //     .get('/rate/export/' + row.id)
@@ -272,8 +297,26 @@ export default {
                         this.$message.error((e || {}).error || '撤回失败');
                     }
                 });
+        },
+        copy() {
+            this.$copyText(this.rate.pdfUrl).then(
+                e => {
+                    this.$message.success('复制成功');
+                },
+                e => {
+                    this.$message.warning('复制失败');
+                }
+            );
         }
     }
 };
 </script>
-<style lang="less" scoped></style>
+<style lang="less" scoped>
+.content {
+    font-size: 14px;
+    line-height: 25px;
+}
+/deep/ .el-dialog {
+    height: 330px;
+}
+</style>

+ 16 - 0
src/main/vue/yarn.lock

@@ -2349,6 +2349,15 @@ cli-width@^2.0.0:
   resolved "https://registry.npm.taobao.org/cli-width/download/cli-width-2.2.1.tgz#b0433d0b4e9c847ef18868a4ef16fd5fc8271c48"
   integrity sha1-sEM9C06chH7xiGik7xb9X8gnHEg=
 
+clipboard@^2.0.0:
+  version "2.0.8"
+  resolved "https://registry.yarnpkg.com/clipboard/-/clipboard-2.0.8.tgz#ffc6c103dd2967a83005f3f61976aa4655a4cdba"
+  integrity sha512-Y6WO0unAIQp5bLmk1zdThRhgJt/x3ks6f30s3oE3H1mgIEU33XyQjEf8gsf6DxC7NPX8Y1SsNWjUjL/ywLnnbQ==
+  dependencies:
+    good-listener "^1.2.2"
+    select "^1.1.2"
+    tiny-emitter "^2.0.0"
+
 clipboard@^2.0.6:
   version "2.0.6"
   resolved "https://registry.npm.taobao.org/clipboard/download/clipboard-2.0.6.tgz#52921296eec0fdf77ead1749421b21c968647376"
@@ -8379,6 +8388,13 @@ vue-cli-plugin-style-resources-loader@^0.1.4:
   resolved "https://registry.npm.taobao.org/vue-cli-plugin-style-resources-loader/download/vue-cli-plugin-style-resources-loader-0.1.4.tgz#6087a86132ea8125aa89e5f8e0a978fbc8cf6f59"
   integrity sha1-YIeoYTLqgSWqieX44Kl4+8jPb1k=
 
+vue-clipboard2@^0.3.3:
+  version "0.3.3"
+  resolved "https://registry.yarnpkg.com/vue-clipboard2/-/vue-clipboard2-0.3.3.tgz#331fec85f9d4f175eb0d4feaef4d77338562af36"
+  integrity sha512-aNWXIL2DKgJyY/1OOeITwAQz1fHaCIGvUFHf9h8UcoQBG5a74MkdhS/xqoYe7DNZdQmZRL+TAdIbtUs9OyVjbw==
+  dependencies:
+    clipboard "^2.0.0"
+
 vue-eslint-parser@^7.0.0:
   version "7.1.0"
   resolved "https://registry.npm.taobao.org/vue-eslint-parser/download/vue-eslint-parser-7.1.0.tgz?cache=0&sync_timestamp=1589539313907&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvue-eslint-parser%2Fdownload%2Fvue-eslint-parser-7.1.0.tgz#9cdbcc823e656b087507a1911732b867ac101e83"

+ 60 - 28
src/test/java/com/izouma/wenlvju/service/RateServiceTest.java

@@ -4,6 +4,7 @@ package com.izouma.wenlvju.service;
 import com.github.kevinsawicki.http.HttpRequest;
 import com.izouma.wenlvju.ApplicationTests;
 import com.izouma.wenlvju.domain.Rate;
+import com.izouma.wenlvju.enums.RateStatus;
 import com.izouma.wenlvju.exception.BusinessException;
 import com.izouma.wenlvju.repo.RateRepo;
 import com.lowagie.text.Document;
@@ -33,32 +34,44 @@ public class RateServiceTest extends ApplicationTests {
     }
 
     @Test
-    public void test2() throws UnsupportedEncodingException {
+    public void test2() {
 
-        Rate rate = rateRepo.findById(625L).orElseThrow(new BusinessException("无记录"));
-        List<InputStream> files = rateService.upLoad1(rate);
+//        Rate rate = rateRepo.findById(11825L).orElseThrow(new BusinessException("无记录"));
+        List<Rate> rates = rateRepo.findAllByStatusAndYearOrderByScoreDesc(RateStatus.COLLECT_PAPER_MATERIALS, "2021");
+        rates.forEach(rate -> {
 
-        String targetPath = "/Users/qiufangchao/Desktop/result.pdf";
-        // pdf合并工具类
-        PDFMergerUtility mergePdf = new PDFMergerUtility();
-//        for (File f : files) {
-//            if (f.exists() && f.isFile()) {
-        // 循环添加要合并的pdf
-//                mergePdf.addSource(f);
-//            }
-//        }
-        mergePdf.addSources(files);
-        // 设置合并生成pdf文件名称
-        mergePdf.setDestinationFileName(targetPath);
-        // 合并pdf
-        try {
-            mergePdf.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
-            for (InputStream is : files) {
-                is.close();
+            List<InputStream> files = null;
+            try {
+                files = rateService.upLoad1(rate);
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
             }
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
+
+            String targetPath = "/Users/qiufangchao/Desktop/rate/material" + rate.getId() + ".pdf";
+//            if (!new File(targetPath).exists()) {
+            // pdf合并工具类
+            PDFMergerUtility mergePdf = new PDFMergerUtility();
+            //for (File f : files) {
+            //      if (f.exists() && f.isFile()) {
+            // 循环添加要合并的pdf
+            //           mergePdf.addSource(f);
+            //      }
+            // }
+            mergePdf.addSources(files);
+            // 设置合并生成pdf文件名称
+            mergePdf.setDestinationFileName(targetPath);
+            // 合并pdf
+            try {
+                mergePdf.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
+                for (InputStream is : files) {
+                    is.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+//            }
+        });
+
 //        System.out.println(writer.toString());
 //        new File(targetPath);
 
@@ -122,9 +135,6 @@ public class RateServiceTest extends ApplicationTests {
 
     @Test
     public void test8() {
-
-//        String img = "https://ticket-exchange.oss-cn-hangzhou.aliyuncs.com/image/2021-04-29-12-39-59rzhrQYhu.jpg";
-
         Rate rate = rateRepo.findById(625L).orElseThrow(new BusinessException("wu"));
         List<String> imageUrllist = rate.getBusiness();
 
@@ -165,9 +175,31 @@ public class RateServiceTest extends ApplicationTests {
         System.out.println(rateService.reviewTimesMessage(rate));
     }
 
-
     @Test
     public void test10() {
-        System.out.println(rateRepo.countByExpertId(700l));
+        System.out.println(rateRepo.countByExpertId(700L));
     }
+
+    @Test
+    public void test11() {
+        Rate rate = rateRepo.findById(11825L).orElseThrow(new BusinessException("无记录"));
+        try {
+            rateService.mergePdf(rate);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    @Test
+    public void test12() {
+        List<Rate> rates = rateRepo.findAllByStatusAndYearOrderByScoreDesc(RateStatus.SUBMIT_PAPER_MATERIALS, "2021");
+        rates.forEach(rate -> {
+            String url = "/Users/qiufangchao/Desktop/rate/material" + rate.getId() + ".pdf";
+            rate.setPdfUrl(url);
+        });
+        rateRepo.saveAll(rates);
+
+    }
+
 }

Some files were not shown because too many files changed in this diff