package cn.besteam.modules.medical.service.impl;
|
|
import cn.besteam.common.constant.CommonConstant;
|
import cn.besteam.modules.medical.dto.MwDeviceQueryDTO;
|
import cn.besteam.modules.medical.entity.MwDevice;
|
import cn.besteam.modules.medical.mapper.MwDeviceMapper;
|
import cn.besteam.modules.medical.service.IMwDeviceService;
|
import cn.besteam.modules.system.entity.SysDepartment;
|
import cn.besteam.modules.system.service.ISysDepartmentService;
|
import cn.besteam.modules.system.service.ISysDictItemService;
|
import cn.besteam.modules.system.util.MybatisParameterUtils;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
|
/**
|
* @Description: 设备管理服务实现
|
* @author: besteam
|
* @date: 2025-08-17
|
*/
|
@Service
|
public class MwDeviceServiceImpl extends ServiceImpl<MwDeviceMapper, MwDevice> implements IMwDeviceService {
|
|
@Autowired
|
private ISysDepartmentService sysDepartmentService;
|
|
@Autowired
|
private ISysDictItemService sysDictItemService;
|
|
@Override
|
public IPage<MwDevice> selectPageList(Page<MwDevice> page, MwDeviceQueryDTO queryDTO) {
|
List<Integer> hospitalIdList = sysDepartmentService.getSearchHospitalIdList(queryDTO.getHospitalId());
|
if (CollectionUtils.isEmpty(hospitalIdList)) {
|
return page;
|
}
|
LambdaQueryWrapper<MwDevice> queryWrapper = new LambdaQueryWrapper<>();
|
try {
|
MybatisParameterUtils.cutInParameter(queryWrapper,MwDevice::getHospitalId, hospitalIdList);
|
} catch (Exception e) {
|
throw new RuntimeException(e);
|
}
|
queryWrapper.eq(MwDevice::getDelFlag, CommonConstant.DEL_FLAG_0);
|
|
if (queryDTO.getDeviceName() != null && !queryDTO.getDeviceName().isEmpty()) {
|
queryWrapper.like(MwDevice::getDeviceName, queryDTO.getDeviceName());
|
}
|
if (queryDTO.getDeviceCode() != null && !queryDTO.getDeviceCode().isEmpty()) {
|
queryWrapper.like(MwDevice::getDeviceCode, queryDTO.getDeviceCode());
|
}
|
if (queryDTO.getDeviceType() != null) {
|
queryWrapper.eq(MwDevice::getDeviceType, queryDTO.getDeviceType());
|
}
|
if (queryDTO.getDeviceStatus() != null) {
|
queryWrapper.eq(MwDevice::getDeviceStatus, queryDTO.getDeviceStatus());
|
}
|
|
queryWrapper.orderByDesc(MwDevice::getCreateTime);
|
|
IPage<MwDevice> pageList = this.page(page, queryWrapper);
|
|
// 填充医院名称和设备类型名称
|
for (MwDevice device : pageList.getRecords()) {
|
fillDeviceNames(device);
|
}
|
|
return pageList;
|
}
|
|
@Override
|
public MwDevice selectById(Integer id) {
|
MwDevice device = this.getById(id);
|
if (device != null && device.getDelFlag() == CommonConstant.DEL_FLAG_0) {
|
fillDeviceNames(device);
|
return device;
|
}
|
return null;
|
}
|
|
@Override
|
public boolean saveDevice(MwDevice mwDevice) {
|
// 设置医院名称
|
if (mwDevice.getHospitalId() != null) {
|
SysDepartment hospital = sysDepartmentService.getById(mwDevice.getHospitalId());
|
if (hospital != null) {
|
mwDevice.setHospitalName(hospital.getDepartName());
|
}
|
}
|
|
// 设置默认状态为启用
|
if (mwDevice.getDeviceStatus() == null) {
|
mwDevice.setDeviceStatus(1);
|
}
|
|
return this.save(mwDevice);
|
}
|
|
@Override
|
public boolean updateDevice(MwDevice mwDevice) {
|
MwDevice existingDevice = this.getById(mwDevice.getId());
|
if (existingDevice == null) {
|
return false;
|
}
|
|
// 如果医院ID发生变化,更新医院名称
|
if (mwDevice.getHospitalId() != null && !mwDevice.getHospitalId().equals(existingDevice.getHospitalId())) {
|
SysDepartment hospital = sysDepartmentService.getById(mwDevice.getHospitalId());
|
if (hospital != null) {
|
mwDevice.setHospitalName(hospital.getDepartName());
|
}
|
}
|
|
return this.updateById(mwDevice);
|
}
|
|
@Override
|
public boolean deleteDevice(Integer id) {
|
return this.removeById(id);
|
}
|
|
/**
|
* 填充设备名称信息
|
* @param device 设备信息
|
*/
|
private void fillDeviceNames(MwDevice device) {
|
// 填充医院名称
|
if (device.getHospitalId() != null && device.getHospitalName() == null) {
|
SysDepartment hospital = sysDepartmentService.getById(device.getHospitalId());
|
if (hospital != null) {
|
device.setHospitalName(hospital.getDepartName());
|
}
|
}
|
|
// 填充设备类型名称
|
if (device.getDeviceType() != null) {
|
try {
|
String dictItemName = sysDictItemService.queryDictItemNameById(device.getDeviceType());
|
device.setDeviceTypeName(dictItemName);
|
} catch (Exception e) {
|
// 如果查询失败,忽略异常
|
device.setDeviceTypeName("");
|
}
|
}
|
}
|
}
|