| | |
| | | package com.moon.server.service.data; |
| | | |
| | | 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.MetaEntity; |
| | | import com.moon.server.entity.data.MetaPubEntity; |
| | | import com.moon.server.entity.data.PublishEntity; |
| | | import com.moon.server.entity.shujian.CreateLayerEntity; |
| | | import com.moon.server.entity.shujian.CreateServiceEntity; |
| | | import com.moon.server.entity.shujian.DeleteEntity; |
| | | import com.moon.server.entity.shujian.*; |
| | | import com.moon.server.entity.sys.LayerEntity; |
| | | import com.moon.server.entity.sys.ResEntity; |
| | | import com.moon.server.helper.HttpHelper; |
| | | import com.moon.server.helper.RestHelper; |
| | | import com.moon.server.helper.StringHelper; |
| | | import com.moon.server.service.sys.LayerService; |
| | | import com.moon.server.service.sys.ResService; |
| | | 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 java.util.List; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.lang.reflect.Field; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 数简.服务 |
| | |
| | | */ |
| | | @Service |
| | | public class ShuJianService { |
| | | @Value("${shujian.ak}") |
| | | String ak; |
| | | |
| | | @Value("${shujian.url1}") |
| | | String sjUrl1; |
| | | |
| | | @Value("${shujian.url5}") |
| | | String sjUrl5; |
| | | |
| | | @Value("${shujian.path}") |
| | | String sjPath; |
| | | |
| | | @Value("${shujian.domName}") |
| | | String domName; |
| | | |
| | | @Value("${shujian.demName}") |
| | | String demName; |
| | | |
| | | @Resource |
| | | ResService resService; |
| | | |
| | | @Resource |
| | | MetaService metaService; |
| | | |
| | | @Resource |
| | | PublishService publishService; |
| | | |
| | | @Resource |
| | | LayerService layerService; |
| | | |
| | | private final static Log log = LogFactory.getLog(ShuJianService.class); |
| | | |
| | | @Value("${shujian.ak}") |
| | | private String ak; |
| | | public final static List<String> TYPES = new ArrayList<>(Arrays.asList("DOM", "DEM")); |
| | | |
| | | @Value("${shujian.url}") |
| | | private String url; |
| | | private final static String DOM_FORMAT = "%s/sj_raster/v6/wmts/service/system/%d/%s"; |
| | | |
| | | private final static String DEM_FORMAT = "%s/sj_raster/v6/terrain_mesh/service/system/%d/%s"; |
| | | |
| | | private final static String API_LAYER = "%s/sj_raster/v6/api/layer?%s&sort=name%%20asc"; |
| | | |
| | | private final static String COLOR_TABLE = "%s/sj_raster/v6/api/color_table?%s&page_count=%d&page_num=%d&key="; |
| | | |
| | | /** |
| | | * 创建数简图层 |
| | | * 分页查询数简的颜色表 |
| | | */ |
| | | public void createShuJianLayer() { |
| | | CreateLayerEntity entity = new CreateLayerEntity(1, 3); |
| | | entity.setCreate_service(0); |
| | | public void selectSjColorTables(Integer port, Integer pageSize, Integer pageIndex, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | String url = String.format(COLOR_TABLE, null == port || 50001 == port ? sjUrl1 : sjUrl5, ak, pageSize, pageIndex); |
| | | |
| | | CreateLayerEntity.Layer layer = entity.getLayer(); |
| | | layer.setName(""); |
| | | layer.setProjection("ESRI:" + StaticData.I104903); |
| | | layer.setType(0); |
| | | layer.setEnhance_type(0); |
| | | |
| | | String[] noData = new String[3]; |
| | | noData[0] = "0"; |
| | | noData[1] = "0"; |
| | | noData[2] = "0"; |
| | | layer.setNodata(noData); |
| | | |
| | | CreateLayerEntity.ImagePathList imagePathList = entity.getImage_path_list().get(0); |
| | | imagePathList.setPath(""); |
| | | |
| | | List<CreateLayerEntity.ImageList> imageLists = entity.getImage_list(); |
| | | CreateLayerEntity.ImageList imageList = imageLists.get(0); |
| | | imageList.setPath(""); |
| | | HttpHelper httpHelper = new HttpHelper(); |
| | | httpHelper.service(req, res, null, url); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建数简服务 |
| | | * 查询数简图层 |
| | | */ |
| | | public void createShuJianService() { |
| | | public void selectSjLayers(Integer port, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | String url = String.format(API_LAYER, null == port || 50001 == port ? sjUrl1 : sjUrl5, ak); |
| | | |
| | | HttpHelper httpHelper = new HttpHelper(); |
| | | httpHelper.service(req, res, null, url); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 插入数简服务 |
| | | */ |
| | | public Integer insertSjService(PubEntity pub) { |
| | | CreateLayerEntity layerEntity = createLayerEntity(pub); |
| | | Integer layerId = postLayerEntity(layerEntity); |
| | | if (null == layerId) { |
| | | return 0; |
| | | } |
| | | |
| | | CreateServiceEntity serviceEntity = createServiceEntity(pub, layerId); |
| | | Integer serviceId = postServiceEntity(serviceEntity); |
| | | if (null == serviceId) { |
| | | return 0; |
| | | } |
| | | |
| | | PublishEntity publishEntity = createPublishEntity(pub, layerId, serviceId); |
| | | int rows = publishService.insert(publishEntity); |
| | | if (0 == rows) { |
| | | return 0; |
| | | } |
| | | |
| | | ResEntity resEntity = createResEntity(publishEntity); |
| | | resService.insert(resEntity); |
| | | |
| | | insertMetaPub(pub, publishEntity.getId()); |
| | | layerService.insert(createLayerEntity(resEntity, StaticData.I3)); |
| | | |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * 创建图层实体类 |
| | | */ |
| | | public CreateLayerEntity createLayerEntity(PubEntity pub) { |
| | | String ids = StringHelper.join(pub.getIds(), ","); |
| | | List<MetaEntity> metas = metaService.selectByIds(ids); |
| | | |
| | | CreateLayerEntity entity = new CreateLayerEntity(); |
| | | entity.setCreate_service(0); |
| | | |
| | | CreateLayerEntity.Layer layer = entity.getLayer(); |
| | | layer.setName(pub.getName() + "_" + pub.getTime()); |
| | | layer.setProjection(getEpsg(pub)); |
| | | layer.setType(TYPES.indexOf(pub.getType())); |
| | | layer.setEnhance_type(pub.getEnhanceType()); |
| | | layer.setEnhance_factor(pub.getEnhanceFactor()); |
| | | layer.setNodata(getNoData(pub, metas)); |
| | | layer.setConfig(getColorTableConfig(entity, pub)); |
| | | |
| | | CreateLayerEntity.ImagePathList imagePathList = entity.new ImagePathList(); |
| | | imagePathList.setPath(sjPath); |
| | | entity.getImage_path_list().add(imagePathList); |
| | | |
| | | List<String> filters = imagePathList.getFilter(); |
| | | for (MetaEntity meta : metas) { |
| | | filters.add(meta.getPath().replace("\\", "/")); |
| | | } |
| | | |
| | | return entity; |
| | | } |
| | | |
| | | /** |
| | | * 获取EPSG编码 |
| | | */ |
| | | public String getEpsg(PubEntity pub) { |
| | | if (StaticData.I104903 == pub.getEpsg()) { |
| | | return "ESRI:" + pub.getEpsg(); |
| | | } |
| | | |
| | | return "EPSG:" + pub.getEpsg(); |
| | | } |
| | | |
| | | /** |
| | | * 获取 nodata |
| | | */ |
| | | private List<Integer> getNoData(PubEntity pub, List<MetaEntity> metas) { |
| | | int bands = 1; |
| | | for (MetaEntity meta : metas) { |
| | | if (StringHelper.isEmpty(meta.getBands())) { |
| | | continue; |
| | | } |
| | | try { |
| | | int b = Integer.parseInt(meta.getBands()); |
| | | if (b > bands) { |
| | | bands = b; |
| | | } |
| | | } catch (Exception e) { |
| | | // |
| | | } |
| | | } |
| | | |
| | | List<Integer> list = new ArrayList<>(); |
| | | for (int i = 0; i < bands; i++) { |
| | | list.add(pub.getNodata()); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 获取颜色表的配置 |
| | | */ |
| | | private CreateLayerEntity.Config getColorTableConfig(CreateLayerEntity entity, PubEntity pub) { |
| | | if (null == pub.getColorTable() && null == pub.getGradientColorTable()) { |
| | | return null; |
| | | } |
| | | |
| | | Integer type = null != pub.getColorTable() ? 0 : 1; |
| | | List<?> levels = null != pub.getColorTable() ? pub.getColorTable() : pub.getGradientColorTable(); |
| | | |
| | | return entity.new Config(type, levels); |
| | | } |
| | | |
| | | /** |
| | | * 发送图层实体类 |
| | | */ |
| | | public Integer postLayerEntity(CreateLayerEntity layerEntity) { |
| | | Map<String, Object> map = getMapData(layerEntity); |
| | | String url = String.format("%s/sj_raster/v6/api/layer?op=create_ex&%s", sjUrl5, ak); |
| | | |
| | | 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(); |
| | | } |
| | | |
| | | /** |
| | | * 创建服务实体类 |
| | | */ |
| | | public CreateServiceEntity createServiceEntity(PubEntity pub, Integer layerId) { |
| | | CreateServiceEntity entity = new CreateServiceEntity(); |
| | | List<Integer> layerList = entity.getLayer_list(); |
| | | layerList.add(layerId); |
| | | |
| | | CreateServiceEntity.Services services = entity.getService(); |
| | | services.setName(""); |
| | | services.setAccess_name(StringHelper.getGuid()); |
| | | services.setName(pub.getName() + "_" + pub.getTime()); |
| | | services.setAccess_name(pub.getUuid()); |
| | | services.setPub_status(1); |
| | | services.setRect_minx(-180.0); |
| | | services.setRect_miny(-90.0); |
| | | services.setRect_maxx(180.0); |
| | | services.setRect_maxy(90.0); |
| | | services.setProjection("ESRI:" + StaticData.I104903); |
| | | services.setProjection(getEpsg(pub)); |
| | | services.setSat_id(-1); |
| | | services.setSensor_id(-1); |
| | | services.setImage_type(-1); |
| | | services.setConfig(null); |
| | | |
| | | return entity; |
| | | } |
| | | |
| | | /** |
| | | * 删除数简服务 |
| | | * 发送图层实体类 |
| | | */ |
| | | public void deleteServe(PublishEntity entity) { |
| | | 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", sjUrl5, ak); |
| | | |
| | | ServiceResultEntity rs = postForRest(url, map, ServiceResultEntity.class); |
| | | boolean flag = null == rs || !StaticData.SUCCESS.equals(rs.getStatus()) || null == rs.getResult(); |
| | | |
| | | return flag ? null : rs.getResult(); |
| | | } |
| | | |
| | | /** |
| | | * 创建发布实体类 |
| | | */ |
| | | public PublishEntity createPublishEntity(PubEntity pub, Integer layerId, Integer serviceId) { |
| | | PublishEntity entity = new PublishEntity(); |
| | | entity.setLayerid(layerId); |
| | | entity.setServiceid(serviceId); |
| | | entity.setEventid(pub.getUuid()); |
| | | entity.setName(pub.getName()); |
| | | entity.setUrl(String.format(TYPES.get(0).equals(pub.getType()) ? DOM_FORMAT : DEM_FORMAT, sjUrl5, serviceId, StaticData.I0)); |
| | | entity.setPath(null); |
| | | entity.setType(pub.getType()); |
| | | entity.setStatus(3); |
| | | entity.setDirid(pub.getDircode()); |
| | | entity.setDepid(pub.getDepcode()); |
| | | entity.setEnhanceType(pub.getEnhanceType()); |
| | | entity.setMin(pub.getMin()); |
| | | entity.setMax(pub.getMax()); |
| | | entity.setEpsg(pub.getEpsg()); |
| | | entity.setCreateUser(pub.getUserId()); |
| | | entity.setCtType(getColorTableType(pub)); |
| | | entity.setCtJson(getColorTableJson(pub)); |
| | | entity.setCreateUser(pub.getUserId()); |
| | | entity.setGeom("null"); |
| | | |
| | | return entity; |
| | | } |
| | | |
| | | /** |
| | | * 创建资源实体类 |
| | | */ |
| | | private ResEntity createResEntity(PublishEntity pub) { |
| | | ResEntity entity = new ResEntity(); |
| | | entity.setCnName(pub.getName()); |
| | | // 状态:0-禁用,1-启用原始地址,2-启用代理地址 |
| | | entity.setStatus(2); |
| | | // 服务类别:0-其他,1-GisServer,2-GeoServer,3-数简 |
| | | entity.setCategory(3); |
| | | // 服务类型:0-URL,1-TMS,2-WMTS,3-WMS,4-WFS,5-Tileset |
| | | entity.setType(StaticData.DOM.equals(pub.getType()) ? 2 : 0); |
| | | // 数据类型:0-URL,1-DOM,2-DEM |
| | | entity.setData(StaticData.DOM.equals(pub.getType()) ? 1 : 2); |
| | | entity.setUrl(pub.getUrl()); |
| | | entity.setArgs(ak); |
| | | entity.setDescr("系统自动创建"); |
| | | entity.setDepid(pub.getDepid()); |
| | | entity.setDirid(pub.getDirid()); |
| | | entity.setCreateUser(pub.getCreateUser()); |
| | | entity.setPubid(pub.getId()); |
| | | |
| | | return entity; |
| | | } |
| | | |
| | | /** |
| | | * 创建图层 |
| | | */ |
| | | private LayerEntity createLayerEntity(ResEntity resEntity, Integer category) { |
| | | Integer pid = layerService.selectIdByName(StaticData.I1 == resEntity.getData() ? domName : demName); |
| | | Integer orderNum = layerService.selectMaxOrderNumByPid(pid); |
| | | LayerEntity layer = layerService.selectById(pid); |
| | | |
| | | LayerEntity entity = new LayerEntity(); |
| | | entity.setPid(pid); |
| | | entity.setCnName(resEntity.getCnName()); |
| | | entity.setEnName(resEntity.getEnName()); |
| | | entity.setUrl(resEntity.getProxy()); |
| | | // 是否为图层:0-图层组,1-图层 |
| | | entity.setIsLayer(1); |
| | | entity.setLevel(null == layer ? 1 : layer.getLevel() + 1); |
| | | entity.setOrderNum(orderNum); |
| | | // 状态:0-停止,1-启用 |
| | | entity.setStatus(1); |
| | | entity.setCreateUser(resEntity.getCreateUser()); |
| | | entity.setResid(resEntity.getId()); |
| | | // 类别:0-URL,1-TMS,2-WMTS,3-WMS,4-WFS,5-Tileset |
| | | entity.setType(StaticData.I1 == resEntity.getData() ? 2 : 0); |
| | | // 数据类型:0-URL,1-DOM,2-DEM |
| | | entity.setData(resEntity.getData()); |
| | | // 服务类别:0-其他,1-GisServer,2-GeoServer,3-数简 |
| | | entity.setCategory(category); |
| | | // 是/否默认显示 |
| | | entity.setIsShow(0); |
| | | |
| | | return entity; |
| | | } |
| | | |
| | | /** |
| | | * 获取颜色表类型 |
| | | */ |
| | | private String getColorTableType(PubEntity pub) { |
| | | if (null == pub.getColorTable() && null == pub.getGradientColorTable()) { |
| | | return null; |
| | | } |
| | | if (null != pub.getGradientColorTable()) { |
| | | return "渐变颜色表"; |
| | | } |
| | | |
| | | return "普通颜色表"; |
| | | } |
| | | |
| | | /** |
| | | * 获取颜色表的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 pub) { |
| | | 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()); |
| | | } |
| | | setPubEntity(pub, entity); |
| | | |
| | | CreateLayerEntity layerEntity = createLayerEntity(pub); |
| | | Integer layerId = postLayerEntity(layerEntity); |
| | | if (null == layerId) { |
| | | return 0; |
| | | } |
| | | |
| | | CreateServiceEntity serviceEntity = createServiceEntity(pub, layerId); |
| | | Integer serviceId = postServiceEntity(serviceEntity); |
| | | if (null == serviceId) { |
| | | return 0; |
| | | } |
| | | |
| | | entity.setLayerid(layerId); |
| | | entity.setServiceid(serviceId); |
| | | entity.setEventid(pub.getUuid()); |
| | | entity.setUpdateUser(pub.getUserId()); |
| | | entity.setUrl(String.format(TYPES.get(0).equals(pub.getType()) ? DOM_FORMAT : DEM_FORMAT, sjUrl5, serviceId, StaticData.I0)); |
| | | if (StringHelper.isEmpty(entity.getGeom())) { |
| | | entity.setGeom(StaticData.NULL); |
| | | } |
| | | |
| | | int rows = publishService.update(entity); |
| | | if (0 == rows) { |
| | | return 0; |
| | | } |
| | | |
| | | ResEntity resEntity = resService.selectByPubid(entity.getId()); |
| | | if (null == resEntity) { |
| | | resEntity = createResEntity(entity); |
| | | resService.insert(resEntity); |
| | | } else { |
| | | resEntity.setUpdateUser(pub.getUserId()); |
| | | resEntity.setCnName(entity.getName()); |
| | | resEntity.setUrl(entity.getUrl()); |
| | | resService.update(resEntity); |
| | | } |
| | | |
| | | LayerEntity lyrEntity = layerService.selectByResId(resEntity.getId()); |
| | | if (null != lyrEntity) { |
| | | lyrEntity.setCnName(resEntity.getCnName()); |
| | | lyrEntity.setUpdateUser(pub.getUserId()); |
| | | layerService.update(lyrEntity); |
| | | } |
| | | |
| | | return entity.getId(); |
| | | } |
| | | |
| | | /** |
| | | * 删除数简图层 |
| | | * 设置发布实体类 |
| | | */ |
| | | public void deleteLayer(Integer id) { |
| | | try { |
| | | DeleteEntity entity = new DeleteEntity(); |
| | | entity.getId_list().add(id); |
| | | private void setPubEntity(PubEntity pub, PublishEntity entity) { |
| | | List<MetaEntity> metas = publishService.selectMetasByPubid(pub.getPubid()); |
| | | |
| | | //.. |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | List<Integer> ids = new ArrayList<>(); |
| | | for (MetaEntity meta : metas) { |
| | | ids.add(meta.getId()); |
| | | } |
| | | pub.setIds(ids); |
| | | |
| | | if (StringHelper.isEmpty(pub.getName())) { |
| | | pub.setName(entity.getName()); |
| | | } |
| | | if (null == pub.getEpsg() || 0 == pub.getEpsg()) { |
| | | pub.setEpsg(entity.getEpsg()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除数简图层 |
| | | * 删除数简服务 |
| | | */ |
| | | public void deleteService(Integer id) { |
| | | public Integer deletesSjServices(List<Integer> ids) { |
| | | String strs = StringHelper.join(ids, ","); |
| | | List<PublishEntity> list = publishService.selectByIds(strs); |
| | | if (null == list || list.isEmpty()) { |
| | | return 0; |
| | | } |
| | | |
| | | for (PublishEntity entity : list) { |
| | | if (null != entity.getLayerid()) { |
| | | deleteLayer(entity.getLayerid()); |
| | | } |
| | | if (null != entity.getServiceid()) { |
| | | deleteService(entity.getServiceid()); |
| | | } |
| | | } |
| | | publishService.deletes(strs); |
| | | |
| | | return list.size(); |
| | | } |
| | | |
| | | /** |
| | | * 删除图层 |
| | | */ |
| | | 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/v6/api/layer?%s", sjUrl5, ak); |
| | | |
| | | DeleteResultEntity rs = deleteForRest(url, map); |
| | | |
| | | return null != rs && StaticData.SUCCESS.equals(rs.getStatus()); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除服务 |
| | | */ |
| | | 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/v6/api/service?%s", sjUrl5, ak); |
| | | |
| | | DeleteResultEntity rs = deleteForRest(url, map); |
| | | |
| | | return null != rs && StaticData.SUCCESS.equals(rs.getStatus()); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 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) { |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | |
| | | HttpEntity<?> entity = new HttpEntity<>(map, headers); |
| | | |
| | | RestTemplate rest = RestHelper.getRestTemplate(); |
| | | ResponseEntity<DeleteResultEntity> rs = rest.exchange(url, HttpMethod.DELETE, entity, DeleteResultEntity.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; |
| | | } |
| | | } |