管道基础大数据平台系统开发-【后端】-Server
13693261870
2024-02-29 36b2f13fff583e0dbc94ee40e9fe4ae6e75af4e0
src/main/java/com/lf/server/service/sys/ReportService.java
@@ -1,6 +1,9 @@
package com.lf.server.service.sys;
import com.lf.server.entity.all.RedisCacheKey;
import com.lf.server.entity.all.SettingData;
import com.lf.server.entity.all.StaticData;
import com.lf.server.entity.ctrl.CoordinateEntity;
import com.lf.server.entity.ctrl.CountEntity;
import com.lf.server.entity.data.DownloadEntity;
import com.lf.server.entity.sys.AttachEntity;
@@ -8,13 +11,16 @@
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.*;
import com.lf.server.mapper.sys.ReportMapper;
import com.lf.server.service.all.RedisService;
import com.lf.server.service.data.DownloadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.locationtech.jts.geom.Coordinate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
 * 报告模板
@@ -22,17 +28,20 @@
 */
@Service
public class ReportService implements ReportMapper {
    @Autowired
    @Resource
    ReportMapper reportMapper;
    @Autowired
    @Resource
    AttachService attachService;
    @Autowired
    @Resource
    PathHelper pathHelper;
    @Autowired
    @Resource
    DownloadService downloadService;
    @Resource
    RedisService redisService;
    @Override
    public Integer selectCount(String name, String code) {
@@ -115,7 +124,64 @@
    @Override
    public List<CountEntity> countExplorationPoints() {
        return reportMapper.countExplorationPoints();
        String key = RedisCacheKey.dataCountKey("countExplorationPoints");
//        Object obj = redisService.get(key);
//        if (obj instanceof List<?>) {
//            return (List<CountEntity>) obj;
//        }
        List<CountEntity> list = reportMapper.countExplorationPoints();
        if (null != list && list.size() > 0) {
            countExplorationArea(list);
            redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES);
        }
        return list;
    }
    @Override
    public List<CoordinateEntity> selectExplorationPoints(String code) {
        return reportMapper.selectExplorationPoints(StringHelper.getRightLike(code));
    }
    /**
     * 统计钻孔点面积
     */
    private void countExplorationArea(List<CountEntity> list) {
        for (CountEntity ce : list) {
            if (0 == ce.getCount()) {
                continue;
            }
            List<CoordinateEntity> ces = selectExplorationPoints(ce.getM3());
            if (null == ces || ces.size() < 3) {
                continue;
            }
            StringBuilder sb = new StringBuilder();
            sb.append("[");
            for (CoordinateEntity e : ces) {
                sb.append(e.getX() + "," + e.getY() + ",");
            }
            sb.replace(sb.length() - 1, sb.length(), "]");
            // double area = JtsHelper.calcAreaByPoints(ces)
            double area = callJsFn(sb.toString());
            ce.setArea(area);
        }
    }
    /**
     * 调用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;
    }
    /**