1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package com.persagy.filemove.service;
- import com.persagy.filemove.dto.SagaFileMoveDTO;
- import com.persagy.filemove.util.HttpTools;
- import java.util.HashMap;
- import java.util.Map;
- public class SagaFileMoveService {
- private SagaFileMoveDTO dto;
- private static final String resp_success = "success";
- private static final String testKey = "persagyAndSagaTest2020121130";
- private static final String url_pj_get = "/mng/project/query";
- private static final String url_source_get = "BASE/common/TYPE_get?systemId=SYSID&key=KEY";
- public SagaFileMoveService(SagaFileMoveDTO dto) {
- this.dto = dto;
- }
- /**
- * 检查数据平台地址和项目信息
- * @return
- */
- public boolean validParamDpfAndPj() {
- boolean result = false;
- Map<Object, Object> param = new HashMap<>();
- param.put("projectId", dto.pjId.getValue());
- try {
- String resp = HttpTools.httpPostJson(dto.dpf.getValue() + url_pj_get, param);
- if(null != resp && resp.contains(resp_success) && resp.contains(dto.pjId.getValue())) {
- result = true;
- }
- }catch (Exception e) {}
- return result;
- }
- /**
- * 校验文件服务From是否可访问
- * @return
- */
- public boolean validParamImgFromUrl() {
- return fileGetTest(dto.imgFromUrl.getValue(), dto.imgFromApiType.getValue(), dto.imgFromSysId.getValue(), testKey);
- }
- /**
- * 校验文件服务From是否可访问
- * @return
- */
- public boolean validParamImgToUrl() {
- return fileGetTest(dto.imgToUrl.getValue(), dto.imgToApiType.getValue(), dto.imgToSysId.getValue(), testKey);
- }
- private boolean fileGetTest(String base, String type, String sysId, String key) {
- boolean result = false;
- String url = url_source_get.replace("BASE", base).replace("TYPE", type).replace("SYSID", sysId).replace("KEY", key);
- try {
- byte[] byteData = HttpTools.httpGetFile(url);
- if(byteData != null && byteData.length == 17) {
- result = true;
- }
- }catch (Exception e){}
- return result;
- }
- }
|