医院废弃物信息化管理平台
“mitao”
2025-12-24 3763145f34d7706923d55edc32f5cfbc8bc08b92
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
package cn.besteam.modules.medical.controller;
 
import java.io.IOException;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import cn.besteam.common.aspect.annotation.OpenApi;
import cn.besteam.common.constant.CommonConstant;
import cn.besteam.common.constant.MedicalWasteEnum;
import cn.besteam.common.dto.IdDTO;
import cn.besteam.common.util.DateUtil;
import cn.besteam.modules.medical.dto.MwCollectRecordOpsDTO;
import cn.besteam.modules.medical.dto.MwCollectionPointDTO;
import cn.besteam.modules.medical.vo.MwCollectRecordVO;
import cn.besteam.modules.medical.vo.MwCollectionPointVO;
import cn.besteam.modules.system.entity.SysDepartment;
import cn.besteam.modules.system.service.ISysDepartmentService;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.besteam.common.api.vo.Result;
import cn.besteam.common.aspect.annotation.AutoLog;
import cn.besteam.common.util.oConvertUtils;
import cn.besteam.modules.medical.entity.MwCollectionPoint;
import cn.besteam.modules.medical.service.IMwCollectionPointService;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
 
 /**
 * @Title: Controller
 * @Description: 收集点位
 * @author: besteam
 * @date:   2022-02-09
 * @version: V1.0
 */
@RestController
@RequestMapping("/medical/mwCollectionPoint")
@Slf4j
@Api(description = "收集点位")
public class MwCollectionPointController {
 
    @Autowired
    private IMwCollectionPointService mwCollectionPointService;
 
    @Autowired
    private ISysDepartmentService sysDepartmentService;
    
    /**
      * 分页列表查询
     * @param mwCollectionPoint
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @GetMapping(value = "/list")
    @ApiOperation(value = "获取收集点位数据列表", notes = "获取所有收集点位数据列表", produces = "application/json")
    public Result<IPage<MwCollectionPoint>> queryPageList(MwCollectionPoint mwCollectionPoint, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
 
        Result<IPage<MwCollectionPoint>> result = new Result<IPage<MwCollectionPoint>>();
        QueryWrapper<MwCollectionPoint> queryWrapper = new QueryWrapper<MwCollectionPoint>(mwCollectionPoint);
        Page<MwCollectionPoint> page = new Page<MwCollectionPoint>(pageNo, pageSize);
        //排序逻辑 处理
        String column = req.getParameter("column");
        String order = req.getParameter("order");
        if(oConvertUtils.isNotEmpty(column) && oConvertUtils.isNotEmpty(order)) {
            if("asc".equals(order)) {
                queryWrapper.orderByAsc(oConvertUtils.camelToUnderline(column));
            }else {
                queryWrapper.orderByDesc(oConvertUtils.camelToUnderline(column));
            }
        }
        IPage<MwCollectionPoint> pageList = mwCollectionPointService.page(page, queryWrapper);
        //log.debug("查询当前页:"+pageList.getCurrent());
        //log.debug("查询当前页数量:"+pageList.getSize());
        //log.debug("查询结果数量:"+pageList.getRecords().size());
        //log.debug("数据总数:"+pageList.getTotal());
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }
    
    /**
      *   添加
     * @param mwCollectionPoint
     * @return
     */
    @PostMapping(value = "/add")
    @AutoLog(value = "添加收集点位")
    @ApiOperation(value = "添加收集点位", notes = "添加收集点位", produces = "application/json")
    public Result<MwCollectionPoint> add(@RequestBody MwCollectionPoint mwCollectionPoint) {
 
        Result<MwCollectionPoint> result = new Result<MwCollectionPoint>();
        try {
 
            String[] ids = mwCollectionPoint.getOfficeId().split(",");
            String officeName="";
            for(String id:ids){
                SysDepartment sysDepartment = sysDepartmentService.getById(id);
                officeName+=sysDepartment.getDepartName()+",";
            }
            mwCollectionPoint.setOfficeName(officeName.substring(0,officeName.length()-1));
            SysDepartment sysDepartment = sysDepartmentService.getById(ids[0]);
 
            SysDepartment sysDepartment1 = sysDepartmentService.getById(sysDepartment.getParentId());
            if(sysDepartment1.getOrgType().equals(2)){
                mwCollectionPoint.setHospitalId(sysDepartment1.getId());
                mwCollectionPoint.setHospitalName(sysDepartment1.getDepartName());
            }else{
                sysDepartment1 = sysDepartmentService.getById(sysDepartment1.getParentId());
                mwCollectionPoint.setHospitalId(sysDepartment1.getId());
                mwCollectionPoint.setHospitalName(sysDepartment1.getDepartName());
            }
            MwCollectionPoint mwCollectionPoint1 = mwCollectionPointService.getOne(new QueryWrapper<MwCollectionPoint>().eq("name",mwCollectionPoint.getName()).eq("hospital_id",mwCollectionPoint.getHospitalId()));
            if(mwCollectionPoint1==null){
                mwCollectionPointService.save(mwCollectionPoint);
                result.success("添加成功!");
            }else{
                result.error500("操作失败,名称重复!");
            }
 
        } catch (Exception e) {
            log.error("", e);
            result.error500("操作失败");
        }
        return result;
    }
    
    /**
      *  编辑
     * @param mwCollectionPoint
     * @return
     */
    @PostMapping(value = "/edit")
    @AutoLog(value = "编辑收集点位")
    @ApiOperation(value = "编辑收集点位", notes = "编辑收集点位", produces = "application/json")
    public Result<MwCollectionPoint> edit(@RequestBody MwCollectionPoint mwCollectionPoint) {
 
        Result<MwCollectionPoint> result = new Result<MwCollectionPoint>();
        MwCollectionPoint mwCollectionPointEntity = mwCollectionPointService.getById(mwCollectionPoint.getId());
        if(mwCollectionPointEntity==null) {
            result.error500("未找到对应实体");
        }else {
            String[] ids = mwCollectionPoint.getOfficeId().split(",");
            String officeName="";
            for(String id:ids){
                SysDepartment sysDepartment = sysDepartmentService.getById(id);
                officeName+=sysDepartment.getDepartName()+",";
            }
            mwCollectionPoint.setOfficeName(officeName.substring(0,officeName.length()-1));
            SysDepartment sysDepartment = sysDepartmentService.getById(ids[0]);
 
            SysDepartment sysDepartment1 = sysDepartmentService.getById(sysDepartment.getParentId());
            if(sysDepartment1.getOrgType().equals(2)){
                mwCollectionPoint.setHospitalId(sysDepartment1.getId());
                mwCollectionPoint.setHospitalName(sysDepartment1.getDepartName());
            }else{
                sysDepartment1 = sysDepartmentService.getById(sysDepartment1.getParentId());
                mwCollectionPoint.setHospitalId(sysDepartment1.getId());
                mwCollectionPoint.setHospitalName(sysDepartment1.getDepartName());
            }
            MwCollectionPoint mwCollectionPoint1 = mwCollectionPointService.getOne(new QueryWrapper<MwCollectionPoint>().ne("id",mwCollectionPoint.getId()).eq("name",mwCollectionPoint.getName()).eq("hospital_id",mwCollectionPoint.getHospitalId()));
            if(mwCollectionPoint1==null){
                boolean ok = mwCollectionPointService.updateById(mwCollectionPoint);
                //TODO 返回false说明什么?
                if(ok) {
                    result.success("修改成功!");
                }
            }else{
                result.error500("操作失败,名称重复!");
            }
 
        }
        
        return result;
    }
    
    /**
      *   通过id删除
     * @return
     */
    @PostMapping(value = "/delete")
    @AutoLog(value = "删除收集点位")
    @ApiOperation(value = "删除收集点位", notes = "删除收集点位", produces = "application/json")
    public Result<MwCollectionPoint> delete(@Validated @RequestBody IdDTO dto) {
 
        Result<MwCollectionPoint> result = new Result<MwCollectionPoint>();
        MwCollectionPoint mwCollectionPoint = mwCollectionPointService.getById(dto.getId());
        if(mwCollectionPoint==null) {
            result.error500("未找到对应实体");
        }else {
            boolean ok = mwCollectionPointService.removeById(dto.getId());
            if(ok) {
                result.success("删除成功!");
            }
        }
        
        return result;
    }
    
    /**
      *  批量删除
     * @param ids
     * @return
     */
    @PostMapping(value = "/deleteBatch")
    @AutoLog(value = "批量删除收集点位")
    @ApiOperation(value = "批量删除收集点位", notes = "批量删除收集点位", produces = "application/json")
    public Result<MwCollectionPoint> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
 
        Result<MwCollectionPoint> result = new Result<MwCollectionPoint>();
        if(ids==null || "".equals(ids.trim())) {
            result.error500("参数不识别!");
        }else {
            this.mwCollectionPointService.removeByIds(Arrays.asList(ids.split(",")));
            result.success("删除成功!");
        }
        return result;
    }
    
    /**
      * 通过id查询
     * @param id
     * @return
     */
    @GetMapping(value = "/queryById")
    @ApiOperation(value = "通过id查询收集点位", notes = "通过id查询收集点位", produces = "application/json")
    public Result<MwCollectionPoint> queryById(@RequestParam(name="id",required=true) String id) {
 
        Result<MwCollectionPoint> result = new Result<MwCollectionPoint>();
        MwCollectionPoint mwCollectionPoint = mwCollectionPointService.getById(id);
        if(mwCollectionPoint==null) {
            result.error500("未找到对应实体");
        }else {
            result.setResult(mwCollectionPoint);
            result.setSuccess(true);
        }
        return result;
    }
     @GetMapping(value = "/listPoint")
     @ApiOperation(value = "收集点位列表", notes = "收集点位列表", produces = "application/json")
     public Result<IPage<MwCollectionPointVO>> listPoint(MwCollectionPointDTO dto, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
 
         //
         IPage<MwCollectionPointVO> pageList = mwCollectionPointService.queryPageCollectList(pageNo, pageSize, dto);
         return Result.ok(pageList);
     }
 
     /*=====医废追溯导出--开始=======*/
     private static Map<String, String> headerMapListPoint = new LinkedHashMap<>();
 
     static {
         headerMapListPoint.put("hospitalName", "机构名称");
         headerMapListPoint.put("name", "点位名称");
         headerMapListPoint.put("nature", "点位性质");
         headerMapListPoint.put("officeNames", "关联科室");
     }
 
     @Data
     private static class MwCollectionPointExportListVO {
 
 
         private String hospitalName="";
 
         private String name="";
 
         private String nature="";
 
         private String officeNames="";
 
     }
 
     @GetMapping("/listExport")
     @OpenApi
     @ApiOperation(value = "收集点位导出", notes = "收集点位导出", produces = "application/json")
     public void listExport(HttpServletResponse response, MwCollectionPointDTO dto) throws IOException {
         List<MwCollectionPointVO> list=mwCollectionPointService.queryPageCollectList( dto);
         List<MwCollectionPointController.MwCollectionPointExportListVO> voList = new ArrayList<>();
         for (MwCollectionPointVO collectRecordVO : list) {
             MwCollectionPointController.MwCollectionPointExportListVO vo=new MwCollectionPointController.MwCollectionPointExportListVO();
             BeanUtils.copyProperties(collectRecordVO, vo);
             //性质(1=院内站点,2=院外站点)
             if (collectRecordVO.getNature().equals(1)) {
                 vo.setNature("院内站点");
             } else if (collectRecordVO.getNature().equals(2)) {
                 vo.setNature("院外站点");
             }
             vo.setOfficeNames(collectRecordVO.getOfficeName().toString());
             voList.add(vo);
         }
 
         ExcelWriter writer = ExcelUtil.getWriter(true);
         writer.renameSheet("收集点位信息");
         writer.setColumnWidth(0, 30);
         writer.setColumnWidth(1, 30);
         writer.setColumnWidth(2, 30);
         writer.setColumnWidth(3, 30);
         writer.setHeaderAlias(headerMapListPoint);
         writer.write(voList);
         //
         String fileName = "收集点位信息";
         response.setContentType("application/octet-stream;charset=utf-8");
         response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
         //response.setContentType("application/octet-stream"); // 响应内容格式
         writer.flush(response.getOutputStream());
         writer.close();
 
     }
}