Commit 4716fae170fa719733d7c4345e3a17cce437617c

Authored by 陶汉栋
1 parent 97289310
Exists in master

1、增加网关负载lb指向

2、文件服务增加21世纪文档生成接口
cloud/autho/src/main/java/com/sincere/autho/mapper/UserMapper.java
... ... @@ -7,4 +7,6 @@ public interface UserMapper {
7 7 String loginTeacher(LoginReqDto loginReqDto) ;
8 8  
9 9 String loginStudent(LoginReqDto loginReqDto) ;
  10 +
  11 + String loginStudentOthName(LoginReqDto loginReqDto);
10 12 }
... ...
cloud/autho/src/main/java/com/sincere/autho/service/impl/LoginServiceImpl.java
... ... @@ -5,6 +5,7 @@ import com.sincere.autho.mapper.UserMapper;
5 5 import com.sincere.autho.service.LoginService;
6 6 import org.springframework.beans.factory.annotation.Autowired;
7 7 import org.springframework.stereotype.Service;
  8 +import org.springframework.util.StringUtils;
8 9  
9 10 @Service
10 11 public class LoginServiceImpl implements LoginService {
... ... @@ -17,6 +18,9 @@ public class LoginServiceImpl implements LoginService {
17 18 String userId = "" ;
18 19 if(loginReqDto.getUserType() == 2){
19 20 userId = userMapper.loginStudent(loginReqDto);
  21 + if (StringUtils.isEmpty(userId)){//用othername登录
  22 + userId = userMapper.loginStudentOthName(loginReqDto);
  23 + }
20 24 }else {
21 25 userId = userMapper.loginTeacher(loginReqDto);
22 26 }
... ...
cloud/autho/src/main/resources/application.yaml
... ... @@ -19,7 +19,7 @@ ribbon:
19 19 ConnectTimeout: 5000
20 20 eureka:
21 21 instance:
22   - hostname: localhost
  22 + hostname: 121.40.30.78
23 23 lease-expiration-duration-in-seconds: 60
24 24 lease-renewal-interval-in-seconds: 10
25 25 client:
... ...
cloud/autho/src/main/resources/mapper/UserMapper.xml
... ... @@ -11,4 +11,8 @@
11 11 select user_id from SZ_User where name = #{account} and pass = #{password}
12 12 </select>
13 13  
  14 + <select id="loginStudentOthName" parameterType="com.sincere.autho.dto.req.LoginReqDto" resultType="java.lang.String">
  15 + select user_id from SZ_User where othername = #{account} and pass = #{password}
  16 + </select>
  17 +
14 18 </mapper>
... ...
cloud/fIle-center/pom.xml
... ... @@ -43,6 +43,18 @@
43 43 <version>2.8.3</version>
44 44 </dependency>
45 45  
  46 + <dependency>
  47 + <groupId>org.apache.poi</groupId>
  48 + <artifactId>poi</artifactId>
  49 + <version>4.1.2</version>
  50 + </dependency>
  51 +
  52 + <dependency>
  53 + <groupId>org.apache.poi</groupId>
  54 + <artifactId>poi-ooxml</artifactId>
  55 + <version>4.1.2</version>
  56 + </dependency>
  57 +
46 58 </dependencies>
47 59 <!-- 形成带第三方jar包的可执行jar包,jar包目录结构如下 application.properties lib META-INF mybatis
48 60 org -->
... ...
cloud/fIle-center/src/main/java/com/sincere/file/control/FileControl.java
1 1 package com.sincere.file.control;
2 2  
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONArray;
  5 +import com.alibaba.fastjson.JSONObject;
  6 +import com.alibaba.fastjson.serializer.SerializerFeature;
  7 +import com.alibaba.fastjson.serializer.ValueFilter;
3 8 import com.sincere.file.model.FileInfo;
  9 +import com.sincere.file.model.question.QuestionDataModel;
4 10 import com.sincere.file.service.FileService;
5 11 import com.sincere.file.utils.FileUtil;
  12 +import com.sincere.file.utils.PoiUtils;
6 13 import io.swagger.annotations.Api;
  14 +import io.swagger.annotations.ApiImplicitParam;
  15 +import io.swagger.annotations.ApiImplicitParams;
7 16 import io.swagger.annotations.ApiOperation;
  17 +import org.apache.poi.xwpf.usermodel.Document;
  18 +import org.slf4j.Logger;
  19 +import org.slf4j.LoggerFactory;
8 20 import org.springframework.beans.factory.annotation.Autowired;
  21 +import org.springframework.boot.configurationprocessor.json.JSONException;
  22 +import org.springframework.util.StringUtils;
9 23 import org.springframework.web.bind.annotation.*;
  24 +import org.springframework.web.client.RestTemplate;
10 25 import org.springframework.web.multipart.MultipartFile;
11 26  
12 27 import javax.servlet.http.HttpServletRequest;
  28 +import java.io.File;
  29 +import java.text.SimpleDateFormat;
  30 +import java.util.ArrayList;
  31 +import java.util.Date;
  32 +import java.util.HashMap;
  33 +import java.util.List;
13 34  
14 35 @RestController
15 36 @Api(tags = "文件管理")
16 37 @RequestMapping(value = "file/*")
17 38 public class FileControl {
18 39  
  40 + Logger logger = LoggerFactory.getLogger(FileControl.class);
  41 +
19 42 @Autowired
20 43 FileService fileService;
21 44  
... ... @@ -31,27 +54,45 @@ public class FileControl {
31 54  
32 55 }
33 56  
34   - @PostMapping("fileUpload1")
35   - @ApiOperation("上传文件")
36   - public String fileUpload1(@RequestParam("file") MultipartFile file) throws Exception {
37   -
38   -// String ossPath = request.getHeader("ossPath");//oss的二级目录
39   -//
40   -// FileInfo fileInfo = fileService.upload(file, ossPath);
  57 + @DeleteMapping("deleteFile/{fileName}")
  58 + @ApiOperation("删除文件")
  59 + public boolean deleteFile(@PathVariable String fileName, HttpServletRequest request) {
  60 + String ossPath = request.getHeader("ossPath");//oss的二级目录
  61 + fileService.delete(fileName, ossPath);
41 62  
42   - return "111";
  63 + System.out.println("fileName:" + fileName + "----ossPath:" + ossPath);
43 64  
  65 + return true;
44 66 }
45 67  
46 68  
47   - @DeleteMapping("deleteFile/{fileName}")
48   - @ApiOperation("删除文件")
49   - public boolean deleteFile(@PathVariable String fileName,HttpServletRequest request){
50   - String ossPath = request.getHeader("ossPath");//oss的二级目录
51   - fileService.delete(fileName,ossPath);
  69 + @RequestMapping(value = "getWord", method = RequestMethod.GET)
  70 + @ApiOperation("获取21世纪题目")
  71 + @ApiImplicitParams(
  72 + {@ApiImplicitParam(name = "url",value = "链接")}
  73 +
  74 + )
  75 + public String getWord(@RequestParam("url") String url) {
  76 +
  77 + RestTemplate restTemplate = new RestTemplate();
  78 +
  79 + String content = restTemplate.getForObject(url, String.class, new HashMap<>());
  80 +
  81 +// logger.error("json:{}", content);
  82 +
  83 + JSONObject jsonObject = JSON.parseObject(content);
  84 + JSONObject data = jsonObject.getJSONObject("data");
  85 + JSONArray questions = data.getJSONArray("questions");
  86 + String wordPath = PoiUtils.createWord(questions);
  87 +
  88 +// QuestionDataModel questionDataModel = JSON.parseObject(content, QuestionDataModel.class);
  89 +
  90 +// logger.error("questionDataModel:{}", questionDataModel);
  91 +
  92 + return fileService.uploadLocalFile(new File(wordPath), "test");
52 93  
53   - System.out.println("fileName:"+fileName+"----ossPath:"+ossPath);
54 94  
55   - return true;
56 95 }
  96 +
  97 +
57 98 }
... ...
cloud/fIle-center/src/main/java/com/sincere/file/model/question/OptionsModel.java 0 → 100644
... ... @@ -0,0 +1,56 @@
  1 +package com.sincere.file.model.question;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +public class OptionsModel implements Serializable {
  6 +
  7 + private String A;
  8 +
  9 + private String B;
  10 +
  11 + private String C;
  12 +
  13 + private String D;
  14 +
  15 + public String getA() {
  16 + return A;
  17 + }
  18 +
  19 + public void setA(String a) {
  20 + A = a;
  21 + }
  22 +
  23 + public String getB() {
  24 + return B;
  25 + }
  26 +
  27 + public void setB(String b) {
  28 + B = b;
  29 + }
  30 +
  31 + public String getC() {
  32 + return C;
  33 + }
  34 +
  35 + public void setC(String c) {
  36 + C = c;
  37 + }
  38 +
  39 + public String getD() {
  40 + return D;
  41 + }
  42 +
  43 + public void setD(String d) {
  44 + D = d;
  45 + }
  46 +
  47 + @Override
  48 + public String toString() {
  49 + return "OptionsModel{" +
  50 + "A='" + A + '\'' +
  51 + ", B='" + B + '\'' +
  52 + ", C='" + C + '\'' +
  53 + ", D='" + D + '\'' +
  54 + '}';
  55 + }
  56 +}
... ...
cloud/fIle-center/src/main/java/com/sincere/file/model/question/QuestionDataModel.java 0 → 100644
... ... @@ -0,0 +1,50 @@
  1 +package com.sincere.file.model.question;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.List;
  5 +
  6 +public class QuestionDataModel implements Serializable {
  7 +
  8 + private int code;
  9 +
  10 + private String msg;
  11 +
  12 + private Questions data;
  13 +
  14 + public int getCode() {
  15 + return code;
  16 + }
  17 +
  18 + public void setCode(int code) {
  19 + this.code = code;
  20 + }
  21 +
  22 + public String isMsg() {
  23 + return msg;
  24 + }
  25 +
  26 + public void setMsg(String msg) {
  27 + this.msg = msg;
  28 + }
  29 +
  30 + public String getMsg() {
  31 + return msg;
  32 + }
  33 +
  34 + public Questions getData() {
  35 + return data;
  36 + }
  37 +
  38 + public void setData(Questions data) {
  39 + this.data = data;
  40 + }
  41 +
  42 + @Override
  43 + public String toString() {
  44 + return "QuestionDataModel{" +
  45 + "code=" + code +
  46 + ", msg=" + msg +
  47 + ", data=" + data +
  48 + '}';
  49 + }
  50 +}
... ...
cloud/fIle-center/src/main/java/com/sincere/file/model/question/QuestionModel.java 0 → 100644
... ... @@ -0,0 +1,47 @@
  1 +package com.sincere.file.model.question;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +public class QuestionModel implements Serializable {
  6 +
  7 +
  8 + private String channel_type_name;
  9 +
  10 + private String question_text;
  11 +
  12 + private OptionsModel options;
  13 +
  14 +
  15 + public String getChannel_type_name() {
  16 + return channel_type_name;
  17 + }
  18 +
  19 + public void setChannel_type_name(String channel_type_name) {
  20 + this.channel_type_name = channel_type_name;
  21 + }
  22 +
  23 + public String getQuestion_text() {
  24 + return question_text;
  25 + }
  26 +
  27 + public void setQuestion_text(String question_text) {
  28 + this.question_text = question_text;
  29 + }
  30 +
  31 + public OptionsModel getOptionsModel() {
  32 + return options;
  33 + }
  34 +
  35 + public void setOptionsModel(OptionsModel optionsModel) {
  36 + this.options = optionsModel;
  37 + }
  38 +
  39 + @Override
  40 + public String toString() {
  41 + return "QuestionModel{" +
  42 + "channel_type_name='" + channel_type_name + '\'' +
  43 + ", question_text='" + question_text + '\'' +
  44 + ", options=" + options +
  45 + '}';
  46 + }
  47 +}
... ...
cloud/fIle-center/src/main/java/com/sincere/file/model/question/Questions.java 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +package com.sincere.file.model.question;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.List;
  5 +
  6 +public class Questions implements Serializable {
  7 +
  8 +
  9 + private List<QuestionModel> questions;
  10 +
  11 + public List<QuestionModel> getQuestions() {
  12 + return questions;
  13 + }
  14 +
  15 + public void setQuestions(List<QuestionModel> questions) {
  16 + this.questions = questions;
  17 + }
  18 +
  19 + @Override
  20 + public String toString() {
  21 + return "Questions{" +
  22 + "questions=" + questions +
  23 + '}';
  24 + }
  25 +}
... ...
cloud/fIle-center/src/main/java/com/sincere/file/service/FileService.java
... ... @@ -3,6 +3,7 @@ package com.sincere.file.service;
3 3 import com.sincere.file.model.FileInfo;
4 4 import org.springframework.web.multipart.MultipartFile;
5 5  
  6 +import java.io.File;
6 7 import java.util.Map;
7 8  
8 9 /**
... ... @@ -14,6 +15,8 @@ public interface FileService {
14 15  
15 16 FileInfo upload(MultipartFile file,String filePath) throws Exception;
16 17  
  18 + String uploadLocalFile(File file,String filePath);
  19 +
17 20 void delete(String fileName,String filePath);
18 21  
19 22 FileInfo getById(String id);
... ...
cloud/fIle-center/src/main/java/com/sincere/file/service/impl/AliyunOssServiceImpl.java
1 1 package com.sincere.file.service.impl;
2 2  
3 3 import com.aliyun.oss.OSSClient;
  4 +import com.aliyun.oss.model.PutObjectResult;
4 5 import com.sincere.file.model.FileInfo;
5 6 import org.springframework.beans.factory.annotation.Autowired;
6 7 import org.springframework.beans.factory.annotation.Value;
7 8 import org.springframework.stereotype.Service;
8 9 import org.springframework.web.multipart.MultipartFile;
9 10  
  11 +import java.io.File;
  12 +
10 13 /**
11 14 * @author 作者 owen E-mail: 624191343@qq.com
12 15 * @version 创建时间:2017年11月12日 上午22:57:51
... ... @@ -48,4 +51,10 @@ public class AliyunOssServiceImpl extends AbstractFileService {
48 51 return true;
49 52 }
50 53  
  54 + @Override
  55 + public String uploadLocalFile(File file, String filePath) {
  56 + PutObjectResult putObjectResult = ossClient.putObject(bucketName,filePath+"/"+file.getName(),file);
  57 + System.out.println("uploadLocalFile;"+putObjectResult.toString());
  58 + return domain+"/"+filePath+"/"+file.getName();
  59 + }
51 60 }
... ...
cloud/fIle-center/src/main/java/com/sincere/file/utils/HtmlUtil.java 0 → 100644
... ... @@ -0,0 +1,56 @@
  1 +package com.sincere.file.utils;
  2 +
  3 +import java.util.regex.Matcher;
  4 +import java.util.regex.Pattern;
  5 +
  6 +public class HtmlUtil {
  7 + private static final String regEx_script = "]*?>[//s//S]*?"; // 定义script的正则表达式
  8 +
  9 + private static final String regEx_style = "]*?>[//s//S]*?"; // 定义style的正则表达式
  10 +
  11 + private static final String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式
  12 +
  13 + private static final String regEx_space = "//s*|/t|/r|/n";//定义空格回车换行符
  14 +
  15 +
  16 +
  17 + /**
  18 +
  19 + * @param htmlStr
  20 +
  21 + * @return
  22 +
  23 + * 删除Html标签
  24 +
  25 + */
  26 +
  27 + public static String delHTMLTag(String htmlStr) {
  28 +
  29 + Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
  30 +
  31 + Matcher m_script = p_script.matcher(htmlStr);
  32 +
  33 + htmlStr = m_script.replaceAll(""); // 过滤script标签
  34 +
  35 + Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
  36 +
  37 + Matcher m_style = p_style.matcher(htmlStr);
  38 +
  39 + htmlStr = m_style.replaceAll(""); // 过滤style标签
  40 +
  41 + Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
  42 +
  43 + Matcher m_html = p_html.matcher(htmlStr);
  44 +
  45 + htmlStr = m_html.replaceAll(""); // 过滤html标签
  46 +
  47 + Pattern p_space = Pattern.compile(regEx_space, Pattern.CASE_INSENSITIVE);
  48 +
  49 + Matcher m_space = p_space.matcher(htmlStr);
  50 +
  51 + htmlStr = m_space.replaceAll(""); // 过滤空格回车标签
  52 +
  53 + return htmlStr.trim(); // 返回文本字符串
  54 +
  55 + }
  56 +}
... ...
cloud/fIle-center/src/main/java/com/sincere/file/utils/PoiUtils.java 0 → 100644
... ... @@ -0,0 +1,243 @@
  1 +package com.sincere.file.utils;
  2 +
  3 +import com.alibaba.fastjson.JSONArray;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import org.apache.poi.ooxml.POIXMLTypeLoader;
  6 +import org.apache.poi.ooxml.util.DocumentHelper;
  7 +import org.apache.poi.util.IOUtils;
  8 +import org.apache.poi.xwpf.usermodel.*;
  9 +import org.apache.xmlbeans.XmlObject;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.xml.sax.InputSource;
  13 +
  14 +import javax.imageio.ImageIO;
  15 +import java.awt.image.BufferedImage;
  16 +import java.io.*;
  17 +import java.net.URL;
  18 +import java.net.URLConnection;
  19 +import java.util.HashSet;
  20 +import java.util.Iterator;
  21 +import java.util.Set;
  22 +import java.util.regex.Matcher;
  23 +import java.util.regex.Pattern;
  24 +
  25 +public class PoiUtils {
  26 +
  27 + static Logger logger = LoggerFactory.getLogger(PoiUtils.class);
  28 +
  29 + public static String createWord(JSONArray questions) {
  30 +
  31 + XWPFDocument doc = new XWPFDocument();//创建word文档
  32 +
  33 + for (int i = 0; i < questions.size(); i++) {
  34 + JSONObject question = questions.getJSONObject(i);
  35 + String question_text = question.getString("question_text");
  36 + String channel_type_name = question.getString("channel_type_name");
  37 + JSONObject options = question.getJSONObject("options");
  38 + XWPFParagraph p = doc.createParagraph();//新建一个段落
  39 +
  40 + p.setAlignment(ParagraphAlignment.LEFT);//设置对其方式
  41 +
  42 + if (channel_type_name.contains("img")){
  43 + getImg(channel_type_name,doc,p);
  44 + }else {
  45 + writeP(HtmlUtil.delHTMLTag(channel_type_name) + "\r\n",p);
  46 + }
  47 +
  48 + question_text=question_text.replaceAll("&nbsp;"," ");
  49 +
  50 + if (question_text.contains("img")){
  51 + writeP(question_text.replaceAll("<img[^>]*/>", " "), p);
  52 + getImg(question_text,doc,p);
  53 + }else {
  54 + writeP(HtmlUtil.delHTMLTag(question_text) + "\r\n", p);
  55 + }
  56 +
  57 + if (null != options) {
  58 + String A = options.getString("A");
  59 + if (A.contains("src")) {
  60 + writeP("A."+A.replaceAll("<img[^>]*/>", " "), p);
  61 + getImg(A, doc,p);
  62 + } else {
  63 + writeP( "A." + A+"\r\n", p);
  64 + }
  65 +
  66 + String B = options.getString("B");
  67 + if (B.contains("src")) {
  68 + writeP("B."+B.replaceAll("<img[^>]*/>", " "), p);
  69 + getImg(B, doc,p);
  70 + } else {
  71 + writeP("B." + B+"\r\n", p);
  72 + }
  73 +
  74 + String C = options.getString("C");
  75 + if (C.contains("src")) {
  76 + writeP("C."+C.replaceAll("<img[^>]*/>", " "), p);
  77 + getImg(C, doc,p);
  78 + } else {
  79 + writeP("C." + C+"\r\n", p);
  80 + }
  81 +
  82 + String D = options.getString("D");
  83 + if (D.contains("src")) {
  84 + writeP("D."+D.replaceAll("<img[^>]*/>", " "), p);
  85 + getImg(D, doc,p);
  86 + } else {
  87 + writeP("D." + D+"\r\n", p);
  88 + }
  89 + }
  90 + }
  91 +
  92 + try {
  93 + File file = new File("D://POI");
  94 + if (!file.exists()) file.mkdirs();
  95 + File file1 = new File(file.getAbsolutePath() + File.separator + System.currentTimeMillis()+".doc");
  96 + if (!file1.exists()) file1.createNewFile();
  97 + FileOutputStream out = new FileOutputStream(file1);
  98 + doc.write(out);
  99 + out.close();
  100 + return file1.getAbsolutePath();
  101 + } catch (FileNotFoundException e) {
  102 + e.printStackTrace();
  103 + } catch (IOException e) {
  104 + e.printStackTrace();
  105 + }
  106 +return "";
  107 + }
  108 +
  109 +
  110 + private static void writeP( String content, XWPFParagraph p) {
  111 +
  112 + XWPFRun r = p.createRun();//创建段落文本
  113 +
  114 + r.setFontSize(14);
  115 + r.setText(content);
  116 + r.setColor("000000");//设置颜色
  117 +
  118 + }
  119 +
  120 +
  121 + private static void getImg(String imgHtml, XWPFDocument doc,XWPFParagraph paragraph) {
  122 +// imgHtml = HtmlUtil.delHTMLTag(imgHtml);
  123 +// imgHtml = imgHtml.substring(imgHtml.indexOf("src="), imgHtml.indexOf("style"));
  124 +// imgHtml = imgHtml.replace("\"", "");
  125 +// imgHtml = imgHtml.replace("src=", "");
  126 +// logger.error("imgHtml:{}", imgHtml);
  127 + Set<String> imgSer = getImgStr(imgHtml);
  128 + Iterator<String> iterator = imgSer.iterator();
  129 + while (iterator.hasNext()){
  130 + String imgUrl = iterator.next();
  131 + String imgName = System.currentTimeMillis() + ".png";
  132 + String filePath = "D://POI//Img";
  133 + download(imgUrl, imgName, filePath);
  134 + writeImg2Word(filePath + File.separator + imgName, doc,paragraph);
  135 + }
  136 +
  137 + }
  138 +
  139 + private static String writeImg2Word(String s, XWPFDocument doc,XWPFParagraph paragraph) {
  140 +
  141 + try {
  142 +
  143 + XWPFRun run = paragraph.createRun();
  144 + // 获取图片
  145 + InputStream is = new FileInputStream(s);
  146 + byte[] bs = IOUtils.toByteArray(is);
  147 + BufferedImage image = ImageIO.read(new ByteArrayInputStream(bs));
  148 +
  149 + // 获取组装图片宽高,单位pt
  150 + StringBuffer dataSize = new StringBuffer();
  151 + dataSize.append("width:").append(image.getWidth()).append("pt;");
  152 + dataSize.append("height:").append(image.getHeight()).append("pt;");
  153 +
  154 + // 添加图片到Word中
  155 + String rid = doc.addPictureData(bs, Document.PICTURE_TYPE_PNG);
  156 +
  157 + StringBuffer xml = new StringBuffer();
  158 + xml.append("<w:pict xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"");
  159 + xml.append(" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\"");
  160 + xml.append(" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">");
  161 + xml.append(" <v:shape id=\"图片1").append("\" o:spid=\"\" type=\"\" alt=\"\" style=\"").append(dataSize).append("\">\r\n");
  162 + xml.append(" <v:imagedata r:id=\"").append(rid).append("\" o:title=\"\" />\r\n");
  163 + xml.append(" </v:shape>");
  164 + xml.append("</w:pict>\r\n");
  165 +
  166 + InputSource source = new InputSource(new StringReader(xml.toString()));
  167 +
  168 + org.w3c.dom.Document pictDoc = DocumentHelper.readDocument(source);
  169 + // 将信息写入run中
  170 + run.setEmbossed(true);
  171 + XmlObject xmlObject = XmlObject.Factory.parse(pictDoc.getDocumentElement(), POIXMLTypeLoader.DEFAULT_XML_OPTIONS);
  172 + run.getCTR().set(xmlObject);
  173 + run.setText("\r\n");
  174 +
  175 + } catch (Exception e) {
  176 + e.printStackTrace();
  177 + }
  178 +
  179 + return null;
  180 + }
  181 +
  182 + public static void download(String urlString, String filename, String savePath) {
  183 + try {
  184 +
  185 + // 构造URL
  186 + URL url = new URL(urlString);
  187 + // 打开连接
  188 + URLConnection con = url.openConnection();
  189 + //设置请求超时为5s
  190 + con.setConnectTimeout(5 * 1000);
  191 + // 输入流
  192 + InputStream is = con.getInputStream();
  193 +
  194 + // 1K的数据缓冲
  195 + byte[] bs = new byte[1024];
  196 + // 读取到的数据长度
  197 + int len;
  198 + // 输出的文件流
  199 + File sf = new File(savePath);
  200 + if (!sf.exists()) {
  201 + sf.mkdirs();
  202 + }
  203 + // 获取图片的扩展名
  204 + String extensionName = filename.substring(filename.lastIndexOf(".") + 1);
  205 + // 新的图片文件名 = 编号 +"."图片扩展名
  206 + OutputStream os = new FileOutputStream(sf.getPath() + "\\" + filename);
  207 + // 开始读取
  208 + while ((len = is.read(bs)) != -1) {
  209 + os.write(bs, 0, len);
  210 + }
  211 + // 完毕,关闭所有链接
  212 + os.close();
  213 + is.close();
  214 + } catch (Exception e) {
  215 + e.printStackTrace();
  216 + }
  217 + }
  218 +
  219 +
  220 + /**
  221 + * 得到网页中图片的地址
  222 + */
  223 + private static Set<String> getImgStr(String htmlStr) {
  224 + Set<String> pics = new HashSet<String>();
  225 + String img = "";
  226 + Pattern p_image;
  227 + Matcher m_image;
  228 + String regEx_img = "<img.*src\\s*=\\s*(.*?)[^>]*?>";
  229 + p_image = Pattern.compile(regEx_img, Pattern.CASE_INSENSITIVE);
  230 + m_image = p_image.matcher(htmlStr);
  231 + while (m_image.find()) {
  232 + // 得到<img />数据
  233 + img = m_image.group();
  234 + // 匹配<img>中的src数据
  235 + Matcher m = Pattern.compile("src\\s*=\\s*\"?(.*?)(\"|>|\\s+)").matcher(img);
  236 + while (m.find()) {
  237 + pics.add(m.group(1));
  238 + }
  239 + }
  240 + return pics;
  241 + }
  242 +
  243 +}
... ...
cloud/getaway/src/main/java/com/sincere/getaway/GetawayApplication.java
... ... @@ -2,6 +2,7 @@ package com.sincere.getaway;
2 2  
3 3 import org.springframework.boot.SpringApplication;
4 4 import org.springframework.cloud.client.SpringCloudApplication;
  5 +import org.springframework.cloud.client.loadbalancer.LoadBalanced;
5 6  
6 7 /**
7 8 * 统一网关配置
... ...
cloud/getaway/src/main/resources/application.yml
... ... @@ -28,28 +28,29 @@ spring:
28 28 filters:
29 29 - StripPrefix=1
30 30 - id: SmartCampusWebApi
31   - uri: http://120.26.116.253:9022
32   -# uri: lb://SmartCampusWebApi
  31 +# uri: http://120.26.116.253:9022
  32 + uri: lb://SmartCampusWebApi
33 33 predicates:
34 34 - Path=/SmartCampusWebApi/**
35 35 filters:
36 36 - StripPrefix=1
37 37 - id: file-center
38   -# uri: lb://file-center
39   - uri: http://121.40.30.78:5000
  38 + uri: lb://file-center
  39 +# uri: http://121.40.30.78:5000
40 40 predicates:
41 41 - Path=/file-center/**
42 42 filters:
43 43 - StripPrefix=1
44 44 - id: authserver
45   - uri: http://121.40.30.78:9005
46   -# uri: lb://authserver
  45 +# uri: http://121.40.30.78:9005
  46 + uri: lb://authserver
47 47 predicates:
48 48 - Path=/authserver/**
49 49 filters:
50 50 - StripPrefix=1
51 51 - id: NewSmartCampus
52   - uri: http://114.55.30.100:1111
  52 +# uri: http://114.55.30.100:1111
  53 + uri: lb://NewSmartCampus
53 54 predicates:
54 55 - Path=/NewSmartCampus/**
55 56 filters:
... ...