管道基础大数据平台系统开发-【后端】-Server
13693261870
2024-02-29 e9509391ffd3e90c64872836ad64d112a89a26a4
src/main/java/com/lf/server/service/sys/ReportService.java
@@ -13,6 +13,11 @@
import com.lf.server.mapper.sys.ReportMapper;
import com.lf.server.service.all.RedisService;
import com.lf.server.service.data.DownloadService;
import com.lf.server.service.data.PublishService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.locationtech.jts.geom.Coordinate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -27,6 +32,9 @@
 */
@Service
public class ReportService implements ReportMapper {
    @Value("${sys.turfServer}")
    private String turfServer;
    @Resource
    ReportMapper reportMapper;
@@ -41,6 +49,8 @@
    @Resource
    RedisService redisService;
    private final static Log log = LogFactory.getLog(ReportService.class);
    @Override
    public Integer selectCount(String name, String code) {
@@ -124,10 +134,10 @@
    @Override
    public List<CountEntity> countExplorationPoints() {
        String key = RedisCacheKey.dataCountKey("countExplorationPoints");
        Object obj = redisService.get(key);
        if (obj instanceof List<?>) {
            return (List<CountEntity>) obj;
        }
//        Object obj = redisService.get(key);
//        if (obj instanceof List<?>) {
//            return (List<CountEntity>) obj;
//        }
        List<CountEntity> list = reportMapper.countExplorationPoints();
        if (null != list && list.size() > 0) {
@@ -152,17 +162,43 @@
                continue;
            }
            List<CoordinateEntity> ces = selectExplorationPoints(ce.getM3());
            if (null == ces || ces.size() < 3) {
                continue;
            }
            double area = JtsHelper.calcAreaByPoints(ces);
            double area = calcPolygonArea(ce.getM3());
            ce.setArea(area);
        }
    }
    /**
     * 计算多边形面积
     */
    private double calcPolygonArea(String code) {
        try {
            String url = turfServer + "/Call/CalcArea?code=" + code;
            String str = RestHelper.get(url);
            if (StringHelper.isEmpty(str)) {
                return 0d;
            }
            return Double.parseDouble(str);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return 0d;
        }
    }
    /**
     * 调用JS方法 *
     */
    private double callJsFn(String str) {
        String staticPath = PathHelper.getStaticPath();
        Object obj = JsHelper.callJsFn(staticPath + "js/turf.min.6.5.js", "pointsToPolygon", str);
        if (null == obj) {
            return 0d;
        }
        return (double) obj;
    }
    /**
     * 创建报告
     */
    public void createReport(UserEntity ue, ReportEntity re, HttpServletResponse res) throws Exception {