| | |
| | | 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.*; |
| | | import com.moon.server.helper.HttpHelper; |
| | | import com.moon.server.helper.PathHelper; |
| | | import com.moon.server.helper.RestHelper; |
| | | import com.moon.server.helper.StringHelper; |
| | | import org.apache.commons.logging.Log; |
| | |
| | | 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; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 数简.服务 |
| | |
| | | */ |
| | | @Service |
| | | public class ShuJianService { |
| | | private final static Log log = LogFactory.getLog(ShuJianService.class); |
| | | |
| | | @Value("${shujian.ak}") |
| | | private String ak; |
| | | String ak; |
| | | |
| | | @Value("${shujian.url}") |
| | | private String sjUrl; |
| | | String sjUrl; |
| | | |
| | | @Resource |
| | | PathHelper pathHelper; |
| | | |
| | | @Resource |
| | | MetaService metaService; |
| | | |
| | | @Resource |
| | | PublishService publishService; |
| | | |
| | | private final static Log log = LogFactory.getLog(ShuJianService.class); |
| | | |
| | | public final static List<String> TYPES = new ArrayList<>(Arrays.asList("DOM", "DEM")); |
| | | |
| | | /** |
| | | * 分页查询数简的颜色表 |
| | |
| | | /** |
| | | * 插入数简服务 |
| | | */ |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 创建图层实体类 |
| | | */ |
| | | public CreateLayerEntity createLayerEntity(PubEntity pubEntity) { |
| | | CreateLayerEntity entity = new CreateLayerEntity(1, 3); |
| | | 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(""); |
| | | 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); |
| | | layer.setName(pub.getName()); |
| | | layer.setProjection(getEpsg(pub)); |
| | | layer.setType(TYPES.indexOf(pub.getType())); |
| | | layer.setEnhance_type(pub.getEnhanceType()); |
| | | layer.setNodata(getNoData(pub, metas)); |
| | | |
| | | CreateLayerEntity.ImagePathList imagePathList = entity.getImage_path_list().get(0); |
| | | imagePathList.setPath(""); |
| | | imagePathList.setPath(pathHelper.getConfig().getUploadPath()); |
| | | |
| | | List<CreateLayerEntity.ImageList> imageLists = entity.getImage_list(); |
| | | CreateLayerEntity.ImageList imageList = imageLists.get(0); |
| | | imageList.setPath(""); |
| | | for (MetaEntity meta : metas) { |
| | | CreateLayerEntity.ImageList imageList = entity.new ImageList(); |
| | | imageList.setPath(meta.getPath()); |
| | | imageLists.add(imageList); |
| | | } |
| | | |
| | | return entity; |
| | | } |
| | | |
| | | /** |
| | | * 获取EPSG编码 |
| | | */ |
| | | public String getEpsg(PubEntity pub) { |
| | | if (StaticData.I104903 == pub.getEpsgCode()) { |
| | | return "ESRI:" + pub.getEpsgCode(); |
| | | } |
| | | |
| | | return "EPSG:" + pub.getEpsgCode(); |
| | | } |
| | | |
| | | private List<String> 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<String> list = new ArrayList<>(); |
| | | for (int i = 0; i < bands; i++) { |
| | | list.add(String.valueOf(pub.getNodata())); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | |
| | | * 创建发布实体类 |
| | | */ |
| | | public PublishEntity createPublishEntity(PubEntity pub, Integer layerId, Integer serviceId) { |
| | | String epsg = (StaticData.I104903 == pub.getEpsgCode() ? "ESRI:" : "EPSG:") + pub.getEpsgCode(); |
| | | |
| | | PublishEntity entity = new PublishEntity(); |
| | | entity.setType(pub.getType()); |
| | | entity.setName(pub.getName()); |
| | | entity.setMin(pub.getMin()); |
| | | entity.setMax(pub.getMax()); |
| | | entity.setBak(epsg); |
| | | entity.setEpsg(pub.getEpsgCode()); |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 获取颜色表的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 deletesSjServices(List<Integer> ids) { |
| | | String strs = StringHelper.join(ids, ","); |
| | | |
| | | List<PublishEntity> list = publishService.selectByIds(strs); |
| | | if (null == list || list.isEmpty()) { |
| | | return 0; |