医院废弃物信息化管理平台
“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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
package cn.besteam.modules.medical.service.impl;
 
import cn.besteam.common.constant.DepartmentEnum;
import cn.besteam.modules.medical.dto.MwServicePeriodDTO;
import cn.besteam.modules.medical.dto.MwServicePeriodEditDTO;
import cn.besteam.modules.medical.dto.RenewOrderRequestVO;
import cn.besteam.modules.medical.dto.RenewOrderResponseVO;
import cn.besteam.modules.medical.entity.MwServicePeriod;
import cn.besteam.modules.medical.entity.MwServicePeriodLog;
import cn.besteam.modules.medical.mapper.MwServicePeriodMapper;
import cn.besteam.modules.medical.service.IMwServicePeriodLogService;
import cn.besteam.modules.medical.service.IMwServicePeriodService;
import cn.besteam.modules.medical.vo.MwServicePeriodListDTO;
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 cn.besteam.modules.system.util.NouNouPayUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
/**
* 服务期限
* @author pzb
* @Date 2022/7/13 20:01
*/
@Service
public class MwServicePeriodServiceImpl extends ServiceImpl<MwServicePeriodMapper, MwServicePeriod> implements IMwServicePeriodService {
 
    @Autowired
    private ISysDictItemService sysDictItemService;
 
    @Autowired
    private ISysDepartmentService departmentService;
 
    @Autowired
    private IMwServicePeriodLogService servicePeriodLogService;
 
    @Autowired
    private ISysDictItemService dictItemService;
 
    @Autowired
    private NouNouPayUtil nouNouPayUtil;
 
 
 
    private List<Integer> getSearchHospitalIdList(Integer hospitalId) {
 
        if (hospitalId == null) {
            return departmentService.listMyHospital(EnvUtils.getUser().getId()).stream().map(SysDepartment::getId).collect(Collectors.toList());
        } else {
            SysDepartment sysDepartment = departmentService.getById(hospitalId);
            if (sysDepartment == null) {
                return new ArrayList<>();
            }
            List<SysDepartment> childrenList = departmentService.list(new QueryWrapper<SysDepartment>().lambda().likeRight(SysDepartment::getTreeCode, sysDepartment.getTreeCode()).eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.HOSPITAL.getType()));
            if (CollectionUtils.isEmpty(childrenList)) {
                return new ArrayList<>();
            }
            return childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList());
        }
    }
 
    /**
     * 获取服务期管理列表
     * @param dto
     * @return
     */
    @Override
    public List<MwServicePeriodListDTO> getServicePeriodList(MwServicePeriodDTO dto) {
        return this.baseMapper.getServicePeriodList(dto);
    }
 
    @Override
    public MwServicePeriodListDTO getServicePeriodInfo(Integer id) {
        MwServicePeriod one = this.getOne(new QueryWrapper<MwServicePeriod>().lambda().eq(MwServicePeriod::getDepartmentId, id)
                .eq(MwServicePeriod::getStatus, 1).eq(MwServicePeriod::getDelFlag, 0).orderByDesc(MwServicePeriod::getCreateTime));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        MwServicePeriodListDTO dto = new MwServicePeriodListDTO();
        SysDepartment byId = departmentService.getById(one.getDepartmentId());
        if(null != one){
            dto.setId(id);
            dto.setExpireDate(sdf.format(byId.getExpireDate()));
            dto.setReminderDays(byId.getReminderDays());
            dto.setServiceCharge(byId.getServiceCharge());
            SysDictItem dictItem = sysDictItemService.getById(byId.getServiceUnit());
            dto.setServiceUnit(dictItem.getItemText());
            dto.setNote(byId.getNote());
        }
        return dto;
    }
 
    @Override
    public List<MwServicePeriodListDTO> getServicePeriodHistoryRecord(Integer id) {
        return this.baseMapper.getServicePeriodHistoryRecord(id);
    }
 
    @Override
    public void editServicePeriod(MwServicePeriodEditDTO dto, Integer userId) {
        String[] split = dto.getIds().split(",");
        for (String s : split) {
            MwServicePeriod one = this.getOne(new QueryWrapper<MwServicePeriod>().lambda().eq(MwServicePeriod::getDepartmentId, s)
                    .eq(MwServicePeriod::getStatus, 1).eq(MwServicePeriod::getDelFlag, 0).orderByDesc(MwServicePeriod::getCreateTime));
            if(null != one){
                one.setStatus(0);
                this.baseMapper.updateById(one);
            }
            MwServicePeriod mwServicePeriod = new MwServicePeriod();
            BeanUtils.copyProperties(dto, mwServicePeriod);
            mwServicePeriod.setDepartmentId(Integer.valueOf(s));
            mwServicePeriod.setPayStatus(1);
            mwServicePeriod.setStatus(1);
            mwServicePeriod.setDelFlag(0);
            mwServicePeriod.setCreateUserId(userId);
            mwServicePeriod.setCreateTime(new Date());
            //支付为0直接修改数据
            SysDepartment department = departmentService.getById(s);
            department.setReminderDays(dto.getReminderDays());
            department.setExpireDate(dto.getExpireDate());
            department.setServiceCharge(dto.getServiceCharge());
            department.setServiceUnit(dto.getServiceUnit());
            department.setNote(dto.getNote());
            departmentService.updateById(department);
 
            //添加操作日志记录
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if(null == one || department.getExpireDate().getTime() != dto.getExpireDate().getTime()){
//                MwServicePeriodLog servicePeriodLog = new MwServicePeriodLog();
//                servicePeriodLog.setServicePeriodId(mwServicePeriod.getId());
//                servicePeriodLog.setServiceType(1);
//                servicePeriodLog.setHistoricalData(null == one ? "" : sdf.format(department.getExpireDate()));
//                servicePeriodLog.setCurrentData(sdf.format(department.getExpireDate()));
//                servicePeriodLog.setCreateTime(new Date());
                servicePeriodLogService.saveLog(Integer.valueOf(s),dto.getServiceCharge(),dto.getExpireDate(),dto.getReminderDays(),dto.getServiceUnit(),dto.getNote(),userId,1);
            }else{
//            if(null == one || department.getServiceCharge() != dto.getServiceCharge()){
//                MwServicePeriodLog servicePeriodLog = new MwServicePeriodLog();
//                servicePeriodLog.setServicePeriodId(mwServicePeriod.getId());
//                servicePeriodLog.setServiceType(2);
//                servicePeriodLog.setHistoricalData(null == one ? "" : department.getServiceCharge().toString());
//                servicePeriodLog.setCurrentData(department.getServiceCharge().toString());
//                servicePeriodLog.setCreateTime(new Date());
//                servicePeriodLogService.saveLog(Integer.valueOf(s),dto.getServiceCharge(),dto.getExpireDate(),dto.getReminderDays(),dto.getServiceUnit(),dto.getNote(),userId,2);
            }
        }
 
    }
 
    @Override
    public void exportServicePeriodList(MwServicePeriodDTO dto, HttpServletResponse response) throws Exception {
        ExcelWriter excelWriter = new ExcelWriter(exportServicePeriodList(dto, "服务期管理"), "服务期管理");
        if (excelWriter != null) {
            response.setContentType("application/octet-stream;charset=utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("服务期管理", "UTF-8") + ".xlsx");
            excelWriter.flush(response.getOutputStream(), true);
            excelWriter.close();
        }
    }
 
 
    private XSSFWorkbook exportServicePeriodList(MwServicePeriodDTO dto, String fileName){
        List<MwServicePeriodListDTO> servicePeriodList = this.baseMapper.getServicePeriodList(dto);
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet(fileName);
        XSSFCellStyle cellStyle = createDefaultCellStyle(workbook);
 
        XSSFRow row = sheet.createRow(0);//表头
        XSSFCell cell = row.createCell(0);
        cell.setCellStyle(cellStyle);
        cell.setCellValue("服务期管理");
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));
 
 
        XSSFRow row1 = sheet.createRow(0);//表头
        XSSFCell cel2 = row1.createCell(0);
        cel2.setCellStyle(cellStyle);
        cel2.setCellValue("所属区域");
 
        XSSFCell cel3 = row1.createCell(1);
        cel3.setCellStyle(cellStyle);
        cel3.setCellValue("医院名称");
 
        XSSFCell cel4 = row1.createCell(2);
        cel4.setCellStyle(cellStyle);
        cel4.setCellValue("到期时间");
 
        XSSFCell cel5 = row1.createCell(3);
        cel5.setCellStyle(cellStyle);
        cel5.setCellValue("是否到期");
 
        XSSFCell cel6 = row1.createCell(4);
        cel6.setCellStyle(cellStyle);
        cel6.setCellValue("即将到期");
 
        XSSFCell cel7 = row1.createCell(5);
        cel7.setCellStyle(cellStyle);
        cel7.setCellValue("即将到期提醒");
 
        XSSFCell cel8 = row1.createCell(6);
        cel8.setCellStyle(cellStyle);
        cel8.setCellValue("服务费");
 
        XSSFCell cel9 = row1.createCell(7);
        cel9.setCellStyle(cellStyle);
        cel9.setCellValue("服务单位");
 
        for (int i = 0; i < servicePeriodList.size(); i++) {
            MwServicePeriodListDTO mwServicePeriodListDTO = servicePeriodList.get(i);
            XSSFRow row21 = sheet.createRow(i);//表头
            row21.setRowStyle(cellStyle);
            XSSFCell cel21 = row21.createCell(0);
            cel21.setCellValue(mwServicePeriodListDTO.getDepartment());
 
            XSSFCell cel22 = row21.createCell(1);
            cel22.setCellValue(mwServicePeriodListDTO.getHospital());
 
            XSSFCell cel23 = row21.createCell(2);
            cel23.setCellValue(null == mwServicePeriodListDTO.getExpireDate() ? "" : mwServicePeriodListDTO.getExpireDate());
 
            XSSFCell cel24 = row21.createCell(3);
            cel24.setCellValue(mwServicePeriodListDTO.getIsExpire() == 1 ? "是" : "否");
 
            XSSFCell cel25 = row21.createCell(4);
            cel25.setCellValue(mwServicePeriodListDTO.getAboutToExpire() == 1 ? "是" : "否");
 
            XSSFCell cel26 = row21.createCell(5);
            cel26.setCellValue(null == mwServicePeriodListDTO.getReminderDays() ? "" : mwServicePeriodListDTO.getReminderDays().toString());
 
            XSSFCell cel27 = row21.createCell(6);
            cel27.setCellValue(null == mwServicePeriodListDTO.getServiceCharge() ? "" : mwServicePeriodListDTO.getServiceCharge().toString());
 
            XSSFCell cel28 = row21.createCell(7);
            cel28.setCellValue(mwServicePeriodListDTO.getServiceUnit());
        }
        return workbook;
 
 
    }
 
 
    private XSSFCellStyle createDefaultCellStyle(XSSFWorkbook workbook) {
 
        XSSFCellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        XSSFFont font = workbook.createFont();
        font.setFontName("宋体");
        font.setFontHeightInPoints((short) 12);
        cellStyle.setFont(font);
        return cellStyle;
    }
 
    @Override
    public IPage<RenewOrderResponseVO> getRenewOrderList(RenewOrderRequestVO vo, Integer pageNo, Integer pageSize) {
        pageNo = vo.getPageNo();
        pageSize = vo.getPageSize();
        vo.setHospitalIdList(getSearchHospitalIdList(vo.getDepartmentId()));
        Page<RenewOrderResponseVO> pageParam = new Page<>(pageNo, pageSize);
        IPage<RenewOrderResponseVO> renewOrderList = this.baseMapper.getRenewOrderList(pageParam, vo);
        return renewOrderList;
    }
 
    @Override
    public RenewOrderResponseVO getRenewOrderOne(Integer id) {
        return this.baseMapper.getRenewOrderOne(id);
    }
 
    @Override
    public void exportRenewOrder(RenewOrderRequestVO vo, HttpServletResponse response) throws Exception {
        ExcelWriter excelWriter = new ExcelWriter(exportRenewOrder(vo, "续费订单"), "续费订单");
        if (excelWriter != null) {
            response.setContentType("application/octet-stream;charset=utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("续费订单", "UTF-8") + ".xlsx");
            excelWriter.flush(response.getOutputStream(), true);
            excelWriter.close();
        }
    }
 
 
    private XSSFWorkbook exportRenewOrder(RenewOrderRequestVO vo, String fileName){
        Page<RenewOrderResponseVO> pageParam = new Page<>(0, 100000000);
        IPage<RenewOrderResponseVO> renewOrderList = this.baseMapper.getRenewOrderList(pageParam, vo);
        List<RenewOrderResponseVO> records = renewOrderList.getRecords();
 
 
 
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet(fileName);
        XSSFCellStyle cellStyle = createDefaultCellStyle(workbook);
 
        XSSFRow row = sheet.createRow(0);//表头
        XSSFCell cell = row.createCell(0);
        cell.setCellStyle(cellStyle);
        cell.setCellValue("续费订单");
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 10));
 
 
        XSSFRow row1 = sheet.createRow(1);//表头
        XSSFCell cel2 = row1.createCell(0);
        cel2.setCellStyle(cellStyle);
        cel2.setCellValue("所属区域");
 
        XSSFCell cel3 = row1.createCell(1);
        cel3.setCellStyle(cellStyle);
        cel3.setCellValue("医院名称");
 
        XSSFCell cel4 = row1.createCell(2);
        cel4.setCellStyle(cellStyle);
        cel4.setCellValue("订单编号");
 
        XSSFCell cel5 = row1.createCell(3);
        cel5.setCellStyle(cellStyle);
        cel5.setCellValue("订单时间");
 
        XSSFCell cel6 = row1.createCell(4);
        cel6.setCellStyle(cellStyle);
        cel6.setCellValue("订单状态");
 
        XSSFCell cel7 = row1.createCell(5);
        cel7.setCellStyle(cellStyle);
        cel7.setCellValue("订单金额");
 
        XSSFCell cel8 = row1.createCell(6);
        cel8.setCellStyle(cellStyle);
        cel8.setCellValue("支付时间");
 
        XSSFCell cel9 = row1.createCell(7);
        cel9.setCellStyle(cellStyle);
        cel9.setCellValue("支付方式");
 
        XSSFCell cel10 = row1.createCell(8);
        cel10.setCellStyle(cellStyle);
        cel10.setCellValue("支付金额");
 
        XSSFCell cel11 = row1.createCell(9);
        cel11.setCellStyle(cellStyle);
        cel11.setCellValue("微信/支付宝订单号");
 
        XSSFCell cel12 = row1.createCell(10);
        cel12.setCellStyle(cellStyle);
        cel12.setCellValue("开票状态");
 
        for (int i = 2; i < records.size(); i++) {
            RenewOrderResponseVO renewOrderResponseVO = records.get(i);
            XSSFRow row21 = sheet.createRow(i);//表头
            row21.setRowStyle(cellStyle);
            XSSFCell cel21 = row21.createCell(0);
            cel21.setCellValue(renewOrderResponseVO.getDepartmentName());
 
            XSSFCell cel22 = row21.createCell(1);
            cel22.setCellValue(renewOrderResponseVO.getHospitalName());
 
            XSSFCell cel23 = row21.createCell(2);
            cel23.setCellValue(renewOrderResponseVO.getCode());
 
            XSSFCell cel24 = row21.createCell(3);
            cel24.setCellValue(renewOrderResponseVO.getOrderTime());
 
            XSSFCell cel25 = row21.createCell(4);
            switch (renewOrderResponseVO.getPayStatus()){
                case 0:
                    cel25.setCellValue("待支付");
                    break;
                case 1:
                    cel25.setCellValue("已支付");
                    break;
                case 2:
                    cel25.setCellValue("支付失败");
                    break;
                case 3:
                    cel25.setCellValue("关闭");
                    break;
                case 4:
                    cel25.setCellValue("退款中");
                    break;
                case 5:
                    cel25.setCellValue("退款成功");
                    break;
                case 6:
                    cel25.setCellValue("退款失败");
                    break;
            }
 
            XSSFCell cel26 = row21.createCell(5);
            cel26.setCellValue(renewOrderResponseVO.getServiceCharge());
 
            XSSFCell cel27 = row21.createCell(6);
            cel27.setCellValue(renewOrderResponseVO.getPayTime());
 
            XSSFCell cel28 = row21.createCell(7);
            cel28.setCellValue(renewOrderResponseVO.getPayType()==null?"":renewOrderResponseVO.getPayType() == 1 ? "微信" : "支付宝");
 
            XSSFCell cel29 = row21.createCell(8);
            cel29.setCellValue(renewOrderResponseVO.getPayMoney()==null?0:renewOrderResponseVO.getPayMoney());
 
            XSSFCell cel30 = row21.createCell(9);
            cel30.setCellValue(renewOrderResponseVO.getOrderNumber());
 
            XSSFCell cel31 = row21.createCell(10);
            if(renewOrderResponseVO.getIsInvoiced()!=null){
                switch (renewOrderResponseVO.getIsInvoiced()){
                    case 0:
                        cel31.setCellValue("未开票");
                        break;
                    case 1:
                        cel31.setCellValue("已开票");
                        break;
                    case 2:
                        cel31.setCellValue("开票失败");
                        break;
                    case 3:
                        cel31.setCellValue("正在开票");
                        break;
                }
            }else{
                cel31.setCellValue("");
            }
 
 
        }
        return workbook;
    }
 
    @Override
    public String getBillingAddress(Integer id) {
        MwServicePeriod servicePeriod = this.getById(id);
        SysDepartment department = departmentService.getById(servicePeriod.getDepartmentId());
        SysDictItem dictItem = dictItemService.getById(department.getBillingCompany());
        String invoiceLinks = nouNouPayUtil.getInvoiceLinks("", servicePeriod.getCode(), dictItem.getItemValue());
        return invoiceLinks;
    }
}