Commit 820f688d8bdbac13aada4bf60841d2a6fa2100cf
1 parent
e2822531
Exists in
master
网关
Showing
35 changed files
with
692 additions
and
909 deletions
Show diff stats
cloud/common/pom.xml
| ... | ... | @@ -22,6 +22,11 @@ |
| 22 | 22 | |
| 23 | 23 | <dependencies> |
| 24 | 24 | <dependency> |
| 25 | + <groupId>com.nimbusds</groupId> | |
| 26 | + <artifactId>nimbus-jose-jwt</artifactId> | |
| 27 | + <version>6.0</version> | |
| 28 | + </dependency> | |
| 29 | + <dependency> | |
| 25 | 30 | <groupId>redis.clients</groupId> |
| 26 | 31 | <artifactId>jedis</artifactId> |
| 27 | 32 | <version>2.9.0</version> |
| ... | ... | @@ -32,19 +37,11 @@ |
| 32 | 37 | <version>4.3</version> |
| 33 | 38 | </dependency> |
| 34 | 39 | <dependency> |
| 35 | - <groupId>org.apache.tomcat.embed</groupId> | |
| 36 | - <artifactId>tomcat-embed-core</artifactId> | |
| 37 | - </dependency> | |
| 38 | - <dependency> | |
| 39 | 40 | <groupId>io.jsonwebtoken</groupId> |
| 40 | 41 | <artifactId>jjwt</artifactId> |
| 41 | 42 | <version>0.9.0</version> |
| 42 | 43 | </dependency> |
| 43 | 44 | <dependency> |
| 44 | - <groupId>org.springframework.security</groupId> | |
| 45 | - <artifactId>spring-security-core</artifactId> | |
| 46 | - </dependency> | |
| 47 | - <dependency> | |
| 48 | 45 | <groupId>org.projectlombok</groupId> |
| 49 | 46 | <artifactId>lombok</artifactId> |
| 50 | 47 | </dependency> |
| ... | ... | @@ -56,12 +53,12 @@ |
| 56 | 53 | <dependency> |
| 57 | 54 | <groupId>io.springfox</groupId> |
| 58 | 55 | <artifactId>springfox-swagger2</artifactId> |
| 59 | - <version>2.5.0</version> | |
| 56 | + <version>2.9.2</version> | |
| 60 | 57 | </dependency> |
| 61 | 58 | <dependency> |
| 62 | 59 | <groupId>io.springfox</groupId> |
| 63 | 60 | <artifactId>springfox-swagger-ui</artifactId> |
| 64 | - <version>2.5.0</version> | |
| 61 | + <version>2.9.2</version> | |
| 65 | 62 | </dependency> |
| 66 | 63 | <dependency> |
| 67 | 64 | <groupId>commons-net</groupId> | ... | ... |
cloud/common/src/main/java/com/sincere/common/commons/PageResult.java
| ... | ... | @@ -1,30 +0,0 @@ |
| 1 | -package com.sincere.common.commons; | |
| 2 | - | |
| 3 | -import lombok.AllArgsConstructor; | |
| 4 | -import lombok.Builder; | |
| 5 | -import lombok.Data; | |
| 6 | -import lombok.NoArgsConstructor; | |
| 7 | - | |
| 8 | -import java.io.Serializable; | |
| 9 | -import java.util.List; | |
| 10 | - | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * @author 作者 owen E-mail: 624191343@qq.com | |
| 14 | - * @version 创建时间:2017年11月12日 上午22:57:51 | |
| 15 | - * 分页实体类 | |
| 16 | - * total 总数 | |
| 17 | - * code 是否成功 | |
| 18 | - * data 当前页结果集 | |
| 19 | - */ | |
| 20 | -@Data | |
| 21 | -@Builder | |
| 22 | -@NoArgsConstructor | |
| 23 | -@AllArgsConstructor | |
| 24 | -public class PageResult<T> implements Serializable { | |
| 25 | - | |
| 26 | - private static final long serialVersionUID = -275582248840137389L; | |
| 27 | - private Long count; | |
| 28 | - private int code; | |
| 29 | - private List<T> data; | |
| 30 | -} |
cloud/common/src/main/java/com/sincere/common/commons/Result.java
| ... | ... | @@ -1,49 +0,0 @@ |
| 1 | -//package com.sincere.common.commons; | |
| 2 | -// | |
| 3 | -//import lombok.AllArgsConstructor; | |
| 4 | -//import lombok.Data; | |
| 5 | -//import lombok.NoArgsConstructor; | |
| 6 | -// | |
| 7 | -//import java.io.Serializable; | |
| 8 | -// | |
| 9 | -///** | |
| 10 | -// * @Author: [zhangzhiguang] | |
| 11 | -// * @Date: [2018-08-01 23:39] | |
| 12 | -// * @Description: [ ] | |
| 13 | -// * @Version: [1.0.0] | |
| 14 | -// * @Copy: [com.zzg] | |
| 15 | -// */ | |
| 16 | -//@Data | |
| 17 | -//@NoArgsConstructor | |
| 18 | -//@AllArgsConstructor | |
| 19 | -//public class Result<T> implements Serializable { | |
| 20 | -// | |
| 21 | -// private T datas; | |
| 22 | -// private Integer resp_code; | |
| 23 | -// private String resp_msg; | |
| 24 | -// | |
| 25 | -// public static <T> Result<T> succeed(String msg) { | |
| 26 | -// return succeedWith(null, CodeEnum.SUCCESS.getCode(),msg); | |
| 27 | -// } | |
| 28 | -// | |
| 29 | -// public static <T> Result<T> succeed(T model, String msg) { | |
| 30 | -// return succeedWith(model, CodeEnum.SUCCESS.getCode(),msg); | |
| 31 | -// } | |
| 32 | -// | |
| 33 | -// public static <T> Result<T> succeedWith(T datas, Integer code,String msg) { | |
| 34 | -// return new Result<T>(datas, code, msg); | |
| 35 | -// } | |
| 36 | -// | |
| 37 | -// public static <T> Result<T> failed(String msg) { | |
| 38 | -// return failedWith(null, CodeEnum.ERROR.getCode(), msg); | |
| 39 | -// } | |
| 40 | -// | |
| 41 | -// public static <T> Result<T> failed(T model,String msg) { | |
| 42 | -// return failedWith(model, CodeEnum.ERROR.getCode(), msg); | |
| 43 | -// } | |
| 44 | -// | |
| 45 | -// public static <T> Result<T> failedWith(T datas, Integer code, String msg) { | |
| 46 | -// return new Result<T>( datas, code, msg); | |
| 47 | -// } | |
| 48 | -// | |
| 49 | -//} |
cloud/common/src/main/java/com/sincere/common/exception/ResultEnums.java
0 → 100644
| ... | ... | @@ -0,0 +1,43 @@ |
| 1 | +package com.sincere.common.exception; | |
| 2 | + | |
| 3 | +public enum ResultEnums { | |
| 4 | + success(0,"成功"), | |
| 5 | + not_avail(-1,"token无效"), | |
| 6 | + expire(-2,"token过期"), | |
| 7 | + account_null(-3,"账号为空"), | |
| 8 | + error(-4,"系统繁忙"), | |
| 9 | + no_token(-5,"没有传token"); | |
| 10 | + | |
| 11 | + private int code ; | |
| 12 | + private String message ; | |
| 13 | + | |
| 14 | + ResultEnums(int code, String message) { | |
| 15 | + this.code = code; | |
| 16 | + this.message = message; | |
| 17 | + } | |
| 18 | + | |
| 19 | + public int getCode() { | |
| 20 | + return code; | |
| 21 | + } | |
| 22 | + | |
| 23 | + public void setCode(int code) { | |
| 24 | + this.code = code; | |
| 25 | + } | |
| 26 | + | |
| 27 | + public String getMessage() { | |
| 28 | + return message; | |
| 29 | + } | |
| 30 | + | |
| 31 | + public void setMessage(String message) { | |
| 32 | + this.message = message; | |
| 33 | + } | |
| 34 | + | |
| 35 | + public static ResultEnums getByCode(int code){ | |
| 36 | + for(ResultEnums enums :ResultEnums.values()){ | |
| 37 | + if(enums.getCode() == code){ | |
| 38 | + return enums ; | |
| 39 | + } | |
| 40 | + } | |
| 41 | + return ResultEnums.error ; | |
| 42 | + } | |
| 43 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/props/PermitUrlProperties.java
| ... | ... | @@ -1,55 +0,0 @@ |
| 1 | -package com.sincere.common.props; | |
| 2 | - | |
| 3 | -import org.springframework.boot.context.properties.ConfigurationProperties; | |
| 4 | - | |
| 5 | -import java.util.ArrayList; | |
| 6 | -import java.util.List; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * @author 作者 owen E-mail: 624191343@qq.com | |
| 10 | - * @version 创建时间:2017年11月12日 上午22:57:51 url白名单处理 application.yml中配置需要放权的url白名单 | |
| 11 | - */ | |
| 12 | -// @ConfigurationProperties(prefix = "permit") | |
| 13 | -@ConfigurationProperties(prefix = "security.oauth2") | |
| 14 | -public class PermitUrlProperties { | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * 监控中心和swagger需要访问的url | |
| 18 | - */ | |
| 19 | - private static final String[] ENDPOINTS = { | |
| 20 | - "/**/actuator/**" , "/**/actuator/**/**" , //断点监控 | |
| 21 | - "/**/v2/api-docs/**", "/**/swagger-ui.html", "/**/swagger-resources/**", "/**/webjars/**", //swagger | |
| 22 | - "/**/turbine.stream","/**/turbine.stream**/**", "/**/hystrix", "/**/hystrix.stream", "/**/hystrix/**", "/**/hystrix/**/**", "/**/proxy.stream/**" , //熔断监控 | |
| 23 | - "/**/druid/**", "/**/favicon.ico", "/**/prometheus" | |
| 24 | - }; | |
| 25 | - | |
| 26 | - private String[] ignored; | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * 需要放开权限的url | |
| 30 | - * | |
| 31 | - * @param urls | |
| 32 | - * 自定义的url | |
| 33 | - * @return 自定义的url和监控中心需要访问的url集合 | |
| 34 | - */ | |
| 35 | - public String[] getIgnored() { | |
| 36 | - if (ignored == null || ignored.length == 0) { | |
| 37 | - return ENDPOINTS; | |
| 38 | - } | |
| 39 | - | |
| 40 | - List<String> list = new ArrayList<>(); | |
| 41 | - for (String url : ENDPOINTS) { | |
| 42 | - list.add(url); | |
| 43 | - } | |
| 44 | - for (String url : ignored) { | |
| 45 | - list.add(url); | |
| 46 | - } | |
| 47 | - | |
| 48 | - return list.toArray(new String[list.size()]); | |
| 49 | - } | |
| 50 | - | |
| 51 | - public void setIgnored(String[] ignored) { | |
| 52 | - this.ignored = ignored; | |
| 53 | - } | |
| 54 | - | |
| 55 | -} |
cloud/common/src/main/java/com/sincere/common/util/ExcelUtils.java
| 1 | -package com.sincere.common.util; | |
| 2 | - | |
| 3 | -import com.google.common.base.Strings; | |
| 4 | -import org.apache.commons.lang3.StringUtils; | |
| 5 | -import org.apache.poi.hssf.usermodel.HSSFCell; | |
| 6 | -import org.apache.poi.hssf.usermodel.HSSFRow; | |
| 7 | -import org.apache.poi.hssf.usermodel.HSSFSheet; | |
| 8 | -import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |
| 9 | - | |
| 10 | -import javax.servlet.http.HttpServletRequest; | |
| 11 | -import javax.servlet.http.HttpServletResponse; | |
| 12 | -import java.io.IOException; | |
| 13 | -import java.io.OutputStream; | |
| 14 | -import java.math.BigDecimal; | |
| 15 | -import java.util.List; | |
| 16 | -import java.util.Map; | |
| 17 | - | |
| 18 | -/** | |
| 19 | - * @author chen | |
| 20 | - * @version 1.0 | |
| 21 | - * @date 2019/10/16 0016 18:46 | |
| 22 | - */ | |
| 23 | -public class ExcelUtils { | |
| 24 | - | |
| 25 | - //各个列的表头 | |
| 26 | - private List<String> heardList; | |
| 27 | - //各个列的元素key值 | |
| 28 | - private List<String> heardKey; | |
| 29 | - //需要填充的数据信息 | |
| 30 | - private List<Map<String,String>> data; | |
| 31 | - //工作表 | |
| 32 | - private String sheetName = "模板"; | |
| 33 | - | |
| 34 | - | |
| 35 | - public List<String> getHeardList() { | |
| 36 | - return heardList; | |
| 37 | - } | |
| 38 | - | |
| 39 | - public void setHeardList(List<String> heardList) { | |
| 40 | - this.heardList = heardList; | |
| 41 | - } | |
| 42 | - | |
| 43 | - public List<String> getHeardKey() { | |
| 44 | - return heardKey; | |
| 45 | - } | |
| 46 | - | |
| 47 | - public void setHeardKey(List<String> heardKey) { | |
| 48 | - this.heardKey = heardKey; | |
| 49 | - } | |
| 50 | - | |
| 51 | - public List<Map<String, String>> getData() { | |
| 52 | - return data; | |
| 53 | - } | |
| 54 | - | |
| 55 | - public void setData(List<Map<String, String>> data) { | |
| 56 | - this.data = data; | |
| 57 | - } | |
| 58 | - | |
| 59 | - public String getSheetName() { | |
| 60 | - return sheetName; | |
| 61 | - } | |
| 62 | - | |
| 63 | - public void setSheetName(String sheetName) { | |
| 64 | - this.sheetName = sheetName; | |
| 65 | - } | |
| 66 | - | |
| 67 | - /** | |
| 68 | - * 开始导出数据信息 | |
| 69 | - * | |
| 70 | - */ | |
| 71 | - public byte[] exportExport(HttpServletRequest request, HttpServletResponse response) throws IOException { | |
| 72 | - //检查参数配置信息 | |
| 73 | - checkConfig(); | |
| 74 | - //创建工作簿 | |
| 75 | - HSSFWorkbook wb = new HSSFWorkbook(); | |
| 76 | - //创建工作表 | |
| 77 | - HSSFSheet wbSheet = wb.createSheet(this.sheetName); | |
| 78 | - | |
| 79 | - //在第0行创建rows | |
| 80 | - HSSFRow row = wbSheet.createRow((int)0); | |
| 81 | - //设置列头元素 | |
| 82 | - HSSFCell cellHead = null; | |
| 83 | - for (int i = 0; i < heardList.size(); i++) { | |
| 84 | - cellHead = row.createCell(i); | |
| 85 | - cellHead.setCellValue(heardList.get(i)); | |
| 86 | - } | |
| 87 | - //开始写入实体数据信息 | |
| 88 | - int a = 1; | |
| 89 | - for (int i = 0; i < data.size(); i++) { | |
| 90 | - HSSFRow roww = wbSheet.createRow((int) a); | |
| 91 | - Map map = data.get(i); | |
| 92 | - HSSFCell cell = null; | |
| 93 | - for (int j = 0; j < heardKey.size(); j++) { | |
| 94 | - cell = roww.createCell(j); | |
| 95 | - Object valueObject = map.get(heardKey.get(j)); | |
| 96 | - String value = null; | |
| 97 | - if (valueObject == null) { | |
| 98 | - valueObject = ""; | |
| 99 | - } | |
| 100 | - if (valueObject instanceof String) { | |
| 101 | - //取出的数据是字符串直接赋值 | |
| 102 | - value = (String) map.get(heardKey.get(j)); | |
| 103 | - } else if (valueObject instanceof Integer) { | |
| 104 | - //取出的数据是Integer | |
| 105 | - value = String.valueOf(((Integer) (valueObject)).floatValue()); | |
| 106 | - } else if (valueObject instanceof BigDecimal) { | |
| 107 | - //取出的数据是BigDecimal | |
| 108 | - value = String.valueOf(((BigDecimal) (valueObject)).floatValue()); | |
| 109 | - } else { | |
| 110 | - value = valueObject.toString(); | |
| 111 | - } | |
| 112 | - cell.setCellValue(Strings.isNullOrEmpty(value) ? "" : value); | |
| 113 | - } | |
| 114 | - a++; | |
| 115 | - } | |
| 116 | - | |
| 117 | - //导出数据 | |
| 118 | - try { | |
| 119 | - //设置Http响应头告诉浏览器下载这个附件 | |
| 120 | - response.setHeader("Content-Disposition", "attachment;Filename=" + System.currentTimeMillis() + ".xls"); | |
| 121 | - OutputStream outputStream = response.getOutputStream(); | |
| 122 | - wb.write(outputStream); | |
| 123 | - outputStream.flush(); | |
| 124 | - outputStream.close(); | |
| 125 | - return wb.getBytes(); | |
| 126 | - } catch (Exception ex) { | |
| 127 | - ex.printStackTrace(); | |
| 128 | - throw new IOException("导出Excel出现严重异常,异常信息:" + ex.getMessage()); | |
| 129 | - } | |
| 130 | - | |
| 131 | - } | |
| 132 | - | |
| 133 | - /** | |
| 134 | - * 检查数据配置问题 | |
| 135 | - * | |
| 136 | - * @throws IOException 抛出数据异常类 | |
| 137 | - */ | |
| 138 | - protected void checkConfig() throws IOException { | |
| 139 | - if (heardKey == null || heardList.size() == 0) { | |
| 140 | - throw new IOException("列名数组不能为空或者为NULL"); | |
| 141 | - } | |
| 142 | - if (StringUtils.isBlank(sheetName)) { | |
| 143 | - throw new IOException("工作表表名不能为NULL"); | |
| 144 | - } | |
| 145 | - } | |
| 146 | - | |
| 147 | -} | |
| 1 | +//package com.sincere.common.util; | |
| 2 | +// | |
| 3 | +//import com.google.common.base.Strings; | |
| 4 | +//import org.apache.commons.lang3.StringUtils; | |
| 5 | +//import org.apache.poi.hssf.usermodel.HSSFCell; | |
| 6 | +//import org.apache.poi.hssf.usermodel.HSSFRow; | |
| 7 | +//import org.apache.poi.hssf.usermodel.HSSFSheet; | |
| 8 | +//import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |
| 9 | +// | |
| 10 | +//import javax.servlet.http.HttpServletRequest; | |
| 11 | +//import javax.servlet.http.HttpServletResponse; | |
| 12 | +//import java.io.IOException; | |
| 13 | +//import java.io.OutputStream; | |
| 14 | +//import java.math.BigDecimal; | |
| 15 | +//import java.util.List; | |
| 16 | +//import java.util.Map; | |
| 17 | +// | |
| 18 | +///** | |
| 19 | +// * @author chen | |
| 20 | +// * @version 1.0 | |
| 21 | +// * @date 2019/10/16 0016 18:46 | |
| 22 | +// */ | |
| 23 | +//public class ExcelUtils { | |
| 24 | +// | |
| 25 | +// //各个列的表头 | |
| 26 | +// private List<String> heardList; | |
| 27 | +// //各个列的元素key值 | |
| 28 | +// private List<String> heardKey; | |
| 29 | +// //需要填充的数据信息 | |
| 30 | +// private List<Map<String,String>> data; | |
| 31 | +// //工作表 | |
| 32 | +// private String sheetName = "模板"; | |
| 33 | +// | |
| 34 | +// | |
| 35 | +// public List<String> getHeardList() { | |
| 36 | +// return heardList; | |
| 37 | +// } | |
| 38 | +// | |
| 39 | +// public void setHeardList(List<String> heardList) { | |
| 40 | +// this.heardList = heardList; | |
| 41 | +// } | |
| 42 | +// | |
| 43 | +// public List<String> getHeardKey() { | |
| 44 | +// return heardKey; | |
| 45 | +// } | |
| 46 | +// | |
| 47 | +// public void setHeardKey(List<String> heardKey) { | |
| 48 | +// this.heardKey = heardKey; | |
| 49 | +// } | |
| 50 | +// | |
| 51 | +// public List<Map<String, String>> getData() { | |
| 52 | +// return data; | |
| 53 | +// } | |
| 54 | +// | |
| 55 | +// public void setData(List<Map<String, String>> data) { | |
| 56 | +// this.data = data; | |
| 57 | +// } | |
| 58 | +// | |
| 59 | +// public String getSheetName() { | |
| 60 | +// return sheetName; | |
| 61 | +// } | |
| 62 | +// | |
| 63 | +// public void setSheetName(String sheetName) { | |
| 64 | +// this.sheetName = sheetName; | |
| 65 | +// } | |
| 66 | +// | |
| 67 | +// /** | |
| 68 | +// * 开始导出数据信息 | |
| 69 | +// * | |
| 70 | +// */ | |
| 71 | +// public byte[] exportExport(HttpServletRequest request, HttpServletResponse response) throws IOException { | |
| 72 | +// //检查参数配置信息 | |
| 73 | +// checkConfig(); | |
| 74 | +// //创建工作簿 | |
| 75 | +// HSSFWorkbook wb = new HSSFWorkbook(); | |
| 76 | +// //创建工作表 | |
| 77 | +// HSSFSheet wbSheet = wb.createSheet(this.sheetName); | |
| 78 | +// | |
| 79 | +// //在第0行创建rows | |
| 80 | +// HSSFRow row = wbSheet.createRow((int)0); | |
| 81 | +// //设置列头元素 | |
| 82 | +// HSSFCell cellHead = null; | |
| 83 | +// for (int i = 0; i < heardList.size(); i++) { | |
| 84 | +// cellHead = row.createCell(i); | |
| 85 | +// cellHead.setCellValue(heardList.get(i)); | |
| 86 | +// } | |
| 87 | +// //开始写入实体数据信息 | |
| 88 | +// int a = 1; | |
| 89 | +// for (int i = 0; i < data.size(); i++) { | |
| 90 | +// HSSFRow roww = wbSheet.createRow((int) a); | |
| 91 | +// Map map = data.get(i); | |
| 92 | +// HSSFCell cell = null; | |
| 93 | +// for (int j = 0; j < heardKey.size(); j++) { | |
| 94 | +// cell = roww.createCell(j); | |
| 95 | +// Object valueObject = map.get(heardKey.get(j)); | |
| 96 | +// String value = null; | |
| 97 | +// if (valueObject == null) { | |
| 98 | +// valueObject = ""; | |
| 99 | +// } | |
| 100 | +// if (valueObject instanceof String) { | |
| 101 | +// //取出的数据是字符串直接赋值 | |
| 102 | +// value = (String) map.get(heardKey.get(j)); | |
| 103 | +// } else if (valueObject instanceof Integer) { | |
| 104 | +// //取出的数据是Integer | |
| 105 | +// value = String.valueOf(((Integer) (valueObject)).floatValue()); | |
| 106 | +// } else if (valueObject instanceof BigDecimal) { | |
| 107 | +// //取出的数据是BigDecimal | |
| 108 | +// value = String.valueOf(((BigDecimal) (valueObject)).floatValue()); | |
| 109 | +// } else { | |
| 110 | +// value = valueObject.toString(); | |
| 111 | +// } | |
| 112 | +// cell.setCellValue(Strings.isNullOrEmpty(value) ? "" : value); | |
| 113 | +// } | |
| 114 | +// a++; | |
| 115 | +// } | |
| 116 | +// | |
| 117 | +// //导出数据 | |
| 118 | +// try { | |
| 119 | +// //设置Http响应头告诉浏览器下载这个附件 | |
| 120 | +// response.setHeader("Content-Disposition", "attachment;Filename=" + System.currentTimeMillis() + ".xls"); | |
| 121 | +// OutputStream outputStream = response.getOutputStream(); | |
| 122 | +// wb.write(outputStream); | |
| 123 | +// outputStream.flush(); | |
| 124 | +// outputStream.close(); | |
| 125 | +// return wb.getBytes(); | |
| 126 | +// } catch (Exception ex) { | |
| 127 | +// ex.printStackTrace(); | |
| 128 | +// throw new IOException("导出Excel出现严重异常,异常信息:" + ex.getMessage()); | |
| 129 | +// } | |
| 130 | +// | |
| 131 | +// } | |
| 132 | +// | |
| 133 | +// /** | |
| 134 | +// * 检查数据配置问题 | |
| 135 | +// * | |
| 136 | +// * @throws IOException 抛出数据异常类 | |
| 137 | +// */ | |
| 138 | +// protected void checkConfig() throws IOException { | |
| 139 | +// if (heardKey == null || heardList.size() == 0) { | |
| 140 | +// throw new IOException("列名数组不能为空或者为NULL"); | |
| 141 | +// } | |
| 142 | +// if (StringUtils.isBlank(sheetName)) { | |
| 143 | +// throw new IOException("工作表表名不能为NULL"); | |
| 144 | +// } | |
| 145 | +// } | |
| 146 | +// | |
| 147 | +//} | ... | ... |
cloud/common/src/main/java/com/sincere/common/util/UrlUtil.java
| ... | ... | @@ -1,47 +0,0 @@ |
| 1 | -package com.sincere.common.util; | |
| 2 | - | |
| 3 | -import javax.servlet.http.HttpServletRequest; | |
| 4 | -import java.io.PrintWriter; | |
| 5 | -import java.io.StringWriter; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * @author: yukong | |
| 9 | - * @date: 2018/11/14 19:50 | |
| 10 | - */ | |
| 11 | -public class UrlUtil { | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * 获取目标主机的ip | |
| 15 | - * @param request | |
| 16 | - * @return | |
| 17 | - */ | |
| 18 | - public static String getRemoteHost(HttpServletRequest request) { | |
| 19 | - String ip = request.getHeader("x-forwarded-for"); | |
| 20 | - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { | |
| 21 | - ip = request.getHeader("Proxy-Client-IP"); | |
| 22 | - } | |
| 23 | - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { | |
| 24 | - ip = request.getHeader("WL-Proxy-Client-IP"); | |
| 25 | - } | |
| 26 | - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { | |
| 27 | - ip = request.getRemoteAddr(); | |
| 28 | - } | |
| 29 | - return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip; | |
| 30 | - } | |
| 31 | - | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * 获取完整的异常栈信息 | |
| 35 | - * @param t | |
| 36 | - * @return | |
| 37 | - */ | |
| 38 | - public static String getTrace(Throwable t) { | |
| 39 | - StringWriter stringWriter= new StringWriter(); | |
| 40 | - PrintWriter writer= new PrintWriter(stringWriter); | |
| 41 | - t.printStackTrace(writer); | |
| 42 | - StringBuffer buffer= stringWriter.getBuffer(); | |
| 43 | - return buffer.toString(); | |
| 44 | - } | |
| 45 | - | |
| 46 | - | |
| 47 | -} |
cloud/common/src/main/java/com/sincere/common/util/UserUtil.java
| ... | ... | @@ -1,95 +0,0 @@ |
| 1 | -package com.sincere.common.util; | |
| 2 | - | |
| 3 | -import com.sincere.common.constants.SecurityConstants; | |
| 4 | -import com.sincere.common.constants.UserConstants; | |
| 5 | -import io.jsonwebtoken.Claims; | |
| 6 | -import io.jsonwebtoken.Jwts; | |
| 7 | -import lombok.extern.slf4j.Slf4j; | |
| 8 | - | |
| 9 | -import javax.servlet.http.HttpServletRequest; | |
| 10 | -import java.util.Base64; | |
| 11 | -import java.util.List; | |
| 12 | - | |
| 13 | -/** | |
| 14 | - * @author: yukong | |
| 15 | - * @date: 2018/10/17 08:56 | |
| 16 | - * @description: | |
| 17 | - */ | |
| 18 | -@Slf4j | |
| 19 | -public class UserUtil { | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 获取请求中的token | |
| 23 | - * @param request | |
| 24 | - * @return token | |
| 25 | - */ | |
| 26 | - public static String getToken(HttpServletRequest request){ | |
| 27 | - String authorization = request.getHeader(SecurityConstants.TOKEN_HEADER); | |
| 28 | - if(authorization == null){ | |
| 29 | - return null; | |
| 30 | - } | |
| 31 | - String token = authorization.split(" ")[1]; | |
| 32 | - //log.info("获取token成功,值为{}", token); | |
| 33 | - return token; | |
| 34 | - } | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * 获取jwt中的claims信息 | |
| 38 | - * @param token | |
| 39 | - * @return claim | |
| 40 | - */ | |
| 41 | - public static Claims getClaims(String token) { | |
| 42 | - String key = Base64.getEncoder().encodeToString(SecurityConstants.SIGN_KEY.getBytes()); | |
| 43 | - Claims claims = Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody(); | |
| 44 | - return claims; | |
| 45 | - } | |
| 46 | - | |
| 47 | - /** | |
| 48 | - * 获取请求中的userId | |
| 49 | - * @param request | |
| 50 | - * @return userId | |
| 51 | - */ | |
| 52 | - public static Integer getUserId(HttpServletRequest request){ | |
| 53 | - String token = getToken(request); | |
| 54 | - if(token == null){ | |
| 55 | - return null; | |
| 56 | - } | |
| 57 | - Claims claims = getClaims(token); | |
| 58 | - Integer userId = (Integer) claims.get(UserConstants.USER_ID); | |
| 59 | - //log.info("获取userId成功,值为", userId); | |
| 60 | - return userId; | |
| 61 | - } | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * 获取请求中的userId | |
| 65 | - * @param request | |
| 66 | - * @return userId | |
| 67 | - */ | |
| 68 | - public static String getUserName(HttpServletRequest request){ | |
| 69 | - String token = getToken(request); | |
| 70 | - if(token == null){ | |
| 71 | - return null; | |
| 72 | - } | |
| 73 | - Claims claims = getClaims(token); | |
| 74 | - String username = (String) claims.get(UserConstants.USER_NAME); | |
| 75 | - //log.info("获取username成功,值为", username); | |
| 76 | - return username; | |
| 77 | - } | |
| 78 | - | |
| 79 | - /** | |
| 80 | - * 获取请求中的roles集合 | |
| 81 | - * @param request | |
| 82 | - * @return roles | |
| 83 | - */ | |
| 84 | - public static List<String> getRoles(HttpServletRequest request) { | |
| 85 | - String token = getToken(request); | |
| 86 | - if(token == null){ | |
| 87 | - return null; | |
| 88 | - } | |
| 89 | - Claims claims = getClaims(token); | |
| 90 | - List<String> roles = (List<String>) claims.get(UserConstants.AUTHORITIES); | |
| 91 | - return roles; | |
| 92 | - } | |
| 93 | - | |
| 94 | - | |
| 95 | -} |
| ... | ... | @@ -0,0 +1,65 @@ |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 3 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 4 | + <modelVersion>4.0.0</modelVersion> | |
| 5 | + <parent> | |
| 6 | + <groupId>com.sincere</groupId> | |
| 7 | + <artifactId>cloud</artifactId> | |
| 8 | + <version>1.0.0</version> | |
| 9 | + </parent> | |
| 10 | + <artifactId>getaway</artifactId> | |
| 11 | + <version>1.0.0</version> | |
| 12 | + <name>getaway</name> | |
| 13 | + <description>Demo project for Spring Boot</description> | |
| 14 | + | |
| 15 | + <properties> | |
| 16 | + <java.version>1.8</java.version> | |
| 17 | + <spring-cloud.version>Greenwich.SR1</spring-cloud.version> | |
| 18 | + </properties> | |
| 19 | + | |
| 20 | + <dependencies> | |
| 21 | + <dependency> | |
| 22 | + <groupId>com.sincere</groupId> | |
| 23 | + <artifactId>common</artifactId> | |
| 24 | + <version>1.0.0</version> | |
| 25 | + </dependency> | |
| 26 | + <!--gateway 网关依赖,内置webflux 依赖--> | |
| 27 | + <dependency> | |
| 28 | + <groupId>org.springframework.cloud</groupId> | |
| 29 | + <artifactId>spring-cloud-starter-gateway</artifactId> | |
| 30 | + <exclusions> | |
| 31 | + <exclusion> | |
| 32 | + <groupId>org.springframework.boot</groupId> | |
| 33 | + <artifactId>spring-boot-starter-web</artifactId> | |
| 34 | + </exclusion> | |
| 35 | + </exclusions> | |
| 36 | + </dependency> | |
| 37 | + <dependency> | |
| 38 | + <groupId>io.springfox</groupId> | |
| 39 | + <artifactId>springfox-swagger-ui</artifactId> | |
| 40 | + <version>2.9.2</version> | |
| 41 | + </dependency> | |
| 42 | + <dependency> | |
| 43 | + <groupId>io.springfox</groupId> | |
| 44 | + <artifactId>springfox-swagger2</artifactId> | |
| 45 | + <version>2.9.2</version> | |
| 46 | + </dependency> | |
| 47 | + </dependencies> | |
| 48 | + | |
| 49 | +<!-- <build>--> | |
| 50 | +<!-- <plugins>--> | |
| 51 | +<!-- <plugin>--> | |
| 52 | +<!-- <groupId>org.springframework.boot</groupId>--> | |
| 53 | +<!-- <artifactId>spring-boot-maven-plugin</artifactId>--> | |
| 54 | +<!-- <executions>--> | |
| 55 | +<!-- <execution>--> | |
| 56 | +<!-- <goals>--> | |
| 57 | +<!-- <goal>repackage</goal>--> | |
| 58 | +<!-- </goals>--> | |
| 59 | +<!-- </execution>--> | |
| 60 | +<!-- </executions>--> | |
| 61 | +<!-- </plugin>--> | |
| 62 | +<!-- </plugins>--> | |
| 63 | +<!-- </build>--> | |
| 64 | + | |
| 65 | +</project> | ... | ... |
cloud/getaway/src/main/java/com/sincere/getaway/GetawayApplication.java
0 → 100644
| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | +package com.sincere.getaway; | |
| 2 | + | |
| 3 | +import org.springframework.boot.SpringApplication; | |
| 4 | +import org.springframework.cloud.client.SpringCloudApplication; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * 统一网关配置 | |
| 8 | + * 通过服务路由的功能,在对外提供服务的时候,只需要通过暴露Zuul中配置的调用地址就可以让调用方统一的来访问我们的服务; | |
| 9 | + */ | |
| 10 | +@SpringCloudApplication | |
| 11 | +public class GetawayApplication { | |
| 12 | + | |
| 13 | + public static void main(String[] args) { | |
| 14 | + SpringApplication.run(GetawayApplication.class, args); | |
| 15 | + } | |
| 16 | + | |
| 17 | + | |
| 18 | +} | ... | ... |
cloud/getaway/src/main/java/com/sincere/getaway/client/config/PermitUrlProperties.java
0 → 100644
| ... | ... | @@ -0,0 +1,49 @@ |
| 1 | +package com.sincere.getaway.client.config; | |
| 2 | + | |
| 3 | +import org.springframework.boot.context.properties.ConfigurationProperties; | |
| 4 | +import org.springframework.stereotype.Component; | |
| 5 | + | |
| 6 | +import java.util.ArrayList; | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 9 | + | |
| 10 | +@Component | |
| 11 | +@ConfigurationProperties(prefix = "url") | |
| 12 | +public class PermitUrlProperties { | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * swagger需要访问的url | |
| 16 | + */ | |
| 17 | + private static final String[] ENDPOINTS = { | |
| 18 | + | |
| 19 | + "/v2/api-docs/**", "/swagger-ui.html", "/swagger-resources/**", "/webjars/**" , // api-gateway webflux swagger | |
| 20 | + "/**/v2/api-docs/**", "/**/swagger-ui.html", "/**/swagger-resources/**", "/**/webjars/**" //业务中心swagger | |
| 21 | + }; | |
| 22 | + | |
| 23 | + private String[] ignored; | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 需要放开权限的url | |
| 27 | + * @return 自定义的url和监控中心需要访问的url集合 | |
| 28 | + */ | |
| 29 | + public String[] getIgnored() { | |
| 30 | + if (ignored == null || ignored.length == 0) { | |
| 31 | + return ENDPOINTS; | |
| 32 | + } | |
| 33 | + | |
| 34 | + List<String> list = new ArrayList<>(); | |
| 35 | + for (String url : ENDPOINTS) { | |
| 36 | + list.add(url); | |
| 37 | + } | |
| 38 | + for (String url : ignored) { | |
| 39 | + list.add(url); | |
| 40 | + } | |
| 41 | + | |
| 42 | + return list.toArray(new String[list.size()]); | |
| 43 | + } | |
| 44 | + | |
| 45 | + public void setIgnored(String[] ignored) { | |
| 46 | + this.ignored = ignored; | |
| 47 | + } | |
| 48 | + | |
| 49 | +} | ... | ... |
cloud/getaway/src/main/java/com/sincere/getaway/client/config/SwaggerProvider.java
0 → 100644
| ... | ... | @@ -0,0 +1,47 @@ |
| 1 | +package com.sincere.getaway.client.config; | |
| 2 | + | |
| 3 | +import lombok.AllArgsConstructor; | |
| 4 | +import org.springframework.cloud.gateway.config.GatewayProperties; | |
| 5 | +import org.springframework.cloud.gateway.route.RouteLocator; | |
| 6 | +import org.springframework.cloud.gateway.support.NameUtils; | |
| 7 | +import org.springframework.context.annotation.Primary; | |
| 8 | +import org.springframework.stereotype.Component; | |
| 9 | +import springfox.documentation.swagger.web.SwaggerResource; | |
| 10 | +import springfox.documentation.swagger.web.SwaggerResourcesProvider; | |
| 11 | + | |
| 12 | +import java.util.ArrayList; | |
| 13 | +import java.util.List; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * @author Sywd | |
| 17 | + */ | |
| 18 | +@Component | |
| 19 | +@Primary | |
| 20 | +@AllArgsConstructor | |
| 21 | +public class SwaggerProvider implements SwaggerResourcesProvider { | |
| 22 | + public static final String API_URI = "/v2/api-docs"; | |
| 23 | + private final RouteLocator routeLocator; | |
| 24 | + private final GatewayProperties gatewayProperties; | |
| 25 | + | |
| 26 | + @Override | |
| 27 | + public List<SwaggerResource> get() { | |
| 28 | + List<SwaggerResource> resources = new ArrayList<>(); | |
| 29 | + List<String> routes = new ArrayList<>(); | |
| 30 | + routeLocator.getRoutes().subscribe(route -> routes.add(route.getId())); | |
| 31 | + gatewayProperties.getRoutes().stream().filter(routeDefinition -> routes.contains(routeDefinition.getId())) | |
| 32 | + .forEach(routeDefinition -> routeDefinition.getPredicates().stream() | |
| 33 | + .filter(predicateDefinition -> ("Path").equalsIgnoreCase(predicateDefinition.getName())) | |
| 34 | + .forEach(predicateDefinition -> resources.add(swaggerResource(routeDefinition.getId(), | |
| 35 | + predicateDefinition.getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0") | |
| 36 | + .replace("/**", API_URI))))); | |
| 37 | + return resources; | |
| 38 | + } | |
| 39 | + | |
| 40 | + private SwaggerResource swaggerResource(String name, String location) { | |
| 41 | + SwaggerResource swaggerResource = new SwaggerResource(); | |
| 42 | + swaggerResource.setName(name); | |
| 43 | + swaggerResource.setLocation(location); | |
| 44 | + swaggerResource.setSwaggerVersion("2.0"); | |
| 45 | + return swaggerResource; | |
| 46 | + } | |
| 47 | +} | ... | ... |
cloud/getaway/src/main/java/com/sincere/getaway/client/filter/AccessFilter.java
0 → 100644
| ... | ... | @@ -0,0 +1,99 @@ |
| 1 | +package com.sincere.getaway.client.filter; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 4 | +import com.sincere.common.exception.ResultEnums; | |
| 5 | +import com.sincere.common.exception.ResultException; | |
| 6 | +import com.sincere.common.util.TokenUtils; | |
| 7 | +import com.sincere.getaway.client.config.PermitUrlProperties; | |
| 8 | +import org.apache.commons.lang3.StringUtils; | |
| 9 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; | |
| 10 | +import org.springframework.cloud.gateway.filter.GatewayFilterChain; | |
| 11 | +import org.springframework.cloud.gateway.filter.GlobalFilter; | |
| 12 | +import org.springframework.core.Ordered; | |
| 13 | +import org.springframework.core.io.buffer.DataBuffer; | |
| 14 | +import org.springframework.http.HttpStatus; | |
| 15 | +import org.springframework.http.server.reactive.ServerHttpRequest; | |
| 16 | +import org.springframework.http.server.reactive.ServerHttpResponse; | |
| 17 | +import org.springframework.stereotype.Component; | |
| 18 | +import org.springframework.util.AntPathMatcher; | |
| 19 | +import org.springframework.web.server.ServerWebExchange; | |
| 20 | +import reactor.core.publisher.Mono; | |
| 21 | + | |
| 22 | +import javax.annotation.Resource; | |
| 23 | +import java.nio.charset.StandardCharsets; | |
| 24 | +import java.util.List; | |
| 25 | + | |
| 26 | +/** | |
| 27 | + */ | |
| 28 | +@Component | |
| 29 | +@EnableConfigurationProperties(PermitUrlProperties.class) | |
| 30 | +public class AccessFilter implements GlobalFilter, Ordered { | |
| 31 | + | |
| 32 | + // url匹配器 | |
| 33 | + private AntPathMatcher pathMatcher = new AntPathMatcher(); | |
| 34 | + | |
| 35 | + @Resource | |
| 36 | + private PermitUrlProperties permitUrlProperties; | |
| 37 | + | |
| 38 | + | |
| 39 | + @Override | |
| 40 | + public int getOrder() { | |
| 41 | + // TODO Auto-generated method stub | |
| 42 | + return -500; | |
| 43 | + } | |
| 44 | + | |
| 45 | + @Override | |
| 46 | + public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { | |
| 47 | + String accessToken = this.extractToken(exchange.getRequest()); | |
| 48 | + // 默认 | |
| 49 | + boolean flag = false; | |
| 50 | + for (String ignored :permitUrlProperties.getIgnored()) { | |
| 51 | + if (pathMatcher.match(ignored, exchange.getRequest().getPath().value())) { | |
| 52 | + flag = true; // 白名单 | |
| 53 | + } | |
| 54 | + } | |
| 55 | + if (flag) { | |
| 56 | + return chain.filter(exchange); | |
| 57 | + } else { | |
| 58 | + ResultEnums result = getResult(accessToken); | |
| 59 | + if(result.getCode() == 0){ | |
| 60 | + return chain.filter(exchange); | |
| 61 | + }else { | |
| 62 | + exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED); | |
| 63 | + ServerHttpResponse response = exchange.getResponse(); | |
| 64 | + JSONObject message = new JSONObject(); | |
| 65 | + message.put("resp_code", result.getCode()); | |
| 66 | + message.put("resp_msg", result.getMessage()); | |
| 67 | + byte[] bits = message.toJSONString().getBytes(StandardCharsets.UTF_8); | |
| 68 | + DataBuffer buffer = response.bufferFactory().wrap(bits); | |
| 69 | + response.setStatusCode(HttpStatus.UNAUTHORIZED); | |
| 70 | + // 指定编码,否则在浏览器中会中文乱码 | |
| 71 | + response.getHeaders().add("Content-Type", "application/json;charset=UTF-8"); | |
| 72 | + return response.writeWith(Mono.just(buffer)); | |
| 73 | + } | |
| 74 | + | |
| 75 | + } | |
| 76 | + } | |
| 77 | + | |
| 78 | + private ResultEnums getResult(String token){ | |
| 79 | + if (StringUtils.isNotBlank(token)) { | |
| 80 | + return ResultEnums.no_token ; | |
| 81 | + }else { | |
| 82 | + try { | |
| 83 | + TokenUtils.validToken(token); | |
| 84 | + } catch (ResultException e) { | |
| 85 | + return ResultEnums.getByCode(e.getCode()); | |
| 86 | + } | |
| 87 | + } | |
| 88 | + return ResultEnums.error ; | |
| 89 | + } | |
| 90 | + | |
| 91 | + public String extractToken(ServerHttpRequest request) { | |
| 92 | + List<String> strings = request.getHeaders().get("X-Authorization"); | |
| 93 | + String authToken = ""; | |
| 94 | + if (strings != null) { | |
| 95 | + authToken = strings.get(0).substring("Bearer".length()).trim(); | |
| 96 | + } | |
| 97 | + return authToken; | |
| 98 | + } | |
| 99 | +} | ... | ... |
cloud/getaway/src/main/java/com/sincere/getaway/client/filter/SwaggerHeaderFilter.java
0 → 100644
| ... | ... | @@ -0,0 +1,36 @@ |
| 1 | +package com.sincere.getaway.client.filter; | |
| 2 | + | |
| 3 | +import com.sincere.getaway.client.config.SwaggerProvider; | |
| 4 | +import org.springframework.cloud.gateway.filter.GatewayFilter; | |
| 5 | +import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; | |
| 6 | +import org.springframework.http.server.reactive.ServerHttpRequest; | |
| 7 | +import org.springframework.stereotype.Component; | |
| 8 | +import org.springframework.util.StringUtils; | |
| 9 | +import org.springframework.web.server.ServerWebExchange; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * Spring 已修复该功能 | |
| 13 | + */ | |
| 14 | +@Component | |
| 15 | +@Deprecated | |
| 16 | +public class SwaggerHeaderFilter extends AbstractGatewayFilterFactory { | |
| 17 | + private static final String HEADER_NAME = "X-Forwarded-Prefix"; | |
| 18 | + | |
| 19 | + @Override | |
| 20 | + public GatewayFilter apply(Object config) { | |
| 21 | + return (exchange, chain) -> { | |
| 22 | + ServerHttpRequest request = exchange.getRequest(); | |
| 23 | + String path = request.getURI().getPath(); | |
| 24 | + if (!StringUtils.endsWithIgnoreCase(path, SwaggerProvider.API_URI)) { | |
| 25 | + return chain.filter(exchange); | |
| 26 | + } | |
| 27 | + | |
| 28 | + String basePath = path.substring(0, path.lastIndexOf(SwaggerProvider.API_URI)); | |
| 29 | + | |
| 30 | + | |
| 31 | + ServerHttpRequest newRequest = request.mutate().header(HEADER_NAME, basePath).build(); | |
| 32 | + ServerWebExchange newExchange = exchange.mutate().request(newRequest).build(); | |
| 33 | + return chain.filter(newExchange); | |
| 34 | + }; | |
| 35 | + } | |
| 36 | +} | ... | ... |
cloud/getaway/src/main/java/com/sincere/getaway/client/handler/SwaggerHandler.java
0 → 100644
| ... | ... | @@ -0,0 +1,45 @@ |
| 1 | +package com.sincere.getaway.client.handler; | |
| 2 | + | |
| 3 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 4 | +import org.springframework.http.HttpStatus; | |
| 5 | +import org.springframework.http.ResponseEntity; | |
| 6 | +import org.springframework.web.bind.annotation.GetMapping; | |
| 7 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 8 | +import org.springframework.web.bind.annotation.RestController; | |
| 9 | +import reactor.core.publisher.Mono; | |
| 10 | +import springfox.documentation.swagger.web.*; | |
| 11 | + | |
| 12 | +import java.util.Optional; | |
| 13 | + | |
| 14 | +@RestController | |
| 15 | +@RequestMapping("/swagger-resources") | |
| 16 | +public class SwaggerHandler { | |
| 17 | + @Autowired(required = false) | |
| 18 | + private SecurityConfiguration securityConfiguration; | |
| 19 | + @Autowired(required = false) | |
| 20 | + private UiConfiguration uiConfiguration; | |
| 21 | + private final SwaggerResourcesProvider swaggerResources; | |
| 22 | + | |
| 23 | + @Autowired | |
| 24 | + public SwaggerHandler(SwaggerResourcesProvider swaggerResources) { | |
| 25 | + this.swaggerResources = swaggerResources; | |
| 26 | + } | |
| 27 | + | |
| 28 | + | |
| 29 | + @GetMapping("/configuration/security") | |
| 30 | + public Mono<ResponseEntity<SecurityConfiguration>> securityConfiguration() { | |
| 31 | + return Mono.just(new ResponseEntity<>( | |
| 32 | + Optional.ofNullable(securityConfiguration).orElse(SecurityConfigurationBuilder.builder().build()), HttpStatus.OK)); | |
| 33 | + } | |
| 34 | + | |
| 35 | + @GetMapping("/configuration/ui") | |
| 36 | + public Mono<ResponseEntity<UiConfiguration>> uiConfiguration() { | |
| 37 | + return Mono.just(new ResponseEntity<>( | |
| 38 | + Optional.ofNullable(uiConfiguration).orElse(UiConfigurationBuilder.builder().build()), HttpStatus.OK)); | |
| 39 | + } | |
| 40 | + | |
| 41 | + @GetMapping("") | |
| 42 | + public Mono<ResponseEntity> swaggerResources() { | |
| 43 | + return Mono.just((new ResponseEntity<>(swaggerResources.get(), HttpStatus.OK))); | |
| 44 | + } | |
| 45 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | +eureka: | |
| 2 | + client: | |
| 3 | + fetch-registry: true | |
| 4 | + register-with-eureka: true | |
| 5 | + service-url: | |
| 6 | +# defaultZone: http://localhost:8761/eureka/ | |
| 7 | + defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/ | |
| 8 | + instance: | |
| 9 | + hostname: localhost | |
| 10 | + lease-expiration-duration-in-seconds: 90 | |
| 11 | + lease-renewal-interval-in-seconds: 10 | |
| 12 | + prefer-ip-address: true | |
| 13 | + | |
| 14 | +spring: | |
| 15 | + cloud: | |
| 16 | + gateway: | |
| 17 | + routes: | |
| 18 | + - id: usersearch | |
| 19 | + uri: lb://usersearch | |
| 20 | + predicates: | |
| 21 | + - Path=/usersearch/** | |
| 22 | + filters: | |
| 23 | + - StripPrefix=1 | |
| 24 | + - id: haikangserver | |
| 25 | + uri: lb://haikangserver | |
| 26 | + predicates: | |
| 27 | + - Path=/haikangserver/** | |
| 28 | + filters: | |
| 29 | + - StripPrefix=1 | |
| 30 | +url: | |
| 31 | + ignored: /user/** | |
| 0 | 32 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | +#端口 | |
| 2 | +server: | |
| 3 | + port: 8083 | |
| 4 | + | |
| 5 | +#服务名称 | |
| 6 | +spring: | |
| 7 | + application: | |
| 8 | + name: sincere_geteway | |
| 9 | + main: | |
| 10 | + allow-bean-definition-overriding: true | |
| 11 | + | |
| 12 | + | |
| 13 | +management: | |
| 14 | + endpoints: | |
| 15 | + web: | |
| 16 | + exposure: | |
| 17 | + include: "*" | |
| 18 | + endpoint: | |
| 19 | + health: | |
| 20 | + show-details: always | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 0 | 24 | \ No newline at end of file | ... | ... |
cloud/geteway/pom.xml
| ... | ... | @@ -1,59 +0,0 @@ |
| 1 | -<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 3 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 4 | - <modelVersion>4.0.0</modelVersion> | |
| 5 | - <parent> | |
| 6 | - <groupId>com.sincere</groupId> | |
| 7 | - <artifactId>cloud</artifactId> | |
| 8 | - <version>1.0.0</version> | |
| 9 | - </parent> | |
| 10 | - <groupId>com.example.geteway</groupId> | |
| 11 | - <artifactId>geteway</artifactId> | |
| 12 | - <version>1.0.0</version> | |
| 13 | - <name>geteway</name> | |
| 14 | - <description>Demo project for Spring Boot</description> | |
| 15 | - | |
| 16 | - <properties> | |
| 17 | - <java.version>1.8</java.version> | |
| 18 | - <spring-cloud.version>Greenwich.SR1</spring-cloud.version> | |
| 19 | - </properties> | |
| 20 | - | |
| 21 | - <dependencies> | |
| 22 | - <!--gateway 网关依赖,内置webflux 依赖--> | |
| 23 | - <dependency> | |
| 24 | - <groupId>org.springframework.cloud</groupId> | |
| 25 | - <artifactId>spring-cloud-starter-gateway</artifactId> | |
| 26 | - </dependency> | |
| 27 | - <dependency> | |
| 28 | - <groupId>org.springframework.boot</groupId> | |
| 29 | - <artifactId>spring-boot-starter-data-redis-reactive</artifactId> | |
| 30 | - </dependency> | |
| 31 | - <dependency> | |
| 32 | - <groupId>io.springfox</groupId> | |
| 33 | - <artifactId>springfox-swagger-ui</artifactId> | |
| 34 | - <version>2.9.2</version> | |
| 35 | - </dependency> | |
| 36 | - <dependency> | |
| 37 | - <groupId>io.springfox</groupId> | |
| 38 | - <artifactId>springfox-swagger2</artifactId> | |
| 39 | - <version>2.9.2</version> | |
| 40 | - </dependency> | |
| 41 | - </dependencies> | |
| 42 | - | |
| 43 | -<!-- <build>--> | |
| 44 | -<!-- <plugins>--> | |
| 45 | -<!-- <plugin>--> | |
| 46 | -<!-- <groupId>org.springframework.boot</groupId>--> | |
| 47 | -<!-- <artifactId>spring-boot-maven-plugin</artifactId>--> | |
| 48 | -<!-- <executions>--> | |
| 49 | -<!-- <execution>--> | |
| 50 | -<!-- <goals>--> | |
| 51 | -<!-- <goal>repackage</goal>--> | |
| 52 | -<!-- </goals>--> | |
| 53 | -<!-- </execution>--> | |
| 54 | -<!-- </executions>--> | |
| 55 | -<!-- </plugin>--> | |
| 56 | -<!-- </plugins>--> | |
| 57 | -<!-- </build>--> | |
| 58 | - | |
| 59 | -</project> |
cloud/geteway/src/main/java/com/example/geteway/GetewayApplication.java
| ... | ... | @@ -1,18 +0,0 @@ |
| 1 | -package com.example.geteway; | |
| 2 | - | |
| 3 | -import org.springframework.boot.SpringApplication; | |
| 4 | -import org.springframework.cloud.client.SpringCloudApplication; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * 统一网关配置 | |
| 8 | - * 通过服务路由的功能,在对外提供服务的时候,只需要通过暴露Zuul中配置的调用地址就可以让调用方统一的来访问我们的服务; | |
| 9 | - */ | |
| 10 | -@SpringCloudApplication | |
| 11 | -public class GetewayApplication { | |
| 12 | - | |
| 13 | - public static void main(String[] args) { | |
| 14 | - SpringApplication.run(GetewayApplication.class, args); | |
| 15 | - } | |
| 16 | - | |
| 17 | - | |
| 18 | -} |
cloud/geteway/src/main/java/com/example/geteway/client/config/SwaggerProvider.java
| ... | ... | @@ -1,48 +0,0 @@ |
| 1 | -package com.example.geteway.client.config; | |
| 2 | - | |
| 3 | -import lombok.AllArgsConstructor; | |
| 4 | -import org.springframework.cloud.gateway.config.GatewayProperties; | |
| 5 | -import org.springframework.cloud.gateway.route.RouteLocator; | |
| 6 | -import org.springframework.cloud.gateway.support.NameUtils; | |
| 7 | -import org.springframework.context.annotation.Primary; | |
| 8 | -import org.springframework.stereotype.Component; | |
| 9 | -import springfox.documentation.swagger.web.SwaggerResource; | |
| 10 | -import springfox.documentation.swagger.web.SwaggerResourcesProvider; | |
| 11 | - | |
| 12 | -import java.util.ArrayList; | |
| 13 | -import java.util.List; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * @author Sywd | |
| 17 | - */ | |
| 18 | -@Component | |
| 19 | -@Primary | |
| 20 | -@AllArgsConstructor | |
| 21 | -public class SwaggerProvider implements SwaggerResourcesProvider { | |
| 22 | - public static final String API_URI = "/v2/api-docs"; | |
| 23 | - private final RouteLocator routeLocator; | |
| 24 | - private final GatewayProperties gatewayProperties; | |
| 25 | - | |
| 26 | - | |
| 27 | - @Override | |
| 28 | - public List<SwaggerResource> get() { | |
| 29 | - List<SwaggerResource> resources = new ArrayList<>(); | |
| 30 | - List<String> routes = new ArrayList<>(); | |
| 31 | - routeLocator.getRoutes().subscribe(route -> routes.add(route.getId())); | |
| 32 | - gatewayProperties.getRoutes().stream().filter(routeDefinition -> routes.contains(routeDefinition.getId())) | |
| 33 | - .forEach(routeDefinition -> routeDefinition.getPredicates().stream() | |
| 34 | - .filter(predicateDefinition -> ("Path").equalsIgnoreCase(predicateDefinition.getName())) | |
| 35 | - .forEach(predicateDefinition -> resources.add(swaggerResource(routeDefinition.getId(), | |
| 36 | - predicateDefinition.getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0") | |
| 37 | - .replace("/**", API_URI))))); | |
| 38 | - return resources; | |
| 39 | - } | |
| 40 | - | |
| 41 | - private SwaggerResource swaggerResource(String name, String location) { | |
| 42 | - SwaggerResource swaggerResource = new SwaggerResource(); | |
| 43 | - swaggerResource.setName(name); | |
| 44 | - swaggerResource.setLocation(location); | |
| 45 | - swaggerResource.setSwaggerVersion("2.0"); | |
| 46 | - return swaggerResource; | |
| 47 | - } | |
| 48 | -} |
cloud/geteway/src/main/java/com/example/geteway/client/filter/SwaggerHeaderFilter.java
| ... | ... | @@ -1,36 +0,0 @@ |
| 1 | -package com.example.geteway.client.filter; | |
| 2 | - | |
| 3 | -import com.example.geteway.client.config.SwaggerProvider; | |
| 4 | -import org.springframework.cloud.gateway.filter.GatewayFilter; | |
| 5 | -import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; | |
| 6 | -import org.springframework.http.server.reactive.ServerHttpRequest; | |
| 7 | -import org.springframework.stereotype.Component; | |
| 8 | -import org.springframework.util.StringUtils; | |
| 9 | -import org.springframework.web.server.ServerWebExchange; | |
| 10 | - | |
| 11 | -/** | |
| 12 | - * Spring 已修复该功能 | |
| 13 | - */ | |
| 14 | -@Component | |
| 15 | -@Deprecated | |
| 16 | -public class SwaggerHeaderFilter extends AbstractGatewayFilterFactory { | |
| 17 | - private static final String HEADER_NAME = "X-Forwarded-Prefix"; | |
| 18 | - | |
| 19 | - @Override | |
| 20 | - public GatewayFilter apply(Object config) { | |
| 21 | - return (exchange, chain) -> { | |
| 22 | - ServerHttpRequest request = exchange.getRequest(); | |
| 23 | - String path = request.getURI().getPath(); | |
| 24 | - if (!StringUtils.endsWithIgnoreCase(path, SwaggerProvider.API_URI)) { | |
| 25 | - return chain.filter(exchange); | |
| 26 | - } | |
| 27 | - | |
| 28 | - String basePath = path.substring(0, path.lastIndexOf(SwaggerProvider.API_URI)); | |
| 29 | - | |
| 30 | - | |
| 31 | - ServerHttpRequest newRequest = request.mutate().header(HEADER_NAME, basePath).build(); | |
| 32 | - ServerWebExchange newExchange = exchange.mutate().request(newRequest).build(); | |
| 33 | - return chain.filter(newExchange); | |
| 34 | - }; | |
| 35 | - } | |
| 36 | -} |
cloud/geteway/src/main/java/com/example/geteway/client/handler/SwaggerHandler.java
| ... | ... | @@ -1,45 +0,0 @@ |
| 1 | -package com.example.geteway.client.handler; | |
| 2 | - | |
| 3 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 4 | -import org.springframework.http.HttpStatus; | |
| 5 | -import org.springframework.http.ResponseEntity; | |
| 6 | -import org.springframework.web.bind.annotation.GetMapping; | |
| 7 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 8 | -import org.springframework.web.bind.annotation.RestController; | |
| 9 | -import reactor.core.publisher.Mono; | |
| 10 | -import springfox.documentation.swagger.web.*; | |
| 11 | - | |
| 12 | -import java.util.Optional; | |
| 13 | - | |
| 14 | -@RestController | |
| 15 | -@RequestMapping("/swagger-resources") | |
| 16 | -public class SwaggerHandler { | |
| 17 | - @Autowired(required = false) | |
| 18 | - private SecurityConfiguration securityConfiguration; | |
| 19 | - @Autowired(required = false) | |
| 20 | - private UiConfiguration uiConfiguration; | |
| 21 | - private final SwaggerResourcesProvider swaggerResources; | |
| 22 | - | |
| 23 | - @Autowired | |
| 24 | - public SwaggerHandler(SwaggerResourcesProvider swaggerResources) { | |
| 25 | - this.swaggerResources = swaggerResources; | |
| 26 | - } | |
| 27 | - | |
| 28 | - | |
| 29 | - @GetMapping("/configuration/security") | |
| 30 | - public Mono<ResponseEntity<SecurityConfiguration>> securityConfiguration() { | |
| 31 | - return Mono.just(new ResponseEntity<>( | |
| 32 | - Optional.ofNullable(securityConfiguration).orElse(SecurityConfigurationBuilder.builder().build()), HttpStatus.OK)); | |
| 33 | - } | |
| 34 | - | |
| 35 | - @GetMapping("/configuration/ui") | |
| 36 | - public Mono<ResponseEntity<UiConfiguration>> uiConfiguration() { | |
| 37 | - return Mono.just(new ResponseEntity<>( | |
| 38 | - Optional.ofNullable(uiConfiguration).orElse(UiConfigurationBuilder.builder().build()), HttpStatus.OK)); | |
| 39 | - } | |
| 40 | - | |
| 41 | - @GetMapping("") | |
| 42 | - public Mono<ResponseEntity> swaggerResources() { | |
| 43 | - return Mono.just((new ResponseEntity<>(swaggerResources.get(), HttpStatus.OK))); | |
| 44 | - } | |
| 45 | -} |
cloud/geteway/src/main/resources/application.yml
| ... | ... | @@ -1,23 +0,0 @@ |
| 1 | -eureka: | |
| 2 | - client: | |
| 3 | - fetch-registry: true | |
| 4 | - register-with-eureka: true | |
| 5 | - service-url: | |
| 6 | -# defaultZone: http://localhost:8761/eureka/ | |
| 7 | - defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/ | |
| 8 | - instance: | |
| 9 | - hostname: localhost | |
| 10 | - lease-expiration-duration-in-seconds: 90 | |
| 11 | - lease-renewal-interval-in-seconds: 10 | |
| 12 | - prefer-ip-address: true | |
| 13 | - | |
| 14 | -spring: | |
| 15 | - cloud: | |
| 16 | - gateway: | |
| 17 | - routes: | |
| 18 | - - id: haikangserver | |
| 19 | - uri: lb://haikangserver | |
| 20 | - predicates: | |
| 21 | - - Path=/haikangserver/** | |
| 22 | - filters: | |
| 23 | - - StripPrefix=1 |
cloud/geteway/src/main/resources/bootstrap.yml
| ... | ... | @@ -1,23 +0,0 @@ |
| 1 | -#端口 | |
| 2 | -server: | |
| 3 | - port: 8083 | |
| 4 | - | |
| 5 | -#服务名称 | |
| 6 | -spring: | |
| 7 | - application: | |
| 8 | - name: sincere_geteway | |
| 9 | - main: | |
| 10 | - allow-bean-definition-overriding: true | |
| 11 | - | |
| 12 | - | |
| 13 | -management: | |
| 14 | - endpoints: | |
| 15 | - web: | |
| 16 | - exposure: | |
| 17 | - include: "*" | |
| 18 | - endpoint: | |
| 19 | - health: | |
| 20 | - show-details: always | |
| 21 | - | |
| 22 | - | |
| 23 | - | |
| 24 | 0 | \ No newline at end of file |
cloud/geteway/src/test/java/com/example/geteway/GetewayApplicationTests.java
| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | -package com.example.geteway; | |
| 2 | - | |
| 3 | -import org.junit.Test; | |
| 4 | -import org.junit.runner.RunWith; | |
| 5 | -import org.springframework.boot.test.context.SpringBootTest; | |
| 6 | -import org.springframework.test.context.junit4.SpringRunner; | |
| 7 | - | |
| 8 | -@RunWith(SpringRunner.class) | |
| 9 | -@SpringBootTest | |
| 10 | -public class GetewayApplicationTests { | |
| 11 | - | |
| 12 | - @Test | |
| 13 | - public void contextLoads() { | |
| 14 | - } | |
| 15 | - | |
| 16 | -} |
cloud/pom.xml
| ... | ... | @@ -28,8 +28,8 @@ |
| 28 | 28 | <module>server1</module> |
| 29 | 29 | <module>server2</module> |
| 30 | 30 | <!-- <module>autho</module>--> |
| 31 | -<!-- <module>common</module>--> | |
| 32 | - <module>geteway</module> | |
| 31 | + <module>common</module> | |
| 32 | + <module>getaway</module> | |
| 33 | 33 | <module>haikang</module> |
| 34 | 34 | <!-- <module>dahua</module>--> |
| 35 | 35 | <!-- <module>consumer</module>--> |
| ... | ... | @@ -42,6 +42,7 @@ |
| 42 | 42 | <!-- <module>independence</module>--> |
| 43 | 43 | <!-- <module>quartz</module>--> |
| 44 | 44 | <!-- <module>zkAttendance</module>--> |
| 45 | + <module>user_search</module> | |
| 45 | 46 | </modules> |
| 46 | 47 | |
| 47 | 48 | <dependencies> |
| ... | ... | @@ -51,18 +52,6 @@ |
| 51 | 52 | <version>1.2.58</version> |
| 52 | 53 | <scope>compile</scope> |
| 53 | 54 | </dependency> |
| 54 | - | |
| 55 | - <dependency> | |
| 56 | - <groupId>org.projectlombok</groupId> | |
| 57 | - <artifactId>lombok</artifactId> | |
| 58 | - <version>1.18.8</version> | |
| 59 | - </dependency> | |
| 60 | - | |
| 61 | - <dependency> | |
| 62 | - <groupId>org.springframework.cloud</groupId> | |
| 63 | - <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> | |
| 64 | - </dependency> | |
| 65 | - | |
| 66 | 55 | <dependency> |
| 67 | 56 | <groupId>org.springframework.cloud</groupId> |
| 68 | 57 | <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> | ... | ... |
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | +package com.sincere.quartz; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 4 | +import com.netflix.ribbon.proxy.annotation.Http; | |
| 5 | +import com.sincere.common.util.HttpClientUtils; | |
| 6 | + | |
| 7 | +public class Test { | |
| 8 | + | |
| 9 | + public static void main(String[] args){ | |
| 10 | + for(int i = 1 ; i < 5000 ; i++){ | |
| 11 | + | |
| 12 | + String infoUrl = "https://static-data.eol.cn/www/2.0/school/"+i+"/info.json" ; | |
| 13 | + String gradePointUrl = "https://api.eol.cn/gkcx/api/?access_token=&local_province_id=33&local_type_id=3&page=1&school_id="+i+"&signsafe=&size=10&uri=apidata/api/gk/score/province&year=" ; | |
| 14 | + String prefessionUrl = "https://static-data.eol.cn/www/2.0/school/"+i+"/pc_special.json" ; | |
| 15 | + | |
| 16 | + JSONObject infoResult = HttpClientUtils.httpGet(infoUrl) ; | |
| 17 | + JSONObject gradePointResult = HttpClientUtils.httpGet(gradePointUrl); | |
| 18 | + JSONObject prefessionResult = HttpClientUtils.httpGet(prefessionUrl); | |
| 19 | + | |
| 20 | + System.out.println(1); | |
| 21 | + } | |
| 22 | + } | |
| 23 | +} | ... | ... |
cloud/quartz/src/main/java/com/sincere/quartz/third/yixueyun/YXYWriteService.java
| ... | ... | @@ -109,10 +109,14 @@ public class YXYWriteService { |
| 109 | 109 | for(String subject : subjectList){ |
| 110 | 110 | subjects.append(subject).append(","); |
| 111 | 111 | } |
| 112 | - object.put("subjects",subjects.toString().substring(0,subjects.toString().length()-1)); | |
| 113 | - array.add(object); | |
| 114 | - YXYResult result = getResult(prefix_url+suffix_subject_add,array.toJSONString()) ; | |
| 115 | - scFeign.updateSchool(school.getSchoolId()); | |
| 112 | + try{ | |
| 113 | + object.put("subjects",subjects.toString().substring(0,subjects.toString().length()-1)); | |
| 114 | + array.add(object); | |
| 115 | + YXYResult result = getResult(prefix_url+suffix_subject_add,array.toJSONString()) ; | |
| 116 | + scFeign.updateSchool(school.getSchoolId()); | |
| 117 | + }catch (Exception e){ | |
| 118 | + | |
| 119 | + } | |
| 116 | 120 | } |
| 117 | 121 | |
| 118 | 122 | private void syncDept(SyncSchoolDto school , List<SyncDeptDto> deptList){ |
| ... | ... | @@ -184,7 +188,7 @@ public class YXYWriteService { |
| 184 | 188 | } |
| 185 | 189 | } |
| 186 | 190 | }else { |
| 187 | - System.out.println(result.getMessage()); | |
| 191 | + errorOut(result); | |
| 188 | 192 | } |
| 189 | 193 | } |
| 190 | 194 | if(updateDept.size() > 0){ |
| ... | ... | @@ -199,7 +203,7 @@ public class YXYWriteService { |
| 199 | 203 | } |
| 200 | 204 | } |
| 201 | 205 | }else { |
| 202 | - System.out.println(result.getMessage()); | |
| 206 | + errorOut(result); | |
| 203 | 207 | } |
| 204 | 208 | for(SyncDeptDto deptDto : updateDept){ |
| 205 | 209 | if(!errorList.contains(deptDto.getDeptName())){ |
| ... | ... | @@ -225,7 +229,7 @@ public class YXYWriteService { |
| 225 | 229 | } |
| 226 | 230 | } |
| 227 | 231 | }else { |
| 228 | - System.out.println(result.getMessage()); | |
| 232 | + errorOut(result); | |
| 229 | 233 | } |
| 230 | 234 | for(SyncDeptDto deptDto : deleteDept){ |
| 231 | 235 | if(!errorList.contains(deptDto.getDeptName())){ |
| ... | ... | @@ -259,12 +263,10 @@ public class YXYWriteService { |
| 259 | 263 | deptRelationDto.setState(1); |
| 260 | 264 | scFeign.updateDeptRelation(deptRelationDto); |
| 261 | 265 | scFeign.updateDept(syncDeptDto.getId()); |
| 262 | - }else { | |
| 263 | - | |
| 264 | 266 | } |
| 265 | 267 | } |
| 266 | 268 | }else { |
| 267 | - System.out.println(result.getMessage()); | |
| 269 | + errorOut(result); | |
| 268 | 270 | } |
| 269 | 271 | } |
| 270 | 272 | if(updateGrade.size() > 0){ |
| ... | ... | @@ -279,7 +281,7 @@ public class YXYWriteService { |
| 279 | 281 | } |
| 280 | 282 | } |
| 281 | 283 | }else { |
| 282 | - System.out.println(result.getMessage()); | |
| 284 | + errorOut(result); | |
| 283 | 285 | } |
| 284 | 286 | for(SyncDeptDto deptDto : updateGrade){ |
| 285 | 287 | if(!errorList.contains(deptDto.getDeptName())){ |
| ... | ... | @@ -305,7 +307,7 @@ public class YXYWriteService { |
| 305 | 307 | } |
| 306 | 308 | } |
| 307 | 309 | }else { |
| 308 | - System.out.println(result.getMessage()); | |
| 310 | + errorOut(result); | |
| 309 | 311 | } |
| 310 | 312 | for(SyncDeptDto deptDto : deleteGrade){ |
| 311 | 313 | if(!errorList.contains(deptDto.getDeptName())){ |
| ... | ... | @@ -339,12 +341,10 @@ public class YXYWriteService { |
| 339 | 341 | deptRelationDto.setState(1); |
| 340 | 342 | scFeign.updateDeptRelation(deptRelationDto); |
| 341 | 343 | scFeign.updateDept(syncDeptDto.getId()); |
| 342 | - }else { | |
| 343 | - | |
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | }else { |
| 347 | - System.out.println(result.getMessage()); | |
| 347 | + errorOut(result); | |
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | 350 | if(updateClass.size() > 0){ |
| ... | ... | @@ -359,7 +359,7 @@ public class YXYWriteService { |
| 359 | 359 | } |
| 360 | 360 | } |
| 361 | 361 | }else { |
| 362 | - System.out.println(result.getMessage()); | |
| 362 | + errorOut(result); | |
| 363 | 363 | } |
| 364 | 364 | for(SyncDeptDto deptDto : updateClass){ |
| 365 | 365 | if(!errorList.contains(deptDto.getDeptName())){ |
| ... | ... | @@ -385,7 +385,7 @@ public class YXYWriteService { |
| 385 | 385 | } |
| 386 | 386 | } |
| 387 | 387 | }else { |
| 388 | - System.out.println(result.getMessage()); | |
| 388 | + errorOut(result); | |
| 389 | 389 | } |
| 390 | 390 | for(SyncDeptDto deptDto : deleteClass){ |
| 391 | 391 | if(!errorList.contains(deptDto.getDeptName())){ |
| ... | ... | @@ -422,7 +422,7 @@ public class YXYWriteService { |
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | }else { |
| 425 | - System.out.println(result.getMessage()); | |
| 425 | + errorOut(result); | |
| 426 | 426 | } |
| 427 | 427 | } |
| 428 | 428 | if(updateStudentList.size() > 0){ |
| ... | ... | @@ -437,7 +437,7 @@ public class YXYWriteService { |
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | 439 | }else { |
| 440 | - System.out.println(result.getMessage()); | |
| 440 | + errorOut(result); | |
| 441 | 441 | } |
| 442 | 442 | for(SyncUserDto user : updateStudentList){ |
| 443 | 443 | if(!errorList.contains(user.getYxyUserId())){ |
| ... | ... | @@ -463,7 +463,7 @@ public class YXYWriteService { |
| 463 | 463 | } |
| 464 | 464 | } |
| 465 | 465 | }else { |
| 466 | - System.out.println(result.getMessage()); | |
| 466 | + errorOut(result); | |
| 467 | 467 | } |
| 468 | 468 | for(SyncUserDto user : deleteStudentList){ |
| 469 | 469 | if(!errorList.contains(user.getYxyUserId())){ |
| ... | ... | @@ -500,7 +500,7 @@ public class YXYWriteService { |
| 500 | 500 | } |
| 501 | 501 | } |
| 502 | 502 | }else { |
| 503 | - System.out.println(result.getMessage()); | |
| 503 | + errorOut(result); | |
| 504 | 504 | } |
| 505 | 505 | } |
| 506 | 506 | if(updateTeacherList.size() > 0){ |
| ... | ... | @@ -515,7 +515,7 @@ public class YXYWriteService { |
| 515 | 515 | } |
| 516 | 516 | } |
| 517 | 517 | }else { |
| 518 | - System.out.println(result.getMessage()); | |
| 518 | + errorOut(result); | |
| 519 | 519 | } |
| 520 | 520 | for(SyncUserDto user : updateTeacherList){ |
| 521 | 521 | if(!errorList.contains(user.getYxyUserId())){ |
| ... | ... | @@ -541,7 +541,7 @@ public class YXYWriteService { |
| 541 | 541 | } |
| 542 | 542 | } |
| 543 | 543 | }else { |
| 544 | - System.out.println(result.getMessage()); | |
| 544 | + errorOut(result); | |
| 545 | 545 | } |
| 546 | 546 | for(SyncUserDto user : deleteTeacherList){ |
| 547 | 547 | if(!errorList.contains(user.getYxyUserId())){ |
| ... | ... | @@ -626,6 +626,10 @@ public class YXYWriteService { |
| 626 | 626 | object.put("name",user.getName()); |
| 627 | 627 | object.put("mobile",user.getMobile()); |
| 628 | 628 | object.put("sex",user.getSex()); |
| 629 | + //添加教师 任职任课关系 | |
| 630 | + JSONArray orgs = new JSONArray(); | |
| 631 | + | |
| 632 | + object.put("userOrgs",orgs); | |
| 629 | 633 | array.add(object); |
| 630 | 634 | } |
| 631 | 635 | return array ; |
| ... | ... | @@ -726,4 +730,14 @@ public class YXYWriteService { |
| 726 | 730 | |
| 727 | 731 | } |
| 728 | 732 | |
| 733 | + | |
| 734 | + private void errorOut(YXYResult result){ | |
| 735 | + try{ | |
| 736 | + for(YXYResultDetail detail : result.getData()){ | |
| 737 | + logger.info(detail.getErr()); | |
| 738 | + } | |
| 739 | + }catch (Exception e){ | |
| 740 | + | |
| 741 | + } | |
| 742 | + } | |
| 729 | 743 | } | ... | ... |
cloud/server1/pom.xml
| ... | ... | @@ -14,23 +14,6 @@ |
| 14 | 14 | <description>Demo project for Spring Boot</description> |
| 15 | 15 | |
| 16 | 16 | <dependencies> |
| 17 | - | |
| 18 | - <dependency> | |
| 19 | - <groupId>com.aliyun.oss</groupId> | |
| 20 | - <artifactId>oss</artifactId> | |
| 21 | - <scope>system</scope> | |
| 22 | - <version>1</version> | |
| 23 | - <systemPath>${project.basedir}/libs/aliyun-sdk-oss-3.8.0.jar</systemPath> | |
| 24 | - </dependency> | |
| 25 | - | |
| 26 | - <dependency> | |
| 27 | - <groupId>com.jdom</groupId> | |
| 28 | - <artifactId>jdom</artifactId> | |
| 29 | - <scope>system</scope> | |
| 30 | - <version>1</version> | |
| 31 | - <systemPath>${project.basedir}/libs/jdom-1.1.jar</systemPath> | |
| 32 | - </dependency> | |
| 33 | - | |
| 34 | 17 | <dependency> |
| 35 | 18 | <groupId>org.springframework.cloud</groupId> |
| 36 | 19 | <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> | ... | ... |
cloud/server1/src/main/java/com/sincere/server1/Test2.java
| ... | ... | @@ -1,91 +0,0 @@ |
| 1 | -package com.sincere.server1; | |
| 2 | - | |
| 3 | -import com.aliyun.oss.OSS; | |
| 4 | -import com.aliyun.oss.OSSClientBuilder; | |
| 5 | - | |
| 6 | -import java.io.*; | |
| 7 | -import java.net.URL; | |
| 8 | - | |
| 9 | -public class Test2 { | |
| 10 | - | |
| 11 | - // Endpoint以杭州为例,其它Region请按实际情况填写。 | |
| 12 | - public static String endpoint = "http://oss-cn-hangzhou.aliyuncs.com"; | |
| 13 | - // 云账号AccessKey有所有API访问权限,建议遵循阿里云安全最佳实践,创建并使用RAM子账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建。 | |
| 14 | - public static String accessKeyId = "QiuM3PwHTnVotcGy"; | |
| 15 | - public static String accessKeySecret = "Yqs7RlaC1MioZu2YYJ6u0TdeO13VFC"; | |
| 16 | - | |
| 17 | - public static void main(String[] args) { | |
| 18 | - File filePath = new File("D:\\OSS\\video.txt"); | |
| 19 | - try { | |
| 20 | - BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath)); | |
| 21 | - | |
| 22 | - String cotnent = null; | |
| 23 | - | |
| 24 | - int index = 0; | |
| 25 | - while ((cotnent=bufferedReader.readLine())!=null){ | |
| 26 | - | |
| 27 | - upLoadNetStraeam(cotnent,"",cotnent.substring(cotnent.lastIndexOf("/")+1,cotnent.length())); | |
| 28 | - index++; | |
| 29 | - System.out.println("index:"+index); | |
| 30 | - | |
| 31 | - } | |
| 32 | - | |
| 33 | - } catch (FileNotFoundException e) { | |
| 34 | - e.printStackTrace(); | |
| 35 | - } catch (IOException e) { | |
| 36 | - e.printStackTrace(); | |
| 37 | - } | |
| 38 | -// File[] files = filePath.listFiles(); | |
| 39 | -// upLoadNetStraeam("http://0575jyzx.oss-cn-hangzhou.aliyuncs.com/Air/Data/898b208f82574ddcba2d439a1e28bd39.mp4", "test", "898b208f82574ddcba2d439a1e28bd39.mp4"); | |
| 40 | - /* for (File file: | |
| 41 | - files) { | |
| 42 | - | |
| 43 | - upload(file,"Data"); | |
| 44 | - | |
| 45 | - }*/ | |
| 46 | - } | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * 上传网络流 | |
| 50 | - * @param url | |
| 51 | - * @param path | |
| 52 | - * @param name | |
| 53 | - */ | |
| 54 | - public static void upLoadNetStraeam(String url, String path, String name) { | |
| 55 | - System.out.println("name:"+name+" url --"+url); | |
| 56 | -// 创建OSSClient实例。 | |
| 57 | - OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); | |
| 58 | - | |
| 59 | -// 上传网络流。 | |
| 60 | - InputStream inputStream = null; | |
| 61 | - try { | |
| 62 | - inputStream = new URL(url).openStream(); | |
| 63 | - } catch (IOException e) { | |
| 64 | - e.printStackTrace(); | |
| 65 | - } | |
| 66 | - ossClient.putObject("szyundisk", "YikeData/" + name, inputStream); | |
| 67 | - | |
| 68 | -// 关闭OSSClient。 | |
| 69 | - ossClient.shutdown(); | |
| 70 | - | |
| 71 | - } | |
| 72 | - | |
| 73 | - public static void upload(File file, String path) { | |
| 74 | - | |
| 75 | -// 创建OSSClient实例。 | |
| 76 | - OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); | |
| 77 | - | |
| 78 | -// 上传文件流。 | |
| 79 | - InputStream inputStream = null; | |
| 80 | - try { | |
| 81 | - inputStream = new FileInputStream(file); | |
| 82 | - ossClient.putObject("szyundisk", "Air/" + path + "/" + file.getName(), inputStream); | |
| 83 | - | |
| 84 | -// 关闭OSSClient。 | |
| 85 | - ossClient.shutdown(); | |
| 86 | - } catch (FileNotFoundException e) { | |
| 87 | - e.printStackTrace(); | |
| 88 | - } | |
| 89 | - } | |
| 90 | - | |
| 91 | -} |
cloud/server1/src/test/java/com/sincere/server1/Server1ApplicationTests.java
| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | -package com.sincere.server1; | |
| 2 | - | |
| 3 | -import org.junit.Test; | |
| 4 | -import org.junit.runner.RunWith; | |
| 5 | -import org.springframework.boot.test.context.SpringBootTest; | |
| 6 | -import org.springframework.test.context.junit4.SpringRunner; | |
| 7 | - | |
| 8 | -@RunWith(SpringRunner.class) | |
| 9 | -@SpringBootTest | |
| 10 | -public class Server1ApplicationTests { | |
| 11 | - | |
| 12 | - @Test | |
| 13 | - public void contextLoads() { | |
| 14 | - } | |
| 15 | - | |
| 16 | -} |
cloud/user_search/pom.xml
| ... | ... | @@ -48,14 +48,8 @@ |
| 48 | 48 | <version>6.4.0.jre8</version> |
| 49 | 49 | </dependency> |
| 50 | 50 | <dependency> |
| 51 | - <groupId>io.springfox</groupId> | |
| 52 | - <artifactId>springfox-swagger2</artifactId> | |
| 53 | - <version>2.5.0</version> | |
| 54 | - </dependency> | |
| 55 | - <dependency> | |
| 56 | - <groupId>io.springfox</groupId> | |
| 57 | - <artifactId>springfox-swagger-ui</artifactId> | |
| 58 | - <version>2.5.0</version> | |
| 51 | + <groupId>org.springframework.boot</groupId> | |
| 52 | + <artifactId>spring-boot-starter-web</artifactId> | |
| 59 | 53 | </dependency> |
| 60 | 54 | </dependencies> |
| 61 | 55 | ... | ... |
cloud/user_search/src/main/java/com/sincere/userSearch/access/MemberFilter.java
| 1 | 1 | package com.sincere.userSearch.access; |
| 2 | 2 | |
| 3 | -import com.fasterxml.jackson.databind.ObjectMapper; | |
| 4 | 3 | import com.sincere.common.exception.ResultException; |
| 5 | 4 | import com.sincere.common.util.TokenUtils; |
| 6 | 5 | import com.sincere.userSearch.vo.UserInfo; |
| ... | ... | @@ -10,8 +9,6 @@ import javax.servlet.*; |
| 10 | 9 | import javax.servlet.annotation.WebFilter; |
| 11 | 10 | import javax.servlet.http.HttpServletRequest; |
| 12 | 11 | import java.io.IOException; |
| 13 | -import java.util.HashMap; | |
| 14 | -import java.util.Map; | |
| 15 | 12 | |
| 16 | 13 | @WebFilter(urlPatterns = "/user/*") |
| 17 | 14 | public class MemberFilter implements Filter { |
| ... | ... | @@ -22,39 +19,21 @@ public class MemberFilter implements Filter { |
| 22 | 19 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { |
| 23 | 20 | |
| 24 | 21 | HttpServletRequest req = (HttpServletRequest) request; |
| 25 | - | |
| 26 | - String token = req.getHeader(token_string); | |
| 27 | - if (StringUtils.isBlank(token)) { | |
| 28 | - respFail(response,-5,"token 没有"); | |
| 29 | - return; | |
| 30 | - } | |
| 31 | - | |
| 32 | -// MemberDetails memberDetails = memberService.getMemberDetailsByToken(tokenId); | |
| 33 | -// if (memberDetails == null) this.respFail(response); | |
| 34 | - String userId = "" ; | |
| 35 | - try{ | |
| 36 | - userId = TokenUtils.validToken(token); | |
| 37 | - }catch (ResultException e){ | |
| 38 | - respFail(response,e.getCode(),e.getMessage()); | |
| 39 | - return; | |
| 40 | - } | |
| 41 | 22 | ParameterRequestWrapper requestWrapper = new ParameterRequestWrapper(req); |
| 42 | 23 | UserInfo userInfo = new UserInfo() ; |
| 43 | - userInfo.setUserId(userId); | |
| 44 | - requestWrapper.addObject(userInfo); | |
| 45 | - chain.doFilter(requestWrapper, response); | |
| 46 | - } | |
| 47 | 24 | |
| 48 | - private void respFail(ServletResponse response , int code , String message) throws IOException { | |
| 49 | - Map<String, Object> map = new HashMap<>(); | |
| 50 | - map.put("status", code); | |
| 51 | - map.put("message", message); | |
| 52 | - map.put("data", null); | |
| 53 | - ObjectMapper objectMapper = new ObjectMapper(); | |
| 54 | - String s = objectMapper.writeValueAsString(map); | |
| 55 | - response.setCharacterEncoding("UTF-8"); | |
| 56 | - response.setContentType("application/json; charset=utf-8"); | |
| 57 | - response.getWriter().write(s); | |
| 25 | + String token = req.getHeader(token_string); | |
| 26 | + if (StringUtils.isNotBlank(token)) { | |
| 27 | + try{ | |
| 28 | + String userId = TokenUtils.validToken(token); | |
| 29 | + userInfo.setUserId(userId); | |
| 30 | + requestWrapper.addObject(userInfo); | |
| 31 | + chain.doFilter(requestWrapper, response); | |
| 32 | + }catch (ResultException e){ | |
| 33 | + chain.doFilter(requestWrapper, response); | |
| 34 | + } | |
| 35 | + }else { | |
| 36 | + chain.doFilter(requestWrapper, response); | |
| 37 | + } | |
| 58 | 38 | } |
| 59 | - | |
| 60 | 39 | } | ... | ... |
cloud/user_search/src/main/java/com/sincere/userSearch/controller/UserController.java
| ... | ... | @@ -37,12 +37,11 @@ public class UserController { |
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * 用户类型 0-班主任; 1-任课老师; 2-学生; 3-家长; 10-学校管理员; |
| 40 | - * @param userId | |
| 41 | 40 | */ |
| 42 | 41 | @ApiOperation("根据userId 获取用户信息") |
| 43 | - @RequestMapping(value = "getUserInfo" , method = RequestMethod.POST) | |
| 44 | - public void getUserInfo(UserInfo userId){ | |
| 45 | - | |
| 42 | + @RequestMapping(value = "getUserInfo" , method = RequestMethod.GET) | |
| 43 | + public String getUserInfo(){ | |
| 44 | + return "aa" ; | |
| 46 | 45 | } |
| 47 | 46 | |
| 48 | 47 | public void getUserId(){ | ... | ... |