| | |
| | | package com.smartearth.poiexcel.service; |
| | | |
| | | import com.smartearth.poiexcel.mapper.EntMapper; |
| | | import com.smartearth.poiexcel.utils.RestHelper; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.*; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.lang.reflect.Field; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 企业服务类 |
| | |
| | | @Resource |
| | | EntMapper entMapper; |
| | | |
| | | // |
| | | @Value("${qylweb.url}") |
| | | String qylwebUrl; |
| | | |
| | | private final static Log log = LogFactory.getLog(EntService.class); |
| | | |
| | | |
| | | /** |
| | | * post请求(Rest) |
| | | */ |
| | | public <T> T postForRest(String url, Map<String, Object> map, Class<T> clazz) { |
| | | RestTemplate rest = RestHelper.getRestTemplate(); |
| | | |
| | | return rest.postForObject(url, map, clazz); |
| | | } |
| | | |
| | | /** |
| | | * delete请求(Rest) |
| | | */ |
| | | public Object deleteForRest(String url, Map<String, Object> map) { |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | |
| | | HttpEntity<?> entity = new HttpEntity<>(map, headers); |
| | | |
| | | RestTemplate rest = RestHelper.getRestTemplate(); |
| | | ResponseEntity<Object> rs = rest.exchange(url, HttpMethod.DELETE, entity, Object.class); |
| | | |
| | | return rs.getBody(); |
| | | } |
| | | |
| | | /** |
| | | * 获取Map数据 |
| | | */ |
| | | public <T> Map<String, Object> getMapData(T t) { |
| | | Map<String, Object> map = new HashMap<>(1); |
| | | |
| | | Field[] fields = t.getClass().getDeclaredFields(); |
| | | for (Field field : fields) { |
| | | try { |
| | | if ("serialVersionUID".equals(field.getName())) { |
| | | continue; |
| | | } |
| | | |
| | | field.setAccessible(true); |
| | | Object obj = field.get(t); |
| | | |
| | | map.put(field.getName(), obj); |
| | | } catch (Exception ex) { |
| | | // |
| | | } |
| | | } |
| | | |
| | | return map; |
| | | } |
| | | } |