医院废弃物信息化管理平台
“mitao”
2025-12-25 0242c8ae596f44427cd23d38f637bf987a4de0bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package cn.besteam.modules.medical.controller;
 
import cn.besteam.common.api.vo.Result;
import cn.besteam.common.aspect.annotation.AutoLog;
import cn.besteam.common.dto.IdDTO;
import cn.besteam.common.util.oConvertUtils;
import cn.besteam.modules.medical.entity.MwDevice;
import cn.besteam.modules.medical.entity.MwDisinfectAddress;
import cn.besteam.modules.medical.service.IMwDisinfectAddressService;
import cn.besteam.modules.system.entity.SysDepartment;
import cn.besteam.modules.system.service.ISysDepartmentService;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 消毒地点 前端控制器
 * </p>
 *
 * @author mitao
 * @since 2025-12-18
 */
@RestController
@RequestMapping("/medical/mwDisinfectAddress")
@Slf4j
@Api(tags = "消毒地点管理")
public class MwDisinfectAddressController {
 
    @Autowired
    private IMwDisinfectAddressService mwDisinfectAddressService;
    @Autowired
    private ISysDepartmentService sysDepartmentService;
    /**
     * 分页列表查询
     *
     * @param pageNo             页码
     * @param pageSize           每页数量
     * @param name                请求对象
     * @return 分页结果
     */
    @GetMapping(value = "/list")
    @ApiOperation(value = "获取消毒地点列表", notes = "获取消毒地点分页列表", produces = "application/json")
    @ApiImplicitParams({@ApiImplicitParam(name = "name", value = "地点名称", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "hospitalId", value = "医院ID", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageNo", value = "页码", dataType = "int", paramType = "query", defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "int", paramType = "query", defaultValue = "10")})
    public Result<IPage<MwDisinfectAddress>> queryPageList(
            Integer hospitalId,
            String name,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        List<Integer> hospitalIdList = sysDepartmentService.getSearchHospitalIdList(hospitalId);
 
        LambdaQueryWrapper<MwDisinfectAddress> queryWrapper = new LambdaQueryWrapper<>();
        // 名称模糊查询
        queryWrapper.like(StringUtils.isNotBlank(name),MwDisinfectAddress::getName, name)
                .eq(MwDisinfectAddress::getDelFlag, 0)
                .in(CollUtil.isNotEmpty(hospitalIdList), MwDisinfectAddress::getHospitalId, hospitalIdList)
                .orderByDesc(MwDisinfectAddress::getCreateTime);
 
        Page<MwDisinfectAddress> page = new Page<>(pageNo, pageSize);
        IPage<MwDisinfectAddress> pageList = mwDisinfectAddressService.page(page, queryWrapper);
        Set<Integer> hospitalIds = pageList.getRecords().stream().map(MwDisinfectAddress::getHospitalId).collect(Collectors.toSet());
        Map<Integer, String> hospitalNameMap = CollUtil.isNotEmpty(hospitalIds) ? sysDepartmentService.listByIds(hospitalIds)
                .stream().collect(Collectors.toMap(SysDepartment::getId, SysDepartment::getDepartName)) : Collections.emptyMap();
        pageList.getRecords().forEach(item->{
            item.setHospitalName(hospitalNameMap.get(item.getHospitalId()));
        });
        return Result.ok(pageList);
    }
 
    /**
     * 添加消毒地点
     *
     * @param mwDisinfectAddress 消毒地点信息
     * @return 操作结果
     */
    @PostMapping(value = "/add")
    @AutoLog(value = "添加消毒地点")
    @ApiOperation(value = "添加消毒地点", notes = "添加消毒地点", produces = "application/json")
    public Result<String> add(@RequestBody MwDisinfectAddress mwDisinfectAddress) {
        // 校验名称唯一性
        if (checkNameExists(mwDisinfectAddress.getName(), null, mwDisinfectAddress.getHospitalId())) {
            return Result.error("地点名称已存在!");
        }
 
        boolean success = mwDisinfectAddressService.save(mwDisinfectAddress);
        if (success) {
            return Result.ok("添加成功!");
        } else {
            return Result.error("添加失败!");
        }
    }
 
    /**
     * 编辑消毒地点
     *
     * @param mwDisinfectAddress 消毒地点信息
     * @return 操作结果
     */
    @PostMapping(value = "/edit")
    @AutoLog(value = "编辑消毒地点")
    @ApiOperation(value = "编辑消毒地点", notes = "编辑消毒地点", produces = "application/json")
    public Result<String> edit(@RequestBody MwDisinfectAddress mwDisinfectAddress) {
        if (mwDisinfectAddress.getId() == null) {
            return Result.error("ID不能为空!");
        }
 
        // 校验实体是否存在
        MwDisinfectAddress entity = mwDisinfectAddressService.getById(mwDisinfectAddress.getId());
        if (entity == null) {
            return Result.error("未找到对应实体");
        }
 
        // 校验名称唯一性(排除自身)
        if (checkNameExists(mwDisinfectAddress.getName(), mwDisinfectAddress.getId(), mwDisinfectAddress.getHospitalId())) {
            return Result.error("地点名称已存在!");
        }
 
        boolean success = mwDisinfectAddressService.updateById(mwDisinfectAddress);
        if (success) {
            return Result.ok("修改成功!");
        } else {
            return Result.error("修改失败!");
        }
    }
 
    /**
     * 通过id删除
     *
     * @param dto ID参数
     * @return 操作结果
     */
    @PostMapping(value = "/delete")
    @AutoLog(value = "删除消毒地点")
    @ApiOperation(value = "删除消毒地点", notes = "删除消毒地点", produces = "application/json")
    public Result<String> delete(@Validated @RequestBody IdDTO dto) {
        MwDisinfectAddress entity = mwDisinfectAddressService.getById(dto.getId());
        if (entity == null) {
            return Result.error("未找到对应实体");
        }
 
        boolean success = mwDisinfectAddressService.removeById(dto.getId());
        if (success) {
            return Result.ok("删除成功!");
        } else {
            return Result.error("删除失败!");
        }
    }
 
    /**
     * 批量删除
     *
     * @param ids ID数组,逗号分隔
     * @return 操作结果
     */
    @PostMapping(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("参数不识别!");
        }
 
        mwDisinfectAddressService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.ok("批量删除成功!");
    }
 
    /**
     * 通过id查询
     *
     * @param id 消毒地点ID
     * @return 消毒地点详情
     */
    @GetMapping(value = "/queryById")
    @ApiOperation(value = "通过ID查询消毒地点", notes = "通过ID查询消毒地点", produces = "application/json")
    public Result<MwDisinfectAddress> queryById(@RequestParam(name = "id", required = true) Integer id) {
        MwDisinfectAddress entity = mwDisinfectAddressService.getById(id);
        if (entity == null) {
            return Result.error("未找到对应实体");
        }
        return Result.ok(entity);
    }
 
    /**
     * 检查名称是否已存在
     *
     * @param name       地点名称
     * @param excludeId  排除的ID(编辑时使用)
     * @param hospitalId 医院ID
     * @return true-存在,false-不存在
     */
    private boolean checkNameExists(String name, Integer excludeId, Integer hospitalId) {
        if (oConvertUtils.isEmpty(name)) {
            return false;
        }
 
        QueryWrapper<MwDisinfectAddress> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);
        queryWrapper.eq("hospital_id",  hospitalId);
        queryWrapper.eq("del_flag", 0);
 
        if (excludeId != null) {
            queryWrapper.ne("id", excludeId);
        }
 
        int count = mwDisinfectAddressService.count(queryWrapper);
        return count > 0;
    }
}