licailing 4 年之前
父节点
当前提交
50ce8334d3

+ 5 - 1
pom.xml

@@ -283,7 +283,11 @@
             <artifactId>pdfbox</artifactId>
             <version>2.0.16</version>
         </dependency>
-
+        <dependency>
+            <groupId>com.lowagie</groupId>
+            <artifactId>itext</artifactId>
+            <version>2.1.7</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 1 - 0
src/main/java/com/izouma/wenlvju/enums/AuthorityName.java

@@ -7,6 +7,7 @@ public enum AuthorityName {
     ROLE_SUPERVISOR("监管员"),
     ROLE_ORGANIZER("承办单位"),
     ROLE_DISTRICT("区县单位"),
+    ROLE_DISTRICT_STAFF("各区人员"),
     ROLE_EXPERT("市政专家");
     private final String description;
 

+ 60 - 1
src/main/java/com/izouma/wenlvju/service/RateService.java

@@ -2,6 +2,7 @@ package com.izouma.wenlvju.service;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.poi.word.WordUtil;
 import com.github.kevinsawicki.http.HttpRequest;
 import com.izouma.wenlvju.config.DateConfig;
 import com.izouma.wenlvju.domain.*;
@@ -24,6 +25,7 @@ import org.apache.pdfbox.io.MemoryUsageSetting;
 import org.apache.pdfbox.multipdf.PDFMergerUtility;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
+import sun.misc.BASE64Encoder;
 
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
@@ -208,6 +210,12 @@ public class RateService {
             //Configuration 用于读取ftl文件
             Configuration configuration = new Configuration(new Version("2.3.0"));
 
+            //图片
+            if (CollUtil.isNotEmpty(rate.getBusiness())) {
+                String img = this.Image2Base64(rate.getBusiness().get(0));
+                dataMap.put("content", img);
+            }
+
             configuration.setDefaultEncoding("utf-8");
             configuration.setClassForTemplateLoading(this.getClass(), "/templates");//指定ftl所在目录,根据自己的改
             StringWriter writer = new StringWriter();
@@ -220,6 +228,57 @@ public class RateService {
         }
     }
 
+    public String Image2Base64(String imgUrl) {
+//            URL url = null;
+        InputStream is = HttpRequest.get(imgUrl).stream();
+        ByteArrayOutputStream outStream = null;
+//            HttpURLConnection httpUrl = null;
+        try {
+//                url = new URL(imgUrl);
+//                httpUrl = (HttpURLConnection) url.openConnection();
+//                httpUrl.connect();
+//                httpUrl.getInputStream();
+//                is = httpUrl.getInputStream();
+
+            outStream = new ByteArrayOutputStream();
+            //创建一个Buffer字符串
+            byte[] buffer = new byte[1024];
+            //每次读取的字符串长度,如果为-1,代表全部读取完毕
+            int len = 0;
+            //使用一个输入流从buffer里把数据读取出来
+            while ((len = is.read(buffer)) != -1) {
+                //用输出流往buffer里写入数据,中间参数代表从哪个位置开始读,len代表读取的长度
+                outStream.write(buffer, 0, len);
+            }
+            // 对字节数组Base64编码
+//            return new BASE64Encoder().encode(outStream.toByteArray());
+            BASE64Encoder encoder = new BASE64Encoder();
+            return encoder.encode(outStream.toByteArray()).replace("\n", "\r\n").replace("\r\r\n", "\r\n");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }  //下载
+        finally {
+            if (is != null) {
+                try {
+                    is.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            if (outStream != null) {
+                try {
+                    outStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+//                if (httpUrl != null) {
+//                    httpUrl.disconnect();
+//                }
+        }
+        return imgUrl;
+    }
+
     public List<File> upLoad(Rate rate) {
         List<File> files = new ArrayList<>();
         String uri = "http://192.168.50.238:8080/word2pdf";
@@ -462,7 +521,7 @@ public class RateService {
 
     public Map<String, String> applyMessage(String district, LocalDateTime time) {
         DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_TIME_FORMAT);
-        String phone = userRepo.findAllByDistrictAndAuthoritiesContainsAndDelFalse(district, Authority.get(AuthorityName.ROLE_DISTRICT))
+        String phone = userRepo.findAllByDistrictAndAuthoritiesContainsAndDelFalse(district, Authority.get(AuthorityName.ROLE_DISTRICT_STAFF))
                 .stream()
                 .map(User::getPhone)
                 .collect(Collectors.joining(","));

+ 12 - 0
src/main/java/com/izouma/wenlvju/web/UserController.java

@@ -152,4 +152,16 @@ public class UserController extends BaseController {
     public List<User> authority(@RequestParam String authorityName) {
         return userRepo.findAllByAuthoritiesContainsAndDelFalse(Authority.builder().name(authorityName).build());
     }
+
+    /**
+     * 判断密码
+     * @return true 密码为123456需要改密码
+     */
+    @ApiOperation("判断密码")
+    @PostMapping("/isEditPw")
+    public boolean isEditPw() {
+            User user = userRepo.findById(SecurityUtils.getAuthenticatedUser().getId()).orElseThrow(new BusinessException("无用户"));
+        return new BCryptPasswordEncoder().matches("123456", user.getPassword());
+    }
+
 }

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

@@ -12,7 +12,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:
@@ -95,5 +95,5 @@ spring:
 
 spring:
     profiles: prod
-    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
 

文件差异内容过多而无法显示
+ 2 - 0
src/main/resources/templates/Rate1.ftl


+ 8 - 3
src/main/vue/src/views/Login.vue

@@ -13,7 +13,8 @@
                         label="用户名"
                         :rules="{ required: true, message: '请输入用户名', trigger: 'blur' }"
                     >
-                        <el-input class="input-width" v-model="registerInfo.username" placeholder="用户名"> </el-input>
+                        <el-input class="input-width" v-model="registerInfo.username" placeholder="用户名(账号)">
+                        </el-input>
                     </el-form-item>
                     <el-form-item
                         prop="password"
@@ -39,12 +40,16 @@
                     <el-form-item
                         prop="organizationName"
                         label="承办单位名称"
-                        :rules="{ required: true, message: '请输入承办单位名称', trigger: 'blur' }"
+                        :rules="{
+                            required: true,
+                            message: '请填营业执照或组织机构代码证上的名称、全称',
+                            trigger: 'blur'
+                        }"
                     >
                         <el-input
                             class="input-width"
                             v-model="registerInfo.organizationName"
-                            placeholder="承办单位名称"
+                            placeholder="营业执照或组织机构代码证上的名称、全称"
                         >
                         </el-input>
                     </el-form-item>

+ 6 - 5
src/main/vue/src/views/user/UserEdit.vue

@@ -150,11 +150,12 @@ export default {
                 .then(res => {
                     this.$message.success('成功');
                     this.formData = res;
-                    this.$router.replace({
-                        query: {
-                            id: res.id
-                        }
-                    });
+                    // this.$router.replace({
+                    //     query: {
+                    //         id: res.id
+                    //     }
+                    // });
+                    this.$router.go(-1);
                 })
                 .catch(e => {
                     console.log(e);

+ 7 - 0
src/test/java/com/izouma/wenlvju/repo/UserRepoTest.java

@@ -2,6 +2,7 @@ package com.izouma.wenlvju.repo;
 
 import com.izouma.wenlvju.domain.User;
 import com.izouma.wenlvju.enums.AuthorityName;
+import com.izouma.wenlvju.exception.BusinessException;
 import com.izouma.wenlvju.security.Authority;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -60,4 +61,10 @@ public class UserRepoTest {
             userRepo.save(user);
         });
     }
+
+    @Test
+    public void test2() {
+        User user = userRepo.findById(1L).orElseThrow(new BusinessException("无用户"));
+        System.out.println(new BCryptPasswordEncoder().matches("123456", user.getPassword()));
+    }
 }

+ 54 - 1
src/test/java/com/izouma/wenlvju/service/RateServiceTest.java

@@ -11,11 +11,11 @@ import org.apache.pdfbox.multipdf.PDFMergerUtility;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.awt.*;
 import java.io.*;
 import java.time.LocalDateTime;
 import java.util.List;
 
-
 public class RateServiceTest extends ApplicationTests {
     @Autowired
     private RateService rateService;
@@ -104,4 +104,57 @@ public class RateServiceTest extends ApplicationTests {
                 .getName()));
     }
 
+    @Test
+    public void test7() throws IOException {
+        Rate rate = rateRepo.findById(625L).orElse(null);
+        String export = rateService.export(rate);
+        InputStream is = new ByteArrayInputStream(export.getBytes());
+
+        int index;
+        byte[] bytes = new byte[1024];
+        FileOutputStream downloadFile = new FileOutputStream("/Users/qiufangchao/Desktop/123.doc");
+        while ((index = is.read(bytes)) != -1) {
+            downloadFile.write(bytes, 0, index);
+            downloadFile.flush();
+        }
+        downloadFile.close();
+        is.close();
+    }
+
+    @Test
+    public void test8() {
+//        String TAG = "PdfManager";
+//        Document doc = new Document(PageSize.A4, 20, 20, 20, 20);
+//        try {
+//            PdfWriter.getInstance(doc, new FileOutputStream(mOutputPdfFileName));
+//            doc.open();
+//            for (int i = 0; i < imageUrllist.size(); i++) {
+//                doc.newPage();
+////                doc.add(new Paragraph("简单使用iText"));
+//                Image png1 = Image.getInstance(imageUrllist.get(i));
+//                float heigth = png1.getHeight();
+//                float width = png1.getWidth();
+//                int percent = getPercent2(heigth, width);
+//                png1.setAlignment(Image.MIDDLE);
+//                png1.scalePercent(percent+3);// 表示是原来图像的比例;
+//                doc.add(png1);
+//            }
+//
+//        } catch (FileNotFoundException e) {
+//            e.printStackTrace();
+//        } catch (DocumentException e) {
+//            e.printStackTrace();
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }finally {
+//            doc.close();
+//
+//        }
+//        File mOutputPdfFile = new File(mOutputPdfFileName);
+//        if (!mOutputPdfFile.exists()) {
+//            mOutputPdfFile.deleteOnExit();
+//            return null;
+//        }
+    }
+
 }

+ 0 - 3
src/test/java/com/izouma/wenlvju/web/RateControllerTest.java

@@ -8,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 
 import java.io.File;
 import java.io.InputStream;
-import java.time.LocalDateTime;
 
 public class RateControllerTest extends ApplicationTests {
     @Autowired
@@ -25,7 +24,6 @@ public class RateControllerTest extends ApplicationTests {
     }
 
 
-
     @Test
     public void test3() {
         String uri = "http://192.168.50.238:8080/word2pdf";
@@ -61,5 +59,4 @@ public class RateControllerTest extends ApplicationTests {
                 .part("file", "审核材料.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", is)
                 .receive(new File("/Users/qiufangchao/Desktop/审核材料1.pdf"));
     }
-
 }

部分文件因为文件数量过多而无法显示