|
@@ -0,0 +1,170 @@
|
|
1
|
+package com.eitc.patient.controller;
|
|
2
|
+
|
|
3
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
4
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
5
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
6
|
+import com.eitc.common.annotation.Log;
|
|
7
|
+import com.eitc.common.core.controller.BaseController;
|
|
8
|
+import com.eitc.common.core.domain.AjaxResult;
|
|
9
|
+import com.eitc.common.enums.BusinessType;
|
|
10
|
+import com.eitc.common.utils.poi.ExcelUtil;
|
|
11
|
+import com.eitc.patient.domain.DiagnosisManage;
|
|
12
|
+import com.eitc.patient.excel.DiagnosisManageTemplateExcel;
|
|
13
|
+import com.eitc.patient.service.IDiagnosisManageService;
|
|
14
|
+import io.swagger.annotations.Api;
|
|
15
|
+import io.swagger.annotations.ApiOperation;
|
|
16
|
+import io.swagger.annotations.ApiParam;
|
|
17
|
+import org.apache.commons.lang3.StringUtils;
|
|
18
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
19
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
20
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
21
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
22
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
23
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
24
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
25
|
+import org.springframework.web.bind.annotation.RestController;
|
|
26
|
+import org.springframework.web.multipart.MultipartFile;
|
|
27
|
+
|
|
28
|
+import javax.annotation.Resource;
|
|
29
|
+import javax.servlet.http.HttpServletResponse;
|
|
30
|
+import javax.validation.Valid;
|
|
31
|
+import java.io.IOException;
|
|
32
|
+import java.util.List;
|
|
33
|
+
|
|
34
|
+/**
|
|
35
|
+ * DiagnosisManageController
|
|
36
|
+ *
|
|
37
|
+ * @author mtx
|
|
38
|
+ * @date: 2024/05/17 15:51
|
|
39
|
+ */
|
|
40
|
+@Api(tags = "诊断管理")
|
|
41
|
+@RestController
|
|
42
|
+@RequestMapping("/diagnosis-manage")
|
|
43
|
+public class DiagnosisManageController extends BaseController {
|
|
44
|
+
|
|
45
|
+ @Resource
|
|
46
|
+ private IDiagnosisManageService diagnosisManageService;
|
|
47
|
+
|
|
48
|
+ /**
|
|
49
|
+ * 查询诊断管理
|
|
50
|
+ */
|
|
51
|
+ @GetMapping("/list")
|
|
52
|
+ @ApiOperation("查询诊断管理")
|
|
53
|
+ public AjaxResult list(@ApiParam(name = "diagnosisParam", value = "搜索条件")
|
|
54
|
+ @RequestParam(name = "diagnosisParam", required = false) String diagnosisParam) {
|
|
55
|
+ LambdaQueryWrapper<DiagnosisManage> wrapper = Wrappers.lambdaQuery();
|
|
56
|
+ if (StringUtils.isNotBlank(diagnosisParam)) {
|
|
57
|
+ wrapper.like(DiagnosisManage::getDiagnosisName, diagnosisParam).or()
|
|
58
|
+ .like(DiagnosisManage::getDiagnosisCode, diagnosisParam);
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ return success(diagnosisManageService.list(wrapper));
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ /**
|
|
65
|
+ * 获取诊断管理详细信息
|
|
66
|
+ */
|
|
67
|
+ @GetMapping(value = "/detail")
|
|
68
|
+ @ApiOperation("获取诊断管理详细信息")
|
|
69
|
+ public AjaxResult detail(String id) {
|
|
70
|
+ return success(diagnosisManageService.getById(id));
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+ /**
|
|
74
|
+ * 新增诊断管理
|
|
75
|
+ */
|
|
76
|
+ @Log(title = "新增诊断管理", businessType = BusinessType.INSERT)
|
|
77
|
+ @PostMapping
|
|
78
|
+ @ApiOperation("新增诊断管理")
|
|
79
|
+ public AjaxResult add(@Valid @RequestBody DiagnosisManage diagnosisManage) {
|
|
80
|
+ checkSaveDiagnosisManage(diagnosisManage);
|
|
81
|
+ return toAjax(diagnosisManageService.save(diagnosisManage));
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ /**
|
|
85
|
+ * 修改诊断管理
|
|
86
|
+ */
|
|
87
|
+ @Log(title = "修改诊断管理", businessType = BusinessType.UPDATE)
|
|
88
|
+ @PutMapping
|
|
89
|
+ @ApiOperation("修改诊断管理")
|
|
90
|
+ public AjaxResult edit(@Valid @RequestBody DiagnosisManage diagnosisManage) {
|
|
91
|
+ checkSaveDiagnosisManage(diagnosisManage);
|
|
92
|
+ return toAjax(diagnosisManageService.updateById(diagnosisManage));
|
|
93
|
+ }
|
|
94
|
+
|
|
95
|
+ /**
|
|
96
|
+ * 导入诊断分类模板
|
|
97
|
+ *
|
|
98
|
+ * @param file 文件
|
|
99
|
+ */
|
|
100
|
+ @Log(title = "导入诊断分类模板", businessType = BusinessType.INSERT)
|
|
101
|
+ @PostMapping("/importTemplate")
|
|
102
|
+ @ApiOperation("导入诊断分类模板")
|
|
103
|
+ public void importTemplate(@RequestParam("file") @ApiParam(name = "file", value = "上传文件") MultipartFile file, HttpServletResponse response) throws IOException {
|
|
104
|
+ // 1.解析excel
|
|
105
|
+ ExcelUtil<DiagnosisManageTemplateExcel> util = new ExcelUtil<>(DiagnosisManageTemplateExcel.class);
|
|
106
|
+ List<DiagnosisManageTemplateExcel> list = util.importExcel(file.getInputStream());
|
|
107
|
+ // 2.如果解析数据为空则返回错误信息
|
|
108
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
109
|
+ throw new RuntimeException("上传数据为空,请填写");
|
|
110
|
+ }
|
|
111
|
+ // 解析模板
|
|
112
|
+ List<DiagnosisManageTemplateExcel> diagnosisManageTemplateExcels = diagnosisManageService.importTemplate(list);
|
|
113
|
+ // 导出错误模板
|
|
114
|
+ if (CollectionUtils.isNotEmpty(diagnosisManageTemplateExcels)) {
|
|
115
|
+ util.exportExcel(response, diagnosisManageTemplateExcels, "模板错误");
|
|
116
|
+ }
|
|
117
|
+ }
|
|
118
|
+
|
|
119
|
+ /**
|
|
120
|
+ * 删除诊断管理
|
|
121
|
+ */
|
|
122
|
+ @Log(title = "删除诊断管理", businessType = BusinessType.DELETE)
|
|
123
|
+ @DeleteMapping("/remove")
|
|
124
|
+ @ApiOperation("删除诊断管理")
|
|
125
|
+ public AjaxResult remove(String id) {
|
|
126
|
+ checkDelDiagnosisManage(id);
|
|
127
|
+ return toAjax(diagnosisManageService.removeById(id));
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+ /**
|
|
131
|
+ * 检查诊断管理对象的诊断编码和诊断名称是否重复
|
|
132
|
+ * 此方法通过查询数据库中是否存在相同的诊断编码或诊断名称来确保数据的唯一性
|
|
133
|
+ * 如果发现重复,将抛出IllegalArgumentException异常
|
|
134
|
+ *
|
|
135
|
+ * @param diagnosisManage 待检查的诊断管理对象
|
|
136
|
+ * @throws IllegalArgumentException 如果诊断编码或诊断名称重复,则抛出此异常
|
|
137
|
+ */
|
|
138
|
+ private void checkSaveDiagnosisManage(DiagnosisManage diagnosisManage) {
|
|
139
|
+ // 查询数据库中是否有与提供的诊断编码相同的记录
|
|
140
|
+ long diagnosisCodeCount = diagnosisManageService.count(Wrappers.<DiagnosisManage>lambdaQuery()
|
|
141
|
+ .ne(StringUtils.isNotBlank(diagnosisManage.getId()), DiagnosisManage::getId, diagnosisManage.getId())
|
|
142
|
+ .eq(DiagnosisManage::getDiagnosisCode, diagnosisManage.getDiagnosisCode()));
|
|
143
|
+ // 如果诊断编码重复,则抛出异常
|
|
144
|
+ if (diagnosisCodeCount > 0) {
|
|
145
|
+ throw new IllegalArgumentException("诊断编码重复");
|
|
146
|
+ }
|
|
147
|
+ // 查询数据库中是否有与提供的诊断名称相同的记录
|
|
148
|
+ long diagnosisNameCount = diagnosisManageService.count(Wrappers.<DiagnosisManage>lambdaQuery()
|
|
149
|
+ .ne(StringUtils.isNotBlank(diagnosisManage.getId()), DiagnosisManage::getId, diagnosisManage.getId())
|
|
150
|
+ .eq(DiagnosisManage::getDiagnosisName, diagnosisManage.getDiagnosisName()));
|
|
151
|
+ // 如果诊断名称重复,则抛出异常
|
|
152
|
+ if (diagnosisNameCount > 0) {
|
|
153
|
+ throw new IllegalArgumentException("诊断名称重复");
|
|
154
|
+ }
|
|
155
|
+ }
|
|
156
|
+
|
|
157
|
+ /**
|
|
158
|
+ * 检查并处理删除诊断管理信息前的准备工作
|
|
159
|
+ *
|
|
160
|
+ * @param id 待删除的诊断管理信息的ID
|
|
161
|
+ * @throws IllegalArgumentException 如果id为空,则抛出此异常
|
|
162
|
+ */
|
|
163
|
+ private void checkDelDiagnosisManage(String id) {
|
|
164
|
+ // 检查ID是否为空,如果为空则抛出异常,提示id不能为空
|
|
165
|
+ if (StringUtils.isEmpty(id)) {
|
|
166
|
+ throw new IllegalArgumentException("id不能为空");
|
|
167
|
+ }
|
|
168
|
+ }
|
|
169
|
+
|
|
170
|
+}
|