管道基础大数据平台系统开发-【后端】-Server
13693261870
2024-02-29 671a88e789a4cd62851bbdc06bbd13b82b535246
src/main/java/com/lf/server/service/sys/ReportService.java
@@ -1,7 +1,6 @@
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;
@@ -13,6 +12,9 @@
import com.lf.server.mapper.sys.ReportMapper;
import com.lf.server.service.all.RedisService;
import com.lf.server.service.data.DownloadService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -27,6 +29,9 @@
 */
@Service
public class ReportService implements ReportMapper {
    @Value("${sys.turfServer}")
    private String turfServer;
    @Resource
    ReportMapper reportMapper;
@@ -41,6 +46,8 @@
    @Resource
    RedisService redisService;
    private final static Log log = LogFactory.getLog(ReportService.class);
    @Override
    public Integer selectCount(String name, String code) {
@@ -132,7 +139,7 @@
        List<CountEntity> list = reportMapper.countExplorationPoints();
        if (null != list && list.size() > 0) {
            countExplorationArea(list);
            redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES);
            redisService.put(key, list, StaticData.I2, TimeUnit.MINUTES);
        }
        return list;
@@ -152,17 +159,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 {