接口可以,图片不可以

version1
anthonywj 2 years ago
parent 6d43783fb5
commit fcc904853b

@ -6,9 +6,12 @@ import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -28,115 +31,170 @@ import com.glxp.sale.common.res.BaseResponse;
/** /**
* *
*/ */
@Slf4j
@RestController @RestController
public class IdcController { public class IdcController {
@Resource @Resource
IdcService idcService; IdcService idcService;
@Resource @Resource
DbDao dbDao; DbDao dbDao;
/*通用上传接口*/
//@Log("中继服务数据接收,下级往上级上传") /*通用上传接口*/
@RequestMapping(value = "/spssync/common/upload") //@Log("中继服务数据接收,下级往上级上传")
public BaseResponse upload(HttpServletRequest request, @RequestMapping(value = "/spssync/common/upload")
@RequestParam("content") String content, public BaseResponse upload(HttpServletRequest request,
@RequestParam(value = "files", required = false) MultipartFile[] files) { @RequestParam("content") String content,
// @RequestParam(value = "files", required = false) MultipartFile[] files) {
return idcService.receive("U",request, content, files); //
} return idcService.receive("U", request, content, files);
/*通用下发接口*/ }
//@Log("中继服务数据接收,上级往下级下发")
@RequestMapping(value = "/spssync/common/issued") /*通用下发接口*/
public BaseResponse issued(HttpServletRequest request, //@Log("中继服务数据接收,上级往下级下发")
@RequestParam("content") String content, @RequestMapping(value = "/spssync/common/issued")
@RequestParam(value = "files", required = false) MultipartFile[] files) { public BaseResponse issued(HttpServletRequest request,
// @RequestParam("content") String content,
return idcService.receive("I",request, content, files); @RequestParam(value = "files", required = false) MultipartFile[] files) {
} //
return idcService.receive("I", request, content, files);
//@Log("数据同步测试") }
@RequestMapping(value = "/spssync/common/test")
public BaseResponse test(HttpServletRequest request,@RequestBody Map<String, Object> params) { //@Log("数据同步测试")
// @RequestMapping(value = "/spssync/common/test")
return idcService.send(params); public BaseResponse test(HttpServletRequest request, @RequestBody Map<String, Object> params) {
} //
return idcService.send(params);
//@Log("数据同步任务列表拉取") }
@RequestMapping(value = "/spssync/common/list")
public BaseResponse list(HttpServletRequest request,@RequestBody(required = false) Map<String, Object> params) { //@Log("数据同步任务列表拉取")
return idcService.taskList(request,params); @RequestMapping(value = "/spssync/common/list")
} public BaseResponse list(HttpServletRequest request, @RequestBody(required = false) Map<String, Object> params) {
return idcService.taskList(request, params);
//@Log("数据同步任务根据任务ID下载数据") }
@RequestMapping(value = "/spssync/common/download")
@ResponseBody //@Log("数据同步任务根据任务ID下载数据")
public BaseResponse download(HttpServletRequest request,@RequestBody Map<String, Object> params) { @RequestMapping(value = "/spssync/common/download")
return idcService.download(request,params); @ResponseBody
} public BaseResponse download(HttpServletRequest request, @RequestBody Map<String, Object> params) {
return idcService.download(request, params);
//@Log("数据同步任务根据任务ID,返回下载成功标记") }
@RequestMapping(value = "/spssync/common/success")
@ResponseBody //@Log("数据同步任务根据任务ID,返回下载成功标记")
public BaseResponse success(HttpServletRequest request,@RequestBody Map<String, Object> params) { @RequestMapping(value = "/spssync/common/success")
return idcService.downlaodSuccess(request,params); @ResponseBody
} public BaseResponse success(HttpServletRequest request, @RequestBody Map<String, Object> params) {
return idcService.downlaodSuccess(request, params);
@RequestMapping("/mapi/**") }
public JSONObject mapi(HttpServletRequest request) {
@RequestMapping("/mapi/**")
return redirect(request); public Object mapi(HttpServletRequest request) {
} String uri = parseUri(request.getRequestURL().toString());
@RequestMapping("/zapi/**")
public JSONObject zapi(HttpServletRequest request) { if (uri.contains("image")) {
return redirectIamge(request, uri);
return redirect(request); } else {
} return redirect(request, uri);
private JSONObject redirect(HttpServletRequest request) { }
String uri = parseUri(request.getRequestURL().toString()); }
RestTemplate restTemplate = new RestTemplate();
HttpEntity<String> buildHeader(HttpServletRequest request) {
Map<String,Object> headerParam = new HashMap<>();
Map<String, Object> bodyParam = new HashMap<String,Object>(); log.info(request.getMethod());
Enumeration pNames=request.getParameterNames(); Map<String, Object> headerParam = new HashMap<>();
while(pNames.hasMoreElements()){ Map<String, Object> bodyParam = new HashMap<String, Object>();
String name=(String)pNames.nextElement(); Enumeration pNames = request.getParameterNames();
String value=request.getParameter(name); while (pNames.hasMoreElements()) {
bodyParam.put(name, value); String name = (String) pNames.nextElement();
} String value = request.getParameter(name);
HttpHeaders headers = new HttpHeaders(); bodyParam.put(name, value);
Enumeration<String> enumeration = request.getHeaderNames(); }
HttpHeaders headers = new HttpHeaders();
Enumeration<String> enumeration = request.getHeaderNames();
while (enumeration.hasMoreElements()) { while (enumeration.hasMoreElements()) {
String name = enumeration.nextElement(); String name = enumeration.nextElement();
String value = request.getHeader(name); String value = request.getHeader(name);
headerParam.put(name, value); headerParam.put(name, value);
headers.add(name, value); headers.add(name, value);
} }
//headers.add("Content-Type", "application/json;charset=UTF-8");
HttpEntity<String> http = new HttpEntity<>(JSON.toJSONString(bodyParam), headers);
return http;
}
private Resource redirectIamge(HttpServletRequest request, String uri) {
uri = uri.replace("mapi/", "");
uri = "http://127.0.0.1:9993/" + uri;
RestTemplate restTemplate = new RestTemplate();
// HttpEntity<String> httpEntity = buildHeader(request);
log.info(request.getMethod());
Map<String, Object> headerParam = new HashMap<>();
Map<String, Object> bodyParam = new HashMap<String, Object>();
Enumeration pNames = request.getParameterNames();
String parm = "";
while (pNames.hasMoreElements()) {
String name = (String) pNames.nextElement();
String value = request.getParameter(name);
bodyParam.put(name, value);
parm = parm + name + "=" + value + "&";
}
uri = uri + "?" + parm.substring(0, parm.length() - 1);
HttpHeaders headers = new HttpHeaders();
Enumeration<String> enumeration = request.getHeaderNames();
while (enumeration.hasMoreElements()) {
String name = enumeration.nextElement();
String value = request.getHeader(name);
headerParam.put(name, value);
headers.add(name, value);
}
//headers.add("Content-Type", "application/json;charset=UTF-8");
HttpEntity<String> http = new HttpEntity<>(JSON.toJSONString(bodyParam), headers);
log.info(uri);
// ResponseEntity<Resource> entity = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, Resource.class);
ResponseEntity<Resource> responseEntity = restTemplate.exchange(uri,
HttpMethod.GET, http, Resource.class, new Object[0]);
// ResponseEntity<HttpServletResponse> responseEntity = restTemplate.exchange(uri, HttpMethod.GET, http, HttpServletResponse.class);
return responseEntity.getBody();
//headers.add("Content-Type", "application/json;charset=UTF-8");
System.out.print(JSON.toJSONString(headerParam));
System.out.print(JSON.toJSONString(bodyParam));
HttpEntity<String> http = new HttpEntity<>(JSON.toJSONString(bodyParam), headers);
ResponseEntity<JSONObject> responseBody = restTemplate.postForEntity("http://127.0.0.1:8090/"+uri, http, JSONObject.class);
JSONObject result = responseBody.getBody();
return result;
} }
private JSONObject redirect(HttpServletRequest request, String uri) {
private String parseUri(String url) { RestTemplate restTemplate = new RestTemplate();
String uri = url; HttpEntity<String> httpEntity = buildHeader(request);
int a1 = uri.indexOf("://"); log.info(uri);
int a2 = 0; uri = uri.replace("mapi/", "");
if(a1>0) { uri = "http://127.0.0.1:9993/" + uri;
a2 = uri.indexOf("/",a1 +4); log.info(uri);
if(a2>0) { ResponseEntity<JSONObject> responseBody = null;
uri = uri.substring(a2 +1); if (request.getMethod().equals("POST"))
} responseBody = restTemplate.postForEntity(uri, httpEntity, JSONObject.class);
} else if (request.getMethod().equals("GET")) {
return uri; responseBody = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, JSONObject.class);
} } else if (request.getMethod().equals("PUT")) {
responseBody = restTemplate.exchange(uri, HttpMethod.PUT, httpEntity, JSONObject.class);
} else if (request.getMethod().equals("DELETE")) {
responseBody = restTemplate.exchange(uri, HttpMethod.DELETE, httpEntity, JSONObject.class);
}
JSONObject result = responseBody.getBody();
return result;
}
private String parseUri(String url) {
String uri = url;
int a1 = uri.indexOf("://");
int a2 = 0;
if (a1 > 0) {
a2 = uri.indexOf("/", a1 + 4);
if (a2 > 0) {
uri = uri.substring(a2 + 1);
}
}
return uri;
}
} }

@ -20,13 +20,13 @@ import com.glxp.sale.admin.req.info.ScheduledRequest;
public class AsyncFetchTask implements SchedulingConfigurer { public class AsyncFetchTask implements SchedulingConfigurer {
final Logger logger = LoggerFactory.getLogger(AsyncIdcTask.class); final Logger logger = LoggerFactory.getLogger(AsyncIdcTask.class);
@Resource @Resource
private ScheduledDao scheduledDao; private ScheduledDao scheduledDao;
@Resource @Resource
private IdcService idcService; private IdcService idcService;
@Override @Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
scheduledTaskRegistrar.addTriggerTask(() -> process(), scheduledTaskRegistrar.addTriggerTask(() -> process(),
@ -35,8 +35,8 @@ public class AsyncFetchTask implements SchedulingConfigurer {
scheduledRequest.setCronName("syncFetch"); scheduledRequest.setCronName("syncFetch");
logger.info("syncFetch----------------"); logger.info("syncFetch----------------");
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest); ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
String cron = scheduledEntity!=null ? scheduledEntity.getCron() : "15 * * * * ?"; String cron = scheduledEntity!=null ? scheduledEntity.getCron() : "* 3/30 * * * ?";
if (cron.isEmpty()) { if (cron.isEmpty()) {
logger.error("cron is null"); logger.error("cron is null");
} }
@ -47,8 +47,8 @@ public class AsyncFetchTask implements SchedulingConfigurer {
private void process() { private void process() {
logger.info("syncFetch----process------------"); logger.info("syncFetch----process------------");
idcService.asyncFetchTask(); idcService.asyncFetchTask();
} }
} }

@ -20,13 +20,13 @@ import com.glxp.sale.admin.req.info.ScheduledRequest;
public class AsyncIdcTask implements SchedulingConfigurer { public class AsyncIdcTask implements SchedulingConfigurer {
final Logger logger = LoggerFactory.getLogger(AsyncIdcTask.class); final Logger logger = LoggerFactory.getLogger(AsyncIdcTask.class);
@Resource @Resource
private ScheduledDao scheduledDao; private ScheduledDao scheduledDao;
@Resource @Resource
private IdcService idcService; private IdcService idcService;
@Override @Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
scheduledTaskRegistrar.addTriggerTask(() -> process(), scheduledTaskRegistrar.addTriggerTask(() -> process(),
@ -35,8 +35,8 @@ public class AsyncIdcTask implements SchedulingConfigurer {
scheduledRequest.setCronName("syncIdc"); scheduledRequest.setCronName("syncIdc");
logger.info("syncIdc----------------"); logger.info("syncIdc----------------");
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest); ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
String cron = scheduledEntity!=null ? scheduledEntity.getCron() : "5 * * * * ?"; String cron = scheduledEntity!=null ? scheduledEntity.getCron() : "* 0/30 * * * ?";
if (cron.isEmpty()) { if (cron.isEmpty()) {
logger.error("cron is null"); logger.error("cron is null");
} }
@ -47,8 +47,8 @@ public class AsyncIdcTask implements SchedulingConfigurer {
private void process() { private void process() {
logger.info("syncIdc----process------------"); logger.info("syncIdc----process------------");
idcService.asyncIdcTask(); idcService.asyncIdcTask();
} }
} }

@ -1,10 +1,10 @@
# \u751F\u4EA7\u73AF\u5883 # \u751F\u4EA7\u73AF\u5883
server.port=10001 server.port=10001
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.jdbc-url=jdbc:mysql://127.0.0.1:3316/udispsync?allowMultiQueries=true&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true spring.datasource.jdbc-url=jdbc:mysql://127.0.0.1:3306/udispsync?allowMultiQueries=true&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=root spring.datasource.username=root
#spring.datasource.password=root spring.datasource.password=123456
spring.datasource.password=xiamenswan #spring.datasource.password=xiamenswan
#server.servlet.context-path= #server.servlet.context-path=
logging.level.com.glxp.sale.admin=debug logging.level.com.glxp.sale.admin=debug
# \u8DE8\u57DF\u8BBE\u7F6E # \u8DE8\u57DF\u8BBE\u7F6E
@ -56,4 +56,4 @@ spring.redis.jedis.pool.max-idle=8
# 连接池中的最小空闲连接 # 连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=0 spring.redis.jedis.pool.min-idle=0
# 连接超时时间(毫秒) # 连接超时时间(毫秒)
spring.redis.jedis.timeout=300 spring.redis.jedis.timeout=300

Loading…
Cancel
Save