package com.gunshi.project.xyt.service; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gunshi.project.xyt.entity.dto.*; import com.gunshi.project.xyt.model.*; import com.gunshi.project.xyt.model.StDamBAutoDao; import com.gunshi.project.xyt.model.StEqptBAutoDao; import com.gunshi.project.xyt.model.StGateBAutoDao; import com.gunshi.project.xyt.model.StResBAutoDao; import com.gunshi.project.xyt.model.StResStcdRefAutoDao; import com.gunshi.project.xyt.model.StRvBAutoDao; import com.gunshi.project.xyt.so.*; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.print.DocFlavor; 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; @Resource private StGateBAutoDao stGateBAutoDao; @Resource private StEqptBAutoDao stEqptBAutoDao; /** * 新增水库基础信息 * @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); } /** * 更新水库的基础信息 * @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); } /** * 根据水库ID删除水库基本信息 * @param resId 水库ID */ public void deleteStRes(String resId) { QueryWrapper 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 updateWrapper = new UpdateWrapper<>(); //水库状态更新为禁用 updateWrapper.eq(StResB.COL_RES_ID,resId) .set(StResB.COL_STATUS,0); stResBAutoDao.update(updateWrapper); } /** * 分页查询水库基本信息 * @param stResPageSo 水库基本信息查询参数 * @return */ public Page pageStRes(StResPageSo stResPageSo){ if (StringUtils.isNotEmpty(stResPageSo.getResId())){ StResB stResB = stResBAutoDao.getById(stResPageSo.getResId()); if (stResB == null){ return null; } List resBList = List.of(stResB); return new Page(1,1,1).setRecords(resBList); } LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); if (StringUtils.isNotEmpty(stResPageSo.getResName())){ lambdaQueryWrapper.like(StringUtils.isNotEmpty(stResPageSo.getResName()),StResB::getResName,stResPageSo.getResName()); } if (StringUtils.isNotEmpty(stResPageSo.getResCode())){ lambdaQueryWrapper.like(StringUtils.isNotEmpty(stResPageSo.getResCode()),StResB::getResCode,stResPageSo.getResCode()); } if (StringUtils.isNotEmpty(stResPageSo.getEngScal())){ lambdaQueryWrapper.eq(StringUtils.isNotEmpty(stResPageSo.getEngScal()),StResB::getEngScal,stResPageSo.getEngScal()); } if (stResPageSo.getStatus() != null){ lambdaQueryWrapper.eq(StResB::getStatus,stResPageSo.getStatus()); } return stResBAutoDao.page(stResPageSo.getPageSo().toPage(),lambdaQueryWrapper); } /** * 根据水库代码查询水库的基础信息 * @param resCode 水库代码 * @return 水库的基础信息 */ public StResB queryByResCode(String resCode) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq(StResB.COL_RES_CODE,resCode); return stResBAutoDao.getOne(queryWrapper); } /** * 新增河流基础信息 * @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 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 updateWrapper = new UpdateWrapper<>(); updateWrapper.eq(StRvB.COL_RV_ID,rvId) .set(StRvB.COL_STATUS,0); stRvBAutoDao.update(updateWrapper); } /** * 分页查询河流基础信息 * @param stRvPageSo 河流基本信息查询参数 */ public Page pageStRv(StRvPageSo stRvPageSo){ if (StringUtils.isNotEmpty(stRvPageSo.getRvId())){ StRvB stRvB = stRvBAutoDao.getById(stRvPageSo.getRvId()); if (stRvB == null){ return null; } List rvBList = List.of(stRvB); return new Page(1,1,1).setRecords(rvBList); } LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); if (StringUtils.isNotEmpty(stRvPageSo.getRvName())){ lambdaQueryWrapper.like(StringUtils.isNotEmpty(stRvPageSo.getRvName()),StRvB::getRvCode,stRvPageSo.getRvName()); } if (StringUtils.isNotEmpty(stRvPageSo.getRvCode())){ lambdaQueryWrapper.like(StringUtils.isNotEmpty(stRvPageSo.getRvCode()),StRvB::getRvCode,stRvPageSo.getRvCode()); } if (stRvPageSo.getStatus() != null){ lambdaQueryWrapper.eq(StRvB::getStatus,stRvPageSo.getStatus()); } return stRvBAutoDao.page(stRvPageSo.getPageSo().toPage(),lambdaQueryWrapper); } /** * 根据河流代码查询河流的基础信息 * @param rvCode 河流代码 * @return 河流的基础信息 */ public StRvB queryByRvCode(String rvCode) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq(StRvB.COL_RV_CODE,rvCode) .eq(StRvB.COL_STATUS,1); return stRvBAutoDao.getOne(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); } /** * 根据大坝ID删除大坝基础信息 * @param damId 大坝ID */ public void deleteStDam(String damId) { StDamB byId = stDamBAutoDao.getById(damId); if (byId == null){ throw new IllegalArgumentException("大坝ID: " + damId + "不存在"); } UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.eq(StDamB.COL_DAM_ID,damId) .set(StDamB.COL_STATUS,0); stDamBAutoDao.update(updateWrapper); } /** * 分页查询大坝基础信息 * @param stDamPageSo 大坝基本信息查询参数 * @return */ public Page pageStDam(StDamPageSo stDamPageSo){ if (StringUtils.isNotEmpty(stDamPageSo.getDamId())){ StDamB stDamB = stDamBAutoDao.getById(stDamPageSo.getDamId()); if (stDamB == null){ return null; } List damBList = List.of(stDamB); return new Page(1,1,1).setRecords(damBList); } LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); if (StringUtils.isNotEmpty(stDamPageSo.getDamName())){ lambdaQueryWrapper.like(StringUtils.isNotEmpty(stDamPageSo.getDamName()),StDamB::getDamName,stDamPageSo.getDamName()); } if (StringUtils.isNotEmpty(stDamPageSo.getDamCode())){ lambdaQueryWrapper.like(StringUtils.isNotEmpty(stDamPageSo.getDamCode()),StDamB::getDamCode,stDamPageSo.getDamCode()); } if (stDamPageSo.getStatus() != null){ lambdaQueryWrapper.eq(StDamB::getStatus,stDamPageSo.getStatus()); } return stDamBAutoDao.page(stDamPageSo.getPageSo().toPage(),lambdaQueryWrapper); } /** * 根据大坝代码查询大坝信息 * @param damCode 大坝代码 * @return 大坝基础信息 */ public StDamB queryByDamCode(String damCode) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq(StDamB.COL_DAM_CODE,damCode) .eq(StDamB.COL_STATUS,1); return stDamBAutoDao.getOne(queryWrapper); } /** * 新增闸阀基础信息 * @param stGateDto 闸阀基础信息DTO */ public void insertStGate(StGateDto stGateDto){ if (queryByGateCode(stGateDto.getGateCd()) != null){ throw new IllegalArgumentException("闸阀编码必须唯一"); } StGateB stGateB = new StGateB(); BeanUtil.copyProperties(stGateDto,stGateB); long gateId = IdWorker.getId(); stGateB.setGateId(gateId); stGateB.setTm(new Date()); stGateBAutoDao.save(stGateB); } /** * 更新闸阀基础信息 * @param stGateB 闸阀基础信息 */ public void updateStGate(StGateB stGateB){ Long gateId = stGateB.getGateId(); StGateB byId = stGateBAutoDao.getById(gateId); if (byId == null){ throw new IllegalArgumentException("闸阀ID : " + gateId + "不存在"); } stGateB.setTm(new Date()); stGateBAutoDao.updateById(stGateB); } /** * 根据闸阀ID删除闸阀基础信息 * @param gateId 闸阀ID */ public void deleteStGate(String gateId){ QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq(StGateB.COL_GATE_ID,gateId) .eq(StGateB.COL_STATUS,1); StGateB stGateB = stGateBAutoDao.getById(gateId); if (stGateB == null){ throw new IllegalArgumentException("闸阀ID : " + gateId + "不存在或闸阀ID : " + gateId + "已被禁用"); } UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.eq(StGateB.COL_GATE_ID,gateId) .set(StGateB.COL_STATUS,0); stGateBAutoDao.update(updateWrapper); } /** * 根据闸阀编码查询闸阀基础信息 * @param gateCd 闸阀编码 * @return 闸阀基础信息 */ public StGateB queryByGateCode(String gateCd){ QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq(StGateB.COL_GATE_CD,gateCd) .eq(StGateB.COL_STATUS,1); return stGateBAutoDao.getOne(queryWrapper); } /** * 分页查询闸阀基础信息 * @param stGatePageSo 闸阀基本信息查询参数 * @return */ public Page pageStGate(StGatePageSo stGatePageSo){ if (StringUtils.isNotEmpty(stGatePageSo.getGateId())){ StGateB stGateB = stGateBAutoDao.getById(stGatePageSo.getGateId()); if (stGateB == null){ return null; } List gateBList = List.of(stGateB); return new Page(1,1,1).setRecords(gateBList); } LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); if (StringUtils.isNotEmpty(stGatePageSo.getGateNm())){ lambdaQueryWrapper.like(StringUtils.isNotEmpty(stGatePageSo.getGateNm()),StGateB::getGateNm,stGatePageSo.getGateNm()); } if (StringUtils.isNotEmpty(stGatePageSo.getGateCd())){ lambdaQueryWrapper.like(StringUtils.isNotEmpty(stGatePageSo.getGateCd()),StGateB::getGateCd,stGatePageSo.getGateCd()); } if (stGatePageSo.getStatus() != null){ lambdaQueryWrapper.eq(StGateB::getStatus,stGatePageSo.getStatus()); } return stGateBAutoDao.page(stGatePageSo.getPageSo().toPage(),lambdaQueryWrapper); } /** * 新增量水堰基础信息 * @param stEqptDto 量水堰基础信息DTO */ public void insertStEqpt(StEqptDto stEqptDto){ if (queryByWmegCode(stEqptDto.getWmeqCode()) != null){ throw new IllegalArgumentException("量水设施代码不能为空"); } StEqptB stEqptB = new StEqptB(); BeanUtil.copyProperties(stEqptDto,stEqptB); long id = IdWorker.getId(); stEqptB.setWmeqId(id); stEqptB.setStatus(1); stEqptBAutoDao.save(stEqptB); } /** * 更新量水堰基础信息 * @param stEqptB 量水堰基础信息 */ public void updateStEqpt(StEqptB stEqptB){ Long wmeqId = stEqptB.getWmeqId(); StEqptB stEqptB1 = stEqptBAutoDao.getById(wmeqId); if (stEqptB1 == null){ throw new IllegalArgumentException("量水设施ID: " + wmeqId + "不存在"); } stEqptBAutoDao.updateById(stEqptB); } /** * 根据量水设施ID删除量水堰基础信息 * @param wmeqId 量水设施ID */ public void deleteStEqpt(String wmeqId){ QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq(StEqptB.COL_WMEQ_ID,wmeqId) .eq(StEqptB.COL_STATUS,1); StEqptB stEqptB1 = stEqptBAutoDao.getOne(queryWrapper); if (stEqptB1 == null){ throw new IllegalArgumentException("量水设施ID: " + wmeqId + "不存在或量水设施ID: " + wmeqId + "被禁用"); } UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.eq(StEqptB.COL_WMEQ_ID,wmeqId) .set(StEqptB.COL_STATUS,0); stEqptBAutoDao.update(updateWrapper); } /** * 分页查询量水堰基础信息 * @param stEqptPageSo 量水堰基本信息查询参数 * @return */ public Page pageStEqpt(StEqptPageSo stEqptPageSo){ if (StringUtils.isNotEmpty(stEqptPageSo.getWmeqId())){ StEqptB stEqptB = stEqptBAutoDao.getById(stEqptPageSo.getWmeqId()); if (stEqptB == null){ return null; } List eqptBList = List.of(stEqptB); return new Page(1,1,1).setRecords(eqptBList); } LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); if (StringUtils.isNotEmpty(stEqptPageSo.getWmeqName())){ lambdaQueryWrapper.like(StringUtils.isNotEmpty(stEqptPageSo.getWmeqName()),StEqptB::getWmeqName,stEqptPageSo.getWmeqName()); } if (StringUtils.isNotEmpty(stEqptPageSo.getWmeqCode())){ lambdaQueryWrapper.like(StringUtils.isNotEmpty(stEqptPageSo.getWmeqCode()),StEqptB::getWmeqCode,stEqptPageSo.getWmeqCode()); } if (stEqptPageSo.getStatus() != null){ lambdaQueryWrapper.eq(StEqptB::getStatus,stEqptPageSo.getStatus()); } return stEqptBAutoDao.page(stEqptPageSo.getPageSo().toPage(),lambdaQueryWrapper); } /** * 根据量水堰代码查询量水堰基础信息 * @param wmeqCode 量水堰代码 * @return 量水堰基础信息 */ public StEqptB queryByWmegCode(String wmeqCode){ QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq(StEqptB.COL_WMEQ_CODE,wmeqCode) .eq(StEqptB.COL_STATUS,1); StEqptB stEqptB = stEqptBAutoDao.getOne(queryWrapper); return stEqptB; } }