SagaFileMoveService.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.persagy.filemove.service;
  2. import com.persagy.filemove.dto.SagaFileMoveDTO;
  3. import com.persagy.filemove.util.HttpTools;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. public class SagaFileMoveService {
  7. private SagaFileMoveDTO dto;
  8. private static final String resp_success = "success";
  9. private static final String testKey = "persagyAndSagaTest2020121130";
  10. private static final String url_pj_get = "/mng/project/query";
  11. private static final String url_source_get = "BASE/common/TYPE_get?systemId=SYSID&key=KEY";
  12. public SagaFileMoveService(SagaFileMoveDTO dto) {
  13. this.dto = dto;
  14. }
  15. /**
  16. * 检查数据平台地址和项目信息
  17. * @return
  18. */
  19. public boolean validParamDpfAndPj() {
  20. boolean result = false;
  21. Map<Object, Object> param = new HashMap<>();
  22. param.put("projectId", dto.pjId.getValue());
  23. try {
  24. String resp = HttpTools.httpPostJson(dto.dpf.getValue() + url_pj_get, param);
  25. if(null != resp && resp.contains(resp_success) && resp.contains(dto.pjId.getValue())) {
  26. result = true;
  27. }
  28. }catch (Exception e) {}
  29. return result;
  30. }
  31. /**
  32. * 校验文件服务From是否可访问
  33. * @return
  34. */
  35. public boolean validParamImgFromUrl() {
  36. return fileGetTest(dto.imgFromUrl.getValue(), dto.imgFromApiType.getValue(), dto.imgFromSysId.getValue(), testKey);
  37. }
  38. /**
  39. * 校验文件服务From是否可访问
  40. * @return
  41. */
  42. public boolean validParamImgToUrl() {
  43. return fileGetTest(dto.imgToUrl.getValue(), dto.imgToApiType.getValue(), dto.imgToSysId.getValue(), testKey);
  44. }
  45. private boolean fileGetTest(String base, String type, String sysId, String key) {
  46. boolean result = false;
  47. String url = url_source_get.replace("BASE", base).replace("TYPE", type).replace("SYSID", sysId).replace("KEY", key);
  48. try {
  49. byte[] byteData = HttpTools.httpGetFile(url);
  50. if(byteData != null && byteData.length == 17) {
  51. result = true;
  52. }
  53. }catch (Exception e){}
  54. return result;
  55. }
  56. }