aijinhui
2023-12-23 f059de0b3cfe92ba2980c8ce4c5772637c64e9d2
ard-work/src/main/java/com/ruoyi/alarmpoints/well/service/impl/ArdAlarmpointsWellServiceImpl.java
@@ -1,5 +1,6 @@
package com.ruoyi.alarmpoints.well.service.impl;
import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -19,6 +20,7 @@
import com.ruoyi.common.utils.bean.BeanValidators;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.utils.gis.GisUtil;
import lombok.ToString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,6 +44,7 @@
    private ArdAlarmpointsWellMapper ardAlarmpointsWellMapper;
    @Autowired
    protected Validator validator;
    /**
     * 查询井管理
     *
@@ -52,6 +55,7 @@
    public ArdAlarmpointsWell selectArdAlarmpointsWellById(String id) {
        return ardAlarmpointsWellMapper.selectArdAlarmpointsWellById(id);
    }
    /**
     * 查询井管理
     *
@@ -70,18 +74,17 @@
     * @return 井管理
     */
    @Override
    @DataScope(deptAlias = "d",userAlias = "u")
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<ArdAlarmpointsWell> selectArdAlarmpointsWellList(ArdAlarmpointsWell ardAlarmpointsWell) {
        return ardAlarmpointsWellMapper.selectArdAlarmpointsWellList(ardAlarmpointsWell);
    }
    /**
     *
     * @param ardAlarmpointsWell 按井编号查询
     * @return
     */
    @Override
    @DataScope(deptAlias = "d",userAlias = "u")
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<ArdAlarmpointsWell> selectArdAlarmpointsWellByWellIdLike(ArdAlarmpointsWell ardAlarmpointsWell) {
        return ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellIdLike(ardAlarmpointsWell);
    }
@@ -96,8 +99,7 @@
    @Transactional
    public int insertArdAlarmpointsWell(ArdAlarmpointsWell ardAlarmpointsWell) {
        boolean wellIdExists = checkWellIdExists(ardAlarmpointsWell);
        if(wellIdExists)
        {
        if (wellIdExists) {
            throw new RuntimeException("井号已存在");
        }
        ardAlarmpointsWell.setId(IdUtils.simpleUUID());
@@ -117,15 +119,20 @@
    @Transactional
    public int updateArdAlarmpointsWell(ArdAlarmpointsWell ardAlarmpointsWell) {
        boolean wellIdExists = checkWellIdExists(ardAlarmpointsWell);
        if(wellIdExists)
        {
        if (wellIdExists) {
            throw new RuntimeException("井号已存在");
        }
        ardAlarmpointsWell.setUpdateBy(SecurityUtils.getUsername());
        ardAlarmpointsWell.setUpdateTime(DateUtils.getNowDate());
        return ardAlarmpointsWellMapper.updateArdAlarmpointsWell(ardAlarmpointsWell);
    }
    @Override
    @Transactional
    public int updateArdAlarmpointsWellByWellId(ArdAlarmpointsWell ardAlarmpointsWell) {
        ardAlarmpointsWell.setUpdateBy(SecurityUtils.getUsername());
        ardAlarmpointsWell.setUpdateTime(DateUtils.getNowDate());
        return ardAlarmpointsWellMapper.updateArdAlarmpointsWellByWellId(ardAlarmpointsWell);
    }
    /**
     * 批量删除井管理
     *
@@ -149,7 +156,7 @@
    }
    @Override
    public String importUser(List<ArdAlarmpointsWell> ardAlarmpointsWellList, Boolean isUpdateSupport, String operName) {
    public String importWell(List<ArdAlarmpointsWell> ardAlarmpointsWellList, Boolean isUpdateSupport, String operName) {
        if (StringUtils.isNull(ardAlarmpointsWellList) || ardAlarmpointsWellList.size() == 0) {
            throw new ServiceException("导入井数据不能为空!");
        }
@@ -162,9 +169,9 @@
                //获取当前登录用户id
                String userId = SecurityUtils.getUserId();
                well.setUserId(userId);
                // 验证是否存在这个用户
                ArdAlarmpointsWell u = ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellId(well.getWellId());
                if (StringUtils.isNull(u)) {
                // 验证是否存在这个井
                ArdAlarmpointsWell w = ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellId(well.getWellId());
                if (StringUtils.isNull(w)) {
                    BeanValidators.validateWithException(validator, well);
                    well.setCreateBy(operName);
                    this.insertArdAlarmpointsWell(well);
@@ -172,10 +179,9 @@
                    successMsg.append("<br/>" + successNum + "、井号 " + well.getWellId() + " 导入成功");
                } else if (isUpdateSupport) {
                    BeanValidators.validateWithException(validator, well);
                    checkWellAllowed(well);
                    checkWellDataScope(well.getUserId());
                    well.setUpdateBy(operName);
                    this.updateArdAlarmpointsWell(well);
                    this.updateArdAlarmpointsWellByWellId(well);
                    successNum++;
                    successMsg.append("<br/>" + successNum + "、井号 " + well.getWellId() + " 更新成功");
                } else {
@@ -204,10 +210,8 @@
     * @param well 井信息
     */
    @Override
    public void checkWellAllowed(ArdAlarmpointsWell well)
    {
        if (StringUtils.isNotNull(well.getId()))
        {
    public void checkWellAllowed(ArdAlarmpointsWell well) {
        if (StringUtils.isNotNull(well.getId())) {
            throw new ServiceException("不允许操作井");
        }
    }
@@ -218,23 +222,21 @@
     * @param userId 用户id
     */
    @Override
    public void checkWellDataScope(String userId)
    {
        if (!SysUser.isAdmin(SecurityUtils.getUserId()))
        {
    public void checkWellDataScope(String userId) {
        if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
            ArdAlarmpointsWell well = new ArdAlarmpointsWell();
            well.setUserId(userId);
            List<ArdAlarmpointsWell> wells = SpringUtils.getAopProxy(this).selectArdAlarmpointsWellList(well);
            if (StringUtils.isEmpty(wells))
            {
            if (StringUtils.isEmpty(wells)) {
                throw new ServiceException("没有权限访问井数据!");
            }
        }
    }
    /**
     * 核对井号是否唯一
     *
     * @param wellId 需要核对的井号
     * @param well 需要核对的井
     * @return 结果
     */
    @Override
@@ -254,7 +256,7 @@
    @Override
    public List<ArdAlarmpointsWell> wellByDeptList(List<Long> deptList) {
        QueryWrapper<ArdAlarmpointsWell> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("dept_id",deptList);
        queryWrapper.in("dept_id", deptList);
        return ardAlarmpointsWellMapper.selectList(queryWrapper);
    }
@@ -266,18 +268,18 @@
    @Override
    public List<ArdAlarmpointsWell> wellList(List<Long> deptList) {
        QueryWrapper<ArdAlarmpointsWell> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","well_id","oil_production","longitude","latitude","altitude").in("dept_id",deptList);
        queryWrapper.select("id", "well_id", "oil_production", "longitude", "latitude", "altitude").in("dept_id", deptList);
        return ardAlarmpointsWellMapper.selectList(queryWrapper);
    }
    @Override
    public PageInfo<ArdAlarmpointsWell> conditionList(ArdAlarmpointsWellParam ardAlarmpointsWellParam){
    public PageInfo<ArdAlarmpointsWell> conditionList(ArdAlarmpointsWellParam ardAlarmpointsWellParam) {
        Integer pageNum = ardAlarmpointsWellParam.getPageNum();
        Integer pageSize = ardAlarmpointsWellParam.getPageSize();
        PageHelper.startPage(pageNum,pageSize);
        PageHelper.startPage(pageNum, pageSize);
        QueryWrapper<ArdAlarmpointsWell> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("dept_id",ardAlarmpointsWellParam.getDeptList())
        .like(!StringUtils.isBlank(ardAlarmpointsWellParam.getWellId()),"well_id",ardAlarmpointsWellParam.getWellId());
        queryWrapper.in("dept_id", ardAlarmpointsWellParam.getDeptList())
                .like(!StringUtils.isBlank(ardAlarmpointsWellParam.getWellId()), "well_id", ardAlarmpointsWellParam.getWellId());
//        .eq(!StringUtils.isBlank(ardAlarmpointsWellParam.getWellNumber()),"well_number",ardAlarmpointsWellParam.getWellNumber())
//        .eq(!StringUtils.isBlank(ardAlarmpointsWellParam.getOilProduction()),"oil_production",ardAlarmpointsWellParam.getOilProduction())
//        .eq(!StringUtils.isBlank(ardAlarmpointsWellParam.getWellBlock()),"well_block",ardAlarmpointsWellParam.getWellBlock())
@@ -297,4 +299,31 @@
    public List<ArdAlarmpointsWellDeptVo> wellListDept(List<Long> deptList) {
        return ardAlarmpointsWellMapper.wellListDept(deptList);
    }
    @Override
    public List<ArdAlarmpointsWell> getNearbyWellList(Double longitudeCenter,Double latitudeCenter, Long deptId, Integer range) {
        List<ArdAlarmpointsWell> nearbyWellList = new ArrayList<>();
        try {
            if (longitudeCenter != null && latitudeCenter != null) {
                ArdAlarmpointsWell ardAlarmpointsWell=new ArdAlarmpointsWell();
                ardAlarmpointsWell.setDeptId(deptId);
                List<ArdAlarmpointsWell> ardAlarmpointsWells = ardAlarmpointsWellMapper.selectArdAlarmpointsWellList(ardAlarmpointsWell);
                if (ardAlarmpointsWells.size() > 0) {
                    for (ArdAlarmpointsWell well : ardAlarmpointsWells) {
                        Double longitude = well.getLongitude();
                        Double latitude = well.getLatitude();
                        if (longitude != null && latitude != null) {
                            double distance = GisUtil.getDistance(new Double[]{longitudeCenter, latitudeCenter}, new Double[]{longitude, latitude});
                            if (distance <= range) {
                                nearbyWellList.add(well);
                            }
                        }
                    }
                }
            }
        } catch (Exception ex) {
            log.error("获取附近井异常:" + ex.getMessage());
        }
        return nearbyWellList;
    }
}