| | |
| | | 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.MetaPubEntity; |
| | | import com.moon.server.entity.data.PublishEntity; |
| | | import com.moon.server.entity.shujian.*; |
| | | import com.moon.server.helper.HttpHelper; |
| | |
| | | */ |
| | | @Service |
| | | public class ShuJianService { |
| | | private final static Log log = LogFactory.getLog(ShuJianService.class); |
| | | |
| | | @Value("${shujian.ak}") |
| | | private String ak; |
| | | |
| | |
| | | |
| | | @Resource |
| | | PublishService publishService; |
| | | |
| | | private final static Log log = LogFactory.getLog(ShuJianService.class); |
| | | |
| | | /** |
| | | * 分页查询数简的颜色表 |
| | |
| | | /** |
| | | * 插入数简服务 |
| | | */ |
| | | public Integer insertSjService(PubEntity pubEntity, HttpServletRequest req, HttpServletResponse res) { |
| | | CreateLayerEntity layerEntity = createLayerEntity(pubEntity); |
| | | public Integer insertSjService(PubEntity pub) { |
| | | CreateLayerEntity layerEntity = createLayerEntity(pub); |
| | | Integer layerId = postLayerEntity(layerEntity); |
| | | if (null == layerId) { |
| | | return 0; |
| | | } |
| | | |
| | | CreateServiceEntity serviceEntity = createServiceEntity(pubEntity); |
| | | CreateServiceEntity serviceEntity = createServiceEntity(pub); |
| | | Integer serviceId = postServiceEntity(serviceEntity); |
| | | if (null == serviceId) { |
| | | return 0; |
| | | } |
| | | |
| | | PublishEntity publishEntity = createPublishEntity(pubEntity, layerId, serviceId); |
| | | PublishEntity publishEntity = createPublishEntity(pub, layerId, serviceId); |
| | | Integer id = publishService.insert(publishEntity); |
| | | if (null == id) { |
| | | return id; |
| | | } |
| | | |
| | | return publishService.insert(publishEntity); |
| | | return insertMetaPub(pub, id); |
| | | } |
| | | |
| | | /** |
| | |
| | | Map<String, Object> map = getMapData(layerEntity); |
| | | String url = String.format("%s/sj_raster/sj_raster/v6/api/layer?%s", sjUrl, ak); |
| | | |
| | | String str = RestHelper.postForRest(url, map); |
| | | if (StringHelper.isEmpty(str)) { |
| | | return null; |
| | | } |
| | | |
| | | LayerResultEntity rs = JSON.parseObject(str, LayerResultEntity.class); |
| | | LayerResultEntity rs = postForRest(url, map, LayerResultEntity.class); |
| | | boolean flag = null == rs || !StaticData.SUCCESS.equals(rs.getStatus()) || null == rs.getResult().getLayer_id(); |
| | | |
| | | return flag ? null : rs.getResult().getLayer_id(); |
| | |
| | | Map<String, Object> map = getMapData(serviceEntity); |
| | | String url = String.format("%s/sj_raster/v6/api/service?op=create_ex&%s", sjUrl, ak); |
| | | |
| | | String str = RestHelper.postForRest(url, map); |
| | | if (StringHelper.isEmpty(str)) { |
| | | return null; |
| | | } |
| | | |
| | | ServiceResultEntity rs = JSON.parseObject(str, ServiceResultEntity.class); |
| | | ServiceResultEntity rs = postForRest(url, map, ServiceResultEntity.class); |
| | | boolean flag = null == rs || !StaticData.SUCCESS.equals(rs.getStatus()) || null == rs.getResult(); |
| | | |
| | | return flag ? null : rs.getResult(); |
| | |
| | | entity.setName(pub.getName()); |
| | | entity.setMin(pub.getMin()); |
| | | entity.setMax(pub.getMax()); |
| | | entity.setBak((StaticData.I104903 == pub.getEpsgCode() ? "ESRI:" : "EPSG:") + pub.getEpsgCode()); |
| | | entity.setBak(getEpsg(pub)); |
| | | entity.setCreateUser(pub.getUserId()); |
| | | entity.setDirid(pub.getDircode()); |
| | | entity.setDepid(pub.getDepcode()); |
| | | entity.setStatus(3); |
| | | entity.setLayerid(layerId); |
| | | entity.setServiceid(serviceId); |
| | | entity.setJson(getColorTableJson(pub)); |
| | | |
| | | return entity; |
| | | } |
| | | |
| | | /** |
| | | * 获取EPSG编码 |
| | | */ |
| | | public String getEpsg(PubEntity pub) { |
| | | if (StaticData.I104903 == pub.getEpsgCode()) { |
| | | return "ESRI:" + pub.getEpsgCode(); |
| | | } |
| | | |
| | | return "EPSG:" + pub.getEpsgCode(); |
| | | } |
| | | |
| | | /** |
| | | * 获取颜色表的JSON字符串 |
| | | */ |
| | | public String getColorTableJson(PubEntity pub) { |
| | | if (null == pub.getColorTable() && null == pub.getGradientColorTable()) { |
| | | return null; |
| | | } |
| | | |
| | | if (null != pub.getGradientColorTable()) { |
| | | return JSON.toJSONString(pub.getGradientColorTable()); |
| | | } |
| | | |
| | | return JSON.toJSONString(pub.getColorTable()); |
| | | } |
| | | |
| | | /** |
| | | * 插入元数据发布类 |
| | | */ |
| | | private int insertMetaPub(PubEntity pub, Integer pubid) { |
| | | int count = 0; |
| | | for (Integer metaid : pub.getIds()) { |
| | | MetaPubEntity mp = new MetaPubEntity(); |
| | | mp.setMetaid(metaid); |
| | | mp.setPubid(pubid); |
| | | mp.setCreateUser(pub.getUserId()); |
| | | |
| | | count += publishService.insertMetaPub(mp); |
| | | } |
| | | |
| | | return count; |
| | | } |
| | | |
| | | /** |
| | | * 插入数简服务 |
| | | */ |
| | | public Integer updateSjService(PubEntity pubEntity, HttpServletRequest req, HttpServletResponse res) { |
| | | // |
| | | public Integer updateSjService(PubEntity pub, HttpServletRequest req, HttpServletResponse res) { |
| | | PublishEntity entity = publishService.selectById(pub.getPubid()); |
| | | if (null == entity) { |
| | | return 0; |
| | | } |
| | | if (null != entity.getLayerid()) { |
| | | deleteLayer(entity.getLayerid()); |
| | | } |
| | | if (null != entity.getServiceid()) { |
| | | deleteService(entity.getServiceid()); |
| | | } |
| | | |
| | | return 1; |
| | | } |
| | |
| | | */ |
| | | public Integer deletesSjServices(List<Integer> ids) { |
| | | String strs = StringHelper.join(ids, ","); |
| | | |
| | | List<PublishEntity> list = publishService.selectByIds(strs); |
| | | if (null == list || list.isEmpty()) { |
| | | return 0; |
| | |
| | | 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); |
| | | DeleteResultEntity rs = deleteForRest(url, map); |
| | | |
| | | return null != rs && StaticData.SUCCESS.equals(rs.getStatus()); |
| | | } catch (Exception ex) { |
| | |
| | | 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); |
| | | DeleteResultEntity rs = deleteForRest(url, map); |
| | | |
| | | return null != rs && StaticData.SUCCESS.equals(rs.getStatus()); |
| | | } catch (Exception ex) { |
| | |
| | | } |
| | | } |
| | | |
| | | public DeleteResultEntity deleteObject(String url, Map<String, Object> map) { |
| | | /** |
| | | * 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 DeleteResultEntity deleteForRest(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(); |