package cn.shlanbao.qms.service.impl;
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.stereotype.Service;
|
import cn.shlanbao.qms.domain.bo.LbDeviceBo;
|
import cn.shlanbao.qms.domain.vo.LbDeviceVo;
|
import cn.shlanbao.qms.domain.LbDevice;
|
import cn.shlanbao.qms.mapper.LbDeviceMapper;
|
import cn.shlanbao.qms.service.ILbDeviceService;
|
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Collection;
|
|
/**
|
* 测试仪Service业务层处理
|
*
|
* @author bsw
|
* @date 2024-12-12
|
*/
|
@RequiredArgsConstructor
|
@Service
|
public class LbDeviceServiceImpl implements ILbDeviceService {
|
|
private final LbDeviceMapper baseMapper;
|
|
/**
|
* 查询测试仪
|
*
|
* @param id 主键
|
* @return 测试仪
|
*/
|
@Override
|
public LbDeviceVo queryById(Long id){
|
return baseMapper.selectVoById(id);
|
}
|
|
/**
|
* 分页查询测试仪列表
|
*
|
* @param bo 查询条件
|
* @param pageQuery 分页参数
|
* @return 测试仪分页列表
|
*/
|
@Override
|
public TableDataInfo<LbDeviceVo> queryPageList(LbDeviceBo bo, PageQuery pageQuery) {
|
LambdaQueryWrapper<LbDevice> lqw = buildQueryWrapper(bo);
|
Page<LbDeviceVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
return TableDataInfo.build(result);
|
}
|
|
/**
|
* 查询符合条件的测试仪列表
|
*
|
* @param bo 查询条件
|
* @return 测试仪列表
|
*/
|
@Override
|
public List<LbDeviceVo> queryList(LbDeviceBo bo) {
|
LambdaQueryWrapper<LbDevice> lqw = buildQueryWrapper(bo);
|
return baseMapper.selectVoList(lqw);
|
}
|
|
private LambdaQueryWrapper<LbDevice> buildQueryWrapper(LbDeviceBo bo) {
|
Map<String, Object> params = bo.getParams();
|
LambdaQueryWrapper<LbDevice> lqw = Wrappers.lambdaQuery();
|
lqw.eq(StringUtils.isNotBlank(bo.getDeviceType()), LbDevice::getDeviceType, bo.getDeviceType());
|
lqw.eq(StringUtils.isNotBlank(bo.getDeviceCode()), LbDevice::getDeviceCode, bo.getDeviceCode());
|
lqw.eq(StringUtils.isNotBlank(bo.getDeviceGroup()), LbDevice::getDeviceGroup, bo.getDeviceGroup());
|
lqw.eq(StringUtils.isNotBlank(bo.getDeviceDept()), LbDevice::getDeviceDept, bo.getDeviceDept());
|
lqw.eq(StringUtils.isNotBlank(bo.getDeviceStation()), LbDevice::getDeviceStation, bo.getDeviceStation());
|
return lqw;
|
}
|
|
/**
|
* 新增测试仪
|
*
|
* @param bo 测试仪
|
* @return 是否新增成功
|
*/
|
@Override
|
public Boolean insertByBo(LbDeviceBo bo) {
|
LbDevice add = MapstructUtils.convert(bo, LbDevice.class);
|
validEntityBeforeSave(add);
|
boolean flag = baseMapper.insert(add) > 0;
|
if (flag) {
|
bo.setId(add.getId());
|
}
|
return flag;
|
}
|
|
/**
|
* 修改测试仪
|
*
|
* @param bo 测试仪
|
* @return 是否修改成功
|
*/
|
@Override
|
public Boolean updateByBo(LbDeviceBo bo) {
|
LbDevice update = MapstructUtils.convert(bo, LbDevice.class);
|
validEntityBeforeSave(update);
|
return baseMapper.updateById(update) > 0;
|
}
|
|
/**
|
* 保存前的数据校验
|
*/
|
private void validEntityBeforeSave(LbDevice entity){
|
//TODO 做一些数据校验,如唯一约束
|
}
|
|
/**
|
* 校验并批量删除测试仪信息
|
*
|
* @param ids 待删除的主键集合
|
* @param isValid 是否进行有效性校验
|
* @return 是否删除成功
|
*/
|
@Override
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
if(isValid){
|
//TODO 做一些业务上的校验,判断是否需要校验
|
}
|
return baseMapper.deleteByIds(ids) > 0;
|
}
|
}
|