Merge branch 'develop' of https://gitea.gentronhealth.com/Yajentine/his into develop
This commit is contained in:
@@ -24,14 +24,6 @@ import java.util.List;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class InspectionTypeController extends BaseController {
|
public class InspectionTypeController extends BaseController {
|
||||||
|
|
||||||
// 辅助方法:将字节数组转换为十六进制字符串
|
|
||||||
private static String bytesToHex(byte[] bytes) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (byte b : bytes) {
|
|
||||||
sb.append(String.format("%02X ", b));
|
|
||||||
}
|
|
||||||
return sb.toString().trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
private final IInspectionTypeService inspectionTypeService;
|
private final IInspectionTypeService inspectionTypeService;
|
||||||
private final TransactionTemplate transactionTemplate;
|
private final TransactionTemplate transactionTemplate;
|
||||||
@@ -43,7 +35,14 @@ public class InspectionTypeController extends BaseController {
|
|||||||
public AjaxResult list(InspectionType inspectionType) {
|
public AjaxResult list(InspectionType inspectionType) {
|
||||||
// 使用Wrapper构建查询条件,确保order字段被正确处理
|
// 使用Wrapper构建查询条件,确保order字段被正确处理
|
||||||
QueryWrapper<InspectionType> queryWrapper = new QueryWrapper<>(inspectionType);
|
QueryWrapper<InspectionType> queryWrapper = new QueryWrapper<>(inspectionType);
|
||||||
|
|
||||||
|
// 默认只查询有效记录(前端也有过滤逻辑,这里是为了减少数据传输量)
|
||||||
|
if (inspectionType.getValidFlag() == null) {
|
||||||
|
queryWrapper.eq("valid_flag", 1);
|
||||||
|
}
|
||||||
|
|
||||||
List<InspectionType> list = inspectionTypeService.list(queryWrapper);
|
List<InspectionType> list = inspectionTypeService.list(queryWrapper);
|
||||||
|
log.debug("查询检验类型列表:条件={}, 返回记录数={}", inspectionType, list.size());
|
||||||
return AjaxResult.success(list);
|
return AjaxResult.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,23 +71,15 @@ public class InspectionTypeController extends BaseController {
|
|||||||
QueryWrapper<InspectionType> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<InspectionType> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("code", inspectionType.getCode());
|
queryWrapper.eq("code", inspectionType.getCode());
|
||||||
|
|
||||||
// 输出调试信息
|
// 查询是否存在相同编码的记录
|
||||||
System.out.println("检查编码唯一性:code=" + inspectionType.getCode() + ", 长度=" + inspectionType.getCode().length());
|
|
||||||
System.out.println("code的十六进制表示:" + bytesToHex(inspectionType.getCode().getBytes()));
|
|
||||||
|
|
||||||
// 直接查询具体记录,而不仅仅是计数
|
|
||||||
List<InspectionType> existingRecords = inspectionTypeService.list(queryWrapper);
|
List<InspectionType> existingRecords = inspectionTypeService.list(queryWrapper);
|
||||||
System.out.println("数据库中存在的记录数:" + existingRecords.size());
|
log.debug("检查编码唯一性:code={}, 数据库中存在记录数={}", inspectionType.getCode(), existingRecords.size());
|
||||||
for (InspectionType record : existingRecords) {
|
|
||||||
System.out.println("已存在记录:id=" + record.getId() + ", code=" + record.getCode() + ", code长度=" + record.getCode().length() + ", code十六进制=" + bytesToHex(record.getCode().getBytes()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!existingRecords.isEmpty()) {
|
if (!existingRecords.isEmpty()) {
|
||||||
return AjaxResult.error("检验类型编码已存在");
|
return AjaxResult.error("检验类型编码已存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存前再次验证
|
// 保存前再次验证
|
||||||
System.out.println("准备保存数据:" + inspectionType);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 使用事务确保一致性
|
// 使用事务确保一致性
|
||||||
@@ -102,11 +93,11 @@ public class InspectionTypeController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean result = inspectionTypeService.save(inspectionType);
|
boolean result = inspectionTypeService.save(inspectionType);
|
||||||
System.out.println("保存结果:" + result);
|
log.info("新增检验类型成功:code={}, name={}", inspectionType.getCode(), inspectionType.getName());
|
||||||
return toAjax(result);
|
return toAjax(result);
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("保存失败,错误信息:" + e.getMessage());
|
log.error("新增检验类型失败:code={}, 错误信息:{}", inspectionType.getCode(), e.getMessage(), e);
|
||||||
|
|
||||||
// 捕获唯一性约束冲突异常
|
// 捕获唯一性约束冲突异常
|
||||||
if (e.getMessage().contains("uk_inspection_type_code") ||
|
if (e.getMessage().contains("uk_inspection_type_code") ||
|
||||||
@@ -139,15 +130,20 @@ public class InspectionTypeController extends BaseController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
boolean result = inspectionTypeService.updateById(inspectionType);
|
boolean result = inspectionTypeService.updateById(inspectionType);
|
||||||
|
if (result) {
|
||||||
|
log.info("修改检验类型成功:id={}, code={}, name={}", inspectionType.getId(), inspectionType.getCode(), inspectionType.getName());
|
||||||
|
}
|
||||||
return toAjax(result);
|
return toAjax(result);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
log.error("修改检验类型失败:id={}, code={}, 错误信息:{}", inspectionType.getId(), inspectionType.getCode(), e.getMessage(), e);
|
||||||
|
|
||||||
// 捕获唯一性约束冲突异常
|
// 捕获唯一性约束冲突异常
|
||||||
if (e.getMessage().contains("uk_inspection_type_code") ||
|
if (e.getMessage().contains("uk_inspection_type_code") ||
|
||||||
e.getMessage().contains("duplicate key value") ||
|
e.getMessage().contains("duplicate key value") ||
|
||||||
e.getMessage().contains("检验类型编码已存在")) {
|
e.getMessage().contains("检验类型编码已存在")) {
|
||||||
return AjaxResult.error("检验类型编码已存在");
|
return AjaxResult.error("检验类型编码已存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
return AjaxResult.error("更新失败:" + e.getMessage());
|
return AjaxResult.error("更新失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,11 +176,4 @@ public class InspectionTypeController extends BaseController {
|
|||||||
return AjaxResult.error("删除失败: " + e.getMessage());
|
return AjaxResult.error("删除失败: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 测试删除接口,直接返回成功
|
|
||||||
@DeleteMapping("/test-delete/{id}")
|
|
||||||
public AjaxResult testDelete(@PathVariable Long id) {
|
|
||||||
log.info("测试删除接口,ID: {}", id);
|
|
||||||
return AjaxResult.success("测试删除成功");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -796,10 +796,10 @@ const getInspectionTypeList = () => {
|
|||||||
// 确保数据结构与前端使用的一致,处理后端返回的AjaxResult格式
|
// 确保数据结构与前端使用的一致,处理后端返回的AjaxResult格式
|
||||||
// 后端返回的数据格式: {code: 200, msg: "查询成功", data: [检验类型列表]}
|
// 后端返回的数据格式: {code: 200, msg: "查询成功", data: [检验类型列表]}
|
||||||
const inspectionTypeList = data.data || [];
|
const inspectionTypeList = data.data || [];
|
||||||
|
// 后端实体字段名本身就是 sortOrder,这里不再从不存在的 item.order 做映射
|
||||||
const formattedData = inspectionTypeList.map(item => ({
|
const formattedData = inspectionTypeList.map(item => ({
|
||||||
...item,
|
...item,
|
||||||
// 将后端返回的order字段映射到前端使用的sortOrder字段
|
sortOrder: item.sortOrder
|
||||||
sortOrder: item.order
|
|
||||||
}));
|
}));
|
||||||
// 过滤掉已逻辑删除的记录(validFlag为0)
|
// 过滤掉已逻辑删除的记录(validFlag为0)
|
||||||
tableData.value = formattedData.filter(item => item.validFlag === 1);
|
tableData.value = formattedData.filter(item => item.validFlag === 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user