mitao
2025-04-04 d89a42213b4a32535e93185dedf41fe7a7fc1940
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
package com.sinata.system.service.impl;
 
import cn.idev.excel.FastExcel;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sinata.common.entity.PageDTO;
import com.sinata.common.exception.ServiceException;
import com.sinata.common.utils.StringUtils;
import com.sinata.system.config.AutoColumnWidthEntityStrategy;
import com.sinata.system.domain.MedicalWasteStaticsVO;
import com.sinata.system.domain.MwCollectRecord;
import com.sinata.system.domain.dto.CollectCarTotalUpDto;
import com.sinata.system.domain.dto.CollectDto;
import com.sinata.system.domain.dto.CollectTotalUpDto;
import com.sinata.system.domain.dto.MwCollectRecordDTO;
import com.sinata.system.domain.query.DisposalReportQuery;
import com.sinata.system.domain.query.MwCollectRecordQuery;
import com.sinata.system.domain.vo.DepartmentTagInfoVO;
import com.sinata.system.domain.vo.MedicalWasteProcessVO;
import com.sinata.system.domain.vo.MwCollectRecordVO;
import com.sinata.system.domain.vo.MwCollectRecordWarningVO;
import com.sinata.system.enums.MedicalWasteStatusEnum;
import com.sinata.system.mapper.MwCollectRecordMapper;
import com.sinata.system.service.MwCollectRecordService;
import com.sinata.system.service.SysDepartmentService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.util.List;
import java.util.Objects;
 
/**
 * <p>
 * 暂存间入库记录 服务实现类
 * </p>
 *
 * @author mitao
 * @since 2024-12-02
 */
@Service
@RequiredArgsConstructor
public class MwCollectRecordServiceImpl extends ServiceImpl<MwCollectRecordMapper, MwCollectRecord> implements MwCollectRecordService {
    private final SysDepartmentService sysDepartmentService;
 
    /**
     * 医废追溯分页列表
     *
     * @param query
     * @return
     */
    @Override
    public PageDTO<MwCollectRecordVO> pageList(MwCollectRecordQuery query) {
        String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId());
        if (StringUtils.isBlank(treeCode)) {
            return PageDTO.empty(0L, 0L);
        }
        Page<MwCollectRecordVO> page = baseMapper.pageList(new Page<>(query.getPageCurr(), query.getPageSize()), query, treeCode);
        return PageDTO.of(page);
    }
 
    /**
     * 医废追溯详情
     *
     * @param id
     * @return
     */
    @Override
    public MwCollectRecordVO detail(Long id) {
        return baseMapper.detail(id);
    }
 
    /**
     * 编辑
     *
     * @param dto
     */
    @Override
    public void edit(MwCollectRecordDTO dto) {
        MwCollectRecord collectRecord = getById(dto.getId());
        if (Objects.nonNull(collectRecord)) {
            collectRecord.setWeight(dto.getWeight());
            updateById(collectRecord);
        }
    }
 
    @Override
    public List<CollectDto> getGroup(String boxNumber,Long departmentId) {
        return this.baseMapper.getGroup(boxNumber,departmentId);
    }
    @Override
    public List<CollectDto> getGroupWithStatus(String boxNumber,Long departmentId,Integer status) {
        return this.baseMapper.getGroupWithStatus(boxNumber,departmentId,status);
    }
 
    @Override
    public List<CollectDto> getGroup1(String boxNumber,Long departmentId) {
        return this.baseMapper.getGroup1(boxNumber,departmentId);
    }
    @Override
    public List<CollectDto> getGroup2(String boxNumber,Long departmentId) {
        return this.baseMapper.getGroup2(boxNumber,departmentId);
    }
    @Override
    public List<CollectDto> getGroup3(String boxNumber,Long departmentId,Long carId) {
        return this.baseMapper.getGroup3(boxNumber,departmentId,carId);
    }
    /**
     * 流转过程
     *
     * @param id
     * @return
     */
    @Override
    public MedicalWasteProcessVO getProcess(Long id) {
        return baseMapper.getProcess(id);
    }
 
    @Override
    public void export(MwCollectRecordQuery query, HttpServletResponse response) throws IOException {
        String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId());
        if (StringUtils.isBlank(treeCode)) {
            return;
        }
        List<MwCollectRecordVO> vo = baseMapper.getExportList(query, treeCode);
        // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
        String fileName = URLEncoder.encode("医废收集记录", "UTF-8").replaceAll("\\+", "%20");
        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
        FastExcel.write(response.getOutputStream(), MwCollectRecordVO.class)
                .registerWriteHandler(new AutoColumnWidthEntityStrategy())
                .sheet("医废追溯").doWrite(vo);
    }
 
    /**
     * 监管报表医疗废物产生列表
     *
     * @param query
     * @return
     */
    @Override
    public List<MwCollectRecordVO> getRegulationReportList(DisposalReportQuery query) {
        String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId());
        return baseMapper.getRegulationReportList(query, treeCode);
    }
 
    @Override
    public List<CollectTotalUpDto> collectTotal(LocalDate date,Long departmentId) {
        return baseMapper.collectTotal(date,departmentId);
    }
    @Override
    public List<CollectTotalUpDto> collectTotal3(Long departmentId) {
        return baseMapper.collectTotal3(departmentId);
    }
    @Override
    public List<CollectTotalUpDto> collectTotal1(LocalDate date,Long checkOutUserId,Long id ) {
        return baseMapper.collectTotal1(date,checkOutUserId,id);
    }
 
    @Override
    public List<CollectCarTotalUpDto> carGroup(Long carId,String name) {
        return this.baseMapper.carGroup(carId,name);
    }
 
    /**
     * 查询日产废记录
     *
     * @return
     */
    @Override
    public List<MwCollectRecordWarningVO> queryListByDay() {
        return baseMapper.queryListTimeType(1);
    }
 
    /**
     * 查询月产废记录
     *
     * @return
     */
    @Override
    public List<MwCollectRecordWarningVO> queryListByMonth() {
        return baseMapper.queryListTimeType(2);
    }
 
    /**
     * 医疗机构存储量预警
     *
     * @return
     */
    @Override
    public List<MwCollectRecordWarningVO> queryListGroupByDepartment() {
        return baseMapper.queryListGroupByDepartment();
    }
 
    /**
     * 预警数据统计
     *
     * @param id
     * @return
     */
    @Override
    public MedicalWasteStaticsVO queryMedicalWasteStatics(String treeCode) {
        return baseMapper.queryMedicalWasteStatics(treeCode);
    }
 
    /**
     * 获取大屏医疗机构标签信息
     *
     * @param id
     * @return
     */
    @Override
    public DepartmentTagInfoVO getTagInfo(Long id) {
        return baseMapper.getTagInfo(id);
    }
 
    /**
     * 删除医废
     *
     * @param id
     */
    @Override
    public void delete(Long id) {
        MwCollectRecord collectRecord = getById(id);
        if (Objects.nonNull(collectRecord)) {
            if (!collectRecord.getStatus().equals(MedicalWasteStatusEnum.TEMPORARILY_STORED.getCode())) {
                throw new ServiceException("该医废已被转运,不能删除");
            }
            removeById(id);
        }
    }
}