MasterService.java 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package com.uas.erp.schedular.service;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.TypeReference;
  4. import com.uas.erp.schedular.entity.Master;
  5. import com.uas.erp.schedular.web.ResultListWrap;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import org.springframework.web.client.RestTemplate;
  9. import java.util.List;
  10. /**
  11. * Created by Pro1 on 2017/7/31.
  12. */
  13. @Service
  14. public class MasterService {
  15. @Autowired
  16. private RestTemplate restTemplate;
  17. @Autowired
  18. private SettingService settingService;
  19. private String getUrl() {
  20. return settingService.getValue("api.database.url");
  21. }
  22. public List<Master> getMasters() {
  23. try {
  24. String resultStr = restTemplate.getForObject(getUrl() + "/v1/master/list?cloudEnabled=true", String.class);
  25. ResultListWrap<Master> result = JSON.parseObject(resultStr, new TypeReference<ResultListWrap<Master>>(Master.class) {
  26. });
  27. if (result.isSuccess()) {
  28. return result.getContent();
  29. }
  30. } catch (Exception e) {
  31. e.printStackTrace();
  32. }
  33. return null;
  34. }
  35. }