421 lines
14 KiB
Java
421 lines
14 KiB
Java
|
|
package com.gunshi.project.xyt.service;
|
||
|
|
|
||
|
|
import cn.hutool.core.bean.BeanUtil;
|
||
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||
|
|
import com.gunshi.project.xyt.entity.dto.StDamDto;
|
||
|
|
import com.gunshi.project.xyt.entity.dto.StResDto;
|
||
|
|
import com.gunshi.project.xyt.entity.dto.StRvDto;
|
||
|
|
import com.gunshi.project.xyt.entity.vo.StResVo;
|
||
|
|
import com.gunshi.project.xyt.model.*;
|
||
|
|
import com.gunshi.project.xyt.model.StDamBAutoDao;
|
||
|
|
import com.gunshi.project.xyt.model.StResBAutoDao;
|
||
|
|
import com.gunshi.project.xyt.model.StResStcdRefAutoDao;
|
||
|
|
import com.gunshi.project.xyt.model.StRvBAutoDao;
|
||
|
|
import jakarta.annotation.Resource;
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
import org.springframework.stereotype.Service;
|
||
|
|
import org.springframework.transaction.annotation.Transactional;
|
||
|
|
|
||
|
|
import java.util.ArrayList;
|
||
|
|
import java.util.Date;
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* TODO
|
||
|
|
*
|
||
|
|
* @ClassName EngineeringDrainageServiceImpl
|
||
|
|
* @Author Huang Qianxiang
|
||
|
|
* @Date 2024/1/24 14:38
|
||
|
|
*/
|
||
|
|
@Service
|
||
|
|
@Slf4j
|
||
|
|
@Transactional(rollbackFor = Exception.class)
|
||
|
|
public class EngineeringDrainageService {
|
||
|
|
|
||
|
|
@Resource
|
||
|
|
private StResBAutoDao stResBAutoDao;
|
||
|
|
@Resource
|
||
|
|
private StResStcdRefAutoDao stResStcdRefAutoDao;
|
||
|
|
@Resource
|
||
|
|
private StRvBAutoDao stRvBAutoDao;
|
||
|
|
@Resource
|
||
|
|
private StDamBAutoDao stDamBAutoDao;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 新增水库基础信息
|
||
|
|
* @param stResDto 水库的基础信息
|
||
|
|
*/
|
||
|
|
public void insertStRes(StResDto stResDto) {
|
||
|
|
StResB stResB = new StResB();
|
||
|
|
BeanUtil.copyProperties(stResDto,stResB);
|
||
|
|
Long resId = IdWorker.getId();
|
||
|
|
stResB.setResId(resId);
|
||
|
|
stResB.setStatus(1);
|
||
|
|
Date date = new Date();
|
||
|
|
stResB.setTm(date);
|
||
|
|
|
||
|
|
//判断水库代码是否唯一
|
||
|
|
if (queryByResCode(stResDto.getResCode()) != null){
|
||
|
|
throw new IllegalArgumentException("水库代码必须唯一");
|
||
|
|
}
|
||
|
|
|
||
|
|
//保存水库基本信息
|
||
|
|
stResBAutoDao.save(stResB);
|
||
|
|
|
||
|
|
StResStcdRef stResStcdRef = new StResStcdRef();
|
||
|
|
stResStcdRef.setResId(resId);
|
||
|
|
stResStcdRef.setStcd(stResDto.getSTCD());
|
||
|
|
stResStcdRef.setTm(date);
|
||
|
|
|
||
|
|
//保存测站关系
|
||
|
|
stResStcdRefAutoDao.save(stResStcdRef);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 更新水库的基础信息
|
||
|
|
* @param stResDto 水库的基础信息
|
||
|
|
*/
|
||
|
|
public void updateStRes(StResDto stResDto) {
|
||
|
|
Long resId = stResDto.getResId();
|
||
|
|
StResB byId = stResBAutoDao.getById(resId);
|
||
|
|
if (byId == null) {
|
||
|
|
throw new IllegalArgumentException("resId:" + resId + "不存在");
|
||
|
|
}
|
||
|
|
//判断水库代码是否唯一
|
||
|
|
if (queryByResCode(stResDto.getResCode()) != null){
|
||
|
|
throw new IllegalArgumentException("水库代码必须唯一");
|
||
|
|
}
|
||
|
|
|
||
|
|
StResB stResB = new StResB();
|
||
|
|
BeanUtil.copyProperties(stResDto,stResB);
|
||
|
|
Date date = new Date();
|
||
|
|
stResB.setTm(date);
|
||
|
|
//更新水库基本信息
|
||
|
|
stResBAutoDao.updateById(stResB);
|
||
|
|
|
||
|
|
if (stResDto.getSTCD() != null){
|
||
|
|
StResStcdRef stResStcdRef = new StResStcdRef();
|
||
|
|
stResStcdRef.setResId(resId);
|
||
|
|
stResStcdRef.setStcd(stResDto.getSTCD());
|
||
|
|
stResStcdRef.setTm(date);
|
||
|
|
//更新水库测站关系
|
||
|
|
StResStcdRef byId1 = stResStcdRefAutoDao.getById(resId);
|
||
|
|
if (byId1 != null) {
|
||
|
|
//先删除之前存在的关系
|
||
|
|
stResStcdRefAutoDao.removeById(resId);
|
||
|
|
}
|
||
|
|
//更新当前水库测站关系
|
||
|
|
stResStcdRefAutoDao.save(stResStcdRef);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 根据水库ID删除水库基本信息
|
||
|
|
* @param resId 水库ID
|
||
|
|
*/
|
||
|
|
public void deleteStRes(String resId) {
|
||
|
|
QueryWrapper<StResB> queryWrapper = new QueryWrapper<>();
|
||
|
|
queryWrapper.eq(StResB.COL_RES_ID,resId)
|
||
|
|
.eq(StResB.COL_STATUS,1);
|
||
|
|
StResB byId = stResBAutoDao.getOne(queryWrapper);
|
||
|
|
if (byId == null) {
|
||
|
|
throw new IllegalArgumentException("resId:" + resId + "不存在");
|
||
|
|
}
|
||
|
|
UpdateWrapper<StResB> updateWrapper = new UpdateWrapper<>();
|
||
|
|
//水库状态更新为禁用
|
||
|
|
updateWrapper.eq(StResB.COL_RES_ID,resId)
|
||
|
|
.set(StResB.COL_STATUS,0);
|
||
|
|
stResBAutoDao.update(updateWrapper);
|
||
|
|
//删除水库测站关系
|
||
|
|
stResStcdRefAutoDao.removeById(resId);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 根据水库代码查询水库的基础信息
|
||
|
|
* @param resCode 水库代码
|
||
|
|
* @return 水库的基础信息
|
||
|
|
*/
|
||
|
|
public StResB queryByResCode(String resCode) {
|
||
|
|
QueryWrapper<StResB> queryWrapper = new QueryWrapper<>();
|
||
|
|
queryWrapper.eq(StResB.COL_RES_CODE,resCode);
|
||
|
|
return stResBAutoDao.getOne(queryWrapper);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 根据水库ID查询水库的基础信息
|
||
|
|
* @param resId 水库ID
|
||
|
|
* @return 水库的基础信息
|
||
|
|
*/
|
||
|
|
public StResVo queryByResId(String resId) {
|
||
|
|
StResB stResB = stResBAutoDao.getById(resId);
|
||
|
|
StResStcdRef stResStcdRef = stResStcdRefAutoDao.getById(resId);
|
||
|
|
if (stResB == null) {
|
||
|
|
throw new IllegalArgumentException("resId:" + resId + "不存在");
|
||
|
|
}
|
||
|
|
StResVo stResVo = new StResVo();
|
||
|
|
BeanUtil.copyProperties(stResB,stResVo);
|
||
|
|
stResVo.setSTCD(stResStcdRef.getStcd());
|
||
|
|
return stResVo;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 查询水库的基础信息
|
||
|
|
* @return 水库的基础信息
|
||
|
|
*/
|
||
|
|
public List<StResVo> queryStRes() {
|
||
|
|
List<StResB> stResBList = stResBAutoDao
|
||
|
|
.list(new QueryWrapper<StResB>().eq(StResB.COL_STATUS,1));
|
||
|
|
List<StResVo> stResVoList = new ArrayList<>();
|
||
|
|
stResBList.stream().forEach(stResB -> {
|
||
|
|
StResVo stResVo = new StResVo();
|
||
|
|
BeanUtil.copyProperties(stResB,stResVo);
|
||
|
|
StResStcdRef stResStcdRef = stResStcdRefAutoDao.getById(stResB.getResId());
|
||
|
|
stResVo.setSTCD(stResStcdRef.getStcd());
|
||
|
|
stResVoList.add(stResVo);
|
||
|
|
});
|
||
|
|
return stResVoList;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 根据水库名称模糊查询水库的基础信息
|
||
|
|
* @param resName 水库名称
|
||
|
|
* @return 水库基础信息
|
||
|
|
*/
|
||
|
|
public List<StResVo> queryLikeResName(String resName) {
|
||
|
|
QueryWrapper<StResB> queryWrapper = new QueryWrapper<>();
|
||
|
|
queryWrapper.like(StResB.COL_RES_NAME,resName)
|
||
|
|
.eq(StResB.COL_STATUS,1);
|
||
|
|
List<StResB> stResBList = stResBAutoDao.list(queryWrapper);
|
||
|
|
List<StResVo> stResVoList = new ArrayList<>();
|
||
|
|
stResBList.stream().forEach(stResB -> {
|
||
|
|
StResVo stResVo = new StResVo();
|
||
|
|
BeanUtil.copyProperties(stResB,stResVo);
|
||
|
|
StResStcdRef stResStcdRef = stResStcdRefAutoDao.getById(stResB.getResId());
|
||
|
|
stResVo.setSTCD(stResStcdRef.getStcd());
|
||
|
|
stResVoList.add(stResVo);
|
||
|
|
});
|
||
|
|
return stResVoList;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 根据水库规模查询水库的基础信息
|
||
|
|
* @param engScal 水库规模
|
||
|
|
* @return 水库的基础信息
|
||
|
|
*/
|
||
|
|
public List<StResVo> queryByEngScal(String engScal) {
|
||
|
|
QueryWrapper<StResB> queryWrapper = new QueryWrapper<>();
|
||
|
|
queryWrapper.eq(StResB.COL_ENG_SCAL,engScal)
|
||
|
|
.eq(StResB.COL_STATUS,1);
|
||
|
|
List<StResB> stResBList = stResBAutoDao.list(queryWrapper);
|
||
|
|
List<StResVo> stResVoList = new ArrayList<>();
|
||
|
|
stResBList.stream().forEach(stResB -> {
|
||
|
|
StResVo stResVo = new StResVo();
|
||
|
|
BeanUtil.copyProperties(stResB,stResVo);
|
||
|
|
StResStcdRef stResStcdRef = stResStcdRefAutoDao.getById(stResB.getResId());
|
||
|
|
stResVo.setSTCD(stResStcdRef.getStcd());
|
||
|
|
stResVoList.add(stResVo);
|
||
|
|
});
|
||
|
|
return stResVoList;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 新增河流基础信息
|
||
|
|
* @param stRvDto 河流的基础信息DTO
|
||
|
|
*/
|
||
|
|
public void insertStRv(StRvDto stRvDto) {
|
||
|
|
if (queryByResCode(stRvDto.getRvCode()) != null){
|
||
|
|
throw new IllegalArgumentException("河流代码必须唯一");
|
||
|
|
}
|
||
|
|
StRvB stRvB = new StRvB();
|
||
|
|
BeanUtil.copyProperties(stRvDto,stRvB);
|
||
|
|
Long rvId = IdWorker.getId();
|
||
|
|
stRvB.setRvId(rvId);
|
||
|
|
stRvB.setStatus(1);
|
||
|
|
stRvB.setTm(new Date());
|
||
|
|
stRvBAutoDao.save(stRvB);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 更新河流的基础信息
|
||
|
|
* @param stRvB 河流的基础信息
|
||
|
|
*/
|
||
|
|
public void updateStRv(StRvB stRvB) {
|
||
|
|
Long rvId = stRvB.getRvId();
|
||
|
|
StRvB byId = stRvBAutoDao.getById(rvId);
|
||
|
|
if (byId == null){
|
||
|
|
throw new IllegalArgumentException("河流ID: " + rvId + "不存在");
|
||
|
|
}
|
||
|
|
stRvB.setTm(new Date());
|
||
|
|
stRvBAutoDao.updateById(stRvB);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 根据河流ID删除河流信息
|
||
|
|
* @param rvId 河流ID
|
||
|
|
*/
|
||
|
|
public void deleteStRv(String rvId) {
|
||
|
|
QueryWrapper<StRvB> queryWrapper = new QueryWrapper<>();
|
||
|
|
queryWrapper.eq(StRvB.COL_RV_ID,rvId)
|
||
|
|
.eq(StRvB.COL_STATUS,1);
|
||
|
|
StRvB byId = stRvBAutoDao.getOne(queryWrapper);
|
||
|
|
if (byId == null){
|
||
|
|
throw new IllegalArgumentException("河流ID: " + rvId + "不存在, 或河流ID: " + rvId + "已被禁用");
|
||
|
|
}
|
||
|
|
UpdateWrapper<StRvB> updateWrapper = new UpdateWrapper<>();
|
||
|
|
updateWrapper.eq(StRvB.COL_RV_ID,rvId)
|
||
|
|
.set(StRvB.COL_STATUS,0);
|
||
|
|
stRvBAutoDao.update(updateWrapper);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 根据河流代码查询河流的基础信息
|
||
|
|
* @param rvCode 河流代码
|
||
|
|
* @return 河流的基础信息
|
||
|
|
*/
|
||
|
|
public StRvB queryByRvCode(String rvCode) {
|
||
|
|
QueryWrapper<StRvB> queryWrapper = new QueryWrapper<>();
|
||
|
|
queryWrapper.eq(StRvB.COL_RV_CODE,rvCode)
|
||
|
|
.eq(StRvB.COL_STATUS,1);
|
||
|
|
return stRvBAutoDao.getOne(queryWrapper);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 根据河流ID查询河流的基础信息
|
||
|
|
* @param rvId 河流ID
|
||
|
|
* @return 河流的基础信息
|
||
|
|
*/
|
||
|
|
public StRvB queryByRvId(String rvId) {
|
||
|
|
StRvB stRvB = stRvBAutoDao.getById(rvId);
|
||
|
|
if (stRvB == null){
|
||
|
|
throw new IllegalArgumentException("河流ID: "+ rvId +"不存在");
|
||
|
|
}
|
||
|
|
return stRvB;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 分页查询河流的基础信息
|
||
|
|
* @param pageNum 当前页
|
||
|
|
* @param pageSize 每页显示条数
|
||
|
|
* @return
|
||
|
|
*/
|
||
|
|
public Page<StRvB> pageStRv(int pageNum,int pageSize) {
|
||
|
|
QueryWrapper<StRvB> queryWrapper = new QueryWrapper<>();
|
||
|
|
queryWrapper.eq(StRvB.COL_STATUS,1);
|
||
|
|
return stRvBAutoDao.page(new Page<>(pageNum,pageSize),queryWrapper);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 根据河流名称模糊查询河流信息
|
||
|
|
* @param rvName 河流名称
|
||
|
|
* @param pageNum 当前页
|
||
|
|
* @param pageSize 每页显示条数
|
||
|
|
* @return
|
||
|
|
*/
|
||
|
|
public Page<StRvB> queryLikeRvName(String rvName,int pageNum,int pageSize) {
|
||
|
|
QueryWrapper<StRvB> queryWrapper = new QueryWrapper<>();
|
||
|
|
queryWrapper.like(StRvB.COL_RV_NAME,rvName)
|
||
|
|
.eq(StRvB.COL_STATUS,1);
|
||
|
|
return stRvBAutoDao.page(new Page<>(pageNum,pageSize),queryWrapper);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 新增大坝基础信息
|
||
|
|
* @param stDamDto 大坝基础信息DTO
|
||
|
|
*/
|
||
|
|
public void insertStDam(StDamDto stDamDto) {
|
||
|
|
if (queryByDamCode(stDamDto.getDamCode()) != null){
|
||
|
|
throw new IllegalArgumentException("大坝代码必须唯一");
|
||
|
|
}
|
||
|
|
StDamB stDamB = new StDamB();
|
||
|
|
BeanUtil.copyProperties(stDamDto,stDamB);
|
||
|
|
Long damId = IdWorker.getId();
|
||
|
|
stDamB.setDamId(damId);
|
||
|
|
stDamB.setStatus(1);
|
||
|
|
stDamB.setTm(new Date());
|
||
|
|
stDamBAutoDao.save(stDamB);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 更新大坝基础信息
|
||
|
|
* @param stDamB 大坝基础信息
|
||
|
|
*/
|
||
|
|
public void updateStDam(StDamB stDamB) {
|
||
|
|
Long damId = stDamB.getDamId();
|
||
|
|
StDamB byId = stDamBAutoDao.getById(damId);
|
||
|
|
if (byId == null){
|
||
|
|
throw new IllegalArgumentException("大坝ID: " + damId + "不存在");
|
||
|
|
}
|
||
|
|
stDamB.setTm(new Date());
|
||
|
|
stDamBAutoDao.updateById(stDamB);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 删除大坝基础信息
|
||
|
|
* @param damId 大坝ID
|
||
|
|
*/
|
||
|
|
public void deleteStDam(String damId) {
|
||
|
|
StDamB byId = stDamBAutoDao.getById(damId);
|
||
|
|
if (byId == null){
|
||
|
|
throw new IllegalArgumentException("大坝ID: " + damId + "不存在");
|
||
|
|
}
|
||
|
|
UpdateWrapper<StDamB> updateWrapper = new UpdateWrapper<>();
|
||
|
|
updateWrapper.eq(StDamB.COL_DAM_ID,damId)
|
||
|
|
.set(StDamB.COL_STATUS,0);
|
||
|
|
stDamBAutoDao.update(updateWrapper);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 根据大坝ID查询大坝信息
|
||
|
|
* @param damId 大坝ID
|
||
|
|
* @return 大坝基础信息
|
||
|
|
*/
|
||
|
|
public StDamB queryByDamId(String damId) {
|
||
|
|
StDamB stDamB = stDamBAutoDao.getById(damId);
|
||
|
|
if (stDamB == null){
|
||
|
|
throw new IllegalArgumentException("大坝ID: " + damId+ "不存在");
|
||
|
|
}
|
||
|
|
return stDamB;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 根据大坝代码查询大坝信息
|
||
|
|
* @param damCode 大坝代码
|
||
|
|
* @return 大坝基础信息
|
||
|
|
*/
|
||
|
|
public StDamB queryByDamCode(String damCode) {
|
||
|
|
QueryWrapper<StDamB> queryWrapper = new QueryWrapper<>();
|
||
|
|
queryWrapper.eq(StDamB.COL_DAM_CODE,damCode)
|
||
|
|
.eq(StDamB.COL_STATUS,1);
|
||
|
|
return stDamBAutoDao.getOne(queryWrapper);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 分页查询大坝基础信息
|
||
|
|
* @param pageNum 当前页
|
||
|
|
* @param pageSize 每页显示条数
|
||
|
|
* @return
|
||
|
|
*/
|
||
|
|
public Page<StDamB> pageStDam(int pageNum, int pageSize) {
|
||
|
|
QueryWrapper<StDamB> queryWrapper = new QueryWrapper<>();
|
||
|
|
queryWrapper.eq(StDamB.COL_STATUS,1);
|
||
|
|
return stDamBAutoDao.page(new Page<>(pageNum,pageSize),queryWrapper);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 根据大坝名称模糊查询大坝基础信息
|
||
|
|
* @param damName 大坝名称
|
||
|
|
* @param pageNum 当前页
|
||
|
|
* @param pageSize 每页显示条数
|
||
|
|
* @return
|
||
|
|
*/
|
||
|
|
public Page<StDamB> queryLikeDamName(String damName, int pageNum, int pageSize) {
|
||
|
|
QueryWrapper<StDamB> queryWrapper = new QueryWrapper<>();
|
||
|
|
queryWrapper.like(StDamB.COL_DAM_NAME,damName)
|
||
|
|
.eq(StDamB.COL_STATUS,1);
|
||
|
|
return stDamBAutoDao.page(new Page<>(pageNum,pageSize),queryWrapper);
|
||
|
|
}
|
||
|
|
}
|