gunshi-project-ss/src/main/java/com/gunshi/project/xyt/service/EngineeringDrainageService....

513 lines
19 KiB
Java
Raw Normal View History

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<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);
}
/**
*
* @param stResPageSo
* @return
*/
public Page<StResB> pageStRes(StResPageSo stResPageSo){
if (StringUtils.isNotEmpty(stResPageSo.getResId())){
StResB stResB = stResBAutoDao.getById(stResPageSo.getResId());
if (stResB == null){
return null;
}
List<StResB> resBList = List.of(stResB);
return new Page<StResB>(1,1,1).setRecords(resBList);
}
LambdaQueryWrapper<StResB> 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<StResB> 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<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 stRvPageSo
*/
public Page<StRvB> pageStRv(StRvPageSo stRvPageSo){
if (StringUtils.isNotEmpty(stRvPageSo.getRvId())){
StRvB stRvB = stRvBAutoDao.getById(stRvPageSo.getRvId());
if (stRvB == null){
return null;
}
List<StRvB> rvBList = List.of(stRvB);
return new Page<StRvB>(1,1,1).setRecords(rvBList);
}
LambdaQueryWrapper<StRvB> 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<StRvB> 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<StDamB> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq(StDamB.COL_DAM_ID,damId)
.set(StDamB.COL_STATUS,0);
stDamBAutoDao.update(updateWrapper);
}
/**
*
* @param stDamPageSo
* @return
*/
public Page<StDamB> pageStDam(StDamPageSo stDamPageSo){
if (StringUtils.isNotEmpty(stDamPageSo.getDamId())){
StDamB stDamB = stDamBAutoDao.getById(stDamPageSo.getDamId());
if (stDamB == null){
return null;
}
List<StDamB> damBList = List.of(stDamB);
return new Page<StDamB>(1,1,1).setRecords(damBList);
}
LambdaQueryWrapper<StDamB> 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<StDamB> 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<StGateB> 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<StGateB> 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<StGateB> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(StGateB.COL_GATE_CD,gateCd)
.eq(StGateB.COL_STATUS,1);
return stGateBAutoDao.getOne(queryWrapper);
}
/**
*
* @param stGatePageSo
* @return
*/
public Page<StGateB> pageStGate(StGatePageSo stGatePageSo){
if (StringUtils.isNotEmpty(stGatePageSo.getGateId())){
StGateB stGateB = stGateBAutoDao.getById(stGatePageSo.getGateId());
if (stGateB == null){
return null;
}
List<StGateB> gateBList = List.of(stGateB);
return new Page<StGateB>(1,1,1).setRecords(gateBList);
}
LambdaQueryWrapper<StGateB> 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<StEqptB> 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<StEqptB> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq(StEqptB.COL_WMEQ_ID,wmeqId)
.set(StEqptB.COL_STATUS,0);
stEqptBAutoDao.update(updateWrapper);
}
/**
*
* @param stEqptPageSo
* @return
*/
public Page<StEqptB> pageStEqpt(StEqptPageSo stEqptPageSo){
if (StringUtils.isNotEmpty(stEqptPageSo.getWmeqId())){
StEqptB stEqptB = stEqptBAutoDao.getById(stEqptPageSo.getWmeqId());
if (stEqptB == null){
return null;
}
List<StEqptB> eqptBList = List.of(stEqptB);
return new Page<StEqptB>(1,1,1).setRecords(eqptBList);
}
LambdaQueryWrapper<StEqptB> 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<StEqptB> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(StEqptB.COL_WMEQ_CODE,wmeqCode)
.eq(StEqptB.COL_STATUS,1);
StEqptB stEqptB = stEqptBAutoDao.getOne(queryWrapper);
return stEqptB;
}
}