医院废弃物信息化管理平台
“mitao”
2026-01-14 ce8e86e7045a6eadc2f06d3cd1af90d22b04fdd0
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
226
227
228
229
230
231
232
233
234
235
236
237
238
package cn.besteam.modules.medical.controller;
 
import cn.besteam.common.api.vo.Result;
import cn.besteam.common.aspect.annotation.AutoLog;
import cn.besteam.common.constant.DepartmentEnum;
import cn.besteam.common.constant.ErrorCode;
import cn.besteam.common.constant.MedicalWasteEnum;
import cn.besteam.common.dto.IdDTO;
import cn.besteam.common.exception.BusinessException;
import cn.besteam.modules.medical.entity.MwBusinessApproval;
import cn.besteam.modules.medical.entity.MwWarningConfigItem;
import cn.besteam.modules.medical.service.IMwBusinessApprovalService;
import cn.besteam.modules.medical.service.IMwWarningConfigItemService;
import cn.besteam.modules.shiro.authc.util.EnvUtils;
import cn.besteam.modules.system.entity.SysDepartment;
import cn.besteam.modules.system.entity.SysDictItem;
import cn.besteam.modules.system.service.ISysDepartmentService;
import cn.besteam.modules.system.service.ISysDictItemService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
 
/**
 * @Title: Controller
 * @Description: 预警-自定义配置
 * @author: besteam
 * @date: 2020-07-17
 * @version: V1.0
 */
@RestController
@RequestMapping("/medical/mwWarningConfigItem")
@Slf4j
@Api(description = "预警-自定义配置")
public class MwWarningConfigItemController {
 
    @Autowired
    private IMwWarningConfigItemService mwWarningConfigItemService;
 
    @Autowired
    private ISysDepartmentService sysDepartmentService;
    /**
     * 业务审批
     */
    @Autowired
    private IMwBusinessApprovalService businessApprovalService;
 
    @Autowired
    private ISysDictItemService sysDictItemService;
 
    /**
     * @param type
     * @return
     */
    @GetMapping(value = "/listByType")
    @ApiOperation(value = "获取预警-自定义配置数据列表", notes = "获取所有预警-自定义配置数据列表", produces = "application/json")
    public Object listByType(@RequestParam Integer type, Integer departmentId,  Integer pageNo,  Integer pageSize) {
        if(pageNo==null || pageSize==null){
            return Result.ok(mwWarningConfigItemService.listByType(type, departmentId));
        }else {
            return Result.ok(mwWarningConfigItemService.listByType(type, departmentId, pageNo, pageSize));
        }
    }
 
    /**
     * 添加
     *
     * @param mwWarningConfigItem
     * @return
     */
    @PostMapping(value = "/add")
    @AutoLog(value = "添加预警-自定义配置")
    @ApiOperation(value = "添加预警-自定义配置", notes = "添加预警-自定义配置", produces = "application/json")
    public Result<Boolean> add(@RequestBody MwWarningConfigItem mwWarningConfigItem) {
 
        if (mwWarningConfigItem.getType() == null) {
            throw new BusinessException(ErrorCode.ERR_500, "类型不能为空");
        }
        //
        QueryWrapper<MwWarningConfigItem> queryWrapper = new QueryWrapper<>();
        SysDepartment hospital = sysDepartmentService.getById(mwWarningConfigItem.getCustomHospitalId());
        SysDepartment office = sysDepartmentService.getById(mwWarningConfigItem.getCustomOfficeId());
        //未出医废 : 医院 + 科室
        if (mwWarningConfigItem.getType().equals(MedicalWasteEnum.WarningConfigTypeEnum.NON_COLLECT.getType())) {
            if (hospital == null || !hospital.getOrgType().equals(DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())) {
                throw new BusinessException(ErrorCode.ERR_500, "医院不存在");
            }
            if (office == null || !office.getOrgType().equals(DepartmentEnum.OrgTypeEnum.OFFICE.getType())) {
                throw new BusinessException(ErrorCode.ERR_500, "科室不存在");
            }
            queryWrapper.lambda().eq(MwWarningConfigItem::getCustomHospitalId, mwWarningConfigItem.getCustomHospitalId()).eq(MwWarningConfigItem::getCustomOfficeId, mwWarningConfigItem.getCustomOfficeId())
                    .eq(MwWarningConfigItem::getApplyType,1);
        } else if (mwWarningConfigItem.getType().equals(MedicalWasteEnum.WarningConfigTypeEnum.CHECKOUT_OVER_TIME.getType())) {
            if (hospital == null || !hospital.getOrgType().equals(DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())) {
                throw new BusinessException(ErrorCode.ERR_500, "医院不存在");
            }
            queryWrapper.lambda().eq(MwWarningConfigItem::getCustomHospitalId, mwWarningConfigItem.getCustomHospitalId()).eq(MwWarningConfigItem::getWasteType, mwWarningConfigItem.getWasteType())
            .eq(MwWarningConfigItem::getApplyType,1);
        }
        Integer approvalCount=businessApprovalService.count(new QueryWrapper<MwBusinessApproval>()
                .eq("hospital_id",mwWarningConfigItem.getCustomHospitalId())
                .eq("office_id",mwWarningConfigItem.getCustomOfficeId())
                .eq("status",0)
                .eq("type",2)
                .eq("apply_type",1)
        );
        if (approvalCount > 0) {
            throw new BusinessException(ErrorCode.ERR_500, "自定义设置还在审核中");
        }
        mwWarningConfigItem.setStatus(1);
        Boolean result=mwWarningConfigItemService.save(mwWarningConfigItem);
        // todo 未出医废预警设置时长 添加审批数据
        if(mwWarningConfigItem.getType()==1){
            mwWarningConfigItem.setStatus(0);
            MwBusinessApproval businessApproval = new MwBusinessApproval();
            businessApproval.setHospitalId(mwWarningConfigItem.getCustomHospitalId());
            businessApproval.setOfficeId(mwWarningConfigItem.getCustomOfficeId());
            businessApproval.setOperatorId(EnvUtils.getUser().getId());
            businessApproval.setLinkman(EnvUtils.getUser().getName());
            businessApproval.setLinkphone(EnvUtils.getUser().getPhone());
            businessApproval.setApplyType(mwWarningConfigItem.getApplyType());
            if(mwWarningConfigItem.getApplyType()==1){//固定时长
                businessApproval.setApplyContent("科室("+office.getDepartName()+")申请未出医废预警自定义设置固定时长:"+mwWarningConfigItem.getCustomValue()+"天");
            }else if(mwWarningConfigItem.getApplyType()==2){//节假日
                SysDictItem sysDictItem=sysDictItemService.getById(mwWarningConfigItem.getCustomValue());
                businessApproval.setApplyContent("科室("+office.getDepartName()+")申请未出医废预警自定义设置节假日:"+sysDictItem.getItemText()+"("+sysDictItem.getDescription()+")");
            }else if(mwWarningConfigItem.getApplyType()==3){//临时时长
                businessApproval.setApplyContent("科室("+office.getDepartName()+")申请未出医废预警自定义设置临时时长:"+mwWarningConfigItem.getCustomValue()+"天");
            }
            if(mwWarningConfigItem.getRemarks()!=null){
                businessApproval.setApplyMark(mwWarningConfigItem.getRemarks());
            }else {
                businessApproval.setApplyMark("无");
            }
            businessApproval.setStatus(0);
            businessApproval.setType(2);
            businessApproval.setApplyDataId(mwWarningConfigItem.getId());
            businessApprovalService.save(businessApproval);
            mwWarningConfigItemService.updateById(mwWarningConfigItem);
        }
 
        return Result.ok(result);
    }
 
    /**
     * 编辑
     *
     * @param mwWarningConfigItem
     * @return
     */
    @PostMapping(value = "/edit")
    @AutoLog(value = "编辑预警-自定义配置")
    @ApiOperation(value = "编辑预警-自定义配置", notes = "编辑预警-自定义配置", produces = "application/json")
    public Result<Boolean> edit(@RequestBody MwWarningConfigItem mwWarningConfigItem) {
 
        MwWarningConfigItem mwWarningConfigItemEntity = mwWarningConfigItemService.getById(mwWarningConfigItem.getId());
        if (mwWarningConfigItemEntity == null) {
            throw new BusinessException(ErrorCode.ERR_500, "自定义配置不存在");
        }
        //
        int count = 0;
        QueryWrapper<MwWarningConfigItem> queryWrapper = new QueryWrapper<>();
        SysDepartment hospital = sysDepartmentService.getById(mwWarningConfigItem.getCustomHospitalId());
        SysDepartment office = sysDepartmentService.getById(mwWarningConfigItem.getCustomOfficeId());
        //未出医废 : 医院 + 科室
        if (mwWarningConfigItem.getType().equals(MedicalWasteEnum.WarningConfigTypeEnum.NON_COLLECT.getType())) {
            if (hospital == null || !hospital.getOrgType().equals(DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())) {
                throw new BusinessException(ErrorCode.ERR_500, "医院不存在");
            }
            if (office == null || !office.getOrgType().equals(DepartmentEnum.OrgTypeEnum.OFFICE.getType())) {
                throw new BusinessException(ErrorCode.ERR_500, "科室不存在");
            }
            queryWrapper.lambda().ne(MwWarningConfigItem::getId,mwWarningConfigItem.getId()).eq(MwWarningConfigItem::getCustomHospitalId, mwWarningConfigItem.getCustomHospitalId()).eq(MwWarningConfigItem::getCustomOfficeId, mwWarningConfigItem.getCustomOfficeId())
                    .eq(MwWarningConfigItem::getApplyType,1);
            count = mwWarningConfigItemService.count(queryWrapper);
        } else if (mwWarningConfigItem.getType().equals(MedicalWasteEnum.WarningConfigTypeEnum.CHECKOUT_OVER_TIME.getType())) {
            if (hospital == null || !hospital.getOrgType().equals(DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())) {
                throw new BusinessException(ErrorCode.ERR_500, "医院不存在");
            }
            queryWrapper.lambda().ne(MwWarningConfigItem::getId,mwWarningConfigItem.getId()).eq(MwWarningConfigItem::getCustomHospitalId, mwWarningConfigItem.getCustomHospitalId()).eq(MwWarningConfigItem::getWasteType, mwWarningConfigItem.getWasteType())
                    .eq(MwWarningConfigItem::getApplyType,1);
            count = mwWarningConfigItemService.count(queryWrapper);
        }
        if (count > 0) {
            throw new BusinessException(ErrorCode.ERR_500, "自定义设置已存在");
        }
        // todo 未出医废预警设置时长 添加审批数据
        if(mwWarningConfigItemEntity.getType()==1){
            mwWarningConfigItem.setStatus(0);
            MwBusinessApproval businessApproval = new MwBusinessApproval();
            businessApproval.setHospitalId(mwWarningConfigItem.getCustomHospitalId());
            businessApproval.setOperatorId(EnvUtils.getUser().getId());
            businessApproval.setLinkman(EnvUtils.getUser().getName());
            businessApproval.setLinkphone(EnvUtils.getUser().getPhone());
            if(mwWarningConfigItem.getApplyType()==1){//固定时长
                businessApproval.setApplyContent("科室("+office.getDepartName()+")申请未出医废预警自定义设置固定时长:"+mwWarningConfigItem.getCustomValue()+"小时");
            }else if(mwWarningConfigItem.getApplyType()==2){//节假日
                SysDictItem sysDictItem=sysDictItemService.getById(mwWarningConfigItem.getCustomValue());
                businessApproval.setApplyContent("科室("+office.getDepartName()+")申请未出医废预警自定义设置节假日:"+sysDictItem.getItemText()+"("+sysDictItem.getDescription()+")");
            }else if(mwWarningConfigItem.getApplyType()==3){//临时时长
                businessApproval.setApplyContent("科室("+office.getDepartName()+")申请未出医废预警自定义设置临时时长:"+mwWarningConfigItem.getCustomValue()+"小时");
            }
 
            if(mwWarningConfigItem.getRemarks()!=null){
                businessApproval.setApplyMark(mwWarningConfigItem.getRemarks());
            }else {
                businessApproval.setApplyMark("无");
            }
            businessApproval.setStatus(0);
            businessApproval.setType(2);
            businessApproval.setApplyDataId(mwWarningConfigItem.getId());
            businessApprovalService.save(businessApproval);
        }
        return Result.ok(mwWarningConfigItemService.updateById(mwWarningConfigItem));
    }
 
    /**
     * 通过id删除
     *
     * @param idDTO
     * @return
     */
    @PostMapping(value = "/delete")
    @AutoLog(value = "删除预警-自定义配置")
    @ApiOperation(value = "删除预警-自定义配置", notes = "删除预警-自定义配置", produces = "application/json")
    public Result<Boolean> delete(@RequestBody IdDTO idDTO) {
 
        MwWarningConfigItem mwWarningConfigItem = mwWarningConfigItemService.getById(idDTO.getId());
        if (mwWarningConfigItem == null) {
            throw new BusinessException(ErrorCode.ERR_500, "自定义配置不存在");
        }
        return Result.ok(mwWarningConfigItemService.removeById(idDTO.getId()));
    }
 
}