package com.elephant.framework.galaxy.aroad.module.zhjc.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.elephant.framework.galaxy.aroad.module.zhjc.entity.ZhjcGhjhFghjdzb;
import com.elephant.framework.galaxy.aroad.module.zhjc.entity.ZhjcGhjhGhjdzb;
import com.elephant.framework.galaxy.aroad.module.zhjc.mapper.ZhjcGhjhGhjdzbMapper;
import com.elephant.framework.galaxy.aroad.module.zhjc.service.ZhjcGhjhGhjdzbService;
import com.elephant.framework.galaxy.aroad.response.R;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.UUID;

/**
 * 智慧决策_规划计划_规划阶段坐标表
 *
 * @author wangjian
 * @date 2019-05-27 14:23:58
 */
@Service
@AllArgsConstructor
public class ZhjcGhjhGhjdzbServiceImpl extends ServiceImpl<ZhjcGhjhGhjdzbMapper, ZhjcGhjhGhjdzb> implements ZhjcGhjhGhjdzbService {

    final ZhjcGhjhGhjdzbMapper zhjcGhjhGhjdzbMapper;

    /**
     * 坐标转换
     */
    public String shapeConversion(String shape) {
        RestTemplate rest =new RestTemplate();
        String url = "http://47.105.99.44:8080/sdlkapi/LRS/GetAmapGeometry?geometry="+shape;
        ResponseEntity<String> res= rest.getForEntity(url,String.class);
        return  res.getBody();
    }

    /**
     * 新增规划阶段坐标
     * @param zhjcGhjhGhjdzb
     * @return
     */
    public Boolean addGhjdzb(ZhjcGhjhGhjdzb zhjcGhjhGhjdzb) {
        zhjcGhjhGhjdzb.setId(UUID.randomUUID().toString().replaceAll("-",""));

        String shape = shapeConversion(zhjcGhjhGhjdzb.getGeomfeature());

        zhjcGhjhGhjdzb.setGeomfeature(shape.substring(1,shape.length()-1));
        return zhjcGhjhGhjdzbMapper.insert(zhjcGhjhGhjdzb)>0;
    }
}
