zhangnaisong
2024-04-30 de54d81a33ad0c47b3b561d824cf6f0fb6343d82
ard-work/src/main/java/com/ruoyi/alarmpoints/well/service/impl/ArdAlarmpointsWellServiceImpl.java
@@ -1,5 +1,7 @@
package com.ruoyi.alarmpoints.well.service.impl;
import java.awt.geom.Point2D;
import java.math.BigDecimal;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
@@ -24,9 +26,12 @@
import com.ruoyi.common.utils.bean.BeanValidators;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.device.camera.domain.ArdCameras;
import com.ruoyi.device.camera.mapper.ArdCamerasMapper;
import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.utils.data.Query;
import com.ruoyi.utils.gis.GisUtil;
import com.ruoyi.utils.gps.GeoTools;
import lombok.ToString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,6 +55,8 @@
    private ArdAlarmpointsWellMapper ardAlarmpointsWellMapper;
    @Resource
    private ArdWellGuideCameraMapper ardWellGuideCameraMapper;
    @Resource
    private ArdCamerasMapper ardCamerasMapper;
    @Autowired
    protected Validator validator;
@@ -291,14 +298,14 @@
        Integer pageNum = ardAlarmpointsWellParam.getPageNum();
        Integer pageSize = ardAlarmpointsWellParam.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
//        QueryWrapper<ArdAlarmpointsWell> queryWrapper = new QueryWrapper<>();
//        queryWrapper.select("id","altitude","metering_station","displacement_mode","latitude","dehydration_station",
//                "well_type","production_date","well_id","transfer_station","oil_production","run_status","longitude",
//                "installed_load","dept_id","user_id","surrounding_environment","well_number","well_block")
//                .eq(!StringUtils.isBlank(ardAlarmpointsWellParam.getWellId()), "well_id", ardAlarmpointsWellParam.getWellId())
//                .in("dept_id", ardAlarmpointsWellParam.getDeptList());
//        List<ArdAlarmpointsWell> list = ardAlarmpointsWellMapper.selectList(queryWrapper);
        List<ArdAlarmpointsWell> list = ardAlarmpointsWellMapper.conditionList(ardAlarmpointsWellParam);
        QueryWrapper<ArdAlarmpointsWell> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","altitude","metering_station","displacement_mode","latitude","dehydration_station",
                "well_type","production_date","well_id","transfer_station","oil_production","run_status","longitude",
                "installed_load","dept_id","user_id","surrounding_environment","well_number","well_block")
                .like(!StringUtils.isBlank(ardAlarmpointsWellParam.getWellId()), "well_id", ardAlarmpointsWellParam.getWellId())
                .in("dept_id", ardAlarmpointsWellParam.getDeptList());
        List<ArdAlarmpointsWell> list = ardAlarmpointsWellMapper.selectList(queryWrapper);
//        List<ArdAlarmpointsWell> list = ardAlarmpointsWellMapper.conditionList(ardAlarmpointsWellParam.getWellId(),ardAlarmpointsWellParam.getDeptList());
        return new PageInfo<>(list);
    }
@@ -575,6 +582,430 @@
        return result;
    }
    @Override
    public Map<String, Object> getWellDataByPatrolplanIdAndPosition(Map<String, Object> para, List<SysConfig> config) {
        String patrolplanId = (String) para.get("patrolplanId");
        Double longitude = null;
        Double latitude = null;
        try{
            longitude = (Double) para.get("longitude");
            latitude = (Double) para.get("latitude");
        } catch (Exception e){
            longitude = ((BigDecimal) para.get("longitude")).doubleValue();
            latitude = ((BigDecimal) para.get("latitude")).doubleValue();
        }
        ArdAlarmpointsWell ardAlarmpointsWell = ardAlarmpointsWellMapper.getWellDataByPatrolplanIdAndPosition(patrolplanId,longitude,latitude);
        if(ardAlarmpointsWell != null){
            Map<String, Object> result = new HashMap();
            if (ardAlarmpointsWell.getWellId() != null) {
                result.put("wellId", ardAlarmpointsWell.getWellId());
            } else {
                result.put("wellId", "");
            }
            if (ardAlarmpointsWell.getWellNumber() != null) {
                result.put("wellNumber", ardAlarmpointsWell.getWellNumber());
            } else {
                result.put("wellNumber", "");
            }
            if (ardAlarmpointsWell.getOilProduction() != null) {
                result.put("oilProduction", ardAlarmpointsWell.getOilProduction());
            } else {
                result.put("oilProduction", "");
            }
            if (ardAlarmpointsWell.getWellBlock() != null) {
                result.put("wellBlock", ardAlarmpointsWell.getWellBlock());
            } else {
                result.put("wellBlock", "");
            }
            if (ardAlarmpointsWell.getProductionDate() != null) {
                result.put("productionDate", ardAlarmpointsWell.getProductionDate());
            } else {
                result.put("productionDate", "");
            }
            if (ardAlarmpointsWell.getDisplacementMode() != null) {
                result.put("displacementMode", ardAlarmpointsWell.getDisplacementMode());
            } else {
                result.put("displacementMode", "");
            }
            if (ardAlarmpointsWell.getSurroundingEnvironment() != null) {
                result.put("surroundingEnvironment", ardAlarmpointsWell.getSurroundingEnvironment());
            } else {
                result.put("surroundingEnvironment", "");
            }
            if (ardAlarmpointsWell.getWellType() != null) {
                result.put("wellType", ardAlarmpointsWell.getWellType());
            } else {
                result.put("wellType", "");
            }
            if (ardAlarmpointsWell.getInstalledLoad() != null) {
                result.put("installedLoad", ardAlarmpointsWell.getInstalledLoad());
            } else {
                result.put("installedLoad", "");
            }
            if (ardAlarmpointsWell.getMeteringStation() != null) {
                result.put("meteringStation", ardAlarmpointsWell.getMeteringStation());
            } else {
                result.put("meteringStation", "");
            }
            if (ardAlarmpointsWell.getTransferStation() != null) {
                result.put("transferStation", ardAlarmpointsWell.getTransferStation());
            } else {
                result.put("transferStation", "");
            }
            if (ardAlarmpointsWell.getDehydrationStation() != null) {
                result.put("dehydrationStation", ardAlarmpointsWell.getDehydrationStation());
            } else {
                result.put("dehydrationStation", "");
            }
            if (ardAlarmpointsWell.getRunStatus() != null) {
                result.put("runStatus", ardAlarmpointsWell.getRunStatus());
            } else {
                result.put("runStatus", "");
            }
            if (ardAlarmpointsWell.getLongitude() != null) {
                result.put("longitude", ardAlarmpointsWell.getLongitude());
            } else {
                result.put("longitude", "");
            }
            if (ardAlarmpointsWell.getLatitude() != null) {
                result.put("latitude", ardAlarmpointsWell.getLatitude());
            } else {
                result.put("latitude", "");
            }
            if (ardAlarmpointsWell.getAltitude() != null) {
                result.put("altitude", ardAlarmpointsWell.getAltitude());
            } else {
                result.put("altitude", "");
            }
            if (ardAlarmpointsWell.getUserId() != null) {
                result.put("userId", ardAlarmpointsWell.getUserId());
            } else {
                result.put("userId", "");
            }
            if (ardAlarmpointsWell.getDeptId() != null) {
                result.put("deptId", ardAlarmpointsWell.getDeptId());
                SysDept sysDept = sysDeptMapper.selectDeptById(ardAlarmpointsWell.getDeptId());//查询兴趣点所在部门
                if (sysDept != null) {
                    result.put("deptName", sysDept.getDeptName());
                } else {
                    result.put("deptName", "");
                }
            } else {
                result.put("deptId", "");
                result.put("deptName", "");
            }
            if (ardAlarmpointsWell.getCreateBy() != null) {
                result.put("createBy", ardAlarmpointsWell.getCreateBy());
            } else {
                result.put("createBy", "");
            }
            if (ardAlarmpointsWell.getCreateTime() != null) {
                result.put("createTime", ardAlarmpointsWell.getCreateTime());
            } else {
                result.put("createTime", "");
            }
            if (ardAlarmpointsWell.getUpdateBy() != null) {
                result.put("updateBy", ardAlarmpointsWell.getUpdateBy());
            } else {
                result.put("updateBy", "");
            }
            if (ardAlarmpointsWell.getUpdateTime() != null) {
                result.put("updateTime", ardAlarmpointsWell.getUpdateTime());
            } else {
                result.put("updateTime", "");
            }
            if (config.size() != 0) {
                String oracle = config.get(0).getConfigValue();
                String[] oracleArr = oracle.split(";");
                if (oracleArr.length == 3) {
                    String url = oracle.split(";")[0];
                    String username = oracle.split(";")[1];
                    String password = oracle.split(";")[2];
                    try {
                        int checkMark = checkTable(url, username, password, "\'RTU_DATA_YJ_8\'");//三厂表存在
                        if (checkMark == 1) {
                            Map<String, Object> resultRTU = getRtuDataYjByJH(url, username, password, "RTU_DATA_YJ_8", "\'" + ardAlarmpointsWell.getWellId() + "\'");
                            result.putAll(resultRTU);
                        } else {
                            result.put("wellRunningState", "n");//油井运行状态
                            result.put("totalPowerConsumption", "n");//总耗电量
                            result.put("communicationMachine", "n");//设备通讯
                            result.put("remark", "n");//备注
                            result.put("singleWellWaterTemperature", "n");//单井掺水温度//
                            result.put("meteringPlantWaterPressure", "n");//计量间掺水压力//
                            result.put("torque", "n");//扭矩
                            result.put("MAT", "n");//回油温度
                            result.put("TGP", "n");//井口油压
                            result.put("CPV", "n");//井口套压
                            result.put("ADL", "n");//A相电流
                            result.put("ADY", "n");//A相电压
                            result.put("BDL", "n");//B相电流
                            result.put("BDY", "n");//B相电压
                            result.put("CDL", "n");//C相电流
                            result.put("CDY", "n");//C相电压
                            result.put("UCV", "n");//上行电流
                            result.put("DCV", "n");//下行电流
                            result.put("SLV", "n");//冲程
                            result.put("CHC", "n");//冲次
                            result.put("BPV", "n");//井口回压
                            result.put("ZWG", "n");//总无功功率
                            result.put("ZYG", "n");//总有功功率
                            result.put("GYS", "n");//功率因数
                            result.put("UWL", "n");//最大载荷
                            result.put("DWL", "n");//最小载荷
                            result.put("ZHS", "n");//转速
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else if (oracleArr.length == 4) {
                    String url = oracle.split(";")[0];
                    String username = oracle.split(";")[1];
                    String password = oracle.split(";")[2];
                    String prod = oracle.split(";")[3];
                    try {
                        //int checkMark = checkTable(url,username,password,"\'RTU_DATA_YJ_8\'");//三厂表存在
                        int checkMark = checkTable(url, username, password, "\'" + prod + ".RTU_DATA_YJ_8\'");//三厂表存在
                        if (checkMark == 1) {
                            Map<String, Object> resultRTU = getRtuDataYjByJH(url, username, password, prod + ".RTU_DATA_YJ_8", "\'" + ardAlarmpointsWell.getWellId() + "\'");
                            result.putAll(resultRTU);
                        } else {
                            result.put("wellRunningState", "n");//油井运行状态
                            result.put("totalPowerConsumption", "n");//总耗电量
                            result.put("communicationMachine", "n");//设备通讯
                            result.put("remark", "n");//备注
                            result.put("singleWellWaterTemperature", "n");//单井掺水温度//
                            result.put("meteringPlantWaterPressure", "n");//计量间掺水压力//
                            result.put("torque", "n");//扭矩
                            result.put("MAT", "n");//回油温度
                            result.put("TGP", "n");//井口油压
                            result.put("CPV", "n");//井口套压
                            result.put("ADL", "n");//A相电流
                            result.put("ADY", "n");//A相电压
                            result.put("BDL", "n");//B相电流
                            result.put("BDY", "n");//B相电压
                            result.put("CDL", "n");//C相电流
                            result.put("CDY", "n");//C相电压
                            result.put("UCV", "n");//上行电流
                            result.put("DCV", "n");//下行电流
                            result.put("SLV", "n");//冲程
                            result.put("CHC", "n");//冲次
                            result.put("BPV", "n");//井口回压
                            result.put("ZWG", "n");//总无功功率
                            result.put("ZYG", "n");//总有功功率
                            result.put("GYS", "n");//功率因数
                            result.put("UWL", "n");//最大载荷
                            result.put("DWL", "n");//最小载荷
                            result.put("ZHS", "n");//转速
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } else {
                result.put("wellRunningState", "n");//油井运行状态
                result.put("totalPowerConsumption", "n");//总耗电量
                result.put("communicationMachine", "n");//设备通讯
                result.put("remark", "n");//备注
                result.put("singleWellWaterTemperature", "n");//单井掺水温度//
                result.put("meteringPlantWaterPressure", "n");//计量间掺水压力//
                result.put("torque", "n");//扭矩
                result.put("MAT", "n");//回油温度
                result.put("TGP", "n");//井口油压
                result.put("CPV", "n");//井口套压
                result.put("ADL", "n");//A相电流
                result.put("ADY", "n");//A相电压
                result.put("BDL", "n");//B相电流
                result.put("BDY", "n");//B相电压
                result.put("CDL", "n");//C相电流
                result.put("CDY", "n");//C相电压
                result.put("UCV", "n");//上行电流
                result.put("DCV", "n");//下行电流
                result.put("SLV", "n");//冲程
                result.put("CHC", "n");//冲次
                result.put("BPV", "n");//井口回压
                result.put("ZWG", "n");//总无功功率
                result.put("ZYG", "n");//总有功功率
                result.put("GYS", "n");//功率因数
                result.put("UWL", "n");//最大载荷
                result.put("DWL", "n");//最小载荷
                result.put("ZHS", "n");//转速
            }
            return result;
        }else{
            return null;
        }
    }
    @Override
    public ArdAlarmpointsWell getWellById(String id) {
        ArdAlarmpointsWell result = ardAlarmpointsWellMapper.getWellById(id);
        return result;
    }
    @Override
    public List<Map<String, Object>> getCameraVideoLable(Long deptId, String cameraId, Float p, Float t, Float fHorFieldAngle, Float fVerFieldAngle) {
        ArdCameras ardCameras = ardCamerasMapper.selectArdCamerasById(cameraId);
        //小三角形腰
        Double xy = Math.tan(Math.PI/2 - (Math.PI * 2 - Math.PI * t/180) - Math.PI * fVerFieldAngle/180/2)*ardCameras.getAltitude()/Math.cos(Math.PI * fHorFieldAngle/180/2);
        //大三角形腰
        Double dy = Math.tan(Math.PI/2 - (Math.PI * 2 - Math.PI * t/180) + Math.PI * fVerFieldAngle/180/2)*ardCameras.getAltitude()/Math.cos(Math.PI * fHorFieldAngle/180/2);
        if(dy < 0){
            dy = -1 * dy;
        }
        if(xy < 0){
            xy = -1 * xy;
        }
        Double lonA = ardCameras.getLongitude() + xy * Math.sin((p + fHorFieldAngle/2)* Math.PI / 180) * 180 / ( Math.PI * 6371229 * Math.cos(ardCameras.getLatitude() * Math.PI / 180));
        Double latA = ardCameras.getLatitude() + xy * Math.cos((p + fHorFieldAngle/2)* Math.PI / 180) / ( Math.PI * 6371229 / 180);
        System.out.println("A点经度:" + lonA);
        System.out.println("A点纬度:" + latA);
        Double lonB = ardCameras.getLongitude() + xy * Math.sin((p - fHorFieldAngle/2)* Math.PI / 180) * 180 / ( Math.PI * 6371229 * Math.cos(ardCameras.getLatitude() * Math.PI / 180));
        Double latB = ardCameras.getLatitude() + xy * Math.cos((p - fHorFieldAngle/2)* Math.PI / 180) / ( Math.PI * 6371229 / 180);
        System.out.println("B点经度:" + lonB);
        System.out.println("B点纬度:" + latB);
        Double lonC = ardCameras.getLongitude() + dy * Math.sin((p + fHorFieldAngle/2)* Math.PI / 180) * 180 / ( Math.PI * 6371229 * Math.cos(ardCameras.getLatitude() * Math.PI / 180));
        Double latC = ardCameras.getLatitude() + dy * Math.cos((p + fHorFieldAngle/2)* Math.PI / 180) / ( Math.PI * 6371229 / 180);
        System.out.println("C点经度:" + lonC);
        System.out.println("C点纬度:" + latC);
        Double lonD = ardCameras.getLongitude() + dy * Math.sin((p - fHorFieldAngle/2)* Math.PI / 180) * 180 / ( Math.PI * 6371229 * Math.cos(ardCameras.getLatitude() * Math.PI / 180));
        Double latD = ardCameras.getLatitude() + dy * Math.cos((p - fHorFieldAngle/2)* Math.PI / 180) / ( Math.PI * 6371229 / 180);
        System.out.println("D点经度:" + lonD);
        System.out.println("D点纬度:" + latD);
        Double dg = Math.tan(Math.PI/2 - (Math.PI * 2 - Math.PI * t/180) - Math.PI * fVerFieldAngle/180/2)*ardCameras.getAltitude();//大三角形高
        Double xg = Math.tan(Math.PI/2 - (Math.PI * 2 - Math.PI * t/180) + Math.PI * fVerFieldAngle/180/2)*ardCameras.getAltitude();//小三角形高
        if(dg < 0){
            dg = -1 * dg;
        }
        if(xg < 0){
            xg = -1 * xg;
        }
        Double mg = xg + 0.5 * (dg - xg);
        Double lonM = ardCameras.getLongitude() + mg * Math.sin(p * Math.PI / 180) * 180 / ( Math.PI * 6371229 * Math.cos(ardCameras.getLatitude() * Math.PI / 180));
        Double latM = ardCameras.getLatitude() + mg * Math.cos(p * Math.PI / 180) / ( Math.PI * 6371229 / 180);
        System.out.println("中点经度:" + lonM);
        System.out.println("中点纬度:" + latM);
        //根据部门及光轴地面投影等腰梯形中点获取兴趣点
        List<ArdAlarmpointsWell> ardAlarmpointsWellResult = ardAlarmpointsWellMapper.getArdAlarmpointsWellByDeptIdAndDistance(deptId, lonM, latM, lonA, latA, lonB, latB, lonC, latC, lonD, latD);
        //设置多边形
        List<Point2D.Double> pts = new ArrayList<Point2D.Double>();
        pts.add(new Point2D.Double(lonA, latA));
        pts.add(new Point2D.Double(lonB, latB));
        pts.add(new Point2D.Double(lonD, latD));
        pts.add(new Point2D.Double(lonC, latC));
        List<ArdAlarmpointsWell> innerList = new ArrayList();//查找多边形内兴趣点
        for(ArdAlarmpointsWell ardAlarmpointsWell : ardAlarmpointsWellResult){
            Point2D.Double point = new Point2D.Double(ardAlarmpointsWell.getLongitude(), ardAlarmpointsWell.getLatitude());
            if(GeoTools.IsPtInPoly(point, pts)){
                innerList.add(ardAlarmpointsWell);
            }
        }
        List<Map<String,Object>> result = new ArrayList();
        for(ArdAlarmpointsWell ardAlarmpointsWell : innerList){
            Map<String,Object> map = new HashMap();
            double distance_Target = RealDistance(ardCameras.getLongitude(),ardCameras.getLatitude(),ardAlarmpointsWell.getLongitude(), ardAlarmpointsWell.getLatitude());
            double Angle_A = GetAngle(ardCameras.getLongitude(),ardCameras.getLatitude(),ardAlarmpointsWell.getLongitude(), ardAlarmpointsWell.getLatitude());
            double Angle_E = Math.atan((ardCameras.getAltitude() - 0) / distance_Target) * 180 / Math.PI;
            Angle_A = Angle_A - (p - fHorFieldAngle/2);//视场角内方位
            Angle_E = Angle_E - (360 - t - fVerFieldAngle/2);//视场角内俯仰
            if(!(Angle_E/fVerFieldAngle < 0.1 || Angle_A/fHorFieldAngle < 0.08 || Angle_A/fHorFieldAngle > 0.08)){//最上,最左,最右去掉
                map.put("id",ardAlarmpointsWell.getId());
                map.put("wellId",ardAlarmpointsWell.getWellId());
                map.put("horFieldProportion",Angle_A/fHorFieldAngle);//横向占比
                map.put("verFieldProportion",Angle_E/fVerFieldAngle);//纵向占比
                result.add(map);
            }
        }
        return result;
    }
    public static double RealDistance(double base_pos_longitude,double base_pos_latitude,double tar_pos_longitude,double tar_pos_latitude){
        double er;
        double f;
        double g;
        double l;
        double sg;
        double sl;
        double sf;
        double s;
        double c;
        double w;
        double r;
        double d;
        double h1;
        double h2;
        double fl;
        er = 6378.137;
        fl = 1 / 298.257;
        f = (base_pos_latitude + tar_pos_latitude)*Math.PI/360;
        g = (base_pos_latitude - tar_pos_latitude)*Math.PI/360;
        l = (base_pos_longitude - tar_pos_longitude)*Math.PI/360;
        sg = Math.sin(g);
        sl = Math.sin(l);
        sf = Math.sin(f);
        sg = Math.pow(sg,2);
        sl = Math.pow(sl,2);
        sf = Math.pow(sf,2);
        s = sg * (1 - sl) + (1 - sf) * sl;
        c = (1 - sg) * (1 - sl) + sf * sl;
        w = Math.atan(Math.sqrt(s / c));
        r = Math.sqrt(s * c) / w;
        d = 2 * w * er;
        h1 = (3 * r - 1) / 2 / c;
        h2 = (3 * r + 1) / 2 / s;
        return 1000*d * (1 + fl * (h1 * sf * (1 - sg) - h2 * (1 - sf) * sg));//84
    }
    public static double GetAngle(double base_pos_longitude,double base_pos_latitude,double tar_pos_longitude,double tar_pos_latitude){
        double lat1 = base_pos_latitude * Math.PI / 180;
        double lon1 = base_pos_longitude * Math.PI / 180;
        double lat2 = tar_pos_latitude * Math.PI / 180;
        double lon2 = tar_pos_longitude * Math.PI / 180;
        double d = Math.sin(lat2)*Math.sin(lat1) + Math.cos(lat2)*Math.cos(lat1)*Math.cos(lon2 - lon1);
        if (d != 1){
            d = Math.asin(Math.cos(lat2) * Math.sin(lon2 - lon1) / Math.sqrt(1 - d * d));
            d = d * 180 / Math.PI;
        }
        else {
            d = 0;
        }
        if (lat1>lat2) {
            d = 180 - d;
        }
        else {
            if (lon1>lon2) {
                d = 360 + d;
            }
        }
        return d;
    }
    public int checkTable(String url, String username, String password, String tableName) throws ClassNotFoundException, SQLException {
        Connection connection = null;