Fix Bug #550: AI修复
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
package com.openhis.web.lab.appservice;
|
||||
|
||||
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentSelParam;
|
||||
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentUpDto;
|
||||
import com.core.common.core.domain.R;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 检验项目 AppService 接口(独立操作 lab_activity_definition 表)
|
||||
*/
|
||||
public interface ILabActivityDefinitionAppService {
|
||||
|
||||
/**
|
||||
* 分页查询检验项目列表
|
||||
*/
|
||||
R<?> getLabActivityDefinitionPage(DiagnosisTreatmentSelParam selParam, String searchKey,
|
||||
Integer pageNo, Integer pageSize, HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* 根据id查询检验项目详情
|
||||
*/
|
||||
R<?> getLabActivityDefinitionOne(Long id);
|
||||
|
||||
/**
|
||||
* 新增检验项目
|
||||
*/
|
||||
R<?> addLabActivityDefinition(DiagnosisTreatmentUpDto dto);
|
||||
|
||||
/**
|
||||
* 编辑检验项目
|
||||
*/
|
||||
R<?> editLabActivityDefinition(DiagnosisTreatmentUpDto dto);
|
||||
|
||||
/**
|
||||
* 停用检验项目
|
||||
*/
|
||||
R<?> stopLabActivityDefinition(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 启用检验项目
|
||||
*/
|
||||
R<?> startLabActivityDefinition(List<Long> ids);
|
||||
}
|
||||
@@ -1,219 +0,0 @@
|
||||
package com.openhis.web.lab.appservice.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.core.common.core.domain.R;
|
||||
import com.core.common.core.domain.model.LoginUser;
|
||||
import com.core.common.utils.*;
|
||||
import com.core.common.utils.bean.BeanUtils;
|
||||
import com.openhis.common.constant.PromptMsgConstant;
|
||||
import com.openhis.common.enums.ActivityType;
|
||||
import com.openhis.common.enums.PublicationStatus;
|
||||
import com.openhis.common.enums.Whether;
|
||||
import com.core.common.utils.ChineseConvertUtils;
|
||||
import com.openhis.common.utils.EnumUtils;
|
||||
import com.openhis.common.utils.HisQueryUtils;
|
||||
import com.openhis.common.enums.AssignSeqEnum;
|
||||
import com.openhis.lab.domain.LabActivityDefinition;
|
||||
import com.openhis.lab.service.ILabActivityDefinitionService;
|
||||
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentDto;
|
||||
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentSelParam;
|
||||
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentUpDto;
|
||||
import com.openhis.web.lab.appservice.ILabActivityDefinitionAppService;
|
||||
import com.openhis.web.datadictionary.mapper.LabActivityDefinitionManageMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* 检验项目 AppService 实现(独立操作 lab_activity_definition 表)
|
||||
*/
|
||||
@Service
|
||||
public class LabActivityDefinitionAppServiceImpl implements ILabActivityDefinitionAppService {
|
||||
|
||||
@Resource
|
||||
private ILabActivityDefinitionService labActivityDefinitionService;
|
||||
|
||||
@Resource
|
||||
private LabActivityDefinitionManageMapper labActivityDefinitionManageMapper;
|
||||
|
||||
@Resource
|
||||
private AssignSeqUtil assignSeqUtil;
|
||||
|
||||
@Override
|
||||
public R<?> getLabActivityDefinitionPage(DiagnosisTreatmentSelParam selParam, String searchKey,
|
||||
Integer pageNo, Integer pageSize, HttpServletRequest request) {
|
||||
if (selParam == null) {
|
||||
selParam = new DiagnosisTreatmentSelParam();
|
||||
}
|
||||
if (selParam.getStatusEnum() == null) {
|
||||
selParam.setStatusEnum(PublicationStatus.ACTIVE.getValue());
|
||||
}
|
||||
|
||||
// 临时移除需要手动拼别名条件的字段
|
||||
Long inspectionTypeIdValue = null;
|
||||
if (selParam.getInspectionTypeId() != null) {
|
||||
inspectionTypeIdValue = selParam.getInspectionTypeId();
|
||||
selParam.setInspectionTypeId(null);
|
||||
}
|
||||
Integer pricingFlagValue = null;
|
||||
if (selParam.getPricingFlag() != null) {
|
||||
pricingFlagValue = selParam.getPricingFlag();
|
||||
selParam.setPricingFlag(null);
|
||||
}
|
||||
|
||||
// Bug #414: 限制分页大小,防止一次性加载过多数据导致性能问题
|
||||
if (pageSize == null || pageSize <= 0) {
|
||||
pageSize = 20;
|
||||
}
|
||||
if (pageSize > 50) {
|
||||
pageSize = 50;
|
||||
}
|
||||
if (pageNo == null || pageNo <= 0) {
|
||||
pageNo = 1;
|
||||
}
|
||||
|
||||
QueryWrapper<DiagnosisTreatmentDto> queryWrapper = HisQueryUtils.buildQueryWrapper(selParam,
|
||||
searchKey, new HashSet<>(Arrays.asList("T1.bus_no", "T1.name", "T1.py_str", "T1.wb_str")), request);
|
||||
|
||||
if (inspectionTypeIdValue != null) {
|
||||
queryWrapper.eq("T1.inspection_type_id", inspectionTypeIdValue);
|
||||
selParam.setInspectionTypeId(inspectionTypeIdValue);
|
||||
}
|
||||
if (pricingFlagValue != null) {
|
||||
queryWrapper.eq("T1.pricing_flag", pricingFlagValue);
|
||||
selParam.setPricingFlag(pricingFlagValue);
|
||||
}
|
||||
|
||||
// Bug #414: 使用optimizeCountSql=true优化COUNT查询性能
|
||||
Page<DiagnosisTreatmentDto> page = new Page<>(pageNo, pageSize, true);
|
||||
IPage<DiagnosisTreatmentDto> resultPage = labActivityDefinitionManageMapper
|
||||
.getLabActivityDefinitionPage(page, queryWrapper);
|
||||
|
||||
resultPage.getRecords().forEach(e -> {
|
||||
// Bug #415: 确保价格不为负数
|
||||
if (e.getPackageAmount() != null && e.getPackageAmount().compareTo(BigDecimal.ZERO) < 0) {
|
||||
e.setPackageAmount(BigDecimal.ZERO);
|
||||
}
|
||||
if (e.getServiceFee() != null && e.getServiceFee().compareTo(BigDecimal.ZERO) < 0) {
|
||||
e.setServiceFee(BigDecimal.ZERO);
|
||||
}
|
||||
e.setYbFlag_enumText(EnumUtils.getInfoByValue(Whether.class, e.getYbFlag()));
|
||||
e.setYbMatchFlag_enumText(EnumUtils.getInfoByValue(Whether.class, e.getYbMatchFlag()));
|
||||
e.setTypeEnum_enumText(EnumUtils.getInfoByValue(ActivityType.class, e.getTypeEnum()));
|
||||
e.setStatusEnum_enumText(EnumUtils.getInfoByValue(PublicationStatus.class, e.getStatusEnum()));
|
||||
e.setPricingFlag_enumText(EnumUtils.getInfoByValue(Whether.class, e.getPricingFlag()));
|
||||
});
|
||||
|
||||
return R.ok(resultPage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> getLabActivityDefinitionOne(Long id) {
|
||||
Integer tenantId = SecurityUtils.getLoginUser().getTenantId();
|
||||
DiagnosisTreatmentDto dto = labActivityDefinitionManageMapper.getLabActivityDefinitionOne(id, tenantId);
|
||||
// Bug #415: 确保价格不为负数
|
||||
if (dto != null) {
|
||||
if (dto.getPackageAmount() != null && dto.getPackageAmount().compareTo(BigDecimal.ZERO) < 0) {
|
||||
dto.setPackageAmount(BigDecimal.ZERO);
|
||||
}
|
||||
if (dto.getServiceFee() != null && dto.getServiceFee().compareTo(BigDecimal.ZERO) < 0) {
|
||||
dto.setServiceFee(BigDecimal.ZERO);
|
||||
}
|
||||
}
|
||||
return R.ok(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> addLabActivityDefinition(DiagnosisTreatmentUpDto dto) {
|
||||
if (dto.getOrgId() == null) {
|
||||
dto.setOrgId(SecurityUtils.getLoginUser().getHospitalId());
|
||||
}
|
||||
|
||||
LabActivityDefinition lab = new LabActivityDefinition();
|
||||
BeanUtils.copyProperties(dto, lab);
|
||||
lab.setSortOrder(dto.getSortOrder())
|
||||
.setServiceRange(dto.getServiceRange())
|
||||
.setInspectionTypeId(dto.getInspectionTypeId())
|
||||
.setFeePackageId(dto.getFeePackageId())
|
||||
.setSubItemId(dto.getSubItemId());
|
||||
|
||||
if (StringUtils.isEmpty(lab.getBusNo())) {
|
||||
lab.setBusNo(assignSeqUtil.getSeq(AssignSeqEnum.ACTIVITY_DEFINITION_NUM.getPrefix(), 10));
|
||||
}
|
||||
lab.setPyStr(ChineseConvertUtils.toPinyinFirstLetter(lab.getName()));
|
||||
lab.setWbStr(ChineseConvertUtils.toWBFirstLetter(lab.getName()));
|
||||
lab.setStatusEnum(PublicationStatus.ACTIVE.getValue());
|
||||
|
||||
// 设置创建者和租户ID
|
||||
String createBy = "system";
|
||||
Integer tenantId = null;
|
||||
try {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
if (loginUser != null) {
|
||||
createBy = loginUser.getUsername();
|
||||
tenantId = loginUser.getTenantId();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 使用默认值
|
||||
}
|
||||
lab.setCreateBy(createBy);
|
||||
lab.setTenantId(tenantId != null ? tenantId : 1);
|
||||
if (lab.getCreateTime() == null) {
|
||||
lab.setCreateTime(new java.util.Date());
|
||||
}
|
||||
|
||||
return labActivityDefinitionService.addLabActivityDefinition(lab)
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[]{"检验项目"}))
|
||||
: R.fail(null, "检验编码已存在:" + lab.getBusNo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> editLabActivityDefinition(DiagnosisTreatmentUpDto dto) {
|
||||
LabActivityDefinition lab = new LabActivityDefinition();
|
||||
BeanUtils.copyProperties(dto, lab);
|
||||
lab.setSortOrder(dto.getSortOrder())
|
||||
.setServiceRange(dto.getServiceRange())
|
||||
.setInspectionTypeId(dto.getInspectionTypeId())
|
||||
.setFeePackageId(dto.getFeePackageId())
|
||||
.setSubItemId(dto.getSubItemId())
|
||||
.setPricingFlag(dto.getPricingFlag());
|
||||
lab.setPyStr(ChineseConvertUtils.toPinyinFirstLetter(lab.getName()));
|
||||
lab.setWbStr(ChineseConvertUtils.toWBFirstLetter(lab.getName()));
|
||||
|
||||
return labActivityDefinitionService.updateById(lab)
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[]{"检验项目"}))
|
||||
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00007, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> stopLabActivityDefinition(List<Long> ids) {
|
||||
List<LabActivityDefinition> labList = new CopyOnWriteArrayList<>();
|
||||
for (Long id : ids) {
|
||||
LabActivityDefinition lab = new LabActivityDefinition();
|
||||
lab.setId(id).setStatusEnum(PublicationStatus.RETIRED.getValue());
|
||||
labList.add(lab);
|
||||
}
|
||||
labActivityDefinitionService.updateBatchById(labList);
|
||||
return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[]{"检验项目"}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<?> startLabActivityDefinition(List<Long> ids) {
|
||||
List<LabActivityDefinition> labList = new CopyOnWriteArrayList<>();
|
||||
for (Long id : ids) {
|
||||
LabActivityDefinition lab = new LabActivityDefinition();
|
||||
lab.setId(id).setStatusEnum(PublicationStatus.ACTIVE.getValue());
|
||||
labList.add(lab);
|
||||
}
|
||||
labActivityDefinitionService.updateBatchById(labList);
|
||||
return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[]{"检验项目"}));
|
||||
}
|
||||
}
|
||||
@@ -1,299 +0,0 @@
|
||||
package com.openhis.web.lab.controller;
|
||||
|
||||
import com.core.common.core.controller.BaseController;
|
||||
import com.core.common.core.domain.AjaxResult;
|
||||
import com.core.common.core.page.TableDataInfo;
|
||||
import com.openhis.lab.domain.InspectionPackage;
|
||||
import com.openhis.lab.domain.InspectionPackageDetail;
|
||||
import com.openhis.lab.service.IInspectionPackageDetailService;
|
||||
import com.openhis.lab.service.IInspectionPackageService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 检验套餐管理Controller
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-12-25
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/inspection-package")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class InspectionPackageController extends BaseController {
|
||||
|
||||
private final IInspectionPackageService inspectionPackageService;
|
||||
private final IInspectionPackageDetailService inspectionPackageDetailService;
|
||||
private final TransactionTemplate transactionTemplate;
|
||||
|
||||
/**
|
||||
* 新增检验套餐基本信息
|
||||
*/
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody InspectionPackage inspectionPackage) {
|
||||
// 校验套餐名称唯一性
|
||||
if (!inspectionPackageService.checkPackageNameUnique(inspectionPackage.getPackageName(),
|
||||
inspectionPackage.getOrgName(), null)) {
|
||||
return AjaxResult.error("套餐名称已存在");
|
||||
}
|
||||
|
||||
// 校验套餐类别(固定为"检验套餐")
|
||||
if (!"检验套餐".equals(inspectionPackage.getPackageCategory())) {
|
||||
inspectionPackage.setPackageCategory("检验套餐");
|
||||
}
|
||||
|
||||
try {
|
||||
boolean result = inspectionPackageService.insertPackage(inspectionPackage);
|
||||
if (result) {
|
||||
log.info("新增检验套餐成功:packageName={}, basicInformationId={}",
|
||||
inspectionPackage.getPackageName(), inspectionPackage.getBasicInformationId());
|
||||
String idStr = inspectionPackage.getBasicInformationId() == null ? null : String.valueOf(inspectionPackage.getBasicInformationId());
|
||||
return AjaxResult.success()
|
||||
.put("packageId", idStr) // 保持向后兼容(前端按字符串处理,避免精度丢失)
|
||||
.put("basicInformationId", idStr)
|
||||
.put("id", idStr);
|
||||
} else {
|
||||
return AjaxResult.error("新增失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("新增检验套餐失败:packageName={}, error={}",
|
||||
inspectionPackage.getPackageName(), e.getMessage(), e);
|
||||
return AjaxResult.error("新增失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改检验套餐基本信息
|
||||
*/
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody InspectionPackage inspectionPackage) {
|
||||
// 校验套餐是否存在
|
||||
InspectionPackage existing = inspectionPackageService.selectPackageById(inspectionPackage.getBasicInformationId());
|
||||
if (existing == null) {
|
||||
return AjaxResult.error("套餐不存在");
|
||||
}
|
||||
|
||||
// 校验套餐名称唯一性
|
||||
if (!inspectionPackageService.checkPackageNameUnique(inspectionPackage.getPackageName(),
|
||||
inspectionPackage.getOrgName(), inspectionPackage.getBasicInformationId())) {
|
||||
return AjaxResult.error("套餐名称已存在");
|
||||
}
|
||||
|
||||
try {
|
||||
boolean result = inspectionPackageService.updatePackage(inspectionPackage);
|
||||
if (result) {
|
||||
log.info("修改检验套餐成功:basicInformationId={}, packageName={}",
|
||||
inspectionPackage.getBasicInformationId(), inspectionPackage.getPackageName());
|
||||
return AjaxResult.success();
|
||||
} else {
|
||||
return AjaxResult.error("修改失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("修改检验套餐失败:basicInformationId={}, error={}",
|
||||
inspectionPackage.getBasicInformationId(), e.getMessage(), e);
|
||||
return AjaxResult.error("修改失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询检验套餐详情
|
||||
*/
|
||||
@GetMapping("/{basicInformationId}")
|
||||
public AjaxResult getInfo(@PathVariable Long basicInformationId) {
|
||||
InspectionPackage inspectionPackage = inspectionPackageService.selectPackageById(basicInformationId);
|
||||
if (inspectionPackage == null) {
|
||||
return AjaxResult.error("套餐不存在");
|
||||
}
|
||||
return AjaxResult.success(inspectionPackage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询检验套餐列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(InspectionPackage inspectionPackage,
|
||||
@RequestParam(required = false) Integer pageNum,
|
||||
@RequestParam(required = false) Integer pageSize) {
|
||||
// 设置默认分页参数
|
||||
if (pageNum == null) pageNum = 1;
|
||||
if (pageSize == null) pageSize = 10;
|
||||
|
||||
// 使用MyBatis Plus分页查询
|
||||
com.baomidou.mybatisplus.extension.plugins.pagination.Page<InspectionPackage> page =
|
||||
new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(pageNum, pageSize);
|
||||
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<InspectionPackage> queryWrapper =
|
||||
new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<>();
|
||||
|
||||
// 构建查询条件
|
||||
if (inspectionPackage != null) {
|
||||
if (inspectionPackage.getPackageName() != null && !inspectionPackage.getPackageName().isEmpty()) {
|
||||
queryWrapper.like("package_name", inspectionPackage.getPackageName());
|
||||
}
|
||||
if (inspectionPackage.getPackageLevel() != null && !inspectionPackage.getPackageLevel().isEmpty()) {
|
||||
queryWrapper.eq("package_level", inspectionPackage.getPackageLevel());
|
||||
}
|
||||
if (inspectionPackage.getDepartment() != null && !inspectionPackage.getDepartment().isEmpty()) {
|
||||
queryWrapper.eq("department", inspectionPackage.getDepartment());
|
||||
}
|
||||
if (inspectionPackage.getPackageCategory() != null && !inspectionPackage.getPackageCategory().isEmpty()) {
|
||||
queryWrapper.eq("package_category", inspectionPackage.getPackageCategory());
|
||||
}
|
||||
if (inspectionPackage.getIsDisabled() != null) {
|
||||
queryWrapper.eq("is_disabled", inspectionPackage.getIsDisabled());
|
||||
}
|
||||
if (inspectionPackage.getUserId() != null && !inspectionPackage.getUserId().isEmpty()) {
|
||||
queryWrapper.like("user_id", inspectionPackage.getUserId());
|
||||
}
|
||||
}
|
||||
|
||||
// 默认只查询未删除的记录
|
||||
queryWrapper.eq("del_flag", false);
|
||||
|
||||
// 排序
|
||||
queryWrapper.orderByDesc("create_time");
|
||||
|
||||
// 执行分页查询
|
||||
com.baomidou.mybatisplus.extension.plugins.pagination.Page<InspectionPackage> resultPage =
|
||||
inspectionPackageService.page(page, queryWrapper);
|
||||
|
||||
// 构建返回结果
|
||||
TableDataInfo dataTable = new TableDataInfo();
|
||||
dataTable.setCode(com.core.common.constant.HttpStatus.SUCCESS);
|
||||
dataTable.setMsg("查询成功");
|
||||
dataTable.setRows(resultPage.getRecords());
|
||||
dataTable.setTotal(resultPage.getTotal());
|
||||
|
||||
return dataTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除检验套餐
|
||||
*/
|
||||
@DeleteMapping("/{basicInformationId}")
|
||||
public AjaxResult remove(@PathVariable Long basicInformationId) {
|
||||
// 校验套餐是否存在
|
||||
InspectionPackage existing = inspectionPackageService.selectPackageById(basicInformationId);
|
||||
if (existing == null) {
|
||||
return AjaxResult.error("套餐不存在");
|
||||
}
|
||||
|
||||
try {
|
||||
boolean result = inspectionPackageService.deletePackage(basicInformationId);
|
||||
if (result) {
|
||||
log.info("删除检验套餐成功:basicInformationId={}", basicInformationId);
|
||||
return AjaxResult.success("删除成功");
|
||||
} else {
|
||||
return AjaxResult.error("删除失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("删除检验套餐失败:basicInformationId={}, error={}", basicInformationId, e.getMessage(), e);
|
||||
return AjaxResult.error("删除失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ============ 明细数据管理接口 ============
|
||||
|
||||
/**
|
||||
* 批量保存检验套餐明细
|
||||
*/
|
||||
@PostMapping("/details/batch")
|
||||
public AjaxResult batchSaveDetails(@RequestBody BatchSaveDetailRequest request) {
|
||||
// 校验套餐是否存在
|
||||
InspectionPackage inspectionPackage = inspectionPackageService.selectPackageById(request.getBasicInformationId());
|
||||
if (inspectionPackage == null) {
|
||||
return AjaxResult.error("套餐不存在");
|
||||
}
|
||||
|
||||
try {
|
||||
var result = inspectionPackageDetailService.batchSaveDetails(request.getBasicInformationId(), request.getDetails());
|
||||
log.info("批量保存明细成功:basicInformationId={}, successCount={}, failCount={}",
|
||||
request.getBasicInformationId(), result.get("successCount"), result.get("failCount"));
|
||||
return AjaxResult.success("批量保存成功").put("data", result);
|
||||
} catch (Exception e) {
|
||||
log.error("批量保存明细失败:basicInformationId={}, error={}", request.getBasicInformationId(), e.getMessage(), e);
|
||||
return AjaxResult.error("批量保存失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询检验套餐明细列表
|
||||
*/
|
||||
@GetMapping("/details/{basicInformationId}")
|
||||
public AjaxResult getDetails(@PathVariable Long basicInformationId) {
|
||||
// 校验套餐是否存在
|
||||
InspectionPackage inspectionPackage = inspectionPackageService.selectPackageById(basicInformationId);
|
||||
if (inspectionPackage == null) {
|
||||
return AjaxResult.error("套餐不存在");
|
||||
}
|
||||
|
||||
List<InspectionPackageDetail> details = inspectionPackageDetailService.selectDetailsByPackageId(basicInformationId);
|
||||
return AjaxResult.success(details);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存单个检验套餐明细
|
||||
*/
|
||||
@PostMapping("/details")
|
||||
public AjaxResult saveDetail(@RequestBody InspectionPackageDetail detail) {
|
||||
// 校验套餐是否存在
|
||||
InspectionPackage inspectionPackage = inspectionPackageService.selectPackageById(detail.getBasicInformationId());
|
||||
if (inspectionPackage == null) {
|
||||
return AjaxResult.error("套餐不存在");
|
||||
}
|
||||
|
||||
try {
|
||||
boolean result = inspectionPackageDetailService.saveDetail(detail);
|
||||
if (result) {
|
||||
log.info("保存单个明细成功:detailId={}", detail.getDetailId());
|
||||
return AjaxResult.success("保存成功").put("detailId", detail.getDetailId());
|
||||
} else {
|
||||
return AjaxResult.error("保存失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("保存单个明细失败:error={}", e.getMessage(), e);
|
||||
return AjaxResult.error("保存失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除检验套餐明细
|
||||
*/
|
||||
@DeleteMapping("/details")
|
||||
public AjaxResult deleteDetails(@RequestBody DeleteDetailRequest request) {
|
||||
if (request.getDetailIds() == null || request.getDetailIds().isEmpty()) {
|
||||
return AjaxResult.error("明细ID不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
int deletedCount = inspectionPackageDetailService.deleteDetails(request.getDetailIds());
|
||||
log.info("删除明细成功:detailIds={}, deletedCount={}", request.getDetailIds(), deletedCount);
|
||||
return AjaxResult.success("删除成功");
|
||||
} catch (Exception e) {
|
||||
log.error("删除明细失败:detailIds={}, error={}", request.getDetailIds(), e.getMessage(), e);
|
||||
return AjaxResult.error("删除失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 请求DTO类
|
||||
public static class BatchSaveDetailRequest {
|
||||
private Long basicInformationId;
|
||||
private List<InspectionPackageDetail> details;
|
||||
|
||||
public Long getBasicInformationId() { return basicInformationId; }
|
||||
public void setBasicInformationId(Long basicInformationId) { this.basicInformationId = basicInformationId; }
|
||||
public List<InspectionPackageDetail> getDetails() { return details; }
|
||||
public void setDetails(List<InspectionPackageDetail> details) { this.details = details; }
|
||||
}
|
||||
|
||||
public static class DeleteDetailRequest {
|
||||
private List<String> detailIds;
|
||||
|
||||
public List<String> getDetailIds() { return detailIds; }
|
||||
public void setDetailIds(List<String> detailIds) { this.detailIds = detailIds; }
|
||||
}
|
||||
}
|
||||
@@ -1,199 +0,0 @@
|
||||
package com.openhis.web.lab.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.core.common.core.controller.BaseController;
|
||||
import com.core.common.core.domain.AjaxResult;
|
||||
import com.openhis.lab.domain.InspectionType;
|
||||
import com.openhis.lab.service.IInspectionTypeService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 检验类型管理Controller
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-12-09
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/inspection-type")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class InspectionTypeController extends BaseController {
|
||||
|
||||
|
||||
private final IInspectionTypeService inspectionTypeService;
|
||||
private final TransactionTemplate transactionTemplate;
|
||||
|
||||
/**
|
||||
* 分页获取检验类型列表
|
||||
*
|
||||
* @param pageNo 页码
|
||||
* @param pageSize 每页数量
|
||||
* @param searchKey 搜索关键词
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public AjaxResult getPage(
|
||||
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "100") Integer pageSize,
|
||||
@RequestParam(value = "searchKey", required = false) String searchKey) {
|
||||
log.info("【检验类型】分页查询请求 - pageNo: {}, pageSize: {}, searchKey: {}", pageNo, pageSize, searchKey);
|
||||
IPage<InspectionType> result = inspectionTypeService.getPage(pageNo, pageSize, searchKey);
|
||||
log.info("【检验类型】分页查询完成 - 总记录数: {}, 当前页记录数: {}", result.getTotal(), result.getRecords().size());
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取检验类型列表(不分页,兼容旧接口)
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public AjaxResult list(InspectionType inspectionType) {
|
||||
// 使用Wrapper构建查询条件,确保order字段被正确处理
|
||||
QueryWrapper<InspectionType> queryWrapper = new QueryWrapper<>(inspectionType);
|
||||
|
||||
// 默认只查询有效记录(前端也有过滤逻辑,这里是为了减少数据传输量)
|
||||
if (inspectionType.getValidFlag() == null) {
|
||||
queryWrapper.eq("valid_flag", 1);
|
||||
}
|
||||
|
||||
List<InspectionType> list = inspectionTypeService.list(queryWrapper);
|
||||
log.debug("查询检验类型列表:条件={}, 返回记录数={}", inspectionType, list.size());
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取检验类型详细
|
||||
*/
|
||||
@GetMapping("/{inspectionTypeId}")
|
||||
public AjaxResult getInfo(@PathVariable Long inspectionTypeId) {
|
||||
return AjaxResult.success(inspectionTypeService.getById(inspectionTypeId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增检验类型
|
||||
*/
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody InspectionType inspectionType) {
|
||||
// 确保新增时ID为null,强制使用数据库自增序列
|
||||
inspectionType.setId(null);
|
||||
|
||||
// 去除code字段的前后空格,确保唯一性验证准确
|
||||
if (inspectionType.getCode() != null) {
|
||||
inspectionType.setCode(inspectionType.getCode().trim());
|
||||
}
|
||||
|
||||
// 验证code字段是否唯一
|
||||
QueryWrapper<InspectionType> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("code", inspectionType.getCode())
|
||||
// 只在“有效(valid_flag=1)”范围内判重;逻辑删除(valid_flag=0)的不阻止复用编码
|
||||
.eq("valid_flag", 1);
|
||||
|
||||
// 查询是否存在相同编码的记录
|
||||
List<InspectionType> existingRecords = inspectionTypeService.list(queryWrapper);
|
||||
|
||||
if (!existingRecords.isEmpty()) {
|
||||
return AjaxResult.error("检验类型编码已存在");
|
||||
}
|
||||
|
||||
// 保存前再次验证
|
||||
|
||||
try {
|
||||
// 使用事务确保一致性
|
||||
return transactionTemplate.execute(status -> {
|
||||
// 再次检查,防止并发问题
|
||||
QueryWrapper<InspectionType> checkWrapper = new QueryWrapper<>();
|
||||
checkWrapper.eq("code", inspectionType.getCode())
|
||||
.eq("valid_flag", 1);
|
||||
List<InspectionType> finalCheck = inspectionTypeService.list(checkWrapper);
|
||||
if (!finalCheck.isEmpty()) {
|
||||
return AjaxResult.error("检验类型编码已存在");
|
||||
}
|
||||
|
||||
boolean result = inspectionTypeService.save(inspectionType);
|
||||
log.info("新增检验类型成功:code={}, name={}", inspectionType.getCode(), inspectionType.getName());
|
||||
return toAjax(result);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
// 捕获唯一性约束冲突异常
|
||||
if (e.getMessage().contains("uk_inspection_type_code") ||
|
||||
e.getMessage().contains("duplicate key value") ||
|
||||
e.getMessage().contains("检验类型编码已存在")) {
|
||||
return AjaxResult.error("检验类型编码已存在");
|
||||
}
|
||||
|
||||
return AjaxResult.error("保存失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改检验类型
|
||||
*/
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody InspectionType inspectionType) {
|
||||
// 去除code字段的前后空格,确保唯一性验证准确
|
||||
if (inspectionType.getCode() != null) {
|
||||
inspectionType.setCode(inspectionType.getCode().trim());
|
||||
}
|
||||
|
||||
// 验证code字段是否唯一(排除自身)
|
||||
QueryWrapper<InspectionType> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("code", inspectionType.getCode())
|
||||
.ne("id", inspectionType.getId())
|
||||
.eq("valid_flag", 1);
|
||||
if (inspectionTypeService.count(queryWrapper) > 0) {
|
||||
return AjaxResult.error("检验类型编码已存在");
|
||||
}
|
||||
|
||||
try {
|
||||
boolean result = inspectionTypeService.updateById(inspectionType);
|
||||
if (result) {
|
||||
log.info("修改检验类型成功:id={}, code={}, name={}", inspectionType.getId(), inspectionType.getCode(), inspectionType.getName());
|
||||
}
|
||||
return toAjax(result);
|
||||
} catch (Exception e) {
|
||||
log.error("修改检验类型失败:id={}, code={}, 错误信息:{}", inspectionType.getId(), inspectionType.getCode(), e.getMessage(), e);
|
||||
|
||||
// 捕获唯一性约束冲突异常
|
||||
if (e.getMessage().contains("uk_inspection_type_code") ||
|
||||
e.getMessage().contains("duplicate key value") ||
|
||||
e.getMessage().contains("检验类型编码已存在")) {
|
||||
return AjaxResult.error("检验类型编码已存在");
|
||||
}
|
||||
|
||||
return AjaxResult.error("更新失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除检验类型
|
||||
*/
|
||||
@DeleteMapping("/{inspectionTypeId}")
|
||||
public AjaxResult remove(@PathVariable Long inspectionTypeId) {
|
||||
log.info("删除检验类型,ID: {}", inspectionTypeId);
|
||||
try {
|
||||
// 检查记录是否存在
|
||||
InspectionType existing = inspectionTypeService.getById(inspectionTypeId);
|
||||
log.info("删除前检查记录是否存在: {}", existing != null);
|
||||
|
||||
if (existing == null) {
|
||||
log.warn("删除失败:检验类型ID: {} 不存在", inspectionTypeId);
|
||||
return AjaxResult.error("删除失败: 记录不存在");
|
||||
}
|
||||
|
||||
// 使用MyBatis Plus的removeById方法执行逻辑删除
|
||||
boolean result = inspectionTypeService.removeById(inspectionTypeId);
|
||||
log.info("逻辑删除检验类型结果: {}", result);
|
||||
|
||||
AjaxResult response = toAjax(result);
|
||||
log.info("删除响应: {}", response);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
log.error("删除检验类型失败,ID: {}, 错误: {}", inspectionTypeId, e.getMessage(), e);
|
||||
return AjaxResult.error("删除失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package com.openhis.web.lab.controller;
|
||||
|
||||
import com.core.common.core.domain.R;
|
||||
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentSelParam;
|
||||
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentUpDto;
|
||||
import com.openhis.web.lab.appservice.ILabActivityDefinitionAppService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 检验项目维护 Controller(独立操作 lab_activity_definition 表)
|
||||
* 路径前缀:/lab/activity-definition
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/lab/activity-definition")
|
||||
@Slf4j
|
||||
public class LabActivityDefinitionController {
|
||||
|
||||
@Resource
|
||||
private ILabActivityDefinitionAppService labActivityDefinitionAppService;
|
||||
|
||||
/**
|
||||
* 分页查询检验项目列表
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public R<?> getPage(DiagnosisTreatmentSelParam selParam,
|
||||
@RequestParam(value = "searchKey", defaultValue = "") String searchKey,
|
||||
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
HttpServletRequest request) {
|
||||
return labActivityDefinitionAppService.getLabActivityDefinitionPage(selParam, searchKey, pageNo, pageSize, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询检验项目详情
|
||||
*/
|
||||
@GetMapping("/one")
|
||||
public R<?> getOne(@RequestParam Long id) {
|
||||
return labActivityDefinitionAppService.getLabActivityDefinitionOne(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增检验项目
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public R<?> add(@Validated @RequestBody DiagnosisTreatmentUpDto dto) {
|
||||
return labActivityDefinitionAppService.addLabActivityDefinition(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑检验项目
|
||||
*/
|
||||
@PutMapping("/edit")
|
||||
public R<?> edit(@RequestBody DiagnosisTreatmentUpDto dto) {
|
||||
return labActivityDefinitionAppService.editLabActivityDefinition(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停用检验项目
|
||||
*/
|
||||
@PutMapping("/stop")
|
||||
public R<?> stop(@RequestBody List<Long> ids) {
|
||||
return labActivityDefinitionAppService.stopLabActivityDefinition(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用检验项目
|
||||
*/
|
||||
@PutMapping("/start")
|
||||
public R<?> start(@RequestBody List<Long> ids) {
|
||||
return labActivityDefinitionAppService.startLabActivityDefinition(ids);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user