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

96 lines
2.9 KiB
Java
Raw Normal View History

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("编码已存在");
}
}
}