门诊号码管理维护界面前后端
This commit is contained in:
@@ -0,0 +1,219 @@
|
||||
package com.openhis.web.basicmanage.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.core.common.annotation.Log;
|
||||
import com.core.common.core.domain.R;
|
||||
import com.core.common.enums.BusinessType;
|
||||
import com.core.common.utils.SecurityUtils;
|
||||
import com.core.common.utils.StringUtils;
|
||||
import com.openhis.administration.domain.OutpatientNoSegment;
|
||||
import com.openhis.administration.service.IOutpatientNoSegmentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 门诊号码段管理控制器
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-01-XX
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/business-rule/outpatient-no")
|
||||
public class OutpatientNoSegmentController {
|
||||
|
||||
@Autowired
|
||||
private IOutpatientNoSegmentService outpatientNoSegmentService;
|
||||
|
||||
/**
|
||||
* 分页查询门诊号码段列表
|
||||
*
|
||||
* @param pageNo 页码
|
||||
* @param pageSize 每页条数
|
||||
* @param onlySelf 是否只查询自己的(true=只查询自己的,false=查询所有)
|
||||
* @return 门诊号码段列表
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public R<?> selectOutpatientNoSegmentPage(
|
||||
@RequestParam(defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(required = false) Boolean onlySelf) {
|
||||
|
||||
// 获取当前用户ID
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
|
||||
// 如果onlySelf为null,默认只查询自己的
|
||||
boolean onlySelfFlag = onlySelf != null ? onlySelf : true;
|
||||
|
||||
// 分页查询门诊号码段列表
|
||||
Page<OutpatientNoSegment> page = new Page<>(pageNo, pageSize);
|
||||
Page<OutpatientNoSegment> result = outpatientNoSegmentService.selectOutpatientNoSegmentPage(page, onlySelfFlag, userId);
|
||||
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增门诊号码段
|
||||
*
|
||||
* @param outpatientNoSegment 门诊号码段信息
|
||||
* @return 操作结果
|
||||
*/
|
||||
@Log(title = "门诊号码管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public R<?> addOutpatientNoSegment(@RequestBody OutpatientNoSegment outpatientNoSegment) {
|
||||
// 校验必填字段
|
||||
if (StringUtils.isEmpty(outpatientNoSegment.getStartNo()) ||
|
||||
StringUtils.isEmpty(outpatientNoSegment.getEndNo()) ||
|
||||
StringUtils.isEmpty(outpatientNoSegment.getUsedNo())) {
|
||||
return R.fail("起始号码、终止号码和使用号码不能为空");
|
||||
}
|
||||
|
||||
// 校验号码段是否重复
|
||||
if (outpatientNoSegmentService.checkNumberSegmentOverlap(
|
||||
outpatientNoSegment.getStartNo(),
|
||||
outpatientNoSegment.getEndNo(),
|
||||
null)) {
|
||||
return R.fail("门诊号码设置重复");
|
||||
}
|
||||
|
||||
// 设置创建人信息
|
||||
outpatientNoSegment.setOperatorId(SecurityUtils.getUserId());
|
||||
if (StringUtils.isEmpty(outpatientNoSegment.getOperatorName())) {
|
||||
outpatientNoSegment.setOperatorName(SecurityUtils.getUsername());
|
||||
}
|
||||
outpatientNoSegment.setCreateBy(SecurityUtils.getUsername());
|
||||
|
||||
int result = outpatientNoSegmentService.insertOutpatientNoSegment(outpatientNoSegment);
|
||||
return result > 0 ? R.ok("保存成功") : R.fail("保存失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改门诊号码段
|
||||
*
|
||||
* @param outpatientNoSegment 门诊号码段信息
|
||||
* @return 操作结果
|
||||
*/
|
||||
@Log(title = "门诊号码管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public R<?> updateOutpatientNoSegment(@RequestBody OutpatientNoSegment outpatientNoSegment) {
|
||||
// 校验必填字段
|
||||
if (StringUtils.isEmpty(outpatientNoSegment.getStartNo()) ||
|
||||
StringUtils.isEmpty(outpatientNoSegment.getEndNo()) ||
|
||||
StringUtils.isEmpty(outpatientNoSegment.getUsedNo())) {
|
||||
return R.fail("起始号码、终止号码和使用号码不能为空");
|
||||
}
|
||||
|
||||
// 校验号码段是否重复(排除自身)
|
||||
if (outpatientNoSegmentService.checkNumberSegmentOverlap(
|
||||
outpatientNoSegment.getStartNo(),
|
||||
outpatientNoSegment.getEndNo(),
|
||||
outpatientNoSegment.getId())) {
|
||||
return R.fail("门诊号码设置重复");
|
||||
}
|
||||
|
||||
// 设置更新人信息
|
||||
outpatientNoSegment.setUpdateBy(SecurityUtils.getUsername());
|
||||
|
||||
int result = outpatientNoSegmentService.updateOutpatientNoSegment(outpatientNoSegment);
|
||||
return result > 0 ? R.ok("保存成功") : R.fail("保存失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除门诊号码段
|
||||
*
|
||||
* @param request 包含ids数组的请求对象
|
||||
* @return 操作结果
|
||||
*/
|
||||
@Log(title = "门诊号码管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping
|
||||
public R<?> deleteOutpatientNoSegment(@RequestBody java.util.Map<String, Object> request) {
|
||||
// 支持接收 Long[] 或 String[] 或混合类型,处理大整数ID
|
||||
Object idsObj = request.get("ids");
|
||||
System.out.println("删除请求 - 接收到的ids原始数据: " + idsObj);
|
||||
System.out.println("删除请求 - 接收到的ids类型: " + (idsObj != null ? idsObj.getClass().getName() : "null"));
|
||||
|
||||
if (idsObj == null) {
|
||||
return R.fail("请选择要删除的数据");
|
||||
}
|
||||
|
||||
// 转换为 Long[] 数组
|
||||
Long[] ids = null;
|
||||
if (idsObj instanceof java.util.List) {
|
||||
java.util.List<?> idList = (java.util.List<?>) idsObj;
|
||||
ids = new Long[idList.size()];
|
||||
for (int i = 0; i < idList.size(); i++) {
|
||||
Object idObj = idList.get(i);
|
||||
if (idObj instanceof Long) {
|
||||
ids[i] = (Long) idObj;
|
||||
} else if (idObj instanceof Integer) {
|
||||
ids[i] = ((Integer) idObj).longValue();
|
||||
} else if (idObj instanceof String) {
|
||||
try {
|
||||
String idStr = (String) idObj;
|
||||
System.out.println("删除请求 - 转换字符串ID: " + idStr);
|
||||
ids[i] = Long.parseLong(idStr);
|
||||
System.out.println("删除请求 - 转换后的Long ID: " + ids[i]);
|
||||
// 验证转换是否正确
|
||||
if (!String.valueOf(ids[i]).equals(idStr)) {
|
||||
System.out.println("删除请求 - 警告:ID转换后值不匹配!原始: " + idStr + ", 转换后: " + ids[i]);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.println("删除请求 - ID转换失败: " + idObj + ", 错误: " + e.getMessage());
|
||||
return R.fail("无效的ID格式: " + idObj);
|
||||
}
|
||||
} else if (idObj instanceof Number) {
|
||||
ids[i] = ((Number) idObj).longValue();
|
||||
} else {
|
||||
return R.fail("无效的ID类型: " + (idObj != null ? idObj.getClass().getName() : "null"));
|
||||
}
|
||||
}
|
||||
} else if (idsObj instanceof Long[]) {
|
||||
ids = (Long[]) idsObj;
|
||||
} else {
|
||||
return R.fail("无效的ID数组格式");
|
||||
}
|
||||
|
||||
System.out.println("删除请求 - 转换后的ids: " + java.util.Arrays.toString(ids));
|
||||
|
||||
if (ids == null || ids.length == 0) {
|
||||
return R.fail("请选择要删除的数据");
|
||||
}
|
||||
|
||||
// 获取当前用户ID
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
System.out.println("删除请求 - 当前用户ID: " + userId);
|
||||
|
||||
// 校验删除权限和使用状态
|
||||
for (Long id : ids) {
|
||||
System.out.println("删除验证 - 检查ID: " + id);
|
||||
OutpatientNoSegment segment = outpatientNoSegmentService.getById(id);
|
||||
|
||||
if (segment == null) {
|
||||
// 记录日志以便调试
|
||||
System.out.println("删除失败:记录不存在,ID=" + id + ",可能已被软删除或不存在");
|
||||
return R.fail("数据不存在,ID: " + id);
|
||||
}
|
||||
|
||||
System.out.println("删除验证 - 找到记录: ID=" + segment.getId() + ", operatorId=" + segment.getOperatorId() + ", usedNo=" + segment.getUsedNo() + ", startNo=" + segment.getStartNo());
|
||||
|
||||
// 校验归属权
|
||||
if (!segment.getOperatorId().equals(userId)) {
|
||||
System.out.println("删除验证 - 权限检查失败: segment.operatorId=" + segment.getOperatorId() + ", userId=" + userId);
|
||||
return R.fail("只能删除自己维护的门诊号码段");
|
||||
}
|
||||
|
||||
// 校验使用状态(使用号码=起始号码表示未使用)
|
||||
if (!segment.getUsedNo().equals(segment.getStartNo())) {
|
||||
System.out.println("删除验证 - 使用状态检查失败: usedNo=" + segment.getUsedNo() + ", startNo=" + segment.getStartNo());
|
||||
return R.fail("已有门诊号码段已有使用的门诊号码,请核对!");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("删除验证 - 所有检查通过,开始执行删除");
|
||||
int rows = outpatientNoSegmentService.deleteOutpatientNoSegmentByIds(ids);
|
||||
System.out.println("删除执行 - 影响行数: " + rows);
|
||||
return rows > 0 ? R.ok("删除成功") : R.fail("删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user