126 changed files with 1138 additions and 321 deletions
@ -0,0 +1,35 @@ |
|||
package com.epmet.commons.tools.feign; |
|||
|
|||
import feign.RequestInterceptor; |
|||
import feign.RequestTemplate; |
|||
import org.springframework.web.context.request.RequestAttributes; |
|||
import org.springframework.web.context.request.RequestContextHolder; |
|||
import org.springframework.web.context.request.ServletRequestAttributes; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.util.Enumeration; |
|||
|
|||
|
|||
public class EpmetBaseRequestInterceptor implements RequestInterceptor { |
|||
|
|||
@Override |
|||
public void apply(RequestTemplate template) { |
|||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); |
|||
if (requestAttributes == null) { |
|||
return; |
|||
} |
|||
|
|||
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); |
|||
Enumeration<String> headerNames = request.getHeaderNames(); |
|||
if (headerNames != null) { |
|||
while (headerNames.hasMoreElements()) { |
|||
String name = headerNames.nextElement(); |
|||
Enumeration<String> values = request.getHeaders(name); |
|||
while (values.hasMoreElements()) { |
|||
String value = values.nextElement(); |
|||
template.header(name, value); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
Binary file not shown.
Binary file not shown.
@ -1,2 +1,2 @@ |
|||
/*ALTER TABLE dim_agency ADD COLUMN AGENCY_DIM_TYPE VARCHAR(10) NOT NULL COMMENT '机关维度类型。self:机关本身自己,all:机关自己+下级+网格+部门等';*/ |
|||
#ALTER TABLE dim_agency ADD COLUMN AGENCY_DIM_TYPE VARCHAR(10) NOT NULL COMMENT '机关维度类型。self:机关本身自己,all:机关自己+下级+网格+部门等'; |
|||
select 1; |
@ -0,0 +1,59 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.config; |
|||
|
|||
import com.epmet.commons.tools.constant.AppClientConstant; |
|||
import com.epmet.commons.tools.feign.EpmetBaseRequestInterceptor; |
|||
import feign.RequestInterceptor; |
|||
import feign.RequestTemplate; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
/** |
|||
* Feign调用,携带header |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Configuration |
|||
public class JobFeignConfig { |
|||
|
|||
@Bean |
|||
RequestInterceptor requestInterceptor() { |
|||
return new JobRequestInterceptor(); |
|||
} |
|||
|
|||
class JobRequestInterceptor extends EpmetBaseRequestInterceptor { |
|||
@Override |
|||
public void apply(RequestTemplate template) { |
|||
super.apply(template); |
|||
|
|||
// job服务自己生成流水号
|
|||
template.header(AppClientConstant.TRANSACTION_SERIAL_KEY, generateTransactionSerial()); |
|||
} |
|||
|
|||
/** |
|||
* 获取事务流水号 |
|||
* |
|||
* @return |
|||
*/ |
|||
public String generateTransactionSerial() { |
|||
String[] letterPool = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n" |
|||
, "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}; |
|||
|
|||
StringBuilder sb = new StringBuilder(); |
|||
for (int i = 0; i < 2; i++) { |
|||
sb.append(letterPool[(int) (Math.random() * 25)]); |
|||
} |
|||
|
|||
sb.append(System.currentTimeMillis()); |
|||
return sb.toString(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,68 @@ |
|||
package com.epmet.controller; |
|||
|
|||
import com.epmet.commons.tools.utils.Result; |
|||
import com.epmet.service.OssService; |
|||
import org.apache.commons.io.FileUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.mock.web.MockMultipartFile; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import java.io.*; |
|||
import java.net.Inet4Address; |
|||
import java.net.InetAddress; |
|||
import java.net.UnknownHostException; |
|||
|
|||
@RestController |
|||
@RequestMapping("test") |
|||
public class TestController { |
|||
|
|||
@Autowired |
|||
private OssService ossService; |
|||
|
|||
@PostMapping("local-upload") |
|||
public Result localUpload(@RequestPart("file") MultipartFile file, @RequestParam("fileName") String fileName) { |
|||
|
|||
final File tempFile = new File("/opt/upload_files/" + fileName); |
|||
|
|||
try(InputStream inputStream = file.getInputStream()) { |
|||
FileUtils.copyInputStreamToFile(inputStream, tempFile); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return new Result(); |
|||
} |
|||
|
|||
@PostMapping("upload2aliyun") |
|||
public Result upload2aliyun(@RequestParam("fileName") String fileName) { |
|||
try (final FileInputStream fis = new FileInputStream("/opt/upload_files/" + fileName)) { |
|||
final MockMultipartFile mockMultipartFile = new MockMultipartFile(fileName, fis); |
|||
return ossService.uploadImg(mockMultipartFile, null); |
|||
} catch (FileNotFoundException e) { |
|||
e.printStackTrace(); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return new Result(); |
|||
} |
|||
|
|||
/** |
|||
* @Description ribbon测试 |
|||
* @return |
|||
* @author wxz |
|||
* @date 2021.08.05 16:28 |
|||
*/ |
|||
@PostMapping("test-ribbon-rcv/{sleep}") |
|||
public Result testRibbonRcv(@PathVariable("sleep") Long sleep) { |
|||
InetAddress localHost = null; |
|||
try { |
|||
Thread.sleep(sleep); |
|||
localHost = Inet4Address.getLocalHost(); |
|||
} catch (UnknownHostException e) { |
|||
e.printStackTrace(); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return new Result().ok(localHost); |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
package com.epmet.controller; |
|||
|
|||
import com.epmet.commons.tools.utils.Result; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.cloud.commons.util.InetUtils; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
@RestController |
|||
@RequestMapping("lb") |
|||
public class LbController { |
|||
|
|||
@Autowired |
|||
private InetUtils inetUtils; |
|||
|
|||
@PostMapping("get-host") |
|||
public Result getHost() { |
|||
String ipAddress = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); |
|||
return new Result().ok(ipAddress); |
|||
} |
|||
|
|||
} |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue