Commit 161c5ad1 by yuwei

2.0.0项目初始化

parent 6330de54
package cn.datax.common.utils; package cn.datax.common.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -50,6 +53,17 @@ public class HttpUtil { ...@@ -50,6 +53,17 @@ public class HttpUtil {
} }
private static String doGet(HttpServletRequest request) { private static String doGet(HttpServletRequest request) {
Map<String, Object> map = new HashMap<>();
Enumeration<String> parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements()) {
String nextElement = parameterNames.nextElement();
String parameter = request.getParameter(nextElement);
map.put(nextElement, parameter);
}
try {
return new ObjectMapper().writeValueAsString(map);
} catch (JsonProcessingException e) {
}
return null; return null;
} }
} }
...@@ -8,12 +8,9 @@ spring: ...@@ -8,12 +8,9 @@ spring:
default-encoding: utf-8 default-encoding: utf-8
properties.mail.smtp.auth: true properties.mail.smtp.auth: true
properties.mail.smtp.port: 465 properties.mail.smtp.port: 465
properties.mail.display.sendmail: 312075478@qq.com
properties.mail.display.sendname: 测试
properties.mail.smtp.starttls.enable: true properties.mail.smtp.starttls.enable: true
properties.mail.smtp.starttls.required: true properties.mail.smtp.starttls.required: true
properties.mail.smtp.ssl.enable: true properties.mail.smtp.ssl.enable: true
from: 测试1
datasource: datasource:
dynamic: dynamic:
type: com.zaxxer.hikari.HikariDataSource type: com.zaxxer.hikari.HikariDataSource
......
...@@ -13,6 +13,7 @@ import cn.datax.service.data.market.api.entity.DataApiEntity; ...@@ -13,6 +13,7 @@ import cn.datax.service.data.market.api.entity.DataApiEntity;
import cn.datax.service.data.market.api.enums.ParamType; import cn.datax.service.data.market.api.enums.ParamType;
import cn.datax.service.data.market.api.feign.DataApiServiceFeign; import cn.datax.service.data.market.api.feign.DataApiServiceFeign;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
...@@ -98,8 +99,6 @@ public class ApiInterceptor implements HandlerInterceptor { ...@@ -98,8 +99,6 @@ public class ApiInterceptor implements HandlerInterceptor {
} }
} }
} }
Map<String, String[]> parameterMap = request.getParameterMap();
System.out.println("parameterMap:" + objectMapper.writeValueAsString(parameterMap));
// 接收参数 // 接收参数
String bodyString = HttpUtil.getBodyString(request); String bodyString = HttpUtil.getBodyString(request);
Map<String, Object> params = null; Map<String, Object> params = null;
...@@ -107,14 +106,16 @@ public class ApiInterceptor implements HandlerInterceptor { ...@@ -107,14 +106,16 @@ public class ApiInterceptor implements HandlerInterceptor {
params = objectMapper.readValue(bodyString, Map.class); params = objectMapper.readValue(bodyString, Map.class);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
} }
Map<String, Object> finalParams = params; if (MapUtil.isNotEmpty(params)) {
dataApiEntity.getReqParams().stream().forEach(param -> { Map<String, Object> finalParams = params;
if (finalParams.containsKey(param.getParamName())) { dataApiEntity.getReqParams().stream().forEach(param -> {
String paramType = param.getParamType(); if (finalParams.containsKey(param.getParamName())) {
// 参数类型是否正确 String paramType = param.getParamType();
ParamType.parse(ParamType.getParamType(paramType), finalParams.get(param.getParamName())); // 参数类型是否正确
} ParamType.parse(ParamType.getParamType(paramType), finalParams.get(param.getParamName()));
}); }
});
}
String apiName = dataApiEntity.getApiName(); String apiName = dataApiEntity.getApiName();
String rateLimit = dataApiEntity.getRateLimit(); String rateLimit = dataApiEntity.getRateLimit();
rateLimit = Optional.ofNullable(rateLimit).orElse(DataConstant.TrueOrFalse.TRUE.getKey()); rateLimit = Optional.ofNullable(rateLimit).orElse(DataConstant.TrueOrFalse.TRUE.getKey());
......
...@@ -19,8 +19,8 @@ public class ApiCallController extends BaseController { ...@@ -19,8 +19,8 @@ public class ApiCallController extends BaseController {
private ApiCallService apiCallService; private ApiCallService apiCallService;
@RequestMapping(value = "/**", method = {RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value = "/**", method = {RequestMethod.GET, RequestMethod.POST})
public R apiV1(){ public R apiCall(){
PageResult<Map<String, Object>> pageResult = apiCallService.v1(); PageResult<Map<String, Object>> pageResult = apiCallService.apiCall();
return R.ok().setData(pageResult); return R.ok().setData(pageResult);
} }
} }
...@@ -6,5 +6,5 @@ import java.util.Map; ...@@ -6,5 +6,5 @@ import java.util.Map;
public interface ApiCallService { public interface ApiCallService {
PageResult<Map<String, Object>> v1(); PageResult<Map<String, Object>> apiCall();
} }
...@@ -55,7 +55,7 @@ public class ApiCallServiceImpl implements ApiCallService { ...@@ -55,7 +55,7 @@ public class ApiCallServiceImpl implements ApiCallService {
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
@Override @Override
public PageResult<Map<String, Object>> v1() { public PageResult<Map<String, Object>> apiCall() {
R apiResult = dataApiServiceFeign.getDataApiById(ThreadUtil.getInstance().get().getApiId()); R apiResult = dataApiServiceFeign.getDataApiById(ThreadUtil.getInstance().get().getApiId());
if(apiResult == null || !apiResult.isSuccess() || ObjectUtil.isEmpty(apiResult.getData())){ if(apiResult == null || !apiResult.isSuccess() || ObjectUtil.isEmpty(apiResult.getData())){
ThreadUtil.getInstance().get().setStatus(DataConstant.EnableState.DISABLE.getKey()); ThreadUtil.getInstance().get().setStatus(DataConstant.EnableState.DISABLE.getKey());
......
...@@ -3,5 +3,6 @@ package cn.datax.service.email.service; ...@@ -3,5 +3,6 @@ package cn.datax.service.email.service;
import cn.datax.service.email.api.entity.EmailEntity; import cn.datax.service.email.api.entity.EmailEntity;
public interface EmailService { public interface EmailService {
void sendEmail(EmailEntity mail); void sendEmail(EmailEntity mail);
} }
package cn.datax.service.email.service.impl; package cn.datax.service.email.service.impl;
import cn.datax.common.utils.ThrowableUtil;
import cn.datax.service.email.api.entity.EmailEntity; import cn.datax.service.email.api.entity.EmailEntity;
import cn.datax.service.email.service.EmailService; import cn.datax.service.email.service.EmailService;
import cn.datax.service.email.utils.EmailUtil; import cn.datax.service.email.utils.EmailUtil;
...@@ -16,11 +17,10 @@ public class EmailServiceImpl implements EmailService { ...@@ -16,11 +17,10 @@ public class EmailServiceImpl implements EmailService {
@Override @Override
public void sendEmail(EmailEntity emailEntity) { public void sendEmail(EmailEntity emailEntity) {
log.info("实体类 {}", emailEntity);
try { try {
emailUtil.sendEmail(emailEntity); emailUtil.sendEmail(emailEntity);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("全局异常信息ex={}, StackTrace={}", e.getMessage(), ThrowableUtil.getStackTrace(e));
} }
} }
} }
...@@ -8,22 +8,15 @@ import org.springframework.mail.javamail.JavaMailSender; ...@@ -8,22 +8,15 @@ import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
import java.io.File; import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.List; import java.util.List;
@Component @Component
public class EmailUtil { public class EmailUtil {
@Value("${spring.mail.from}")
private String fromNick;
@Value("${spring.mail.username}") @Value("${spring.mail.username}")
private String fromAddress; private String from;
@Autowired @Autowired
private JavaMailSender mailSender; private JavaMailSender mailSender;
...@@ -31,18 +24,6 @@ public class EmailUtil { ...@@ -31,18 +24,6 @@ public class EmailUtil {
public void sendEmail(EmailEntity mailEntity) throws Exception { public void sendEmail(EmailEntity mailEntity) throws Exception {
MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
InternetAddress from = null;
String alias = null;
try {
alias = MimeUtility.encodeText(fromNick);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
from = new InternetAddress(alias + " <" + fromAddress + ">");
} catch (AddressException e) {
e.printStackTrace();
}
helper.setFrom(from); helper.setFrom(from);
helper.setSubject(mailEntity.getSubject()); helper.setSubject(mailEntity.getSubject());
helper.setText(mailEntity.getText(),true); helper.setText(mailEntity.getText(),true);
......
...@@ -123,7 +123,6 @@ export default { ...@@ -123,7 +123,6 @@ export default {
this.statusOptions = response.data this.statusOptions = response.data
} }
}) })
this.getDataApiList()
this.getDicts('data_cipher_type').then(response => { this.getDicts('data_cipher_type').then(response => {
if (response.success) { if (response.success) {
this.cipherTypeOptions = response.data this.cipherTypeOptions = response.data
...@@ -141,7 +140,7 @@ export default { ...@@ -141,7 +140,7 @@ export default {
}) })
}, },
mounted () { mounted () {
this.getApiMask(this.data.id) this.init ()
}, },
methods: { methods: {
showCard () { showCard () {
...@@ -159,33 +158,36 @@ export default { ...@@ -159,33 +158,36 @@ export default {
getApiMask(id).then(response => { getApiMask(id).then(response => {
if (response.success) { if (response.success) {
this.form = response.data this.form = response.data
console.log(this.form) }
console.log(this.apiOptions) })
this.resParamList = this.apiOptions.find(function (item) { },
return item.id === this.form.apiId /** 解决异步问题 */
}).resParams async init () {
this.form.rules.forEach(rule => { await this.getDataApiList()
let fieldParamIndex = this.resParamList.findIndex((param) => { await this.getApiMask(this.data.id)
return param.fieldName === rule.fieldName this.resParamList = this.apiOptions.find(function (item) {
}) return item.id === this.form.apiId
if (fieldParamIndex !== -1) { }).resParams
let cipher = this.cipherTypeOptions.find((item) => { this.form.rules.forEach(rule => {
return item.itemText === rule.cipherType let fieldParamIndex = this.resParamList.findIndex((param) => {
}) return param.fieldName === rule.fieldName
let crypt = {} })
if (rule.cipherType === '1') { if (fieldParamIndex !== -1) {
crypt = this.regexCryptoOptions.find((item) => { let cipher = this.cipherTypeOptions.find((item) => {
return item.itemText === rule.cryptType return item.itemText === rule.cipherType
})
} else if (rule.cipherType === '2') {
crypt = this.algorithmCryptoOptions.find((item) => {
return item.itemText === rule.cryptType
})
}
let resParam = Object.assign({}, this.resParamList[fieldParamIndex], { cipherType: (cipher && cipher.itemValue) || undefined, cryptType: (crypt && crypt.itemValue) || undefined })
this.$set(this.resParamList, fieldParamIndex, resParam)
}
}) })
let crypt = {}
if (rule.cipherType === '1') {
crypt = this.regexCryptoOptions.find((item) => {
return item.itemText === rule.cryptType
})
} else if (rule.cipherType === '2') {
crypt = this.algorithmCryptoOptions.find((item) => {
return item.itemText === rule.cryptType
})
}
let resParam = Object.assign({}, this.resParamList[fieldParamIndex], { cipherType: (cipher && cipher.itemValue) || undefined, cryptType: (crypt && crypt.itemValue) || undefined })
this.$set(this.resParamList, fieldParamIndex, resParam)
} }
}) })
} }
......
...@@ -192,7 +192,6 @@ export default { ...@@ -192,7 +192,6 @@ export default {
this.statusOptions = response.data this.statusOptions = response.data
} }
}) })
this.getDataApiList()
this.getDicts('data_cipher_type').then(response => { this.getDicts('data_cipher_type').then(response => {
if (response.success) { if (response.success) {
this.cipherTypeOptions = response.data this.cipherTypeOptions = response.data
...@@ -210,7 +209,7 @@ export default { ...@@ -210,7 +209,7 @@ export default {
}) })
}, },
mounted () { mounted () {
this.getApiMask(this.data.id) this.init()
}, },
methods: { methods: {
showCard () { showCard () {
...@@ -228,31 +227,36 @@ export default { ...@@ -228,31 +227,36 @@ export default {
getApiMask(id).then(response => { getApiMask(id).then(response => {
if (response.success) { if (response.success) {
this.form = response.data this.form = response.data
this.resParamList = this.apiOptions.find(function (item) { }
return item.id === this.form.apiId })
}).resParams },
this.form.rules.forEach(rule => { /** 解决异步问题 */
let fieldParamIndex = this.resParamList.findIndex((param) => { async init () {
return param.fieldName === rule.fieldName await this.getDataApiList()
}) await this.getApiMask(this.data.id)
if (fieldParamIndex !== -1) { this.resParamList = this.apiOptions.find(function (item) {
let cipher = this.cipherTypeOptions.find((item) => { return item.id === this.form.apiId
return item.itemText === rule.cipherType }).resParams
}) this.form.rules.forEach(rule => {
let crypt = {} let fieldParamIndex = this.resParamList.findIndex((param) => {
if (rule.cipherType === '1') { return param.fieldName === rule.fieldName
crypt = this.regexCryptoOptions.find((item) => { })
return item.itemText === rule.cryptType if (fieldParamIndex !== -1) {
}) let cipher = this.cipherTypeOptions.find((item) => {
} else if (rule.cipherType === '2') { return item.itemText === rule.cipherType
crypt = this.algorithmCryptoOptions.find((item) => {
return item.itemText === rule.cryptType
})
}
let resParam = Object.assign({}, this.resParamList[fieldParamIndex], { cipherType: (cipher && cipher.itemValue) || undefined, cryptType: (crypt && crypt.itemValue) || undefined })
this.$set(this.resParamList, fieldParamIndex, resParam)
}
}) })
let crypt = {}
if (rule.cipherType === '1') {
crypt = this.regexCryptoOptions.find((item) => {
return item.itemText === rule.cryptType
})
} else if (rule.cipherType === '2') {
crypt = this.algorithmCryptoOptions.find((item) => {
return item.itemText === rule.cryptType
})
}
let resParam = Object.assign({}, this.resParamList[fieldParamIndex], { cipherType: (cipher && cipher.itemValue) || undefined, cryptType: (crypt && crypt.itemValue) || undefined })
this.$set(this.resParamList, fieldParamIndex, resParam)
} }
}) })
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment