| | |
| | | package com.moon.server.service.data; |
| | | |
| | | import com.alibaba.druid.support.spring.stat.annotation.Stat; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.moon.server.entity.all.StaticData; |
| | | import com.moon.server.entity.ctrl.PubEntity; |
| | | import com.moon.server.entity.data.PublishEntity; |
| | | import com.moon.server.entity.shujian.*; |
| | | import com.moon.server.helper.HttpHelper; |
| | | import com.moon.server.helper.RestHelper; |
| | | import com.moon.server.helper.StringHelper; |
| | | import io.swagger.models.auth.In; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.lang.reflect.Field; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 数简.服务 |
| | |
| | | */ |
| | | public Integer insertSjService(PubEntity pubEntity, HttpServletRequest req, HttpServletResponse res) { |
| | | CreateLayerEntity layerEntity = createLayerEntity(pubEntity); |
| | | LayerResultEntity layerResult = postLayerEntity(layerEntity); |
| | | if (null == layerResult || !StaticData.SUCCESS.equals(layerResult.getStatus()) || null == layerResult.getResult().getLayer_id()) { |
| | | Integer layerId = postLayerEntity(layerEntity); |
| | | if (null == layerId) { |
| | | return 0; |
| | | } |
| | | |
| | | CreateServiceEntity serviceEntity = createServiceEntity(pubEntity); |
| | | ServiceResultEntity serviceResult = postServiceEntity(serviceEntity); |
| | | if (null == serviceResult || !StaticData.SUCCESS.equals(serviceResult.getStatus()) || null == serviceResult.getResult()) { |
| | | Integer serviceId = postServiceEntity(serviceEntity); |
| | | if (null == serviceId) { |
| | | return 0; |
| | | } |
| | | |
| | | PublishEntity publishEntity = createPublishEntity(pubEntity, layerResult.getResult().getLayer_id(), serviceResult.getResult()); |
| | | PublishEntity publishEntity = createPublishEntity(pubEntity, layerId, serviceId); |
| | | |
| | | return publishService.insert(publishEntity); |
| | | } |
| | |
| | | /** |
| | | * 发送图层实体类 |
| | | */ |
| | | public LayerResultEntity postLayerEntity(CreateLayerEntity layerEntity) { |
| | | // |
| | | public Integer postLayerEntity(CreateLayerEntity layerEntity) { |
| | | Map<String, Object> map = getMapData(layerEntity); |
| | | String url = String.format("%s/sj_raster/sj_raster/v6/api/layer?%s", sjUrl, ak); |
| | | |
| | | return new LayerResultEntity(); |
| | | String str = RestHelper.postForRest(url, map); |
| | | if (StringHelper.isEmpty(str)) { |
| | | return null; |
| | | } |
| | | |
| | | LayerResultEntity rs = JSON.parseObject(str, LayerResultEntity.class); |
| | | boolean flag = null == rs || !StaticData.SUCCESS.equals(rs.getStatus()) || null == rs.getResult().getLayer_id(); |
| | | |
| | | return flag ? null : rs.getResult().getLayer_id(); |
| | | } |
| | | |
| | | /** |
| | |
| | | /** |
| | | * 发送图层实体类 |
| | | */ |
| | | public ServiceResultEntity postServiceEntity(CreateServiceEntity serviceEntity) { |
| | | // |
| | | public Integer postServiceEntity(CreateServiceEntity serviceEntity) { |
| | | Map<String, Object> map = getMapData(serviceEntity); |
| | | String url = String.format("%s/sj_raster/v6/api/service?op=create_ex&%s", sjUrl, ak); |
| | | |
| | | return new ServiceResultEntity(); |
| | | String str = RestHelper.postForRest(url, map); |
| | | if (StringHelper.isEmpty(str)) { |
| | | return null; |
| | | } |
| | | |
| | | ServiceResultEntity rs = JSON.parseObject(str, ServiceResultEntity.class); |
| | | boolean flag = null == rs || !StaticData.SUCCESS.equals(rs.getStatus()) || null == rs.getResult(); |
| | | |
| | | return flag ? null : rs.getResult(); |
| | | } |
| | | |
| | | /** |
| | |
| | | /** |
| | | * 删除图层 |
| | | */ |
| | | public void deleteLayer(Integer id) { |
| | | public boolean deleteLayer(Integer id) { |
| | | try { |
| | | DeleteEntity entity = new DeleteEntity(); |
| | | entity.getId_list().add(id); |
| | | |
| | | //.. |
| | | Map<String, Object> map = getMapData(entity); |
| | | String url = String.format("%s/sj_raster/sj_raster/v6/api/layer?%s", sjUrl, ak); |
| | | |
| | | DeleteResultEntity rs = deleteObject(url, map); |
| | | |
| | | return null != rs && StaticData.SUCCESS.equals(rs.getStatus()); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除服务 |
| | | */ |
| | | public void deleteService(Integer id) { |
| | | public boolean deleteService(Integer id) { |
| | | try { |
| | | DeleteEntity entity = new DeleteEntity(); |
| | | entity.getId_list().add(id); |
| | | |
| | | //.. |
| | | Map<String, Object> map = getMapData(entity); |
| | | String url = String.format("%s/sj_raster/sj_raster/v6/api/service?%s", sjUrl, ak); |
| | | |
| | | DeleteResultEntity rs = deleteObject(url, map); |
| | | |
| | | return null != rs && StaticData.SUCCESS.equals(rs.getStatus()); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | public DeleteResultEntity deleteObject(String url, Map<String, Object> map) { |
| | | RestTemplate rest = RestHelper.getRestTemplate(); |
| | | |
| | | ResponseEntity<DeleteResultEntity> rs = rest.exchange(url, HttpMethod.DELETE, null, DeleteResultEntity.class, map); |
| | | |
| | | 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; |
| | | } |
| | | } |