package com.ard.work.point.well.service.impl;
|
|
import com.ard.common.core.constant.DeviceConstants;
|
import com.ard.common.core.constant.SecurityConstants;
|
import com.ard.common.core.constant.UserConstants;
|
import com.ard.common.core.domain.R;
|
import com.ard.common.core.exception.ServiceException;
|
import com.ard.common.core.utils.DateUtils;
|
import com.ard.common.core.utils.SpringUtils;
|
import com.ard.common.core.utils.StringUtils;
|
import com.ard.common.core.utils.bean.BeanValidators;
|
import com.ard.common.core.utils.uuid.IdUtils;
|
import com.ard.common.datascope.annotation.DataScope;
|
import com.ard.common.security.utils.SecurityUtils;
|
import com.ard.system.api.RemoteDeptService;
|
import com.ard.system.api.domain.SysDept;
|
import com.ard.system.api.domain.SysUser;
|
import com.ard.work.api.domian.ArdWell;
|
import com.ard.work.point.well.domain.ArdWellDeptVo;
|
import com.ard.work.point.well.domain.RtuDataYjEntity;
|
import com.ard.work.point.well.mapper.ArdWellMapper;
|
import com.ard.work.point.well.service.IArdWellService;
|
import com.ard.work.utils.data.Query;
|
import jakarta.annotation.Resource;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
|
import jakarta.validation.Validator;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import static com.ard.work.utils.gis.GisUtil.isInChina;
|
|
/**
|
* 井管理Service业务层处理
|
*
|
* @author ruoyi
|
* @date 2024-09-07
|
*/
|
@Slf4j
|
@Service
|
public class ArdWellServiceImpl implements IArdWellService {
|
|
@Value("${orcl.orclUrl}")
|
private String url;
|
|
@Value("${orcl.orclUser}")
|
private String user;
|
|
@Value("${orcl.orclPwd}")
|
private String pwd;
|
|
@Value("${orcl.orclSql}")
|
private String sql;
|
|
@Value("${orcl.openClose}")
|
private Boolean openClose;
|
|
@Resource
|
private ArdWellMapper ardWellMapper;
|
@Resource
|
protected Validator validator;
|
@Resource
|
private RemoteDeptService remoteDeptService;
|
|
/**
|
* 查询井管理
|
*
|
* @param id 井管理主键
|
* @return 井管理
|
*/
|
@Override
|
public ArdWell selectArdWellById(String id) {
|
ArdWell ardWell = ardWellMapper.selectArdWellById(id);
|
R<SysDept> r = remoteDeptService.getDeptById(ardWell.getDeptId(), SecurityConstants.INNER);
|
if (r.getCode() == 200) {
|
ardWell.setDeptName(r.getData().getDeptName());
|
}
|
|
return ardWell;
|
}
|
|
/**
|
* 查询井管理列表
|
*
|
* @param ardWell 井管理
|
* @return 井管理
|
*/
|
@Override
|
@DataScope(deptAlias = "d", userAlias = "u")
|
public List<ArdWell> selectArdWellList(ArdWell ardWell) {
|
return ardWellMapper.selectArdWellList(ardWell);
|
}
|
|
/**
|
* 新增井管理
|
*
|
* @param ardWell 井管理
|
* @return 结果
|
*/
|
@Override
|
public int insertArdWell(ArdWell ardWell) {
|
ardWell.setId(IdUtils.simpleUUID());
|
ardWell.setCreateTime(DateUtils.getNowDate());
|
return ardWellMapper.insertArdWell(ardWell);
|
}
|
|
/**
|
* 修改井管理
|
*
|
* @param ardWell 井管理
|
* @return 结果
|
*/
|
@Override
|
public int updateArdWell(ArdWell ardWell) {
|
ardWell.setUpdateTime(DateUtils.getNowDate());
|
return ardWellMapper.updateArdWell(ardWell);
|
}
|
|
/**
|
* 批量删除井管理
|
*
|
* @param ids 需要删除的井管理主键
|
* @return 结果
|
*/
|
@Override
|
public int deleteArdWellByIds(String[] ids) {
|
return ardWellMapper.deleteArdWellByIds(ids);
|
}
|
|
/**
|
* 删除井管理信息
|
*
|
* @param id 井管理主键
|
* @return 结果
|
*/
|
@Override
|
public int deleteArdWellById(String id) {
|
return ardWellMapper.deleteArdWellById(id);
|
}
|
|
/**
|
* 导入井管理数据
|
*
|
* @param ardWellList 井数据列表
|
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
* @param operName 操作用户
|
* @return 结果
|
*/
|
@Override
|
public String importWell(List<ArdWell> ardWellList, Boolean isUpdateSupport, String operName) {
|
if (StringUtils.isNull(ardWellList) || ardWellList.size() == 0) {
|
throw new ServiceException("导入井数据不能为空!");
|
}
|
int successNum = 0;
|
int failureNum = 0;
|
StringBuilder successMsg = new StringBuilder();
|
StringBuilder failureMsg = new StringBuilder();
|
for (ArdWell well : ardWellList) {
|
try {
|
//获取当前登录用户id
|
Long userId = SecurityUtils.getUserId();
|
well.setUserId(userId);
|
// 验证是否存在这个井
|
ArdWell w = ardWellMapper.selectArdWellByWellId(well.getWellId());
|
// 验证井是否在国内
|
if (!isInChina(well.getLongitude(), well.getLatitude())) {
|
throw new ServiceException(well.getWellId() + "经纬度不在中国范围内!");
|
}
|
if (StringUtils.isNull(w)) {
|
BeanValidators.validateWithException(validator, well);
|
well.setCreateBy(operName);
|
this.insertArdWell(well);
|
successNum++;
|
successMsg.append("<br/>" + successNum + "、井号 " + well.getWellId() + " 导入成功");
|
} else if (isUpdateSupport) {
|
BeanValidators.validateWithException(validator, well);
|
checkWellDataScope(well.getUserId());
|
well.setUpdateBy(operName);
|
this.updateArdWell(well);
|
successNum++;
|
successMsg.append("<br/>" + successNum + "、井号 " + well.getWellId() + " 更新成功");
|
} else {
|
failureNum++;
|
failureMsg.append("<br/>" + failureNum + "、井号 " + well.getWellId() + " 已存在");
|
}
|
} catch (Exception e) {
|
failureNum++;
|
String msg = "<br/>" + failureNum + "、井号 " + well.getWellId() + " 导入失败:";
|
failureMsg.append(msg + e.getMessage());
|
log.error(msg, e);
|
}
|
}
|
if (failureNum > 0) {
|
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
throw new ServiceException(failureMsg.toString());
|
} else {
|
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
}
|
return successMsg.toString();
|
}
|
|
|
/**
|
* 校验用户是否有数据权限
|
*
|
* @param userId 用户id
|
*/
|
@Override
|
public void checkWellDataScope(Long userId) {
|
if (!UserConstants.isAdmin(SecurityUtils.getUserId())) {
|
ArdWell well = new ArdWell();
|
well.setUserId(userId);
|
List<ArdWell> wells = SpringUtils.getAopProxy(this).selectArdWellList(well);
|
if (StringUtils.isEmpty(wells)) {
|
throw new ServiceException("没有权限访问井数据!");
|
}
|
}
|
}
|
|
/**
|
* 根据deptId获取对应所有兴趣点数据
|
*
|
* @param deptList deptId
|
* @return 结果
|
*/
|
@Override
|
public List<ArdWellDeptVo> wellListDept(List<Long> deptList) {
|
return ardWellMapper.wellListDept(deptList);
|
}
|
|
/**
|
* 根据wellId获取设备运行状态
|
*
|
* @param wellId wellId
|
* @return 结果
|
*/
|
@Override
|
public List<RtuDataYjEntity> getRTUDataYJ8(String wellId) {
|
if (!openClose) {
|
// 目前解决,六厂,二厂,四厂。没有数据库的问题,让其返回空不影响下一步操作。
|
return new ArrayList<>();
|
}
|
return Query.getRTUDataYJ8(wellId, url, user, pwd, sql);
|
}
|
|
|
/**
|
* 校验井号是否唯一
|
*
|
* @param ardWell 井信息
|
* @return 是否唯一
|
*/
|
@Override
|
public String checkWellIdUnique(ArdWell ardWell) {
|
String wellId = ardWell.getWellId();
|
ArdWell info = ardWellMapper.checkWellIdUnique(wellId);
|
if (StringUtils.isNotNull(info) && !info.getId().equals(ardWell.getId())) {
|
return DeviceConstants.NOT_UNIQUE;
|
}
|
return DeviceConstants.UNIQUE;
|
}
|
@Override
|
public List<ArdWell> selectArdWellByUserId(Long userId){
|
return ardWellMapper.selectArdWellByUserId(userId);
|
}
|
}
|