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.MwMaterialCategoryDTO;
|
import cn.besteam.modules.medical.dto.MwMaterialCategoryQueryDTO;
|
import cn.besteam.modules.medical.entity.MwMaterialCategory;
|
import cn.besteam.modules.medical.service.IMwMaterialCategoryService;
|
import cn.besteam.modules.system.entity.SysDepartment;
|
import cn.besteam.common.util.UserContextUtil;
|
import cn.besteam.modules.system.service.ISysDepartmentService;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
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 java.util.Arrays;
|
import java.util.List;
|
|
/**
|
* @Description: 资料分类管理控制器
|
* @author: besteam
|
* @date: 2025-08-17
|
*/
|
@RestController
|
@RequestMapping("/medical/mwMaterialCategory")
|
@Slf4j
|
@Api(tags = "【0729迭代】资料分类管理")
|
public class MwMaterialCategoryController {
|
|
@Autowired
|
private IMwMaterialCategoryService mwMaterialCategoryService;
|
|
@Autowired
|
private ISysDepartmentService sysDepartmentService;
|
|
@Autowired
|
private UserContextUtil userContextUtil;
|
|
/**
|
* 分页列表查询
|
* @param queryDTO 查询条件
|
* @param req 请求对象
|
* @return 分页结果
|
*/
|
@GetMapping(value = "/list")
|
@ApiOperation(value = "获取资料分类列表", notes = "获取所有资料分类列表", produces = "application/json")
|
public Result<IPage<MwMaterialCategory>> queryPageList(MwMaterialCategoryQueryDTO queryDTO) {
|
|
Page<MwMaterialCategory> page = new Page<>(queryDTO.getPageNo(), queryDTO.getPageSize());
|
IPage<MwMaterialCategory> pageList = mwMaterialCategoryService.selectPageList(page, queryDTO);
|
|
return Result.ok(pageList);
|
}
|
|
/**
|
* 添加资料分类
|
* @param materialCategoryDTO 资料分类信息
|
* @return 操作结果
|
*/
|
@PostMapping(value = "/add")
|
@AutoLog(value = "添加资料分类")
|
@ApiOperation(value = "添加资料分类", notes = "添加资料分类", produces = "application/json")
|
public Result<String> add(@RequestBody MwMaterialCategoryDTO materialCategoryDTO, HttpServletRequest request) {
|
// 验证分类名称是否重复
|
if (checkCategoryNameExists(materialCategoryDTO.getCategoryName(), materialCategoryDTO.getHospitalId(), null)) {
|
return Result.error("分类名称已存在!");
|
}
|
|
MwMaterialCategory materialCategory = new MwMaterialCategory();
|
BeanUtils.copyProperties(materialCategoryDTO, materialCategory);
|
|
boolean success = mwMaterialCategoryService.saveMaterialCategory(materialCategory);
|
if (success) {
|
return Result.ok("添加成功!");
|
} else {
|
return Result.error("添加失败!");
|
}
|
}
|
|
/**
|
* 编辑资料分类
|
* @param materialCategoryDTO 资料分类信息
|
* @return 操作结果
|
*/
|
@PostMapping(value = "/edit")
|
@AutoLog(value = "编辑资料分类")
|
@ApiOperation(value = "编辑资料分类", notes = "编辑资料分类", produces = "application/json")
|
public Result<String> edit(@RequestBody MwMaterialCategoryDTO materialCategoryDTO, HttpServletRequest request) {
|
if (materialCategoryDTO.getId() == null) {
|
return Result.error("ID不能为空!");
|
}
|
|
// 验证分类名称是否重复
|
if (checkCategoryNameExists(materialCategoryDTO.getCategoryName(), materialCategoryDTO.getHospitalId(), materialCategoryDTO.getId())) {
|
return Result.error("分类名称已存在!");
|
}
|
|
MwMaterialCategory materialCategory = new MwMaterialCategory();
|
BeanUtils.copyProperties(materialCategoryDTO, materialCategory);
|
|
boolean success = mwMaterialCategoryService.updateMaterialCategory(materialCategory);
|
if (success) {
|
return Result.ok("修改成功!");
|
} else {
|
return Result.error("修改失败!");
|
}
|
}
|
|
/**
|
* 通过id删除
|
* @param id 资料分类ID
|
* @return 操作结果
|
*/
|
@DeleteMapping(value = "/delete")
|
@AutoLog(value = "删除资料分类")
|
@ApiOperation(value = "删除资料分类", notes = "删除资料分类", produces = "application/json")
|
public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
|
// 验证资料分类是否存在
|
MwMaterialCategory category = mwMaterialCategoryService.getById(Integer.parseInt(id));
|
if (category == null) {
|
return Result.error("资料分类不存在");
|
}
|
|
boolean success = mwMaterialCategoryService.deleteMaterialCategory(Integer.parseInt(id));
|
if (success) {
|
return Result.ok("删除成功!");
|
} else {
|
return Result.error("删除失败!");
|
}
|
}
|
|
/**
|
* 批量删除
|
* @param ids 资料分类ID数组
|
* @return 操作结果
|
*/
|
@DeleteMapping(value = "/deleteBatch")
|
@AutoLog(value = "批量删除资料分类")
|
@ApiOperation(value = "批量删除资料分类", notes = "批量删除资料分类", produces = "application/json")
|
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) {
|
mwMaterialCategoryService.deleteMaterialCategory(Integer.parseInt(id));
|
}
|
|
return Result.ok("批量删除成功!");
|
}
|
|
/**
|
* 通过id查询
|
* @param id 资料分类ID
|
* @return 资料分类详情
|
*/
|
@GetMapping(value = "/queryById")
|
@ApiOperation(value = "通过ID查询资料分类", notes = "通过ID查询资料分类", produces = "application/json")
|
public Result<MwMaterialCategory> queryById(@RequestParam(name = "id", required = true) String id) {
|
MwMaterialCategory category = mwMaterialCategoryService.selectById(Integer.parseInt(id));
|
if (category != null) {
|
return Result.ok(category);
|
} 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) {
|
|
MwMaterialCategory category = mwMaterialCategoryService.getById(id);
|
if (category == null) {
|
return Result.error("未找到对应实体");
|
}
|
|
category.setStatus(status);
|
boolean success = mwMaterialCategoryService.updateById(category);
|
if (success) {
|
return Result.ok("状态更新成功!");
|
} else {
|
return Result.error("状态更新失败!");
|
}
|
}
|
|
/**
|
* 获取医院列表
|
* @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 categoryName 分类名称
|
* @param hospitalId 医院ID
|
* @param id 资料分类ID(编辑时传入)
|
* @return 是否重复
|
*/
|
@GetMapping(value = "/checkCategoryName")
|
@ApiOperation(value = "检查分类名称是否重复", notes = "检查分类名称是否重复", produces = "application/json")
|
public Result<Boolean> checkCategoryName(
|
@RequestParam(name = "categoryName", required = true) String categoryName,
|
@RequestParam(name = "hospitalId", required = true) Integer hospitalId,
|
@RequestParam(name = "id", required = false) Integer id) {
|
|
boolean exists = checkCategoryNameExists(categoryName, hospitalId, id);
|
return Result.ok(!exists);
|
}
|
|
/**
|
* 检查分类名称是否存在
|
* @param categoryName 分类名称
|
* @param hospitalId 医院ID
|
* @param id 资料分类ID(编辑时传入)
|
* @return 是否存在
|
*/
|
private boolean checkCategoryNameExists(String categoryName, Integer hospitalId, Integer id) {
|
QueryWrapper<MwMaterialCategory> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("category_name", categoryName);
|
queryWrapper.eq("hospital_id", hospitalId);
|
queryWrapper.eq("del_flag", 0);
|
|
if (id != null) {
|
queryWrapper.ne("id", id);
|
}
|
|
int count = mwMaterialCategoryService.count(queryWrapper);
|
return count > 0;
|
}
|
}
|