| package com.ruoyi.alarmpoints.well.service.impl; | 
|   | 
| import java.util.List; | 
|   | 
| import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWell; | 
| import com.ruoyi.alarmpoints.well.mapper.ArdAlarmpointsWellMapper; | 
| import com.ruoyi.alarmpoints.well.service.IArdAlarmpointsWellService; | 
| import com.ruoyi.common.annotation.DataScope; | 
| import com.ruoyi.common.core.domain.entity.SysUser; | 
| import com.ruoyi.common.exception.ServiceException; | 
| import com.ruoyi.common.utils.DateUtils; | 
| import com.ruoyi.common.utils.SecurityUtils; | 
| import com.ruoyi.common.utils.StringUtils; | 
| import com.ruoyi.common.utils.bean.BeanValidators; | 
| import com.ruoyi.common.utils.spring.SpringUtils; | 
| import lombok.ToString; | 
| import org.slf4j.Logger; | 
| import org.slf4j.LoggerFactory; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import javax.annotation.Resource; | 
| import javax.validation.Validator; | 
|   | 
| /** | 
|  * 井管理Service业务层处理 | 
|  * | 
|  * @author 刘苏义 | 
|  * @date 2023-03-07 | 
|  */ | 
| @Service | 
| public class ArdAlarmpointsWellServiceImpl implements IArdAlarmpointsWellService { | 
|     private static final Logger log = LoggerFactory.getLogger(ArdAlarmpointsWellServiceImpl.class); | 
|     @Resource | 
|     private ArdAlarmpointsWellMapper ardAlarmpointsWellMapper; | 
|     @Autowired | 
|     protected Validator validator; | 
|     /** | 
|      * 查询井管理 | 
|      * | 
|      * @param id 井管理主键 | 
|      * @return 井管理 | 
|      */ | 
|     @Override | 
|     public ArdAlarmpointsWell selectArdAlarmpointsWellById(String id) { | 
|         return ardAlarmpointsWellMapper.selectArdAlarmpointsWellById(id); | 
|     } | 
|     /** | 
|      * 查询井管理 | 
|      * | 
|      * @param wellId 井管理主键 | 
|      * @return 井管理 | 
|      */ | 
|     @Override | 
|     public ArdAlarmpointsWell selectArdAlarmpointsWellByWellId(String wellId) { | 
|         return ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellId(wellId); | 
|     } | 
|   | 
|     /** | 
|      * 查询井管理列表 | 
|      * | 
|      * @param ardAlarmpointsWell 井管理 | 
|      * @return 井管理 | 
|      */ | 
|     @Override | 
|     @DataScope(deptAlias = "d",userAlias = "u") | 
|     public List<ArdAlarmpointsWell> selectArdAlarmpointsWellList(ArdAlarmpointsWell ardAlarmpointsWell) { | 
|         return ardAlarmpointsWellMapper.selectArdAlarmpointsWellList(ardAlarmpointsWell); | 
|     } | 
|   | 
|     /** | 
|      * | 
|      * @param ardAlarmpointsWell 按井编号查询 | 
|      * @return | 
|      */ | 
|     @Override | 
|     @DataScope(deptAlias = "d",userAlias = "u") | 
|     public List<ArdAlarmpointsWell> selectArdAlarmpointsWellByWellIdLike(ArdAlarmpointsWell ardAlarmpointsWell) { | 
|         return ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellIdLike(ardAlarmpointsWell); | 
|     } | 
|   | 
|     /** | 
|      * 新增井管理 | 
|      * | 
|      * @param ardAlarmpointsWell 井管理 | 
|      * @return 结果 | 
|      */ | 
|     @Override | 
|     @Transactional | 
|     public int insertArdAlarmpointsWell(ArdAlarmpointsWell ardAlarmpointsWell) { | 
|         boolean wellIdExists = ardAlarmpointsWellMapper.checkWellIdExists(ardAlarmpointsWell.getWellId()); | 
|         if(wellIdExists) | 
|         { | 
|             throw new RuntimeException("井号已存在"); | 
|         } | 
|         ardAlarmpointsWell.setUserId(SecurityUtils.getUserId()); | 
|         ardAlarmpointsWell.setCreateBy(SecurityUtils.getUsername()); | 
|         ardAlarmpointsWell.setCreateTime(DateUtils.getNowDate()); | 
|         return ardAlarmpointsWellMapper.insertArdAlarmpointsWell(ardAlarmpointsWell); | 
|     } | 
|   | 
|     /** | 
|      * 修改井管理 | 
|      * | 
|      * @param ardAlarmpointsWell 井管理 | 
|      * @return 结果 | 
|      */ | 
|     @Override | 
|     @Transactional | 
|     public int updateArdAlarmpointsWell(ArdAlarmpointsWell ardAlarmpointsWell) { | 
|         boolean wellIdExists = ardAlarmpointsWellMapper.checkWellIdExists(ardAlarmpointsWell.getWellId()); | 
|         if(wellIdExists) | 
|         { | 
|             throw new RuntimeException("井号已存在"); | 
|         } | 
|         ardAlarmpointsWell.setUpdateBy(SecurityUtils.getUsername()); | 
|         ardAlarmpointsWell.setUpdateTime(DateUtils.getNowDate()); | 
|         return ardAlarmpointsWellMapper.updateArdAlarmpointsWell(ardAlarmpointsWell); | 
|     } | 
|   | 
|     /** | 
|      * 批量删除井管理 | 
|      * | 
|      * @param ids 需要删除的井管理主键 | 
|      * @return 结果 | 
|      */ | 
|     @Override | 
|     public int deleteArdAlarmpointsWellByIds(String[] ids) { | 
|         return ardAlarmpointsWellMapper.deleteArdAlarmpointsWellByIds(ids); | 
|     } | 
|   | 
|     /** | 
|      * 删除井管理信息 | 
|      * | 
|      * @param id 井管理主键 | 
|      * @return 结果 | 
|      */ | 
|     @Override | 
|     public int deleteArdAlarmpointsWellById(String id) { | 
|         return ardAlarmpointsWellMapper.deleteArdAlarmpointsWellById(id); | 
|     } | 
|   | 
|     @Override | 
|     public String importUser(List<ArdAlarmpointsWell> ardAlarmpointsWellList, Boolean isUpdateSupport, String operName) { | 
|         if (StringUtils.isNull(ardAlarmpointsWellList) || ardAlarmpointsWellList.size() == 0) { | 
|             throw new ServiceException("导入井数据不能为空!"); | 
|         } | 
|         int successNum = 0; | 
|         int failureNum = 0; | 
|         StringBuilder successMsg = new StringBuilder(); | 
|         StringBuilder failureMsg = new StringBuilder(); | 
|         for (ArdAlarmpointsWell well : ardAlarmpointsWellList) { | 
|             try { | 
|                 //获取当前登录用户id | 
|                 String userId = SecurityUtils.getUserId(); | 
|                 well.setUserId(userId); | 
|                 // 验证是否存在这个用户 | 
|                 ArdAlarmpointsWell u = ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellId(well.getWellId()); | 
|                 if (StringUtils.isNull(u)) { | 
|                     BeanValidators.validateWithException(validator, well); | 
|                     well.setCreateBy(operName); | 
|                     this.insertArdAlarmpointsWell(well); | 
|                     successNum++; | 
|                     successMsg.append("<br/>" + successNum + "、井号 " + well.getWellId() + " 导入成功"); | 
|                 } else if (isUpdateSupport) { | 
|                     BeanValidators.validateWithException(validator, well); | 
|                     checkWellAllowed(well); | 
|                     checkWellDataScope(well.getUserId()); | 
|                     well.setUpdateBy(operName); | 
|                     this.updateArdAlarmpointsWell(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 well 井信息 | 
|      */ | 
|     @Override | 
|     public void checkWellAllowed(ArdAlarmpointsWell well) | 
|     { | 
|         if (StringUtils.isNotNull(well.getId())) | 
|         { | 
|             throw new ServiceException("不允许操作井"); | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 校验用户是否有数据权限 | 
|      * | 
|      * @param userId 用户id | 
|      */ | 
|     @Override | 
|     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)) | 
|             { | 
|                 throw new ServiceException("没有权限访问井数据!"); | 
|             } | 
|         } | 
|     } | 
| } |