医院废弃物信息化管理平台
“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
package cn.besteam.modules.medical.service.impl;
 
import cn.besteam.common.constant.DepartmentEnum;
import cn.besteam.common.constant.ErrorCode;
import cn.besteam.common.exception.BusinessException;
import cn.besteam.modules.medical.dto.MwTransitConfigListDTO;
import cn.besteam.modules.medical.dto.MwTransitConfigDTO;
import cn.besteam.modules.medical.mapper.MwCollectRecordMapper;
import cn.besteam.modules.medical.vo.MwTransitConfigVO;
import cn.besteam.modules.medical.entity.MwTransitConfig;
import cn.besteam.modules.medical.mapper.MwTransitConfigMapper;
import cn.besteam.modules.medical.service.IMwTransitConfigService;
import cn.besteam.modules.medical.vo.MwTransitConfigSelectVO;
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 com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Description: 出库-运输配置
 * @author: besteam
 * @date: 2020-04-25
 * @version: V1.0
 */
@Service
public class MwTransitConfigServiceImpl extends ServiceImpl<MwTransitConfigMapper, MwTransitConfig> implements IMwTransitConfigService {
 
    @Autowired
    private ISysDictItemService sysDictItemService;
 
    @Autowired
    private ISysDepartmentService sysDepartmentService;
 
 
    @Autowired
    private MwCollectRecordMapper mwCollectRecordMapper;
 
    private List<Integer> getSearchHospitalIdList(Integer hospitalId) {
 
        if (hospitalId == null) {
            return sysDepartmentService.listMyHospital(EnvUtils.getUser().getId()).stream().map(SysDepartment::getId).collect(Collectors.toList());
        } else {
            SysDepartment sysDepartment = sysDepartmentService.getById(hospitalId);
            if (sysDepartment == null) {
                return new ArrayList<>();
            }
            List<SysDepartment> childrenList = sysDepartmentService.list(new QueryWrapper<SysDepartment>().lambda().likeRight(SysDepartment::getTreeCode, sysDepartment.getTreeCode()).eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.HOSPITAL.getType()));
            if (org.apache.commons.collections.CollectionUtils.isEmpty(childrenList)) {
                return new ArrayList<>();
            }
            return childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList());
        }
    }
 
    /**
     * 填充用户列表中的区域、医院、部门、科室字段
     *
     * @param vo
     */
    private void fillDepartmentPath(Map<Integer, SysDepartment> sysDepartmentMap, MwTransitConfigVO vo, String separateChar) {
 
        if (StringUtils.isEmpty(separateChar)) {
            separateChar = "/";
        }
        if (vo.getDepartmentId() != null) {
            SysDepartment sysDepartment = sysDepartmentMap.get(vo.getDepartmentId());
            if (sysDepartment == null) {
                sysDepartment = sysDepartmentService.getById(vo.getDepartmentId());
                if (sysDepartment != null) {
                    sysDepartmentMap.put(sysDepartment.getId(), sysDepartment);
                }
            }
            if (sysDepartment != null && sysDepartment.getId().equals(-1)) {
                vo.setArea(sysDepartment.getDepartName());
                return;
            }
            while (sysDepartment != null && !sysDepartment.getId().equals(-1)) {
                //科室
                if (sysDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.OFFICE.getType())) {
                    vo.setOffice(sysDepartment.getDepartName());
                }
                //部门
                else if (sysDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.DEPARTMENT.getType())) {
                    if (StringUtils.isNotEmpty(vo.getDepartment())) {
                        vo.setDepartment(sysDepartment.getDepartName() + separateChar + vo.getDepartment());
                    } else {
                        vo.setDepartment(sysDepartment.getDepartName());
                    }
                }
                //区域
                else {
                    if (StringUtils.isNotEmpty(vo.getArea())) {
                        vo.setArea(sysDepartment.getDepartName() + separateChar + vo.getArea());
                    } else {
                        vo.setArea(sysDepartment.getDepartName());
                    }
                }
                if (sysDepartmentMap.get(sysDepartment.getParentId()) == null) {
                    sysDepartment = sysDepartmentService.getById(sysDepartment.getParentId());
                    if (sysDepartment != null) {
                        sysDepartmentMap.put(sysDepartment.getId(), sysDepartment);
                    }
                } else {
                    sysDepartment = sysDepartmentMap.get(sysDepartment.getParentId());
                }
            }
        }
    }
    /**
     * 获取出库-运输配置数据列表
     *
     * @param dto
     * @return
     */
    @Override
    public IPage<MwTransitConfigVO> queryPageList(MwTransitConfigListDTO dto) {
 
        IPage<MwTransitConfigVO> page = new Page<>(dto.getPageNo(), dto.getPageSize());
        List<Integer> hospitalIdList = getSearchHospitalIdList(dto.getHospitalId());
        if (org.apache.commons.collections.CollectionUtils.isEmpty(hospitalIdList)) {
            return page;
        }
        dto.setHospitalIdList(hospitalIdList);
        SysDepartment sysDepartment = null;
        if (dto.getHospitalId() == null) {
            sysDepartment = sysDepartmentService.getMyDepartment(EnvUtils.getUser().getId());
            if (sysDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.DEPARTMENT.getType()) || sysDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.OFFICE.getType())) {
                sysDepartment = sysDepartmentService.getHospital(sysDepartment.getParentId());
            }
        } else {
            sysDepartment = sysDepartmentService.getById(dto.getHospitalId());
        }
        List<SysDepartment> sysDepartmentList = sysDepartmentService.list(new QueryWrapper<SysDepartment>().lambda().likeRight(SysDepartment::getTreeCode, sysDepartment.getTreeCode()));
        Map<Integer, SysDepartment> sysDepartmentMap = sysDepartmentList.stream().collect(Collectors.toMap(SysDepartment::getId, e -> e));
        //dto.setHospitalIdList(sysDepartmentService.listMyHospital(EnvUtils.getUser().getId()).stream().map(SysDepartment::getId).collect(Collectors.toList()));
        List<MwTransitConfigVO> mwTransitConfigList = baseMapper.getMwTransitConfigList(page, dto);
        if (CollectionUtils.isNotEmpty(mwTransitConfigList)) {
            mwTransitConfigList.stream().map(mwTransitConfig -> {
                Set<String> set = sysDictItemService.listByIds(Arrays.asList(mwTransitConfig.getWasteType().split(","))).stream().map(SysDictItem::getItemText).collect(Collectors.toSet());
                mwTransitConfig.setWasteType(StringUtils.join(set, "/"));
                fillDepartmentPath(sysDepartmentMap, mwTransitConfig, "/");
                mwTransitConfig.setHospitalIdList(sysDepartmentService.getParentIdList(mwTransitConfig.getHospitalId()));
                return mwTransitConfig;
            }).collect(Collectors.toSet());
        }
        page.setRecords(mwTransitConfigList);
        return page;
    }
 
    /**
     * 获取出库-运输配置新增/编辑
     *
     * @param dto
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveOrUpdate(MwTransitConfigDTO dto) {
 
        if (dto.getId() == null || dto.getId() <= 0) {
            MwTransitConfig mwTransitConfig = new MwTransitConfig();
            BeanUtils.copyProperties(dto, mwTransitConfig);
            save(mwTransitConfig);
        } else {
            MwTransitConfig mwTransitConfig = getById(dto.getId());
            if (mwTransitConfig == null) {
                throw new BusinessException(ErrorCode.ERR_500, "运输配置不存在");
            }
            BeanUtils.copyProperties(dto, mwTransitConfig);
            updateById(mwTransitConfig);
        }
    }
 
    @Override
    public List<MwTransitConfigSelectVO> listSelect(Integer parentId, Integer wasteType) {
 
        List<MwTransitConfig> list = new ArrayList<>();
        SysDepartment myDepartment = sysDepartmentService.getMyDepartment(EnvUtils.getUser().getId());
        if (parentId != null) {
            myDepartment = sysDepartmentService.getById(parentId);
        }
        if (myDepartment != null) {
            if (myDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.DEPARTMENT.getType()) || myDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.OFFICE.getType())) {
                SysDepartment hospital = sysDepartmentService.getHospital(myDepartment.getParentId());
                List<SysDepartment> childrenList = sysDepartmentService.list(new QueryWrapper<SysDepartment>().lambda().likeRight(SysDepartment::getTreeCode, hospital.getTreeCode()).eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.HOSPITAL.getType()));
                list = list(new QueryWrapper<MwTransitConfig>().lambda().in(MwTransitConfig::getHospitalId, childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList())));
            } else {
                List<SysDepartment> childrenList = sysDepartmentService.list(new QueryWrapper<SysDepartment>().lambda().likeRight(SysDepartment::getTreeCode, myDepartment.getTreeCode()).eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.HOSPITAL.getType()));
                list = list(new QueryWrapper<MwTransitConfig>().lambda().in(MwTransitConfig::getHospitalId, childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList())));
            }
        }
        List<MwTransitConfigSelectVO> voList = new ArrayList<>();
        for (MwTransitConfig mwTransitConfig : list) {
            if (wasteType != null) {
                String[] wasteTypeArray = mwTransitConfig.getWasteType().split(",");
                for (String s : wasteTypeArray) {
                    if (Integer.valueOf(s).equals(wasteType)) {
                        MwTransitConfigSelectVO vo = new MwTransitConfigSelectVO();
                        BeanUtils.copyProperties(mwTransitConfig, vo);
                        voList.add(vo);
                        break;
                    }
                }
            } else {
                MwTransitConfigSelectVO vo = new MwTransitConfigSelectVO();
                BeanUtils.copyProperties(mwTransitConfig, vo);
                voList.add(vo);
            }
        }
        return voList;
    }
 
    @Override
    public List<MwTransitConfigSelectVO> listSelectX(Integer parentId, Integer wasteType) {
 
        List<MwTransitConfigSelectVO> list = new ArrayList<>();
        SysDepartment myDepartment = sysDepartmentService.getMyDepartment(EnvUtils.getUser().getId());
        if (parentId != null) {
            myDepartment = sysDepartmentService.getById(parentId);
        }
        if (myDepartment != null) {
            if (myDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.DEPARTMENT.getType()) || myDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.OFFICE.getType())) {
                myDepartment = sysDepartmentService.getHospital(myDepartment.getParentId());
            }
            List<SysDepartment> childrenList = sysDepartmentService.list(new QueryWrapper<SysDepartment>().lambda().likeRight(SysDepartment::getTreeCode, myDepartment.getTreeCode()).eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.HOSPITAL.getType()));
            list = mwCollectRecordMapper.getTransitInfoList(childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList()));
        }
        List<MwTransitConfigSelectVO> voList = new ArrayList<>();
        for (MwTransitConfigSelectVO mwTransitConfigSelectVO : list) {
            Boolean ok=true;
            for(MwTransitConfigSelectVO vo:voList){
                if(vo.getTransitCompany().trim().equals(mwTransitConfigSelectVO.getTransitCompany().trim())){
                    ok=false;
                }
            }
            if(ok){
                MwTransitConfigSelectVO vo = new MwTransitConfigSelectVO();
                BeanUtils.copyProperties(mwTransitConfigSelectVO, vo);
                voList.add(vo);
            }
        }
        return voList;
    }
 
 
    @Override
    public List<MwTransitConfigSelectVO> listAppSelect(Integer parentId) {
 
        List<MwTransitConfig> list = new ArrayList<>();
        SysDepartment myDepartment = sysDepartmentService.getById(parentId);
        if (myDepartment != null) {
            if (myDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.DEPARTMENT.getType()) || myDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.OFFICE.getType())) {
                SysDepartment hospital = sysDepartmentService.getHospital(myDepartment.getParentId());
                list = list(new QueryWrapper<MwTransitConfig>().lambda().eq(MwTransitConfig::getHospitalId, hospital.getId()));
            } else if (myDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())) {
                list = list(new QueryWrapper<MwTransitConfig>().lambda().eq(MwTransitConfig::getHospitalId, myDepartment.getId()));
            }
        }
        List<MwTransitConfigSelectVO> voList = new ArrayList<>();
        for (MwTransitConfig mwTransitConfig : list) {
            MwTransitConfigSelectVO vo = new MwTransitConfigSelectVO();
            BeanUtils.copyProperties(mwTransitConfig, vo);
            voList.add(vo);
        }
        return voList;
    }
 
}