96 lines
2.9 KiB
Java
96 lines
2.9 KiB
Java
package com.gunshi.project.xyt.service;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.gunshi.project.xyt.entity.basedata.CheckStringSearch;
|
|
import com.gunshi.project.xyt.entity.basedata.GeneralSearch;
|
|
import com.gunshi.project.xyt.entity.basedata.StSpgPztbVo;
|
|
import com.gunshi.project.xyt.mapper.StSpgPztbMapper;
|
|
import com.gunshi.project.xyt.model.StSpgPztb;
|
|
import lombok.Data;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.util.Date;
|
|
|
|
/**
|
|
* 渗压设备Service
|
|
* @author Sun Lejun
|
|
* @version 1.0
|
|
* @date 2024/1/26
|
|
*/
|
|
|
|
@Service
|
|
@Slf4j
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Data
|
|
public class StSpgPztbService {
|
|
private final StSpgPztbMapper stSpgPztbMapper;
|
|
|
|
/**
|
|
* 按查询条件查询渗压设备信息表
|
|
* @param search 查询条件
|
|
* @return 渗压设备信息表列表
|
|
*/
|
|
public Page<StSpgPztbVo> queryBySearch(GeneralSearch search) {
|
|
Page<StSpgPztbVo> page = search.getPageSo().toPage();
|
|
return stSpgPztbMapper.queryBySearch(page, search);
|
|
}
|
|
|
|
/**
|
|
* 新增渗压设备信息
|
|
* @param stSpgPztb 渗压设备信息
|
|
*/
|
|
public void insert(StSpgPztb stSpgPztb) {
|
|
|
|
// 校验编码是否存在
|
|
String deviceId = stSpgPztb.getDeviceId();
|
|
CheckStringSearch checkStringSearch = new CheckStringSearch();
|
|
checkStringSearch.setKeyword(deviceId);
|
|
checkCode(checkStringSearch);
|
|
String stationCode = stSpgPztb.getStationCode();
|
|
checkStringSearch.setKeyword(stationCode);
|
|
checkCode(checkStringSearch);
|
|
|
|
// 保存
|
|
stSpgPztb.setId(IdWorker.getId());
|
|
stSpgPztb.setModificationTime(new Date());
|
|
stSpgPztb.setCreationTime(new Date());
|
|
stSpgPztbMapper.insert(stSpgPztb);
|
|
}
|
|
|
|
/**
|
|
* 修改渗压设备信息
|
|
* @param stSpgPztb 渗压设备信息
|
|
*/
|
|
public void update(StSpgPztb stSpgPztb) {
|
|
// 校验编码是否存在
|
|
Long id = stSpgPztb.getId();
|
|
String deviceId = stSpgPztb.getDeviceId();
|
|
CheckStringSearch checkStringSearch = new CheckStringSearch();
|
|
checkStringSearch.setKeyword(deviceId);
|
|
checkStringSearch.setId(id);
|
|
checkCode(checkStringSearch);
|
|
String stationCode = stSpgPztb.getStationCode();
|
|
checkStringSearch.setKeyword(stationCode);
|
|
checkCode(checkStringSearch);
|
|
|
|
// 更新
|
|
stSpgPztb.setModificationTime(new Date());
|
|
stSpgPztbMapper.updateById(stSpgPztb);
|
|
}
|
|
|
|
|
|
/**
|
|
* 检查编码是否存在
|
|
* @param checkStringSearch 检查对象
|
|
*/
|
|
public void checkCode(CheckStringSearch checkStringSearch) {
|
|
boolean b = stSpgPztbMapper.checkCode(checkStringSearch);
|
|
if (b) {
|
|
throw new IllegalArgumentException("编码已存在");
|
|
}
|
|
}
|
|
}
|