16639036659
2024-05-14 964dd88319269c16d4ebb99007a954b51e625ef2
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
package com.gkhy.labRiskManage.domain.basic.service.impl;
 
import com.gkhy.labRiskManage.application.basic.dto.bo.BasicExperimentDeviceAppInsertBO;
import com.gkhy.labRiskManage.application.basic.dto.bo.BasicExperimentDeviceAppQueryBO;
import com.gkhy.labRiskManage.application.basic.dto.bo.BasicExperimentDeviceAppUpdateBO;
import com.gkhy.labRiskManage.application.basic.dto.dto.BasicExperimentDeviceAppListDTO;
import com.gkhy.labRiskManage.commons.domain.SearchResult;
import com.gkhy.labRiskManage.commons.enums.ResultCode;
import com.gkhy.labRiskManage.commons.enums.StatusEnum;
import com.gkhy.labRiskManage.commons.enums.UserTagEnum;
import com.gkhy.labRiskManage.commons.exception.BusinessException;
import com.gkhy.labRiskManage.commons.utils.BeanCopyUtils;
import com.gkhy.labRiskManage.domain.account.model.dto.UserInfoDomainDTO;
import com.gkhy.labRiskManage.domain.account.service.UserDomainService;
import com.gkhy.labRiskManage.domain.basic.converter.ToBasicDeviceInfoConverter;
import com.gkhy.labRiskManage.domain.basic.converter.ToQueryDeviceBOConverter;
import com.gkhy.labRiskManage.domain.basic.converter.ToUpdateDeviceBOConverter;
import com.gkhy.labRiskManage.domain.basic.entity.BasicExperimentDevice;
import com.gkhy.labRiskManage.domain.basic.entity.BasicExperimentDeviceType;
import com.gkhy.labRiskManage.domain.basic.model.bo.DeviceInsertBO;
import com.gkhy.labRiskManage.domain.basic.model.bo.DeviceQueryBO;
import com.gkhy.labRiskManage.domain.basic.model.bo.DeviceUpdateBO;
import com.gkhy.labRiskManage.domain.basic.model.dto.*;
import com.gkhy.labRiskManage.domain.basic.repository.jpa.BasicExperimentDeviceRepository;
import com.gkhy.labRiskManage.domain.basic.service.BasicExperimentDeviceService;
import com.gkhy.labRiskManage.domain.basic.service.BasicExperimentDeviceTypeService;
import com.gkhy.labRiskManage.domain.riskReport.utils.GetRoleTagUtils;
import com.gkhy.labRiskManage.domain.riskReport.utils.SearchAuthUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
 
 
/**
 * 基础仪器设备表
 */
@Service
public class BasicExperimentDeviceServiceImpl implements BasicExperimentDeviceService {
 
    @Autowired
    private BasicExperimentDeviceRepository basicExperimentDeviceRepository;
    @Autowired
    private UserDomainService userDomainService;
    @Autowired
    private BasicExperimentDeviceTypeService deviceTypeService;
 
 
    /**
     * 基础仪器设备表 - 新增
     * */
    @Override
    public DeviceInsertDTO insertBasicExperimentDevice(Long currentUserId, BasicExperimentDeviceAppInsertBO basicExperimentDeviceAppInsertBO) {
 
        if (currentUserId < 0){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆");
        }
        //接收、转换参数
        ToBasicDeviceInfoConverter deviceParam =  new ToBasicDeviceInfoConverter();
        DeviceInsertBO deviceInsertBO = deviceParam.toBasicDeviceInfoConvert(basicExperimentDeviceAppInsertBO);
 
        //参数校验
        if (ObjectUtils.isEmpty(deviceInsertBO.getDeviceCode())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备编码不能为空");
        }
        BasicExperimentDevice deviceByCode = basicExperimentDeviceRepository.getDeviceByCode(deviceInsertBO.getDeviceCode());
//        if (!ObjectUtils.isEmpty(deviceByCode)){
//            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"设备编码已存在");
//        }
        if (ObjectUtils.isEmpty(deviceInsertBO.getDeviceName())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备名称不能为空");
        }
        BasicExperimentDevice deviceByName = basicExperimentDeviceRepository.getDeviceByName(deviceInsertBO.getDeviceName());
//        if (!ObjectUtils.isEmpty(deviceByName)){
//            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"设备名称已存在");
//        }
        if (ObjectUtils.isEmpty(deviceInsertBO.getSpecialDevice())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备类型不能为空");
        }
        if (ObjectUtils.isEmpty(deviceInsertBO.getDevicePower())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备功率不能为空");
        }
        if (ObjectUtils.isEmpty(deviceInsertBO.getDeviceUnit())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备计量单位不能为空");
        }
        if (ObjectUtils.isEmpty(deviceInsertBO.getDeviceTypeId())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备类型不能为空");
        }
        BasicExperimentDeviceType deviceTypeById = deviceTypeService.getDeviceTypeById(deviceInsertBO.getDeviceTypeId());
        if (ObjectUtils.isEmpty(deviceTypeById)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"找不到该类型的设备,请检查输入是否正确,或者先添加设备类型");
        }
        if (ObjectUtils.isEmpty(deviceInsertBO.getDeviceDesc())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备型号不能为空");
        }
        if (ObjectUtils.isEmpty(deviceInsertBO.getDeviceStatus())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备状态不能为空");
        }
        if (ObjectUtils.isEmpty(deviceInsertBO.getBuyTime())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备购买时间不能为空");
        }
        if (ObjectUtils.isEmpty(deviceInsertBO.getAdjustTime())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备校准时间不能为空");
        }
        //获取需要的参数
        LocalDateTime date = LocalDateTime.now();
        if (date.isBefore(deviceInsertBO.getBuyTime())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备购买时间不能在当前时间之后");
        }
        if (date.isBefore(deviceInsertBO.getAdjustTime())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备校准时间不能在当前时间之后");
        }
        if (deviceInsertBO.getAdjustTime().isBefore(deviceInsertBO.getBuyTime())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备校准时间不能在购买时间之后");
        }
        //获取需要的参数
        BasicExperimentDevice device = BeanCopyUtils.copyBean(deviceInsertBO, BasicExperimentDevice.class);
        UserInfoDomainDTO userInfoById = userDomainService.getUserInfoById(currentUserId);
 
 
        device.setCreateTime(date);
        device.setUpdateTime(date);
        device.setCreateByUserId(userInfoById.getId());
        device.setUpdateByUserId(userInfoById.getId());
        device.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
        device.setDeviceType(deviceTypeById.getDeviceType());
 
        BasicExperimentDevice saveResult = basicExperimentDeviceRepository.save(device);
 
        DeviceInsertDTO deviceInsertDTO = BeanCopyUtils.copyBean(saveResult, DeviceInsertDTO.class);
 
        return deviceInsertDTO;
    }
 
    /**
     * 基础仪器设备表 - 分页查询
     * */
    @Override
    public SearchResult<DeviceQueryDTO> getBasicExperimentDevicePage(Long currentUserId, BasicExperimentDeviceAppQueryBO deviceQueryBO) {
 
        //校验参数
        if (ObjectUtils.isEmpty(deviceQueryBO.getPageSize())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"分页信息不能为空");
        }
        if (ObjectUtils.isEmpty(deviceQueryBO.getPageIndex())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"分页信息不能为空");
        }
        if (deviceQueryBO.getDeviceCode() == ""){
            deviceQueryBO.setDeviceCode(null);
        }
        if (deviceQueryBO.getDevicePower()  == ""){
            deviceQueryBO.setDevicePower(null);
        }
        if (deviceQueryBO.getDeviceName()  == ""){
            deviceQueryBO.setDeviceName(null);
        }
 
        ToQueryDeviceBOConverter toQueryDeviceBOConverter = new ToQueryDeviceBOConverter();
        DeviceQueryBO queryPageParam = toQueryDeviceBOConverter.ToQueryDeviceDTOConverter(deviceQueryBO);
 
        SearchResult searchResult = new SearchResult<>();
 
        searchResult.setPageIndex(queryPageParam.getPageIndex());
        searchResult.setPageSize(queryPageParam.getPageSize());
 
        UserInfoDomainDTO user = userDomainService.getUserById(currentUserId);
        int roleTag = GetRoleTagUtils.GetRoleTagUtils(user);
        //组装查询条件
        Specification<BasicExperimentDevice> specification = new Specification<BasicExperimentDevice>() {
            @Override
            public Predicate toPredicate(Root<BasicExperimentDevice> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
                List<Predicate> predicateList = new ArrayList<>();
                if (deviceQueryBO.getDeviceCode() != null && !deviceQueryBO.getDeviceCode().equals("")){
                    predicateList.add(criteriaBuilder.equal(root.get("deviceCode"), deviceQueryBO.getDeviceCode()));
                }
                if (deviceQueryBO.getDeviceName() != null && !deviceQueryBO.getDeviceName().equals("")){
                    predicateList.add(criteriaBuilder.equal(root.get("deviceName"), deviceQueryBO.getDeviceName()));
                }
                if (deviceQueryBO.getDevicePower() != null && !deviceQueryBO.getDevicePower().equals("")){
                    predicateList.add(criteriaBuilder.equal(root.get("devicePower"), deviceQueryBO.getDevicePower()));
                }
                if (deviceQueryBO.getSpecialDevice() != null && !deviceQueryBO.getSpecialDevice().equals("")){
                    predicateList.add(criteriaBuilder.equal(root.get("specialDevice"), deviceQueryBO.getSpecialDevice()));
                }
                if (SearchAuthUtils.basicSearchAuth() == 1){
                    if (roleTag == UserTagEnum.USER_TAG_0.getCode()){
                        predicateList.add(criteriaBuilder.equal(root.get("createByUserId"), currentUserId));
                    }
                }
                predicateList.add(criteriaBuilder.equal(root.get("deleteStatus"),StatusEnum.DELETE_NOT.getCode()));
                //返回组装的条件
                return criteriaBuilder.and(predicateList.toArray(predicateList.toArray(new Predicate[0])));
            }
        };
 
        PageRequest page = PageRequest.of(queryPageParam.getPageIndex() - 1, queryPageParam.getPageSize(), Sort.Direction.DESC, "updateTime");
 
        Page<BasicExperimentDevice> pageResult = basicExperimentDeviceRepository.findAll(specification, page);
        List<DeviceQueryDTO> deviceQueryDTO = BeanCopyUtils.copyBeanList(pageResult.getContent(), DeviceQueryDTO.class);
 
        List<UserInfoDomainDTO> userList = userDomainService.getUserList();
        for (DeviceQueryDTO queryDTO : deviceQueryDTO) {
            for (UserInfoDomainDTO userInfo : userList) {
                 if (userInfo.getId() == queryDTO.getCreateByUserId()){
                     queryDTO.setCreateByUserName(userInfo.getRealName());
                 }
                 if (userInfo.getId() == queryDTO.getUpdateByUserId()){
                     queryDTO.setUpdateByUserName(userInfo.getRealName());
                 }
            }
        }
 
 
        searchResult.setTotal(pageResult.getTotalElements());
        searchResult.setData(deviceQueryDTO);
 
        return searchResult;
    }
 
    /**
     * 基础仪器设备表 - 修改
     * */
    @Override
    public DeviceUpdateDTO updateBasicExperimentDevice(Long currentUserId, BasicExperimentDeviceAppUpdateBO deviceAppUpdateDO) {
 
        if (currentUserId < 0){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆");
        }
        //接收、转换参数
        ToUpdateDeviceBOConverter converter = new ToUpdateDeviceBOConverter();
        DeviceUpdateBO updateDeviceParam = converter.toUpdateDeviceDO(deviceAppUpdateDO);
 
        //参数校验
        if (ObjectUtils.isEmpty(updateDeviceParam.getId())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode(), "修改参数错误");
        }
        BasicExperimentDevice deviceById = basicExperimentDeviceRepository.getDeviceById(updateDeviceParam.getId());
        if (ObjectUtils.isEmpty(deviceById)){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "要修改的数据不存在,或已被删除");
        }
 
        if (ObjectUtils.isEmpty(deviceAppUpdateDO.getDeviceCode())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备编码不能为空");
        }
        BasicExperimentDevice deviceByCode = basicExperimentDeviceRepository.getDeviceByCode(deviceAppUpdateDO.getDeviceCode());
//        if (!ObjectUtils.isEmpty(deviceByCode) && !deviceByCode.getId().equals(updateDeviceParam.getId())){
//            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"设备编码已存在");
//        }
        if (ObjectUtils.isEmpty(deviceAppUpdateDO.getDeviceName())  && !deviceByCode.getId().equals(updateDeviceParam.getId())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备名称不能为空");
        }
//        BasicExperimentDevice deviceByName = basicExperimentDeviceRepository.getDeviceByName(deviceAppUpdateDO.getDeviceName());
//        if (!ObjectUtils.isEmpty(deviceByName)){
//            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"设备名称已存在");
//        }
 
        if (ObjectUtils.isEmpty(deviceAppUpdateDO.getSpecialDevice())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备类型不能为空");
        }
        if (ObjectUtils.isEmpty(deviceAppUpdateDO.getDevicePower())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备功率不能为空");
        }
        if (ObjectUtils.isEmpty(deviceAppUpdateDO.getDeviceUnit())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备计量单位不能为空");
        }
        if (ObjectUtils.isEmpty(deviceAppUpdateDO)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"找不到该类型的设备,请检查输入是否正确,或者先添加设备类型");
        }
        if (ObjectUtils.isEmpty(deviceAppUpdateDO.getDeviceDesc())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备型号不能为空");
        }
        if (ObjectUtils.isEmpty(deviceAppUpdateDO.getDeviceStatus())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备状态不能为空");
        }
        if (ObjectUtils.isEmpty(deviceAppUpdateDO.getBuyTime())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备购买时间不能为空");
        }
        if (ObjectUtils.isEmpty(deviceAppUpdateDO.getAdjustTime())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备校准时间不能为空");
        }
        //获取需要的参数
        LocalDateTime date = LocalDateTime.now();
        if (date.isBefore(deviceAppUpdateDO.getBuyTime())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备购买时间不能在当前时间之后");
        }
        if (date.isBefore(deviceAppUpdateDO.getAdjustTime())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备校准时间不能在当前时间之后");
        }
        if (deviceAppUpdateDO.getAdjustTime().isBefore(deviceAppUpdateDO.getBuyTime())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"设备校准时间不能在购买时间之后");
        }
        BasicExperimentDevice device = BeanCopyUtils.copyBean(deviceById, BasicExperimentDevice.class);
        UserInfoDomainDTO userInfoById = userDomainService.getUserInfoById(currentUserId);
 
        device.setUpdateTime(date);
        device.setUpdateByUserId(userInfoById.getId());
 
        device.setDeviceCode(updateDeviceParam.getDeviceCode());
        device.setDeviceName(updateDeviceParam.getDeviceName());
        device.setDevicePower(updateDeviceParam.getDevicePower());
        device.setDeviceUnit(updateDeviceParam.getDeviceUnit());
        device.setSpecialDevice(updateDeviceParam.getSpecialDevice());
        device.setSafeProtect(updateDeviceParam.getSafeProtect());
        device.setDeviceTypeId(updateDeviceParam.getDeviceTypeId());
        device.setDeviceType(updateDeviceParam.getDeviceType());
        device.setDeviceDesc(updateDeviceParam.getDeviceDesc());
        device.setDeviceStatus(updateDeviceParam.getDeviceStatus());
        device.setBuyTime(updateDeviceParam.getBuyTime());
        device.setAdjustTime(updateDeviceParam.getAdjustTime());
 
        BasicExperimentDevice saveResult = basicExperimentDeviceRepository.save(device);
 
        DeviceUpdateDTO deviceUpdateDTO = BeanCopyUtils.copyBean(saveResult, DeviceUpdateDTO.class);
 
        return deviceUpdateDTO;
    }
 
    /**
     * 基础仪器设备表 - 删除
     * */
    @Override
    public DeviceDeleteDTO deleteBasicExperimentDevice(Long currentUserId, Long id) {
 
        if (currentUserId < 0){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆");
        }
        if (ObjectUtils.isEmpty(id)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"请选择正常的设备进行删除");
        }
        BasicExperimentDevice deviceById = basicExperimentDeviceRepository.getDeviceById(id);
        if (ObjectUtils.isEmpty(deviceById)){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode() ,"要删除的设备不存在,或已被删除");
        }
        UserInfoDomainDTO userInfoById = userDomainService.getUserInfoById(currentUserId);
 
        LocalDateTime date = LocalDateTime.now();
        //设置数据为删除
        deviceById.setDeleteStatus(StatusEnum.DELETED.getCode().byteValue());
        deviceById.setUpdateByUserId(userInfoById.getId());
        deviceById.setUpdateTime(date);
 
        BasicExperimentDevice deleteResult = basicExperimentDeviceRepository.save(deviceById);
 
        return BeanCopyUtils.copyBean(deleteResult, DeviceDeleteDTO.class);
    }
 
    /**
     * 基础仪器设备表 - 设备列表
     * */
    @Override
    public List<BasicExperimentDeviceAppListDTO> listBasicExperimentDevice(Long currentUserId) {
 
        UserInfoDomainDTO user = userDomainService.getUserById(currentUserId);
        int roleTag = GetRoleTagUtils.GetRoleTagUtils(user);
 
        List<BasicExperimentDevice> deviceList = new ArrayList<>();
        if (SearchAuthUtils.basicSearchAuth() == 0){
            deviceList = basicExperimentDeviceRepository.listDevice();
            return BeanCopyUtils.copyBeanList(deviceList, BasicExperimentDeviceAppListDTO.class);
        }
 
 
        if (roleTag != UserTagEnum.USER_TAG_0.getCode()){
            deviceList = basicExperimentDeviceRepository.listDevice();
        }else {
            deviceList = basicExperimentDeviceRepository.listDeviceByUserId(currentUserId);
        }
        return BeanCopyUtils.copyBeanList(deviceList, BasicExperimentDeviceAppListDTO.class);
    }
 
    /**
     * 基础仪器设备表 - 通过id查询
     * */
    @Override
    public DeviceQueryDTO getBasicExperimentDeviceById(Long id) {
        if (ObjectUtils.isEmpty(id)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "请求参数不能为空");
        }
        BasicExperimentDevice deviceById = basicExperimentDeviceRepository.getDeviceById(id);
 
        if (ObjectUtils.isEmpty(deviceById)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode(), "风险源信息不存在,请检查是否输入有误或已被删除");
        }
        return BeanCopyUtils.copyBean(deviceById, DeviceQueryDTO.class);
    }
 
    /**
     * 基础仪器设备表 - 通过id列表查询
     * */
    @Override
    public List<DeviceQueryDTO> getBasicExperimentDeviceByIdList(List<Long> ids) {
        if (ids.size() < 1){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode(), "请求参数不能为空");
        }
 
        List<BasicExperimentDevice> listResult = basicExperimentDeviceRepository.batchById(ids);
        if (listResult.size() < 1){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode(), "查询结果为空");
        }
 
        return BeanCopyUtils.copyBeanList(listResult, DeviceQueryDTO.class);
    }
}