package cn.besteam.modules.medical.controller;
|
|
import cn.besteam.common.api.vo.Result;
|
import cn.besteam.common.aspect.annotation.AutoLog;
|
import cn.besteam.common.util.oConvertUtils;
|
import cn.besteam.modules.medical.dto.MwDeviceDTO;
|
import cn.besteam.modules.medical.dto.MwDeviceQueryDTO;
|
import cn.besteam.modules.medical.entity.MwDevice;
|
import cn.besteam.modules.medical.service.IMwDeviceService;
|
import cn.besteam.modules.shiro.authc.util.EnvUtils;
|
import cn.besteam.modules.system.entity.SysDepartment;
|
import cn.besteam.modules.system.service.ISysDepartmentService;
|
import cn.besteam.common.util.UserContextUtil;
|
import cn.besteam.modules.system.service.ISysDictItemService;
|
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 io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiParam;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.validation.Valid;
|
import java.util.Arrays;
|
import java.util.List;
|
|
/**
|
* @Description: 设备管理控制器
|
* @author: besteam
|
* @date: 2025-08-17
|
*/
|
@RestController
|
@RequestMapping("/medical/mwDevice")
|
@Slf4j
|
@Api(tags = "【0729迭代】设备管理")
|
public class MwDeviceController {
|
|
@Autowired
|
private IMwDeviceService mwDeviceService;
|
|
@Autowired
|
private ISysDepartmentService sysDepartmentService;
|
|
@Autowired
|
private ISysDictItemService sysDictItemService;
|
|
@Autowired
|
private UserContextUtil userContextUtil;
|
|
/**
|
* 分页列表查询
|
* @param queryDTO 查询条件
|
* @return 分页结果
|
*/
|
@GetMapping(value = "/list")
|
@ApiOperation(value = "获取设备数据列表", notes = "获取所有设备数据列表")
|
public Result<IPage<MwDevice>> queryPageList(@Valid MwDeviceQueryDTO queryDTO) {
|
Page<MwDevice> page = new Page<>(queryDTO.getPageNo(), queryDTO.getPageSize());
|
IPage<MwDevice> pageList = mwDeviceService.selectPageList(page, queryDTO);
|
|
return Result.ok(pageList);
|
}
|
|
/**
|
* 添加设备
|
* @param mwDeviceDTO 设备信息
|
* @return 操作结果
|
*/
|
@PostMapping(value = "/add")
|
@AutoLog(value = "添加设备")
|
@ApiOperation(value = "添加设备", notes = "添加设备", produces = "application/json")
|
public Result<String> add(@RequestBody MwDeviceDTO mwDeviceDTO, HttpServletRequest request) {
|
MwDevice mwDevice = new MwDevice();
|
BeanUtils.copyProperties(mwDeviceDTO, mwDevice);
|
|
boolean success = mwDeviceService.saveDevice(mwDevice);
|
if (success) {
|
return Result.ok("添加成功!");
|
} else {
|
return Result.error("添加失败!");
|
}
|
}
|
|
/**
|
* 编辑设备
|
* @param mwDeviceDTO 设备信息
|
* @return 操作结果
|
*/
|
@PostMapping(value = "/edit")
|
@AutoLog(value = "编辑设备")
|
@ApiOperation(value = "编辑设备", notes = "编辑设备", produces = "application/json")
|
public Result<String> edit(@RequestBody MwDeviceDTO mwDeviceDTO, HttpServletRequest request) {
|
if (mwDeviceDTO.getId() == null) {
|
return Result.error("ID不能为空!");
|
}
|
|
MwDevice mwDevice = new MwDevice();
|
BeanUtils.copyProperties(mwDeviceDTO, mwDevice);
|
String name = EnvUtils.getUser().getName();
|
mwDevice.setUpdateBy(name);
|
boolean success = mwDeviceService.updateDevice(mwDevice);
|
if (success) {
|
return Result.ok("修改成功!");
|
} else {
|
return Result.error("修改失败!");
|
}
|
}
|
|
/**
|
* 通过id删除
|
* @param id 设备ID
|
* @return 操作结果
|
*/
|
@DeleteMapping(value = "/delete")
|
@AutoLog(value = "删除设备")
|
@ApiOperation(value = "删除设备", notes = "删除设备")
|
public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
|
// 验证设备是否存在
|
MwDevice device = mwDeviceService.getById(Integer.parseInt(id));
|
if (device == null) {
|
return Result.error("设备不存在");
|
}
|
|
boolean success = mwDeviceService.deleteDevice(Integer.parseInt(id));
|
if (success) {
|
return Result.ok("删除成功!");
|
} else {
|
return Result.error("删除失败!");
|
}
|
}
|
|
/**
|
* 批量删除
|
* @param ids 设备ID数组
|
* @return 操作结果
|
*/
|
@DeleteMapping(value = "/deleteBatch")
|
@AutoLog(value = "批量删除设备")
|
@ApiOperation(value = "批量删除设备", notes = "批量删除设备")
|
public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
if (oConvertUtils.isEmpty(ids)) {
|
return Result.error("参数不识别!");
|
}
|
|
String[] idArray = ids.split(",");
|
|
for (String id : idArray) {
|
mwDeviceService.deleteDevice(Integer.parseInt(id));
|
}
|
|
return Result.ok("批量删除成功!");
|
}
|
|
/**
|
* 通过id查询
|
* @param id 设备ID
|
* @return 设备详情
|
*/
|
@GetMapping(value = "/queryById")
|
@ApiOperation(value = "通过ID查询设备", notes = "通过ID查询设备")
|
public Result<MwDevice> queryById(@RequestParam(name = "id", required = true) String id) {
|
MwDevice device = mwDeviceService.selectById(Integer.parseInt(id));
|
if (device != null) {
|
return Result.ok(device);
|
} else {
|
return Result.error("未找到对应实体");
|
}
|
}
|
|
/**
|
* 更新设备状态
|
* @param id 设备ID
|
* @param status 设备状态
|
* @return 操作结果
|
*/
|
@PostMapping(value = "/updateStatus")
|
@AutoLog(value = "更新设备状态")
|
@ApiOperation(value = "更新设备状态", notes = "更新设备状态", produces = "application/json")
|
public Result<String> updateStatus(
|
@RequestParam(name = "id", required = true) Integer id,
|
@RequestParam(name = "status", required = true) Integer status) {
|
|
MwDevice device = mwDeviceService.getById(id);
|
if (device == null) {
|
return Result.error("未找到对应实体");
|
}
|
|
device.setDeviceStatus(status);
|
boolean success = mwDeviceService.updateById(device);
|
if (success) {
|
return Result.ok("状态更新成功!");
|
} else {
|
return Result.error("状态更新失败!");
|
}
|
}
|
|
/**
|
* 获取设备类型列表
|
* @return 设备类型列表
|
*/
|
@GetMapping(value = "/getDeviceTypes")
|
@ApiOperation(value = "获取设备类型列表", notes = "获取设备类型列表", produces = "application/json")
|
public Result<List<?>> getDeviceTypes() {
|
// 获取设备类型字典数据
|
List<?> deviceTypes = sysDictItemService.queryDictItemsByDictCode("DEVICETYPE");
|
return Result.ok(deviceTypes);
|
}
|
|
/**
|
* 获取医院列表
|
* @return 医院列表
|
*/
|
@GetMapping(value = "/getHospitals")
|
@ApiOperation(value = "获取医院列表", notes = "获取医院列表", produces = "application/json")
|
public Result<List<SysDepartment>> getHospitals() {
|
QueryWrapper<SysDepartment> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("org_type", 2); // 2表示单位(医院)
|
queryWrapper.eq("del_flag", 0);
|
queryWrapper.orderByAsc("depart_order");
|
|
List<SysDepartment> hospitals = sysDepartmentService.list(queryWrapper);
|
return Result.ok(hospitals);
|
}
|
|
/**
|
* 检查设备编号是否重复
|
* @param deviceCode 设备编号
|
* @param id 设备ID(编辑时传入)
|
* @return 是否重复
|
*/
|
@GetMapping(value = "/checkDeviceCode")
|
@ApiOperation(value = "检查设备编号是否重复", notes = "检查设备编号是否重复", produces = "application/json")
|
public Result<Boolean> checkDeviceCode(
|
@RequestParam(name = "deviceCode", required = true) String deviceCode,
|
@RequestParam(name = "id", required = false) Integer id) {
|
|
QueryWrapper<MwDevice> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("device_code", deviceCode);
|
queryWrapper.eq("del_flag", 0);
|
|
if (id != null) {
|
queryWrapper.ne("id", id);
|
}
|
|
int count = mwDeviceService.count(queryWrapper);
|
return Result.ok(count == 0);
|
}
|
}
|